RULES pragma with class constraint
John Meacham
john at repetae.net
Mon Mar 20 06:49:14 EST 2006
Is it possible to create a RULES that fires only if a type has a given
class constraint? something like:
> snub :: Ord a => [a] -> [a]
> snub xs = f Set.empty xs where
> f _ [] = []
> f (x:xs) set
> | x `Set.member` set = f xs
> | otherwise = x:f xs (Set.insert x set)
>
>
> {-# RULES "nub/snub" Ord a => forall a xs . nub (xs::[a]) = snub xs #-}
Such a rule would probably only be able to fire on monotypes with known
instances since otherwise the dictionary won't necessarily be available.
but it seems like it might be a useful feature even with that
restriction.
John
--
John Meacham - ⑆repetae.net⑆john⑈
More information about the Glasgow-haskell-users
mailing list