You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
finalclassMyFun[A,B](f: A=>B):defapply(x: A):B= f(x)
defapplyAll(l: List[MyFun[Int,Int]], init: Int):Int= {
l match {
caseNil() => init
caseCons(h, t) => applyAll(t, h(init))
}
}
valt1=MyFun[Int,Int]((x:Int) => x +1)
valt2=newMyFun[Int,Int]((x: Int) => x -1)
vall:List[MyFun[Int,Int]] =List(t2, t1, t2)
@main @extern
deff=valres:Int= applyAll(l, 100)
If instead we use traits, we end up using type encoding, which can make things much less efficient in large programs.
traitMyFun[A,B]:defapply(x: A):BdefapplyAll(l: List[MyFun[Int,Int]], init: Int):Int= {
l match {
caseNil() => init
caseCons(h, t) => applyAll(t, h(init))
}
}
valt1=newMyFun[Int,Int]:defapply(x: Int) = x +1valt2=newMyFun[Int,Int]:defapply(x: Int) = x -1vall:List[MyFun[Int,Int]] =List(t2, t1, t2)
@main @extern
deff=valres:Int= applyAll(l, 100)
I would like that, if we write @opaque trait MyFun then it can only be extended by final and anonymous classes, and we treat it more like the first case class, avoiding the type encoding. Using function types will not work in the presence of mutation, but we should be able to do it by generating extern methods. As with opaque methods, we are purposely giving up on the precision of the underapproximation and the ability to execute the resulting encoding.
The text was updated successfully, but these errors were encountered:
The following program uses no type encoding:
If instead we use traits, we end up using type encoding, which can make things much less efficient in large programs.
I would like that, if we write
@opaque trait MyFun
then it can only be extended by final and anonymous classes, and we treat it more like the first case class, avoiding the type encoding. Using function types will not work in the presence of mutation, but we should be able to do it by generating extern methods. As with opaque methods, we are purposely giving up on the precision of the underapproximation and the ability to execute the resulting encoding.The text was updated successfully, but these errors were encountered: