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

Mauricio briqueabraque at yahoo.com
Wed Sep 17 10:52:14 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")? I'm happy to
>> finaly use a language where I can
>> use words of my language to name
>> variables, so I wonder if we could
>> also make that step.
> 
> That would be quite problematic in combination with lists, is
> 
>   read "[1,2,3,4]" == [1,2,3,4]
> 
> or
> 
>   read "[1,2,3,4]" == [1.2, 3.4]
> 
> Or something else?

As of today, at least in ghc, show ([1,2,3]::[Double])
will always produce "[1.0,2.0,3.0]". Since the requirement
for read is to read what is produced by show, that
would not be a problem.

> 
> 
> Localized reading should be somewhere else, perhaps related to Locales.

No! If we had that, string from a program would not
be readable by some program running in other machine,
or other locale. As, actually, you describe below.
Show and Read are for programs reading, not for
user reading. That's a work for Pango :)

> 
> As an aside, this is one of the (many) places where Haskell has made the 
> right choice. In other languages such as Java input functions suddenly 
> break when the user has a different locale setting. While for user input 
> this might be desired, in my experience much of the i/o a program does 
> is with well defined file formats where changing '.' to ',' just 
> shouldn't happen.

Best,
Maurício



More information about the Haskell-Cafe mailing list