HVM icon indicating copy to clipboard operation
HVM copied to clipboard

Checker for the derivatives of `(λx(x x) λx(x x))`

Open steinerkelvin opened this issue 3 years ago • 11 comments

If a lambda that clones its argument is itself cloned, then its clones aren't allowed to clone each-other.

See https://github.com/Kindelia/HVM/issues/44 for more information, as well as the superposed duplication section on HOW.md.

Example of what is not allowed:

let f = λs λz (s (s z)) # a lambda that clones its argument
let g = f               # a clone of that lambda
(g f)                   # the clone will clone the original

steinerkelvin avatar Feb 03 '22 16:02 steinerkelvin

@quleuber Where would be a good place to add this check? I'm thinking either in rulebook::sanitize_rule or builder::build_dynfun, but what do you think?

nothingnesses avatar Feb 03 '22 17:02 nothingnesses

@nothingnesses Is this the first type-checker in HVM? If my understanding is correct, I wish it will be designed for future enhancement.

ken-okabe avatar Feb 03 '22 17:02 ken-okabe

For information, some terms a lot more natural than (λx(x x) λx(x x)) are forbidden as well, for instance (Map l1 (λf(Map l2 f))) (however, (Map l1 (λl2(Map l2 f))) is allowed and very common in functional programs, so the distinction to be made will have to be subtle).

Ekdohibs avatar Feb 03 '22 19:02 Ekdohibs

Why do you think (Map l1 (λf(Map l2 f))) is forbidden?

VictorTaelin avatar Feb 06 '22 00:02 VictorTaelin

Because it breaks the "clones must not clone their own clone" rule and produces incorrect results, see the comment in the other thread.

Ekdohibs avatar Feb 06 '22 10:02 Ekdohibs

@Ekdohibs it doesn't! But I see HVM can't reduce it now. That is actually due to a temporary HVM's limitation (it isn't generating labels for rhs dups), but this program doesn't actually hit the cloning limit (not even close). It is a relatively easy fix that should be patched in a few days.

VictorTaelin avatar Feb 06 '22 13:02 VictorTaelin

Hi! I'm really interested in this, but am still trying to understand this entirely. I'm taking a grad course on semantics for programming languages and would love to do my final project on HVM. I don't see any good first issue right now, but in the future please tag me :smile:

Andrew-Fryer avatar Feb 10 '22 23:02 Andrew-Fryer

This is a very complex subject though, definitely not a good "first issue". We plan to make this repo more contribution friendly soon! Now if you do want a PhD-level challenge, let me know and I can give you pointers on how this could be done.

VictorTaelin avatar Feb 10 '22 23:02 VictorTaelin

@VictorTaelin I caught that :laughing: I'm going to at least get my head around builder.rs and maybe have a chat with my prof first. Thanks!

Andrew-Fryer avatar Feb 11 '22 00:02 Andrew-Fryer

The algorithm is described here: https://arxiv.org/pdf/cs/0305011

Appendix has a good example of type checking, although the term there does not type check.

In general though HVM could handle ALL lambda terms by inserting Lamping level-changing terms very very rarely in the places where the Coppola type checking algorithm proves it is necessary.

lukaszlew avatar Feb 21 '22 03:02 lukaszlew

@lukaszlew yep, that sounds like an awesome approach. I think that paper is too restrictive though, since it only allows EAL-typeable terms. There are many, even simple, terms that aren't EAL typeable yet are perfectly fine.

VictorTaelin avatar Feb 21 '22 16:02 VictorTaelin