Review request for my toy elm project

The following is just my take.

The reuse of Turn for pieces on the board and whose turn is next bothered me. It caused naming issues Player and PlayerW, Computer and ComputerW. Also required awkward case like handling Unoccupied for case model.nextTurn of

I’d introduce type Party = Player | Computer upfront, which then allowed me to talk about

type Piece  = Occupied Party | Unoccupied
type Winner = Winner Party | Draw | Unknown

type alias Model =
    { pieces : Array Piece
    , nextTurn : Party
    , winner : Winner
    }

i feel it clarified other areas of the code

case model.nextTurn of
    Player ->
    Computer ->
symbol : Piece -> String
symbol piece =
    case piece of
        Occupied Player ->
        Occupied Computer ->
        Unoccupied ->
case model.winner of
    Winner Player ->
        "Human won!"

    Winner Computer ->
        "Computer won!"

    Draw ->
        "It's a draw!"

    Unknown ->
        "..."

Also, watch_compile.sh can be replaced with the very awesome elm-live

elm-live --start-page index.html src/Main.elm -- --output main.js
1 Like