From: Mart Lubbers Date: Mon, 31 Aug 2015 14:11:40 +0000 (+0200) Subject: assignment1 added X-Git-Tag: assignment2~14 X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=fa6d15c516ae56b7257f4a01ba20d01468906043;p=ap2015.git assignment1 added --- diff --git a/a1/a1.pdf b/a1/a1.pdf new file mode 100644 index 0000000..725e3b8 Binary files /dev/null and b/a1/a1.pdf differ diff --git a/a1/mart/skeleton1.icl b/a1/mart/skeleton1.icl new file mode 100644 index 0000000..af8a628 --- /dev/null +++ b/a1/mart/skeleton1.icl @@ -0,0 +1,58 @@ +module skeleton1 + +/* + Course I00032 Advanced Programming 2014 + Skeleton for assignment 1 + Pieter Koopman +*/ + +import StdEnv + +/**************** Prelude: *******************************/ +// Example types +:: Color = Red | Yellow | Blue +:: Tree a = Tip | Bin a (Tree a) (Tree a) +:: Rose a = Rose a [Rose a] + +// Binary sums and products (in generic prelude) +:: UNIT = UNIT +:: PAIR a b = PAIR a b +:: EITHER a b = LEFT a | RIGHT b + +// Generic type representations +:: RoseG a :== PAIR a [Rose a] + +// Conversions +fromRose :: (Rose a) -> RoseG a +fromRose (Rose a l) = PAIR a l + +// Oerdering + +:: Ordering = Smaller | Equal | Bigger + +class (><) infix 4 a :: !a !a -> Ordering + +instance >< Int where // Standard ordering for Int + (><) x y + | x < y = Smaller + | x > y = Bigger + | otherwise = Equal + +instance >< Char where // Standard ordering for Char + (><) x y + | x < y = Smaller + | x > y = Bigger + | otherwise = Equal + +instance >< String where // Standard lexicographical ordering + (><) x y + | x < y = Smaller + | x > y = Bigger + | otherwise = Equal + +instance >< Bool where // False is smaller than True + (><) False True = Smaller + (><) True False = Bigger + (><) _ _ = Equal + +/**************** End Prelude *************************/