News for hackers. Stuff that matters.
Re:Reflecting on Haskell in 2016 by s_kilk on Monday December 26, 2016 @07:03AM (#13257960)
> I stress that the types are not enough

Exactly.

Quick, tell me what this function does:

    foo :: Num a => a -> a
Re:Reflecting on Haskell in 2016 by Buttons840 on Monday December 26, 2016 @02:23PM (#13259405)
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.

Re:Reflecting on Haskell in 2016 by 14113 on Tuesday December 27, 2016 @05:58PM (#13266987)
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.

Re:Reflecting on Haskell in 2016 by rpglover64 on Monday December 26, 2016 @04:07PM (#13259776)
> 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

Re:Reflecting on Haskell in 2016 by Buttons840 on Monday December 26, 2016 @05:58PM (#13260230)
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.

Re:Reflecting on Haskell in 2016 by pronik on Monday December 26, 2016 @09:24AM (#13258319)
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.

Re:Reflecting on Haskell in 2016 by auggierose on Monday December 26, 2016 @10:52AM (#13258606)
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.

Re:Reflecting on Haskell in 2016 by icebraining on Monday December 26, 2016 @01:45PM (#13259264)
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)
Re:Reflecting on Haskell in 2016 by pronik on Monday December 26, 2016 @04:26PM (#13259841)
(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)