Questions tagged [gadt]

Generalized algebraic data types, GADTs, are a more powerful form of algebraic data types that support custom constructor types.

397 questions
8
votes
1 answer

GHC complains about non-exhaustive patterns that are enforced by the type checker

I have the following code {-# LANGUAGE DataKinds, GADTs, TypeOperators #-} data Vect v a where Nil :: Vect '[] a Vec :: a -> Vect v a -> Vect (() ': v) a instance Eq a => Eq (Vect v a) where (==) Nil Nil = True (Vec…
user2407038
  • 14,400
  • 3
  • 29
  • 42
8
votes
1 answer

Enumeration of GADTs in Haskell

Could you please tell me are there any extensions of Haskell deriving mechanism for Enum class? I mean there are a lot of reasonable situations besides ``nullary constructors'' case. Are there any works on this topic?
Katty J.
  • 686
  • 4
  • 11
8
votes
1 answer

How to use functional dependencies and existential quantification to remove an unnecessary parameter to my type

In the HLearn library that I'm working on, I have some container data type that looks like this: data (Model params model) => Container' params model = Container' { baseparams :: params , basemodel :: model } The problem is that this…
Mike Izbicki
  • 6,286
  • 1
  • 23
  • 53
8
votes
2 answers

What's the closest thing to Haskell GADTs and typeclasses in F#?

F# is an ML with OOP. What's the closest it comes to Haskell generalized algebraic data types and typeclasses?
mcandre
  • 22,868
  • 20
  • 88
  • 147
8
votes
1 answer

Simulating existential quantification in function return types

Sometimes I come upon a need to return values of an existentially quantified type. This happens most often when I'm working with phantom types (for example representing the depth of a balanced tree). AFAIK GHC doesn't have any kind of exists…
Petr
  • 62,528
  • 13
  • 153
  • 317
8
votes
1 answer

how to parse strings to syntax tree using GADTs

I was reading GADT introduction here and it I found the idea of restricting programmer to create only right type of syntax tree great, and I put this idea into my simple lambda calculus interpreter, but later I realized that I can't parse a string…
sinan
  • 6,809
  • 6
  • 38
  • 67
7
votes
3 answers

type level integers in ocaml

Could anyone give me suggestions/advice on making type level integers in OCaml (3.12) supporting addition and subtraction operations on them? For example, if I have numbers represented like this: type zero type 'a succ type pos1 = zero succ type…
etaoin
  • 81
  • 1
  • 5
7
votes
1 answer

Functional dependency does not unify when bound in GADT

In the following code: class FD a b | a -> b data Foo a where Foo :: FD a b => b -> Foo a unFoo :: FD a b => Foo a -> b unFoo (Foo x) = x By common sense this should work, since a is the same in constraints in both GADT and function, and it…
Ryba
  • 681
  • 4
  • 13
7
votes
1 answer

Weaken GADTs type constraints to deal with unpredictable data

I am trying to make use of GADTs to have well constrained types, but some dependencies are impossible to handle during compilation time – for example user input. Let's consider following AVL tree definition: data Zero data S a data AVL depth where …
radrow
  • 6,419
  • 4
  • 26
  • 53
7
votes
3 answers

Why does eqT returning Maybe (a :~: b) work better than it returning Bool?

I made a variant of eqT that would allow me work with the result like any other Bool to write something like eqT' @a @T1 || eqT' @a @T2. However, while that worked well in some cases, I found that I couldn't replace every use of eqT with it. For…
JoL
  • 1,017
  • 10
  • 15
7
votes
1 answer

Safest way to generate random GADT with Hedgehog (or any other property-based testing framework)

I have GADT like this one: data TType a where TInt :: TType Int TBool :: TType Bool I want to have a function like this one: genTType :: Gen (TType a) Which can generate random constructor of TType type. I can do this simply by creating…
Shersh
  • 9,019
  • 3
  • 33
  • 61
7
votes
2 answers

Recreating Lisp's `apply` in Haskell using GADTs

As an exercise I'm trying to recreate Lisp's apply in Haskell. I do not intend to use this for any practical purpose, I just think it's a nice opportunity to get more familiar with Haskell's type system and type systems in general. (So I am also not…
Sam van Herwaarden
  • 2,321
  • 14
  • 27
7
votes
1 answer

Using record update syntax with constrained GADT records

I stumbled upon the following small problem. I am using Haskell record syntax, together with GADTs: {-# LANGUAGE GADTs #-} data Test a where Test :: {someString :: String, someData :: a} -> Test a Now I want to create a new Test value with a…
Tobias Weck
  • 269
  • 1
  • 8
7
votes
1 answer

Converting GADT to phantom types

I was playing around with GADT and phantom types in OCaml. I understood that GADT is a convenience for describing certain kinds of phantom types—correct me if I'm wrong. So I decided to try out to convert a program using GADT type into an one with…
Vladimir Keleshev
  • 13,753
  • 17
  • 64
  • 93
7
votes
1 answer

Deriving Typeable and Data for GADTs?

Using: {-# LANGUAGE GADTs #-} {-#…
fho
  • 6,787
  • 26
  • 71