git.iko.soy/typeable/control-has
on master help sign in
4 files changed+62−73
since splitsnapshots
unifiedsplit
.gitignore+1 control-has.cabal+39−36 src/Control/EnvT.hs+7−26 src/Control/Has.hs+15−11
.gitignorenew file+1
@@ -0,0 +1 @@
1+.stack-work
control-has.cabal+39−36
@@ -1,38 +1,41 @@
1−cabal-version: 2.4
2−name: control-has
3−version: 0.1.0.0
4−synopsis: Typeclass for things that have parts
5−license-file: LICENSE
6−build-type: Simple
1+cabal-version: 2.4
2+name: control-has
3+version: 0.2.0.0
4+synopsis: Typeclass for things that have parts
5+license-file: LICENSE
6+build-type: Simple
77
88library
9− hs-source-dirs: src
10− ghc-options: -Wall
11− exposed-modules: Control.Has
12− Control.EnvT
13− build-depends: base
14− , exceptions
15− , lens
16− , monad-control
17− , mtl
18− , resourcet
19− , transformers-base
20− if !impl(ghcjs)
21− build-depends: katip
22− default-language: Haskell2010
23− default-extensions: ConstraintKinds
24− , DataKinds
25− , DefaultSignatures
26− , DerivingStrategies
27− , FlexibleContexts
28− , FlexibleInstances
29− , FunctionalDependencies
30− , GADTs
31− , GeneralizedNewtypeDeriving
32− , KindSignatures
33− , RankNTypes
34− , StandaloneDeriving
35− , TypeOperators
36− , TypeFamilies
37− , UndecidableInstances
38− , UndecidableSuperClasses
9+ hs-source-dirs: src
10+ ghc-options: -Wall
11+ exposed-modules:
12+ Control.EnvT
13+ Control.Has
14+
15+ build-depends:
16+ , base >=4.10
17+ , exceptions
18+ , lens
19+ , monad-control
20+ , mtl
21+ , resourcet
22+ , transformers-base
23+
24+ default-language: Haskell2010
25+ default-extensions:
26+ ConstraintKinds
27+ DataKinds
28+ DefaultSignatures
29+ DerivingStrategies
30+ FlexibleContexts
31+ FlexibleInstances
32+ FunctionalDependencies
33+ GADTs
34+ GeneralizedNewtypeDeriving
35+ KindSignatures
36+ RankNTypes
37+ StandaloneDeriving
38+ TypeFamilies
39+ TypeOperators
40+ UndecidableInstances
41+ UndecidableSuperClasses
src/Control/EnvT.hs+7−26
@@ -14,16 +14,19 @@ import Control.Lens
1414import Control.Monad.Base
1515import Control.Monad.Catch
1616import Control.Monad.Except
17−import Control.Monad.Fail
1817import Control.Monad.Reader as X
1918import Control.Monad.Trans.Control
2019import Control.Monad.Trans.Resource
2120import Control.Monad.Zip
22−#ifndef ghcjs_HOST_OS
23−import Katip
24−import Katip.Monadic
21+
22+#if MIN_VERSION_mtl(2,3,0)
23+import Control.Monad
24+import Control.Monad.Fix
2525#endif
2626
27+#if !MIN_VERSION_base(4,13,0)
28+import Control.Monad.Fail
29+#endif
2730
2831-- | The only reason this exists is that there are a lot of instances for
2932-- 'EnvT, which simply pass the implementation to the inner 'm'
@@ -63,27 +66,5 @@ execEnvT :: forall r m a. r -> EnvT r m a -> m a
6366execEnvT = flip runEnvT
6467{-# INLINE execEnvT #-}
6568
66−#ifndef ghcjs_HOST_OS
67−-- FIXME: These lens should probably be moved into a separate package
68−-- or sent to upstream katip.
69−makeLensesFor
70− [ ("ltsLogEnv", "_ltsLogEnv")
71− , ("ltsContext", "_ltsContext")
72− , ("ltsNamespace", "_ltsNamespace")
73− ] ''KatipContextTState
74−
75−instance (Has KatipContextTState r, MonadIO m)
76− => KatipContext (EnvT r m) where
77− getKatipContext = view $ part . _ltsContext
78− localKatipContext f = local (part . _ltsContext %~ f)
79− getKatipNamespace = view $ part . _ltsNamespace
80− localKatipNamespace f = local (part . _ltsNamespace %~ f)
81−
82−instance (Has KatipContextTState r, MonadIO m)
83− => Katip (EnvT r m) where
84− getLogEnv = view $ part . _ltsLogEnv
85− localLogEnv f = local (part . _ltsLogEnv %~ f)
86−#endif
87−
8869instance MonadResource m => MonadResource (EnvT r m) where
8970 liftResourceT = lift . liftResourceT
src/Control/Has.hs+15−11
@@ -9,7 +9,11 @@ module Control.Has
99 ) where
1010
1111import Control.Lens
12+-- reexport all from Reader except Control.Monad etc
13+-- to correspond mtl-2.3+
1214import Control.Monad.Reader as X
15+ ( MonadReader(..), asks, Reader, runReader, mapReader, withReader
16+ , ReaderT(ReaderT), runReaderT, mapReaderT, withReaderT )
1317import Data.Kind
1418import GHC.Generics as G
1519
@@ -20,11 +24,11 @@ class Has x r where
2024instance {-# OVERLAPS #-} Has r r where
2125 part = id
2226
23−type family HasAll (xs :: [*]) r :: Constraint where
27+type family HasAll (xs :: [Type]) r :: Constraint where
2428 HasAll '[] r = ()
2529 HasAll (x ': xs) r = (Has x r, HasAll xs r)
2630
27−data LensList (r :: *) (es :: [*]) where
31+data LensList (r :: Type) (es :: [Type]) where
2832 LLNil :: LensList r '[]
2933 LLCons :: Lens r r e e -> LensList r es -> LensList r (e ': es)
3034
@@ -32,7 +36,7 @@ mapLL :: Lens s s r r -> LensList r es -> LensList s es
3236mapLL _ LLNil = LLNil
3337mapLL m (LLCons l ls) = LLCons (m . l) (mapLL m ls)
3438
35−type family (xs :: [*]) ++ (ys :: [*]) :: [*] where
39+type family (xs :: [Type]) ++ (ys :: [Type]) :: [Type] where
3640 '[] ++ ys = ys
3741 (x ': xs) ++ ys = x ': (xs ++ ys)
3842
@@ -43,7 +47,7 @@ concatLL (LLCons l ls) ys = LLCons l (concatLL ls ys)
4347-- borrowed from Data.HSet.Get
4448data N = Z | S N
4549
46−type family IndexOf (x :: *) (xs :: [*]) :: N where
50+type family IndexOf (x :: Type) (xs :: [Type]) :: N where
4751 IndexOf x (x ': _) = 'Z
4852 IndexOf x (_ ': xs) = 'S (IndexOf x xs)
4953
@@ -52,8 +56,8 @@ class (i ~ IndexOf e es) => GetLens e es i | i es -> e where
5256
5357type Elem e es = GetLens e es (IndexOf e es)
5458
55−class Fieldy (r :: *) where
56− type Fields r :: [*]
59+class Fieldy (r :: Type) where
60+ type Fields r :: [Type]
5761 type Fields r = GFields (Rep r)
5862 lensList :: LensList r (Fields r)
5963 default lensList
@@ -73,16 +77,16 @@ instance (GetLens e' es n, 'S n ~ IndexOf e' (e ': es))
7377 => GetLens e' (e ': es) ('S n) where
7478 getLens (LLCons _ ls) = getLens ls
7579
76−class GFieldy (r :: * -> *) where
77− type GFields r :: [*]
80+class GFieldy (r :: Type -> Type) where
81+ type GFields r :: [Type]
7882 glensList :: LensList (r x) (GFields r)
7983
8084instance GFieldyProduct r => GFieldy (D1 d (C1 c r)) where
8185 type GFields (D1 d (C1 c r)) = GFieldsProduct r
8286 glensList = mapLL (iso unM1 M1 . iso unM1 M1) glensListProduct
8387
84−class GFieldyProduct (r :: * -> *) where
85− type GFieldsProduct r :: [*]
88+class GFieldyProduct (r :: Type -> Type) where
89+ type GFieldsProduct r :: [Type]
8690 glensListProduct :: LensList (r x) (GFieldsProduct r)
8791
8892instance (GFieldyProduct r, GFieldyProduct s) => GFieldyProduct (r :*: s) where
@@ -101,7 +105,7 @@ instance GFieldyProduct (S1 s (K1 k r)) where
101105 type GFieldsProduct (S1 s (K1 k r)) = '[r]
102106 glensListProduct = LLCons (iso unM1 M1 . iso unK1 K1) LLNil
103107
104−type family AllElem (xs :: [*]) (es :: [*]) :: Constraint where
108+type family AllElem (xs :: [Type]) (es :: [Type]) :: Constraint where
105109 AllElem '[] _ = ()
106110 AllElem (x ': xs) es = (Elem x es, AllElem xs es)
107111