!
, .
-, Haskell , .
infixr 0 :->
data Type = Unit | Type :-> Type
, , .
Comb, .
data Comb a where
S :: Comb ((a :-> b :-> c) :-> (a :-> b) :-> a :-> c)
K :: Comb (a :-> b :-> a)
(:$) :: Comb (a :-> b) -> Comb a -> Comb b
i = S :$ K :$ i
b = (S :$ (K :$ S)) :$ K
c = S :$ (S :$ (K :$ (S :$ (K :$ S) :$ K)) :$ S) :$ (K :$ K)
w = S :$ S :$ (S :$ K)
. , , , , .
data Ex f = forall a. Ex (f a)
: , ? a Comb , , Comb. .
data (f :*: g) i = f i :*: g i
( .) :*: , , . Ex -: , . , f GADT, - , f g.
type Sg f g = Ex (f :*: g)
pattern Sg x y = Ex (x :*: y)
: GADT, .
data Typey t where
Unity :: Typey Unit
Arry :: Typey a -> Typey b -> Typey (a :-> b)
Typey . t Typey t. , Typey t, , t.
. Typey Type; Type . , .
- . AComb a Comb . Comb; , .
type AComb = Sg Typey Comb
($$), AComb AComb? Typey, , . , , .
, GADT, . Refl, GHC, a b . , Refl, GHC a ~ b .
data a :~: b where
Refl :: a :~: a
withEq :: a :~: b -> (a ~ b => r) -> r
withEq Refl x = x
:->.
arrEq :: (a :~: c) -> (b :~: d) -> (a :-> b) :~: (c :-> d)
arrEq Refl Refl = Refl
, , , Type. singleton Typey s, , . , , .
tyEq :: Typey t -> Typey u -> Maybe (t :~: u)
tyEq Unity Unity = Just Refl
tyEq (Arry a b) (Arry c d) = liftA2 arrEq (tyEq a c) (tyEq b d)
tyEq _ _ = Nothing
withTyEq :: Typey t -> Typey u -> (t ~ u => a) -> Maybe a
withTyEq t u x = fmap (\p -> withEq p x) (tyEq t u)
, $$. :
f : a -> b y : a
------------------- App
f y : b
, $$ , , . , ( withTyEq) , .
($$) :: AComb -> AComb -> Maybe AComb
Sg (Arry a b) x $$ Sg t y = withTyEq a t $ Sg b (x :$ y)
_ $$ _ = Nothing
Typey . , parse :: String -> AComb , . .
, , , .
data Expr = S | K | Expr :$ Expr
parse :: String -> Parser Expr
typeCheck :: Expr -> Maybe AComb
( ) typeCheck, , , -:
data Void : Set where
Not : Set -> Set
Not a = a -> Void
data TypeError : Expr -> Set where
notArr : Not (IsFunction f) -> TypeError (f :$ x)
mismatch : Not (domain f :~: type x) -> TypeError (f :$ x)
inFunc : TypeError f -> TypeError (f :$ x)
inArg : TypeError x -> TypeError (f :$ x)
typeCheck : (e : Expr) -> Either (TypeError e) AComb
typeCheck , , , ( ).
. , -.