Search code examples
haskelltype-families

Contrained type familly


I have the following type family in haskell :

type family Foo (a :: Bar) :: * where

followed by a bunch of equality. I want to put a constraint on the kind return to ensure they're all instance of a typeclass. How can i do that ?


Solution

  • In Haskell, it's better not to do that. (See also the desire to put constraints on type variables in data declarations.) You should put constraints where they're actually going to be used. That will still get called out during type checking if it's missing when it's needed, but it will allow things that don't need it to be more flexible.