An HTTP client in Haskell using io-streams
blogs.operationaldynamics.com
blogs.operationaldynamics.com
Aside: As a Haskell beginner, I find it astonishing that 1-letter names are the norm in Haskell-land. To me, names are not just placeholders imposed on you by the language, they should convey meaning, too!
Also, Haskell programmers use 1-letter variable names in functions that could/should be made point free [1] but aren't for some reason [2].
[1] \c -> c + 1 is not point free whereas (+1) is. An expression is point free if it doesn't have any bound variable.
[2] Because reasoning with flip or const may be confusing in the current context for example.
Other idioms come from math, e.g. 'x' for an unknown value, and then we get 'xs' for a list of unknown values.
map :: (a -> b) -> [a] -> [b]
map f (x:xs) = f x : map f xs
Is much clearer than the Zed Shaw version: map theFunction (firstElement:otherElements) = theFunction firstElement : map theFunction otherElementsI don't write haskell but if I did I think I'd go with:
map func (first:rest) = func first : map func rest
Maybe using car and cdr for first and rest because of my lisp background.That being said, for such a simple function using f, x and xs is probably fine (the way using int i; in C is fine).
For generic code, writing first:rest is not bad but it does look a bit superfluous, somewhat like writing
quotient = numerator / denominator
instead of simply x = y / z. It doesn't really give you any extra information, and for me it sort of suggests that the programmer needs to remind themselves of what the operators : and / mean.Of course, if the code is not generic and the variables do have concrete meanings you should name them appropriately, e.g. roi = return / investment. But when we write x:xs it's typically polymorphic (or otherwise generic) code.
However, the example code uses `c' for connection and `q' for query. Surely, knowing what those are from the variable name would be a good thing?
It's not that I want to impose Obj-C's verbosity but the other extreme (1-letter names) is just as bad.
In this case, the example is short enough that there's no chance of confusion (for the intended audience): clearly c is a connection and q is a request. They're only used in those few lines.
However, I wouldn't say 1-letter names are the norm in typical Haskell code (outside type variables).
(go), type parameters, (x:xs) "\ds ->", "import qualified This as That".
I think it's just like a java programmer internalizes when to use HashSet, HashMap, TreeSet, ArrayList etc. After a while you just know what to do.______________
yesterday's long debate about this:
http://www.reddit.com/r/programming/comments/19mw7v/on_f_rea...
________
APL and C, with some scheme and prolog thrown in, were my first languages, so maybe readability just isn't important to me ;-}