I'm trying to define a data type family, one of whose parameters results in the type of the empty tuple (), but it doesn't compile. Here is a minimal working example:
{-# LANGUAGE TypeFamilies #-}
data family F a
data instance F Int = ()
The compiler error thrown says "Illegal binding of built-in syntax: ()". Why am I getting this error, even though I'm not trying to change the definition of (), but rather set it as the output of some computation (evaluation of a type family)?
For what it's worth, the program compiled when () is changed to Bool instead.
With data families, you're supposed to provide an ADT or GADT definition on the right side of the equation. () is not a valid definition of a constructor. data instance F Int = Bool declares a single constructor with the name Bool, which works, but doesn't have anything to do with the type Bool. It's just that Bool is available as a constructor name.
What you're trying to do can be realized with type families instead:
type family F a
type instance F Int = ()
-- or in closed form
type family F a where
F Int = ()
Or you can give a right hand side for the data instance which's equivalent to ():
data instance F Int = FUnit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With