[Haskell-cafe] Mis-understanding something in Haskell
interpretation
J. Garrett Morris
trevion at gmail.com
Tue Oct 3 13:57:06 EDT 2006
On 10/3/06, Edward Ing <inge at ihitacow.com> wrote:
> The source is below. Side is types as Float. My assumption was that
> Haskell would know how to convert the Int to a float and all would be
> well. I am I mistaken somewhere? The problem is with the last line.
Yes - Haskell does not automatically promote numeric types. In this
case, the following code compiles:
vertex :: Vertex -> Int -> Int -> Side -> Vertex
vertex (a ,b) currentSide totalSides length =
let angle = (360 / fromIntegral totalSides) * fromIntegral
currentSide in
( a + ( length * (sin angle)), b + ( (*) (cos angle) length ) )
although I'm not sure it's exactly what you want.
/g
More information about the Haskell-Cafe
mailing list