Does Go support operator type variables? -
this might not such question, since don't know of compiled language supports feature, since go surprising me, i'll ask anyway:
for own practice, writing little calculator program in go. i'm wondering if there way can declare , assign variable of type "operator", such could, example, write:
var o operator o = + var o1 operator o1 = / and write function this
func dooperation(a,b int,o operator) int{ return o b } (no, not asking operator overloading.)
offhand, don't know of compiled language supports such thing (i'm not expert in this). did @ docs under operators , found nothing. can go surprise me again?
edit: accepted answer states haskell supports this,
no, go operators not functions , hence no valid right-hand expressions. work in generic way e.g. plus-operator works on numeric types , infix-notation la haskell not supported either.
you have write own "soft"-generic addition function using reflection.
one compiled language covers of requirements haskell.
Comments
Post a Comment