HVM icon indicating copy to clipboard operation
HVM copied to clipboard

Reflection / rules depending on type constructors

Open nmushegian opened this issue 3 years ago • 3 comments

Thoughts on this? Allow pattern matching like this when used in a special 'reflect' term? I still don't understand the runtime enough to know if this info is always there for constant access or if it gets erased somehow. Maybe the purpose of the reflect op would be to capture and not erase this type tag, but I'm just freestyling.

(Reflect (x y)) = (Tag x)

want:   (Reflect (Pink (Val))  ->  (Tag (Pink))

nmushegian avatar May 06 '22 22:05 nmushegian

So this original thing fails to compile,

Invalid left-hand side
On rule: `(Reflect (x y)) = (Tag x)`.

This lets me compile run the program (it does not complain about invalid pattern), but does not match.

(a (Reflect (x y))) = (Tag x)

(Main) = (1 (Reflect (Pink (Val))))

I do not understand this at all

nmushegian avatar May 07 '22 11:05 nmushegian

IIRC you can't take constructors' value, the rule matches an application, I think, not a constructor

bsless avatar May 08 '22 05:05 bsless

I understand that you can't, but what I am asking is whether maybe you can, like theoretically could a reflection feature be built in like this in the current HVM paradigm, or would it be equivalent to designing reflection in a higher level language that compiles down

nmushegian avatar May 08 '22 12:05 nmushegian

That wouldn't be possible on HVM's paradigm :( on the interaction net view, that would imply you're pattern-matching on an application node, which isn't (and can't be) possible to do efficiently, sadly.

VictorTaelin avatar Nov 23 '22 15:11 VictorTaelin