Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write a Haskell function with type Int -> Float

Tags:

haskell

I can write

double :: Int -> Float
double i = 2.0

but that isn't in any way a function of its argument. Casting is apparently forbidden, mixed-mode arithmetic isn't supported, so I can't do anything like

double :: Int -> Float
double i = 2.0 * i

I'm actually trying to figure out how to define

series :: (Int -> Float) -> Int -> [Float]

to return the infinite series [f(i), f(i+1), f(i+2),...] but I'm stuck at computing f(i).

If this is really impossible, what type must I use?

Thanks!

like image 652
David Matuszek Avatar asked Nov 27 '25 15:11

David Matuszek


1 Answers

I think you're looking for the fromIntegral function.

like image 127
Michael Snoyman Avatar answered Nov 30 '25 04:11

Michael Snoyman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!