<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Balu.&nbsp; It looks like you've gotten some excellent advice from
others, but permit me to add a further comment regarding the broader
context, now that I've had a chance to look a little closer.<br>
<br>
It looks like you're trying to solve the "fractal snowflake" exercise.&nbsp;
One of the challenges in programming with numbers is deciding what
representation to use.&nbsp; Ints are great because they are efficient, but
if you need to use trigonometric functions such as sine, etc. then you
need Floats or Doubles.&nbsp; The problem here is that you need both -- you
need Ints because polygon is defined in terms of pixels, which are
represented as Ints, and you need Floats because you need to compute
the coordinates of an equilateral triangle, which (interestingly) can't
be represented using integer coordinates.&nbsp; But also, in the case of the
snowflake fractal, you will need to scale the size as you recurse.&nbsp; The
reason that the latter is important is that it implies that the
arguments to equilateralTri should perhaps be floats -- otherwise you
will once again run into numeric conversion problems as you try to
scale the arguments (unless you always start with a pixel size that is
a multiple of six).<br>
<br>
So -- I would still suggest using Window -&gt; Float -&gt; Float -&gt;
Float -&gt; IO() as the type for equilateralTri.&nbsp; It's only when you
make the call to polygon that you need Ints.&nbsp; And there you can just
use "round" to convert the Floats to Ints.<br>
<br>
As an aside, looking at your code a bit closer, I see this:<br>
<br>
&nbsp;&nbsp;&nbsp; (polygon [(x,y),(a,b),(x,y)]))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = y + side * sin(pi/3)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = x + side * cos(pi/3)&nbsp;<br>
<br>
Something is not right here -- you repeat (x,y) as a vertex.&nbsp; Probably
the third vertex should be (x+side,y).&nbsp; Also, note that sin (pi/3) and
cos (pi/3) are constants (namely 0.866... and 0.5, resp.).<br>
<br>
I hope this helps,<br>
<br>
&nbsp;&nbsp;&nbsp; -Paul<br>
<br>
<br>
Balu Raman wrote:
<blockquote
 cite="mid48f668e30706270837iee253d2sd7246f567e3a3b3d@mail.gmail.com"
 type="cite">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 -&gt; Float -&gt; Float
-&gt; Float -&gt; 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) =&gt; a -&gt; b<br>
round :: (RealFrac a, Integral b) =&gt; a-&gt;b<br>
Is it proper/ok to defines them as :<br>
fromIntegral :: (a::Integral) -&gt; (b::Num)<br>
and<br>
round :: (a::RealFrac) -&gt; (b::Integral)&nbsp; ?
  <br>
Is RealFrac is-a Num ?<br>
Does the order matters in (Num b,Integral a) =&gt; a -&gt; b or<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (Integral a,Num b) =&gt; a
-&gt; 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> &lt;<a href="mailto:bf3@telenet.be">bf3@telenet.be</a>&gt;
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 -&gt; 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 -&gt; IO()
    <br>
spaceClose w = do k &lt;- getKey w<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if k == ' ' then closeWindow w<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)<br>
    <br>
all of the above in file triangle.hs<br>
when I do a :l triangle.h in ghci,&nbsp;&nbsp;I get the following error<br>
triangle.hs:17:36:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;No instance for (Floating Int)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arising from use of 'pi' at triangle.hs:17:36-37<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Probable fix: add an instance declaration for (Floating Int)
    <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;In the first argument of '(/)', namely 'pi'<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;In the first argument of 'cos', namely '(pi / 3)'<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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>
  </blockquote>
  </div>
</blockquote>
<br>
</body>
</html>