Newsgroups: comp.lang.scheme,comp.lang.functional
Path: cantaloupe.srv.cs.cmu.edu!nntp.club.cc.cmu.edu!hudson.lm.com!news.pop.psu.edu!psuvax1!uwm.edu!spool.mu.edu!howland.reston.ans.net!swrinde!ihnp4.ucsd.edu!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Subject: Re: when to use state?
Message-ID: <9500118.16942@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU
Organization: Computer Science, University of Melbourne, Australia
References: <3dfv8i$ifp@nkosi.well.com> <ROCKWELL.94Dec28104921@nova.umd.edu> <JDONHAM.94Dec28135842@hadron.us.oracle.com> <9436516.26620@mulga.cs.mu.OZ.AU> <3e45ts$9e@agate.berkeley.edu>
Date: Sun, 1 Jan 1995 07:43:09 GMT
Lines: 34
Xref: glinda.oz.cs.cmu.edu comp.lang.scheme:11673 comp.lang.functional:5465

bh@anarres.CS.Berkeley.EDU (Brian Harvey) writes:

>fjh@munta.cs.mu.OZ.AU (Fergus Henderson) writes:
>>	(1) The compiler can warn if the programmer fails to declare
>>	    a side-effect free function as "pure".
>
>This is probably a stupid question, but if the compiler can figure that
>out by itself, why should I have to declare it in the first place?

Several reasons:

	(1) Documentation

		The declaration is good documentation.
		In fact, it's better than a comment, because it
		is verified by the compiler, so it is guaranteed to
		be true.

	(2) Ease & efficiency of implementation

		In general, checking is easier than inference,
		especially when you start talking about separate compilation.

	(3) Error-checking

		If a function that you think should be pure actually
		depends on global state, the compiler will tell you about it.
		
The same principles apply to other sorts of declarations such as
type declarations, although the trade-offs differ (e.g. (3) is a lot
more important for type declarations than for "purity" declarations).

-- 
Fergus Henderson - fjh@munta.cs.mu.oz.au
