optional – Option String in ocaml

optional – Option String in ocaml

Note that Some x is a value, not a type. The type returned by the library would be string option. If you happen to know that the value always looks like Some x, thats a different question. But its also pretty unlikely, as the library author could just use the type string for that. You use an option type specifically so you can use None to represent the absence of a value.

Id say the type a option has the same semantics for every type a. The type a option represents a value of the type that can either be present or not. If the value is present, it takes the form Some x, where x is a value of the type. If the value isnt present, it takes the form None.

A value of type string option can be None, or it can be Some , or it can be Some xxx for any string xxx. Theres no special string-specific meaning.

optional – Option String in ocaml

Leave a Reply

Your email address will not be published. Required fields are marked *