HNHacker News
TopNewBestAskShowJobs

danidiaz

628 karma · joined December 22, 2012

productivedetour.blogspot.com
submissionscomments
danidiaz··on A primer on the cruel, tacit laws of type-level programming in Haskell
Kinds in Haskell seem to be evolving in the direction of controlling the representation of datatypes in memory. * (also called Type) is the kind of types whose values are "lifted": they can be lazy computations which might cause an infinite loop, throw an exception, and so on.

There are also kinds for types whose values are "unlifted", meaning they really correspond to actual values in memory, not lazy thunks.

Right now the language for expressing unlifted datatypes is quite limited. Hopefully it will be expanded so that we can write "strict Haskell" more easily.

"Levity polymorphism" paper https://www.microsoft.com/en-us/research/wp-content/uploads/...

"Kinds are calling conventions" paper https://www.microsoft.com/en-us/research/uploads/prod/2019/0...

The -XUnliftedNewtypes extension https://downloads.haskell.org/ghc/latest/docs/html/users_gui...

https://stackoverflow.com/questions/35318562/what-is-levity-...

https://stackoverflow.com/questions/56311510/what-does-type-...

danidiaz··on The Case for Stanislaw Lem
I absolutely love 'Eden', even if Lem himself thought it wasn't among his best work. It's an alien dystopia seen through human eyes.

Are the scenarios the explorers encounter something "normal" in some sense, or something gone terribly, terribly wrong? And how can the humans judge, coming from outside?

The final revelation dispels some of that ambiguity, and what it shows is not pretty. For me, it's among the most unnerving passages in science fiction. Also, it taught me the word "procrustean"...

danidiaz··on Ask HN: How to be fluent in functional language speak?
In Java terms, a "type constructor" would be a generic class like, say, `ArrayList<T>`.

A constructor can be viewed as a function that takes values for the fields of a datatype and gives a value of the datatype in return. Not all functions are constructors, but some are.

At the type level, if we squint a little, "Maybe" or "List" behave a bit like constructors. They take types like "Int" or "Bool" as parameters, and give types like "Maybe Int" and "List Bool" in return. Not all type-level "functions" are type constructors (for example, in Haskell type families are not type constructors) but some are.

danidiaz··on Do notation considered harmful
I think the position that do-notation is harmful is nowadays in the minority. Personally, I prefer it to long chains of monadic operators.

It proved so convenient that there are extensions like "ApplicativeDo" that let you use do-notation in contexts other than monadic: https://downloads.haskell.org/~ghc/latest/docs/html/users_gu...

> Imperative programming is the most natural thing for people. "Do this, then that, then that, in that order."

I'm not sure. For example, do users of Excel really care in which order the cells are calculated, beyond the order imposed by the data dependencies they have defined?

danidiaz··on Conversations with a six-year-old on functional programming (2018)
There's a notable book by philosopher Derek Parfit called "Reasons and Persons" that—among other things—uses "transporter" thought experiments to explore the nature of personal identity.

The quasi-buddhistic conclusion, with which I agree, is that personal identity is largely an illusion. It's an easy illusion to maintain however, given that in practice our "software" is very difficult to "copy" exactly.

https://en.wikipedia.org/wiki/Reasons_and_Persons#Personal_i...

danidiaz··on Yet another novel I will no longer write
Also used by Stanislaw Lem in "A Perfect Vacuum" https://en.wikipedia.org/wiki/A_Perfect_Vacuum The last review in that book anticipates much of the premise of Cixin Liu's "Remembrance of Earth's Past".
danidiaz··on Münchhausen Trilemma
Pyrrhonism. n. An ancient philosophy, named for its inventor. It consisted of an absolute disbelief in everything but Pyrrhonism. Its modern professors have added that.—Ambrose Bierce, The Devil's Dictionary
danidiaz··on Ask HN: Book recommendations for understanding financial systems?
I'm not knowledgeable enough to properly recommend a book on the subject so take this with a grain of salt, but I thought the historical (and opinionated) overview of the evolution of English money in Christine Desan's "Making Money: Coin, Currency, and the Coming of Capitalism" was interesting https://www.goodreads.com/book/show/21492062-making-money

I like this quote about how financial institutions evolved:

"It happened improvisationally, indeed probably unintentionally. Participants solved one problem and created others; they reacted as often as they acted affirmatively; they moved by experience and intuition, without an overarching theory; and the whole affair took decades, involved many different actors, and coheres largely in retrospect."

danidiaz··on Show HN: Helium – Lighter web automation based on Selenium
> WaitForFile(filename, absoluteTimeout)

The Java bindings have support for this in the form of FluentWait#until http://javadox.com/org.seleniumhq.selenium/selenium-support/...

Using explicit waits for expected conditions (instead of static waits or implicit waits) helps with making the tests more robust. It's a bit more work though.

