Skip to content

Instantly share code, notes, and snippets.

@k0001
Created April 21, 2017 15:28
Show Gist options
  • Select an option

  • Save k0001/6af281adedcfe1a33decceefbead1b69 to your computer and use it in GitHub Desktop.

Select an option

Save k0001/6af281adedcfe1a33decceefbead1b69 to your computer and use it in GitHub Desktop.
{-# 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