Hacker News new | ask | show | jobs
by mohamedsa 5346 days ago
Whenever I try to learn e.g Haskell, the small things stand in my way; for example everything looks like a series of identifiers separated by whitespace, and the only way to understand it is to manually parse it in my mind, knowing the arity of every function, data constructor, and the like. Probably a minor thing to most Haskellers, but still an obstacle to me..

Besides being easily able to visually parse a source file, a usability issues in some languages for me is 'voicing' the code in my head or reading it to another programmer; a problem I also have with mathematical notation sometimes.

When creating my own language for teaching programming, I decided to have a 'canonical reading style' so that teachers and students always know how to read a given code snippet out loud or in their head, facilitating understanding and communication.

2 comments

Well, Haskell functions are curried, so you could think of the arity as always being 1. ;-)

If you're writing code, you can always use redundant parentheses at first. Then you refactor, gradually removing the parentheses or replacing them with an appropriate combination of ($) and (.).

Another useful thing to learn is how to write point-free code. An example:

    strToUpper xs = map toUpper xs
    strToUpper' = map toUpper
These are essentially the same function, but the latter is often preferred. Note also that they have the same type, namely String -> String.

If you're reading code and you find it hard to parse, you probably need to read easier code (for instance, from LYAH or RWH), but more likely you need to write more code of your own.

Besides LY and RW, the Stanford lectures notes are an excellent resource:

http://www.scs.stanford.edu/11au-cs240h/notes/

https://github.com/bos/stanford-cs240h

Somewhere in here are notes from Washington U of St. Louis studnets that were really helpful:

http://www.haskell.org/haskellwiki/Tutorials

http://haskell.org/haskellwiki/Category:Tutorials

http://haskell.org/haskellwiki/Learning_Haskell

I know about currying, but there's still a certain meaning to arity even in this case.

It might be argued that on the long run the current syntax is better for the veteran Haskeller, but it's still some barrier to entry. I wonder if a Haskell IDE could have a 'clarify calls' mode that shows where each function argument goes or comes from..

There are plenty of things to criticize in the Haskell syntax rules — they're hard to get used to and they're not so beneficial that the learning curve seems worthwhile — but parsing isn't as ambiguous as it seems at first. When you see a sequence of identifiers separated by spaces, the first one has to be a function accepting all the others as arguments.

It's different (and complicated to explain) if there are newlines involved, though. Haskell isn't a whitespace-insensitive language.