[Haskell-cafe] Re: Using type classes for polymorphism of data constructors


Posted by Thomas Sutton on June 23, 2005

Re: Using type classes for polymorphism of data constructors

A message on the Haskell-cafe mailing list gives an alternative (better, even) approach to the polymorphism of formulae using differential types. It works just as well as my solution, and results in much more complex (and therefore complete) types:

Main> :t (Impl (Prop “p”) (Poss (Prop “p”)))Impl (Prop “p”) (Poss (Prop “p”)) :: PC2 PC0 (Modal1 PC0)

I’m not yet sure which route I’ll take. My approach results in a single data type (PC, Modal, etc) for each language, which is good, but the types don’t mean much and it isn’t Haskell-98 (or, at least, Hugs won’t load it as such). Ralf’s approach also works, the types is assigns formulae contain more information and it is Haskell-98.

I’ll probably wind up using a version based on Ralf’s example, unless I run into problems.

This post was published on June 23, 2005 and last modified on January 26, 2024. It is tagged with: .