Charlie Koster
May 28 · 1 min read

Hey! There are tradeoffs to both options. One advantage to using a phantom type instead of two separate distinct types is it allows you to create functions that accept a single type without caring about type parameter.

For example, you could create a reset function that resets all of the fields of a form to their original default values regardless of whether the form being reset is valid or invalid.

With two opaque types this would require two reset functions, one for a valid form data and one for an invalid form data.

    Charlie Koster

    Written by

    Advocate of technology and techniques that move the tech industry forward. charliek on Elm slack