recursion - Ocaml - This expression has type 'a list but an expression was expected of type 'a The type variable 'a occurs inside 'a list -


why following code giving me error? note is_sorted function returns either true or false , make_move function returns list of lists. e.g [[0,1,3,2],[1,0,2,3]]

let rec solve_helper b pos n r fn =     if n = 0 b :: r :: fn (*fn final array paths*)     else match pos         [] -> fn        |(h::t) -> if is_sorted h = true h         else h :: r (* error here: r temp array contains 1 path*)              solve_helper  b (make_moves h) (n-1) r              solve_helper b t (n-1) r (*tail recursion*) ;;  let solve_board b n = solver_helper b (make_moves b) n [] [] ;; 

new code:

let rec solve_helper b pos n r fn =     if n = 0 r :: fn (*fn final array paths*)     else match pos         [] -> fn        |(h::t) -> if is_sorted h = true              let j = h :: r in             r :: fn         else             let u = h :: r in             let  k = solve_helper b (make_moves h) (n - 1) r fn in             solve_helper b t (n - 1) r fn(*tail recursion*) ;;  let solve_board b n = solve_helper b (make_moves b) n [] [] ;; 

these lines of code:

    else h :: r (* error here: r temp array contains 1 path*)          solve_helper  b (make_moves h) (n-1) r          solve_helper b t (n-1) r (*tail recursion*) 

do not make sense far can tell. represent call function named r 10 arguments (two of function r itself).

possibly need edit code show compiler seeing.

if code looks this, need rethink part. reads imperative code (a series of things do) rather functional code (an expression consisting of functions applied arguments).


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -