-- board piece structural type P = X | O | E structural type Board = Board P P P P P P P P P use Board Board use P O X E use Optional Some None orElse a b = match a with None -> b a -> a b = (Board X O X O X X O E X) isWin board = same : P -> P -> P -> Optional P same a b c = if (a == b) && (a == c) && not (a == E) then Some a else None match board with -- vertical top/center/bottom -- horizontal left/center/right -- diagonal rising/falling Board a b c d e f g h i -> (same a b c) > isWin b -- Some 3