Type Relations

Paulo J. Matos pocm at soton.ac.uk
Mon Dec 17 14:32:58 EST 2007


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?

-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK


More information about the Glasgow-haskell-users mailing list