source: doc/theses/jiada_liang_MMath/test.hs@ e15293b

Last change on this file since e15293b was 1725989, checked in by Peter A. Buhr <pabuhr@…>, 15 months ago

add enumeration test programs for different programming languages

  • Property mode set to 100644
File size: 633 bytes
Line 
1data S = S { i::Int, d::Double }
2data Foo = A Int | B Double | C S
3
4foo = A 3;
5bar = B 3.5
6baz = C S{ i = 7, d = 7.5 }
7
8prtfoo val =
9 -- pattern match on constructor
10 case val of
11 A a -> print a
12 B b -> print b
13 C (S i d) -> do
14 print i
15 print d
16
17data Bar = X Int | Y Int | Z Int;
18prtbar val =
19 -- pattern match on constructor
20 case val of
21 X x -> print x
22 Y y -> print y
23 Z z -> print z
24
25foo2 = X 3;
26bar2 = Y 4;
27baz2 = Z 5;
28
29main = do
30 prtfoo foo
31 prtfoo bar
32 prtfoo baz
33 prtbar foo2
34 prtbar bar2
35 prtbar baz2
36
37-- Local Variables: --
38-- compile-command: "ghc test.hs; ./test" --
39-- End: --
Note: See TracBrowser for help on using the repository browser.