Skip to content

Commit bf46dc5

Browse files
committed
SKI combinators
1 parent fed13c0 commit bf46dc5

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Diff for: ski.hs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 ++ ")"

0 commit comments

Comments
 (0)