Functions & Dragons – Part 3

Much better progress today compared to yesterday. Fixed the proficiency bonus display (wasn’t actually tied to the model value) and successfully modularized the ability scores type and its related functions. As part of this, I reorganized the code and split it up.

I also realized the abilities record type could easily be genericized to support e.g. Bool for saving throw proficiencies. This feels like a huge design win. It’s just so clean. Although I can’t for the life of me figure out what to do about the repetition here:

update : Abilities a -> Ability -> a -> Abilities a
update abilities ability val =
    case ability of
        Strength ->
          { abilities | str = val }

        Dexterity ->
          { abilities | dex = val }

        Constitution ->
          { abilities | con = val }

        Intelligence ->
          { abilities | int = val }

        Wisdom ->
          { abilities | wis = val }

        Charisma ->
          { abilities | cha = val }

I guess I could redefine Abilities a as List (Ability, a) and have value return Maybe a? I’ll give that a try tomorrow and see how it goes.

Oh, I also implemented the saving throws box, complete with proficiency bonus check boxes and modifier calculation.

Which reminds me. I think it would be a good idea to introduce a viewModel : Model -> ViewModel function and type that computes derived values like saving throw bonuses all in one convenient place.

Leave a Reply

Your email address will not be published. Required fields are marked *