Cannot specify type signature in GHCI when using DataKinds

So ghci gives me an interesting error when I try to set the return type of a polymorphic 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 build SomeDatain ghci and don’t specify what 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 to indicate the type of error:

> 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 seems that the quote is not interpreted by ghci. I started replacing with stack ghci. Has anyone come across this before? Thanks in advance for any help.

+4
source share
1 answer

SomeData 2 Nothing :: SomeData 'KindA , :seti -XDataKinds. , , , REPL, GHCi.

, GHCi, , REPL . GHCi , /.

+9

Source: https://habr.com/ru/post/1665770/


All Articles