Stack Exchange
Stack Overflow
Questions
Tags
Users
About
Stack Overflow
Public
Questions
Tags
Users
About
A list comprehension with double elements
Asked
Jun 25 '16 at 17:49
Active
Jun 25 '16 at 18:02
Viewed
102 times
2
In Haskell if I write
[x/10 | x <- [1,3..10]]
I obtain
[0.1, 0.3, 0.5, 0.7, 0.9, 1.1]
What's wrong?
haskell
edited Jun 25 '16 at 18:02
Willem Van Onsem
443,496
30
428
555
asked Jun 25 '16 at 17:49
Joan Tarrasso
121
1
2
`[1,3..10]` is wrong. Don't write that.
–
Reid Barton
Jun 25 '16 at 17:53
Why? What fixes that, i.e. to 0.9?
–
Joan Tarrasso
Jun 25 '16 at 17:55
`[1,3..9]` of course.
–
Reid Barton
Jun 25 '16 at 17:56
1
But if you want `[0.1, 0.3, 0.5, 0.7, 0.9]` then just write `[0.1, 0.3..0.9]`. Maybe you've oversimplified your real question?
–
Reid Barton
Jun 25 '16 at 18:00
1
Yes, but if I do [1,3..10] in ghci it displays [1,3,5,7,9]
–
Joan Tarrasso
Jun 25 '16 at 18:01
If I do that, the last term isn't exactly 0.9. It's 0.899999999999999
–
Joan Tarrasso
Jun 25 '16 at 18:06
Thank you very much! I'm going to see this link.
–
Joan Tarrasso
Jun 25 '16 at 18:22
0 Answers
0