Skip to content

Morphir-Elm Interpreter fails with first-class or partially applied functions #1139

@edwardpeters

Description

@edwardpeters

Describe the bug
The morphir-elm based interpreter frequently fails to work with first class or higher order functions; in particular, it reliably fails whenever a first class function relies on anything from lexical scope.

To Reproduce
The following code works in native elm:

type MyEnum = TwoArg Int Int

unable_to_compute : Int -> MyEnum
unable_to_compute x = 
    let 
        inner = 
            let y = 5 in \z -> TwoArg y z
    in
        inner x

wrong_result : Int -> MyEnum
wrong_result x = 
    let 
        inner = TwoArg 5
    in
        inner x

In the morphir-elm interpreter, "unable_to_compute", as the name would imply, is unable to be computed. "wrong result" meanwhile ignores its input argument and results in "TwoArg 5".

Expected behavior
I would expect the behavior to match elm, with first-class functions maintaining locally scoped variables.

Desktop (please complete the following information):

  • OS:OSX
  • Browser Chrome
  • Version 2.89.0

Additional context
This may be relevant to the morphir-scala discussion on RTValue, MDM and IR at finos/morphir-scala#529

Metadata

Metadata

Assignees

No one assigned

    Labels

    taskTask level project item

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions