How to represent many subsets of an enum?

Depends on exactly what you want to achieve with the API. If you’re quite sure about the types, than crashing is not unreasonable (you can crash without Debug with just endless recursion). You could also expose a API returned an unknown error handler, that would be the default handler, if things go wrong in an unexpected way (which might be sensible in this case). It really depends on the exact circumstances of this API.

Ah that is essentially what we see in elm-css, right?

In that,

-- Css.Structure
type Compatible =
    Compatible

is used as a static tag, and functions return records with .value and many “compatibility” fields. For example px returns records compatible against .length, .calc, .fontSize and so on. While functions such as fontSize takes

type alias FontSize compatible =
    { compatible | value : String, fontSize : Compatible }

so that they only take values with .fontSize : Compatible in them.

I was really amazed by how strong it is to express such kind of compatibility in type-safe manner, with Elm’s type system.

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