elm-lang/virtual-dom/VirtualDom.js, F2(), F3(), A2(), A3()

225 views
Skip to first unread message

jeff...@gmail.com

unread,
Aug 23, 2016, 3:23:09 PM8/23/16
to Elm Discuss
The source code for Elm virtual-dom contains a file VirtualDom.js
In this file are calls to functions F2(), F3(), A2(), A3().
I can't find where these functions are defined or what they do, and I would like to know.

OvermindDL1

unread,
Aug 23, 2016, 3:33:25 PM8/23/16
to Elm Discuss
https://github.com/elm-lang/elm-make/blob/master/src/Pipeline/Generate.hs

In the Elm core, they are just wrappers like:

```javascript
function F2(fun)
{
  function wrapper(a) { return function(b) { return fun(a,b); }; }
  wrapper.arity = 2;
  wrapper.func = fun;
  return wrapper;
}

function A2(fun, a, b)
{
  return fun.arity === 2
    ? fun.func(a, b)
    : fun(a)(b);
}
```

Joey Eremondi

unread,
Aug 23, 2016, 3:35:55 PM8/23/16
to elm-d...@googlegroups.com
They get bundled into the Runtime of a generated Elm file.

They allow for currying of JS functions. F2 takes a 2-argument JS function and returns a curried version of it (takes one argument, and returns another function taking one argument).

A2 is for applying two arguments to a curried function.

You need to use these when returning functions to Elm, or calling Elm functions, since they're meant for dealing with the function format Elm uses internally.

--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jeff...@gmail.com

unread,
Aug 23, 2016, 5:21:03 PM8/23/16
to Elm Discuss
Thanks.
Reply all
Reply to author
Forward
0 new messages