module FridaySession5 where import Data.Maybe (fromJust,fromMaybe) import Prelude hiding (seq) mymap :: [(Int,[Int])] mymap = [(1, [3,4,2,5]), (2,[6,5]), (3,[2,4,5,1,6]) ] wrong :: Int wrong = length $ lookup 2 mymap correct :: Int correct = length list where (Just list) = lookup 2 mymap correct2 :: Int correct2 = length (fromMaybe (error "Not found.") $ lookup 2 mymap) correct3 :: Int correct3 = length (fromJust $ lookup 2 mymap) data UnOrdPair a = Pair (a,a) instance (Show a, Ord a) => Show (UnOrdPair a) where show (Pair (x,y)) | x <= y = "Pair (" ++ show x ++ "," ++ show y ++ ")" | otherwise = "Pair (" ++ show y ++ "," ++ show x ++ ")" instance Ord a => Eq (UnOrdPair a) where (==) (Pair (x1,y1)) (Pair (x2,y2)) = (x1==x2 && y1 == y2) || (x1==y2 && y1 == x2)