[Haskell] Classes with no data type
chad.scherrer at gmail.com
Tue Oct 10 09:39:14 EDT 2006
If you want to display them differently depending on how they were
generated, I would wrap each one in a newtype. Then you can make the
newtypes instances of different typeclasses. The wrapper remembers how
the structure was generated, and using typeclasses, you should be able
to treat each in the appropriate way pretty easily.
> I've met an interesting problem in terms of how to type a data
> structure and the functions that operate upon it.
> The problem centres around a single data type. This data type can be
> constructed in multiple ways using different functions, depending on
> the options the user specifies. That's all simple enough. The
> problem really comes later on. Depending on the function used
> generate the data structure I want to use different functions later
> on for example, to display the data.
> Thus I have a typical classes problem, in that I have several
> implementations of essentially the same function for different
> circumstances. The problem is, they must all operate on the same
> data type, so I cannot define them as seperate instances.
> Anyone got any ideas how to type this?
> Haskell mailing list
> Haskell at haskell.org
> End of Haskell Digest, Vol 38, Issue 6
"Time flies like an arrow; fruit flies like a banana" -- Groucho Marx
More information about the Haskell