I was playing with monads, and I was curious - why can’t we
open functor module expressions? Why do we have to give them a name, or include them? Is there anything preventing us from doing this?
Code I was playing with:
module type Type = sig type t end module type Monad = sig type 'a t val pure : 'a -> 'a t val (>>=) : 'a t -> ('a -> 'b t) -> 'b t end module Monad_result(T: Type) : Monad = struct type 'o t = ('o, T.t) result let pure x = Ok x let (>>=) res f = match res with | Ok o -> f o | Err e -> Err e end (* what I have to write *) module M = Monad_result(struct type t = int end) open M (* what I'd like to write *) open Monad_result(struct type t = int end)