[Haskell-cafe] fundeps and overlapping/undecidable instances

Jeff Polakow jeff.polakow at db.com
Fri Dec 7 16:22:55 EST 2007


Hello,

  Does the following code work for you?

-Jeff

---------------------------

{-# OPTIONS_GHC -fglasgow-exts -fallow-undecidable-instances 
-fallow-overlapping-instances #-}
data Nil = Nil
data x ::: xs = x ::: xs
infixr 5 :::

data HTrue = HTrue deriving Show
data HFalse = HFalse deriving Show

class Member x xs b | x xs -> b where member :: x -> xs -> b
instance Member x Nil HFalse where member _ _ = HFalse
instance Member x xs b => Member x (x ::: xs) HTrue where member _ _ = 
HTrue
instance Member x xs b => Member x (y ::: xs) b where member x (_ ::: xs) 
= member x xs

{-
member 'a' (() ::: "a" ::: '1' ::: Nil)  ==>  HTrue
member 'a' (() ::: "a" ::: Nil)  ==>  HFalse
-}

---

This e-mail may contain confidential and/or privileged information. If you 
are not the intended recipient (or have received this e-mail in error) 
please notify the sender immediately and destroy this e-mail. Any 
unauthorized copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071207/40397e76/attachment.htm


More information about the Haskell-Cafe mailing list