What is the connection between laziness and purity?

You’re right, from a modern POV this doesn’t really make sense. What is true is that lazy-by-default would make reasoning about side-effectful code a nightmare, so lazyness does require purity – but not the other way around. What does require lazyness though is the way Haskell in versions 1.0–1.2, following its predecessor Miranda, emulated IO … Read more

Kotlin: lateinit to val, or, alternatively, a var that can set once

You can implement own delegate like this: class InitOnceProperty<T> : ReadWriteProperty<Any, T> { private object EMPTY private var value: Any? = EMPTY override fun getValue(thisRef: Any, property: KProperty<*>): T { if (value == EMPTY) { throw IllegalStateException(“Value isn’t initialized”) } else { return value as T } } override fun setValue(thisRef: Any, property: KProperty<*>, value: … Read more

Is everything in Haskell stored in thunks, even simple values?

Official answer It’s none of your business. Strictly implementation detail of your compiler. Short answer Yes. Longer answer To the Haskell program itself, the answer is always yes, but the compiler can and will do things differently if it finds out that it can get away with it, for performance reasons. For example, for ”’add … Read more