Whers "Some()" is defined in Vine?

18 views
Skip to first unread message

upkevin

unread,
Apr 12, 2012, 4:27:12 AM4/12/12
to BitBlaze User Discussion group, bitblaz...@googlegroups.com
hello ,I am reading the source codes of Vine. I find the Some() func
is important and used widely. but I could not know where it is
defined? Is someone know ? Thanks !

gustavo...@gmail.com

unread,
Apr 12, 2012, 10:39:27 AM4/12/12
to bitblaz...@googlegroups.com
You mean the option module that defines Some type constructor?

2012/4/12 upkevin <upk...@gmail.com>

Stephen McCamant

unread,
Apr 16, 2012, 8:29:05 PM4/16/12
to bitblaz...@googlegroups.com
GG> 2012/4/12 upkevin <upk...@gmail.com>
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...@gmail.com> writes:

GG> You mean the option
GG> module<http://ocaml-lib.sourceforge.net/doc/Option.html>that
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
style.

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
Google hits:

http://mirror.ocamlcore.org/ocaml-tutorial.org/null_pointers,_asserts_and_warnings.html

Hope this helps,

-- Stephen

Reply all
Reply to author
Forward
0 new messages