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
| 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
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 =
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