Skip to content

Instantly share code, notes, and snippets.

@wreczek
Created January 26, 2018 13:31
Show Gist options
  • Save wreczek/b0e3d2f11d2a5a54be214b787907379c to your computer and use it in GitHub Desktop.
Save wreczek/b0e3d2f11d2a5a54be214b787907379c to your computer and use it in GitHub Desktop.
module Pairs
(first, second,pair) where
--needed for first and second operations, uses true and false
-- from ChurchBooleans
import ChurchBooleans
-- functions that are needed for list operations
first :: ((t1 -> t2 -> t1) -> t) -> t
first = \f -> f(true)
second :: ((t1 -> t2 -> t2) -> t) -> t
second = \f -> f(false)
pair :: t1 -> t2 -> (t1 -> t2 -> t) -> t
pair= \x y f -> f(x)(y)
-- to_integer(second(pair(one)(two))) returns 2
-- unchurch(second(pair(one)(church(15)))) returns 15
-- unchurch(second(pair(one)(church(15)))) returns 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment