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 #35

Closed paulyoung closed 7 years ago

paulyoung commented 7 years ago

When ready, this should close #27.

It's not clear to me how to determine whether NonRec or Rec should be used.

@paf31, can you offer any advice?

paulyoung commented 7 years ago

readBind currently uses objectProp which is insufficient in its current form. This is because so far we have only been concerned with objects containing a single key.

I think what probably needs to happen is to introduce a function called objectProps which is similar to objectProp but instead just maps the keys to record pairs. objectProp could then be implemented in terms of objectProps.

FWIW, I originally wanted objectProp to return F Prop and tried to create PR to add a newtype instance to Prop but ran into an issue that I thought was fixed in 0.10.3 after reading this mailing list thread, but in the latest message the OP was still having trouble

paulyoung commented 7 years ago

Scratch that – objectProp should be fine because decls is an array of objects with a single key.

paulyoung commented 7 years ago

While the scope of the JSON fixture used here is consistent with the other tests, I can't see how we can be certain that f is the same as Example.f and so on without the ModuleName also being present in the JSON.

paulyoung commented 7 years ago

@paf31 explained that it's not possible to distinguish between NonRec and Rec Based on the information in the JSON output (as I was beginning to suspect).

Phil suggested changing the type of Bind to something like:

newtype Bind a = Bind (Array (Tuple Ident (Expr a)))
paulyoung commented 7 years ago

Scratch that – objectProp should be fine because decls is an array of objects with a single key.

I was wrong about this, the example in https://github.com/paulyoung/purescript-corefn/issues/27#issuecomment-269918957 shows an object with multiple keys.

paulyoung commented 7 years ago

In hindsight, I probably could have used NonRec for an object with a single key and Rec for an object with multiple keys.

I'm not sure if there would be any benefit to that though.