File tree 1 file changed +39
-0
lines changed
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ -- TODO: add codewars link
2
+
3
+ {-# LANGUAGE GADTs #-}
4
+ {-# LANGUAGE KindSignatures #-}
5
+ {-# LANGUAGE DataKinds #-}
6
+
7
+ data SKI :: * -> * where
8
+ S :: SKI ((a -> b -> c ) -> (a -> b ) -> a -> c )
9
+ K :: SKI (a -> b -> a )
10
+ I :: SKI (a -> a )
11
+ Ap :: SKI (a -> b ) -> SKI (a ) -> SKI (b )
12
+
13
+ -- a convenient symbol to avoid tons of parentheses
14
+ infixl <|
15
+ (<|) = Ap
16
+
17
+ instance Show (SKI c ) where
18
+ show S = " S"
19
+ show K = " K"
20
+ show I = " I"
21
+ show (Ap a b) = " (" ++ show a ++ " " ++ show b ++ " )"
22
+
23
+ -- equality is guaranteed by type system
24
+ -- you can check this by `Ap (Ap S K) _ == I`
25
+ instance Eq (SKI c ) where
26
+ a == b = True
27
+
28
+ data Variables a = Sing a
29
+ | Cons a (Variables a )
30
+
31
+ -- data Lambda :: Variables * -> * where
32
+ -- Var :: a -> Lambda (Sing a)
33
+ -- Abs :: a -> Lambda b -> Lambda (Just a)
34
+ -- App :: Lambda a -> Lambda b -> Lambda c
35
+ --
36
+ -- instance (Show a) => Show (Lambda (Maybe a)) where
37
+ -- show (Var a) = show a
38
+ -- show (Abs x y) = "(λ" ++ show x ++ ". " ++ show y++ ")"
39
+ -- show (App a b) = "(" ++ show a ++ " " ++ show b ++ ")"
You can’t perform that action at this time.
0 commit comments