assignment1 added
[ap2015.git] / a1 / mart / skeleton1.icl
1 module skeleton1
2
3 /*
4 Course I00032 Advanced Programming 2014
5 Skeleton for assignment 1
6 Pieter Koopman
7 */
8
9 import StdEnv
10
11 /**************** Prelude: *******************************/
12 // Example types
13 :: Color = Red | Yellow | Blue
14 :: Tree a = Tip | Bin a (Tree a) (Tree a)
15 :: Rose a = Rose a [Rose a]
16
17 // Binary sums and products (in generic prelude)
18 :: UNIT = UNIT
19 :: PAIR a b = PAIR a b
20 :: EITHER a b = LEFT a | RIGHT b
21
22 // Generic type representations
23 :: RoseG a :== PAIR a [Rose a]
24
25 // Conversions
26 fromRose :: (Rose a) -> RoseG a
27 fromRose (Rose a l) = PAIR a l
28
29 // Oerdering
30
31 :: Ordering = Smaller | Equal | Bigger
32
33 class (><) infix 4 a :: !a !a -> Ordering
34
35 instance >< Int where // Standard ordering for Int
36 (><) x y
37 | x < y = Smaller
38 | x > y = Bigger
39 | otherwise = Equal
40
41 instance >< Char where // Standard ordering for Char
42 (><) x y
43 | x < y = Smaller
44 | x > y = Bigger
45 | otherwise = Equal
46
47 instance >< String where // Standard lexicographical ordering
48 (><) x y
49 | x < y = Smaller
50 | x > y = Bigger
51 | otherwise = Equal
52
53 instance >< Bool where // False is smaller than True
54 (><) False True = Smaller
55 (><) True False = Bigger
56 (><) _ _ = Equal
57
58 /**************** End Prelude *************************/