Type error in OCaml

I am trying to create a list of indexes that meet the minimum values.

let rec max_index l =
let rec helper inList min builtList index = 
match inList with
| [] -> builtList
| x :: xs ->
    if (x < min) then
        helper xs x index :: builtList index + 1 //line 63
    else
        helper xs min builtList index + 1
in helper l 100000 [] 0;;

This gives me the following error for line 63.

Error: This expression has type 'a list -> 'a list
       but an expression was expected of type 'a
       The type variable 'a occurs inside 'a list -> 'a list

Expected expression like 'a? I do not know why this is so. I guess this has something to do withindex::builtList

+3
source share
2 answers
        helper xs x index :: builtList index + 1 //line 63
    else
        helper xs x index min index + 1

The problem you are facing is that you are trying to pass a non-list of your helper function on line 65 ( min), trying to pass int listthe same parameter on line 63. Try replacing minwith [min]or min::[].

Edit:

, , (. ), helper xs x index index :: builtList, helper xs x index :: builtList index + 1. , , .. :: +, :

        helper xs x (index :: builtList) (index + 1) //line 63
    else
        helper xs x index min (index + 1)
+5

. , .

if (x < min) then
    helper xs x (index :: builtList) (index + 1)
else
    helper xs min builtList (index + 1)
+2

All Articles