On Mon, Jan 18, 2016 at 11:01 AM, Joshua Ballanco <[email protected]> wrote: > On January 18, 2016 at 17:08:46, Anonymous ([email protected]) wrote: > > > This mimics the behavior of OOP since just like in OOP the internal method > cannot be changed (since the type is immutable). Sometimes it really does > make the most sense to attach a function to an instance of a type... > > I don’t believe you. > > Not trying to be snide, but after spending ~10 years as an “OOP programmer” > (mostly Java & Ruby) and ~3 as a “FP programmer” (mostly Clojure and now > Julia), I’ve come to realize that the difference between: > > foo.bar(baz) > > and: > > bar(foo, baz) > > is little more than a case of what you’re comfortable with. I could *almost* > see a case for the former over the latter if you were dynamically changing > the definition of `bar` (which has its own problems), but the example you > gave has the type being immutable. > > I’m curious what scenario you’re picturing where having a method attached to > an instance makes more sense than the other way around?
I think this has already been brought up elsewhere but IMHO the advantage of the first is namespace. You can define independent `bar`'s for different types without collision between them or with local variables.
