Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type cell = { alive : bool }
- ;;
- type cellzipper = cell list * cell * cell list
- ;;
- type grid = {gamegrid : cell list}
- ;;
- type gridzipper =
- { above : grid
- ; below : grid
- ; left : cell list
- ; right : cell list
- ; focus : cell }
- let focuscell celllist n =
- let rec loop acc n l =
- match l,n with
- | hd :: tl,n when n > 0 -> loop (hd :: acc) (n - 1) tl
- | [],_ -> None
- | hd :: tl,0 -> Some (acc, hd, tl)
- in loop [] 0 celllist
- ;;
- let gridfocus x y g =
- let a = focuscell x g in
- match a with
- | Some(before, line , after) -> (
- let b = focuscell y line in
- match b with
- Some (left , focus, right) ->
- let above = { gamegrid = before } in
- let below = { gamegrid = after} in
- Some(
- { above
- ; below
- ; left
- ; right
- ; focus }
- )
- | None -> None
- )
- | None -> None
- ;;
- let left g =
- match g.left with
- [] -> None
- | hd::tl -> let newgridzipper = { g with focus = hd; left = tl; right = g.right @ [g.focus] } in
- Some(newgridzipper)
- ;;
- let right g =
- match g.left with
- [] -> None
- | hd::tl -> let newgridzipper = { g with focus = hd; left = [g.focus]; right = tl } in
- Some(newgridzipper)
- ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement