Advertisement
Guest User

Untitled

a guest
Jan 11th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. type cell = { alive : bool }
  2. ;;
  3. type cellzipper = cell list * cell * cell list
  4. ;;
  5. type grid = {gamegrid : cell list}
  6. ;;
  7.  
  8. type gridzipper =
  9. { above : grid
  10. ; below : grid
  11. ; left : cell list
  12. ; right : cell list
  13. ; focus : cell }
  14.  
  15. let focuscell celllist n =
  16. let rec loop acc n l =
  17. match l,n with
  18. | hd :: tl,n when n > 0 -> loop (hd :: acc) (n - 1) tl
  19. | [],_ -> None
  20. | hd :: tl,0 -> Some (acc, hd, tl)
  21. in loop [] 0 celllist
  22. ;;
  23.  
  24. let gridfocus x y g =
  25. let a = focuscell x g in
  26. match a with
  27. | Some(before, line , after) -> (
  28. let b = focuscell y line in
  29. match b with
  30. Some (left , focus, right) ->
  31. let above = { gamegrid = before } in
  32. let below = { gamegrid = after} in
  33. Some(
  34. { above
  35. ; below
  36. ; left
  37. ; right
  38. ; focus }
  39. )
  40. | None -> None
  41. )
  42. | None -> None
  43. ;;
  44.  
  45. let left g =
  46. match g.left with
  47. [] -> None
  48. | hd::tl -> let newgridzipper = { g with focus = hd; left = tl; right = g.right @ [g.focus] } in
  49. Some(newgridzipper)
  50. ;;
  51.  
  52. let right g =
  53. match g.left with
  54. [] -> None
  55. | hd::tl -> let newgridzipper = { g with focus = hd; left = [g.focus]; right = tl } in
  56. Some(newgridzipper)
  57. ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement