paulyoung / purescript-corefn

A library for working with the PureScript functional core.
Apache License 2.0
23 stars 7 forks source link

Mutually recursive bindings #27

Closed paulyoung closed 7 years ago

paulyoung commented 7 years ago

As explained in https://github.com/paulyoung/purescript-corefn/pull/25#issuecomment-269015471, mutually recursive bindings are not yet supported (mostly due to lack of a minimal example to test against).

tfausak commented 7 years ago

I haven't cracked this nut yet, but I think this is the shortest pair of mutually recursive bindings:

module Example where

f :: forall a. a -> a
f x = g x

g :: forall a. a -> a
g x = f x

That is represented as this corefn:

{
  "Example": {
    "builtWith": "0.10.3",
    "exports": [ "f", "g" ],
    "imports": [ "Prim", "Example" ],
    "foreign": [],
    "decls": [
      {
        "g": [
          "Abs",
          "x",
          [
            "App",
            [ "Var", "Example.f" ],
            [ "Var", "x" ]
          ]
        ],
        "f": [
          "Abs",
          "x",
          [
            "App",
            [ "Var", "Example.g" ],
            [ "Var", "x" ]
          ]
        ]
      }
    ]
  }
}
paulyoung commented 7 years ago

Thanks @tfausak! I'll give this a try soon.

I'm a bit surprised to see the module itself in the import list, but I guess it sort of makes sense.

I'm currently filtering out the import for Prim in some backend implementations. I suppose I'd need to do the same.

tfausak commented 7 years ago

I think the module shows up in its own import list because the references are fully qualified. You end up with essentially f = \ x -> Example.g x instead of the simpler but potentially ambiguous f = \ x -> g x.

paulyoung commented 7 years ago

@tfausak I made a bit of progress on this in #35.