HNHacker News
TopNewBestAskShowJobs

mrkgnao

1,913 karma · joined March 29, 2016

submissionscomments
mrkgnao··on Mice treated with a protein from umbilical cord plasma showed improved memory
"I Have No Mouth, and I Must Bleed"?
mrkgnao··on Mice treated with a protein from umbilical cord plasma showed improved memory
And a black metal band, if memory serves.
mrkgnao··on Ask HN: Can I get in trouble for crawling using the Googlebot user agent?
"When the time comes, add an adblocker to your browser. This will put an end to the whole affair."
mrkgnao··on How to Remember More of What You Learn with Spaced Repetition (2016)
From my own org-mode link dumps:

https://news.ycombinator.com/item?id=14013310

mrkgnao··on Tmux and Vim – better together
I don't really know zsh, but that looks like it should be

  zle flush-input
mrkgnao··on Serde 1.0.0 for Rust released
The reason is that class instances are really not first-class in Haskell. You can never import a module and choose not to import its instances, not even with

  import Module (just_one_symbol_i_need)
or to not import a couple of them. I think named instances a la PureScript let you do

  import Module (instance toJsonText, ...)
which would be great to have in Haskell, but probably breaks something deep inside instance resolution.

PureScript as a "Haskell without the mistakes" really is a great idea.

mrkgnao··on Inside Every Utopia Is a Dystopia
That picture did something to me.
mrkgnao··on What programming languages are used late at night?
I'm itching to write a bash script for this now.

Or, you know, a quasiquoter (which is sort of like a Haskell macro thing, although Template Haskell is closer to that).

mrkgnao··on What programming languages are used late at night?
If you use a good "IDE" setup, it'll tell you what extensions you should enable for some code to compile. Intero (on Emacs) allows you to hit C-c C-r to insert the relevant incantation at the top of the file.

About what extensions people consider kosher, Stephen Diehl's "What I Wish I Knew When Learning Haskell" has a great list that sorts them into "common", "uhh", and "you obviously know what you're doing".

mrkgnao··on Young White America Is Haunted by a Crisis of Despair
Linus' law? :)
mrkgnao··on What programming languages are used late at night?
Bonsoir, allow me to introduce Servant.

http://haskell-servant.readthedocs.io/en/stable/index.html

Servant allows you to write a type that describes a server/API, and automatically derives a specification for it. You can then write handlers for the different API endpoints, and it will only compile if every endpoint is correctly handled. That includes content types, status codes, and so on, everything is verified, and things are often derived for you. All (de)serialization to/from JSON is automatic (although you can write your own instances if you want your JSON to look a certain way).

For example, from the Servant docs:

    type API = "position"  :> Capture "x" Int :> Capture "y" Int :> Get  '[JSON] Position
          :<|> "hello"     :> QueryParam "name" String           :> Get  '[JSON] HelloMessage
          :<|> "marketing" :> ReqBody '[JSON] ClientInfo         :> Post '[JSON] Email
This is equivalent to an API that defines these three endpoints:

    GET  /position/:x/:y/      returns a Position object as JSON
    GET  /hello?name=whatever  returns a HelloMessage object as JSON
    POST /marketing            given a JSON request that represents a ClientInfo object,
                               returns an Email object as JSON
but the spec is code: code that the compiler can check for you!

You can then write functions of the following types

    handlePosition  :: Int -> Int   -> Handler Position
    handleHello     :: Maybe String -> Handler HelloMessage
    handleMarketing :: ClientInfo   -> Handler Email
where "Handler thing" effectively means that you can do something like write to a log or throw an exception while you return the thing. This will typecheck, and you have a server that must do what it says on the "tin", the tin being the API type above.

If you add a new API endpoint, and forget to write a Handler for it, you'll get to know. If you change the Position type to work with x, y, and z coordinates but forget to update your handlers, you'll get to know. If you'd like to also allow clients to request HTML instead for some endpoint, just change the '[JSON] to '[JSON,HTML]. The Haskell typesystem will make sure that someone requesting a text/html Content-Type doesn't get hit with a 500 or something.

Note the Maybe String there: if you wrote a handler for the /hello endpoint that had the type String -> Handler HelloMessage, Servant would complain: you're expecting a query parameter, which the client doesn't have to provide. This is in stark contrast to, say, the "NoneType has no attribute whatever" problems that one risks having to face with Django: if it compiles, it meets the spec.

Of course, static typing won't prevent you from responding to /hello with Lovecraft quotes.

--

> I start getting lost in layers of monad transformers

Handler is actually a monad transformer, and it's a great first one: it's essentially[0]

  type Handler a = ExceptT ServantErr (ReaderT Config IO) a
if memory serves, which means that a "Handler a" is a computation that can

  * throw a ServantErr
  * read values from a Config object
  * perform IO actions (read files, make other network requests, log things, "fire missiles")
when run, returning a value of type a. Anecdotally, monad transformers never clicked for me until I started muddling through actually using them in code like this.

After a couple of months, you realise it's not too wrong to say you understand how to use them, and you slowly begin to be able to rely on the type system for support. Libraries like Servant are a great example of how this can really, really help. I stopped to think last week how similar it is to pair-programming with a really intelligent but sometimes obtuse friend who likes pointing out how "this doesn't follow from your assumptions", all the way from

> "Wait, but you can't add two books together."

to

> "What if someone PUTs to /login?"

which is what we had above, to

> "And what happens if I try to withdraw all my money exactly when the payment I've made to you is getting executed?"

(in this case, you discover the wonders of software transactional memory[1]). A better typesystem allows you to let the compiler handle more of the busywork that you'd originally have written tests or comments for.

