Claudiu Razlet
Claudiu Razlet

Reputation: 650

Why one parameter Ocaml function works with two arguments

I can't understand why the following function works with 2 arguments even if we declare it with one param:

let rec removeFromList e = function
   h :: t -> if h=e then h 
             else h :: removeFromList e t
   | _ -> [];;

removeFromList 1 [1;2;3];;

Upvotes: 3

Views: 411

Answers (1)

ivg
ivg

Reputation: 35210

You're declaring it with two parameters. The syntax:

let f = function ...

can be seen as a shortcut for

let f x = match x with

So, your definition is actually:

let rec removeFromList e lst = match lst with
  h :: t -> if h=e then h else h :: removeFromList e 

Upvotes: 4

Related Questions