I haven't used it myself but it's pretty cool that it's out there.
2,032 karma · joined April 1, 2013
http://github.com/adnelson
I haven't used it myself but it's pretty cool that it's out there.
Nevertheless, if that was the only benefit of it, one might argue it’d be more of a party trick. But it’s simply one more facet of a very powerful, simple-to-use technique for expressing how your code reacts to the shape of your data.
I’m curious how much exposure you’ve had to languages which support it — you might find it more useful than you think.
switch (mylist) {
| [“”, _, “”] => x
| _ => y
}
Moreover, pattern matching usually involves pulling information out of the object at the same time. In the above example, maybe you want to do something with the middle element: switch (mylist) {
| [“”, middle, “”] => middle ++ “!”
| [“foo”, x] => String.reverse(x)
| _ => “never mind”
}
All of this would be possible to do with a series of if conditions, but significantly harder to read and implement correctly.The power of pattern matching grows clearer as more complex data and rules are introduced. For example, it works just as well with nested lists:
switch (mylist) {
| [outer, [middle, [inner]]] => outer ++ middle ++ inner ++ “!”
| _ => “never mind”
}
While having a type system is helpful in all of the ways a type system is generally helpful, there’s nothing about this code which wouldn’t also be handy in a dynamic language like JavaScript. For further evidence of this see Erlang and Elixir, dynamic languages which make heavy use of pattern matching.(Code typed on my iPhone so forgive the dopey examples)
I can’t count how many times I’ve seen error messages that look like this, often with no context at all, in JavaScript apps, even widely used ones like npm and webpack. Proper error handling is never easy, but the JS community seems particularly given to avoiding it.
The second issue is that regardless of the accuracy of the claim, downplaying the value of slavery is a way to devalue the debt owed to black Americans and has been used as such in arguments. The less valuable slavery was, the less white Americans should feel owed to pay back. So I think there’s a significant moral cost to this argument, and yes I think it’s disrespectful. But again, it’s factually controversial as well.
I had also made a variety of significant points which GP failed to respond to, instead focusing only on a hyper-literal interpretation of one subset of my argument. ¯\_(ツ)_/¯
The fact that England, another state with a horrific history of exploitation and colonialism, was also guilty of slavery, is hardly exculpatory for the US. Whether slavery was economically beneficial in every single historical example is a separate question from whether it was beneficial to the United States.
However, if your intention is to dispute the claim that slavery was immensely beneficial to the development of the American economy, or to suggest that the morality of American slavery was somehow mitigated by other historical examples of slavery, I strongly disagree. I think in general this mentality is incredibly disrespectful. Acknowledging the role played in our success by the (unwilling) sacrifice made by millions of slaves and Native Americans is the very least that we can do.
To be clear, I don't think studying this is a waste of time. On the off chance that we get there, that'll be great (setting aside the concerns of this article of course). It just gives me a sense of a terminally ill person planning their retirement. Sorry to be the downer here.
I never made the claim that any country can become rich simply by having slavery. The question of why the West is so much richer than e.g. Africa or Brazil is obviously vastly complex and does not boil down to "because of slavery." But whether or not the American South was richer than the North at the time of the civil war, it certainly very very wealthy, and slavery was instrumental in this.[0] I don't think this is really controversial.
> Native Americans had slaves:
The existence of slavery in these or other societies does not in any way absolve the US from its past in this regard. Pointing an accusatory finger at some Native Americans who enslaved prisoners of war and the like, in contrast to a vast and extremely profitable business empire built on systematic enslavement, which has had ripple effects of racism on individuals and communities since, seems incredibly tone-deaf. Even more so when you consider that we killed the Native Americans by the literal millions.
[0]: https://www.history.com/news/slavery-profitable-southern-eco...
This is a pretty half-baked comparison. Math is great for describing things which can be defined precisely and their interactions. Numbers, physical systems, economics, etc.
Human language can be (and is) used for these purposes as well, but more broadly is useful for an entirely different purpose: expressing emotions, sussing out the meaning of things, developing relationships, providing a voice for the human condition. Mathematics is ill-suited at best for these purposes. Both language paradigms may be able to quantify how fast one has to run to get away from a lion. Only one of them can express why you’d want to, or the terror you’d feel trying to do so.
The wording here confuses me. They say they took the implementation from hashbrown, but then finish by saying that the implementation is different. What am I missing?
Of course, there are times when you need to compile yourself, but most slow-to-compile packages, such as Aeson, Lens, Servant or the aforementioned Parsec, and many more on top of that have prebuilt binaries available when built from community snapshots (nixpkgs/nixos). You can even pin your package definitions to guarantee that you’re building something that will have prebuilt versions available. New project build is usually less than a minute or two, sometimes substantially so (anecdotally). Again, not always, but usually.
I find it hard to co-sign on your assertion that all non-trivial programs require mutation. This hasn’t been my experience at all. While having access to side-effects is certainly essential (which Haskell is fully capable of doing), mutation is quite rarely needed in my experience. In the cases that it is, IORefs are trivial to use. On top of that Haskell has MVars, which I hazard to claim are the best concurrent mutation primitive I’ve ever had the pleasure of using. Quite the opposite of being crippled.
The size of China is not the source of their politics; the source is a totalitarian state that ruthlessly suppresses any dissent and maintains constant surveillance of its people. Not to imply that you meant otherwise, but the citizens of mainland China are no less deserving of political rights than those of Hong Kong; rather, they have simply been denied them by those in power. The 30th anniversary of the Tiananmen Square massacre was only last week —- it could have ended similarly in Hong Kong. Also, unsurprisingly, Chinese media has been almost completely silent about these protests and many on the mainland are completely unaware that anything is happening at all.
https://www.opensecrets.org/industries/lobbying.php?cycle=20...
counter :: IORef Int
counter = unsafePerformIO (newIORef 0)
usesGlobalState :: IO ()
usesGlobalState = do
count <- readIORef counter
putStrLn (“the counter was “ ++ show count)
modifyIORef (+1) counter
It’s even easier in ocaml, where you’d use ref and not need to worry about the IO monad.Anecdotally, I find it incredibly rare that such a thing is desirable, when you could instead create it in an IO monad and pass it through to functions that need it. But, it’s there when necessary. And making this kind of anti pattern hard is a strength of these languages, not a weakness.