684 karma · joined Jun 20, 2017 (9y ago) · 230 submissions
comment 8y ago · link · parent
The code you sketch out above is basically the Writer Monad, which exists in the libraries, and does see use, but it's not IO -- as I mentioned above the semantics of IO don't entirely just fall out of the monadic structure.
But I find the computed-imperative-program description lends itself to thinking about IO values as values in a way that thinking about them as type system goop to tame side effects doesn't; for example, the program:
import Data.List (intersperse)
import Control.Concurrent (threadDelay)
main = sequence_ $ intersperse (threadDelay 1000000) (map print [1..])
will print out the natural numbers, one per second until you kill it. It works by constructing a (lazily evaluated) list of actions to perform, which alternately print out a number or wait for one second. sequence_ has type [IO a] -> IO (), and it just performs each action in the list in sequence (its type is actually a bit more general than this, but..).This kind of code is really weird to think about from the "tamed side-effects" model, but very natural from the "computing a script" model.
comment 8y ago · link · parent
getLine :: RealWorld -> (String, RealWorld)
putLine :: RealWorld -> String -> RealWorld
And some code like:
Let (line, w1) = getLine w0
w2 = putLine w1 line
w3 = putLine w2 "other stuff"
w4 = putLine w3 line
...
Now, imagine an optimization compiler for some reason decides it would be better to recompute `line`, rather than hang on to the value in the interim. It would be well within its rights to do so, because referential transparency guarantees that this is safe.IIRC ghc essentially "plays dumb" and just never duplicates a computation (which is not typically a desirable optimization at this level, though register allocators will sometimes do it). But it's arguably a hack.
A better metaphor is to think of values of type IO a as fragments of a script in some other (imperative) language. The Haskell program merely computes the script, and the runtime then takes care of actually executing it. In this sense, effects in Haskell are not "side" -- they are first class citizens. What order the fragments of the imperative program are computed in (or how many times) is independent of the text of the final program.
In very early versions of Haskell, main had a type roughly like [Response] -> [Request]; you computed a list of things for the runtime to do, as a function of the results of its (hopefully) previous commands. This kinda works, but it's easy to deadlock by creating a circular data dependency. What the Monad structure does for you is avoid that problem, by making it impossible to depend on a future value.
It's also worth pointing out that all of this is specific to IO; understanding monads in general are neither necessary nor sufficient to understand Haskell's IO.
comment 8y ago · link · parent
It was kindof upsetting to read this after having switched the article into Firefox's reader mode, because the page was completely unusable.
If you want to talk about consumers' wallets not existing in a vacuum: if your 3.5 KB article is sending me 10 megs of crap, then your mobile users' carriers are charging them more than the advertizers are paying you.
There are some real challenges in figuring out how to fund journalism, but if bandwidth is one of them you're doing something very wrong.
comment 8y ago · link · parent
comment 8y ago · link · parent
comment 8y ago · link · parent
comment 8y ago · link · parent
comment 8y ago · link · parent
RHEL/CentOS 6 is still reasonably widely used, and the system Python there is 2.6.
comment 8y ago · link · parent
For folks like me, who spent their evenings in high-school screwing around with obscure linux distros and have been scouring badly written man pages trying to fix their computer for half their life, the little stuff is forgivable, and a lot of the big stuff is pretty good. But it's a shame how many inessential hurdles there are. See also:
https://git-man-page-generator.lokaltog.net/
Biggest piece of advice for not losing data: learn about git-reflog and git-reset before doing anything that modifies history. Nothing is destroyed, even by "scary" operations like rebase, so it's always possible to recover something, but you need to know how to find stuff.
I do some contract work for a university, where we have lots of student interns going through. We use GitHub, and we rarely rebase or cherry-pick, basically because while I could spend a bunch of time trying to teach git to new interns that will be gone in 4 months, It seems like a more efficient use of time to just occasionally put up with a messy history.
comment 8y ago · link · parent
TFA does all of the above, plus a parenthetical saying "inference is addressed in the next section" -- and then does not actually address inference later in the post.
I'd much rather have type inference than optional typing.
comment 8y ago · link · parent
This proposal is about fixing some of the edge cases where the current implementation doesn't do what the interface is supposed to. It outlines another, simpler approach which just has the compiler add more yields, but apparently the performance impact of that is too high. But it's just a question of perf & implementation complexity, not semantics.
comment 8y ago · link · parent
comment 8y ago · link · parent
I think part of the trouble is that we spend too much time at work for most people to actually be productive the whole time -- if you buy the notion that it's reasonable for people to be at work to work, and they shouldn't be socializing whathaveyou, then logging everything seems more reasonable than if you recognize that no one can actually be a drone 40/hr a week, then the surveillance starts to look like de facto surveillance of stuff other than the job, which is more worrying.
I am in the privileged position of doing freelance work, on my own machine, mostly remote. As such, if I'm using a client's communication systems it is essentially guaranteed to be work related, so having it logged doesn't bother me; if I'm not working I'm using something else. But being monitored for half your waking hours five days a week feels much more onerous.
I suspect some of a this is tension with reasonable expectations of levels of monitoring from when less of our communication was via the network.
comment 8y ago · link · parent
The big thing with Vim's modal editing is that it allows you to have keyboard shortcuts involving keys that aren't way off in the boonies. Some examples:
* / or ? to search for text
* dd to delete the current line
* Stuff like ciw or ci" will delete a word or the contents of a double-quoted string, and drop you into insert mode. I use this one constantly.
When prompted, people try to come up with really crazy complex things, but frankly the bigger thing is just being able to actually reach things.
If I tried to use shortcuts in other editors to the extent that I do in vim, my hands would constantly be in pain. This is why I never got into emacs, though I've seen some folks be terrifyingly fast with it as well.
comment 8y ago · link · parent
Haskell will recognize a .lhs extension and do comments by default, using > to prefix lines that are actual code (looks block-quote like).
Frankly I am something of a skeptic of literate programming. In most of the literate source code I've read, the code is clearer than the prose anyway, and having every detail in comments just makes the whys and the high level design harder to find.
My approach is to basically assume the reader is familiar with the language and the key libraries, document the whys, overall design, and the api contracts, and try to pick good variables and write clear code. This is not to say "inline comments are bad," but I find that usually when I find myself writing a lot of comments explaining the details it's because I'm writing a lot of confusing code.
comment 8y ago · link · parent
with_file "hello.txt" (fun fd -> (* do stuff *) )
where you've basically created a c++ destructor style api with a lambda.It's certainly not "verification" in any formal sense, and the type system can't help you there any more than it can in c++.
But this is a perfectly reasonable pattern.
comment 8y ago · link · parent
And of course "perform" is a very muilti-dimentional thing, not a single value.
The truth of the matter is that any generic memory management strategy is going to fall on it's face in certain scenarios; most folks have seen first hand the raii failure mode where some application takes forever just to exit, because it's pointlessly calling god-knows how many destructors.
It's late, and I should generally try to be more clear with myself about what my point is before I post. The thing in there that I think is more salient is, with manual memory management you're opting into control, not magic everything-is-faster-now. I don't think the op was suggesting it, but people often act like using a lower level language is going to always make things faster, ans it just isn't true. Idiomatic, decently performing OCaml is going to make for some very slow Rust.