Loading ...
Sorry, an error occurred while loading the content.

11533Re: "ocaml_beginners"::[] using a list instead of option

Expand Messages
  • Lukasz Stafiniak
    Nov 1, 2009
    • 0 Attachment
      You may need some general functions that lack from the basic standard library:

      let unsome default = function
      | None -> default
      | Some v -> v


      let map_some f l =
      let rec maps_f accu = function
      | [] -> accu
      | a::l -> maps_f (match f a with None -> accu
      | Some r -> r::accu) l
      in
      List.rev (maps_f [] l)

      etc. (see Batteries).

      On Sun, Nov 1, 2009 at 11:04 AM, Martin DeMello <martindemello@...> wrote:
      >
      >
      >
      > thinking about it, you're right, i was being silly :) code changed to use
      > option type.
      >
      > martin
      >
      > On Sat, Oct 31, 2009 at 3:06 PM, Lukasz Stafiniak <lukstafi@...>wrote:
      >
      > >
      > >
      > > I think performance-wise the difference is very small. But you should
      > > use the option type to express your program's semantics correctly!
    • Show all 6 messages in this topic