Skip to content

Add DreamCoder abstraction typing (converter + compute_type_abs) - #375

Open
kavigupta wants to merge 1 commit into
mainfrom
ns-abstraction-typing
Open

Add DreamCoder abstraction typing (converter + compute_type_abs)#375
kavigupta wants to merge 1 commit into
mainfrom
ns-abstraction-typing

Conversation

@kavigupta

Copy link
Copy Markdown
Owner

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 NeuroSym AbstractionProduction.
  • 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 a LambdaTypeSignature, not a function. A naive implementation asserts there. Here each #k gets 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 (#0 first).

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

  • the abstraction that a naive impl crashes on → now skips cleanly
  • #(lambda (lambda (gt? $1 (sum $0))))(i, [i]) -> b (correct argument order)

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant