# Sort: 'a list vs sort: int list

**URL:** <https://discuss.ocaml.org/t/sort-a-list-vs-sort-int-list/12227>\
**Category:** Learning\
**Created:** [May 25, 2023, 12:56am UTC](https://discuss.ocaml.org/t/sort-a-list-vs-sort-int-list/12227 "2023-05-25T00:56:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeroexcuses](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/zeroexcuses/32/1692_2.png) [@zeroexcuses](https://discuss.ocaml.org/u/zeroexcuses)\
**Post date:** [May 25, 2023, 12:56am UTC](https://discuss.ocaml.org/t/sort-a-list-vs-sort-int-list/12227/1 "2023-05-25T00:56:29Z")

</div>

I can not get the following example from the OCaml manual to work:

```auto
# let rec sort lst =
    match lst with
      [] -> []
    | head :: tail -> insert head (sort tail)
  and insert elt lst =
    match lst with
      [] -> [elt]
    | head :: tail -> if elt <= head then elt :: lst else head :: insert elt tail
  ;;

```

^-- this part works so far

```auto
# sort l;;
- : string list = ["a"; "etc."; "is"; "tale"; "told"]

```

^-- this is line from OCaml manual. I can’t run this line because the `<` in my case seems to force to `int`, whereas in the OCaml manual, somehow the `<` is polymorphic.

Question: how do I define sort/insert above so that it is polymorphic ? Thanks!

EDIT: forgot actual link: [OCaml - The core language](https://v2.ocaml.org/releases/5.0/htmlman/coreexamples.html)

---

<div class="post-metadata">

**Author:** ![askvortsov](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/askvortsov/32/3034_2.png) [@askvortsov](https://discuss.ocaml.org/u/askvortsov)\
**Post date:** [May 25, 2023, 1:11am UTC](https://discuss.ocaml.org/t/sort-a-list-vs-sort-int-list/12227/2 "2023-05-25T01:11:49Z")

</div>

Which module is the `<=` operator coming from, in this case? E.g. if you hover over it?

`Stdlib.(<=)` should be polymorphic: [OCaml library : Stdlib](https://v2.ocaml.org/releases/5.0/api/Stdlib.html)

But the `Base` equivalents are not: [Removing polymorphic compare from Core](https://discuss.ocaml.org/t/removing-polymorphic-compare-from-core/2994)

---

<div class="post-metadata">

**Author:** ![zeroexcuses](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/zeroexcuses/32/1692_2.png) [@zeroexcuses](https://discuss.ocaml.org/u/zeroexcuses)\
**Post date:** [May 25, 2023, 1:23am UTC](https://discuss.ocaml.org/t/sort-a-list-vs-sort-int-list/12227/3 "2023-05-25T01:23:27Z")

</div>

If I hit goto def, it jumps me to `lib/base/import0.ml` . I do have an `open Core` at the top of the file.

Is there a polymorphic (\<=) in Core ?

---

<div class="post-metadata">

**Author:** ![askvortsov](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/askvortsov/32/3034_2.png) [@askvortsov](https://discuss.ocaml.org/u/askvortsov)\
**Post date:** [May 25, 2023, 1:36am UTC](https://discuss.ocaml.org/t/sort-a-list-vs-sort-int-list/12227/4 "2023-05-25T01:36:02Z")

</div>

> [@zeroexcuses](#):
>
> I do have an `open Core`

Yeah, that’d do it.

> [@zeroexcuses](#):
>
> Is there a polymorphic (\<=) in Core

You can locally open the [`Poly` module](https://ocaml.org/p/base/latest/doc/Base/Poly/index.html)
