-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathEDSL.hs
97 lines (78 loc) · 1.71 KB
/
EDSL.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
{-# LANGUAGE ImpredicativeTypes #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleInstances #-}
module EDSL (
-- * Data types used in contracts
Asset (..),
Party (..),
Exp,
acc,
ife,
-- * Real expression combinators
RExp,
rLit,
rObs,
-- * Boolean expression combinators
BExp,
false, true,
(!<!), (!<=!), (!=!), (!/=!), (!>!), (!>=!), (!&!), (!|!),
bNot,
bObs,
-- * Contract combinators
ContrHoas,
Contr,
zero,
transfer,
scale,
(#),
both,
(&),
translate,
(!),
ifWithin,
iff,
letc,
-- * Operations on contracts
ObsLabel (..),
RealObs (..),
BoolObs (..),
ExtEnvP,
FMap,
horizon,
advance,
specialise,
hasType,
printContr,
showContr,
mkExtEnvP,
ExpHoas,
R, B,
) where
import Contract hiding (Exp,Contr,specialise,horizon,map)
import qualified Contract as C
import HOAS
import qualified Data.Map as Map
import Data.Maybe
horizon :: Contr -> Int
horizon c = C.horizon (fromHoas c)
advance :: Contr -> ExtEnvP -> (Contr, FMap)
advance c env = let (c',t) = fromJust (redfun (fromHoas c) [] env)
in (toHoas c', t)
specialise :: Contr -> ExtEnvP -> Contr
specialise c = toHoas . C.specialise (fromHoas c) []
mkExtEnvP :: [(RealObs, Int,Double)] -> [(BoolObs, Int,Bool)] -> ExtEnvP
mkExtEnvP rs bs = env
where real (l,i,r) = ((l,i),RVal r)
bool (l,i,r) = ((l,i),BVal r)
tabR = Map.fromList (map real rs)
tabB = Map.fromList (map bool bs)
env (LabR l) i = Map.lookup (l,i) tabR
env (LabB l) i = Map.lookup (l,i) tabB
hasType :: Contr -> Bool
hasType = C.has_type . fromHoas
printContr :: Contr -> IO ()
printContr = putStrLn . showContr
showContr :: Contr -> String
showContr = show . fromHoas