haskellfunctional-programmingconstraintsghcitype-kinds

How do I access the `Constraint` kind properly?


I'm playing around with the ConstraintKinds in GHCi. In the linked post I found a nice example:

type NoConstraint = (() :: Constraint)

But I can't get it to work. GHCi outputs the Constraint kind freely, not allowing me to use it at the same time. I. e. here's my full GHCi session (I'm not quite sure I know the right word; if there is a proper term I would appreciate the reader's edit):

GHCi, version 8.6.5: http://www.haskell.org/ghc/  :? for help
Prelude> :set -XConstraintKinds -XKindSignatures
Prelude> type NoConstraint = (() :: Constraint)

<interactive>:2:28: error:
    Not in scope: type constructor or class `Constraint'
    Perhaps you meant `NoConstraint' (line 2)

How do I access the Constraint kind properly?


Solution

  • As mentioned in the docs, the Constraint kind needs to be imported from the Data.Kind module. See my GHCi session below:

    Prelude> :set -XConstraintKinds -XKindSignatures
    Prelude> type NoConstraint = (() :: Constraint)
    
    <interactive>:2:28: error:
        Not in scope: type constructor or class `Constraint'
        Perhaps you meant `NoConstraint' (line 2)
    Prelude> :m +Data.Kind
    Prelude Data.Kind> type NoConstraint = (() :: Constraint)
    Prelude Data.Kind>