Generalized algebraic data types, GADTs, are a more powerful form of algebraic data types that support custom constructor types.
Questions tagged [gadt]
397 questions
0
votes
1 answer
How do I interpret this GADT error in OCaml?
Sorry about the "what am I missing here" style of question here, but I'm just missing something here.
I was trying to understand how GADTs work in OCaml, I define the following (in utop):
type value =
| Bool : bool -> value
| Int : int ->…

agam
- 5,064
- 6
- 31
- 37
0
votes
1 answer
What is the purpose of using type parameters for an empty trait when extending it?
I have recently come across a code that looks similar to the following.
The question I want to ask is what would be the possible purposes of the Second's type parameters(namely the first type parameter) specified when being extended by the case…

d-_-b
- 4,142
- 6
- 28
- 43
0
votes
1 answer
OCaml GADTs - pattern matching matches wrong type of argument
I have to implement a perfectly balanced binary tree (or PBT for short) using generalized algebraic data types. I have understood how GADTs work in general and the (somewhat ugly) syntax that I have to use in order for it to work in OCaml.
Then I…

Neptonus2
- 3
- 3
0
votes
2 answers
'IsList' instance for GADT
I have troubles implementing IsList instance for GADT which represents structure of values inside nested arrays. Here is complete code:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-#…

Shersh
- 9,019
- 3
- 33
- 61
0
votes
2 answers
OCaml polymorphic recursion errors
Given the following types:
type _ task =
| Success : 'a -> 'a task
| Fail : 'a -> 'a task
| Binding : (('a task -> unit) -> unit) -> 'a task
| AndThen : ('a -> 'b task) * 'a task -> 'b task
| OnError : ('a -> 'b task) * 'a task -> 'b task
type _…

Erik Lott
- 697
- 1
- 9
- 17
0
votes
1 answer
defining type class instance on GADT
Consider the following code
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Test where
data…

marcosh
- 8,780
- 5
- 44
- 74
0
votes
1 answer
Type juggling with GADTs at runtime
I'm designing a typed formal language, that is, a formal language where each letter has a representation of a specific type. So far, I have the following:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE…

WorldSEnder
- 4,875
- 2
- 28
- 64
0
votes
1 answer
Representing Country Id and Text in Haskell datatype
I have a list of country id and country text in json
{
1 : "country one",
2 : "country two"
}
I have created below code to represent country id and text in haskell
data Country a = Country a
country1 :: Country String -- Representing country…

navin
- 165
- 1
- 12
0
votes
1 answer
Generalizing from a specific type to a class in a GADT
I have the following definitions
{-# LANGUAGE GADTs, TypeInType, RankNTypes #-}
import Data.Kind
class Character (a :: * -> *) where
showVal :: a b -> b -> String
data ExampleCharacter a where
Variable :: ExampleCharacter String
EqualSign ::…

WorldSEnder
- 4,875
- 2
- 28
- 64
0
votes
0 answers
Type-level graphs via GADTs and DataKinds
I'm trying to encode a type-level graph with some constraints on the construction of edges (via a typeclass) but I'm running into an "Illegal constraint in type" error when I try to alias a constructed graph. What's causing this issue? If it's…

o1lo01ol1o
- 440
- 1
- 5
- 13
0
votes
1 answer
Context in data instances
I have a datatype which only makes sense if its arguments can be ordered, however I seem to be needing to get deep into some complex and potentially hacky stuff to get it to work (GADTs, mainly).
Is what I'm doing (constrained datatypes) considered…

Zoey Hewll
- 4,788
- 2
- 20
- 33
0
votes
1 answer
Data type without input value and multiple primitive types
Firstly, I'd like to apologize if I'm repeating this but I searched everywhere without finding an answer to my question.
Suppose I have the following code:
data TestType = Nothing | Int | Float deriving (Show)
jaykay :: TestType -> [Char]
jaykay…

ymg
- 1,500
- 2
- 22
- 39
0
votes
2 answers
Heterogeneous List for a DSL
TL;DR
is their a way I can construct a heterogenous list constrained to some typeclass, without calling a constructor on each element?
I finally have the opportunity to take a deeper dive into Haskell, and I am trying to build a DSL that generates…

Brandon Ogle
- 715
- 1
- 8
- 23
0
votes
1 answer
How to get a constructor as a function from the (G)ADT argument in Haskell?
How to get a constructor as a function from the (G)ADT argument in Haskell?
Is it possible to do something like this?
data Ex1 = C1 Int | C2 Int -- | .....
| C3
fun :: Ex1 -> Ex1
fun C3 = C3
fun (c i) = c $ i^2
It is not…

Alex K.
- 93
- 4
0
votes
1 answer
Trouble refactoring current types(possibly GADT/Type Families related)
I've got types like this:
-- There are codes
newtype ICode = ICode { fromICode :: String }
newtype RCode = RCode { fromRCode :: String }
data DCode = DCode1 | DCode2 | DCode3
-- There are locations described by type and code.
-- Current…

dredozubov
- 715
- 1
- 6
- 11