Skip to content

Instantly share code, notes, and snippets.

@wasabi315
Last active August 1, 2023 00:10
Show Gist options
  • Save wasabi315/4093f3f366bb5d4635a2744aff01f757 to your computer and use it in GitHub Desktop.
Save wasabi315/4093f3f366bb5d4635a2744aff01f757 to your computer and use it in GitHub Desktop.
type family IsFun a where
IsFun (_ -> _) = 'True
IsFun _ = 'False
type NotFun a = IsFun a ~ 'False
data CTerm a where
CFun :: (CTerm a -> CTerm b) -> CTerm (a -> b)
CConst :: NotFun a => a -> CTerm a
instance Applicable CTerm where
($$) :: CTerm (a -> b) -> CTerm a -> CTerm b
CFun f $$ x = f x
-- Couldn't match type ‘'True’ with ‘'False’ arising from a use of ‘CConst’
-- bad = CConst id
-- The TypeError type family can be used here for a better error message.
type family NoFunParams a where
NoFunParams (a -> b) = (NotFun a, NoFunParams b)
NoFunParams _ = ()
runCTerm :: NoFunParams a => CTerm a -> a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment