> class Subtype sub super where
> up :: sub -> super
> down :: super -> Maybe sub
See the extensible union types of
@InProceedings{
Liang*95:Monad,
author="Sheng Liang and Paul Hudak and Mark Jones",
title="Monad Transformers and Modular Interpreters",
crossref="ACM95:POPL",
year="1995",
pages="{333--343}",
}
>From the abstract:
"... Finally, we have implemented our interpreter in Gofer,
whose constructor classes provide just the added power over
Haskell's type classes to allow precise and convenient
expression of our ideas. This implementation includes a method
for constructing extensible unions and a form of subtyping that
is interested in its own right."
They have a multiparameter type class SubType, with methods `inj' and
'prj', just as you describe, implemented in Gofer.
I used this in my Masters thesis,
@MastersThesis{
Wansbrough97:Modular,
author="Keith Wansbrough",
title="A Modular Monadic Action Semantics",
school="Department of Computer Science, University of Auckland",
year="1997",
month=feb,
note="Available \path|http://www.cl.cam.ac.uk/users/kw217/research/msc/thesis/|",
}
--KW 8-)