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
30
votes
1 answer

Is there any standard implementation of the "trivial constraint", or "object class"?

I want just class Trivial t instance Trivial t This is of course useless in Haskell 98 since you can just omit the constraint; but with ConstraintKinds we can have explicitly required arguments of kind * -> Constraint. Ideally, I would like to just…
leftaroundabout
  • 117,950
  • 5
  • 174
  • 319
26
votes
1 answer

ConstraintKinds explained on a super simple example

What is a Constraint kind? Why would someone use it (in practice)? What is it good for? Could you give a simple code example to illustrate the answers to the previous two questions? Why is it used in this code for example?
jhegedus
  • 20,244
  • 16
  • 99
  • 167
20
votes
1 answer

What's the constraint kinds syntax for GHC 7.4.1?

I'm getting an error that Constraint is not in scope, when I try to write a simple example, {-# LANGUAGE UndecidableInstances, MultiParamTypeClasses, KindSignatures, Rank2Types, ConstraintKinds, …
gatoatigrado
  • 16,580
  • 18
  • 81
  • 143
20
votes
1 answer

Is there a library that uses ConstraintKinds to generalize all the base type classes to allow constraints?

We can use the extension ConstraintKinds to extend the functionality of the base type classes to allow constraints. For example, we can make an unboxed vector a functor: class Functor f where type FunctorConstraint f x :: Constraint type…
Mike Izbicki
  • 6,286
  • 1
  • 23
  • 53
14
votes
3 answers

When (if ever) can type synonyms be partially applied?

Apparently a bit absent-mindedly, I wrote something like the following: {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE TypeFamilies #-} class Foo f where type Bar f :: * retbar :: Bar f -> IO f type Baz f = (Foo f, Eq f) --…
leftaroundabout
  • 117,950
  • 5
  • 174
  • 319
9
votes
2 answers

What is Constraint in kind signature

If I inspect the kind of Maybe I get this: λ> :k Maybe Maybe :: * -> * Now, if I inspect the kind of Monad I get this: λ> :k Monad Monad :: (* -> *) -> Constraint What is Constraint there and why it is needed ? Why not just this * -> * ?
Sibi
  • 47,472
  • 16
  • 95
  • 163
6
votes
1 answer

How can I express this Constraint?

I would like to express a Constraint on types of kind k -> k -> Type, which can be stated in English as: A type s such that, forall x x', y, and y' where Coercible x x' and Coercible y y', Coercible (s x y) (s x' y') Or in even plainer English: A…
Wheat Wizard
  • 3,982
  • 14
  • 34
6
votes
3 answers

Constrained heterogeneous list

I searched Hackage and couldn't find anything like the following but it seems to be fairly simple and useful. Is there a library that contains sort of data type? data HList c where (:-) :: c a => a -> HList c Nil :: HList c All the HLists I…
Clinton
  • 22,361
  • 15
  • 67
  • 163
6
votes
1 answer

Constraining constraints

I can write the following: {-# LANGUAGE RankNTypes #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE ConstraintKinds #-} f :: Integral a => (forall b. Num b => b) -> a f = id And all is good. Presumably GHC…
Clinton
  • 22,361
  • 15
  • 67
  • 163
6
votes
1 answer

Constraint kinds: Pass multiple constraints

When I have a data type like the following in haskell: data A ctx = A (forall a. ctx a => a -> a) Then I can put functions that work on values of types of a given class into this datatype: > A (+3) :: A Num A (+3) :: A Num :: A Num But is it also…
bennofs
  • 11,873
  • 1
  • 38
  • 62
6
votes
1 answer

Revisiting Polymorphic STUArrays with Constraint Kinds

I want to implement a dynamic programming algorithm polymorphic in the score type; here's a simplified 1D version with no boundary conditions: {-# LANGUAGE ConstraintKinds, FlexibleContexts, RankNTypes, ScopedTypeVariables #-} import…
Zorn
  • 73
  • 6
5
votes
1 answer

Receiving as Argument Functions with Constrained Existentials in Haskell

I've been playing with some GHC extensions to define a function that can do the following: let a = A :: A -- Show A b = B :: B -- Show B in myFunc show a b -- This should return (String, String) myFunc should be fully polymorphic in the…
enobayram
  • 4,650
  • 23
  • 36
5
votes
2 answers

Typeable instance for Constraint tupling

I'm trying to derive a Typeable instance for tupled constraints. See the following code: {-# LANGUAGE ConstraintKinds, GADTs #-} {-# LANGUAGE DataKinds, PolyKinds, AutoDeriveTypeable #-} {-# LANGUAGE StandaloneDeriving, DeriveDataTypeable…
Impredicative
  • 5,039
  • 1
  • 17
  • 43
5
votes
1 answer

Haskell Constraint Kinds - default constraint for default implementation

Headline: I would like to provide a default implementation for a class method parametrised over a constraint, which uses the default instance for that constraint. Consider the following: {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE TypeFamilies…
Impredicative
  • 5,039
  • 1
  • 17
  • 43
5
votes
1 answer

Acceptable types in Numeric.AD functions

I'm having little success wrapping my head around the basic plumbing of the types involved in the ad package. For example, the following works perfectly: import Numeric.AD ex :: Num a => [a] -> a ex [x, y] = x + 2*y > grad ex [1.0, 1.0] [1.0,…
jtobin
  • 3,253
  • 3
  • 18
  • 27
1
2 3