[Haskell-cafe] conflicting variable definitions in pattern

Claus Reinke claus.reinke at talk21.com
Fri May 15 05:54:29 EDT 2009

> I miss lots of stuff from when I was a kid. I used to write
>   elem x (_ ++ x : _)  = True
>   elem _ _             = False
> and think that was cool. How dumb was I?

Yeah, the Kiel Reduction Language had similarly expressive
and fun pattern matching, with subsequence matching and 
backtracking if the guard failed. Of course, these days, you 
could use view patterns for the simpler cases, but it doesn't 
look quite as nice:

    elem x (break (==x) -> (_, _:_)) = True
    elem _ _                         = False

and gets ugly enough to spoil the fun quickly:

    -- lookup key (_++((key,value):_)) = Just value
    lookup key (break ((==key).fst) -> (_ , (_,value):_)) = Just value
    lookup _   _                                          = Nothing

Also, view patterns don't handle match failure by an implicit
Monad, let alone MonadPlus, so one often has to insert an
explicit Maybe, and there is no backtracking:-(


-- Nostalgia isn't what it used to be [source: ?]

More information about the Haskell-Cafe mailing list