Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I really hope modular implicits will make it to the language one day. While OCaml libraries are no stranger to monads they usually only include `bind` and `return`.

Since I'm coming from Haskell I'm used to a vast Applicative and Monad vocabulary and making do with just `bind` and `return` is rather painful. So having a generic library of Monad combinators that one could use with any Monad would be great. Also, being able to just write `show x` is so nice!

Edit: while I often see "modular implicits are being worked on" it is not very clear whether there is a concrete plan to add them to the language. Is there any place in the official OCaml repository / issue tracking system / wiki etc where one could check the status?



> I really hope modular implicits will make it to the language one day

"I'm expecting there will be more news about those in the next six months".

I'd be very surprised not to see modular implicits in 4.04 now that the foundation has been put in place with Flambda[1]:

"Even if you're perfectly happy with OCaml's performance as is, Flambda is still an exciting change. That's because various upcoming language improvements like modular implicits (a feature that brings some of the same benefits as Haskell's typeclasses) will only really perform acceptably well with a good inliner in place".

[1] https://blogs.janestreet.com/flambda/


> Is there any place in the official OCaml repository / issue tracking system / wiki etc where one could check the status?

You can see some things on:

  https://github.com/ocamllabs/ocaml-modular-implicits
but you shouldn't take a lack of activity on there as a sign nothing is happening. For instance, Frederic is actively hacking on the prototype at the moment but hasn't pushed anything to that repo.


That's really great.


I have this library:

https://github.com/Chattered/ocaml-monad

and use it regularly when writing Ocaml. I'd like to get back to it and try to implement some MTL style interfaces (MonadState etc...). Edward Kmett says this is not likely to work, but that sounded like a wager to me.


"monads they usually only include `bind` and `return`"

All you need for a monad is `bind` and `return`. Is the problem that there are not polymorphic monad combinators like `sequence`, `traverse`, etc.?


Yes, there are a lot of operations that can be implemented just in terms of bind and return. It is possible to make some functions more efficient by implementing them directly but having a generic library to fall back to would help with consistency. For instance both `lwt` and `async` are monadic, but `async` provides a richer API. I think having a generic monad library would help to bridge the gap a little bit*

* Since I am only dabbling in OCaml and only use `lwt` and `async` occasionally I'm not entirely sure. But judging by the usual structure of Haskell libraries, it should help


Yes. You can implement sequence/traverse/etc. for each specific monad in OCaml, but if you want to write a generic implementation that will work for any monad then you need typeclass-like functionality.


Not necessarily. You can manually pass in the module for the monad using first-class modules and then define the functions in terms of that. You could also define those operations in terms of monads using a functor if you want it to look more like Haskell.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: