Re: "ocaml_beginners":: How to stifle the 'non exhaustive pattern warning' here ?
- 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 ?Yes, I see.
> 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.
>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.
> 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.
> > Of course, with 4 elements, could write :But I've about 20 let ... = f ... to repeat.
> > let foo = f 12
> > let bar = f 7
> > ...
> That's what I usually do.