From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 34FD9BC6B for ; Sat, 1 Dec 2007 17:09:04 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAK4VUUfUnw6FhWdsb2JhbACCOY0RAQgCCA8TBw X-IronPort-AV: E=Sophos;i="4.23,238,1194217200"; d="scan'208";a="5139009" Received: from pih-relay06.plus.net ([212.159.14.133]) by mail1-smtp-roc.national.inria.fr with ESMTP; 01 Dec 2007 17:09:04 +0100 Received: from [80.229.56.224] (helo=beast.local) by pih-relay06.plus.net with esmtp (Exim) id 1IyUtr-0008Df-4h for caml-list@yquem.inria.fr; Sat, 01 Dec 2007 16:09:03 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: MicMatch Date: Sat, 1 Dec 2007 16:00:00 +0000 User-Agent: KMail/1.9.5 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200712011600.00627.jon@ffconsultancy.com> X-Spam: no; 0.00; wiki:01 ocaml:01 ocaml:01 cater:98 frog:98 syntactic:01 defines:01 matched:01 lazy:02 lazy:02 disables:02 implemented:02 match:02 match:02 checking:02 I just stumbled upon this Wiki page discussing MicMatch: http://ocaml.pbwiki.com/Micmatch and noted that the implementation of views disables exhaustiveness checking. I think it is worth keeping the static checking of view patterns. So MicMatch uses definitions like: type 'a lazy_list = Empty | Cons of 'a * 'a lazy_list lazy_t let view Empty = fun l -> Lazy.force l = Empty let view Cons = fun l -> match Lazy.force l with Cons x -> Some x match ll with %Empty -> ... | %Cons (x, %Empty) -> ... | %Cons (x1, %Cons (x2, %Empty)) -> ... | _ -> ... where F# would use: let (|PEmpty|PCons|) l = match Lazy.force l with | Empty -> PEmpty | Cons(h, t) -> PCons(h, t) This basically defines a new sum type and every time a view pattern is encountered, it is converted using this function into the new sum type and then matched over. This means you cannot mix view and non-view patterns in the same match but you do get to keep exhaustiveness checking. Having said all of that, the only application of F#-style views in OCaml that I can think of is simply matching lazy values, which could be implemented more easily and with no syntactic overhead. There are other applications that MicMatch might not cater for. Specifically, factoring patterns and parameterizing patterns over values. For example, you might want an active pattern than handles commutativity: Commute(p1, p2) => p1, p2 | p2, p1 -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e