# why doesn't this work?

4 messages
Open this post in threaded view
|

## 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 _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|

## Re: why doesn't this work?

 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_______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|

## Re: why doesn't this work?

 In reply to this post by Alexander Chen 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 roundround :: (Integral b, RealFrac a) => a -> bThe 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,UtIl giorno mer 8 gen 2020 alle ore 16:01 Alexander Chen <[hidden email]> 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 [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|

## Re: why doesn't this work?

 In reply to this post by Alexander Chen 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 <[hidden email]> 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.what am i doing wrong?best,Alexander _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners