Skip to content

Instantly share code, notes, and snippets.

@DrBoolean
Created July 20, 2017 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DrBoolean/c255cabc6c0d48bb9c0765a13551ae2a to your computer and use it in GitHub Desktop.
Save DrBoolean/c255cabc6c0d48bb9c0765a13551ae2a to your computer and use it in GitHub Desktop.
rep5
const Pair = (x, y) =>
({
 _0: x,
 _1: y,
 map: f => Pair(x, f(y))
})
// to :: Pair a -> (Bool -> a)
const to = ({_0, _1}) =>
 bool => bool ? _0 : _1
// from :: (Bool -> a) -> Pair a
const from = f =>
 Pair(f(true), f(false))
from(to(Pair(‘hot’, ‘cold’))) // Pair(‘hot’, ‘cold’)
to(from(x => !x ? ‘cold’ : ‘hot’)) // bool => bool ? _0 : _1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment