<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:p="urn:schemas-microsoft-com:office:powerpoint" xmlns:a="urn:schemas-microsoft-com:office:access" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" xmlns:b="urn:schemas-microsoft-com:office:publisher" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:oa="urn:schemas-microsoft-com:office:activation" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:q="http://schemas.xmlsoap.org/soap/envelope/" xmlns:D="DAV:" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:ois="http://schemas.microsoft.com/sharepoint/soap/ois/" xmlns:dir="http://schemas.microsoft.com/sharepoint/soap/directory/" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" xmlns:udc="http://schemas.microsoft.com/data/udc" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sps="http://schemas.microsoft.com/sharepoint/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:udcxf="http://schemas.microsoft.com/data/udc/xmlfile" xmlns:wf="http://schemas.microsoft.com/sharepoint/soap/workflow/" xmlns:mver="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns:mrels="http://schemas.openxmlformats.org/package/2006/relationships" xmlns:ex12t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.gmailquote
        {mso-style-name:gmail_quote;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Newbie helping newbie, cool </span><span style='font-size:11.0pt;
font-family:Wingdings;color:#1F497D'>J</span><span style='font-size:11.0pt;
font-family:"Calibri","sans-serif";color:#1F497D'> And indeed, this is an
amazing mailing list!<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Personally, I prefer to read </span>fromIntegral :: (Num b,
Integral a) => a -> b<span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> like<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>IF</span></b><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> (b is a Num) <b>AND</b> (a is an Integral) <b>THEN</b> (fromIntegral
is defined and is a function from a to b)<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>This way it resembles the mathematical symbol for implication (=>)<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>PS: Haskells “generic number system” can be very
confusing for the beginner, but it becomes very cool when you start working
with type classes. You will see that in the later chapters of the great SOE
book (animation and reactive behaviors). The reactive behavior chapter is
really hard, but don’t give up. In my case I got a real revelation,
finally understanding the real power of streams and lazy evaluation; it really
changes the way you look at the “world”… As a videogames
developer, I still have a lot of unanswered questions though (for example, how
to efficiently handle events between behaviors, like collision, but I hope to find
that in Yampa or newer work)<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] <b>On
Behalf Of </b>Balu Raman<br>
<b>Sent:</b> Wednesday, June 27, 2007 5:37 PM<br>
<b>To:</b> Haskell-Cafe@haskell.org<br>
<b>Subject:</b> Re: [Haskell-cafe] New New newbie question/help<o:p></o:p></span></p>
</div>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal style='margin-bottom:12.0pt'>I am for ever obliged to this
haskell community. Who would have thought that Prof.Hudak would reply
instantly, from on-the-road. I am reading his SOE. Thanks so much.<br>
<br>
I went with peterv's response after trying so many things. <br>
I tried to change to : equilateralTri Window -> Float -> Float ->
Float -> IO()<br>
which bombed because polygon wants list of integer-pairs.<br>
<br>
I read the definitions of fromIntegral and round and they are defined as : <br>
fromIntegral :: (Num b, Integral a) => a -> b<br>
round :: (RealFrac a, Integral b) => a->b<br>
Is it proper/ok to defines them as :<br>
fromIntegral :: (a::Integral) -> (b::Num)<br>
and<br>
round :: (a::RealFrac) -> (b::Integral) ? <br>
Is RealFrac is-a Num ?<br>
Does the order matters in (Num b,Integral a) => a -> b or<br>
(Integral a,Num b) => a -> b<br>
<br>
With your encouragements, I'll keep pluuging. Thanks. <br>
- br<o:p></o:p></p>
<div>
<p class=MsoNormal><span class=gmailquote>On 6/27/07, <b>peterv</b> <<a
href="mailto:bf3@telenet.be">bf3@telenet.be</a>> wrote:</span><o:p></o:p></p>
<p class=MsoNormal style='margin-bottom:12.0pt'>I'm also a haskell newbie, but
I'll try to help; the experts here will<br>
correct me if I'm wrong.<br>
<br>
The compiler cannot in all cases infer the type of a number. pi can be a<br>
Float, a Double, or even a complex number. <br>
<br>
Furthermore unlike in C/C++ you cannot just mix integer and floating<br>
operations.<br>
<br>
For example, the following works for me:<br>
<br>
f :: Int -> Int<br>
f side = round ( (fromIntegral side) * sin ( (pi::Float) / 3 ) ) <br>
<br>
or easier<br>
<br>
f side = round ( (fromIntegral side) * sin (pi / 3.0) )<br>
<br>
I'm sure the experts here will have a better solution.<br>
<br>
Peter<br>
-----Original Message-----<br>
From: <a href="mailto:haskell-cafe-bounces@haskell.org">haskell-cafe-bounces@haskell.org</a><br>
[mailto:<a href="mailto:haskell-cafe-bounces@haskell.org">haskell-cafe-bounces@haskell.org</a>]
On Behalf Of Balu Raman<br>
Sent: Wednesday, June 27, 2007 1:25 PM<br>
To: <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
Subject: [Haskell-cafe] New New newbie question/help<br>
<br>
Hi,<br>
Hope someone can help me, just starting out with SOE.My code :<br>
module Main where<br>
import Graphics.SOE.Gtk<br>
<br>
spaceClose :: WIndow -> IO() <br>
spaceClose w = do k <- getKey w<br>
if k == ' ' then closeWindow w<br>
else spaceClose w<br>
<br>
equilateralTri :: Window -> Int -> Int -> Int -> IO() <br>
equilateralTri w x y side<br>
= drawInWindow w (withColor Red<br>
(polygon<br>
[(x,y),(a,b),(x,y)]))<br>
where<br>
b
= y + side * sin(pi/3)<br>
a
= x + side * cos(pi/3)<br>
main =<br>
runGraphics(<br>
do
w <- openWindow "Equilateral<br>
Triangle" (400,400) <br>
equilateralTri
w 50 300 200<br>
spaceClose
w<br>
)<br>
<br>
all of the above in file triangle.hs<br>
when I do a :l triangle.h in ghci, I get the following error<br>
triangle.hs:17:36:<br>
No instance for (Floating Int)<br>
arising from use of 'pi' at triangle.hs:17:36-37<br>
Probable fix: add an instance
declaration for (Floating Int) <br>
In the first argument of '(/)',
namely 'pi'<br>
In the first argument of 'cos',
namely '(pi / 3)'<br>
In the second argument of
'(*)', namely 'cos (pi/3)' <br>
Failed, modules loaded: none<br>
<br>
Can someone help me what's going on to a brand new newbie. All I can<br>
figure out is that some type mismatch between float and int . I tried<br>
various<br>
combinations of lets and wheres and I still get the same complaints. <br>
I am just linearly studying SOE<br>
Thanks,<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">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><o:p></o:p></p>
</div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
</body>
</html>