type hackery question

Hello, The HList paper gives a type cast: class TypeCast a b | a -> b, b->a where typeCast :: a -> b class TypeCast' t a b | t a -> b, t b -> a where typeCast' :: t->a->b class TypeCast'' t a b | t a -> b, t b -> a where typeCast'' :: t->a->b instance TypeCast' () a b => TypeCast a b where typeCast x = typeCast' () x instance TypeCast'' t a b => TypeCast' t a b where typeCast' = typeCast'' instance TypeCast'' () a a where typeCast'' _ x = x and a type equality check: class TypeEq x y b | x y -> b instance TypeEq x x HTrue instance TypeCast HFalse b => TypeEq x y b The type cast succeeds causing its two argument types to be unified, or simply fails if the arguments are not unifiable. The type equality always succeeds "returning" HTrue if the arguments are syntactically equal, and HFalse if the arguments are not syntactically equal; thus the type equality will return false for two arguments which could be unified. If I understand correctly, these two classes do not provide a way to check for unifiability. Is it possible to write a class which checks to see if two given type arguments are unifiable? thanks, Jeff

[Sorry for the duplicate Jeff.]
Is it possible to write a class which checks to see if two given type arguments are unifiable?
This will probably help: http://www.haskell.org/pipermail/haskell-cafe/2006-November/019705.html That was Oleg's response to a post of mine: http://www.haskell.org/pipermail/haskell-cafe/2006-November/019610.html I find his code is much clearer and idiomatic, but it offers a little less control than mine (which kinda crosses the elegance boundary for type hackery with kinds and such). Hopefully you just need the Normalize type class. Happy hacking, Nick

Hello, Thanks for the response.
Is it possible to write a class which checks to see if two given type arguments are unifiable?
This will probably help: http://www.haskell.org/pipermail/haskell-cafe/2006-November/019705.html
That was Oleg's response to a post of mine: http://www.haskell.org/pipermail/haskell-cafe/2006-November/019610.html
I don't think either of these approaches really accomplishes what I'm after since they both require both arguments to be instantiated (correct me if I'm wrong about this). I would like a TypeCastP class for which I can write something like: instance (TypeClassP xs (HCons targ rest) b, Branch b targ rest) => Member targ xs where Member can used to build the expected list via unification (similar to Prolog) as well as check membership in an already instantiated list. I was thinking of trying to use Oleg's explicit backtracking machinery (http://okmij.org/ftp/Haskell/poly2.hs) to get backtracking based on unification failure. Also, I was hoping to do this with Haskell's type variables and unification, rather than encoding my own machinery. I'm beginning to think what I'm after is not possible... -Jeff

Hello,
I'm beginning to think what I'm after is not possible...
I figure I should try to explain exactly what it is I'm after... Basically I'm trying to mix type hackery with HOAS. More specifically, here is a data type which I would like to use: data Exp a where Lam :: (Exp a -> Exp b) -> Exp (a -> b) App :: Exp (a -> b) -> Exp a -> Exp b Rcd :: (IsRecord (HCons (F l (Exp v)) r) => F l (Exp v) -> Exp r -> Exp (HCons (F l (Exp v)) r) Proj :: (HasLabel l r v) => l -> Exp r -> Exp v where F is a datatype constructor for record fields (as in the HList paper), IsRecord checks that the argument is an HList of F l v and has unique labels (also as in the HList paper); and HasLabel fishes the appropriate type out of a HList of fields. The catch is that I want GHC to infer my types, as well as check ascribed types. Thus I would like to be able to successfully infer a type for: Lam $ \x -> App (Proj l1 x) (Proj l2 x) for some given labels l1 and l2. However, I cannot figure out how to write HasLabel (or if it's even possible). Anyone have any thoughts on this? thanks, Jeff
participants (2)
-
jeff p
-
Nicolas Frisby