It is sometimes confusing starting out (when one discovers that 3 isn't an Int, but a "Num a => a", for instance), but it gets better. Once you get past the Project Euler/"look ma, infinite lists!" stuff, "real" Haskell does have a tendency to make people underestimate how much they really know, but as I've discovered, taking the plunge reveals that one has progressed much farther than one thinks.

Also, #haskell on Freenode is one of the friendliest places I've encountered on the internet[0].

[0]: http://haskell-servant.readthedocs.io/en/stable/tutorial/Ser...

[1]: https://www.schoolofhaskell.com/school/advanced-haskell/beau...

[2]: Here's a hilarious example (NSFW language warning): https://gist.github.com/quchen/5280339

--

Other stuff:

Corrode is a C-to-Rust converter written in literate Haskell (as in, it's like a blog post that you can compile and run, to give a slightly strained analogy).

https://github.com/jameysharp/corrode

webshit weekly actually "quoted" a previous HN comment of mine about it, in which I was falsely slandered: I'm not a Rust evangelist!

I wrote a small "script" to make tmux status bars a while back that was a good example of how fun "scripting"-style thing can be in Haskell.

https://github.com/mrkgnao/remux

And there's always XMonad!

mrkgnao··on What programming languages are used late at night?
And also happen to employ Simon Peyton Jones and Simon Marlow, respectively, two of the originators of the GHC project.
mrkgnao··on Odd Lots Podcast: Signs That a Civilization Is About to Collapse [audio]
> But the increased complexity also increases the fragility of the system, and also adds ongoing maintenance costs.

Somewhat tangentially related:

https://news.ycombinator.com/item?id=14027705

Abstraction is one possible mitigation to this problem.

mrkgnao··on Chrome 55-57 showed “download” button for all HTML5 media
> We disable right-click on our work

Ugh.

mrkgnao··on Optical illusions that flummox computers
More blatant "SEO walks into a headline" jokes, anyone?
mrkgnao··on Musical User Interfaces
Didn't someone (well-known on HN) write an essay with descriptions of UIs that would be controllable using Solresol-ish voice commands​, with more advanced users using three-or-four syllable commands up from the monosyllabic ones for lay users?

It was a very 90s website.

Edit: found it. http://www.erasmatazz.com/library/the-journal-of-computer/jc...

mrkgnao··on Prettier 1.0
While I understand the reasons for this (especially with the culture, for lack of a better word, around Go), I feel like this is a step backward in general. The "standard" Haskell formatter, hindent, did something similar. I found the maintainer's behavior admirable -- the style that was agreed on was very different from his own, but it was what he saw after analyzing publicly available code -- but what's the problem with custom formats if they're consistent across a whole codebase?
mrkgnao··on Intel Haskell Research Compiler
Also something called STG.
mrkgnao··on Intel Haskell Research Compiler
GHC is an entire library too. It has parsers, AST datatypes, desugarers, typecheckers for both Haskell and Core, multiple intermediate representation libraries, ... and the actual compiler is "just" an application that uses that library.

An excellent overview: http://www.aosabook.org/en/ghc.html

mrkgnao··on Programming in the Point-Free Style
So German trennbare Verben (split verbs)? :)

Whenever the literary German dives into a sentence, that is the last you are going to see of him till he emerges on the other side of his Atlantic with his verb in his mouth. - Mark Twain

mrkgnao··on Programming in the Point-Free Style
Conventions also help.

For instance, the lazy readTVar, modifyTVar, etc. functions have strict analogs called readTVar' and so on. mapM, foldM, replicateM, and traverse return a monadic value, while mapM_, foldM_, replicateM_, traverse_ and friends discard the return value (giving an m () instead of an m a).

mrkgnao··on Fourier transform – A math tool used in optics, MP3s, JPEGs and more (2013)
https://acko.net/files/gltalks/toolsforthought/#0
mrkgnao··on Typing the technical interview

  PeanoEqual(a,    b) =    # a and b are both nonzero
     PeanoEqual(a-1, b-1)  # so recurse
Subtracting Peano literals would involve some constraints in the type, so shouldn't that be (a+1,b+1) for typing purposes?
mrkgnao··on Typing the technical interview
Is this an HN novelty account in the making?
mrkgnao··on Typing the technical interview
This is closer to using the type system to simulate something Prolog-like, where typeclass membership is like a predicate.
mrkgnao··on Typing the technical interview
I doubt Aphyr/Kyle is one of those people who would know how to simultaneously rotate five binary trees using only one pointer off the top of his head (or whatever). The point of this series isn't that it's an attack on people who aren't comfortable with Haskell type magic (or the extremes of Lisp or JVM classloader-fu): whatever made you think that?

Now if you mean that making fun of the coding interview itself is wrong because there exist people who either interview people for a living or people who are job-hunting right now, and this makes light of their troubles, well, that's different. I disagree, but it's still more sensible than "lol you dont know Haskal, nub".

mrkgnao··on Typing the technical interview
> Summon a linked list from the void. It floats to the surface of the screen: a timeless structure, expressed a thousand ways, but always beautiful.

Coincidentally, I had Bach's E minor organ sonata on in the background, so...

> You sigh contentedly.

I did, I started smiling from ear as soon as I read the now-classic "Summon a ______ from the void". :)

Also, TIL: https://en.wikipedia.org/wiki/Sei%C3%B0r

mrkgnao··on Why Kids Shouldn’t Sit Still in Class
> such a pill

That sounds quaint (ergo, British!) and I'd love to know where it's from.

mrkgnao··on Wire messenger server code open-sourced
Isn't there some music-learning app too? Chordify, I think it was called.
mrkgnao··on Jeff Bezos Is Selling $1B a Year in Amazon Stock to Finance Race to Space
See my replies downthread. It's not Hindi that I dislike, it's the choice of the name. I'm definitely on board about Hindi being a good idea for Indian spacecraft.

Calling the Mars mission "Mars Vehicle" in any language is stupid.

← PreviousPage 9 of 19Next →