List Info

Thread: "ocaml_beginners"::[] using string array option type




"ocaml_beginners"::[] using string array option type
user name
2007-01-05 18:48:44

On Fri, 5 Jan 2007, al_kolesnikoff wrote:

> # let dbs = list_dbs db ();;
> val dbs : string array option = Some [|"mysql"; "radius"; "test"|]
>
> If I'm trying:
>
> # Array.length dbs;;
>;
> I'm teceive: This expression has type string array option but is here
> used with type
> 'a array
>;
> Yes, Array.length must be same type as "dbs", but how it can be done?

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

Martin

--
Martin Jambon
http://martin.jambon.free.fr

__._,_.___
.

__,_._,___
"ocaml_beginners"::[] using string array option type
user name
2007-01-05 19:15:42

--- In ocaml_beginners%40yahoogroups.com">ocaml_beginnersyahoogroups.com, Martin Jambon
<martin_jambon...> wrote:
&gt;
> Your dbs object is not exactly an array, it is an option type: its
value
> is either "None" or "Some a" where "a&quot; is an array.
&gt; 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&quot;
> | Some a -> Array.length a

Does this method only for work with "option type" ?

Thank you very much for your answer!

Alexander

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )