4 ms·
Lazy is easy: it's call-by-name evaluation, i.e. (lambda x.M)N -> M[N/x] with caching, ie. each argument is evaluated at most once. Purity is more subtle. I do
by mafribe 11y ago
Lazy is easy: it's call-by-name evaluation, i.e. (lambda x.M)N -> M[N/x] with caching, ie. each argument is evaluated at most once.
Purity is more subtle. I don't think there's an agreed upon definition. [1] essentially ties purity to the equivalency of
call-by-name, call-by-need and call-by-value evaluation orders (ignoring divergence and errors). I'm not totally sure that is the right definition.
[1] A. Sabry, What is a Purely Functional Language?
- dllthomas 11y agoThe most proximate question here, with respect to purity, is "can you do O(1) mutation (outside of the narrow case of replacing a thunk with its result)?" The theory is far more interesting when we say "no", but the answer in the case of Haskell is "yes".
- tome 11y agoWith those definitions pure and lazy languages can certainly do mutation and have effects, viz. the IO and ST monads.