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 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id EFABDBB84 for ; Tue, 17 Jun 2008 13:20:56 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgADAMQ6V0jAXQIniGdsb2JhbACBW5BMAQEBDyCbQA X-IronPort-AV: E=Sophos;i="4.27,657,1204498800"; d="scan'208";a="12161768" Received: from concorde.inria.fr ([192.93.2.39]) by mail2-smtp-roc.national.inria.fr with ESMTP; 17 Jun 2008 13:20:56 +0200 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m5HBKu8a009126 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 17 Jun 2008 13:20:56 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AssAAMQ6V0hTkhUImmdsb2JhbACBW5BMAQEBAQEIBQgHEQObPQ X-IronPort-AV: E=Sophos;i="4.27,657,1204498800"; d="scan'208";a="13946526" Received: from smtp.dslgb.com (HELO cht-smtp-002.bulldogdsl.com) ([83.146.21.8]) by mail1-smtp-roc.national.inria.fr with ESMTP; 17 Jun 2008 13:20:56 +0200 Received: by cht-smtp-002.bulldogdsl.com (Postfix, from userid 1002) id 6C7201E4037; Tue, 17 Jun 2008 12:20:55 +0100 (BST) Received: from [192.168.123.191] (host-84-9-233-143.dslgb.com [84.9.233.143]) by cht-smtp-002.bulldogdsl.com (Postfix) with ESMTP id 1EF1A1E417E; Tue, 17 Jun 2008 12:20:51 +0100 (BST) Message-ID: <48579E13.8070706@ed.ac.uk> Date: Tue, 17 Jun 2008 12:20:51 +0100 From: Jeremy Yallop User-Agent: Mozilla-Thunderbird 2.0.0.14 (X11/20080509) MIME-Version: 1.0 To: caml-list@inria.fr Subject: ANN: patterns v0.4 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 48579E18.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 camlp:01 wiki:01 conjunctive:01 conjunctive:01 generalise:01 ocaml:01 syntax:01 syntax:01 notation:01 haskell:01 integers:01 pred:01 pred:01 bug:01 I'm pleased to announce a new release of `patterns', an OCaml framework for writing extensions to pattern matching using Camlp4. You can download `patterns' from http://code.google.com/p/ocaml-patterns/ Previous releases provided specific extensions to pattern matching ("pattern guards" and "lazy patterns"). From this release onwards "patterns" is not itself an extension, but a means for writing extensions to pattern matching. Some examples are provided with the release: * Pattern-matching for lazy values As in previous releases, but now available as an application of the framework rather than a hardcoded extension. http://code.google.com/p/ocaml-patterns/wiki/LazyPatterns * Conjunctive patterns Conjunctive patterns (as found in F#) generalise "as"-patterns. In standard OCaml the syntax `patt as var' may be used to bind a value simultaneously to both a pattern and a variable; with conjunctive patterns the syntax `patt & patt' may be used to bind a value simultaneously to two patterns. For example, let ((`A a, b) & (c, `B d)) = (`A 3, `B 4) in (a,b,c,d) evaluates to (3, `B 4, `A 3, 4) * "Object patterns" Object patterns bind the results of calling an object's methods to other patterns during a pattern match. This makes it more convenient to use objects as structurally-typed records. The notation mirrors that in Jacques Garrigue's pa_oo extension. For example, let {| x = x; y = _ |} = object method x = 3 method y = 4 method z = 5 end in x + 1 evaluates to 4 * Negative patterns. Matching with negative patterns succeeds if the value does not match the pattern given. For example, let nonzero = function | ~0 -> true | _ -> false in (nonzero 4, nonzero 0) evaluates to (true, false) * N+K patterns The infamous n+k patterns (as found in Haskell) offer a "Peano-number" view of integers. Matching an integer value v against `patt+k' (where k is an integer literal) succeeds, binding patt to v-k, if v>=k. For example let pred = function | x+1 -> x | 0 -> 0 in (pred 10, pred 0) evaluates to (9, 0) Pattern guards are gone for now. I intend to restore them in a future release, implemented as an application of the framework. The "patterns" framework has the following features: * it makes it easy to write extensions to deep pattern matching, otherwise an arduous task. For example, the entire implementation of lazy patterns is just a few lines of code. * it works with original and revised syntax. * pattern-matching extensions written using the framework extend patterns in every context in which patterns can be used: function, match, try/with, let, object, etc. * the extensions that use the framework may be used in any combination: for example, you can choose to use negative and n+k patterns in your program without loading any of the other extensions. Users of previous versions may notice additional improvements. For example, "patterns" no longer modifies the OCaml grammar, so it should coexist more happily with other extensions. Feedback, including bug reports and patches, are very welcome. Jeremy.