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…
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…
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
…
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…
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:
{-#…
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…
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) :: * ->…
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…
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…
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,…
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…
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…
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…
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…
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,…