7

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
```

or

```
(.) 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.

### Testing

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"
```

I'm not really sure what it is the above is doing (note that I'm not very familiar with functional programming). – Kyle Kanos – 2014-05-29T18:37:03.110

I added a link. Why so many close votes? Is this not a good programming puzzle? – dspyz – 2014-05-29T18:40:40.400

@dspyz the close-vote reason selected so far is "it's unclear what you're asking". so I guess that's the reason. – Martin Ender – 2014-05-29T18:43:11.407

Even with the link, I'm still not sure what you want (possibly due to my lack of familiarity with functional languages). In general, language-specific tasks are looked down because not everyone can participate. – Kyle Kanos – 2014-05-29T18:43:37.653

Yeah, I guess this could be written in any functional language. But it lends itself more nicely to haskell. I'll remove the haskell tag. What's unclear about it? – dspyz – 2014-05-29T18:44:47.880

1This is indeed very language specific. But the question is certainly clear, for someone with minimal knowledge of Haskell (very minimal in my case). – ugoren – 2014-05-29T19:01:27.113

Actually, I'm starting to wonder if an optimal solution could be found with some sort of BFS. There's probably a lot of theory I don't know revolving around this sort of thing. – dspyz – 2014-05-29T19:07:33.587

Looks like an interesting problem, but perhaps out of reach for those unfamiliar with haskell. If possible, can you provide some examples of expected input and output? – Digital Trauma – 2014-05-29T19:15:33.303

I don't think the problem really lends itself to input and output. However, I think anything which matches the type signature and compiles (not including recursive functions and calls to "error") is correct. So, in that sense, you could say the input is the GHC compiler together with the type signature and the output is no compilation error – dspyz – 2014-05-29T19:20:01.073

Edited to clarify for people who are familiar with combinator calculus but not Haskell, or who know other FP languages but don't want to try finding proper definitions of

`flip`

and`(.)`

. I was tempted to delete the [tag:haskell] tag, but I wasn't sure why you had edited it back in after once editing it out. I don't think there's anything Haskell-specific about this other than the names of the functions: the type signature syntax is the same as SML, and the core question could be an exercise inTo Mock a Mockingbird. – Peter Taylor – 2014-05-30T08:57:24.353