
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 String".
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 String String". 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 the purpose). HTH Christian
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.
Thanks,