[Haskell-beginners] Ord [] instance

Keith Sheppard keithshep at gmail.com
Sat Oct 31 15:39:57 EDT 2009


the compare function for lists seems to be work like (leaving off
class details):

> compare [] [] = EQ
> compare [] _ = LT
> compare _ [] = GT
> compare (x:xt) (y:yt) = case x `compare` y of
>     EQ -> xt `compare` yt
>    _ -> x `compare` y

I poked around to see if I could find where this was defined in the
spec or if it was an implementation specific thing (I need to be able
to rely on this definition across implementations). I found this text
in the report:

-- Lists


data  [a]  =  [] | a : [a]  deriving (Eq, Ord)
-- Not legal Haskell; for illustration only

Is this basically saying the same thing as my compare definition?

Thanks
Keith

-- 
keithsheppard.name


More information about the Beginners mailing list