[Haskell-beginners] Tuples .vs Either Vs datatypes
Christian.Maeder at dfki.de
Wed Apr 6 11:24:45 CEST 2011
Am 05.04.2011 19:41, schrieb Mike Meyer:
> data CharClass = Fail | Pattern String
> matchCharClass :: Pattern -> Char -> CharClass
As mentioned by Alex Rozenshteyn this CharClass is isomorphic to "Maybe
> This only required minor changes to the code, but made it easy to add
> "Error String" to the CharClass datatype later. That version can be
Replacing Fail (or Nothing) by "Error String" is like going to "Either
Yet, user-defined data types (no type synonyms!) may increase
readability (and type safety). However, one disadvantage is that some
type class instances have to be redefined (or derived) if needed.
"Maybe" and "Either String" are fairly standard (and have Monad and what
not instances), still your data type CharClass is perfect (if it serves
> seen at http://pastebin.com/eyre8795 (as always, critiques welcome).
> I'd like to hear what more experienced haskell programmers have to say
> about those three ways of returning multiple values.
More information about the Beginners