Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Frustrated Beginner
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-12-23 (06:38)
From: Shawn Wagner <shawnw@s...>
Subject: Re: [Caml-list] Frustrated Beginner
On Tue, Dec 23, 2003 at 01:11:08AM -0500, Tyler Eaves wrote:
> On Dec 23, 2003, at 12:34 AM, Matt Gushee wrote:
> >
> >      match foo with
> >      | None -> print_endline "Nothing"; ""
> >      | Some x -> print_endline x; x
> If I understand the match syntax correctly, in this case, x takes the 
> value of foo?

Not quite. foo is an option type - it can hold either Some valid bit of data
(A string in this case), or nothing (None). x ends up taking the value of
whatever the valid bit of data is. The same thing in C would look like

if (foo) {
   return foo;
} else {
   return "";

Options are nicer, however, because you don't have the problem that crops up
in C of not handling cases where NULL is a valid bit of data because it's
treated as 'No data'. Hash lookup functions that return NULL when a key's
not found are a classic example. What happens when you want to store NULL in

Shawn Wagner

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: