Le Fri, 17 Jan 2014, Gabriel Scherer a écrit : > There have been recurrent discussions of optimizing `'a option` to > avoid allocation in some cases, which is interesting when it is used > as a default value for example. (The nice recent blog post by Thomas > Leonard also seems to assume that `'a option` is somehow optimized.) > > My strictly personal opinion is that I doubt this would be a good > idea, because I expect a fair share of the programming practice that > currently use ('a option) to move to something like (('a, > error-description) either) later in their lifetime, and I wouldn't > want people to avoid to do that for performance concerns. > Historically, we've rather come to see special-case representation > optimizations (eg. array of floats) as a mistake -- but on the other > hand there is not much downside to record of floats. I think optimization of some local uses of options, such as: let rec iter_stream f s = match (try Some (MyStream.get s) with End_of_stream -> None) with | None -> () | Some (x, s') -> f x; iter_stream f s' where an option is used to keep the function tail-rec (I've heard several people tell me they often need to use this), or other cases like optional parameters (which are not going to move to Either), would be useful and future-proof. I hope the current work on optimizations will help with this kind of cases (removing useless allocations of local options, references, exceptions when no escape is possible). > -- Simon