danidiaz··on Move, simply
I also get moves confused with the return-value optimization, though my understanding is that RVO appeared earlier.
danidiaz··on What ruins can teach us about beauty and decay
An earlier book about the subject is "In Ruins" by Christopher Woodward.

I also liked this "Ruins and Futurity" article http://www.sf-encyclopedia.com/entry/ruins_and_futurity about the use of ruins in science fiction.

danidiaz··on Board Games of the Ancient World
The cathedrals of Ourense and León in Spain have a few game boards etched in stone at discreet places. Some of them look like Nine Men Morris (Alquerque?) boards: http://jesus-manuel.com/2015/08/08/658/ (in Spanish) https://en.wikipedia.org/wiki/Alquerque
danidiaz··on Dynamic type systems are not inherently more open
It seems that "ghcide" can do this: https://twitter.com/chris__martin/status/1218331415869190144 https://github.com/digital-asset/ghcide
danidiaz··on A Son’s Race to Give His Dying Father Artificial Immortality (2017)

    "And yet, if only from my dreams when I was asleep, I might have
    learned that my grief for my grandmother's death was diminishing, for
    she appeared in them less crushed by the idea that I had formed of her
    non-existence. I saw her an invalid still, but on the road to
    recovery, I found her in better health. And if she made any allusion
    to what she had suffered, I stopped her mouth with my kisses and
    assured her that she was now permanently cured. I should have liked to
    call the sceptics to witness that death is indeed a malady from which
    one recovers. Only, I no longer found in my grandmother the rich
    spontaneity of old times. Her words were no more than a feeble, docile
    response, almost a mere echo of mine; she was nothing more than the
    reflexion of my own thoughts."
    —Marcel Proust, Cities of the Plain
danidiaz··on A Map That Made Los Angeles Make Sense
Kevin Lynch notes as much in "The Image of the City", his book about urban form:

> Paths proved to be the dominant element [of orientation] in terms of quantity [...] The single exception was the shift in attention from paths and edges to landmarks, which was noted in Los Angeles. This was an striking change for an automobile-oriented city, but it may perhaps have been due to the lack of differentiation in the gridiron streets.

danidiaz··on Show HN: I built a poker site with Haskell
In your first version, I think I would use =<< to keep "flow" of information right-to-left. I also use parentheses instead of . and $ when there isn't a lot of nesting, I got that habit from this post about writing legible Haskell http://www.haskellforall.com/2015/09/how-to-make-your-haskel...

    getSocketAPIPort :: Int -> IO Int
    getSocketAPIPort defaultPort = do
        maybeEnvPort <- lookupEnv "socketPort"
        return (fromMaybe defaultPort (readMaybe =<< maybeEnvPort))
Keeping the pattern match instead of using "fromMaybe" wouldn't be a bad idea, either:

    getSocketAPIPort :: Int -> IO Int
    getSocketAPIPort defaultPort = do
        maybeEnvPort <- lookupEnv "socketPort"
        return (case readMaybe =<< maybeEnvPort of
            Nothing   -> defaultPort
            Just port -> port)
It makes the default value stand out a bit more.
danidiaz··on Seeing France’s Wild Mountains Through a Clouded, Classic Windshield
Writer Edith Wharton (of "The age of innocence" fame) traveled across France by automobile in 1908. She wrote her experiences in "A Motor-Flight Through France" http://www.gutenberg.org/ebooks/57347 which is a good read.

> The motor-car has restored the romance of travel.

> Freeing us from all the compulsions and contacts of the railway, the bondage to fixed hours and the beaten track, the approach to each town through the area of ugliness and desolation created by the railway itself, it has given us back the wonder, the adventure and the novelty which enlivened the way of our posting grand-parents. Above all these recovered pleasures must be ranked the delight of taking a town unawares, stealing on it by back ways and unchronicled paths, and surprising in it some intimate aspect of past time, some silhouette hidden for half a century or more by the ugly mask of railway embankments and the iron bulk of a huge station. Then the villages that we missed and yearned for from the windows of the train—the unseen villages have been given back to us!

danidiaz··on Rust, Macros, λ-calculus/Church numerals, oh my
Relatively easy in Vim with digraphs (:h digraph)

Ctrl-K l* produces λ

Ctrl-K L* produces Λ

Unsurprisingly, Emacs also supports this when programming in Agda (\lambda) i'm not sure if it's a builtin feature or part of the Agda plugin.

In Agda using Unicode identifiers is widely accepted, even in the standard library: https://github.com/agda/agda-stdlib/blob/master/src/Relation...

danidiaz··on The C language is purely functional (2009)
Section 7 of "A History of Haskell: Being Lazy With Class" http://haskell.cs.yale.edu/wp-content/uploads/2011/02/histor... explains how Haskell IO was done in the pre-IO monad days.

