-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hs
55 lines (44 loc) · 1.44 KB
/
Main.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
{-# LANGUAGE NoMonomorphismRestriction #-}
import Test
import Example
import ParseLambda
import Lambda
import Data.List
import Control.Monad
import Control.Applicative
import System.IO (isEOF)
main = do
b <- isEOF
unless b $ do
putStrLn $ replicate 100 '#'
t <- parseExpr <$> getLine
putStrLn $ "parsed: " ++ show t
putStrLn $ replicate 100 '='
case effects t of
[] -> interpretPure t $ testPure
[EffNondet] -> interpretNondet t $ testNondet
[EffState] -> interpretState t $ testState
main
data EffectType = EffNondet | EffState
deriving Eq
effects :: LambdaExpr -> [EffectType]
effects (Oplus l1 l2) = nub $ [EffNondet] ++ effects l1 ++ effects l2
effects (Drf _) = [EffState]
effects (Asg _ _ l) = nub $ [EffState] ++ effects l
effects (Apply l1 l2) = nub $ effects l1 ++ effects l2
effects (Abst _ l) = effects l
effects (Hole _) = error "Do not input ...[...]..."
effects _ = []
mainOld = do
shout "(\\ x y -> x + y) 5 3"
interpretPure firstPureExample $ testPure
shout "(\\ x -> x + x) 3"
interpretPure secondPureExample $ testPure
shout "(\\ x -> x + x) (3 |_| 5)"
interpretNondet firstNondetExample $ testNondet
shout "(\\ f -> f 0 + f 1) (\\ x -> 3 |_| 5)"
interpretNondet secondNondetExample $ testNondet
shout "(l := 2); (\\ x -> x + (l := 3); x) (! l)"
interpretState stateExample $ testState
shout str = mapM_ putStrLn $
[replicate 100 '#', str, replicate 100 '=']