On 8 April 2013 21:11, Jan Stolarek <jan.stola...@p.lodz.pl> wrote:
> 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
>
> The meaning of pattern in the second equation is "match this equation if the 
> first argument equals
> to head of the list". Many times I have found myself instinctively writing 
> patterns in this way,
> only to get a compilation error. I was thinking about implementing language 
> extension for GHC
> that would allow to write Prolog-style patterns. Would there be an interest 
> in such an extension?
> Also, if I missed something obvious please let me know.

My initial take on this is that such capabilities would be too easy to
mis-use accidentally; e.g. refactoring and changing variable names,
thus causing patterns to match when you don't mean them to.

>
> Janek
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
http://IvanMiljenovic.wordpress.com

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to