On Fri, 5 Jan 2007, al_kolesnikoff wrote:
> --- In ocaml_beginners%40yahoogroups.com">ocaml_beginners
yahoogroups.com, Martin Jambon
> <martin_jambon
...> wrote:
>>
>> Your dbs object is not exactly an array, it is an option type: its
> value
>> is either "None" or "Some a" where "a" is an array.
>> If you want to get the length of the array, you should do something
> like:
>>
>> match dbs with
>> None -> failwith "I cannot answer your question"
>> | Some a -> Array.length a
>
> Does this method only for work with "option type" ?
No, it's a very general and powerful mechanism in OCaml.
These kind of types are called sum types or variants, and the "match with"
stuff is what is called pattern matching. I think it's nicely explained
there:
http://www.ocaml-tutorial.org/data_types_and_matching
Martin
--
Martin Jambon
http://martin.jambon.free.fr
.