HN Books @HNBooksMonth

The best books of Hacker News.

Hacker News Comments on
The Haskell Road to Logic, Maths and Programming. Second Edition (Texts in Computing)

Kees Doets, Jan van Eijck · 8 HN comments
HN Books has aggregated all Hacker News stories and comments that mention "The Haskell Road to Logic, Maths and Programming. Second Edition (Texts in Computing)" by Kees Doets, Jan van Eijck.
View on Amazon [↗]
HN Books may receive an affiliate commission when you make purchases on sites after clicking through links on this page.
Amazon Summary
Long ago, when Alexander the Great asked the mathematician Menaechmus for a crash course in geometry, he got the famous reply ``There is no royal road to mathematics.’’ Where there was no shortcut for Alexander, there is no shortcut for us. Still, the fact that we have access to computers and mature programming languages means that there are avenues for us that were denied to the kings and emperors of yore. The purpose of this book is to teach logic and mathematical reasoning in practice, and to connect logical reasoning with computer programming in Haskell. Haskell emerged in the 1990s as a standard for lazy functional programming, a programming style where arguments are evaluated only when the value is actually needed. Haskell is a marvelous demonstration tool for logic and maths because its functional character allows implementations to remain very close to the concepts that get implemented, while the laziness permits smooth handling of infinite data structures. This book does not assume the reader to have previous experience with either programming or construction of formal proofs, but acquaintance with mathematical notation, at the level of secondary school mathematics is presumed. Everything one needs to know about mathematical reasoning or programming is explained as we go along. After proper digestion of the material in this book, the reader will be able to write interesting programs, reason about their correctness, and document them in a clear fashion. The reader will also have learned how to set up mathematical proofs in a structured way, and how to read and digest mathematical proofs written by others. This is the updated, expanded, and corrected second edition of a much-acclaimed textbook. Praise for the first edition: ‘Doets and van Eijck’s ``The Haskell Road to Logic, Maths and Programming’’ is an astonishingly extensive and accessible textbook on logic, maths, and Haskell.’ Ralf Laemmel, Professor of Computer Science, University of Koblenz-Landau
HN Books Rankings

Hacker News Stories and Comments

All the comments and stories posted to Hacker News that reference this book.
I like Julia for all of the libraries, the Lisp underneath, however, from the article:

"Many of the encodings are as immutable, purely functional data structures (even in imperative languages), a topic unfortunately omitted from many computer science curricula."

Julia and similar PLs don't express math like APL, J[1], Haskell[2], Scheme[3] or even Clojure can with immutable structures and function composition to name a couple. Sure you can write it in Julia, but I don't think the article is about creating math output in the Latexify.jl example, but how to code these math structures where certain languages can express them out of the box in an easier manner.

[1] https://www.jsoftware.com/books/pdf/

[2] https://www.amazon.com/Haskell-Logic-Programming-Second-Comp...

[3] https://mitpress.mit.edu/sites/default/files/titles/content/...

