u936293
u936293

Reputation: 16274

Pattern matching for lambdas?

Is it possible to have pattern matching of arguments and casing for an anonymous function? If so, what is the syntax?

Ipsum lorem

Upvotes: 1

Views: 45

Answers (1)

molbdnilo
molbdnilo

Reputation: 66459

It's exactly the same as for named functions:

- (fn 0 => 1 | x => 34) 1;
val it = 34 : int

- (fn (_::y::_) => y) [1,2,3];
val it = 2 : int

(A warning was omitted in the second example.)

Upvotes: 3

Related Questions