2011-05-28 9 views
5

Capisco da questo blog post come un singolo shift all'interno di un reset viene reificato.Come viene resettato un reset con due turni in Scala?

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

è reificata a

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

Ora ho un altro esempio:

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

Si reificata a:

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

Come posso reificarla ulteriormente per ottenere liberare il 2 ° shift?

risposta

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

Fondamentalmente la stessa trasformazione.

(scala non installata qui, quindi ho testato questa trasformazione solo in Scheme, che dovrebbe comportarsi allo stesso modo, ignorando qualsiasi problema di sistema.)