hexaquark
hexaquark

Reputation: 941

Call 2 or more functions inside a match expression

I am a beginner in OCaml. I am curious to know how, syntactically speaking, call two functions, or more, within a match expression. Or is that possible at all?

For example :

let rec foo l:list = 
  match l with
  | [x,y] -> (foo1 x) (foo2 y)
  | _ -> doSome

I have tried using the ; operator but that seems to be used for something else. I have tried different combinations of bracketing but in all cases I get This is not a function it cannot be applied under foo1 x.

Upvotes: 2

Views: 817

Answers (1)

Jeffrey Scofield
Jeffrey Scofield

Reputation: 66818

You just need a semicolon (no begin/end). You don't need the parentheses (they don't hurt but they're not especially idiomatic OCaml).

let rec foo l : 'a list = match l with
| [x,y] -> foo1 x; foo2 y
| _ -> doSome

Upvotes: 3

Related Questions