Questions tagged [constraint-kinds]

Use this tag for asking question related to Constraint Kind or/and ConstraintKinds GHC extension.

ConstraintKinds is an GHC Haskell extension. Also it is a type of kind.

Interesting Questions:

36 questions
4
votes
2 answers

Is it possible to emulate a limited form of intesection types in Haskell with ConstraintKinds?

Recently, I came up with the idea that one could potentially emulate "intersection types" in Haskell. Specifically, I mean intersection of "interfaces", as they are usually conceived in OOP languages. For instance, to use some pseudo-code for a…
Nathan BeDell
  • 2,263
  • 1
  • 14
  • 25
4
votes
1 answer

Where is the Constraint kind defined?

I'm not familiar with GHC internals but I have a couple questions about ConstraintKinds. It says from GHC.Exts that data Constraint :: BOX which is misleading because Constraint is a kind of sort BOX. This brings us to the first question: we can…
gspindles
  • 187
  • 6
4
votes
2 answers

Prove that a constraint holds for a component of a product from the fact it holds for the product

I have a class C with instances for one type and for tuples. class C a instance C Int instance (C a, C b) => C (a, b) Using the normal Dict GADT for capturing constraints {-# LANGUAGE GADTs #-} {-# LANGUAGE ConstraintKinds #-} data Dict c where …
Cirdec
  • 24,019
  • 2
  • 50
  • 100
4
votes
1 answer

When can GHC infer constraint variables?

I am getting type inference errors because GHC will not infer a constraint variable. It looks inferable by first-order unification. In further investigation, I found that inserting let-bindings changes the behavior of type inference. I'd like to…
Heatsink
  • 7,721
  • 1
  • 25
  • 36
4
votes
1 answer

Using constraint kinds and type families with 'limited' constraints

I'm working on an applicative functor that contains a monoid to "view" the execution. However, sometimes I don't care about this part at all, so the choice of monoid is irrelevant as it will never be consumed. I've simplified what I have into: {-#…
ocharles
  • 6,172
  • 2
  • 35
  • 46
3
votes
0 answers

Preventing premature monomorphization of constrained polymorphic values

This is a question concerning constrained polymorphic values, i.e.: values of type forall f. cxt f => a, where cxt is some constraint. As normal, for such a value to be used, we need some reified constraints type: data Dict (c :: k -> Constraint) (a…
James Koppel
  • 1,587
  • 1
  • 10
  • 16
3
votes
2 answers

Could you write a type function to invert a constraint?

Is it possible to write a type function that would take a constraint like Show and return one that constrains the RHS to types that are not an instance of Show? The signature would be something like type family Invert (c :: * -> Constraint) :: * ->…
David Fox
  • 654
  • 4
  • 10
3
votes
4 answers

() as empty constraint

how can one represent the empty constraint ? for the following file {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE KindSignatures #-} import Data.Kind(Type, Constraint) type Empty = (() :: Type -> Constraint) main :: IO () main = return () ghc…
libeako
  • 2,324
  • 1
  • 16
  • 20
3
votes
1 answer

Type Lists with constraints

I'm trying to build a list at the type level, but I'm having some trouble figuring out how to enforce constraints. My base code is: data Foo z q = Foo1 (z q) | Foo2 (z q) class Qux q -- where ... class Baz z -- where ... class Bar a…
crockeea
  • 21,651
  • 10
  • 48
  • 101
2
votes
1 answer

Unhelpful Kind equality error at the start of file

I get an error app\Main.hs:1:1: error: Couldn't match kind `*' with `Constraint' When matching types b :: * (Set b, Set s) :: Constraint | 1 | {-# LANGUAGE TypeFamilies #-} | ^ I don't know why b and the constraint (Set b,…
2
votes
0 answers

Is there any way to constrain type parameters in a typeclass from an external library?

I continually trick myself into thinking it'd be possible to somehow (at least imitate) having a typeclass, say, from base be arbitrarily constrained (For all my searching I haven't found anything that satisfyingly addresses constraining type params…
Josh.F
  • 3,666
  • 2
  • 27
  • 37
2
votes
1 answer

Higher kinded empty constraint

I want to have an empty constraint at a higher kind. Suppose I have the following class: class Category k where type Obj k :: * -> Constraint id :: Obj k a => a `k` a (.) :: (Obj k a, Obj k b, Obj k c) => b `k` c -> a `k` b -> a `k` c Now I…
svenningsson
  • 4,009
  • 1
  • 24
  • 32
2
votes
1 answer

GHC stuck due to UndecidableSuperClasses - expected behaviour or bug?

The following snippet makes GHC (checked with 8.6.2 & 8.4.4) stuck during compilation: {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE UndecidableSuperClasses #-} import GHC.Exts…
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
1 answer

ConstraintKind inconsistency?

I want to use custom constraints to help curb combinatorial explosion: {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE MultiParamTypeClasses #-} class DifferentTypes a b type DifferentTypes3 a b c = (DifferentTypes a b, DifferentTypes b c,…
Thomas Eding
  • 35,312
  • 13
  • 75
  • 106