[Haskell-beginners] why doesn't this work?
Ut Primum
utprimum at gmail.com
Wed Jan 8 17:50:35 UTC 2020
Hi,
I think the problem is in the types.
If you look at the type of the function round, you can see its result is an
Integral:
>> :t round
round :: (Integral b, RealFrac a) => a -> b
The result of the division x/y, instead, is a Fractional, and you cannot
test equality between two things of different types.
To solve the problem you can do a type cast, by converting the Integral to
a Num, using fromInteger:
(fromInteger (round (x/y))) == (x/y)
This should work.
Cheers,
Ut
Il giorno mer 8 gen 2020 alle ore 16:01 Alexander Chen <alexander at chenjia.nl>
ha scritto:
> hi,
>
> for a List comprehension I want to only include the integers of a
> division. In my beginners mind this should work:
>
> (round (x / y)) == (x / y)
>
> however, i get a nontrivial error blurp.
>
> what am i doing wrong?
>
> best,
>
> Alexander
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200108/4efa2af4/attachment.html>
More information about the Beginners
mailing list