With a derived Bounded instance for TokenType, I can drop my SkyToken newtype & ensure any newly added values to the TokenType type get pulled into my list of "all tokens".
Add Bounded to the derived instances for the TokenType type. This allows consumers to use [minBound .. maxBound] to generate a list of all token types when writing a Style.
In one of my projects I wanted to convert my molokai vim colorscheme into a skylighting
Style
.To build the
tokenStyles
field, I wanted to map over a list of all TokenTypes & pass them through to a function that usescase ... of
:I can't define
allTokens
generically, I'm stuck using discrete values for the start & end of the range:With a derived
Bounded
instance forTokenType
, I can drop mySkyToken
newtype & ensure any newly added values to theTokenType
type get pulled into my list of "all tokens".Add
Bounded
to the derived instances for theTokenType
type. This allows consumers to use[minBound .. maxBound]
to generate a list of all token types when writing aStyle
.