From: Richard W.M. Jones Date: Tue, 1 Apr 2008 10:05:14 +0000 (+0000) Subject: Avoid compiler warning from 'raise Exit; ()' X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=ebfd9926bf4f89aa61371e7d9916fb52eef6937b;p=ocaml-bitstring.git Avoid compiler warning from 'raise Exit; ()' --- diff --git a/pa_bitmatch.ml b/pa_bitmatch.ml index 95b80a5..fc50e68 100644 --- a/pa_bitmatch.ml +++ b/pa_bitmatch.ml @@ -1,5 +1,5 @@ (* Bitmatch syntax extension. - * $Id: pa_bitmatch.ml,v 1.2 2008-04-01 08:56:43 rjones Exp $ + * $Id: pa_bitmatch.ml,v 1.3 2008-04-01 10:05:14 rjones Exp $ *) open Printf @@ -314,9 +314,18 @@ let output_bitmatch _loc bs cases = ) cases in + (* Join them into a single expression. + * + * Don't do it with a normal fold_right because that leaves + * 'raise Exit; ()' at the end which causes a compiler warning. + * Hence a bit of complexity here. + * + * Note that the number of cases is always >= 1 so List.hd is safe. + *) + let cases = List.rev cases in let cases = - List.fold_right (fun case base -> <:expr< $case$ ; $base$ >>) - cases <:expr< () >> in + List.fold_left (fun base case -> <:expr< $case$ ; $base$ >>) + (List.hd cases) (List.tl cases) in (* The final code just wraps the list of cases in a * try/with construct so that each case is tried in