<div dir="ltr"><div><div>I seem to making a mess of it, first accidentally posting an empty message and then forgetting to reply to the list. Thirdly I forgot to mention that my message only describes the &#39;GHCi magic&#39;.<br>
<br></div>Lars<br><br></div>P.S. Conclusion, I shouldn&#39;t write complicated email this late on the evening.<div><div><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">L Corbijn</b> <span dir="ltr">&lt;<a href="mailto:aspergesoepje@gmail.com">aspergesoepje@gmail.com</a>&gt;</span><br>
Date: Mon, Jun 17, 2013 at 12:07 AM<br>Subject: Re: [Haskell-cafe] opengl type confusion<br>To: <a href="mailto:briand@aracnet.com">briand@aracnet.com</a><br><br><br><div dir="ltr"><div class="gmail_extra"><div><div class="h5">
<div class="gmail_quote">On Sun, Jun 16, 2013 at 11:10 PM, L Corbijn <span dir="ltr">&lt;<a href="mailto:aspergesoepje@gmail.com" target="_blank">aspergesoepje@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><div dir="ltr"><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Sun, Jun 16, 2013 at 10:42 PM,  <span dir="ltr">&lt;<a href="mailto:briand@aracnet.com" target="_blank">briand@aracnet.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>On Sun, 16 Jun 2013 16:15:25 -0400<br>
Brandon Allbery &lt;<a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a>&gt; wrote:<br>
<br>
&gt; On Sun, Jun 16, 2013 at 4:03 PM, &lt;<a href="mailto:briand@aracnet.com" target="_blank">briand@aracnet.com</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; Changing the declaration to GLdouble -&gt; GLdouble -&gt; GLdouble -&gt; IO() and<br>
&gt; &gt; using<br>
&gt; &gt; (0.0::GLdouble) fixes it, and I&#39;m not clear on why it&#39;s not automagic.<br>
&gt; &gt;  There are many times I see the<br>
&gt;<br>
&gt;<br>
&gt; Haskell never &quot;automagic&quot;s types in that context; if it expects GLdouble,<br>
&gt; it expects GLdouble. Pretending it&#39;s Double will not work. It &quot;would&quot; in<br>
&gt; the specific case that GLdouble were actually a type synonym for Double;<br>
&gt; however, for performance reasons it is not. Haskell Double is not directly<br>
&gt; usable from the C-based API used by OpenGL, so GLdouble is a type synonym<br>
&gt; for CDouble which is.<br>
&gt;<br>
&gt; compiler doing type conversion an numerican arguments although sometimes<br>
&gt; &gt; the occasional fracSomethingIntegralorOther is required.<br>
&gt; &gt;<br>
&gt;<br>
&gt; I presume the reason the type specification for numeric literals is because<br>
&gt; there is no defaulting (and probably can&#39;t be without introducing other<br>
&gt; strange type issues) for GLdouble.<br>
&gt;<br>
<br>
</div>What I was thinking about, using a very poor choice of words, was this :<br>
<br>
<br>
*Main&gt; let a = 1<br>
*Main&gt; :t a<br>
a :: Integer<br>
*Main&gt; let a = 1::Double<br>
*Main&gt; a<br>
1.0<br>
*Main&gt; :t a<br>
a :: Double<br>
*Main&gt;<br>
<br>
so normally 1 would be interpreted as an int, but if I declare &#39;a&#39; a 
Double then it gets &quot;promoted&quot; to a Double without me having to call a 
conversion routine explicitly.<br>
<br>
That seems automagic to me.<br>
<br>
(0.0::GLdouble) works to make the compiler happy.  So it appears to be taking care of the conversion automagically.<br>
<br>
So maybe a better question, I hope, is:<br>
<br>
How can I simply declare 0.0 to be (0.0::GLdouble) and have the 
functional call work.  Doesn&#39;t a conversion have to be happening, i.e. 
shouldn&#39;t I really have to do (realToFrac 0.0) ?<br>
<div><div><br>
Brian<br>
<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>Oops sorry for the empty reply, I accidentally hit the sent button. </div><div class="gmail_extra"><br></div><div class="gmail_extra">What you are seeing is the defaulting (see <a href="http://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-790004.3.4" target="_blank">http://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-790004.3.4</a>).
 Which roughly speaking means that if you need a specific instance of a 
number first try Integer then Double and as a last resort fail.<br>
<br><div class="gmail_extra">Prelude&gt; :t 1<br>1 :: Num a =&gt; a<br></div>Prelude&gt; :t 1.0<br>1.0 :: Fractional a =&gt; a<br><br></div><div class="gmail_extra">So normally a number can be just any instance of the Num class, and any 
number with a decimal can be any Fractional instance. And now with let 
bindings<br><br></div><div class="gmail_extra"><br>The need for defaulting is caused by the monomorphism restriction (<a href="http://www.haskell.org/haskellwiki/Monomorphism_restriction" target="_blank">http://www.haskell.org/haskellwiki/Monomorphism_restriction</a>),
 which states that let binds should be monomorphic, or roughly speaking 
it should contain no type variables (unless of course you provide a type
 signature).<br>
<br>Prelude&gt; let b = 1<br>Prelude&gt; :t b<br>b :: Integer<br><br>Prelude&gt; let c = 1.0<br>Prelude&gt; :t c<br>c :: Double<br><br></div>So
 here you see the result of the combination. The monomorphism 
restriction doesn&#39;t allow &#39;Num a =&gt; a&#39; as type for &#39;b&#39;. So the 
defaulting kicks in and finds that its first guess &#39;Integer&#39; fits. 
Therefore &#39;b&#39;  gets type Integer. Though for &#39;c&#39; the guess &#39;Integer&#39; 
fails as it isn&#39;t a Fractional. Its second guess, Double, is a 
fractional so &#39;c&#39; gets type Double.<br>
<div><br><div class="gmail_extra">You can see that the monomorphism restriction is to blame by disabling it<br></div><div class="gmail_extra"><br>Prelude&gt; :set -XNoMonomorphismRestriction<br>
Prelude&gt; let b = 1<br>Prelude&gt; :t b<br>b :: Num a =&gt; a<br><br></div><div class="gmail_extra">But you shouldn&#39;t normally need to do this, as you can provide a specific type signature.<br><br></div><div class="gmail_extra">

(in a fresh GHCi session)<br>Prelude&gt; let {b :: Num a =&gt; a; b = 1}<br>Prelude&gt; :t b<br>b :: Num a =&gt; a<br><br></div></div></div>
</div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Jun 16, 2013 at 10:42 PM,  <span dir="ltr">&lt;<a href="mailto:briand@aracnet.com" target="_blank">briand@aracnet.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Sun, 16 Jun 2013 16:15:25 -0400<br>
Brandon Allbery &lt;<a href="mailto:allbery.b@gmail.com">allbery.b@gmail.com</a>&gt; wrote:<br>
<br>
&gt; On Sun, Jun 16, 2013 at 4:03 PM, &lt;<a href="mailto:briand@aracnet.com">briand@aracnet.com</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; Changing the declaration to GLdouble -&gt; GLdouble -&gt; GLdouble -&gt; IO() and<br>
&gt; &gt; using<br>
&gt; &gt; (0.0::GLdouble) fixes it, and I&#39;m not clear on why it&#39;s not automagic.<br>
&gt; &gt;  There are many times I see the<br>
&gt;<br>
&gt;<br>
&gt; Haskell never &quot;automagic&quot;s types in that context; if it expects GLdouble,<br>
&gt; it expects GLdouble. Pretending it&#39;s Double will not work. It &quot;would&quot; in<br>
&gt; the specific case that GLdouble were actually a type synonym for Double;<br>
&gt; however, for performance reasons it is not. Haskell Double is not directly<br>
&gt; usable from the C-based API used by OpenGL, so GLdouble is a type synonym<br>
&gt; for CDouble which is.<br>
&gt;<br>
&gt; compiler doing type conversion an numerican arguments although sometimes<br>
&gt; &gt; the occasional fracSomethingIntegralorOther is required.<br>
&gt; &gt;<br>
&gt;<br>
&gt; I presume the reason the type specification for numeric literals is because<br>
&gt; there is no defaulting (and probably can&#39;t be without introducing other<br>
&gt; strange type issues) for GLdouble.<br>
&gt;<br>
<br>
</div>What I was thinking about, using a very poor choice of words, was this :<br>
<br>
<br>
*Main&gt; let a = 1<br>
*Main&gt; :t a<br>
a :: Integer<br>
*Main&gt; let a = 1::Double<br>
*Main&gt; a<br>
1.0<br>
*Main&gt; :t a<br>
a :: Double<br>
*Main&gt;<br>
<br>
so normally 1 would be interpreted as an int, but if I declare &#39;a&#39; a Double then it gets &quot;promoted&quot; to a Double without me having to call a conversion routine explicitly.<br>
<br>
That seems automagic to me.<br>
<br>
(0.0::GLdouble) works to make the compiler happy.  So it appears to be taking care of the conversion automagically.<br>
<br>
So maybe a better question, I hope, is:<br>
<br>
How can I simply declare 0.0 to be (0.0::GLdouble) and have the functional call work.  Doesn&#39;t a conversion have to be happening, i.e. shouldn&#39;t I really have to do (realToFrac 0.0) ?<br>
<div class="HOEnZb"><div class="h5"><br>
Brian<br>
<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br></div>