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

Re: "ocaml_beginners"::[] How to stifle the 'non exhaustive pattern warning' here ?

Expand Messages
  • Fabrice Marchant
    Thanks a lot Martin ! On Sun, 31 Aug 2008 23:27:01 +0200 (CEST) ... Yes, I see. ... Great ! This tuple map solution seems to do the job for my needs. Maybe
    Message 1 of 3 , Aug 31, 2008
      Thanks a lot Martin !

      On Sun, 31 Aug 2008 23:27:01 +0200 (CEST)
      Martin Jambon <martin_jambon@...> wrote:

      > > How to write things in order to suppress the warning ?
      >
      > match List.map f [12; 7; 4; 9] with
      > [foo; bar; gizmo; whatsit] ->
      > ( ... )
      > | _ -> assert false
      >
      > This will make your code hard to follow and slightly less safe than using
      > a tuple or direct bindings.
      Yes, I see.

      >
      > If the number of items is fixed (or up to a reasonable number), you can
      > use tuples:
      >
      > let map2 f (x1, x2) = f x1, f x2
      > let map3 f (x1, x2, x3) = f x1, f x2, f x3
      > ...
      >
      > let foo, bar, gizmo, whatsit = map4 f (12, 7, 4, 9)
      >
      > It is safer than lists, but still inefficient unless the execution of "f"
      > is costly enough.

      Great ! This tuple map solution seems to do the job for my needs. Maybe shutting about 40 of such mapx, in a catalogue of possibly useful things, in an utilities.ml file.

      > > Of course, with 4 elements, could write :
      > > let foo = f 12
      > > let bar = f 7
      > > ...
      >
      > That's what I usually do.
      But I've about 20 let ... = f ... to repeat.

      Regards,

      Fabrice
    Your message has been successfully submitted and would be delivered to recipients shortly.