marc0der
11/12/2020, 10:31 PMST
, short for State Token, which is a type that encapsulates local memory mutation and isolates the outside world from it. ST
is also a Monad
, and works very similar to the State
monad.
In my code samples while working with ST
, I am ending up with gnarly nested flatMap
and map
sequences that seem so redundant and difficult to interpret for the reader.
I would love to replace these nested monstrosities with neat for comprehension fx
blocks, and I have been digging into the arrow source code to get some tips about how to achieve this. The problem is that adding fx
binding capabilities to my own data type seems way complicated. Is there an easy way to achieve this? (or at least a guide or tutorial that instructs how to go about equipping your own data types with fx
binding)?
Hoping that someone can advise or shed some light on this.
I really appreciate any help you can provide.Jannis
11/13/2020, 12:17 AMST
? Haskell uses a universally quantified type variable as a Token
which moves this entirely to the type level, so dunno how different scala here is.raulraja
11/13/2020, 9:24 AMmarc0der
11/13/2020, 6:19 PMmarc0der
11/14/2020, 9:25 AMraulraja
11/14/2020, 7:28 PMraulraja
11/14/2020, 7:29 PMmarc0der
11/15/2020, 12:05 PMmain()
function. Also worth noting that the entire algebra is run from the runST
interpreter that lives in the ST
companion object. We shouldn't need to use any suspend
, as this monad doesn't deal with any long running blocking calls. It is only used for segregating local effects like reference mutation from pure code. Hope it makes more sense now!marc0der
11/15/2020, 9:20 PMmarc0der
11/15/2020, 9:21 PMraulraja
11/15/2020, 9:48 PM