Closed liamoc closed 11 years ago
I'm not really sure this fixes it as I don't remember how this code works since it is no longer related to my thesis. Are you sure this is a fix and doesn't introduce more bugs? I can see this trick being used in at least 2 other places and I can go change it if you are sure.
-Matt
It seems to work for me. The goal is to ensure that the same variable is never used in two different contexts. Seeing as the context will be different after each use of a variable, this makes it impossible to use the same variable twice.
With the rank-2 type, the context h is specialised on each usage of the repeated variable to different contexts. Without the rank-2 type, the context h is global in scope and therefore there can only be one.
This does fix the problem, as far as I can tell. I'm not sure if the rest of it needs changes, I haven't examined it all in detail, just yet.
I found your trick most useful though as I am currently working on a linear-typed deeply-embedded DSL in Haskell for my work, so I needed an HOAS alternative to Oleg's de Bruijn encoding. Thanks for that.
This incorrectly typechecks:
In other words, in the case where two variables have the same (linear) type, it does not ensure that both variables are used once, but instead ensures that either variable is used twice.
To fix this, simply remove the Rank-2 type from lam:
There may be similar bugs elsewhere in your tagless class.