2017-05-15 46 views
0

大家好我有这个错误信息,我找不到一种方法来解决这个...这个表达式有类型(String.t * String.t *'a)list - >'b但是表达式需要类型'c list OCAML

这是我的函数:

let station gares dist = 
let rec station2 firstT secondT index gares final = function 
    | [] -> final 
    | tete::reste when (String.equal (getFirstTown tete) firstT) == true 
     && (String.equal (getSecondTown tete) secondT) == true -> if (index + 1) < (List.length gares) then 
      station2 (List.nth gares index) (List.nth gares (index + 1)) (index + 1) gares [email protected][(firstT, secondT, (getDistance tete))] reste 
     else final 
    | tete::reste when (String.equal (getFirstTown tete) firstT) == false 
     || (String.equal (getSecondTown tete) secondT) == false -> station2 firstT secondT index gares final reste 
    | _::_ -> final 
in station2 (List.nth gares 0) (List.nth gares 1) 1 gares [] dist 

,这是我的函数的签名:

val station : string list -> (string * string * int) list -> (string * string * int) list 

我觉得我的错误是从那里部分未来我试图在我的最终列表中添加一个新的元组:

[email protected][(firstT, secondT, (getDistance tete))] 

我在这一点上失去了,我觉得我已经tryed一切......

回答

0

这是来自优先之间的功能应用和(@)运营商的差异。

这行:既然你想通过新的列表作为参数

station2 (List.nth gares index) (List.nth gares (index + 1)) 
    (index + 1) gares [email protected][(firstT, secondT, (getDistance tete))] reste 

被解析为

(station2 (List.nth gares index) (List.nth gares (index + 1)) 
    (index + 1) gares final)@([(firstT, secondT, (getDistance tete))] reste) 

,使用括号:

station2 (List.nth gares index) (List.nth gares (index + 1)) 
    (index + 1) gares ([email protected][(firstT, secondT, (getDistance tete))]) reste 

或者更好的,提取让结合:

let final2 = [email protected][(firstT, secondT, (getDistance tete))] in 
station2 (List.nth gares index) (List.nth gares (index + 1)) 
    (index + 1) gares final2 reste 
+0

谢谢!工作完美:) –

相关问题