I just got it! (invariant/const)
    Janice Caron 
    caron800 at googlemail.com
       
    Wed Apr  9 11:04:07 PDT 2008
    
    
  
On 09/04/2008, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
>  It's the
>  same reason you will be able to pass strings to a pure function.  A string
>  is mutable, but the data it points to is not.
No, that's because of Andrei's
    RULE 3:
    T implicitly converts to and from invariant(T) iff T refers to no
mutable memory
(from accu-functional.pdf)
Therefore, string implicitly casts to invariant(string).
Perhaps then, we may say that the parameters of a pure function should
be invariant, or implicitly castable to invariant?
Of course, it's /possible/ to write a pure function that takes mutable
pointers, e.g.
    int f(char[] s) pure?
    {
        return 42;
    }
but do we care? Wouldn't it just be easier to make that illegal and
insist that the programmer rewrite the function more sensibly?
    
    
More information about the Digitalmars-d
mailing list