← Back to context

Comment by munchler

7 months ago

Are these languages pure in the functional sense? E.g. Do they allow/encourage mutation? My understanding is that APL permits mutable state and side effects, but maybe they are rarely used in practice? If you're modifying the contents of an array in-place, I don't think it's reasonable to consider that functional.

> My understanding is that APL permits mutable state and side effects ... If you're modifying the contents of an array in-place, I don't think it's reasonable to consider that functional.

      a←'hello'
      a[1]←'c'

This does _not_ modify the array in-place. It's actually the same as:

     a←'hello'
     a←'c'@1⊢a

which is more obviously functional. It is easy to convince yourself of this:

      a←'hello'
      b←a
      b[1]←'j'
      a,b

returns 'hellojello' and not 'jellojello'.

APL arrays are values in the same sense as value types in any functional language. You don't explicitly modify arrays in-place; if they happen to have a refcount of 1 operations may happen in-place as an optimization, but not in a manner which observably alters program behavior.

Futhark, SaC, and Accelerate have purely functional semantics. Futhark has something called "in-place updates" that operationally mutate the given array, but semantically they work as if a new array is created (and are statically guaranteed to work this way by the type system).