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 sem a = Reader { unReader :: r -> sem a }
12 type instance Derived (Reader r sem) = sem
13 instance LiftDerived (Reader r sem) where
14 liftDerived = Reader . const
15 instance LiftDerived1 (Reader r sem) where
16 liftDerived1 f a = Reader (f . unReader a)
17 instance LiftDerived2 (Reader r sem) where
18 liftDerived2 f a b = Reader (\r -> f (unReader a r) (unReader b r))
19 instance LiftDerived3 (Reader r sem) where
20 liftDerived3 f a b c = Reader (\r -> f (unReader a r) (unReader b r) (unReader c r))
21 instance LiftDerived4 (Reader r sem) 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 sem => Abstractable (Reader r sem) where
25 lam f = Reader (\r -> lam ((`unReader` r) . f . liftDerived))
26 lam1 f = Reader (\r -> lam1 ((`unReader` r) . f . liftDerived))
27 instance Functionable sem => Functionable (Reader r sem)
28 instance Anythingable sem => Anythingable (Reader r sem)
29 instance Constantable c sem => Constantable c (Reader r sem)
30 instance Eitherable sem => Eitherable (Reader r sem)
31 instance Equalable sem => Equalable (Reader r sem)
32 instance IfThenElseable sem => IfThenElseable (Reader r sem)
33 -- Using 'Inferable' with a specific @a@ and keeping @sem@ polymorphic
34 -- is more usual; hence commenting this instance that would overlap.
35 --instance Inferable a sem => Inferable a (Reader r sem)
36 instance Listable sem => Listable (Reader r sem)
37 instance Maybeable sem => Maybeable (Reader r sem)
38 instance IsoFunctor sem => IsoFunctor (Reader r sem)
39 instance (ProductFunctor sem, IsoFunctor sem) => ProductFunctor (Reader r sem)
40 instance (SumFunctor sem, IsoFunctor sem) => SumFunctor (Reader r sem)
41 instance AlternativeFunctor sem => AlternativeFunctor (Reader r sem)
42 instance Dicurryable sem => Dicurryable (Reader r sem)
43 instance Emptyable sem => Emptyable (Reader r sem)
44 instance Semigroupable sem => Semigroupable (Reader r sem)
45 instance Optionable sem => Optionable (Reader r sem)
46 instance Repeatable sem => Repeatable (Reader r sem)
47 -- instance Permutable sem => Permutable (Reader r sem)
48 instance Routable sem => Routable (Reader r sem)
49 instance Voidable sem => Voidable (Reader r sem)
50 instance Substractable sem => Substractable (Reader r sem)