[Haskell-cafe] Prolog-style patterns

Jan Stolarek jan.stolarek at p.lodz.pl
Mon Apr 8 15:11:01 CEST 2013


> You can achieve something similar with the ViewPatterns language
> extension.
>
> member _ [] = False
> member x (((x ==) -> True) : _) = True
> member x (_ : xs) = member x xs
Hi Tillmann,

there are a couple of ways to achieve this in Haskell, for example using guards:

member :: Eq a => a -> [a] -> Bool
member _ []             = False
member y (x:_) | x == y = True
member y (_:xs)         = member y xs

The goal of my proposal is to provide a concise syntax, whereas ViewPatterns are very verbose and 
guards are slightly verbose. I want something simple and something that is very intuitive if 
you've programmed in Prolog :)

Janek



More information about the Haskell-Cafe mailing list