Generalising a boardgame scoring app

I am trying to make a boardgame score calculator that supports multiple games. I have managed to make a usable UI for a single toy example game, and I am stuck on generalising Main.elm to work with different Player records for different games.

The code is here: https://gitlab.com/aidalgol/elm-tabletop-scoreboard/
I tried adding a second Player module and renaming both to be named after the game (like ToyGame and AnotherGame), importing them in Main.elm without the exposing part, and defining a Player type in Main.elm as type Player = ToyGame.Player | AnotherGame.Player, but that’s not valid in Elm.

Should I even be trying to generalise my Main module in this case, or should I approach this by making each game scorer a separate page and refactoring code into common modules as duplicate emerges?

Sounds like there might be a way to use extensible records? If you’re not familiar, here’s an article on them:


You’d define a function that works on any record type as long as it has a certain field. Then there’s no need to import every one of the submodule record types.

By the way you might also find this package handy. I noticed you’d defined your own versions of some of the functions so there might be more useful stuff in there for you
https://package.elm-lang.org/packages/circuithub/elm-array-extra/latest/Array-Extra

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