packages feed

basic (empty) → 0.1.0.0

raw patch · 5 files changed

+170/−0 lines, 5 filesdep +basedep +stmdep +template-haskellsetup-changed

Dependencies added: base, stm, template-haskell, transformers, util

Files

+ Data/Basic.hs view
@@ -0,0 +1,91 @@+{-# LANGUAGE TemplateHaskell #-}++module Data.Basic where++import Control.Concurrent.STM (STM)+import Control.Exception (Handler (..))+import Control.Monad (replicateM)+import Control.Monad.Trans.Accum+import Control.Monad.Trans.Class+import Control.Monad.Trans.Cont+import Control.Monad.Trans.Except+import Control.Monad.Trans.Identity+import Control.Monad.Trans.Maybe+import Control.Monad.Trans.Reader+import Control.Monad.Trans.Select+import Control.Monad.Trans.State.Lazy as L+import Control.Monad.Trans.State.Strict as S+import Control.Monad.Trans.Writer.Lazy as L+import Control.Monad.Trans.Writer.Strict as S+import Control.Monad.ST.Lazy as L (ST)+import Control.Monad.ST.Strict as S (ST)+import Data.Foldable+import Data.Functor.Compose+import Data.Functor.Const+import Data.Functor.Identity+import Data.Functor.Product+import Data.List.NonEmpty (NonEmpty)+import Data.Monoid (Alt (..))+import Data.Proxy+import Data.Semigroup (Arg (..))+import Language.Haskell.TH+import Text.ParserCombinators.ReadP (ReadP)+import Text.ParserCombinators.ReadPrec (ReadPrec)++-- | Laws if @'Functor' f@:+--+-- * @'liftBase' . 'fmap' f = 'fmap' f . 'liftBase'@+class Basic1 (f :: α -> *) where+    type Base f :: α -> *+    liftBase :: Base f a -> f a++$(let f :: Int -> Name -> Q Dec+      f n name =+          [InstanceD Nothing [] (ConT (mkName "Basic1") `AppT` t)+           [TySynInstD ''Base $ TySynEqn [t] t,+            ValD (VarP 'liftBase) (NormalB (VarE 'id)) []]+            | t <- foldl' AppT (ConT name) <$> replicateM n (VarT <$> newName "a") ]+  in traverse (uncurry f) [(0, ''IO), (1, ''L.ST), (1, ''S.ST), (0, ''STM),+                           (0, ''Maybe), (1, ''Either), (0, ''Identity),+                           (0, ''[]), (0, ''NonEmpty),+                           (0, ''Proxy), (1, ''Const),+                           (0, ''ReadP), (0, ''ReadPrec), (0, ''Handler),+                           (1, ''Arg), (1, ''Alt)])++instance Basic1 ((,) a) where+    type Base ((,) a) = (,) a+    liftBase = id++instance Basic1 ((->) a) where+    type Base ((->) a) = (->) a+    liftBase = id++instance (Monad f, Basic1 g) => Basic1 (Compose f g) where+    type Base (Compose f g) = Base g+    liftBase = Compose . pure . liftBase++instance (Basic1 f, Basic1 g, Base f ~ Base g) => Basic1 (Product f g) where+    type Base (Product f g) = Base f+    liftBase = Pair <$> liftBase <*> liftBase++$(let f :: Int -> Name -> Q Dec+      f n name = +          [InstanceD Nothing [ConT ''Basic1 `AppT` f, ConT ''Monad `AppT` f] (ConT ''Basic1 `AppT` AppT t f)+           [TySynInstD ''Base $ TySynEqn [AppT t f] (ConT ''Base `AppT` f),+            ValD (VarP 'liftBase) (NormalB (foldl' AppE (VarE '(.)) (VarE <$> ['lift, 'liftBase]))) []]+            | t <- foldl' AppT (ConT name) <$> replicateM n (VarT <$> newName "a")+            , f <- VarT <$> newName "f"]+  in traverse (uncurry f) [(0, ''IdentityT), (0, ''MaybeT), (1, ''ContT), (1, ''SelectT),+                           (1, ''ReaderT), (1, ''L.StateT), (1, ''S.StateT), (1, ''ExceptT)])++instance (Basic1 f, Monad f, Monoid a) => Basic1 (L.WriterT a f) where+    type Base (L.WriterT a f) = Base f+    liftBase = lift . liftBase++instance (Basic1 f, Monad f, Monoid a) => Basic1 (S.WriterT a f) where+    type Base (S.WriterT a f) = Base f+    liftBase = lift . liftBase++instance (Basic1 f, Monad f, Monoid a) => Basic1 (AccumT a f) where+    type Base (AccumT a f) = Base f+    liftBase = lift . liftBase
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright M Farkas-Dyck © 2018++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of M Farkas-Dyck nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,1 @@+# basic
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ basic.cabal view
@@ -0,0 +1,46 @@+name:                basic+version:             0.1.0.0+synopsis:            Lifting values from base types+-- description:+license:             BSD3+license-file:        LICENSE+author:              M Farkas-Dyck+maintainer:          strake888@gmail.com+copyright:           2018 M Farkas-Dyck+-- category:            +build-type:          Simple+extra-source-files:  README.md+cabal-version:       >=1.10++library+  exposed-modules:     Data.Basic+  build-depends:       base >= 4.7 && < 5+                     , stm+                     , template-haskell+                     , transformers >=0.5 && <0.6+                     , util >=0.1.10 && <0.2+  default-language:    Haskell2010+  default-extensions:  UnicodeSyntax+                     , LambdaCase+                     , EmptyCase+                     , MonadComprehensions+                     , InstanceSigs+                     , PartialTypeSignatures+                     , PolyKinds+                     , ConstraintKinds+                     , FlexibleContexts+                     , FlexibleInstances+                     , TypeFamilies+                     , StandaloneDeriving+                     , DeriveFunctor, DeriveFoldable, DeriveTraversable+  ghc-options:         -Wall -Wcompat -Wredundant-constraints -Wno-name-shadowing+                       -Wincomplete-record-updates -Wincomplete-uni-patterns+                       -Werror=incomplete-patterns+                       -Werror=incomplete-uni-patterns+                       -Werror=incomplete-record-updates+                       -Werror=missing-fields+                       -Werror=missing-methods++source-repository head+  type:     git+  location: https://github.com/strake/basic.hs