HalogenM's relation to monad transformers?

halogen

#1

thomashoneyman [12:39 PM]
Oh, I see, as I return to the thread. You guys are storing the actual function Route -> Effect Unit in ReaderT, so you’re pulling out the function and then running it.
:thumbsup:
“you guys” = people involved in the example snippets I’ve seen :slightly_smiling_face:

natefaubion [12:40 PM]
Anything that uses Halogen.hoist will need to be equivalent to the ReaderT pattern in some way
because it’s not a true transformer

thomashoneyman [12:41 PM]

because it’s not a true transformer

HalogenM isn’t, or ReaderT isn’t?

natefaubion [12:41 PM]
HalogenM

thomashoneyman [12:41 PM]
I’m assuming the former
Do you mind elaborating on that a little?
What does it mean to not be a “true” transformer?
In that it can’t be applied to the Identity monad or something along those lines?

natefaubion [12:42 PM]
HalogenM obeys the transformer laws, but there is no function like runUI :: Component q i o m -> m (HalogenIO ...)
that is, you can’t runUI in your m

thomashoneyman [12:43 PM]
Oh, so more in the sense that HalogenM can be a monad transformer so long as it’s at the top of the stack

natefaubion [12:43 PM]
HalogenM is a valid MonadTrans, but it does not have an eliminator that you generally expect from transformers
it only works over natural transformations to Aff
this means you can’t use continuation based implementations like StateT
And you’d have to implement MonadState in terms of a mutable ref or something
likewise, it cannot support MonadReader, only MonadAsk

thomashoneyman [12:45 PM]
This is super interesting, thank you for explaining

And you’d have to implement MonadState in terms of a mutable ref or something

I thought this was more because HalogenM already has an instance for this
but supposing it didn’t have the instance and you wanted HalogenM over State, then in that case you’d have to implement with a mutable ref? (edited)

natefaubion [12:46 PM]
Sorry, yes, HalogenM uses MonadState for component state, that’s true, I mean more that using StateT as m won’t behave as you might expect (edited)
and that’s because you can’t run it through the StateT continuation
each step resets the state

thomashoneyman [12:47 PM]
I think I see. I’ll need to dig into some of the threads you’ve dropped here to educate myself a bit more though.

natefaubion [12:52 PM]
@thomashoneyman https://github.com/slamdata/purescript-halogen/issues/386

thomashoneyman [12:54 PM]
thanks for this!
there’s such a wealth of knowledge in the Halogen issues :laughing: