[Haskell-cafe] Pattern matching does not work like this?

Sebastian Fischer sebf at informatik.uni-kiel.de
Thu Jul 16 03:21:10 EDT 2009


On Jul 15, 2009, at 2:30 PM, Hans Aberg wrote:

>> If ++ could be pattern matched, what should have been the result of
>> "let (x++y)=[1,2,3] in (x,y)"?
>>
>> It will branch. In terms of unification, you get a list of  
>> substitutions.
>>
>> f :: [a] -> ([a],[a])
>> f (x ++ y) = (x,y)
>
> For an argument s, any pair (x, y) satisfying s = x ++ y will match.  
> That is, if s = [s_1, ..., s_k], the solutions j = 0, ..., k, x =  
> [s_1, ..., s_j], y = [s_(j+1), ..., s_k]. And for each one, a  
> potentially different value could given. That is, s could produce  
> multiple values.

Curry (a Haskell extension with non-determinism) supports exactly that.

Sergio Antoy and Michael Hanus: Declarative Programming with Function  
Patterns
available at: <http://www.informatik.uni-kiel.de/~mh/papers/ 
LOPSTR05.pdf>


-- 
Underestimating the novelty of the future is a time-honored tradition.
(D.G.)





More information about the Haskell-Cafe mailing list