<div dir="ltr">Thank you, my head's spinning just starting to read [1] :)<div><br></div><div>BTW, you led me to find the answer to why ghci was different in the</div><div>interactive mode vs loading. I discovered there are two sets of options</div><div>used for ghci which are controlled by ":set" and ":seti", [2]. And in the</div><div>interactive mode we see -XNoMonomorphismRestriction is in effect:</div><div><br></div><div><div>Prelude> :seti</div><div>base language is: Haskell2010</div><div>with the following modifiers:</div><div> -XExtendedDefaultRules</div><div> -XNoMonomorphismRestriction</div><div> -XNondecreasingIndentation</div><div>GHCi-specific dynamic flag settings:</div><div>other dynamic, non-language, flag settings:</div><div> -fimplicit-import-qualified</div><div>warning settings:</div><div><br></div><div><br></div><div><div>But it's not in the "non-interactive" mode:</div><div><br></div><div><div>Prelude> :set</div><div>options currently set: none.</div><div>base language is: Haskell2010</div><div>with the following modifiers:</div><div> -XNondecreasingIndentation</div><div>GHCi-specific dynamic flag settings:</div><div>other dynamic, non-language, flag settings:</div><div> -fimplicit-import-qualified</div><div>warning settings:</div></div><div><br></div><div>[1]: <a href="https://wiki.haskell.org/Monomorphism_restriction">https://wiki.haskell.org/Monomorphism_restriction</a><br></div></div></div><div>[2]: <a href="https://downloads.haskell.org/~ghc/7.8.4/docs/html/users_guide/ghci-set.html">https://downloads.haskell.org/~ghc/7.8.4/docs/html/users_guide/ghci-set.html</a></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Oct 17, 2017 at 10:53 AM David McBride <<a href="mailto:toad3k@gmail.com">toad3k@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>It is because of NoMomomorphismRestriction<br><br>>let mTh4 = \x -> \y -> \z -> x * y * z</div></div><div dir="ltr"><div><br>>:t mTh4<br>mTh4 :: Integer -> Integer -> Integer -> Integer<br></div></div><div dir="ltr"><div>>:set -XNoMonomorphismRestriction <br>>let mTh4 = \x -> \y -> \z -> x * y * z</div></div><div dir="ltr"><div><br>>:t mTh4<br>mTh4 :: Num a => a -> a -> a -> a<br><br></div></div><div dir="ltr"><div></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"></div></div><div class="gmail_extra"><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></div></div><div class="gmail_extra"><div class="gmail_quote"><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="m_-6172431381477467222HOEnZb"><font color="#888888"><div><br></div><div><br></div><div>-- Wink</div><div><br></div></font></span></div>
<br></blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">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-bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">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-bin/mailman/listinfo/beginners</a><br>
</blockquote></div>