Skip to content

Instantly share code, notes, and snippets.

@msakai
Last active August 4, 2020 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msakai/aa1c56e1c48b2d484cf0741a62dca3b5 to your computer and use it in GitHub Desktop.
Save msakai/aa1c56e1c48b2d484cf0741a62dca3b5 to your computer and use it in GitHub Desktop.
Interaction of ConstraintKinds and QuantifiedConstraints. There was already an issue about it https://gitlab.haskell.org/ghc/ghc/-/issues/16139 .
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE QuantifiedConstraints #-}
data Rose f a = Branch a (f (Rose f a))
type Eq1 f = (forall b. Eq b => Eq (f b))
{-
ng.hs:6:33: error:
• Expected a type, but ‘Eq (f b)’ has kind ‘Constraint’
• In the type ‘(forall b. Eq b => Eq (f b))’
In the type declaration for ‘Eq1’
|
6 | type Eq1 f = (forall b. Eq b => Eq (f b))
| ^^^^^^^^
Failed, no modules loaded.
-}
instance (Eq a, Eq1 f) => Eq (Rose f a) where
Branch x1 c1 == Branch x2 c2 = x1==x1 && c1==c2
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE QuantifiedConstraints #-}
data Rose f a = Branch a (f (Rose f a))
instance (Eq a, forall b. Eq b => Eq (f b)) => Eq (Rose f a) where
Branch x1 c1 == Branch x2 c2 = x1==x1 && c1==c2
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RankNTypes #-}
import Data.Kind
data Rose f a = Branch a (f (Rose f a))
type Eq1 f = (forall b. Eq b => Eq (f b)) :: Constraint
instance (Eq a, Eq1 f) => Eq (Rose f a) where
Branch x1 c1 == Branch x2 c2 = x1==x1 && c1==c2
resolver: nightly-2020-08-03
packages: []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment