Pure functions in D

Brian Palmer d at brian.codekitchen.net
Mon Sep 22 07:23:59 PDT 2008


bearophile Wrote:

> >(Invariant means immutable.)<
> 
> This specification, near the top of the article, that tells that a word means something else is a WARNING SIGN large as a wall that tells that that name is wrong and it has to change. Now I think D2 will sooner of later have to use the "immutable" word instead, as Python and Java communities too use.

That's exactly what went through my head when I saw this line of the article and I agree 100%, invariant needs to change to immutable in D2 before it becomes too late.

> >A pure function can throw an exception (purity does not imply nothrow).<

Since this wasn't touched on in the article, I want to point out that Haskell allows "pure functions" to throw exceptions, but not catch them. We need the same limitation in D2 pure functions -- since the exceptions can only be caught in impure code, it's OK that the pure function threw instead of returning. What can't happen is we can't have pure functions catching exceptions, since they can then return a different value when, for example, an out-of-memory exception is thrown.

-- Brian



More information about the Digitalmars-d mailing list