简体   繁体   中英

ocaml - unbound value error in recursive list matching function

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?

Using MX 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 MX tuarge-eval-region with only the fac 3 selected so the function was never defined.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM