mmark
mmark copied to clipboard
Implement Monadic Extensions/Rendering
Closes #46.
I hadn't seen #74 until now, but it seems this is more or less the same idea. So most of the comments on it still apply. Instead of duplicating the API we could just expose the monadic interface, but I'm concerned that the usability for those not so familiar with monad transformers and the like, might suffer. However, I didn't want to break the existing API.
A couple of other things:
- [ ] Names: I used the extension
Ton types andMon functions but maybe they should all just beM? - [ ] Comments: I think I updated them all and added basic ones for new functions, but maybe the comments for the pure interface and the monadic one should be switched?
- [x] Optimization: I tried benchmarking and I didn't see a noticeable performance difference (in fact, the benchmarks got faster so I might've done something wrong)
- [ ] Alternative API: I also experimented with CPS encoding
EndoMas(a -> m a) -> a -> m ain order to reassociate the binds soEndoM f <> (EndoM <> g <> EndoM h)doesn't end up asEndo (\x -> (h x >>= g) >>= f)but ratherEndoM (\k x -> g (h (f k)) x). This seemed to be slightly faster (take that with a grain of salt) and might allow a*TransMAPI similar to the*RenderMAPI. - [ ] Tests: Since
mtlis already a dependency, would some test usingState,Reader,Writer, etc. be sufficient?