[Haskell-beginners] Learn You a Haskell! I have a few questions!

Norbert Melzer timmelzer at gmail.com
Fri Apr 18 19:38:32 UTC 2014


Am 18.04.2014 21:26 schrieb "Gilberto Melfe" <gilbertomelfe at gmail.com>:

> -- ---------- Start Quote
>
> Names can't be enumerated. What comes after "John"? I don't know.
>
> -- ---------- End Quote
>
> "a" to "z" then "aa" to "zz" then "aaa" to "zzz" and so on! Is it to
difficult or impossible to create a function that enumerates all possible
strings?

Following your theory the next "name" would be "Joho", is that a name or
just random letters? That's why you don't have predecessor or successor
functions on String.

> -- ---------- Start Quote
>
> To make a list with all the numbers from 20 to 1, you can't just do
[20..1], you have to do [20,19..1].
>
> -- ---------- End Quote
>
> Why is this? If the first was greater than the second it would just
subtract! Right?

I would be with you, but that's not how it is designed. We can't change the
given behavior.

> -- ---------- Start Quote
>
> Watch out when using floating point numbers in ranges! Because they are
not completely precise (by definition), their use in ranges can yield some
pretty funky results.
>
> ghci> [0.1, 0.3 .. 1]
> [0.1,0.3,0.5,0.7,0.8999999999999999,1.0999999999999999]
>
> -- ---------- End Quote
>
> Can anyone explain me why it works for the first few values, and not
"completely"?

To explain that we had to go into how floating point numbers are
represented internally in the PCs memory, I'm to tired to do that right
now.

But problems comparable to this one exist on every language that has
floating point numbers.

HTH
Norbert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140418/d7aed1bd/attachment.html>


More information about the Beginners mailing list