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

Type inference fails on some recursive functions

Open edwardpeters opened this issue 1 year ago • 0 comments

Describe the bug Some recursive functions cause the compiler to fail to type check.

To Reproduce The following code compiles in native elm:

count : Int -> Int
count x = 
    if x == 0
        then 0
        else x + (count (x-1))

In morphir-elm, it gives the following error:

Error: [
  [
    "RepoError",
    "Cannot process value",
    [
      [
        "TypeCheckError",
        [
          [
            "example",
            "module"
          ]
        ],
        [
          "count"
        ],
        [
          "UnifyError",
          [
            "CouldNotUnify",
            "NoUnificationRule",
            [
              "meta_ref",
              [
                [
                  [
                    "morphir"
                  ],
                  [
                    "s",
                    "d",
                    "k"
                  ]
                ],
                [
                  [
                    "basics"
                  ]
                ],
                [
                  "int"
                ]
              ],
              [],
              null
            ],
            [
              "meta_fun",
              [
                "meta_var",
                16
              ],
              [
                "meta_var",
                17
              ]
            ]
          ]
        ]
      ]
    ]
  ]
]

Expected behavior Type inference should be able to resolve this, and I'm unclear why it is trying to unify an Int with a function.

Desktop (please complete the following information):

  • OS: OSX
  • Version 2.88.0

edwardpeters avatar Feb 20 '24 16:02 edwardpeters