frank-lang / frank

Frank compiler
GNU General Public License v3.0
272 stars 9 forks source link

Fixed bug where adaptors reversed the order of instances when being typed. #8

Closed jasigal closed 2 years ago

jasigal commented 2 years ago

This PR fixes issue #7. Credit to @slindley for the fix. Before the fix, the should-fail example would type check, run, but produce the value a of type A, thus breaking preservation.

Explanation of bug and fix

Abilites are snoc lists, and so the rightmost interface instance is the active one. Suppose we have an interface Eff X and that the ambient ability, when restricted to Eff, is [Eff A, Eff B]. The list ns in applyAdaptor is a list of indices into the restricted ambient ability as a snoc list, i.e. right-to-left so 0 corresponds to Eff B. Thus, when indexing into instances, we should index from the back. Thus the first change is for clarity. The order of the indices in ns, however, is cons list order, i.e. left-to-right. Suppose that ns is [0,0,1]. Then this represents the adaptor <Eff(s a b -> s a b b)>. Therefore, we should not reverse instances' as it is already in the correct form of a cons list. Thus the second change is for correctness.