Skip to content

Instantly share code, notes, and snippets.

@k0001
Created April 21, 2017 14:35
Show Gist options
  • Save k0001/2ff37a939f85cd6ae4b653060133bc58 to your computer and use it in GitHub Desktop.
Save k0001/2ff37a939f85cd6ae4b653060133bc58 to your computer and use it in GitHub Desktop.
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
import Data.Kind
import GHC.Exts (Constraint)
import GHC.TypeLits (Nat)
type family StarMaker k :: Constraint where
StarMaker Type = ()
StarMaker (_ -> x) = StarMaker x
a :: StarMaker Type => ()
a = ()
b :: StarMaker (Type -> Type) => ()
b = ()
c :: StarMaker Nat => ()
c = ()
d :: StarMaker (Nat -> Type) => ()
d = ()
e :: StarMaker (Type -> Nat) => ()
e = ()
-- Example GHCI interaction
--
-- @
-- > a
-- ()
--
-- > b
-- ()
--
-- > c
-- <interactive>:36:1: error:
-- • Could not deduce: StarMaker Nat arising from a use of ‘c’
-- • When instantiating ‘it’, initially inferred to have
-- this overly-general type:
-- StarMaker Nat => ()
-- NB: This instantiation can be caused by the monomorphism restriction.
-- > d
-- ()
--
-- > e
-- <interactive>:38:1: error:
-- • Could not deduce: StarMaker Nat arising from a use of ‘e’
-- • When instantiating ‘it’, initially inferred to have
-- this overly-general type:
-- StarMaker (Type -> Nat) => ()
-- NB: This instantiation can be caused by the monomorphism restriction.
-- @
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment