Hacker News new | comments | show | ask | jobs | submit login

I am one of the people who are interested in Haskell and find its documentation lacking. I don’t miss comprehensive language books, I miss module documentation. It almost looks as the Haskell community has something against examples in documentation. I stress that the types are not enough. Contrast that with Elm, where I was able to write a working app in a day or so. But Elm is written off quite harshly in the post, so I am again left with the feeling that Haskell may not be the language meant for people like me.



To be fair this thread is an example of the Haskell community agreeing with you: https://www.reddit.com/r/haskell/comments/2ory86/there_is_a_... (2014)

After using the language for two years I find that the types are actually enough to understand a new library, however, am taking for granted that it's an acquired skill.

Looking back I do recall being in the same position as you, someone who just wanted to wrap their head around something and get an example working. I was stubborn and plowed through things I didn't understand until it clicked, but do realize that not everyone is as hard headed as myself.


As a recent beginner, I've found it incredibly hard to write something practical by putting a library into good use. If you want more that printing out Fibonnacci sequences, like printing out your own Twitter stream, like I have done, you better be ready for a lot of pain. The twitter module makes extensive usage of lens, wraps everything with conduit (at least within the examples). Conduit itself is exhaustively documented, as are lens, but you can't get started without a couple of external tutorials, since there is no practical description of the basic underlying concepts in the main documentation on hackage. And even then you don't know exactly how everything fits in, since all you get is for the most part what, but not how and especially why you should be using this what.

So my basic impression is: as soon as you know where the library fits in and how it works and even more importantly why it is doing things the way it does, you can get by just by using type signatures. But that knowledge is usually hidden behind a myriad of half-done blog posts and well-meant tutorials, which introduce you to the what but still assume a good deal of knowledge about why. And the rabbit hole gets larger with every dependency boiled onto your actual study target.

It's not by any means impossible to get in, but I think it could get a lot better. Just making a habit of merging tutorials and introductions into the module's documentation would be a great step forward. A mandatory ELI5 section might do wonders :)


> After using the language for two years I find that the types are actually enough to understand a new library, however, am taking for granted that it's an acquired skill.

I think this overstating it, unfortunately. I'm an intermediate Haskeller, and when I tried to use `hasql`, I found the lack of documentation to slow me down.

It's a testament to the power of types as documentation that I was able to use it at all, but examples and simple cookbook-style "Here's how you do this thing" or "Here's how you use this component" or "You can't do this because the interface doesn't allow it; here's why" would have sped up my acquisition of the library immensely.


Elm was written off because it still does an incredibly bad job at implementing polymorphism. It has a hardcoded "Show" class for turning things into strings and only certain privileged entities can be turned into strings using it.

It's all in all a very bad way to do polymorphism and that's what the article points out. It's especially odd in a language like Elm, that obviously is supposed to be like other ML-like languages.


My point is: I tried several times to write something in Haskell, I really want to like the language. But each time I felt too stupid for it, it just feels like too much work. In Elm I got a working app in a day and enjoyed the experience. Isn’t there a lesson for the Haskell community other than “Elm does polymorphism wrong, meh”?


Maybe both are catering to different programmers?


Is Haskell catering to programmers who don't want to be able to get a simple app up in a day? Who are these programmers who fight through the first steps of picking up a language and are thrilled by that.


Maybe yes, You can not learn Haskell in one day, if that was your point. My point is learning Haskell takes time and it's hard and it is totally understandable if for some people that is not a good investment.


I was writing a reply to this, but it got long enough that I decided to make it a standalone blog post.

http://softwaresimply.blogspot.com/2016/12/on-haskell-docume...


I was considering writing roughly the same thing you did, thanks. There's a lot of terrible documentation in every language, but I think it may be a losing battle to show this as a counter example unfortunately.

I think it's just that the gap to get proficient with Haskell for an imperative programmer is a hurdle they are blind to (I was blind myself!), and they assume a few simple tutorials will bootstrap them into the language like it did the other handful they learned.

This is clearly an education problem, but I guess we still have a ways to go to get acceptance.


> I think it may be a losing battle to show this as a counter example unfortunately.

Yeah, my intent wasn't to suggest that all non-haskell docs suck. But to show how other languages are much more howto/tutorial oriented, which I didn't appreciate as much before I had to look at ACE recently.


