[Haskell-cafe] Re: Float instance of 'read'

Mauricio briqueabraque at yahoo.com
Wed Sep 17 12:59:18 EDT 2008

>     Do you think 'read' (actually,
>     'readsPrec'?) could be made to also
>     read the international convention
>     (ie., read "1,5" would also work
>     besides read "1.5")?
> No, as read is really intended to be a language-level tool, not 
> something that you should expose to end users. For locale-aware number 
> input and formatting, you'd want to do something else.

Sure. What I think would be great if possible
would be a language-level tool. The same way
'.' can be used as decimal separator even if
it's the function composition operator. If
it's not possible to change the syntax,
changing 'read' could be a good step (since,
sometimes, 'read' is a good way to inialize
some variables if proper care is taken.

I know this sound weird, but it is an issue,
for instance, when teaching programming.
Students who face programming classes usually
start writing numbers the wrong way, and
sometimes this leads to confusion. A similar
problem we had in the days when zeros were
cut so they would be different of O, and
now we have a lot of grown up people still
writing 0 as if it were a greek phi. (As
my father used to complain, when his students
had to write something like phi=0.)

Read and Show are, IMHO, a great way to
initialize variables. a = read "123" is
an alternative to a = 123, and maybe even
a replacement. If, for instance, both
show and read used some kind of delimiter,
it would be easy to use reasonable ways
to write constants of any kind. A big effort,
but not less than is needed for unicode
support in strings, and almost as usefull.


More information about the Haskell-Cafe mailing list