[Haskell-cafe] Type level seq
Benjamin Franksen
ben.franksen at online.de
Fri Jun 22 20:21:31 UTC 2018
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
More information about the Haskell-Cafe
mailing list