-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathski.hs
39 lines (32 loc) · 1.08 KB
/
ski.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
-- TODO: add codewars link
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
data SKI :: * -> * where
S :: SKI ((a -> b -> c) -> (a -> b) -> a -> c)
K :: SKI (a -> b -> a)
I :: SKI (a -> a)
Ap :: SKI (a -> b) -> SKI (a) -> SKI (b)
-- a convenient symbol to avoid tons of parentheses
infixl <|
(<|) = Ap
instance Show (SKI c) where
show S = "S"
show K = "K"
show I = "I"
show (Ap a b) = "(" ++ show a ++ " " ++ show b ++ ")"
-- equality is guaranteed by type system
-- you can check this by `Ap (Ap S K) _ == I`
instance Eq (SKI c) where
a == b = True
data Variables a = Sing a
| Cons a (Variables a)
--data Lambda :: Variables * -> * where
-- Var :: a -> Lambda (Sing a)
-- Abs :: a -> Lambda b -> Lambda (Just a)
-- App :: Lambda a -> Lambda b -> Lambda c
--
--instance (Show a) => Show (Lambda (Maybe a)) where
-- show (Var a) = show a
-- show (Abs x y) = "(λ" ++ show x ++ ". " ++ show y++ ")"
-- show (App a b) = "(" ++ show a ++ " " ++ show b ++ ")"