]> Git — Sourcephile - haskell/symantic.git/blob - symantic/Language/Symantic/Interpreting/Dup.hs
Archive old attempt to remove proto tokens without polymorphic types.
[haskell/symantic.git] / symantic / Language / Symantic / Interpreting / Dup.hs
1 {-# LANGUAGE AllowAmbiguousTypes #-}
2 {-# LANGUAGE ConstraintKinds #-}
3 -- | Interpreter to duplicate the representation of an expression
4 -- in order to evaluate it with different interpreters.
5 --
6 -- NOTE: this is a more verbose, less clear,
7 -- and maybe less efficient alternative
8 -- to maintaining the universal polymorphism of @term@
9 -- at parsing time as done with 'Term';
10 -- it is mainly here for the sake of curiosity.
11 module Language.Symantic.Interpreting.Dup where
12
13 -- | Interpreter's data.
14 data DupI term1 term2 a
15 = DupI
16 { dupI_1 :: term1 a
17 , dupI_2 :: term2 a
18 }
19
20 dupI0
21 :: (cl r, cl s)
22 => (forall term. cl term => term a)
23 -> DupI r s a
24 dupI0 f = f `DupI` f
25
26 dupI1
27 :: (cl r, cl s)
28 => (forall term. cl term => term a -> term b)
29 -> DupI r s a
30 -> DupI r s b
31 dupI1 f (a1 `DupI` a2) =
32 f a1 `DupI` f a2
33
34 dupI2
35 :: (cl r, cl s)
36 => (forall term. cl term => term a -> term b -> term c)
37 -> DupI r s a
38 -> DupI r s b
39 -> DupI r s c
40 dupI2 f (a1 `DupI` a2) (b1 `DupI` b2) =
41 f a1 b1 `DupI` f a2 b2
42
43 dupI3
44 :: (cl r, cl s)
45 => (forall term. cl term => term a -> term b -> term c -> term d)
46 -> DupI r s a
47 -> DupI r s b
48 -> DupI r s c
49 -> DupI r s d
50 dupI3 f (a1 `DupI` a2) (b1 `DupI` b2) (c1 `DupI` c2) =
51 f a1 b1 c1 `DupI` f a2 b2 c2