source:
doc/theses/jiada_liang_MMath/test.hs@
9ae4f5f
| Last change on this file since 9ae4f5f was 1725989, checked in by , 17 months ago | |
|---|---|
|
|
| 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.