1 module Symantic.Reader where
3 import Data.Function ((.), const)
5 import Symantic.Classes hiding (const, (.))
9 -- | An intermediate interpreter exposing an environment.
10 newtype Reader r repr a = Reader { unReader :: r -> repr a }
12 type instance Derived (Reader r repr) = repr
13 instance LiftDerived (Reader r repr) where
14 liftDerived = Reader . const
15 instance LiftDerived1 (Reader r repr) where
16 liftDerived1 f a = Reader (f . unReader a)
17 instance LiftDerived2 (Reader r repr) where
18 liftDerived2 f a b = Reader (\r -> f (unReader a r) (unReader b r))
19 instance LiftDerived3 (Reader r repr) where
20 liftDerived3 f a b c = Reader (\r -> f (unReader a r) (unReader b r) (unReader c r))
21 instance LiftDerived4 (Reader r repr) where
22 liftDerived4 f a b c d = Reader (\r -> f (unReader a r) (unReader b r) (unReader c r) (unReader d r))
24 instance Abstractable repr => Abstractable (Reader r repr) where
25 lam f = Reader (\r -> lam ((`unReader` r) . f . liftDerived))
26 lam1 f = Reader (\r -> lam1 ((`unReader` r) . f . liftDerived))
27 instance Functionable repr => Functionable (Reader r repr)
28 instance Anythingable repr => Anythingable (Reader r repr)
29 instance Constantable c repr => Constantable c (Reader r repr)
30 instance Eitherable repr => Eitherable (Reader r repr)
31 instance Equalable repr => Equalable (Reader r repr)
32 instance IfThenElseable repr => IfThenElseable (Reader r repr)
33 -- Using 'Inferable' with a specific @a@ and keeping @repr@ polymorphic
34 -- is more usual; hence commenting this instance that would overlap.
35 --instance Inferable a repr => Inferable a (Reader r repr)
36 instance Listable repr => Listable (Reader r repr)
37 instance Maybeable repr => Maybeable (Reader r repr)
38 instance IsoFunctor repr => IsoFunctor (Reader r repr)
39 instance (ProductFunctor repr, IsoFunctor repr) => ProductFunctor (Reader r repr)
40 instance (SumFunctor repr, IsoFunctor repr) => SumFunctor (Reader r repr)
41 instance AlternativeFunctor repr => AlternativeFunctor (Reader r repr)
42 instance Dicurryable repr => Dicurryable (Reader r repr)
43 instance Emptyable repr => Emptyable (Reader r repr)
44 instance Semigroupable repr => Semigroupable (Reader r repr)
45 instance Optionable repr => Optionable (Reader r repr)
46 instance Repeatable repr => Repeatable (Reader r repr)
47 -- instance Permutable repr => Permutable (Reader r repr)
48 instance Routable repr => Routable (Reader r repr)
49 instance Voidable repr => Voidable (Reader r repr)
50 instance Substractable repr => Substractable (Reader r repr)