I’m not well versed into singletons, but I’m not too sure why can’t I use withSing
(from the singleton package) taking advantage of knowledge from Data Kinds?
For example, given the following data types:
infixr 0 :->
data Types
= Value Types0
| Lazy Types
| LazyS Types
deriving (Typeable,Eq)
data Types0
= Z
| (:->) Types Types
deriving (Typeable,Eq)
$(genSingletons [''Types0, ''Types])
The following code fails to compile:
withTypeableType' :: forall (z :: Types) r. (Typeable z => r) -> r
withTypeableType' f = withSing $ \case
(z :: Sing z) -> withTypeableType z f
where
withTypeableType :: forall (z :: Types) r. Sing z -> (Typeable z => r) -> r
withTypeableType = undefined
With the following error message:
No instance for ‘SingI z’ arising from a use of ‘withSing’
My reasoning on why this should work, is that we know that z :: Types
, and we have generated the SingI
instances using the genSingletons
splice.
would anyone be so kind to shine a light on why this isn’t possible?