From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p09A0YIh024275 for ; Sun, 9 Jan 2011 11:00:34 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsEAALMVKU1KfVK2kGdsb2JhbACEApI1jgcIFQEBAgkJDAcRBCClAYk8PIIVg1YuhWwBAQMFgRyDN3QEjxQ X-IronPort-AV: E=Sophos;i="4.60,295,1291590000"; d="scan'208";a="86347810" Received: from mail-wy0-f182.google.com ([74.125.82.182]) by mail2-smtp-roc.national.inria.fr with ESMTP; 09 Jan 2011 11:00:29 +0100 Received: by wyf19 with SMTP id 19so19251183wyf.27 for ; Sun, 09 Jan 2011 02:00:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:subject :message-id:references:mime-version:content-type:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=AE1udj0/P44ntCAViQ1jBGGNzQjJWt4DJM59Rhgq8ek=; b=FGSzpKFOoXRW02WAO2Sv/ZKxB7n1fbi91z+9/8rgAqhWmgaV7jDHz30gJFvXGss6jN 1X9vTwahxc4jhxcp6rYbsBH5P6r+HkPWZtyCvKd+Bj2aOv7+VmMEfaFq4SskSWatotbG O6oc0Avrpo+iD4o3AgAJdBXtHYAgmzDsTxwqw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:references:mime-version :content-type:content-disposition:content-transfer-encoding :in-reply-to:user-agent; b=GiVZ5ZZcZP2JnVt8OpN/edw92DwtHD9cvUd5MJFg3me69RJj74Q784L5e9WYrITHK/ N/mSZ61s4BZlmu/G0GAHTVPwVHZQdoMU1jUV365FEVzyjfG2ld6lCqAB/lUE+N6OYHkv jAppOsWZ+gmoqoHoNhhFNZkJR7AmxzlxM2SIM= Received: by 10.227.59.208 with SMTP id m16mr6813894wbh.224.1294567228274; Sun, 09 Jan 2011 02:00:28 -0800 (PST) Received: from eideticdew.org (79.142.225.158.static.router1.bolignet.dk [79.142.225.158]) by mx.google.com with ESMTPS id f35sm19128145wbf.8.2011.01.09.02.00.26 (version=SSLv3 cipher=RC4-MD5); Sun, 09 Jan 2011 02:00:27 -0800 (PST) Date: Sun, 9 Jan 2011 11:00:15 +0100 From: Petter Urkedal To: caml-list@inria.fr Message-ID: <20110109100015.GA25941@eideticdew.org> References: <699537.6718.qm@web111509.mail.gq1.yahoo.com> <87vd20plpv.fsf@mid.deneb.enyo.de> <87ipxzhv2b.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87ipxzhv2b.fsf@mid.deneb.enyo.de> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [Caml-list] Purity and lazyness On 2011-01-08, Florian Weimer wrote: > * Elias Gabriel Amaral da Silva: > > >> As specified, Haskell is not a pure language because every pattern > >> match can have side effects.  The Haskell community is split between > >> those who think that this is a good thing, and those that consider it > >> problematic.  (Obviously, there is a large pure subset, much more > >> useful than Erlang's pure subset and covering almost the whole > >> language; you just avoid lazy I/O and use unsafePerformIO only for > >> correcting the type of functions imported through FFI.) > > > > Wait, a pattern match can have side effects? Can you provide some > > example code? (do you mean, pattern match failure / exceptions / run > > time errors?) > > > > It uses seq instead of pattern matches for clarity. But laziness > means that you could hide the side effect in any pattern match > whatsoever. Do you mean that pattern matching could be used instead of seq in this example? But the example is do demonstrate that hGetContents has side effects, whereas seq is only used to force two different evaluation orders. IIUC, the issue with pattern matching is that it may throw an exception, and exceptions are impure because *if* and *where* they are thrown is hard to predict, and may affect the outcome of a program witch tries to catch it. My experience with Haskell is limited, but I suspect a pattern matching failure is to be considered a bug, and that the exception mechanism doubles as a software diagnostic system, like in many languages. That is, a program should not try to catch those exceptions, except at the for bug-reporting and recovery purposes. From this point of view, shouldn't a pattern match be considered pure in a bug-free program?