Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is a reset with two shifts reified in Scala?

I understand from this blog post how a single shift within a reset is reified.

reset { 1 + shift {k:Int => Int => k(5)} + 1}

is reified to

val reified = {shiftValue:Int => 1 + shiftValue + 1}; reified (5)

Now I have another example:

reset { 
  1 + shift(k1:Int => Int => k1(5)} + 1;
  2 + shift(k2:Int => Int => k2(6)} + 2
}

It is reified to:

val reified ={shifyValue1:Int =>
    1 + shiftValue + 1; 
    2 + shift(k2:Int => Int => k2(6)} + 2
}
reified(5)

How can I reify it further to get rid of the 2nd shift?

like image 224
Michael Avatar asked Oct 10 '22 21:10

Michael


1 Answers

val reified ={shiftValue1:Int =>
    1 + shiftValue + 1; 
    val reified2 = {shiftValue2: Int => 2 + shiftValue + 2};
    reified2(6)
}
reified(5)

Basically the same transformation.

(scala not installed here, so I only tested this transformation in Scheme, which should behave the same, ignoring any type system issues.)

like image 120
hzap Avatar answered Oct 14 '22 01:10

hzap