Contexts for data constructors.
anatoli
anatoli@yahoo.com
Sun, 11 Feb 2001 06:07:38 -0800 (PST)
A lot of thanks to everybody who helped me with
fundeps. Now for another question (I asked it
already but I think the message was lost).
Wouldn't it be nice if we could specify contexts for data constructors?
I mean something like that:
data Quick a = Eq a => Unsorted [a]
| Ord a => Sorted (Tree a)
findquick :: a -> Quick a -> Maybe a
findquick (Unsorted list) = ... -- find slowly using linear search and (==)
findquick (Sorted tree) = ... -- find quickly using binary search and (<)
Note that findquick does not require any context with this hypothetical
extension. Indeed, in the "Unsorted" branch of findquick (Eq a) is
required, but we know that it's satisfied because of the constraint on
the data constructor. Similarly for the Sorted branch and (Ord a).
I tried achieving this with current Haskell, but couldn't. Everything I
tried gives me "findquick :: Ord a => a -> Quick a -> Maybe a".
Regards
--
anatoli
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35
a year! http://personal.mail.yahoo.com/