[Haskell-cafe] isFunction
john lask
jvlask at hotmail.com
Fri Jan 4 03:01:55 EST 2008
Oleg provided the following code to test whether a is a function, this code will not type check in hugs, due to the overlapping instances in
IsFunction (x->y) f
IsFunction x f
and the functional dependency | a-> b
ERROR "isfunction.lhs":43 - Instances are not consistent with dependencies
*** This instance : IsFunction a b
*** Conflicts with : IsFunction (a -> b) c
*** For class : IsFunction a b
*** Under dependency : a -> b
is there a way to acheive the same effect in hugs ?
> data HTrue
> data HFalse
>
> class IsFunction a b | a -> b
> instance TypeCast f HTrue => IsFunction (x->y) f
> instance TypeCast f HFalse => IsFunction x f
>
> -- literally lifted from the HList library
> 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
_________________________________________________________________
New music from the Rogue Traders - listen now!
http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=832&referral=hotmailtaglineOct07&URL=http://music.ninemsn.com.au/roguetraders
More information about the Haskell-Cafe
mailing list