Skip to content

Using an array for Application/FunctionCall #238

@jfmengels

Description

@jfmengels

The arguments for Expression.Application (renamed to FunctionCall in v8) are stored in a List. That has the unfortunate consequence that in the parser we have to append a newly discovered argument to the end:

Expression.Application (args ++ [ right ])

And as far as I understand, we have to do that for new argument. I'm pretty sure that making this operation efficient would make the parser quite faster, as function calls are very common. (Maybe we have to rethink function calls in the pratt parser, but I haven't been able to figure out how).

My proposal is to have the arguments to a function call be an Array. I'm still brainstorming so I'm not entirely convinced either.

Pros:

  • Faster parsing of function calls
  • Access to the n-th argument of a function call becomes much more performant.
  • Transforming pipelines to FunctionCalls is faster because appending to the end is fast (we do this in elm-review-simplify quite a lot for instance)

Cons:

  • No more pattern matching on arguments. This is a real shame though...
  • Iteration may be more painful in some cases, as we lose the ability to iterate through
  • We need a representation of a non-empty Array, as in v8 we introduced the guarantee that function calls have at least one argument. We could do FunctionCall fnNode firstArg arrayOfArgs ->, but that would mean that accessing the N-th argument becomes less straightforward.

Let me know what you think.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions