Generalized algebraic data types, GADTs, are a more powerful form of algebraic data types that support custom constructor types.
Questions tagged [gadt]
397 questions
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
How do I code this dependently-typed example in Haskell?
Suppose I want to represent the finite models of the first-order language with constant c, unary function symbol f, and predicate P. I can represent the carrier as a list m, the constant as an element of m, the function as a list of ordered pairs…

lambdacalculator
- 363
- 2
- 7
9
votes
2 answers
Typeably casting GADTs
Let's say I'm writing a DSL and want to have support for both phantom type support and badly typed expressions. My value types might be
{-# LANGUAGE GADTs, DataKinds #-}
data Ty = Num | Bool deriving (Typeable)
data Val a where
VNum :: Int ->…

J. Abrahamson
- 72,246
- 9
- 135
- 180
8
votes
2 answers
Scala Type-Inference For Type Constructor
I have a question regarding type-inferencing on Scala's type-constructors. I'm running Scala 2.9.1...
Suppose I defined Tree:
sealed trait Tree[C[_], A]
case class Leaf[C[_], A](a: A) extends Tree[C, A]
case class Node[C[_], A](a: A, c:…

shj
- 1,558
- 17
- 23
8
votes
2 answers
differences: GADT, data family, data family that is a GADT
What/why are the differences between those three? Is a GADT (and regular data types) just a shorthand for a data family? Specifically what's the difference between:
data GADT a where
MkGADT :: Int -> GADT Int
data family FGADT a
data instance…

AntC
- 2,623
- 1
- 13
- 20
8
votes
1 answer
TypeFamilies or GADTs suddenly breaks the valid code
I have very innocent-looking code
data Config = Config
{ cInts :: [Int]
, cStrings :: [String] }
instance Semigroup Config where
c1 <> c2 = Config
{ cInts = andCombiner cInts
, cStrings = andCombiner cStrings }
…

vrom911
- 694
- 1
- 5
- 16
8
votes
1 answer
Creating a list of valid constructors
Consider the following:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE GADTs #-}
data T = T1 | T2
data D (t :: T) where
D1 :: D T1
D2 :: D T2
D3 :: D d
D4 :: D T1
x1 :: [D T1]
x1 = [D1, D3, D4]
x2 :: [D T2]
x2 =…

Clinton
- 22,361
- 15
- 67
- 163
8
votes
2 answers
Understanding when to uses type classes or GADT's?
I'm trying to figure out the differences between type classes and GADTS, especially when using -XMultiParamTypeClasses extension.
Both appear to have similar uses:
class MyClass a b where
f :: a -> b -> Bool
instance MyClass String String where
…

Babra Cunningham
- 2,949
- 1
- 23
- 50
8
votes
1 answer
Are type variables in GADT heads meaningful?
Is there a difference between these two GADT declarations?
data A a b where
...
data A :: * -> * -> * where
...
user1804599
8
votes
2 answers
GADT type argument not being used for typeclass resolution
Consider the following code
data Foo f where
Foo :: Foo Int
class DynFoo t where
dynFoo :: Foo f -> Foo t
instance DynFoo Int where
dynFoo Foo = Foo
obsFoo :: (DynFoo t) => Foo f -> Foo t
obsFoo = dynFoo
useDynFoo :: Foo f -> Int
useDynFoo…

James Koppel
- 1,587
- 1
- 10
- 16
8
votes
1 answer
How to resolve ambiguity in my GADTs
I have two GADTs I am using to model a SQL EDSL. To keep the client facing api clean and simple I want to use OverloadedStrings to cast string literals to a Column Selection.
Therefore you can simply type
select ["a", "b"] $ from tbl
instead of…

Brandon Ogle
- 715
- 1
- 8
- 23
8
votes
1 answer
makeLenses for GADTs (Haskell)
Is there an equivalent of makeLenses for GADTs? If I have a simple GADT like:
data D a b where
D :: (Ord a, Ord b) => !a -> !b -> D a b
Is there a way to generate lenses automatically by passing in a constructor and a list of field names?

yong
- 3,583
- 16
- 32
8
votes
2 answers
GADT vs Existentially quantified types (*forall*)
One can use GADT to express Existentially quantified types.
I see that GADT is more generic - data-type-extensions, paragraph section 7.4.7
When it's better to use Existentially quantified types then GADT? Are there any drawbacks using GADT compared…

Robert Zaremba
- 8,081
- 7
- 47
- 78
8
votes
1 answer
How can I use restricted constraints with GADTs?
I have the following code, and I would like this to fail type checking:
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
import Control.Lens
data GADT e a where
One :: Greet e => String -> GADT e String
Two…

ocharles
- 6,172
- 2
- 35
- 46
8
votes
1 answer
GADT definition
This is just a test so I'm not much concerned, but I have these definitions:
type z
type _ s
type (_, _, _) balance =
| Less : (*∀'a.*) ('a, 'a s, 'a s) balance
| Same : (*∀'b.*) ('b, 'b, 'b) balance
| More : (*∀'a.*) ('a s, 'a, 'a s)…

lukstafi
- 1,883
- 15
- 22