
22 Jun
2018
22 Jun
'18
8:21 p.m.
On 06/22/2018 08:40 PM, Matt wrote:
Haskell's type families are strict -- they evaluate (or, try to evaluate) all of their arguments before they compute the result. When a type family doesn't have a matching equation, it is "stuck", and GHC just carries the applied type family around. This can be pretty confusing.
If you want a type family to work on defined cases, and error otherwise, you must write a manual TypeError message:
type family TurnOff (s :: Bool) where TurnOff True = False TurnOff _ = TypeError (Text "You tried to use TurnOff with False, but it can only be used with True.")
Where TypError etc comes from `GHC.TypeLits`
Thanks! That was exactly the missing piece. Cheers Ben