Advertisement
Guest User

Untitled

a guest
Jan 10th, 2017
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 acc =
  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. How do I convert the following Haskell to OCaml ?
  25.  
  26. focusGridAt :: Int -> Int -> Grid a -> Maybe (GridZipper a)
  27. focusGridAt x y g = do
  28. (before, line , after) <- focusListAt x $ unGrid g
  29. (left , focus, right) <- focusListAt y line
  30. let above = Grid before
  31. let below = Grid after
  32. return GridZipper{..}
  33.  
  34. Is it like this ?
  35.  
  36. let gridfocus x y g =
  37. let a = focuscell x g in
  38. match a with
  39. Some (before, line , after ) -> (
  40. let b = focuscell y line in
  41. match b with
  42. Some (left , focus, right) ->
  43. let above = grid before in
  44. let below = grid after in
  45. { above
  46. ; below
  47. ; left
  48. ; right
  49. ; focus }
  50. | _, None -> None`
  51. )
  52. | None, _ -> None`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement