Review request for my toy elm project

I am a beginner and made a tic-tac-toe with elm: https://github.com/kindlychung/elm-tic-tac-toe, hoping to get some suggestions for improvement here.

Thanks in advance.

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

That’s very helpful, I’ve adopted all of your suggestions. :slight_smile:
Thanks!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.