5 ms·
So, in the end the library will inject „identity“ symbol into the execution environment of n-fold by a compiler magic? How is that better than (get-identity tra
by artemonster 5y ago
So, in the end the library will inject „identity“ symbol into the execution environment of n-fold by a compiler magic? How is that better than (get-identity tran) ??
- deleted 5y ago[deleted]
- lmm 5y agoYou can't use the latter polymorphically (particularly since you don't always have an instance of your transformation to work with - for example, if you make a method that combines a list of transformations, it needs to return the identity when given an empty list). So you end up having to thread it down your call stack. Once you have a non-toy method that's using two or three type parameters it gets pretty cumbersome.
- artemonster 5y agoThen you have to use a method that will get an identity given a container (even if empty). Relying on types here, when we say thats a list of rotation transformers so their identity will he THAT, is exactly s compiler magic to me.
- lmm 5y agoYou resolve which method is called based on the type, yes. I don't see that as "magic" since it's fundamental language functionality that you rely on all the time - in Haskell typeclasses are the way you do polymorphism. If you want to implement polymorphism at all you will have to do something that's more or less equivalent (e.g. an OO virtual function table is effectively the same thing as a typeclass instance - it's just that the language forces you to bundle the data members and the virtual function table together, whereas in Haskell they're decoupled and can be used separately). Or even function overloading requires a similar "the compiler chooses which one is actually called" concept. (Of course there are purist languages that insist on e.g. using different forms of + for different-sized integers, but they're very much a minority)