
20 Mar
2006
20 Mar
'06
6:49 a.m.
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⑈