#15: Simple Combinators

Tagged as challenge

Written on 2018-01-30

Part 1

Implement the following combinators, high-order functions that are usually composed together. (Here we specify the type signatures in Haskell-like notation.)

  1. (constantly x), a function which takes an argument x and produces a unary function which always returns x.
  2. Using constantly, implement yes which always returns a true value, and no which always returns a false value.
  3. (complement f), a function which takes a function returning a Boolean, and produces another function which does the same but with the Boolean inverted.
  4. (conjunction f g) which returns a function which takes an argument and returns true iff both f and g are satisfied by x.
  5. (disjunction f g) which is like conjunction but checks iff either f or g are satisfied by the input.

One should note the similarity between these functions and some of the basic unary and binary Boolean predicates.

Part 2

Write out the type signature of each of the above functions.

Part 3

Implement Fizz Buzz using these combinators.


Unless otherwise credited all material copyright © 2010–2018 by Robert Smith