<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
Hi All,<BR>
<BR>
I found a really strange case where GHC and GHCi behave differently in inferring types. It took me hours to figure this out.<BR>
<BR>
The following program<BR>
<BR>
{-# LANGUAGE NoMonomorphismRestriction #-}<BR>g x i = x ++ show i<BR>[a,b] = map g ["X","Y"]<BR>
<BR>
will not load without "NoMonomorphismRestriction". With that option, it will load and return the correct types (as expected):<BR>
*Main> :t [a,b]<BR>[a,b] :: Show a => [a -> [Char]]<BR>
<BR>
*Main> a 1<BR>"X1"<BR>
<BR>
However, if I do the same thing GHCi, the type inferencing seems to have been messed up:<BR>
<BR>
*Main> let g x i = x ++ show i<BR>*Main> let [a,b] = map g ["X","Y"]<BR>*Main> :t [a,b]<BR>[a,b] :: [() -> [Char]]<BR>
*Main> :t map g ["X","Y"]<BR>map g ["X","Y"] :: Show a => [a -> [Char]]<BR>
<BR>
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 <BR>
the parameter. Now the result is unusable:<BR>
<BR>
*Main> a 1<BR>
<interactive>:52:3:<BR> No instance for (Num ())<BR> arising from the literal `1'<BR> Possible fix: add an instance declaration for (Num ())<BR> In the first argument of `a', namely `1'<BR> In the expression: a 1<BR> In an equation for `it': it = a 1<BR>
<BR>
I am using GHCi 7.4.1 under windows. I also tried this under GHC 7.0x<BR>
Is this a GHCi bug or could anyone please explain why this can of strange behavior happens?<BR>
If this is a bug, could anyone with an account help file a bug for this?<BR>
<BR>
Thanks in advance,<BR>
<BR>
Ting<BR>
<BR>                                            </div></body>
</html>