Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
The Expression Problem in Go (thegreenplace.net)
6 points by signa11 on Feb 22, 2018 | hide | past | favorite | 2 comments


Why don't you define Expr to be:

type Expr interface { Eval() float64 }

Instead of that being an empty interface and ditch the "Eval" interface? Or just require the structs to take instances of "Eval"? That way BinaryPlus won't accept the string without being wrapped in a type with an Eval method?


Interestingly, Julia handles the type safety aspect with ease despite being dynamic, since it has both multimethods and parametric polymorphism.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: