# Immediately Opened Functors - why aren't they possible?

**URL:** <https://discuss.ocaml.org/t/immediately-opened-functors-why-arent-they-possible/1391>\
**Category:** Learning\
**Created:** [January 4, 2018, 9:26pm UTC](https://discuss.ocaml.org/t/immediately-opened-functors-why-arent-they-possible/1391 "2018-01-04T21:26:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ubsan](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ubsan/32/700_2.png) [@ubsan](https://discuss.ocaml.org/u/ubsan)\
**Post date:** [January 4, 2018, 9:26pm UTC](https://discuss.ocaml.org/t/immediately-opened-functors-why-arent-they-possible/1391/1 "2018-01-04T21:26:28Z")

</div>

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:

```ocaml
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)

```

---

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [January 4, 2018, 11:59pm UTC](https://discuss.ocaml.org/t/immediately-opened-functors-why-arent-they-possible/1391/2 "2018-01-04T23:59:09Z")

</div>

See [https://stackoverflow.com/questions/32102839/is-it-possible-to-open-or-use-a-functor-without-an-intermediate-module-in-ocaml](https://stackoverflow.com/questions/32102839/is-it-possible-to-open-or-use-a-functor-without-an-intermediate-module-in-ocaml)

---

<div class="post-metadata">

**Author:** ![didier-wenzek](https://avatars.discourse-cdn.com/v4/letter/d/9de0a6/32.png) [@didier-wenzek](https://discuss.ocaml.org/u/didier-wenzek)\
**Post date:** [January 5, 2018, 8:21am UTC](https://discuss.ocaml.org/t/immediately-opened-functors-why-arent-they-possible/1391/3 "2018-01-05T08:21:41Z")

</div>

Indeed it would be great!

Jeremy Yallop and Runhang Li presented a proposal at the OCaml Workshop 2017.  
Here are the paper and the pull request:

- [Extending OCaml’s `open`](https://www.cl.cam.ac.uk/~jdy22/papers/extending-ocamls-open.pdf)
- [Extending `open` to accept arbitrary module expression](https://github.com/ocaml/ocaml/pull/1506)
