]> Git — Sourcephile - haskell/symantic.git/blob - Language/Symantic/Interpreting/Dup.hs
Add Gram_Term.
[haskell/symantic.git] / Language / Symantic / Interpreting / Dup.hs
1 {-# LANGUAGE ConstraintKinds #-}
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 @term@ at parsing time
8 -- as done with 'TermO';
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 term1 term2 a
16 = DupI
17 { dupI_1 :: term1 a
18 , dupI_2 :: term2 a
19 }
20
21 dupI0
22 :: (cl r, cl s)
23 => Proxy cl
24 -> (forall term. cl term => term 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 term. cl term => term a -> term 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 term. cl term => term a -> term b -> term 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 term. cl term => term a -> term b -> term c -> term 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