RULES pragma with class constraint

2006-03-20 Thread John Meacham
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

RE: RULES pragma with class constraint

2006-03-20 Thread Simon Peyton-Jones
| To: glasgow-haskell-users@haskell.org | Subject: RULES pragma with class constraint | | 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

Re: RULES pragma with class constraint

2006-03-20 Thread Bulat Ziganshin
Hello John, Monday, March 20, 2006, 2:49:14 PM, you wrote: JM Is it possible to create a RULES that fires only if a type has a given JM 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 =

Re: RULES pragma with class constraint

2006-03-20 Thread John Meacham
On Mon, Mar 20, 2006 at 12:09:41PM -, Simon Peyton-Jones wrote: Definitely not at present, and I see no easy way to implement it. RULES are implemented by simple matching in Core. A call to nub will have an Eq dictionary, but Core knows nothing of instance declarations, and has no clue