OCaml error in basic loop -


i'm new ocaml. i'm making function working way : have "tab" in scope represents 2d map, , 3 parameters, x, y , u.

x , y represent position of player, , u direction of bomb (right, top left etc.). want function update tab every cell not in given direction updated 0.

here code far :

let test = fun x y u -> (for = 0 (w-1)     j = 0 (h-1)         if > x             if j > y                 tab.(i).(j) = (if u = "dr" tab.(i).(j) else 0)             else                 if j = y                     tab.(i).(j) = (if u = "r" tab.(i).(j) else 0)                 else                     tab.(i).(j) = (if u = "ur" tab.(i).(j) else 0)         else             if = x                 if j > y                      tab.(i).(j) = (if u = "d" tab.(i).(j) else 0)                 else                     tab.(i).(j) = (if u = "u" tab.(i).(j) else 0)             else                 if j > y                     tab.(i).(j) = (if u = "dl" tab.(i).(j) else 0)                 else                     if j = y                         tab.(i).(j) = (if u = "l" tab.(i).(j) else 0)                     else                         tab.(i).(j) = (if u = "ul" tab.(i).(j) else 0)     done done) 

on line 6, following error : "characters 20-71: warning 10: expression should have type unit." , don't know why.

could explain error please ?

have day !

the = symbol here check equality when not preceded let. if want change value of 1 element of array, have use <- instead.

let test = fun x y u ->   = 0 (w-1)     j = 0 (h-1)       if > x         if j > y           tab.(i).(j) <- (if u = "dr" tab.(i).(j) else 0)         else           if j = y             tab.(i).(j) <- (if u = "r" tab.(i).(j) else 0)           else             tab.(i).(j) <- (if u = "ur" tab.(i).(j) else 0)       else         if = x           if j > y              tab.(i).(j) <- (if u = "d" tab.(i).(j) else 0)           else             tab.(i).(j) <- (if u = "u" tab.(i).(j) else 0)         else           if j > y             tab.(i).(j) <- (if u = "dl" tab.(i).(j) else 0)           else             if j = y               tab.(i).(j) <- (if u = "l" tab.(i).(j) else 0)             else               tab.(i).(j) <- (if u = "ul" tab.(i).(j) else 0)     done   done 

the error got returned booleans unit expected.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -