@@ -6,14 +6,11 @@ module Control.Has
66 , MonadHas
77 , Fieldy
88 , Generic
9− ) where
9+ )
10+where
1011
1112import Control.Lens
12−-- reexport all from Reader except Control.Monad etc
13−-- to correspond mtl-2.3+
1413import Control.Monad.Reader as X
15− ( MonadReader(..), asks, Reader, runReader, mapReader, withReader
16− , ReaderT(ReaderT), runReaderT, mapReaderT, withReaderT )
1714import Data.Kind
1815import GHC.Generics as G
1916
@@ -24,11 +21,11 @@ class Has x r where
2421instance {-# OVERLAPS #-} Has r r where
2522 part = id
2623
27−type family HasAll (xs :: [Type]) r :: Constraint where
24+type family HasAll (xs :: [*]) r :: Constraint where
2825 HasAll '[] r = ()
2926 HasAll (x ': xs) r = (Has x r, HasAll xs r)
3027
31−data LensList (r :: Type) (es :: [Type]) where
28+data LensList (r :: *) (es :: [*]) where
3229 LLNil :: LensList r '[]
3330 LLCons :: Lens r r e e -> LensList r es -> LensList r (e ': es)
3431
@@ -36,7 +33,7 @@ mapLL :: Lens s s r r -> LensList r es -> LensList s es
3633mapLL _ LLNil = LLNil
3734mapLL m (LLCons l ls) = LLCons (m . l) (mapLL m ls)
3835
39−type family (xs :: [Type]) ++ (ys :: [Type]) :: [Type] where
36+type family (xs :: [*]) ++ (ys :: [*]) :: [*] where
4037 '[] ++ ys = ys
4138 (x ': xs) ++ ys = x ': (xs ++ ys)
4239
@@ -47,7 +44,7 @@ concatLL (LLCons l ls) ys = LLCons l (concatLL ls ys)
4744-- borrowed from Data.HSet.Get
4845data N = Z | S N
4946
50−type family IndexOf (x :: Type) (xs :: [Type]) :: N where
47+type family IndexOf (x :: *) (xs :: [*]) :: N where
5148 IndexOf x (x ': _) = 'Z
5249 IndexOf x (_ ': xs) = 'S (IndexOf x xs)
5350
@@ -56,8 +53,8 @@ class (i ~ IndexOf e es) => GetLens e es i | i es -> e where
5653
5754type Elem e es = GetLens e es (IndexOf e es)
5855
59−class Fieldy (r :: Type) where
60− type Fields r :: [Type]
56+class Fieldy (r :: *) where
57+ type Fields r :: [*]
6158 type Fields r = GFields (Rep r)
6259 lensList :: LensList r (Fields r)
6360 default lensList
@@ -68,7 +65,9 @@ class Fieldy (r :: Type) where
6865instance {-# OVERLAPPABLE #-} (Fieldy r, Elem e (Fields r)) => Has e r where
6966 part = getLens lensList
7067
71−type MonadHas es r m = (MonadReader r m, HasAll es r)
68+class (MonadReader r m, HasAll es r)
69+ => MonadHas (es :: [*]) (r :: *) (m :: * -> *) | m -> r
70+instance (MonadReader r m, HasAll es r) => MonadHas es r m
7271
7372instance GetLens e (e ': es) 'Z where
7473 getLens (LLCons l _) = l
@@ -77,16 +76,16 @@ instance (GetLens e' es n, 'S n ~ IndexOf e' (e ': es))
7776 => GetLens e' (e ': es) ('S n) where
7877 getLens (LLCons _ ls) = getLens ls
7978
80−class GFieldy (r :: Type -> Type) where
81− type GFields r :: [Type]
79+class GFieldy (r :: * -> *) where
80+ type GFields r :: [*]
8281 glensList :: LensList (r x) (GFields r)
8382
8483instance GFieldyProduct r => GFieldy (D1 d (C1 c r)) where
8584 type GFields (D1 d (C1 c r)) = GFieldsProduct r
8685 glensList = mapLL (iso unM1 M1 . iso unM1 M1) glensListProduct
8786
88−class GFieldyProduct (r :: Type -> Type) where
89− type GFieldsProduct r :: [Type]
87+class GFieldyProduct (r :: * -> *) where
88+ type GFieldsProduct r :: [*]
9089 glensListProduct :: LensList (r x) (GFieldsProduct r)
9190
9291instance (GFieldyProduct r, GFieldyProduct s) => GFieldyProduct (r :*: s) where
@@ -105,7 +104,7 @@ instance GFieldyProduct (S1 s (K1 k r)) where
105104 type GFieldsProduct (S1 s (K1 k r)) = '[r]
106105 glensListProduct = LLCons (iso unM1 M1 . iso unK1 K1) LLNil
107106
108−type family AllElem (xs :: [Type]) (es :: [Type]) :: Constraint where
107+type family AllElem (xs :: [*]) (es :: [*]) :: Constraint where
109108 AllElem '[] _ = ()
110109 AllElem (x ': xs) es = (Elem x es, AllElem xs es)
111110