Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an experiment to lift some restrictions in the mlton monomorphization PR #229
There are many different ways to solve the problem of (mutual) recursion over datatypes / records which are introduced by monomorphization. None is really satisfying.
https://gist.github.com/b-studios/c52a5c7a9cfa6c0021f441d3ac2655a2
Alternative 1
This works, but is suboptimal, since ALL block member selections need to be translated to first "force". I don't like it, but it is the only solution so far, that actually works...
Alternative 2
Here is another version of the same idea, but it does not require to change any use sites:
It only requires to redefine the extractors locally (since they need to force
self
). However, it does not work in MLton (and also variants) sincemyFun
will not be generalized.Also local function definitions will not be generalized.
Alternative 3
This does also not work:
Due to let generalization failing on
myFun
. Annotating explicitly gives:makeFun ()
is not a value and does not follow the value restriction! It does not know that it is pure, which would be an alternative to the value restriction..Summary
So in the end, it looks like we can only go with Alternative 1 which is implemented in this PR.
Here is a very small and preliminary nano benchmark to check that this encoding does not massively lead to performance problems:
https://gist.github.com/b-studios/59d48fb4873341d7c64cc4f57ded953d