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
1
vote
1 answer
Type-safe union in Haskell?
Can I have a type-safe union (As in C's union) in Haskell? This is the best I tried, here Variant, named after C++'s std::variant:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables…

Dannyu NDos
- 2,458
- 13
- 32
1
vote
1 answer
Can you not use DataKinds inside Associated Data Types?
I have the following type class
class BoolHolding h where
data MyBool b :: 'Bool
However, I keep getting the error: Not in scope: data constructor ‘Bool’. Does Haskell not permit this for some reason, or is there away to include the data…

Anders Miltner
- 253
- 3
- 12
1
vote
2 answers
Haskell kinds. Beginner
What is the kind of f?
class C f where
comp :: f b c -> f a b -> f a c
I have written: (* -> *) -> * -> *
Is this correct? c is a concrete type *. a is a type that takes a type and produces a type. And these both are the parameters for f? Is my…

Anonnnn
- 53
- 2
1
vote
0 answers
Returning phantom typed value with data kinds
I am parsing some input, for which I have something similar to this:
{-# LANGUAGE DataKinds, KindSignatures #-}
data InputKind = A | B | C
data Input (kind :: InputKind) =
InputA Char
| InputB Double String
| InputC Int String
And then I…

Misguided
- 1,302
- 1
- 14
- 22
1
vote
1 answer
Convert a list to list with type-constrained fixed length
Let I define a list with constrained length. I.e.
data List (n::Nat) a where
Nil :: List 0 a
Cons :: a -> List (n-1) a -> List n a
Then I want to initialize this list from common list (e.g. input string with any length). Can I do that? Is it…

Dmitry Olshansky
- 483
- 2
- 8
1
vote
2 answers
How to process a recursive GADT with kind :: '[SomeDataKind]
I think this is the furthest into the Haskell type system extensions that I've even been and I've run into an error that I haven't been able to figure out. Apologies in advance for the length, it's the shortest example I could create that still…

m-renaud
- 1,275
- 8
- 11
1
vote
2 answers
Problems with EDSL related implementation of array subscription in Haskell
Context
I'm trying to implement a EDSL that loosely resembles IBM's OLP (modelling language for linear programming).
Code
Haskell EDSL Code
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE…

forflo
- 33
- 3
1
vote
1 answer
Constructing Proxy type given the input
Given the code below which looks up type-specific information in Data.HashMap for a type, is it possible to define a new function getMapVal2 as documented in the comments, to build the TypeKey argument given the type?
{-# LANGUAGE TypeFamilies…

Sal
- 4,312
- 1
- 17
- 26
1
vote
0 answers
Overloading show method for Maybe types
This is followup to an earlier question I asked. Now, I am trying to modify the toText method so that it also handles Maybe a with overloaded toText function. Below is a code that compiles and works fine - now, I will like to overload toText for…

Sal
- 4,312
- 1
- 17
- 26
1
vote
1 answer
Android ContactsContract.Display_Name returns contact phone number or any other available data
I'm using the code below to get contacts name from the phonebook
Uri contactUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
Cursor phones = getContentResolver().query(contactUri,null,null,null,null);
while (phones.moveToNext())
…

Elior
- 3,178
- 6
- 37
- 67
1
vote
1 answer
Vector containing GADT
I'm just learning everything I can about ExistentialQuantification and GADTs and KindSignatures, etc. And to do that I try to come up with some small programs which help me to understand everything better.
Now I have this small snippet (which…

ksaveljev
- 550
- 2
- 16
1
vote
1 answer
Fortran dynamic kind of integer
I want to write a piece of code that can find all of the available integer kinds of my machine and print the range for all of them.
Finding the kinds was not the hard part, using selected_int_kind I was able to iterate over all of the available kind…

DoubleDouble
- 49
- 1
- 4
1
vote
1 answer
List of any `DataKind` in GADT
Disclaimer
GADTs & DataKinds are unexplored territory for me, so some of the limitations and capabilities of them are unknown to me.
The Question
So I'm writing an AST for a JavaScript code emitter, and I've identified one edge case between…

akst
- 935
- 11
- 21
1
vote
1 answer
Trying to develop a recursive type-level function to derive function input and output
The following definitons are kind of required to understand what I'm asking:
data Param = PA | PB | PC
data R p a where
A :: S a -> R PA (S a)
B :: S a -> R PB (S a)
data S a where
Prim :: a -> S a
HO :: R pa a -> R pb b -> S ((R pa a)…

kaosjester
- 121
- 4
1
vote
2 answers
Trouble with DataKinds
I have created a very simple example of a problem I'm having using GADTs and DataKinds. My real application is obviously more complicated but this captures the essence of my situation clearly. I'm trying to create a function that can return any of…

MFlamer
- 2,340
- 2
- 18
- 25