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<br><br><div><span class="gmail_quote">On 6/27/07, <b class="gmail_sendername">peterv</b> <<a href="mailto:bf3@telenet.be">bf3@telenet.be</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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><br><br></blockquote></div><br>