roc/test/snapshots/lambda_capture/lambda_capture_basic.md
2025-11-23 09:20:48 -05:00

1.1 KiB

META

description=Basic lambda capture detection during canonicalization
type=expr

SOURCE

(|x| |y| x + y)(1)(2)

EXPECTED

NIL

PROBLEMS

NIL

TOKENS

OpenRound,OpBar,LowerIdent,OpBar,OpBar,LowerIdent,OpBar,LowerIdent,OpPlus,LowerIdent,CloseRound,NoSpaceOpenRound,Int,CloseRound,NoSpaceOpenRound,Int,CloseRound,
EndOfFile,

PARSE

(e-apply
	(e-apply
		(e-tuple
			(e-lambda
				(args
					(p-ident (raw "x")))
				(e-lambda
					(args
						(p-ident (raw "y")))
					(e-binop (op "+")
						(e-ident (raw "x"))
						(e-ident (raw "y"))))))
		(e-int (raw "1")))
	(e-int (raw "2")))

FORMATTED

NO CHANGE

CANONICALIZE

(e-call
	(e-call
		(e-lambda
			(args
				(p-assign (ident "x")))
			(e-closure
				(captures
					(capture (ident "x")))
				(e-lambda
					(args
						(p-assign (ident "y")))
					(e-binop (op "add")
						(e-lookup-local
							(p-assign (ident "x")))
						(e-lookup-local
							(p-assign (ident "y")))))))
		(e-num (value "1")))
	(e-num (value "2")))

TYPES

(expr (type "a where [a.from_numeral : Numeral -> Try(a, [InvalidNumeral(Str)])]"))