Created
April 21, 2017 15:28
-
-
Save k0001/6af281adedcfe1a33decceefbead1b69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE FlexibleContexts #-} | |
| {-# LANGUAGE FlexibleInstances #-} | |
| {-# LANGUAGE TypeFamilies #-} | |
| {-# LANGUAGE TypeInType #-} | |
| {-# LANGUAGE KindSignatures #-} | |
| {-# LANGUAGE ScopedTypeVariables #-} | |
| {-# LANGUAGE PolyKinds #-} | |
| import Data.Kind (Type) | |
| import GHC.TypeLits (Nat) | |
| class HasAssociatedKind k where | |
| type AssociatedKind k :: k' | |
| instance HasAssociatedKind Type where | |
| type AssociatedKind Type = Type | |
| instance HasAssociatedKind k2 => HasAssociatedKind (k1 -> k2) where | |
| type AssociatedKind (k1 -> k2) = AssociatedKind k2 | |
| class (HasAssociatedKind k, AssociatedKind k ~ Type) => UseAssociatedKind (t :: k) where | |
| type AssociatedType t x :: Type | |
| instance (HasAssociatedKind k, AssociatedKind k ~ Type) => UseAssociatedKind (t :: k) where | |
| type AssociatedType t x = x | |
| a :: UseAssociatedKind Int => AssociatedType Int () | |
| a = () | |
| b :: UseAssociatedKind Maybe => AssociatedType Maybe () | |
| b = () | |
| -- `c` fails to compile with an horrible message about AllowAmbiguousTypes | |
| c :: forall (t :: Type -> Nat). UseAssociatedKind t => AssociatedType t () | |
| c = () | |
| d :: forall (t :: Nat -> Type ). UseAssociatedKind t => AssociatedType t () | |
| d = () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment