From ebfd9926bf4f89aa61371e7d9916fb52eef6937b Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 1 Apr 2008 10:05:14 +0000 Subject: [PATCH] Avoid compiler warning from 'raise Exit; ()' --- pa_bitmatch.ml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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 -- 1.8.3.1