[Haskell-cafe] Pattern matching does not work like this?
Richard O'Keefe
ok at cs.otago.ac.nz
Wed Jul 15 21:45:21 EDT 2009
On Jul 15, 2009, at 9:59 PM, minh thu wrote:
> 2009/7/15 Magicloud Magiclouds <magicloud.magiclouds at gmail.com>:
>> Hi,
>> I do not notice this before. "fun ([0, 1] ++ xs) = .." in my code
>> could not be compiled, parse error.
>
> ++ is a function; you can't pattern-match on that.
Doesn't matter, it's not trying to.
Part of Erlang syntax is that in a pattern
[c1,...,cn] ++ P
is equivalent to
[c1,...,cn|P]
For example,
wee(X) ->
F = fun ([0,1] ++ L) -> L end,
F(X).
is perfectly legal.
The problem might be the "xs", or it might be the "=".
Presumably it should be
fun ([0,1] ++ Xs) -> ...
More information about the Haskell-Cafe
mailing list