简体   繁体   中英

Recursive Function in OCaml return Unbound Value Error

I'm getting Unbound Value Error in visual studio when trying to use OCaml

Tried restarting App.

let rec contains elt l = 
    match l with
    | [] -> false
    |x ::xs ->
        if x = elt then
            true
        else 
            contains(xs)

I don't see any unbound values being used in this code. What is the exact error message you're seeing?

There is a type error, which could lead to other problems down the line, perhaps.

Your recursive call to contains passes just one argument. But contains is expecting two arguments.

Update

Here's what an unbound value error looks like in OCaml (the usual INRIA release at least):

# let x = abc;;
Error: Unbound value abc

So if your error message literally says "unbound value error", then you are trying to use a value named error that isn't defined.

I actually tend to doubt this. It really would help if you could copy/paste the exact error message.

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