View difference between Paste ID: YMdV4fSL and exKXcZGs
SHOW: | | - or go back to the newest paste.
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 =
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
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 ) -> (
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
43+
                                                               let above =  { gamegrid = before } in
44-
                                                               let below = grid after in
44+
                                                               let below = { gamegrid = after} in
45
                                                                            {  above
46
                                                                            ;  below
47
                                                                            ;  left
48
                                                                            ;  right
49
                                                                            ;  focus }
50-
                                   | _, None -> None`
50+
51-
                                  )
51+
                                  )