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
- { above
- ; below
- ; left
- ; right
- ; focus }
- )
- How do I port this Haskell function ?
- goLeft :: GridZipper a -> Maybe (GridZipper a)
- goLeft g@GridZipper{..} =
- case left of
- [] -> Nothing
- (hd:tl) -> Just $ g { focus = hd, left = tl, right = focus : right }
- Is it something like this ?
- let left g =
- match g.left with
- [] -> None
- | hd::tl -> Some ( let newgridzipper = { g with focus = hd, left = tl, right = focus :: right })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement