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

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

Expand Messages
  • Martin DeMello
    Nov 1, 2009
    • 0 Attachment
      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!
      >
      >
      > On Sat, Oct 31, 2009 at 10:09 AM, Martin DeMello
      > <martindemello@... <martindemello%40gmail.com>> wrote:
      > >
      > >
      > >
      > > Is there any disadvantage (performance, e.g.) to having a function
      > > return [] or [string], and consume it via
      > >
      > > let collecting traversal =
      > > let retval = ref [] in
      > > let add_word = function [] -> () | s::_ -> retval := s :: !retval in
      > > traversal add_word;
      > > List.rev !retval
      > >
      > > rather than
      > >
      > > let add_word = function None -> () | Some s -> retval := s :: !retval
      > in...
      > >
      > > ?
      > >
      > > I just think the former looks neater, but of course if I'm taking a
      > > performance hit by using this in my inner loops I'll switch to using
      > > an option.
      > >
      > > martin
      >
      >
      >


      [Non-text portions of this message have been removed]
    • Show all 6 messages in this topic