Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Fabio Labella
@SystemFw
for example you can't do async or concurrency
error handling is weirder
and the api you get is much more limited
Vinayak Pathak
@vinayakpathak
i see i see
so above I asked "what's the minimal thing that would ensure referential transparency"... perhaps () => A is a good candidate?
Fabio Labella
@SystemFw
for synchronous stuff only though
Vinayak Pathak
@vinayakpathak
yeah ok
Fabio Labella
@SystemFw
and without errors
Vinayak Pathak
@vinayakpathak
true
Fabio Labella
@SystemFw
but yeah, at the end of the day you need suspension
because you want to separate evaluation and execution
that being said, this is trying to understand (imho) how IO is implemented
rather than its semantics
Vinayak Pathak
@vinayakpathak
i see
Drew Boardman
@drewboardman
is he saying def is not RT because it's lazy and not memoized?
because I don't see how that follows
Fabio Labella
@SystemFw
no
we're trying to discuss where def is enough to ensure referential transparency, which it isn't
Vinayak Pathak
@vinayakpathak
def + by value is not referentially transparent because you will evaluate the arguments prematurely
Fabio Labella
@SystemFw
exactly
def + by name is, and in that model val is the equivalent of <-
but the whole thing is then easier to understand by considering IO[A] = () => A , which has the limitations outlined above
(you can replace all def t: A with val t: () => A)
Paul Snively
@paul-snively
Maybe it's worth looking at the implementation of Id, which you might think of as "the fake monad."
Drew Boardman
@drewboardman
Id is a datatype
Paul Snively
@paul-snively
So is IO, and they both have Monad instances.
Among others.
The point is, you can compare what happens in various scenarios in code using Id and 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).
Fabio Labella
@SystemFw

https://github.com/SystemFw/Scala-World-2019/blob/master/Examples.scala

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

which is great, it means we actually have an abstraction
Christopher Davenport
@ChristopherDavenport
I’m missing a lot of context. But Id is by no means a fake monad.
Paul Snively
@paul-snively
Looking at the implementation of IO is a horrible way to understand it, I think.
Vinayak Pathak
@vinayakpathak
@SystemFw nice, that's great. that answers a lot of my questions. I'm probably going to start thinking of IO as () => A until I realize it's a huge simplification
Fabio Labella
@SystemFw
well, I wouldn't recommend that :)
Paul Snively
@paul-snively
@ChristopherDavenport: Sure. I should have put "fake" in scare-quotes, at the very least.
Fabio Labella
@SystemFw
this is a general point about FP btw
trying to start using algebraic thinking
it's actually the biggest benefit imho, one of the ultimate goals
and it's hard to get your head around that at first
switching mindset from executing actions to composing programs
and I think that the earlier you start trying, the better
Paul Snively
@paul-snively
@vinayakpathak: Just to give one example: the () => A model certainly doesn't give you IO(1) |+| IO(1).
Christopher Davenport
@ChristopherDavenport
Or race, or async, or continual. Without even considering +Effect
Or for that matter Bracket
Fabio Labella
@SystemFw
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. fs2.Stream to IO, or Option to Either)
Vinayak Pathak
@vinayakpathak
@SystemFw yeah, but with IO you get to write things that look like they are about executing actions but they're really about composing programs... so it's a little confusing
Fabio Labella
@SystemFw
I have a suggestion for that
avoid for
completely avoid it for the time being
Vinayak Pathak
@vinayakpathak
ah interesting