reset password
Author Message
jgarc629
Posts: 76
Posted 16:56 Oct 18, 2018 |

Can anyone give an example of how to use the fromIntegral function. It is supposed to be defined as :: (Integer a, RealFloat b) => a -> b ?

Andy Echeverria
Posts: 11
Posted 17:35 Oct 18, 2018 |

fromIntegral is a function and it can be used like this:

fromIntegral parameter

If you declare an Int, x = 5, then if you do fromIntegral x, it will return a float of x.

It is used for conversion.

Last edited by Andy Echeverria at 17:44 Oct 18, 2018.
msargent
Posts: 519
Posted 17:51 Oct 18, 2018 |
jgarc629 wrote:

Can anyone give an example of how to use the fromIntegral function. It is supposed to be defined as :: (Integer a, RealFloat b) => a -> b ?

Note, Integer is not a typeclass, but a specific type, so you can't do (Integer a) => a. Just say Integer -> whatever the return value type is

jgarc629
Posts: 76
Posted 00:50 Oct 19, 2018 |

Alright thanks guys I figured it out