Iaroslav Postovalov
12/08/2020, 8:41 AMaltavir
12/09/2020, 12:31 PMbreandan
12/09/2020, 3:02 PM(A)->B is syntactic sugar for invoke(a: A): B , and the syntax does not fully compose. As it needs to interface with Java's type system, there are some limitations. I have some intuition but need more experience to recommend using this pattern. I tried to understand some of the tradeoffs in this SO question: https://stackoverflow.com/questions/54799122/type-inference-for-higher-order-functions-with-generic-return-typesaltavir
12/09/2020, 3:11 PMbreandan
12/09/2020, 5:48 PMaltavir
12/09/2020, 5:52 PMplus or exp. It is done via named function handlers. The question in only either handler should take argument and return the result immediatly (one step) or it should return unary/binary function which wen could be called. The function will be in most cases called immediatly. @Iaroslav Postovalov if you have and exmple of the delayed execution, plesase intervene.breandan
12/09/2020, 6:25 PMoverride fun binaryOperation(operation: String, left: MST, right: MST): MST.Binary =
MstAlgebra.binaryOperation(operation, left, right)
This data structure instead becomes a binary lambda function:
public override fun binaryOperation(operation: String): (left: MST, right: MST) -> MST.Binary =
MstAlgebra.binaryOperation(operation)
I agree with Iaroslav this is the mathematically more elegant definition, but I have been struggling to justify exactly what benefit this provides from an implementation perspective, if it is true that (left: MST, right: MST) -> MST.Binary is just syntactic sugar for invoke(left: MST, right: MST) -> MST.Binary.
I am curious to learn if there is some obvious advantage, because there is something about using monads that feels more "beautiful" than simply constructing a tree, although I am somewhat suspicious of this feeling because it leads to Haskell land where (+) :: Num a => a -> a -> aaltavir
12/09/2020, 6:29 PMoverride fun binaryOperation(operation: String, left: Double, right: Double): Double
and
overide fun binaryOperation(operation: String): (Double, Double) -> Double
respectively.
The only difference I see is that during implementation you can do something like this:
return when(operation){
"+" -> ::plus
}
This will be done only once, so I do not see any significant advantages.breandan
12/09/2020, 6:38 PMreturn when(operation){
"+" -> ::plus
}
that much easier to read than:
return when(operation){
"+" -> left(bindings) + right(bindings)
}
I don't know. Maybe there is another benefit?
Just a small nitpick, but I would personally use an enum instead of a string for operationaltavir
12/09/2020, 6:39 PMIaroslav Postovalov
12/10/2020, 11:46 AMIaroslav Postovalov
12/10/2020, 11:46 AMIaroslav Postovalov
12/10/2020, 11:47 AM