adamnemecek
Idk why apl or haskell would be any better.
new4thaccount
I'm not as opinionated on Haskell, but APL is both a programming language AND executable math notation. It's just the notation is different than what most are already used to.
ddragon
Can you explain it better? I do agree with Haskell due to laziness by default and arrow types for example, but against Scheme and Clojure the only aspect seels like it would be the more strict rebinding/shadowing rules (which doesn't limit what you can express, just that you can also express non-mathematical expressions).

Primitive types (like pretty much all languages) are immutable and structs in Julia are immutable by default (which includes pretty much every math type like complex numbers), and all math operators are non mutating (in fact mutating operators should have a ! in the name).

Function composition is just as simple in this scenario:

f(x) = x + 2

g(x) = 2x

h = g ∘ f

h(3) == 10

eggy
@ddragon your points are well taken. I will look further into Julia. I still think when I wrote "out of the box" with APL in mind as far as expressing math, or J for that matter if you learn the ASCII symbols. I've seen other examples since your post on Julia that show similar math expressiveness, but they seem to rely on libraries or the syntactic sugar provided by the libraries. I haven't tried your example, but it looks like vanilla Julia. My familiarity with Matlab makes Julia an easy choice for me too.

Here is a simple example in J:

+/ % #

The above is an average function in J. It is a fork, where you fold right over the input (+/), and divde (%) by the tally (#) or count of items, so that

(+/ % #) 4.5 3 2 12

produces 5.375 as the average of the input vector. Notice the array-based language deals with singular quantities or scalars, vectors, and multi-dimensional arrays as fundamentals of the PL.

You could also define it as:

average =: +/ % #

for those who make the readability argument, however, you learn math symbols and read math papers full of them, and not lengthy verbal descriptions of these math formulas (average is equal to the "sum all of the input elements, and divde by the count or tally of input items").

The fact that a highly-functional APL program can fit on one screen negates the argument that you need readability, so that when you pick up or someone else picks up, your 110K lines of JavaScript code they can make a change. You may have to do a refresh read in APL and J, but because it is terse, you can deal it pretty quickly. Well-commented code in the 100k to 1 million lines of code scale will never allow one person to see the whole picture.

The work by Aaron Hsu in APL is amazing. Here is a link to the slides from a talk he gave. It's a bit lengthy but I found it very interesting and appropriate to this topic:

https://sway.office.com/b1pRwmzuGjqB30On

The YouTube link to the talk is here:

https://www.youtube.com/watch?v=9xCJ3BCIudI

May 12, 2019 · eggy on Calculus with Julia
I loved working through Ken Iverson's, the creator of APL, books in J: "Calculus", "Algebra", and the "Concrete Math Companion" (a companion Knuth and Patashnik's book "Concrete Math" in J)[1].

I also like the Physics and Math in SICM (Structure and Interptretation of Classical Mechanics), and Scheme maps well to math equations, at least for me [2].

Julia does follow the way math is written, but I prefer Haskell. The book "The Haskell Road to Logic, Math and Programming" [3] is great, and this article on Geometric Algebra (GA) in Haskell is excellent [4].

[1] https://www.jsoftware.com/books/pdf/

[2] https://mitpress.mit.edu/sites/default/files/titles/content/...

[3] https://www.amazon.com/Haskell-Logic-Programming-Second-Comp...

[4] https://crypto.stanford.edu/~blynn/haskell/ga.html

The 2nd edition (2012) fixes this and recommends ghci -- http://www.amazon.com/Haskell-Programming-Second-Edition-Com...

Worth the purchase!

While there is no "royal road" to mathematics for programmers who don't care about proofs, there is a programmer's road to proofs for those interested in Math.

In fact, the book is even called "The Haskell Road to Logic, Maths and Programming" [0]. It covers mathematical notation, proof construction, and lots of interesting portions of discrete math that should be of interest to programmers. And large portions of the results are demonstrated or used in interesting Haskell programs.

[0] http://www.amazon.com/Haskell-Programming-Second-Edition-Com...

dysoco
That book is on my to-read list, yet I don't know what to think of a book that starts like this: http://i.imgur.com/rSc0fpw.png
hcarvalhoalves
Both Haskell and LISP are in the "top-down" approach (approaching programming from an abstract angle, without concerns about the underlying machine), as opposed to the "bottom-up" approach (where you are explicitly managing I/O, memory, and the underlying machine is not abstracted away), like C or Ada.
JulianMorrison

    lambda calculus --> Haskell
                   \--> LISP --> Scheme
                            \--> Common Lisp
ef4
The validity of that statement depends on your historical perspective.

To the modern eye, we see radically different type systems and conclude they are as different as night and day.

But there was a time when the world was divided into people who thought anything higher-level than C or FORTRAN was stupid and impractical, and those who aspired to build more abstract languages. LISP was one of the rallying cries of the latter group. Haskell clearly falls into that group too.

slurry
I' m not sure it makes a ton of sense either, even for an older book. OTOH, knowing a lot about programming language history/politics and knowing a lot about math and rigorous CS theory tend to be negatively correlated in my experience.

I know I should be demonstrating that assertion with hard numbers, but in my defense I do know a lot about programming language history and politics. ;)

dysoco
Hm, that makes some sense, the book might be old, that's why.
andrewflnr
It can't be that old, since according to Wikipedia Haskell itself is only about 23 years old. http://en.wikipedia.org/wiki/Haskell_(programming_language)
j2kun
And before that, there were the people who thought anyone using an assembler was wasting precious CPU cycles, and something like FORTRAN was considered heresy.
rplacd
The Acknowledgements has an interesting anecdote - Thierry Coquand, apparently, found the original lecture notes that would become the book out the blue and seems to have offered quite a bit.
mathattack
I would add that Project Euler (www.projecteuler.net) is a fun place to practice.

To your point, many of the best solutions are done in Haskell. They make it seem so easy!

elviejo
The Haskell Road to Logic is a pretty good.

I took a class on discrete mathematics only with formulas. I didn't understand any of it.

Then I read this book and all of it made sense.

"What I cannot program, I cannot understand.." (with my apologies to Feynman)

There is a really nice book trying to teach exactly this (among other things) called "The Haskell Road To Logic, Maths and Programming":

http://www.amazon.com/Haskell-Logic-Maths-Programming-Comput...

gtani
available for free, according to

http://hackershelf.com/topic/math/

Oct 18, 2011 · Adaptive on Why Not Haskell?
For those interested in learning Haskell, I can recommend the lesser known "Haskell Road to Logic, Maths, and Programming":

http://www.amazon.com/Haskell-Logic-Maths-Programming-Comput...

It's great to go over old and new math concepts and do so while exploring Haskell.

gtirloni
I've read numerous Haskell docs online and they are pretty good. However I felt the need for a more in-depth book and I chose "Haskell: The Craft of Functional Programming" (3rd edition) and I'm LOVING it. It's excellent and I recomment it for anyone starting on Haskell.

ps.: I'm not a professional coder and my experience has been on using Python/Shell Script for sysadmin stuff only. However, I constantly read C code to figure out issues and how the book tries to make a parallel between FP and Imperative is quite nice for me.

twfarland
I'm going through this now. I've no math/logic background but wish to learn, so is perfect for where I'm at. Interactivity is a great learning tool. The book's focus isn't on real world software engineering though, so anyone expecting that should look elsewhere.
darklajid
I don't know. For me this sounds like a very bad idea.

What is putting me off (tried building small things in Haskell a couple of times) is the already heavily buzzword compliant community, throwing not only a new language with new concept at me, but adding words that at first seem to be made up on the spot.

Additionally, as others have said here, I'm having most troubles interacting with the world (IO!). Pure functions (Math!) are ~easy~ to represent.

You suggest starting with that language and learning 'new math concepts' on the go?

(I'm sure this works for some people and hats off to you guys, but for me this increases the mental complexity immensely)

Adaptive
I think you raise a good point and I wouldn't want to put others off if this isn't commensurate with their learning style. I suspect the overlap between math geeks and haskell learners is pretty big, but one should, as you are, evaluate one's own preferred learning style against this approach.

I find human languages are the same for me. I have always liked to approach them from a bottom up linguistic direction, but this means largely self-structured study.

Aug 04, 2011 · lostmypw on [Missing Story]
> My goal is really to add math to my diet, ...

I've started reading "The Haskell Road to Logic, Maths and Programming", maybe that's something for you or some other lurker here that would like to improve on math.

There is a review [2] that gives an interesting impression on the book. The other ones at amazon might also be interesting.

The table of contents + first chapter is available as a postscript file[3]. This should give you an idea what to expect from the book.

[1] http://www.amazon.com/Haskell-Logic-Maths-Programming-Comput...

[2] http://www.amazon.com/review/R3CL50MCVEO7UA/ref=cm_cr_pr_per...

[3] http://www.cwi.nl/~jve/HR/HR-27.ps.gz

jinfiesto
I have this book as well has "How to Prove it." They cover virtually the same material, however I found the prose in "The Haskell Road" to be stilted and sometimes confusing. I got much more out of "How to Prove it."
lostmypw
Interesting; thank you for providing your perspective. Both books indeed share most of the topics, although from glancing at both TOCs HR seems to add Polynomials and Corecursion. I'll gladly keep this in mind should I get stuck with HR.
jinfiesto
This isn't to say that HR is bad, on the contrary it's quite good. Be prepared to use Google though. How to Prove it is much more self-contained.

It is true that HR covers Polynomials and Corecursion. If I were you, I'd order both and use How to Prove it if you get stuck with The Haskell Road. They're both very inexpensive.

HN Books is an independent project and is not operated by Y Combinator or Amazon.com.
~ yaj@
;laksdfhjdhksalkfj more things
yahnd.com ~ Privacy Policy ~
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.