An instance of a data family is illegally linked with inline syntax :()
I am trying to define a type family, one of whose parameters results in an empty tuple type ()
, but it does not compile. Here's a minimal working example:
{-# LANGUAGE TypeFamilies #-}
data family F a
data instance F Int = ()
Compiler error: "Inline syntax invalid bindings: ()
". Why am I getting this error even though I am not trying to change the definition ()
, but rather am asking it as the result of some computation (type family evaluation)?
For what it's worth, a program compiled when replaced ()
with Bool
.
source to share
With data families, you must provide the definition of ADT or GADT on the right side of the equation. ()
is not a valid constructor definition. data instance F Int = Bool
declares a single named constructor Bool
that works but has nothing to do with the type Bool
. It's just what's Bool
available as the name of the constructor.
What you are trying to do can be implemented with type families:
type family F a
type instance F Int = ()
-- or in closed form
type family F a where
F Int = ()
Or you can specify the right side of the data instance, equivalent to ()
:
data instance F Int = FUnit
source to share