Question about Haskell types

I've been trying to get to the point with Haskell where I can write useful programs, and I've come across something I don't understand with the type system. I hope this is the right place to ask. I came up with the following list of declarations: a = (<) b x = (x <) c x y = (x < y) It turns out that 'a' is badly typed and gives an error at compile time. 'B' and 'c' are equivalent and have type "Ord a => a -> a -> Bool". What I don't understand is why 'a' doesn't behave the same way as the other two. Thanks for any help you can give me, and in the meantime I'll go back to relearning everything I thought I knew about programming. :-) Pete

Hi Pete,
a = (<) b x = (x <) c x y = (x < y)
I'm pretty sure this is the Monomorphism Restriction, its on the wiki at: http://www.haskell.org/hawiki/MonomorphismRestriction Thanks Neil

Neil Mitchell wrote:
Hi Pete,
a = (<) b x = (x <) c x y = (x < y)
I'm pretty sure this is the Monomorphism Restriction, its on the wiki at: http://www.haskell.org/hawiki/MonomorphismRestriction
You can use ghc -fno-monomorphism-restriction to compile the above or alternatively give a type signature for a ie a :: Ord p => p->p->Bool a = (<) Perhaps some later version of Haskell might get rid of this restriction by default (here's hoping! :-) ) Regards, Brian.
participants (3)
-
Brian Hulley
-
Neil Mitchell
-
Pete Chown