Jannis
11/15/2019, 9:32 AMNikita Smolenskii
11/15/2019, 11:13 AMval result = Either.catch { 1/0 }Jannis
11/15/2019, 11:20 AMJannis
11/15/2019, 11:21 AMkioba
11/15/2019, 12:37 PMcatch itself never fails, and catch indicates the error with the return type 🤔
is it because suspended functions could only be called from a suspended function?Jannis
11/15/2019, 1:19 PMEither.catch only makes sense if it can throw, hence suspend is needed. And Either.catch needs to be suspend because evaluating a suspended function needs to be in suspend because suspend can carry more than just throwing as a side effect.kioba
11/15/2019, 1:30 PM"suspend can carry more than just throwing as a side effect" <- this is interesting, can you suggest somewhere to read more about this?Jannis
11/15/2019, 1:35 PMIO and IO can carry any effect, in terms of power its infinite for IO. (Which is also why I don't like plain IO but the only language capable of providing fast and easy to use effect systems is haskell 😕 ). A good way to view it is: You can lift any, literally any, effect into an IO value (and suspend as it's equivalent in power). Don't know where some good resources are, I think haskell effect systems provide some overview, I'll check that in a secJannis
11/15/2019, 1:48 PMIO models any effect: Exceptions, Concurreny, Parallelism, Delay, State, Input, Output, Launching nukes and more. A return value of IO<A> or suspend fun(): A can do all of those and more. And that is why it has to be marked as such. In haskell with mtl or extensible effects you have more fine grained control where you can define literally any effect and defer lifiting it to IO as late as possible to further constrain functions. That is also (in part) the point for Free monads. You can define and test functions that, for example, return Par<A> which only allows parallel computation effects but not all of IO. That obviously needs to be evaluated to IO later, but for reasoning about that code you know that it can only do parallel computations. Sorry if this is somewhat incoherent 🙂 I am basically just writing down my thoughts on this as they come 😄kioba
11/15/2019, 2:30 PMsuspend this way. I don’t say I understand the whole concept but I see the idea now.
I Suppose that is the part which is used by the Android Compose framework where the effect is a widget tree 🤔Jannis
11/15/2019, 2:43 PMsuspend and IO is definitly quite arbitrary at first (especially if you know that haskell defines it as State<RealWorld, A> which seems even crazier as it's completely eliminated by the compiler and only exists for reasoning about code). I have never written a single line of code for android etc, how does this model look?
I write down thoughts all the time in code ^-^ But that is usually just a reminder for me, mental models for more complex parts of whatever I am writing. Maybe I should just write stuff down somewhere public if its interesting enough 🙂kioba
11/16/2019, 5:35 PMkioba
11/16/2019, 5:39 PMState<WidgetTree, A>, it might be better explained by Leland Richardson’s post http://intelligiblebabble.com/compose-from-first-principles/
the last part is the interesint one with the title of The @Composable AnnotationJannis
11/16/2019, 5:56 PM