From 15b8a1751bd49a1c2e326bc49e643344f9b2c41b Mon Sep 17 00:00:00 2001 From: Vasiliy Vanchuk Date: Tue, 8 May 2018 14:34:12 +0400 Subject: [PATCH] Add combinators --- src/ChurchNum.hs | 6 ++++-- src/Combinators.hs | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 src/Combinators.hs diff --git a/src/ChurchNum.hs b/src/ChurchNum.hs index 0cc662a..f10ae44 100644 --- a/src/ChurchNum.hs +++ b/src/ChurchNum.hs @@ -13,6 +13,7 @@ module ChurchNum ( ) where import Base +import Combinators -- zero :: p2 -> t3 -> t3 zero = Base.flip constant @@ -21,8 +22,9 @@ zero = Base.flip constant one = apply -- two :: (t -> t) -> t -> t --- @help: can't figure out point free version -two x y = x $ x y +-- @help: can't figure out point free version (cause s-combinator is not) +-- two x y = x $ x y +two = s Base.compose identity -- inc :: Num a => a -> a inc = (+1) diff --git a/src/Combinators.hs b/src/Combinators.hs new file mode 100644 index 0000000..88490ff --- /dev/null +++ b/src/Combinators.hs @@ -0,0 +1,5 @@ +module Combinators where + +s f g x = f x (g x) -- S-combinator +identity x = x -- I-combinator +constant x y = y -- K -combinator