<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>
&nbsp;<BR>
I found&nbsp;a really&nbsp;strange&nbsp;case&nbsp;where GHC and GHCi behave differently in inferring types. It took me hours to figure this out.<BR>
&nbsp;<BR>
The following program<BR>
&nbsp;<BR>
{-# LANGUAGE NoMonomorphismRestriction #-}<BR>g x i = x ++ show i<BR>[a,b] = map g ["X","Y"]<BR>
&nbsp;<BR>
will not load without "NoMonomorphismRestriction".&nbsp;With that option,&nbsp;it will&nbsp;load and&nbsp;return the correct types (as expected):<BR>
*Main&gt; :t [a,b]<BR>[a,b] :: Show a =&gt; [a -&gt; [Char]]<BR>
&nbsp;<BR>
*Main&gt; a 1<BR>"X1"<BR>
&nbsp;<BR>
However, if I do the same thing GHCi, the type inferencing seems to have been messed up:<BR>
&nbsp;<BR>
*Main&gt; let g x i = x ++ show i<BR>*Main&gt; let [a,b] = map g ["X","Y"]<BR>*Main&gt; :t [a,b]<BR>[a,b] :: [() -&gt; [Char]]<BR>
*Main&gt; :t map g ["X","Y"]<BR>map g ["X","Y"] :: Show a =&gt; [a -&gt; [Char]]<BR>
&nbsp;<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>
&nbsp;<BR>
*Main&gt; a 1<BR>
&lt;interactive&gt;:52:3:<BR>&nbsp;&nbsp;&nbsp; No instance for (Num ())<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arising from the literal `1'<BR>&nbsp;&nbsp;&nbsp; Possible fix: add an instance declaration for (Num ())<BR>&nbsp;&nbsp;&nbsp; In the first argument of `a', namely `1'<BR>&nbsp;&nbsp;&nbsp; In the expression: a 1<BR>&nbsp;&nbsp;&nbsp; In an equation for `it': it = a 1<BR>
&nbsp;<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>
&nbsp;<BR>
Thanks in advance,<BR>
&nbsp;<BR>
Ting<BR>
&nbsp;<BR>                                               </div></body>
</html>