Nested pattern matching in Ocaml -
Want to write a function in the Okmail, which is given a list of quadruple and quadruple (x, y, z, f) I
RCRR interrupted = match with BC = S. [] - & gt; [] | HD :: TL - & gt; Start starting in cell (x, y, r, _) = c (* warning *). Cell (X, _, _, some (_)) - & gt; HD :: Compulsive Cil | Cells (_, y, _, few (_)) - & gt; HD :: Compulsive Cil | Cells (_, _, r, some (_)) - & gt; HD :: Compulsive Cil | _ - & gt; Constrained_by c tl end end Problem: When it is called, it gives the original list, no matter what the quadruple we match, the problem warns that X, Y, RR ( warning ) is unused
As Jian said The good news is that the guards are resolved to your problem. The code can be close to your written specification:
RCR interrupted (by, x, y, z, _) C As c) list = match list | [] - & gt; [] | ('X', 'y', 'z', _) as C '): TL when x = x' or y = y 'or z = z' - & gt; C ':: constrained_by c tl | HD :: TL - & gt; Constrained_by c tl ;; Tiny test:
let_ = interrupted = (1,2,3, "foo") [1,0,0,0; 0,2,0,0; 0,0,3,0; 0,0,0,0] ;; -: (int * int * int * int) list = [(1, 0, 0, 0); (0, 2, 0, 0); (0, 0, 3, 0)] Note that you also use List.filter : Can; (X, Y, Z, _) = List Filter (funny (x ', y', 'z', _) - gt; x = x 'or y = y' or z = z ') ;;
Comments
Post a Comment