3 ms·
I'm curious about scoping. How come `main` in the typeclass.bon example gets to call `norm()` unqualified? Do all the functions in all `impl` definitions just
by zestyping 8y ago
I'm curious about scoping. How come `main` in the typeclass.bon example gets to call `norm()` unqualified? Do all the functions in all `impl` definitions just get tossed in one global namespace? If `Norm` is a class, then why are there no `Norm` objects?
- perfunctory 8y agoThis seems to be straight from Haskell. `class` here doesn't mean what it means in oop languages.
- FBMachine 8y agoYeah, 'class' in Bon defines a typeclass. While I plan on adding x.norm() as syntactic sugar for norm(x), typeclasses in general are a bit more flexible. For example, while you can use it for polymorphic operator overloading [0], you can also overload a function by changing the types of multiple parameters [1] (as in multiple dispatch). [0] https://github.com/FBMachine/bon/blob/master/examples/equality.bon https://github.com/FBMachine/bon/blob/master/examples/equali... [1] https://github.com/FBMachine/bon/blob/master/examples/multiple_dispatch.bon https://github.com/FBMachine/bon/blob/master/examples/multip...
- bausshf 8y agoYou should look into UFCS from dlang, maybe that can give you some inspiration. https://dlang.org/spec/function.html#pseudo-member https://dlang.org/spec/function.html#pseudo-member