Hacker News new | ask | show | jobs
by mega_dean 966 days ago
Here's a similar article that I read recently about using Ocaml's type system to implement a sudoku solver: https://ocamlpro.com/blog/2017_04_01_ezsudoku/ The author defines types to represent a valid sudoku board, and then uses the obscure syntax `-> .` to tell the compiler that a pattern should be unreachable.

There is no compiler error when he compiles an unsolvable input. But when there is a solution, the compiler provides it:

``` Error: This match case could not be refuted. Here is an example of a value that would reach it: Grid (A, B, C, D, C, D, A, B, B, A, D, C, D, C, B, A) ```

1 comments

That's actually pretty amazing. Thank you for the link.