1

I'm looking for a function of type (a -> b -> c -> d) -> c -> a -> b -> d. In other words, a function which can partially apply the third argument to a function.

Is there a library that has such a function? Would it be useful for me to make one or add such functions to one of the elm-community libraries (perhaps elm-function-extra)?

dta
  • 654
  • 4
  • 19

2 Answers2

4

I don't believe there exists a library with the function but it's trivial to define:

f : (a -> b -> c -> d) -> c -> a -> b -> d
f fn c a b =
  fn a b c

The question of whether it belongs in a community library is probably best handled as a discussion in the mailing list or other contribution channels.

I could not find an equivalent Haskell function on Hoogle, so my hunch would be that if it hasn't been useful enough to generalize in the Haskell ecosystem, where much of Elm draws its inspiration, it probably isn't a good fit for a core Elm Community library, but you can always make your case in the community forums!

Chad Gilbert
  • 36,115
  • 4
  • 89
  • 97
  • I intended to make a smart-ass comment about you having mistyped 'Google', but then found out Hoogle is an actual thing for Haskell... – Tails Aug 26 '19 at 11:21
3

The Elm package website now links to a utility to search functions by type signature.

I used it to look for your function and found:

swirlr : (a -> b -> c -> d) -> c -> a -> b -> d

It is located in Fresheyeball/elm-function-extra.

You seem to already know that (or have the intuition) but note that, just from looking at the type, you can know that this is the function which you are looking for. Indeed, it is a theorem that there exist only one function of this type (unless you use Debug.crash to implement it!). Here is the 1989 article which described this result but to be honest, it's quite hard to read.

Zimm i48
  • 2,901
  • 17
  • 26