From: Amit D. <ad...@Co...> - 2003-03-10 13:49:39
|
> > > > Hi list ! > > > > > > Let's continue working together on ExtLib ! > > > Here's the new version, adding some changes. > > > Please report any missing function and any comments you could have on > it. > > > > Where did Option.val_of go? (maybe I'm missing something) > > > > The problem I can see with val_of is the following : > val_of should raise an exception when you're using it with None, and if > you're using a good programming style, this is the kind of excecption you > have to catch quite immediatly, so I think it's better to write : > > match x with > | None -> do_something > | Some v -> use_it > > than > > try > use_it (val_of x) > with > NoneException -> do_something I disagree: val_of has two reasonable uses. First, it can be used with throwaway prototype programs, where simplicity and speed matter more than correctness. Second, it can be used where the semantics of the program dictate that the option has "Some" value. If you don't have a "Some" value in these cases, there often is nothing to do except bail out in the "with" clause, so you might as well catch the exception somewhere else higher up. I might add: if it's good enough for SML, it's good enough for me :) -Amit |