In the vein of functional programming, I've been learning Elm to visualize the progress of a Sudoku solver.
The JSON decoding tutorials are clear, and the JSON.Decode library is well-documented once you know how to read it (in general, the library documentation in Elm seems to be on the terse side).
- https://elmprogramming.com/decoding-json-part-1.html
- https://elmprogramming.com/decoding-json-part-2.html
Two things were not very clear from initial read of the docs: how to parse lists to tuples, and how to parse strings to custom types.
Leaning on SO for the below example, tuples apparently used to be supported as first-class decoders, but in the current version of Json.Decoder, index seems to be the official way to construct decoders for tuples.
arrayAsTuple2 a b c =
Decode.index 0 a
|> Decode.andThen (\ aVal -> Decode.index 1 b
|> Decode.andThen (\ bVal -> Decode.succeed (aVal, bVal)))
boardDecoder : Decoder Board
boardDecoder = Decode.list <| arrayAsTuple2 Decode.int Decode.int
Elm 0.19 only supports up to three-value tuples (somewhat surprising coming from Haskell, though with records and custom data types, the decision to limit unnamed tuples has a certain logic...). So the helper construction isn't too bad.