[Haskell-cafe] Prolog-style patterns

Jon Fairbairn jon.fairbairn at cl.cam.ac.uk
Tue Apr 9 11:23:55 CEST 2013


Jan Stolarek <jan.stolarek at p.lodz.pl> writes:

> Hi all,
>
> consider this simple reimplementation of 'elem' function:
>
> member :: Eq a => a -> [a] -> Bool
> member _ [] = False
> member y (x:xs) | x == y    = True
>                 | otherwise = member y xs
>
> If Haskell allowed to write pattern matching similar to Prolog then we could write this function 
> like this:
>
> member :: Eq a => a -> [a] -> Bool
> member _ []     = False
> member x (x:_)  = True
> member x (_:xs) = member x xs

This kind of pattern matching was considered and rejected by the
very first Haskell committee. Others have given some of the
reasoning, and I don’t recall the rest so won’t attempt to
rehearse them here. What I would like to say (without meaning to
attack you personally, Jan) is that we really need to make a
rule that this sort of small convenience should never be
considered.

Every now and a language feature will be invented that really
makes a large difference to a large number of programmes (do
notation was a prime example), so the language should evolve.
But against that, there is considerable value in having the
basic syntax remain unchanged for as long as possible.

I don’t know how to formulate it formally, but the rule should
be something like, unless a new feature shortens programmes that
can use it by a significant factor, it shouldn’t be included.

-- 
Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk





More information about the Haskell-Cafe mailing list