0

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?

glennsl
  • 28,186
  • 12
  • 57
  • 75
user3435407
  • 1,019
  • 4
  • 15
  • 31

1 Answers1

0

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.

Goswin von Brederlow
  • 11,875
  • 2
  • 24
  • 42