int to float problem

Wang Meng wangmeng@comp.nus.edu.sg
Sat, 1 Mar 2003 03:59:53 +0800 (GMT-8)


Try 

intToFloat :: Int -> Float
intToFloat n = fromInteger (toInteger n)
  
 -W-M-
  @ @  
   |
  \_/   

On Fri, 28 Feb 2003, Mike T. Machenry wrote:

> Hello,
> 
>   I am having a problem. I recently desided I wanted a bunch function to return
> float instead of Int. I changed their type and wrote a new function that
> returned a float. I figured it'd be okay if all the others still returned
> Int since it's trivial to convert Int to Float. Sadly Haskell won't let me do
> this. What should I do? I attempted to cast all of the values in the functions
> that returned Int to Float, but I found no way to do this. I found fromInteger
> but it didn't seem to work on the return value of the cardinality function for
> instance. I guess cardinality much return Int. This is one of my functions.
> 
> smallestSet :: GameState -> Float
> smallestSet s = (-1 * cardinality (fLocations s))
> 
> This function is an error because it infer's an Int.
> 
> Thanks,
> -mike
> _______________________________________________
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>