[Haskell-cafe] Type hierarchy

Thiago Negri evohunz at gmail.com
Wed Jan 16 16:03:22 CET 2013


Hello.

How do I achieve type hierarchy in Haskell?

Suppose we have the following code:

foo :: A -> C
bar :: B -> C

I want something that allow me to say that B is a subtype of A, meaning:
1. I can use a value of type A where a value of type A is needed.
2. I can use a value of type B where a value of type B is needed.
3. I can use a value of type B where a value of type A is needed.
4. I can't use a value of type A where a value of type B is needed.

What are my options?

I've thought in type classes and data types with an attribute representing
the extension. Any other way to do this?

Thanks,
Thiago.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130116/5c634ac6/attachment.htm>


More information about the Haskell-Cafe mailing list