0
votes

I have a problem on my program, when I call on the Ocaml terminal "#matrix81 cache;;" it gives me the error: "This expression has type cache list but is here used with type cache list" This is my code. Any help?

  let rec makeLine w = 
    let y = w - 1 in
    if w <> 0 then 0::(makeLine y)
    else []

;; 


    let rec makeMatrix w h = 
        let y = h - 1 in
        if h <> 0 then (makeLine w)::(makeMatrix w y)
        else []
    ;;

    let rec checkCache lc d t = 
        match lc with
        [] -> 0
        |x::xs -> if (x.difficulty = d) && (x.terrain = t) then (checkCache xs d t) + 1
              else (checkCache xs d t)

    ;;

    let rec checkLine lc d t line =
        match line with 
        []->[]
        |x::xs -> let nt = t +. 0.5 in
              let v = 5.0 in
              if (nt < v) then
              let nx = (checkCache lc d t) in
              (nx)::(checkLine lc d nt xs)
              else []
    ;;


    let rec matrix81Aux m d lc = 
        match m with
        [] -> []
        |x::xs -> let nd = d +. 0.5 in
              let v = 5.0 in
              if (nd < v) then
              (checkLine lc d 1.0 x)::(matrix81Aux xs nd lc)
              else []
    ;;


    let matrix81 lc = 
        let m = makeMatrix 9 9 in
        matrix81Aux m 1.0 lc
    ;;
1
Please do not vandalize your post. Note that once you post a question or answer to this site, those posts become part of the collective efforts of others who have also contributed to that content. Posts that are potentially useful to others should not be removed except under extraordinary circumstances. Even if the post is no longer useful to the original author, that information is still beneficial to others who may run into similar problems in the future - this is the underlying philosophy of Stack Exchange. - Matt

1 Answers

1
votes

You don't show the definition of the type cache (or give the line number for the error).

The most common cause of this strange type of error message is that you have defined the same type name twice. This often happens when working from the toplevel and loading files with #use.

It's also possible you're defining the name cache twice some other way.

Recent versions of OCaml add an integer to the type name, to (try to) clarify that two different types are involved:

# type cache = A | B;;
type cache = A | B
# let f = function A -> 3 | B -> 4;;
val f : cache -> int = <fun>
# type cache = C | D;;
type cache = C | D
# let g x = match x with C -> f x | D -> 14;;
Error: This expression has type cache/1023
       but an expression was expected of type cache/1018