19
3
I got the following question at a test:
Write a function
f
with the following typea -> b -> (a -> b)
.a
andb
should not be bound in any sense, the shorter the code, the better.
I came up with f a b = \x -> snd ([a,x],b)
. Can you find something tinier?
Currently the winner is: f _=(.f).const
Can the answer be a partial function? – Post Rock Garf Hunter – 2018-06-10T15:14:38.753
If a more general type is allowed:
f = const const
. – hammar – 2014-02-13T12:22:02.247@hammar: or
f _ b _ = b
, but, given the solution in the question, I suspect a more general type is not allowed. – Tikhon Jelvis – 2014-02-13T12:31:33.3876If a more general type is allowed, why not
f = id
? – Tom Ellis – 2014-02-13T13:18:47.4077In fact if a more general type is allowed then
f = f
is a solution, so I guess the conditions on the type are very important! – Tom Ellis – 2014-02-13T13:56:00.2973A more general type is not allowed, your assumptions were correct. – Radu Stoenescu – 2014-02-14T09:28:11.090
If you're allowed to import Control.Applicative, you can replace
const
bypure
, which is one character less. – bennofs – 2014-02-14T23:08:01.853