# Who needs polymorphics types? (when we have modules)

**URL:** <https://discuss.ocaml.org/t/who-needs-polymorphics-types-when-we-have-modules/7706>\
**Category:** Learning\
**Created:** [April 19, 2021, 4:28pm UTC](https://discuss.ocaml.org/t/who-needs-polymorphics-types-when-we-have-modules/7706 "2021-04-19T16:28:08Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![octachron](https://avatars.discourse-cdn.com/v4/letter/o/49beb7/32.png) [@octachron](https://discuss.ocaml.org/u/octachron)\
**Post date:** [April 19, 2021, 5:20pm UTC](https://discuss.ocaml.org/t/who-needs-polymorphics-types-when-we-have-modules/7706/3 "2021-04-19T17:20:02Z")

</div>

You cannot write the following function with monomorphic functor currently:

```ocaml
type 'a t =
  | Elt of 'a
  | List of 'a list t
let rec list: 'a. 'a t -> 'a list = function
  | Elt x -> [x]
  | List l -> List.concat (list l)

```

since the corresponding recursive functor is unsafe:

```ocaml
module Listify(T: sig type t end) = struct
  type t = T.t list
end
module rec L: functor (T: sig type t end) -> sig
  type t =
    | Elt of T.t
    | List of L(Listify(T)).t
  val list: t -> T.t list
end = functor (T: sig type t end) -> struct
  type t =
    | Elt of T.t
    | List of L(Listify(T)).t
  let rec list = function
    | Elt x -> [x]
    | List l ->
      let module Sub = L(Listify(T)) in
      List.concat (Sub.list l)
end

```

But even without this limitation, modules are far more complex than polymorphic types. Expressing the simple feature (polymorphic types) using the complex one (modules and functors) for the sake of losing type inference (and we also need explicit type applications with functors) does not seem like a good idea.

---

_[View the full topic](https://discuss.ocaml.org/t/who-needs-polymorphics-types-when-we-have-modules/7706)._
