17 Dec 20:29
Type Relations
From: Paulo J. Matos <pocm <at> soton.ac.uk>
Subject: Type Relations
Newsgroups: gmane.comp.lang.haskell.glasgow.user
Date: 2007-12-17 19:32:58 GMT
Subject: Type Relations
Newsgroups: gmane.comp.lang.haskell.glasgow.user
Date: 2007-12-17 19:32:58 GMT
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?
(Continue reading)
RSS Feed