4 ms·
Even newbie computer users understand mutation, because they have moved files (or other objects, like mail box items) from one place to another, deleted or rena
by kazinator 12y ago
Even newbie computer users understand mutation, because they have moved files (or other objects, like mail box items) from one place to another, deleted or renamed them or edited their contents.
Mutation is also something exhibited by everyday objects. This is modeled much better by object-oriented programming with mutable state. More importantly, the rigid typing of Haskell isn't found in the real world in which backpacks can hold dissimilar items, and donkeys can mate with horses to produce sterile offspring.
Haskell is close to mathematics, sure. Many people know mathematics. However, many people do not know that mathematics which Haskell is close to! So your (2) is a slight equivocation on the term "mathematics".
- coolsunglasses 12y agoMost people using Haskell are using it to write imperative programs, giving up mutation specifically is less of a big deal than you'd think.
- joe_the_user 12y agoI'm pretty sure I can implement any imaginable algorithm without mutation. Implementing it with any efficiency seems like a different question. A common activity in many programs is scanning a list and changing a few items based on some criteria. So far I've heard in Haskel you either duplicate the list or create a complicated data-structure that somehow essentially makes this mutation OK. Either ways seems silly - especially do what you did before but with complex dance around it.
- coolsunglasses 12y ago>Implementing it with any efficiency seems like a different question. Nah, same asymptotic limitations, just different constants and patterns in what's sensible. Example: https://www.youtube.com/watch?v=6nh6LpcXGsI https://www.youtube.com/watch?v=6nh6LpcXGsI Data.Map, Data.Sequence, Data.Vector all serve for most anything you'd want.
- gizmo686 12y agoHaskell relies heavily on the compiler being intelligent. In most cases, it will use stream fusion to avoid duplicating the list.
- tome 12y ago> Either ways seems silly - especially do what you did before but with complex dance around it. Interesting you think that. I think the opposite. It seems silly to overwrite something that someone else may have been relying on to not change when I can do a persistent update with pretty much the same performance.
- seanmcdirmid 12y agoConcurrency requires the someone else to see the change. Persistent collections work by throwing out concurrency.
- joe_the_user 12y agoWell, That makes immutability a nice technique if you happen to be dealing with a situation of synchronous access and otherwise an unneeded approach. The topic was haskell as first-language. Despite the hype, most people aren't going to be writing fully synchronous applications most of the time and thus immutability all the time seems mostly like unneeded bondage and discipline programming.
- BillMryes 12y agoEven in non-Haskell, a lazy list is a obvious possibility for that. It's not for no reason that many languages have implemented map, reduce, filter; laziness can still be pretty efficient while increasing composability and readability. Even Java has finally been dragged into the 1960s!
- peterfirefly 12y agohttp://en.wikipedia.org/wiki/Persistent_data_structure http://en.wikipedia.org/wiki/Persistent_data_structure
- kazinator 12y ago> I'm pretty sure I can implement any imaginable algorithm without mutation. We know this from the equivalence of Universal Turing Machines (which mutate a tape) and partial recursive functions (application of operations to immutable values). Any mutation is a functional mapping from the total previous state to the total new state. Of course, you generally don't want your ethernet driver to clone the entire OS just because it has another packet to add to a queue. Mutation can be tremendously resource-saving, when you don't need the previous state. The problems occur when parts of the software develop nostalgia for the way things were before the mutation. :)
- tel 12y agoMutation is just how you cut up time. If I pick up a coin and place is 6 inches to the left I've mentally cut the world into three epochs, the prior, the mutation, and the posterior. Thus I feel I mutated it. If I drop a ball, I can do the same trick and cut the world into the before and after of my releasing the ball, but for the duration of it falling I think of physics just happening. This is smooth, continuous, and not a set of discrete mutations. The math backs this up as well in the sense that integration is exactly what lets us convert the world of mutation into the world of constant physics (FRP from the "continuous time denotational semantics" perspective of Conal Elliott not the usual way the term is abused). So to claim that "everyday objects" are beholden to mutation or immutability I think is a game of confusing the map with the terrain.
- seanmcdirmid 12y agoMutation is a function over time, for sure. Most people understand the change and not the continuous function behind the change, and many processes are too chaotic to be described by nice clean continuous functions (a physical simulation with instantaneous collisions...). I believe even FRP uses steppers for those kinds of things. Most people think in terms of mutation, not in terms of the abstract functions that cause values to change over time.
- tel 12y agoI think this is just a vocabulary difference, not a genuine mental one. When I see a ball falling I don't think of it moving forward and accelerating in an infinite number of infinitesimal mutations---I see it as being in the state of falling and recognize the space of actions I could perform in time with it. There's mutation in the sense that I cannot arbitrarily go back in time. There's immutability in the sense that the rules governing that motion are not "staged" in any way outside of the interference of my hand. A better example is perhaps catching a fly ball as an outfielder in baseball. I absolutely cannot be processing that motion as a set of mutations in order to function---instead, I predict according to a "mathematical pattern" if not a formula, where it will land based on scant observation of segments of its space-time trajectory. And that's all more or less instinctual, I believe. It must be in order for me as an outfielder to execute my task. That stuff needs to just be built in to my brain. So while ultimately FRP and physics might be "implemented" (ha, ha, philosophers forgive me) in discrete steps, there's a vital model of each which is continuous.