This recent paper by Oleg Kiselyov ("Effects Without Monads: Non-determinism Back to the Meta Language" https://arxiv.org/abs/1905.06544 https://www.youtube.com/watch?v=fABeIG_HiyU) explores an alternative to monads for structuring effectful computations in OCaml. The effect used in the examples is nondeterminism, instead of IO.

The ICFP presentation "Automatically escaping Monads" is also interesting https://www.youtube.com/watch?v=wG8AErq6Bbo http://benl.ouroborus.net/talks/2016-HIW-Escape.pdf

danidiaz··on Terry Gilliam’s Don Quixote film finally hits the big screen after 25 years
The continuous blurring between different levels of fiction and reality in this movie reminded of Philip K. Dick's novels, also of Stanislaw Lem's "Futurological Congress".
danidiaz··on Higher-Order Type-Level Programming in Haskell [pdf]
->> is a function at the type level without extra properties like matchability, so it can be simply read as "to" or "into"

-> is used with type constructors like Maybe or Either, and arguments passed to it can still be "read" in the result (for example, a -> Maybe a, or a -> b -> Either a b). I would call it a "slotting" arrow to connote that the argument will be fitted into a hole of a type constructor.

So I would read a -> Maybe a as "slotting a into Maybe".

danidiaz··on Writing a simple evaluator and type-checker in Haskell
Another educational (but more sophisticated) evaluator / typechecker in Haskell is described in "Stitch: The Sound Type-Indexed Type Checker" https://cs.brynmawr.edu/~rae/papers/2018/stitch/stitch.pdf
danidiaz··on Ask HN: What made you change your mind about a programming language/paradigm?
This is usually called the classical vs. mockist, or test interactions vs. test final state debate.

Instead of mocks, some people prefer to build fakes / stubs which are versions of a dependency which are "fully operative" in a sense but with a simplified internal implementation. For example a repository that keeps entities in memory. (Not the same as an in-memory database! The fake repository wouldn't use SQL at all.)

Tests would check the final state of the fakes after the interactions, or simply verify that the values returned by the tested component are correct.

The hope is that fakes, while possibly more laborious to set up, allow an style of testing that focuses less on the exact interactions between components, and therefore is less brittle.

Some links:

- Mocks aren't stubs https://martinfowler.com/articles/mocksArentStubs.html#Class...

- From interaction-based to state-based testing http://blog.ploeh.dk/2019/02/18/from-interaction-based-to-st...

danidiaz··on Poor-quality relationships linked to greater distress than too few relationships
Looks like this kind of competition is beneficial to society—to the point of granting a new lease of life to gravely ill people—and should be encouraged.
danidiaz··on A monad is a monoid in the category of endofunctors, what’s the problem?
The laws are important though. They ensure that the "statement-like" things we build out of expressions do behave like statements.

For example, it would be weird if we had three statements A B C that wrote to console, and sequencing A with B and then sequencing the result with C resulted in a different program than sequencing B with C and then sequencing A with the result.

Or, for non-IO things: it would be weird if we had three levels of nested lists, and concatenating two times "from the outside" resulted in a different list than concatenating each inner list first, and then the outer list.

danidiaz··on If I were to invent a programming language for the 21st century
Even if duplicate expressions are optimized by the engine, they hurt the readability and maintainability of the query, especially if they are big and complex.
danidiaz··on If I were to invent a programming language for the 21st century
LATERAL joins can help with reusing calculations https://www.periscopedata.com/blog/reuse-calculations-in-the...
danidiaz··on Type-Driven Program Synthesis [video]
Another good talk about using types to guide your programming—instead of merely checking it for errors—is "Is a type a lifebuoy or a lamp?" by Conor McBride https://skillsmatter.com/skillscasts/8893-is-a-type-a-lifebu... It is best approached with some knowledge about how the Haskell typeclass mechanism works.

The second part of the talk (from 25:50) is about how to expand the traditional Haskell Hindley-Milner type system (which is very centered on avoiding the need for explicit type annotations, using type inference) to allow the user to provide more explicit type information, which pays off by automating the generation of parts of the term-level code.

danidiaz··on Why Futurism Has a Cultural Blindspot (2015)
I'm reminded of Gerard O'Neill's seventies vision of space habitats https://99percentinvisible.org/episode/home-on-lagrange/ The artistic depictions tend to have a "suburb in a bottle" feel.
danidiaz··on The Little Typer
If the project had no existing dependent types at all, couldn't you just perform a runtime check before calling the library? The check would return evidence that [i: i%2 == 0] for the particular i, or fail at runtime. If it succeeded, then you could invoke the library using the new evidence.

One appealing aspect of dependent types is that they let you decouple validation of inputs from the function calls themselves, while still disallowing passing wrong inputs to the function by mistake.

← PreviousPage 3 of 9Next →