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