Question about Haskell types

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about Haskell types

Bugzilla from 1@234.cx
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

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Question about Haskell types

Neil Mitchell
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
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Question about Haskell types

Brian Hulley
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.

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe