Inconsistencies in type inference

Hey, While trying to wrap my head around how type inference works in haskell I stumbled across the following inconsistency: If I type :t (*) in ghci, I obtain (*) :: Num a => a -> a -> a But if I write let mul = (*) :t mul I get the less generic type signature mul :: Integer -> Integer -> Integer How is this inconsistency explained? After all, I would expect the haskell compiler to deduce the most generic type possible. Thanks in advance, Stefan.

The monomorphism restriction forces ghci to infer a default type. Prelude> :set -XNoMonomorphismRestriction Prelude> let mul = (*) Prelude> :t mul mul :: Num a => a -> a -> a

I should add that it is recommended to disable the monomorphism restriction, by putting :set -XNoMonomorphismRestriction in your .ghci file. It has very dubious benefits and usually only serves to confuse. -Brent On Tue, Jun 25, 2013 at 01:36:26PM +0200, David Virebayre wrote:
The monomorphism restriction forces ghci to infer a default type.
Prelude> :set -XNoMonomorphismRestriction Prelude> let mul = (*) Prelude> :t mul mul :: Num a => a -> a -> a
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Am 6/25/2013 8:45 PM, schrieb Brent Yorgey:
I should add that it is recommended to disable the monomorphism restriction, by putting
:set -XNoMonomorphismRestriction
in your .ghci file. It has very dubious benefits and usually only serves to confuse.
Hm, this is interesting. To me, most of the extensions are in the "crazy stuff only the profesionalls use" category - I successfully tip-toed around them so far. :-) Are there other extensions which people would consider to be "generally good to have, unless you know a good reason *not* to enable them"? -- Frerich Raabe - raabe@froglogic.com www.froglogic.com - Multi-Platform GUI Testing

2013/6/26 Frerich Raabe
Are there other extensions which people would consider to be "generally good to have, unless you know a good reason *not* to enable them"?
I don't use the "crazy" stuff, but I find myself using often : - NoMonomorphismRestriction - OverloadedStrings - BangPatterns - GeneralizedNewtypeDeriving David.

On Wed, Jun 26, 2013 at 9:47 AM, Frerich Raabe
Am 6/25/2013 8:45 PM, schrieb Brent Yorgey:
I should add that it is recommended to disable the monomorphism
restriction, by putting
:set -XNoMonomorphismRestriction
in your .ghci file. It has very dubious benefits and usually only serves to confuse.
Hm, this is interesting. To me, most of the extensions are in the "crazy stuff only the profesionalls use" category - I successfully tip-toed around them so far. :-)
Are there other extensions which people would consider to be "generally good to have, unless you know a good reason *not* to enable them"?
There has been a question about that on stackoverflow which you might find interesting: http://stackoverflow.com/questions/10845179/which-haskell-ghc-extensions-sho... Ciao, Martin

On Wed, Jun 26, 2013 at 09:47:16AM +0200, Frerich Raabe wrote:
Am 6/25/2013 8:45 PM, schrieb Brent Yorgey:
I should add that it is recommended to disable the monomorphism restriction, by putting
:set -XNoMonomorphismRestriction
in your .ghci file. It has very dubious benefits and usually only serves to confuse.
Hm, this is interesting. To me, most of the extensions are in the "crazy stuff only the profesionalls use" category - I successfully tip-toed around them so far. :-)
Are there other extensions which people would consider to be "generally good to have, unless you know a good reason *not* to enable them"?
I don't know of any others in that category. But there are a few others which are quite innocuous and if the compiler ever suggests you might like to turn them on, you should not hesitate, in particular FlexibleInstances and FlexibleContexts. -Brent
participants (5)
-
Brent Yorgey
-
David Virebayre
-
Frerich Raabe
-
Martin Ruderer
-
Stefan Jaax