Grafting Functional Support on Top of an Imperative Language

Janice Caron caron800 at googlemail.com
Sat Apr 5 07:55:23 PDT 2008


On 05/04/2008, Christopher Wright <dhasenan at gmail.com> wrote:
>  If you have a function that is amoral, it would be pure if you gave it all
> invariant arguments, but you could give it const or mutable arguments as
> well.

That's probably not possible. Consider the declaration:

    pure invariant(C) f(invariant(C) x)

Exactly how could the compiler deduce a version with const or mutable
arguments? Would it be (a)

    invariant(C) f(const(C) x)

or would it be (b)

    const(C) f(const(C) x)

? If you answered (a), consider that the function body might have been:

    pure invariant(C) f(invariant(C) x)
    {
        return x;
    }

Conversely, if you answered (b), consider that the function body might
have been:

    pure invariant(C) f(invariant(C) x)
    {
        return x.idup;
    }

(assuming idup is implemented for class C)



More information about the Digitalmars-d mailing list