add datatype generation DSL stuff
[clean-tests.git] / datatype / Main.hs
1 {-# LANGUAGE FlexibleContexts #-}
2 module Main where
3
4 import Language
5
6 import Compiler
7 import Printer
8
9 import Tuple
10
11 main :: IO ()
12 main
13 -- = putStrLn (runPrint e0)
14 -- >> putStrLn (runPrint e1)
15 -- >> putStrLn (runPrint e2)
16 -- >> putStrLn (runPrint e3)
17 -- >> putStrLn (show $ runCompiler e0)
18 -- = putStrLn (show $ interpret 10 <$> runCompiler e0)
19 -- = putStrLn (show $ interpret 10 <$> runCompiler e1'')
20 = putStrLn (show $ interpret 10 <$> runCompiler (e1))
21 >> putStrLn (show $ interpret 10 <$> runCompiler (tuplef0' e1))
22 >> putStrLn (show $ interpret 10 <$> runCompiler (tuplef1' e1))
23 >> putStrLn (show $ interpret 10 <$> runCompiler (tuplef1' $ second' e3))
24 >> putStrLn (runPrint $ lit (42 :: Int) `cons` (lit (10 :: Int) `cons` nil))
25 >> putStrLn (show $ interpret 20 <$> runCompiler (lit (42 :: Int) `cons` (lit (10 :: Int) `cons` nil)))
26 >> putStrLn (runPrint $ unmain $ f0)
27 >> putStrLn (show $ runCompiler (unmain f0))
28 >> putStrLn (show $ interpret 20 <$> runCompiler (unmain f0))
29 >> putStrLn (show $ runCompiler (unmain f1))
30 >> putStrLn (show $ interpret 20 <$> runCompiler (unmain f1))
31 >> putStrLn (show $ runCompiler (unmain f2))
32 >> putStrLn (show $ interpret 20 <$> runCompiler (unmain f2))
33 >> putStrLn (show $ runCompiler (unmain f3))
34 >> putStrLn (show $ interpret 20 <$> runCompiler (unmain f3))
35 -- >> putStrLn (show $ interpret <$> runCompiler e1)
36 -- >> putStrLn (show $ interpret <$> runCompiler e1')
37 -- >> putStrLn (show $ interpret <$> runCompiler e1'')
38
39 e0 :: Expression v => v Int
40 e0 = lit 2 ^. lit 8
41
42 e1 :: (Expression v, Tuple' v) => v (Tuple Char Int)
43 e1 = tuple (lit 'c') (lit 42)
44
45 e1' :: (Expression v, Tuple' v) => v Char
46 e1' = tuplef0' e1
47
48 e1'' :: (Expression v, Tuple' v) => v Int
49 e1'' = tuplef1' e1
50
51 e2 :: (Expression v, TupleR' v) => v (TupleR Char Bool)
52 e2 = tupler (lit 'c') (lit True)
53
54 e3 :: (Expression v, Tuple' v, TupleR' v) => v (TupleR Char (Tuple Int Bool))
55 e3 = tupler (lit 'c') (tuple (lit 42) (lit True))
56
57 f0 :: (Expression v, Function () v) => Main (v Int)
58 f0
59 = fun ( \c42->(\()->lit 42)
60 :- Main {unmain=c42 () +. lit 38}
61 )
62
63 f1 :: (Expression v, Function (v Int) v, Function () v) => Main (v Int)
64 f1
65 = fun ( \c42->(\()->lit 42)
66 :- fun ( \inc->(\i->i +. lit 1)
67 :- Main {unmain=c42 () +. inc (lit 41)}
68 ))
69
70 f2 :: (Expression v, Function (v Int, v Int) v) => Main (v Int)
71 f2
72 = fun ( \sub->(\(x, y)->x -. y)
73 :- Main {unmain=sub (lit 2, lit 8)}
74 )
75
76 f3 :: (Expression v, Tuple' v, Function (v Int) v) => Main (v (Tuple Int Int))
77 f3
78 = fun ( \idfun->(\x->x)
79 :- Main {unmain=tuple (idfun (lit 42)) (idfun (lit 4)) }
80 )
81
82 f4 :: (Expression v, Function (v Int) v) => Main (v Int)
83 f4
84 = fun ( \fac->(\x->x)
85 :- Main {unmain=tuple (idfun (lit 42)) (idfun (lit 4)) }
86 )