
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

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

On Dec 17, 2007 8:36 PM, Wolfgang Jeltsch
Isn't this what multi-parameter type classes are about?
I didn't know about those. I'll check them out. Thanks for the pointer.
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.
Sorry, You're right. I posted here in fact because I was hoping it would be a GHC extension of some sort. Cheers, Paulo Matos
Best wishes, Wolfgang _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
-- Paulo Jorge Matos - pocm at soton.ac.uk http://www.personal.soton.ac.uk/pocm PhD Student @ ECS University of Southampton, UK
participants (2)
-
Paulo J. Matos
-
Wolfgang Jeltsch