I am trying to find the length of a list in ocaml.
I call a function first called
> let get_list_length e in > print_list_length out x
the actual code in get_list_length is where I am confused. The "e" is a list of "commands" and I want to find the length of all the "commands".
let get_list_length(e:values) : unit =
match e with let x = list.length(e);;
So my e is the list of "commands" which are a bunch of values specified in 开发者_如何学运维my grammar file. I am confused about how to get the length of the list since e is a list of values and I want the length of that list.
Any help would be appreciated.
To get the length of a list is simple:
List.length my_list
Your get_list_length
function can be as simple as:
let get_list_length e = List.length e
or more simply:
let get_list_length = List.length
As you currently have defined it, get_list_length
returns type unit
so you won't get anything useful from it. You are also using match incorrectly, it's usually used like this:
match e with something -> do something
| something_else -> do something_else
精彩评论