[Haskell-cafe] List as input
ryani.spam at gmail.com
Fri Oct 17 09:36:10 EDT 2008
I can't think of a language that lets you do this; that is, allow you
to input a list of any type as text.
Some languages effectively encode the types in the parsing, for
example in LISP, you know that 'foo is a symbol. It has a very
limited set of data types and new types are described entirely in
terms of those simple types, which makes parsing simple. But lets say
> data Color = Red | Green | Blue deriving (Read,Show,Eq,Ord)
Now you suddenly expect "readLn" to detect the word "Green" and
interpret it differently from "1.0", restricting the type at runtime?
Do you realize how difficult this is?
What if Green is also used in a type in another module?
You need to specify the type to read, or provide a parser that works
for every type you care about.
On Fri, Oct 17, 2008 at 2:21 PM, leledumbo <leledumbo_cool at yahoo.co.id> wrote:
> So, what's the solution? This one:
> (l::[Ord]) <- readLn
> doesn't work (because Ord isn't a type constructor). It doesn't even comply
> to Haskell 98 standard. I want to be able to read any list of ordered
> View this message in context: http://www.nabble.com/List-as-input-tp19987726p20033244.html
> Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe