Skip to content

Commit

Permalink
Optimize arity wrapper for << and >>
Browse files Browse the repository at this point in the history
Prior to this, << (and similarly >>) would be compiled to

  var $elm$core$Basics$composeL = F3(function (g, f, x) { ... })

which doesn't match the call sites, which is always of the shape

  A2($elm$core$Basics$composeL, f, g)

This change makes it so that composeL/composeR are now wrapped with A2,
which improves the performance by about 30%.
  • Loading branch information
jfmengels committed Jul 15, 2024
1 parent 65cea00 commit 31038c2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Basics.elm
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,9 @@ So our example expands out to something like this:
\n -> not (isEven (sqrt n))
-}
composeL : (b -> c) -> (a -> b) -> (a -> c)
composeL g f x =
g (f x)
composeL g f =
\x ->
g (f x)


{-| Function composition, passing results along in the suggested direction. For
Expand All @@ -857,8 +858,9 @@ example, the following code checks if the square root of a number is odd:
-}
composeR : (a -> b) -> (b -> c) -> (a -> c)
composeR f g x =
g (f x)
composeR f g =
\x ->
g (f x)


{-| Saying `x |> f` is exactly the same as `f x`.
Expand Down

0 comments on commit 31038c2

Please sign in to comment.