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
2
votes
2 answers
Why aren't existential quantification and datakinds working together?
{-# LANGUAGE DataKinds, ExistentialQuantification, KindSignatures #-}
import Data.Proxy
data Type t= forall (a :: t). Type (Proxy a)
gives the error
Type variable ‘t’ used in a kind
In the kind ‘t’
In the definition of data constructor ‘Type’
In…

PyRulez
- 10,513
- 10
- 42
- 87
2
votes
1 answer
HList with DataKinds, kind not promotable
I have this code snippet which uses a plethora of GHC extensions:
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
import…

cdk
- 6,698
- 24
- 51
2
votes
2 answers
Anonymous Type Functions
This is a followup to a previous question: Type-level Map with DataKinds, starting with from the two answers it received.
My goal is to take a HList of arbitrary types and turn it into a list of related/derived types
type family TypeMap (a :: * ->…

crockeea
- 21,651
- 10
- 48
- 101
2
votes
1 answer
Return Type as a result of Term or Value calculation
I'm trying to get a good grasp on Kinds, Types & Terms(or Values, not sure which is correct) and the GHC extensions for manipulating them. I understand that we can use TypeFamilies to write functions with Types and now we can also manipulate Kinds…

MFlamer
- 2,340
- 2
- 18
- 25
1
vote
1 answer
Haskell equivalent of Kotlin's invariant types
In Kotlin i can do
sealed class Substance {
object Uranus : Substance()
object Mercury: Substance()
object Ammonia : Substance()
}
data class DangerousBox(val item: T)
fun main() {
val uranus =…

True Warg
- 85
- 4
1
vote
1 answer
Inhabitants of promoted type by DataKinds
{-# LANGUAGE DataKinds #-}
data Nat = Zero | Succ Nat
DataKinds according to GHC User Guide, promotes datatype to a kind and constructors to type constructors.
Nat :: Type
'Zero :: Nat
'Succ :: Nat -> Nat
Q1. Types are sets of values, but how can…

wliao
- 1,416
- 11
- 18
1
vote
2 answers
Type of a heterogeneous list (HList) of values behind a type constructor
I want to define a function that takes an arbitrarily sized HList of values behind some type constructor, e.g. Maybe:
foo :: HList '[t a, t b, t c, ...] -> Bar
-- For example:
foo :: HList '[Maybe a, Maybe b, Maybe c, ...] -> Bar
Is there some way…

malte-v
- 330
- 1
- 12
1
vote
2 answers
using list types with Haskell's -XDataKinds
I was using a return type in a function (using package haskell-src-exts):
import Language.Haskell.Exts.Syntax (Exp(..))
import Language.Haskell.Exts.SrcLoc (SrcSpanInfo(..))
:k Exp SrcSpanInfo
Exp SrcSpanInfo :: *
That's a type. So far so good.
But…

Kiara Grouwstra
- 5,723
- 4
- 21
- 36
1
vote
1 answer
Haskell Squeal SQL library - Type error with MonadReader
I'm building a Haskell Servant API using an SQL library called Squeal:
https://github.com/morphismtech/squeal
I need help getting the types correct so the app compiles.
My Schema is of type
type Schema = '["users" ::: UsersTable, ...]
type Schemas…

Hopia
- 180
- 1
- 8
1
vote
1 answer
What is the exact criteria for a type to be Storable?
I implemented a data type for symmetric groups (and cyclic groups) long time ago:
newtype Cyclic (n :: Nat) = Cyclic {cIndex :: Integer}
data Symmetric (n :: Nat) where
S1 :: Symmetric 1
(:.) :: Cyclic n -> Symmetric (n-1) -> Symmetric n…

Dannyu NDos
- 2,458
- 13
- 32
1
vote
1 answer
Unable to convert type-level list back to value-level using singletons library
I'm trying to write s reasonably statically-checked authorisation system [1], and currently struggling with trying to write a function that will extract the required permissions from a type-level annotation/phantom to the value-level.
{-# LANGUAGE…

Saurabh Nanda
- 6,373
- 5
- 31
- 60
1
vote
1 answer
Recursion through Nat-kinds
This question is a sequel to the following question. Refer to it first:
Overlapping instances via Nat-kind
Now it's time to make the instance of Group Symmetric. After some savage math, I've come up to an instance that works in principle, but…

Dannyu NDos
- 2,458
- 13
- 32
1
vote
1 answer
Errors upon creation of 2d list of my own types in Haskell
Basically I've created a type with three attributes, lets call it "Foo"
type Foo = Foo Att1 Att2 Att3
Each attribute is one of 3 values, I declared each attribute with this format:
data Att1 = A | B | C
Now, after a little guesswork about the…

Gabriel Vega
- 325
- 2
- 3
- 7
1
vote
1 answer
Construct value from Kind in Haskell
I'd like to go from a type to value as follows, but without using the depreciated DatatypeContexts:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DatatypeContexts #-}
import Data.Proxy
import…

Scott
- 4,070
- 3
- 21
- 16
1
vote
0 answers
How to pass the kind for real precision to functions and subroutines in Fortran?
I want to make my subroutines and functions in Fortran support both single and double precisions for reals, and other kinds for various variables, the same as intrinsic functions in Fortran. sin(x) would give us a double precision value of the sine…

PolarXYZ
- 63
- 8