So, ghci is giving me an interesting error when I try and pin down the type of a polymorphic return value when using DataKinds
. I have the following code:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE StandaloneDeriving #-}
data DataKind
= KindA
| KindB
data SomeData (a :: DataKind) = forall c. SomeData
{ val :: Int
, sub :: Maybe (SomeData c)
}
deriving instance Show (SomeData a)
two :: SomeData 'KindA
two = SomeData 2 Nothing
This code compiles as expected. If I construct SomeData
in ghci and don't specify the type it works fine:
> two
SomeData {val = 2, sub = Nothing}
> :t two
two :: SomeData 'KindA
> SomeData 2 Nothing
SomeData 2 Nothing :: SomeData a
But if I try and specify the type it errors:
> SomeData 2 Nothing :: SomeData 'KindA
<interactive>:745:32-37: error:
• Data constructor ‘KindA’ cannot be used here
(Perhaps you intended to use DataKinds)
• In the first argument of ‘SomeData’, namely ‘KindA’
In an expression type signature: SomeData KindA
In the expression: SomeData 1 Nothing :: SomeData KindA
It appears that the quote is not being interpreted by ghci. I started the repl using stack ghci
. Has anyone encountered this before? Thanks in advance for any help.
:set -XDataKinds
to manually enable the extension. For some reason the interpreter doesn't load it automatically when you load a file. – Illustrative