<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'>
Ketil,<BR>&nbsp;<BR>Thanks for the response.&nbsp;It seems that defining them as a pair&nbsp;only postphones the error.<BR>GHC will give an error when you extract the components of the pair, no matter whether you add<BR>the "NoMonomorphismRestriction" flag or not.<BR>&nbsp;<BR>--{-# LANGUAGE NoMonomorphismRestriction #-}<BR>p :: (Show a, Ord b) =&gt; (a -&gt; String, b -&gt; b -&gt; Bool)<br>p = (id . show, flip (&lt;))<BR>f1 = fst p<br>f2 = snd p<BR>-----------------------<BR>Without NoMonomorphismRestriction, I got:<BR><br>D:\work\test1.hs:6:10:<br>&nbsp;&nbsp;&nbsp; Ambiguous type variable `a0' in the constraint:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (Show a0) arising from a use of `p'<br>&nbsp;&nbsp;&nbsp; Possible cause: the monomorphism restriction applied to the following:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f1 :: a0 -&gt; String (bound at D:\work\hsOcaml\test1.hs:6:1)<br>&nbsp;&nbsp;&nbsp; Probable fix: give these definition(s) an explicit type signature<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or use -XNoMonomorphismRestriction<br>&nbsp;&nbsp;&nbsp; In the first argument of `fst', namely `p'<br>&nbsp;&nbsp;&nbsp; In the expression: fst p<br>&nbsp;&nbsp;&nbsp; In an equation for `f1': f1 = fst p<BR>D:\work\hsOcaml\test1.hs:6:10:<br>&nbsp;&nbsp;&nbsp; Ambiguous type variable `b0' in the constraint:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (Ord b0) arising from a use of `p'<br>&nbsp;&nbsp;&nbsp; Probable fix: add a type signature that fixes these type variable(s)<br>......&nbsp;<BR>Failed, modules loaded: none.<BR>&nbsp;<BR>------------------<BR>With NoMonomorphismRestriction, I got:<BR>&nbsp;<BR><br>D:\work\test1.hs:6:10:<br>&nbsp;&nbsp;&nbsp; Ambiguous type variable `b0' in the constraint:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (Ord b0) arising from a use of `p'<br>&nbsp;&nbsp;&nbsp; Probable fix: add a type signature that fixes these type variable(s)<br>&nbsp;&nbsp;&nbsp; In the first argument of `fst', namely `p'<br>&nbsp;&nbsp;&nbsp; In the expression: fst p<br>&nbsp;&nbsp;&nbsp; In an equation for `f1': f1 = fst p<BR>D:\work\test1.hs:7:10:<br>&nbsp;&nbsp;&nbsp; Ambiguous type variable `a0' in the constraint:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (Show a0) arising from a use of `p'<br>&nbsp;&nbsp;&nbsp; Probable fix: add a type signature that fixes these type variable(s)<br>&nbsp;&nbsp;&nbsp; In the first argument of `snd', namely `p'<br>&nbsp;&nbsp;&nbsp; In the expression: snd p<br>&nbsp;&nbsp;&nbsp; In an equation for `f2': f2 = snd p<br>Failed, modules loaded: none.<BR>&nbsp;<BR>&nbsp;<BR>Thanks,<BR><br>&nbsp;Ting<BR>&nbsp;<BR><div><div id="SkyDrivePlaceholder"></div>&gt; From: ketil@malde.org<br>&gt; To: tinlyx@hotmail.com<br>&gt; CC: haskell-cafe@haskell.org<br>&gt; Subject: Re: [Haskell-cafe] a code that cannot compile with or without NoMonomorphismRestriction<br>&gt; Date: Thu, 29 Mar 2012 12:27:04 +0200<br>&gt; <br>&gt; Ting Lei &lt;tinlyx@hotmail.com&gt; writes:<br>&gt; <br>&gt; &gt; (f1, f2) =<br>&gt; &gt;     let commond_definitions = undefined in<br>&gt; &gt;     let f1 = id.show <br>&gt; &gt;         f2 x = (&lt; x) <br>&gt; &gt;     in<br>&gt; &gt;       (f1, f2)<br>&gt; <br>&gt; I think the type signatures should be:<br>&gt; <br>&gt;   f1 :: Show a =&gt; a -&gt; String<br>&gt; <br>&gt; and <br>&gt; <br>&gt;   f2 :: Ord b =&gt; b -&gt; b -&gt; Bool <br>&gt; <br>&gt; When I define these separately, this works:<br>&gt; <br>&gt;   f1 :: Show a =&gt; a -&gt; String<br>&gt;   f1 = id . show<br>&gt; <br>&gt;   f2 :: Ord b =&gt; b -&gt; b -&gt; Bool <br>&gt;   f2 = flip (&lt;)<br>&gt; <br>&gt; <br>&gt; But when I define them as a pair<br>&gt; <br>&gt;   f1 :: Show a =&gt; a -&gt; String<br>&gt;   f2 :: Ord b =&gt; b -&gt; b -&gt; Bool <br>&gt;   (f1,f2) = (id . show, flip (&lt;))<br>&gt; <br>&gt; I get an error message:<br>&gt; <br>&gt; Line 9: 1 error(s), 0 warning(s)<br>&gt; <br>&gt; Couldn't match expected type `forall a. Show a =&gt; a -&gt; String'<br>&gt;             with actual type `a -&gt; String'<br>&gt; When checking that `f1'<br>&gt;   has the specified type `forall a1. Show a1 =&gt; a1 -&gt; String'<br>&gt; <br>&gt; Defining the pair at once works:<br>&gt; <br>&gt;   p :: (Show a, Ord b) =&gt; (a -&gt; String, b -&gt; b -&gt; Bool)<br>&gt;   p = (id . show, flip (&lt;))<br>&gt; <br>&gt; I guess that didn't help a lot, somebody with deeper GHC-fu than me will<br>&gt; have to step in.<br>&gt; <br>&gt; -k<br>&gt; -- <br>&gt; If I haven't seen further, it is by standing in the footprints of giants<br></div>                                               </div></body>
</html>