Module Constraints

If I write a Functor module, i am thinking of following constraints to implement Alternative type class (like Haskell). In the following snippet, I am showing the way, I’d like to constrain the types being passed to the functor module.

module type K = { type t<'a>; }
module type ALT = { type t<'a>;  let alt : t<'a> => t<'a> => t<'a>; }

module ALTERNATIVE = (K: AT, L: ALT with t<'a> = K.t<'a>) => {

}

It seems, it is not possible to add such constraints. Is there any alternative to this?

I don’t fully understand what you’re trying to show in this code example, but it’s likely that you need destructive substitution here:

module ALTERNATIVE = (K: AT, L: ALT with t<'a> := K.t<'a>) => {
...

(Note the :=).

You should also take a look at Bastet, which implements the Alternative and many other type classes: https://github.com/Risto-Stevcev/bastet/search?l=Reason&q=alternative