Type Relations

Wolfgang Jeltsch g9ks157k at acme.softbase.org
Mon Dec 17 15:36:45 EST 2007


Am Montag, 17. Dezember 2007 20:32 schrieb Paulo J. Matos:
> Hello all,
>
> I've came across a problem which would be best implemented if I could
> define what I think to be a Type Relation. Let's consider classes as
> being type properties.
> When you say:
> class Num a where
>    (+) :: a -> a -> a
> ...
>
> it defines a property of the type a. Basically all types a of class
> Num are addable, etc..
> However, how can I (if I can) represent the fact that you can coerce a
> type a to a type b?
>
> A particular example of that is the fromInteger function from Num
> class where you say that if your type a is of class Num, you must be
> able to coerce an Int to a.
> I would like to define a relation between types and then say that two
> types are in the relation if they define the coerce function.
> Something I imagine would be:
> typerelation Coercible a b where
>        coerce :: a -> b
>
> And then you would define instances of Coercible if you could define
> the function coerce between the types. You could then define function
> only over types which can be coerced from one to the other.
>
> Any suggestions on how to do something like this?

Isn’t this what multi-parameter type classes are about?

By the way, such questions are better asked on the Haskell Mailing List or the 
Haskell Café Mailing List.  This list is more about using GHC, not so much 
about topics related to the language Haskell as such.

Best wishes,
Wolfgang


More information about the Glasgow-haskell-users mailing list