> I stress that the types are not enough

Exactly.

Quick, tell me what this function does:

    foo :: Num a => a -> a


I don't know exactly what it does, but I do know it only uses basic mathematical operations, it's just a formula. I also know it doesn't do any logging, or "launch nukes", and that it is thread safe.

You're never given only the type signature however, you also will have the source code. It's very likely that foo is no more complicated than something like:

    foo :: Num a => a -> a
    foo n = n * 42 + 1
If foo is as complicated as that, then a sentence or two explaining what it's purpose is would be helpful; explaining the "why" of such an odd function would be good. The documentation probably can't say "what" foo does any more clearly than the source code however.

If the function is reasonably named, like:

    double :: Num a => a -> a
    double n = n + n
then having some documentation that says "Doubles the given number" isn't going to add much value, and might become out of sync with the actual code. I appreciate that all the Haskell documentation I have ever encountered has a links to the source code throughout.

Aside: When I look at the definition of an unknown function in Haskell, I feel like I'm at the top of an hierarchy. The unknown function may be comprised of other unknown functions, but the entire structure of what is happening is present. I know what all the variables are, etc. When I look at the definition of an unknown object-oriented function I often find myself in the middle of an inheritance stack with implicit behaviors and variables being inherited from above, and unknown functions being called below, and it's more confusing in my opinion.


I guess the counterexample would be library functions that look like:

     foo :: (BarMonad m, BazApplicative b) => ConfigurationStructure t -> (b -> m t) -> [b] -> t
You can figure out a little of what it does, but how that fits into the application it supports, and what exactly it should be used for is non trivial.

Haskell programmers (whose numbers I count myself amongst) saying that "the types are the documentation" is like expecting someone to build a lego model from the picture on the box, and saying "well the studs are the documentation of how the pieces fit together". It's correct, but it misses all the nuance of how the functions should be composed, not just how they can be composed.


> it's just a formula. I also know it doesn't do any logging, or "launch nukes", and that it is thread safe.

So the type claims. Without looking at the implementation or using `-XSafeHaskell`, you don't know if there's an `unsafePerformIO` call lurking.

/pedantry


Even if the function had documentation that said "this function does not have side effects" it could still have side effects.

So within the context of this thread, type signatures vs hand written documentation, I would say your point is a +0 for hand written documentation. Both type signatures and hand written documentation can lie.


It foos a number into another number, what else? If it does something else or if it's unclear what fooing is, it should be renamed and the parameter types should be at least aliased to something more adjusted to the task.

It's basically Haskell code smell. Other languages we are used to do not allow exact precision when talking about input and output types, that's why we don't think about overly-generic function declarations as smelly, but they are.


That's typical Haskell brain wash talk.

Types can be a useful part of the documentation, but if your program is the least bit interesting, you will have parts that you should properly document. This is so much more true for libraries, especially those that adhere to a more mathematical style. If you write such a library, you should also write a paper explaining the library.


Just out of curiosity, how would you change the following definition to make sure it's clear without reading anything else?

    words :: String -> [String]
If you say it's already obvious, I disagree, since this code prints "1":

    main = print $ length $ words "jack am I"
(The spaces in the string are six-per-em unicode characters)


(like I said elsewhere, I'm a beginner, so I might be over-euphorical about controversial ideas. Also I don't in any way propose working only with type definitions instead of prosa documentation, however I think type definitions can go a long way to introduce the basic operations to the user)

In this case, I'd try something like this:

  words :: Sentence -> [Word]
(Sentence and Word being aliases for String)

A function named `words` with `Sentence` as a parameter implies a common-sense do-what-I-mean function, like breaking on all sensible whitespace. With common sense in play, it's your task to make the function behave like people expect it to (which differs per person of course). If you choose not to, don't write `words`, write a `split` with a parameter for character classes (or indeed a boolean function working on a character) the split should be performed on.

(PS. I assume you are implicitely critisizing Prelude's `words`, which breaks on anything that's `isSpace`, which is explicitely defined. Its definition is way out of my competence, there are probably good reasons for not including thin spaces. If not, they could probably get included with a due process -- with common sense, it's always an iterative process till it's done)




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: