jcpetruzza / barbies

BSD 3-Clause "New" or "Revised" License
92 stars 15 forks source link

Raise an error if `Wear` is used with incompatible tag #15

Closed alexpeits closed 5 years ago

alexpeits commented 5 years ago

Currently Bare and Covered are plain types with kind *, so nothing prevents someone setting t to a type other than these two when using Wear. This will lead to Wear being stuck. Another approach is using DataKinds:

data Clothes = Bare | Covered

type family Wear (t :: Clothes) f a where
  Wear Bare f a = a
  Wear Covered f a = f a

This 1) introduces a breaking change and 2) forces users to use DataKinds.

This PR adds a catch-all case to Wear which raises a type error that looks like this:

> data MyTag
> undefined :: Wear MyTag Maybe String

<interactive>:8:1: error:
    • `Wear` should only be used with `Bare` or `Covered`.
      `MyTag` is not allowed in this context.
    • When checking the inferred type
        it :: (TypeError ...)

which is backwards compatible with current code that uses Wear

jcpetruzza commented 5 years ago

Thanks!