For Haskell questions about involving the `-XDataKinds` extension in GHC. With -XDataKinds, GHC automatically promotes every suitable datatype to be a kind, and its (value) constructors to be type constructors.
Questions tagged [data-kinds]
155 questions
9
votes
1 answer
Reflecting Heterogeneous Promoted Types back to Values, Compositionally
I've been playing with -XDataKinds recently, and would like to take a promoted structure build with type families and pull it back down to the value level. I believe this is possible because the compositional components are very simple, and the…

Athan Clark
- 3,886
- 2
- 21
- 39
9
votes
0 answers
Promoting complex GADTs
I've been toying around with -XDataKinds recently, and was wondering why Foo below won't be automatically promoted:
{-# LANGUAGE
GADTs
, DataKinds
, KindSignatures #-}
import Data.HList
data Foo a where
Foo :: Bar a =>
a -> Foo…

Athan Clark
- 3,886
- 2
- 21
- 39
9
votes
1 answer
Haskell type family applications are not evaluated
I found an interesting situation, when using data kinds with type families.
The compiler's error message is No instance for (C (ID ())) arising from a use of W. It suggests that a type family application is not fully evaluated, even when it is…

Boldizsár Németh
- 1,847
- 13
- 20
9
votes
1 answer
Retrieving information from DataKinds constrained existential types
If I have a type constrained by a finite DataKind
{-# LANGUAGE DataKinds #-}
data K = A | B
data Ty (a :: K) = Ty { ... }
and an existential type which forgets the exact choice of K in the type... but remembers it in a passed dictionary.
class AK…

J. Abrahamson
- 72,246
- 9
- 135
- 180
8
votes
4 answers
DataKind Unions
I'm not sure if it is the right terminology, but is it possible to declare function types that take in an 'union' of datakinds?
For example, I know I can do the following:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
...
data…

Allan W
- 2,791
- 4
- 23
- 41
8
votes
2 answers
What is '[] and ': in Haskell?
I've seen this '[] and ': syntax in a few places, most notably in heterogeneous lists packages like HList or HVect.
For example, the heterogeneous vector HVect is defined as
data HVect (ts :: [*]) where
HNil :: HVect '[]
(:&:) :: !t ->…

mcmayer
- 1,931
- 12
- 22
8
votes
2 answers
Confused on DataKinds extension
I learn type programming of Haskell from Basic Type Level Programming in Haskell but when it introduce DataKinds extension, there are something seems confusing from the example:
{-# LANGUAGE DataKinds #-}
data Nat = Zero | Succ Nat
Now, Nat is…

JoeChoi
- 395
- 1
- 9
8
votes
1 answer
Couldn't match kind '*' with 'Nat'
I'm trying to create a type that guarantees that a string is less than N characters long.
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DataKinds #-}
import GHC.TypeLits…

Sean Clark Hess
- 15,859
- 12
- 52
- 100
8
votes
1 answer
Pattern synonym can't unify types within type-level list
I'm getting an error when trying to define a pattern synonym based
on a GADT that has a type-level list.
I managed to boil it down to this example:
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE…

rampion
- 87,131
- 49
- 199
- 315
8
votes
1 answer
Why compiler couldn't match type 'a==a' with '`True' for type family?
Is there some reason why this code is not compiled:
type family Foo a b :: Bool where
Foo a b = a == b
foo :: Foo a b ~ True => Proxy a -> Proxy b
foo _ = Proxy
bar :: Proxy a -> Proxy a
bar = foo
with error:
Couldn't match type ‘a == a’ with…

Dmitry Olshansky
- 483
- 2
- 8
7
votes
2 answers
Data type parametrized by constant in Haskell
I would like to define a data type in Haskell which is parametrized by an Int constant along the lines:
data Q (n :: Int) = Q n (Int,Int) -- non-working code
in order to allow me to define functions of the type:
addQ :: (Q n)->(Q n)->(Q n)
addQ (Q k…

BeMuSeD
- 181
- 2
- 8
7
votes
1 answer
Using * as a primitive on Nat
I'm currently going through Sandy Maguire's Thinking with Types, and chapter 2 covers Terms, Types and Kinds. In it, there's an example of a simple interaction with the type-level primitives for performing arithmetic on Nats.
The following session…

Mark Seemann
- 225,310
- 48
- 427
- 736
7
votes
1 answer
Can't specify type signature in GHCI when using DataKinds
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…

m-renaud
- 1,275
- 8
- 11
7
votes
2 answers
Functions that only work with one constructor of a type
I'm writing a lib for message queues. Queues can be either Direct or Topic. Direct queues have a static binding key, while Topic queues can have dynamic ones.
I want to write a function publish that only works on Direct queues. This works:
{-#…

Sean Clark Hess
- 15,859
- 12
- 52
- 100
7
votes
2 answers
Deciphering DataKind type promotion in Servant library
I am trying to gork the tutorial for the servant library, a type-level web DSL. The library makes extensive use of the DataKind language extension.
Early in that that tutorial we find the following line which defines a web service end point:
type…

John F. Miller
- 26,961
- 10
- 71
- 121