]> Git — Sourcephile - haskell/symantic-base.git/blob - src/Symantic/Semantics/Reader.hs
doc: update `ChangeLog.md`
[haskell/symantic-base.git] / src / Symantic / Semantics / Reader.hs
1 module Symantic.Semantics.Reader where
2
3 import Data.Function (const, (.))
4
5 import Symantic.Syntaxes.Classes hiding (const, (.))
6 import Symantic.Syntaxes.Derive
7
8 -- * Type 'Reader'
9
10 -- | An intermediate interpreter exposing an environment.
11 newtype Reader r sem a = Reader {unReader :: r -> sem a}
12
13 type instance Derived (Reader r sem) = sem
14 instance LiftDerived (Reader r sem) where
15 liftDerived = Reader . const
16 instance LiftDerived1 (Reader r sem) where
17 liftDerived1 f a = Reader (f . unReader a)
18 instance LiftDerived2 (Reader r sem) where
19 liftDerived2 f a b = Reader (\r -> f (unReader a r) (unReader b r))
20 instance LiftDerived3 (Reader r sem) where
21 liftDerived3 f a b c = Reader (\r -> f (unReader a r) (unReader b r) (unReader c r))
22 instance LiftDerived4 (Reader r sem) where
23 liftDerived4 f a b c d = Reader (\r -> f (unReader a r) (unReader b r) (unReader c r) (unReader d r))
24
25 instance Unabstractable sem => Unabstractable (Reader r sem)
26 instance Abstractable sem => Abstractable (Reader r sem) where
27 lam f = Reader (\r -> lam ((`unReader` r) . f . liftDerived))
28 lam1 f = Reader (\r -> lam1 ((`unReader` r) . f . liftDerived))
29 instance Functionable sem => Functionable (Reader r sem)
30 instance Anythingable sem => Anythingable (Reader r sem)
31 instance Constantable c sem => Constantable c (Reader r sem)
32 instance Eitherable sem => Eitherable (Reader r sem)
33 instance Equalable sem => Equalable (Reader r sem)
34 instance IfThenElseable sem => IfThenElseable (Reader r sem)
35
36 -- Using 'Inferable' with a specific @a@ and keeping @sem@ polymorphic
37 -- is more usual; hence commenting this instance that would overlap.
38 --instance Inferable a sem => Inferable a (Reader r sem)
39 instance Listable sem => Listable (Reader r sem)
40 instance Maybeable sem => Maybeable (Reader r sem)
41 instance IsoFunctor sem => IsoFunctor (Reader r sem)
42 instance (ProductFunctor sem, IsoFunctor sem) => ProductFunctor (Reader r sem)
43 instance (SumFunctor sem, IsoFunctor sem) => SumFunctor (Reader r sem)
44 instance AlternativeFunctor sem => AlternativeFunctor (Reader r sem)
45 instance Dicurryable sem => Dicurryable (Reader r sem)
46 instance Emptyable sem => Emptyable (Reader r sem)
47 instance Semigroupable sem => Semigroupable (Reader r sem)
48 instance Optionable sem => Optionable (Reader r sem)
49 instance Repeatable sem => Repeatable (Reader r sem)
50
51 -- instance Permutable sem => Permutable (Reader r sem)
52 instance Routable sem => Routable (Reader r sem)
53 instance Voidable sem => Voidable (Reader r sem)
54 instance Substractable sem => Substractable (Reader r sem)