-
Notifications
You must be signed in to change notification settings - Fork 37
Open
Description
Given inductively defined naturals data N = Z | S N
we can define finite sets as follows:
data Fin :: N -> Type where
FZ :: Fin (S n)
FS :: Fin n -> Fin (S n)
If I wrap the above definition in singletons [d| |]
I get these errors:
R.hs:23:1: error:
• Expected kind ‘N’, but ‘a0’ has kind ‘*’
• In the first argument of ‘Fin’, namely ‘a_ap1v’
In the first argument of ‘SingKind’, namely ‘Fin a_ap1v’
In the instance declaration for ‘SingKind (Fin a_ap1v)’
R.hs:23:1: error:
• Expected kind ‘Fin a0’, but ‘'FS n1’ has kind ‘Fin ('S n0)’
• In the definition of data constructor ‘SFS’
In the data instance declaration for ‘Sing’
Instead I'd expect these definitions to be generated:
data instance Sing (fn :: Fin n) where
SFZ :: Sing FZ
SFS :: Sing fn -> Sing (FS fn)
instance SingKind (Fin n) where
type DemoteRep (Fin n) = Fin n
toSing = \case
FZ -> SomeSing SFZ
FS fn -> case toSing fn of
SomeSing sfn -> SomeSing (SFS sfn)
fromSing = \case
SFZ -> FZ
SFS sfn -> FS (fromSing sfn)
isovector, andy-morris and michaelmesserju1m