Reputation: 1155
I would like to define a data family that supports polymorphism for explicitly uninstantiated cases:
data family Foo a
-- handles some specific case
data instance Foo Int = CreateInt Int Int String
-- handles all other cases
data instance Foo bar = CreateBar bar
Is this possible?
Upvotes: 2
Views: 74
Reputation: 120711
Use a closed type family. Unfortunately, this requires an extra newtype wrapper:
newtype Foo a = CreateFoo {getFoo :: Foo' a}
type family Foo' a where
Foo' Int = IntFoo
Foo' bar = Barbar bar
data IntFoo = CreateInt Int Int String
data Barbar bar = CreateBar bar
Upvotes: 6