基本循环中的OCaml错误

时间:2015-06-14 08:10:28

标签: ocaml

我是OCaml的新手。 我正在以这种方式工作:我在示波器中有“tab”表示2D地图,以及三个参数x,y和u。

x和y代表玩家的位置,u代表炸弹的方向(右,左上等)。我希望函数更新选项卡,以便不在给定方向上的每个单元格都更新为0.

到目前为止,这是我的代码:

> info: --> POST /wd/hub/session {"desiredCapabilities":{"browserName":"Browser","platformName":"Android","version":"5.1.1","deviceName":"Android emulator"}}
> info: Client User-Agent string: Apache-HttpClient/4.3.3 (java 1.5)
> info: [debug] The following desired capabilities were provided, but not recognized by appium. They will be passed on to any other services running on this server. : version

在第6行,我收到以下错误: “人物20-71: 警告10:这个表达式应该有类型单位。“我不知道为什么。

有人可以解释我的错误吗?

祝你有个美好的一天!

1 个答案:

答案 0 :(得分:1)

=符号用于检查不在let之前的相等性。 如果要更改数组中某个元素的值,则必须改为使用<-

let test = fun x y u ->
  for i = 0 to (w-1) do
    for j = 0 to (h-1) do
      if i > x then
        if j > y then
          tab.(i).(j) <- (if u = "DR" then tab.(i).(j) else 0)
        else
          if j = y then
            tab.(i).(j) <- (if u = "R" then tab.(i).(j) else 0)
          else
            tab.(i).(j) <- (if u = "UR" then tab.(i).(j) else 0)
      else
        if i = x then
          if j > y then 
            tab.(i).(j) <- (if u = "D" then tab.(i).(j) else 0)
          else
            tab.(i).(j) <- (if u = "U" then tab.(i).(j) else 0)
        else
          if j > y then
            tab.(i).(j) <- (if u = "DL" then tab.(i).(j) else 0)
          else
            if j = y then
              tab.(i).(j) <- (if u = "L" then tab.(i).(j) else 0)
            else
              tab.(i).(j) <- (if u = "UL" then tab.(i).(j) else 0)
    done
  done

您得到的错误是您返回了预期unit的布尔值。

相关问题