[Haskell-cafe] How to define Show [MyType] ?
wss at Cs.Nott.AC.UK
Tue Dec 9 04:36:28 EST 2008
> The biggest wart is that "view" is not a total function; the compiler
> needs to be extra careful to only call it on types that are instances
> of "View". I wonder if there is a good way to solve this problem?
The usual way to solve this is to define a data type corresponding to
all the types in your class. For example:
data Data a where
| CHAR : Data Char
| STRING : Data String
| LIST : Data a -> Data [a]
With this representation you no longer need typecase (which is
horrendous semantic hack) and your dispatch function can be made
total. Hope this helps,
This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.
More information about the Haskell-Cafe