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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 02E62BC6C for ; Fri, 26 Oct 2007 09:02:28 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAANOpIEfAXQImh2dsb2JhbACBWo0AAgEICimBJw X-IronPort-AV: E=Sophos;i="4.21,330,1188770400"; d="scan'208";a="18616026" Received: from discorde.inria.fr ([192.93.2.38]) by mail4-smtp-sop.national.inria.fr with ESMTP; 25 Oct 2007 23:39:16 +0200 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l9PLdG6I025591 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Thu, 25 Oct 2007 23:39:16 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AswMAEqqIEdT9QHmbGdsb2JhbACBWo0ACwICBhAZgSc X-IronPort-AV: E=Sophos;i="4.21,330,1188770400"; d="scan'208";a="3608917" Received: from pop.bulldoghome.com (HELO bdmail1.accesst.com) ([83.245.1.230]) by mail2-smtp-roc.national.inria.fr with ESMTP; 25 Oct 2007 23:39:16 +0200 Received: from host-84-9-233-205.bulldogdsl.com ([84.9.233.205] helo=[192.168.123.191]) by bdmail1.accesst.com with esmtpa (Exim 4.50) id 1IlAMM-0000c3-87 for caml-list@inria.fr; Thu, 25 Oct 2007 22:35:22 +0100 Message-ID: <47210CA4.60707@ed.ac.uk> Date: Thu, 25 Oct 2007 22:37:40 +0100 From: Jeremy Yallop User-Agent: Mozilla-Thunderbird 2.0.0.6 (X11/20071009) MIME-Version: 1.0 To: caml-list@inria.fr Subject: ANN: lazy patterns (patterns v 0.3) Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 47210D04.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 ocaml:01 syntax:01 bug:01 wiki:01 0.3:98 016:98 rec:01 assert:01 constructor:01 delayed:01 lazy:02 lazy:02 define:02 caml:02 I'm pleased to announce a new release of `patterns', an OCaml extension providing general-purposes additions to pattern matching. This release includes a new feature, "lazy patterns". You can download patterns from http://code.google.com/p/ocaml-patterns/ Lazy patterns extend OCaml pattern syntax with the keyword "lazy", mirroring the use of lazy in expressions. With this extension patterns can be used to deconstruct lazy values; for example, you can define a function that behaves like Lazy.force as follows let force (lazy x) = x or, given a type of lazy lists in the "odd style": type 'a llist = Nil | Cons of 'a * lazy llist you can write a lazy map function: let rec map f = function | Nil -> Nil | Cons (h, lazy t) -> Cons (f h, lazy (map f t)) You can use "lazy" anywhere you can use a constructor: in nested patterns, or-patterns, patterns for "let", "function", "match", "try/with", etc. Lazy patterns can also be used with the other extension provided in the current release, pattern guards: you can write, for example, match v with | A (x, y) with lazy (z,w) = f x -> e Paradoxically, lazy patterns make pattern-matching more eager, since they force evaluation of delayed values. However, no more forcing than necessary (for some suitable definition thereof) will occur: the following will return "true", for example. match lazy 3, lazy (assert false) with | lazy 2, lazy x -> false | lazy 3, _ -> true Documentation for lazy patterns will be available soon. Comments are welcome, bug reports especially so. A caveat: due to the translation used, lazy patterns can sometimes give rise to spurious warnings. For example, for the following function function lazy (Some _) -> 1 | lazy None -> 0 OCaml gives the warning "Warning X: bad style, all clauses in this pattern-matching are guarded." It is of course possible to avoid these warnings by using "-w x" or by adding redundant match cases. For information on pattern guards see the previous announcements v0.1: http://groups.google.com/group/fa.caml/msg/b0ec5324180bfeba v0.2: http://groups.google.com/group/fa.caml/msg/016e76d7a51559c8 and the documentation on the website http://code.google.com/p/ocaml-patterns/wiki/PatternGuards Jeremy.