
What is the reason for the definition ReadS a = [(a, String)] not being ReadS a = Maybe (a, String) ? The latter one reflects that either one or no value is read, whereas the first definition allows an arbitrary number of read values which is confusing and unsafe in my opinion.

From the GHC docs: type ReadS a = String -> [(a, String)] A parser for a type a, represented as a function that takes a String and returns a list of possible parses (a,String) pairs. So it returns all possible parses, hence the list. This is useful if the encoding is ambiguous. Henning Thielemann wrote:
What is the reason for the definition
ReadS a = [(a, String)]
not being
ReadS a = Maybe (a, String)
? The latter one reflects that either one or no value is read, whereas the first definition allows an arbitrary number of read values which is confusing and unsafe in my opinion.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Mon, Jan 03, 2005 at 08:48:26PM +0100, Henning Thielemann wrote:
What is the reason for the definition
ReadS a = [(a, String)]
not being
ReadS a = Maybe (a, String)
? The latter one reflects that either one or no value is read, whereas the first definition allows an arbitrary number of read values which is confusing and unsafe in my opinion.
I always wondered why we have readIO :: Read a => String -> IO a instead of the absurdly more useful and strictly superior readM :: (Monad m,Read a) => String -> m a then we can just readM as a list, a maybe, in IO, for pattern matching in arbitrary monads... sigh. I think I am just a real fan of type classes when it comes to code reuse :) John -- John Meacham - ⑆repetae.net⑆john⑈

On Mon, Jan 03, 2005 at 08:48:26PM +0100, Henning Thielemann wrote:
What is the reason for the definition
ReadS a = [(a, String)]
not being
ReadS a = Maybe (a, String)
? The latter one reflects that either one or no value is read, whereas the first definition allows an arbitrary number of read values which is confusing and unsafe in my opinion.
Isn't that because there could be more than one way to read the string? For example, in theory reads of an int from "123" might return [(123,""), (12,"3"), (1,"23")] -- David Roundy http://www.darcs.net
participants (4)
-
David Roundy
-
Henning Thielemann
-
John Meacham
-
Robert Dockins