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