I am a beginner to Ocaml. I am trying to write some code about normal order reduction, and is confused by some syntax. The following is some truncated code to isolate my error.
type expr =
| Var of char
| Num of int
| Lambda of expr
| Apply of expr * expr
let rec substitute f id e = match f with
| Num(i) -> if id == i then e else f
| _ -> f
let rec beta_lor e = match e with
| Apply(Lambda(f), e2) -> substitute f 1 e2
| Apply(e1,e2) -> beta_lor e1
| Lambda e1 -> beta_lor e1
| _ -> None
In a file of .mli I claim the beta_lor shall be of type: val beta_lor: expr -> expr option
Now when I compile this file it report error about the line the "None" I used in beta_lor: Error: This expression has type 'a option but an expression was expected of type expr
I understand that ocaml compiler tries to do type inference, and it expects me to output an expression, rather than 'a option, but I have claimed that beta_lor may output option? I am somewhat confused, please help.