Last active
August 1, 2023 00:10
-
-
Save wasabi315/4093f3f366bb5d4635a2744aff01f757 to your computer and use it in GitHub Desktop.
CConst invariant (https://byorgey.wordpress.com/2023/07/13/compiling-to-intrinsically-typed-combinators#compiling-type-indexed-combinators-to-haskell)
This file contains 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
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