Advertisement
Guest User

Untitled

a guest
Jan 11th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 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. { above
  34. ; below
  35. ; left
  36. ; right
  37. ; focus }
  38.  
  39. )
  40.  
  41. How do I port this Haskell function ?
  42.  
  43. goLeft :: GridZipper a -> Maybe (GridZipper a)
  44. goLeft g@GridZipper{..} =
  45. case left of
  46. [] -> Nothing
  47. (hd:tl) -> Just $ g { focus = hd, left = tl, right = focus : right }
  48.  
  49. Is it something like this ?
  50.  
  51. let left g =
  52. match g.left with
  53. [] -> None
  54. | hd::tl -> Some ( let newgridzipper = { g with focus = hd, left = tl, right = focus :: right })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement