<div dir="ltr"><div>It is because of NoMomomorphismRestriction<br><br>>let mTh4 = \x -> \y -> \z -> x * y * z<br>>:t mTh4<br>mTh4 :: Integer -> Integer -> Integer -> Integer<br>>:set -XNoMonomorphismRestriction <br>>let mTh4 = \x -> \y -> \z -> x * y * z<br>>:t mTh4<br>mTh4 :: Num a => a -> a -> a -> a<br><br></div>I'm not going into it too deeply, as it is somewhat involved and you can read about it but I believe when a function "takes no arguments", it is allowed to specialize polymorphic variables to defaults, and due to the Num constraint it chooses Integer.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 17, 2017 at 1:28 PM, Wink Saville <span dir="ltr"><<a href="mailto:wink@saville.com" target="_blank">wink@saville.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm going through "Haskell Programming from first principles" and in section 7.3 Anonymous Functions there is an exercise on converting multiple parameters to anonymous functions, and it asks:<div><br></div><div>1. Which (two or more) of the following are equivalent?<br></div><div><br></div><div><div>mTh1 x y z = x * y * z</div><div>mTh2 x y = \z -> x * y * z</div><div>mTh3 x = \y -> \z -> x * y * z</div><div>mTh4 = \x -> \y -> \z -> x * y * z<br></div></div><div><br></div><div>So I created a file, anon.hs (attached):</div><div><br></div><div><div>module Anon where</div><div><br></div><div>mTh1 x y z = x * y * z</div><div>mTh2 x y = \z -> x * y * z</div><div>mTh3 x = \y -> \z -> x * y * z</div><div>mTh4 = \x -> \y -> \z -> x * y * z</div></div><div><br></div><div>I load that into ghci and check the function types:</div><div><br></div><div><div>$ ghci anon.hs </div><div>GHCi, version 8.2.1: <a href="http://www.haskell.org/ghc/" target="_blank">http://www.haskell.org/ghc/</a> :? for help</div><div>[1 of 1] Compiling Anon ( anon.hs, interpreted )</div><div>Ok, 1 module loaded.</div><div>*Anon> :t mTh1</div><div>mTh1 :: Num a => a -> a -> a -> a</div><div>*Anon> :t mTh2</div><div>mTh2 :: Num a => a -> a -> a -> a</div><div>*Anon> :t mTh3</div><div>mTh3 :: Num a => a -> a -> a -> a</div><div>*Anon> :t mTh4</div><div>mTh4 :: Integer -> Integer -> Integer -> Integer</div></div><div><br></div><div>Why is mTh4 different from the rest?</div><div><br></div><div><br></div><div>On the flip side If I enter "mTh4 = \x -> \y -> \z -> x * y * z" directly in ghci command line then it has same type as the others:</div><div><br></div><div><div>$ ghci</div><div>GHCi, version 8.2.1: <a href="http://www.haskell.org/ghc/" target="_blank">http://www.haskell.org/ghc/</a> :? for help</div><div>Prelude> mTh4 = \x -> \y -> \z -> x * y * z</div><div>Prelude> :t mTh4</div><div>mTh4 :: Num a => a -> a -> a -> a</div></div><span class="HOEnZb"><font color="#888888"><div><br></div><div><br></div><div>-- Wink</div><div><br></div></font></span></div>
<br>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>