Tagged as challenge
Written on 2018-01-30
Implement the following combinators, high-order functions that are usually composed together. (Here we specify the type signatures in Haskell-like notation.)
(constantly x)
, a function which takes an argument x
and produces a unary function which always returns x
.yes
which always returns a true value, and no
which always returns a false value.(complement f)
, a function which takes a function returning a Boolean, and produces another function which does the same but with the Boolean inverted.(conjunction f g)
which returns a function which takes an argument and returns true iff both f
and g
are satisfied by x
.(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.
Write out the type signature of each of the above functions.
Implement Fizz Buzz using these combinators.