morphir-elm icon indicating copy to clipboard operation
morphir-elm copied to clipboard

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

Open edwardpeters opened this issue 1 year ago • 0 comments

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 https://github.com/finos/morphir-scala/discussions/529

edwardpeters avatar Feb 08 '24 16:02 edwardpeters