ocaml - unbound value error in recursive list matching function

1k views Asked by At

I copied a recursive list matching function from a slide of an introductory ocaml course.

let rec fac n = match n with
     0 -> 1
     | _ -> n * fac(n-1);;

fac 3;;

I get: "Error: Unbound value fac"

Why is this?

1

There are 1 answers

0
Goswin von Brederlow On

Using M-X tuareg-eval-buffer in emacs gives:

        OCaml version 4.02.3

# let rec fac n = match n with
     0 -> 1
     | _ -> n * fac(n-1);;

fac 3;;
    val fac : int -> int = <fun>
#   - : int = 6
# 

You probably run M-X tuarge-eval-region with only the fac 3 selected so the function was never defined.