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