() => Ais a good candidate?
defis enough to ensure referential transparency, which it isn't
def + by nameis, and in that model
valis the equivalent of
IO[A] = () => A, which has the limitations outlined above
def t: Awith
val t: () => A)
Idand in code using
IO, and see how they differ (because the latter takes great care to satisfy various laws under a broad range of operational conditions, and the former doesn't).
Here there are a few implementations of
IO, the first one of which is essentially with
() => A. But I do think that looking at the implementation is not the right way to understand
IO at first
IO[A]is a program.
Option[A]is a program. These programs can be composed using certain operations. You build your code by building mini-programs, assembling bigger programs out of small ones, and translating programs from one "language" to another (eg.