The Haskell function
biSp has type signature
biSp :: (a -> c) -> (b -> d) -> (c -> d -> e) -> a -> b -> e
and (for those who prefer combinator calculus) can be defined as
biSp g h f x y = f (g x) (h y)
Your task is to implement
biSp in point-free form (equivalently: as a combinator without any lambdas) using only two primitives:
(.) :: (b -> c) -> (a -> b) -> a -> c flip :: (a -> b -> c) -> b -> a -> c
(.) f g x = f (g x) flip f x y = f y x
For those with a background in combinator calculus, these are respectively the B and C combinators.
You may define helper functions so long as they are point-free. Your score is the total number of terms in all right-hand-side expressions.
You can test a Haskell solution without installing any software using Ideone. By providing an explicit type alongside the definition you ensure a compile-time error if the function is incorrect. E.g. using the
:pl reference implementation (online demo):
biSp :: (a -> c) -> (b -> d) -> (c -> d -> e) -> a -> b -> e biSp = flip . ((flip . ((.) .)) .) . flip (.) main = putStrLn "Compiled ok"