Weak type when partitioning a list

Hey, I am looking to get first n elements of a list:

let rec first_helper accum n l =
  match n, l with
    | 0, _ -> accum |> List.rev
    | n, h :: t -> first_helper (h :: accum) (n - 1) t
    | _, _ -> accum |> List.rev

let first = first_helper []

However, I am getting weak types:

val first_helper : 'a list -> int -> 'a list -> 'a list = <fun>
val first : int -> '_weak3 list -> '_weak3 list = <fun>

Why is this so?

Short answer: the value restriction. You can find more details in the manual: https://v2.ocaml.org/manual/polymorphism.html#s%3Aweak-polymorphism

The usual solution, in your case, is to make first an explicit function:

let first n l = first_helper [] n l

Thank you for the explanation.