[Haskell-cafe] Ord type on lists

Lloyd Smith lloyd.g.smith at gmail.com
Sat Apr 2 22:04:03 EST 2005


On Apr 2, 2005 4:12 PM, Lemmih <lemmih at gmail.com> wrote:
> <=), (>) and (>=) are defined using 'compare', not (<). Write
> 'compare' yourself and everything will be good.
> But why don't you just derive Eq and Ord for List?
I didn't even think of doing that. So I will say I did this way for
pedagogical reasons :-)


On Apr 2, 2005 4:35 PM, Claus Reinke <claus.reinke at talk21.com> wrote:
> > Hi everyone, I defined my own list datatype and then tried to declare
> > it as an instance of type class Ord. However when I test it with
> >
> > Nil > Cons 1(Nil)
> > I get an "ERROR - Control stack overflow"
> >
> > I am under the impression that the ord class defines default
> > implementations of (<=), (>),(>=) so that I only have to supply the
> > implementation of (<) shown below. Can some one tell me why this does
> > not work the way I expect it to?
> 
> Now, whereever did that interpretation come from?-)

Page 32 of Introduction to Functional Programming using Haskell. I
guess thats what I deserve for trusting a dead trees :-)

> 
> The library docs are pretty clear about what constitutes a minimal definition:
> 
> http://www.haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t%3AOrd
> 
> Have a closer look at Ord and its default definitions to see what happens in
> your case:
> 
> http://www.haskell.org/onlinereport/basic.html#sect6.3.2
> 
> hth,
> claus
> 

Thanks for the pointers to the documentation. 

-- 
Lloyd G Smith


More information about the Haskell-Cafe mailing list