why doesn't this work?

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

On Wed, 8 Jan 2020, at 3:01 PM, Alexander Chen wrote:
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.
Could you share what the "nontrivial error blurp" is? It will be easier for people to reply to you if they can see the problem without having to reproduce it manually. Ollie

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
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@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Floating point comparisons are a bad idea.
A better way would be x `mod` y == 0.
On Wed, Jan 8, 2020 at 10:01 AM Alexander Chen
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@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
participants (4)
-
Alexander Chen
-
David McBride
-
Oliver Charles
-
Ut Primum