rounding - Round IO Double to specified number of digits - Haskell -
is there way round io double
? looking function:
ownround :: io double -> io double
with these unit tests:
ownround 0.51 == 0.5 ownround 0.49 == 0.5 ownround 0.5 == 0.5 ownround 0.7132 == 0.7 ownround 0.39 == 0.4
what asking can't had. test cases you've written function
tensround :: double -> double
but type signature wrote function
ownround :: io double -> io double
if meant write test cases as
ownround (return 0.51) == return 0.5 ownround (return 0.49) == return 0.5
and on, every number wrapped io, these implementations work:
tensround :: double -> double tensround d = frominteger (round (d*10)) / 10 ownround :: io double -> io double ownround = fmap tensround
Comments
Post a Comment