Add DreamCoder abstraction typing (converter + compute_type_abs) - #375
Open
kavigupta wants to merge 1 commit into
Open
Add DreamCoder abstraction typing (converter + compute_type_abs)#375kavigupta wants to merge 1 commit into
kavigupta wants to merge 1 commit into
Conversation
Introduce `abstraction_production_from_dreamcoder`, which converts a DreamCoder/Stitch invented-primitive string (e.g. `#(lambda (gt? 1 (sum $0)))`) into a NeuroSym `AbstractionProduction`, and `DSL.compute_type_abs`, which infers its type. An abstraction parameter is a stitch metavariable `#k`. compute_type_abs types it wherever it appears -- including as the body of an inner lambda, where the parent production is a lambda (`LambdaTypeSignature`), not a function -- by giving it a fresh type variable resolved by unification, and keys it in the environment at a depth-adjusted slot so it survives lambda-unwinding. Parameters are collected into the abstraction's argument list in application order (`#0` first). Abstractions the list DSL cannot represent yet (e.g. a curried callback passed to `mapi`, which wants an uncurried multi-argument arrow) are skipped (return None), not crashed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR 1 of 4 in a stack that adds typed DreamCoder-abstraction support to the NeuroSym DSL. Merges into
main; the rest stack on this one.What
abstraction_production_from_dreamcoder(dsl, name, s)— convert a DreamCoder/Stitch invented-primitive string (e.g.#(lambda (gt? 1 (sum $0)))) into a NeuroSymAbstractionProduction.DSL.compute_type_abs— infer an abstraction's type.Why it's non-trivial
An abstraction parameter is a stitch metavariable
#k. It has to be typed wherever it appears — including as the body of an inner lambda, where the parent production is aLambdaTypeSignature, not a function. A naive implementation asserts there. Here each#kgets a fresh type variable resolved by unification, keyed in the environment at a depth-adjusted slot so it survives lambda-unwinding, and parameters are collected in application order (#0first).Abstractions the list DSL can't represent yet (e.g. a curried callback to
mapi, which wants an uncurried multi-argument arrow) are skipped (return None), not crashed — later PRs in the stack make more of them representable.Reproducing test
tests/s_exp/dreamcoder_abstractions_test.py::TestAbstractionParameterTyping#(lambda (lambda (gt? $1 (sum $0))))→(i, [i]) -> b(correct argument order)🤖 Generated with Claude Code