@@ -18,6 +18,7 @@ import type { Obj } from "@/schemas/objs/union";
1818import { PolynomialObj } from "@/schemas/objs/unions/polynomials" ;
1919import { fnTokenSchema } from "@/schemas/token/function-literal" ;
2020import { Effect , Either , Match , Schema } from "effect" ;
21+ import { left } from "effect/Either" ;
2122import type { ParseError } from "effect/ParseResult" ;
2223import type { KennethParseError } from "src/errors/kenneth/parse" ;
2324import type { DiffExp } from "src/schemas/nodes/exps/diff" ;
@@ -58,6 +59,29 @@ import {
5859 STRING_OPERATOR_TO_FUNCTION_MAP ,
5960} from "./constants" ;
6061
62+ const isContaminatedExpression = (
63+ exp : Exp ,
64+ contaminatedIdents : readonly IdentExp [ ] ,
65+ ) : boolean =>
66+ Match . value ( exp ) . pipe (
67+ Match . tag ( "IdentExp" , ( ident ) =>
68+ contaminatedIdents . some ( ( id ) => IdentExpEq ( id , ident ) ) ,
69+ ) ,
70+ Match . tag (
71+ "InfixExp" ,
72+ ( { left, right } ) =>
73+ isContaminatedExpression ( left , contaminatedIdents ) ||
74+ isContaminatedExpression ( right , contaminatedIdents ) ,
75+ ) ,
76+ Match . tag ( "PrefixExp" , ( { right } ) =>
77+ isContaminatedExpression ( right , contaminatedIdents ) ,
78+ ) ,
79+ Match . tag ( "CallExp" , ( { args } ) =>
80+ args . some ( ( arg ) => isContaminatedExpression ( arg , contaminatedIdents ) ) ,
81+ ) ,
82+ Match . orElse ( ( ) => false ) ,
83+ ) ;
84+
6185// this error is what we pay for!!!
6286const nodeEvalMatch = ( env : Environment ) =>
6387 matchKnode ( {
@@ -106,10 +130,8 @@ const nodeEvalMatch = (env: Environment) =>
106130 ) . pipe (
107131 Effect . flatMap ( ( obj ) =>
108132 Effect . gen ( function * ( ) {
109- const identoverlap = env . idents . some ( ( ident ) =>
110- args . some (
111- ( arg ) => isIdentExp ( arg ) && ident . value === arg . value ,
112- ) ,
133+ const identoverlap = args . some ( ( arg ) =>
134+ isContaminatedExpression ( arg , env . idents ) ,
113135 ) ;
114136
115137 const either =
@@ -184,6 +206,7 @@ export const evalDiff = (diffExp: DiffExp) => (env: Environment) =>
184206 yield * Effect . log ( "diff:" ) ;
185207 const diffSoftEval = yield * diffPolynomial ( softEval , diffExp . params [ 0 ] ) ;
186208
209+ yield * Effect . log ( "diff-eval" , diffSoftEval ) ;
187210 // maybe simplest will be to convert back to exp and Eval.
188211 const convertToExp = ( obj : PolynomialObj ) : Effect . Effect < Exp , ParseError > =>
189212 Match . value ( obj ) . pipe (
0 commit comments