
Eric: Thanks a lot for explaining the issue. That's very helpful. Kind of a newbie question, how can I automatically turn on NoMonomorphismRestriction using emacs mode for haskell? I know there is the :set command, but I don't want to do it every time I start up emacs. In my humble opinion, I think the GHC should turn on ExtendedDefaulting if GHCi has it on by default. Otherwise it is confusing for newbies. Also, the defaulting is a kind of wierd and arbitrary behavior as I see it. In the case I showed, it gives unintuivive (or even errorneous) behavior. A function that can be applied now suddenly causes type mismatches. Isn't it a good thing in Haskell that if you get the type right, you get a big portition your program right? If turning on ExtendedDefaulting causes too much trouble, maybe then GHC should turn it off by default in both GHI and GHCi. In either case, I think the two should be consistent. Thanks again for help, Ting
From: hesselink@gmail.com Date: Sun, 15 Apr 2012 22:45:47 +0200 Subject: Re: [Haskell-cafe] strange GHCi type inference behavior involving map and partially applied functions To: tinlyx@hotmail.com CC: haskell-cafe@haskell.org
GHCi is defaulting the 'a' in 'Show a' to unit because of the extended defaulting feature [1] in GHCi. If you turn on NoMonomorphismRestriction in GHCi, you get the same behavior as in GHC. If you turn on ExtendedDefaulting in GHC, you get the same behavior as in GHCi.
Erik
[1] http://www.haskell.org/ghc/docs/latest/html/users_guide/interactive-evaluati...
On Sun, Apr 15, 2012 at 22:31, Ting Lei
wrote: Hi All,
I found a really strange case where GHC and GHCi behave differently in inferring types. It took me hours to figure this out.
The following program
{-# LANGUAGE NoMonomorphismRestriction #-} g x i = x ++ show i [a,b] = map g ["X","Y"]
will not load without "NoMonomorphismRestriction". With that option, it will load and return the correct types (as expected): *Main> :t [a,b] [a,b] :: Show a => [a -> [Char]]
*Main> a 1 "X1"
However, if I do the same thing GHCi, the type inferencing seems to have been messed up:
*Main> let g x i = x ++ show i *Main> let [a,b] = map g ["X","Y"] *Main> :t [a,b] [a,b] :: [() -> [Char]] *Main> :t map g ["X","Y"] map g ["X","Y"] :: Show a => [a -> [Char]]
Note how in the last two instances the terms on the left and right-hand sides of the definition return different types. Also, the correct return type should be a list of unary functions taking an (Show a) as the parameter. Now the result is unusable:
*Main> a 1 <interactive>:52:3: No instance for (Num ()) arising from the literal `1' Possible fix: add an instance declaration for (Num ()) In the first argument of `a', namely `1' In the expression: a 1 In an equation for `it': it = a 1
I am using GHCi 7.4.1 under windows. I also tried this under GHC 7.0x Is this a GHCi bug or could anyone please explain why this can of strange behavior happens? If this is a bug, could anyone with an account help file a bug for this?
Thanks in advance,
Ting
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe