[Haskell-cafe] Having typing problem with "tan" function.
inge at ihitacow.com
Thu Oct 12 20:22:48 EDT 2006
I am new to Haskell, so the following problem is probably easy for you to spot but difficult for me.
Any pointers would be appreciated.
In GHCI on a load I am getting the following message:
No instance for (Floating Int)
arising from use of `pi' at Snowflake.hs:41:45-46
Probable fix: add an instance declaration for (Floating Int)
In the first argument of `(/)', namely `pi'
In the first argument of `tan', namely `(pi / 3)'
In the second argument of `(*)', namely `(tan (pi / 3))'
Failed, modules loaded: none.
When I put the expression "tan ( pi / 3)" at the GHCI interpreter prompt I get a value, but this is not accepted on a load the code.
Here is the code:
triangle :: Window -> (Point,Point) -> Int -> IO ()
triangle window ((x1,y1), (x2,y2)) size =
let height = fromIntegral(y2 - y1) * 3 / 2
halfWidth = height * (tan (pi / 3 )) in
drawInWindow window (withColor (sizeColorMap size)
(polygon [(x1,y1),( x1 - halfWidth, height ), (x1 + halfWidth, height)] ))
More information about the Haskell-Cafe