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 acc =
- 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
- ;;
- How do I convert the following Haskell to OCaml ?
- focusGridAt :: Int -> Int -> Grid a -> Maybe (GridZipper a)
- focusGridAt x y g = do
- (before, line , after) <- focusListAt x $ unGrid g
- (left , focus, right) <- focusListAt y line
- let above = Grid before
- let below = Grid after
- return GridZipper{..}
- Is it like this ?
- 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 = grid before in
- let below = grid after in
- { above
- ; below
- ; left
- ; right
- ; focus }
- | _, None -> None`
- )
- | None, _ -> None`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement