Closed paf31 closed 7 years ago
Any objection to merging this one or the ST
PR?
None from me!
Thanks!
An alternative would be an "askless reader", which is like Reader
but lacks ask
so you can mutate the environment without anybody seeing it. Here's an example with StringBuilder
in Scala:
case class Build[A](run: StringBuilder => A) extends AnyClass {
def map[B](f: A => B): Build[B] =
Build(s => f(run(s)))
def flatMap[B](f: A => Build[B]): Build[B] =
Build(s => f(run(s)).run(s))
}
object Build {
def run[A](b: Build[A]): (String, A) = {
val s = new StringBuilder()
val r = b.run(s)
(s.toString(), r)
}
}
With an IxMonad
you could alter the type of the record. The benefit of this approach is that you get an indexed monad and can use all the available indexed monad APIs.
Not a bad idea :)
Fixes #8.
Operations are safe since all arguments are used linearly and copied in
build
. Crucially, theBuilder
constructor is not exported.Compare this to my linear DSLs blog post or
purescript-substructural
by @rightfold.This should make it simpler to write certain
RowList
-based operations, like mapping over, zipping or traversing records.