Last change
on this file since 38f6e66 was
1725989,
checked in by Peter A. Buhr <pabuhr@…>, 5 months ago
|
add enumeration test programs for different programming languages
|
-
Property mode set to
100644
|
File size:
633 bytes
|
Line | |
---|
1 | data S = S { i::Int, d::Double } |
---|
2 | data Foo = A Int | B Double | C S |
---|
3 | |
---|
4 | foo = A 3; |
---|
5 | bar = B 3.5 |
---|
6 | baz = C S{ i = 7, d = 7.5 } |
---|
7 | |
---|
8 | prtfoo 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 | |
---|
17 | data Bar = X Int | Y Int | Z Int; |
---|
18 | prtbar 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 | |
---|
25 | foo2 = X 3; |
---|
26 | bar2 = Y 4; |
---|
27 | baz2 = Z 5; |
---|
28 | |
---|
29 | main = 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.