From: Mart Lubbers Date: Mon, 31 Aug 2015 18:06:42 +0000 (+0200) Subject: rose now works X-Git-Tag: assignment2~11 X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=319efa41e84489a7367e8595ecda5033d1033f5e;p=ap2015.git rose now works --- diff --git a/a1/mart/skeleton1.icl b/a1/mart/skeleton1.icl index bcb57fe..18dac9a 100644 --- a/a1/mart/skeleton1.icl +++ b/a1/mart/skeleton1.icl @@ -51,6 +51,10 @@ instance >< Bool where // False is smaller than True (><) _ _ = Equal /**************** End Prelude *************************/ +isEqual :: Ordering -> Bool +isEqual Equal = True +isEqual _ = False + // 1. Ordering by overloading instance >< Color where (><) Red Red = Equal @@ -61,35 +65,32 @@ instance >< Color where (><) Blue Blue = Equal (><) _ _ = Smaller -instance >< (Tree a) | >< a & == a where +instance >< (Tree a) | >< a where (><) Tip Tip = Equal (><) (Bin _ _ _) Tip = Bigger (><) Tip (Bin _ _ _) = Smaller (><) (Bin x ltx rtx) (Bin y lty rty) - | x == y = case ltx >< lty of - Equal = rtx >< rty - otherwise = ltx >< lty - | otherwise = x >< y - -instance >< (Rose a) | >< a & == a where - (><) (Rose _ _) (Rose _ []) = Bigger - (><) (Rose _ []) (Rose _ _) = Smaller - (><) (Rose x xs) (Rose y ys) - | x == y = xs >< ys + | isEqual (x >< y) + | isEqual (ltx >< lty) = rtx >< rty + | otherwise = ltx >< lty | otherwise = x >< y -instance >< [a] | Ord a & == a where +instance >< [a] | >< a where (><) [] [] = Equal (><) [] _ = Smaller (><) _ [] = Bigger (><) [x:xs] [y:ys] - | x == y = xs >< ys - | x < y = Smaller - | otherwise = Bigger + | isEqual (x >< y) = xs >< ys + | otherwise = x >< y + +instance >< (Rose a) | >< a where + (><) (Rose x xs) (Rose y ys) + | isEqual (x >< y) = xs >< ys + | otherwise = x >< y -instance >< (a, b) | >< a & >< b & == a where +instance >< (a, b) | >< a & >< b where (><) (xa, xb) (ya, yb) - | xa == ya = xb >< yb + | isEqual (xa >< ya) = xb >< yb | otherwise = xa >< ya //2. Generic representation