You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have recently gotten a great deal out of censor mempty . listen with MonadWriter.
Essentially I want to delimit part of the log in a subcomputation, but make use of that part of the log (in my case capture some of it in the result). My main example is HM esque type checking. A simplified example:
generalise::MonadWriter (SetVar) m=>mType->mScheme
generalise mt =do
(t, vars) <- (censor mempty. listen) mt
pure (Scheme vars t)
Here generalise captures all of the metavariables the subcomputation would introduce, and uses them to quantify the result.
It is the flip side of an instantiate that would open a scheme with fresh variables and tell them.
Main idea (general case is a field of the log):
f::MonadWriterwm=>Lens'wu->u->ma->m (a, u)
f l x = censoring l (const x) . listening l
The const could be a function, but I almost always use mempty (aka const mempty).
It would be kind of arbitrary to use a function here, since you're not retrieving a function of it.
This is normally a field of the log, but doesn't necessarily have to be a monoid itself, hence I haven't made it mempty.
Maybe it would make sense to have the mempty version additionally, since a record monoid is often a pointwise record of monoids.
f':: (MonadWriterwm, Monoidu) =>Lens'wu->ma->m (a, u)
f' l = censoring l mempty. listening l
-- = f l mempty
(The mempty version is to this what scribe is to tell)
Bikeshedding: Not sure what to call either of these. capturing, delimiting, censored, silently, de-scribing, observing, simulating, recording?
Ideally something that indicates both that the log doesn't escape & that it is captured and returned.
With MTL (censor mempty . listen) is actually a form of runWriterT - otherwise I would have also proposed this for mtl.
There is probably a zoom/magnify writer analogue with a setter, but it doesn't address this use case, as there aren't analagous (eval/exec/)runStateT zooms that merely take the present state and don't change the overall state.
The text was updated successfully, but these errors were encountered:
I have recently gotten a great deal out of
censor mempty . listen
withMonadWriter
.Essentially I want to delimit part of the log in a subcomputation, but make use of that part of the log (in my case capture some of it in the result). My main example is HM esque type checking. A simplified example:
Here
generalise
captures all of the metavariables the subcomputation would introduce, and uses them to quantify the result.It is the flip side of an
instantiate
that would open a scheme with fresh variables andtell
them.Main idea (general case is a field of the log):
The const could be a function, but I almost always use
mempty
(akaconst mempty
).It would be kind of arbitrary to use a function here, since you're not retrieving a function of it.
This is normally a field of the log, but doesn't necessarily have to be a monoid itself, hence I haven't made it mempty.
Maybe it would make sense to have the mempty version additionally, since a record monoid is often a pointwise record of monoids.
(The mempty version is to this what
scribe
is totell
)Bikeshedding: Not sure what to call either of these. capturing, delimiting, censored, silently, de-scribing, observing, simulating, recording?
Ideally something that indicates both that the log doesn't escape & that it is captured and returned.
With MTL (censor mempty . listen) is actually a form of runWriterT - otherwise I would have also proposed this for mtl.
There is probably a zoom/magnify writer analogue with a setter, but it doesn't address this use case, as there aren't analagous (eval/exec/)runStateT zooms that merely take the present state and don't change the overall state.
The text was updated successfully, but these errors were encountered: