GG> 2012/4/12 upkevin <upke...
UK> hello ,I am reading the source codes of Vine. I find the Some()
UK> func is important and used widely. but I could not know where it
UK> is defined? Is someone know ? Thanks !
>>>>> "GG" == gustavo grieco <gustavo.gri...
GG> You mean the option
GG> defines Some type constructor?
To be precise, "Some" and its counterpart "None" are the constructors
of the "option" built-in type, whose definition is effectively just:
type 'a option = None | Some of 'a
The "Option" module from ExtLib you mention there contains some
additional functions that are useful in conjunction with option-typed
values. The Vine code tends to mostly just use "option" directly
without "Option", though the difference is mostly just a question of
Values of option type are an idiom in ML-family languages for a value
that may or not be present. They fulfill a purpose somewhat similar to
the null values in SQL, C pointers, and Java references, the undefined
value in Perl, None in Python, and so on. But the ML option type
is stricter than these in that you have to explicitly account for the
possibility that a value might be missing every time you mention it.
So rather than having null pointer exceptions as in Java, or their
equivalents, the compiler checks that you have made explicit
everywhere what to do if a value is missing.
Option types should be covered in just about any full-length
introduction or tutorial for OCaml. If you haven't already read one of
these, and you want to read or modify the Vine source, it would
probably be a good idea. Here's an example from one of the first
Hope this helps,