Live data from Hacker News

Reading Simple Haskell

soupi.github.io

41–50 of 82 posts

Re: Reading Simple Haskell

#41

I once downloaded a python script, ran it with some input, and got a result. Curious, I opened the script in Emacs, which then opened it into python mode. As is my habit, I indented the whole file, which did basic white space changes to it according to python mode. I didn't realize I did this at first, and I saved and exited the script, then played around with it some more. Still got results, everything seemed the sa…

What did you use to do the indenting?

Just default emacs indent behavior for python mode.

Re: Reading Simple Haskell

#42
post #32

I once downloaded a python script, ran it with some input, and got a result. Curious, I opened the script in Emacs, which then opened it into python mode. As is my habit, I indented the whole file, which did basic white space changes to it according to python mode. I didn't realize I did this at first, and I saved and exited the script, then played around with it some more. Still got results, everything seemed the sa…

> Which is partly why OCaml gets some bias from me over Haskell. Sounds like you made a mistake, then, because indentation is optional in Haskell: https://en.m.wikibooks.org/wiki/Haskell/Indentation#Explicit...

I have never seen a Haskell dev do this.

Re: Reading Simple Haskell

#43
post #17

I once downloaded a python script, ran it with some input, and got a result. Curious, I opened the script in Emacs, which then opened it into python mode. As is my habit, I indented the whole file, which did basic white space changes to it according to python mode. I didn't realize I did this at first, and I saved and exited the script, then played around with it some more. Still got results, everything seemed the sa…

You used a buggy beautifier that mishandled some code, and you blame significant whitespace? For that to be valid criticism, it must be particularly hard to write a beautifier for languages with significant whitespace relative to other languages. I don’t think it is. Beautifying C, for example, also can be tricky in the presence of nested comments (potentially of different types) and nested if statements, some withou…

Python and emacs are both popular, and I'm talking about default indent behavior for python in emacs, not some fringe or esoteric plugin for beautifying.

If that's buggy, then there's a larger problem in my opinion.

Re: Reading Simple Haskell

#44
post #29

Earlier quoted context omitted.

I’d honestly appreciate some examples of non-indentation syntax. They’re think on the ground.

It's as noted above: put an opening brace after the "where", "let", "do" and "of" keywords[0], put semi-colons between (or after both work) "statements" in a given "scope" e.g. declarations (in let and where blocks), clauses (in case/of blocks) and actual statements (in do blocks) module Main where { main = do { let { a :: Int; a = 8; b :: Int; b = 3; }; let { c = a `quot` b } in print c; }} You can also format it al…

Yeah, I think the real problem I have is the impossibility of opting out of the indentation style. Not using any indentation or newlines seems pretty extreme. All I want to do is write it like it was C, and that’s not possible (maybe we need yet another extension)

Re: Reading Simple Haskell

#45
post #19

Earlier quoted context omitted.

Because braces don't introduce bugs? You can just as easily omit braces in a if/for etc statement and have a bug, or close the wrong brace at the wrong point (and also introduce a bug).

>omit braces so you're saying braceless ifs and fors are bad? yes I agree. > close the wrong brace -/+ 1 flipping the right number of braces to get that kind of bug is much much harder than indenting a block incorrectly

>flipping the right number of braces to get that kind of bug is much much harder than indenting a block incorrectly

Maybe, but enclosing an additional statement or more in your brace because you visually indented it incorrectly is just as easy as in Python.

  for (i=0; i
And if you didn't indent it incorrectly, then it's still possible:

  for (i=0; i
whereas in Python it's not:

  for i in range(100):
     do_this_100_times()
  but_this_just_once() # correct indentation takes care of it

Re: Reading Simple Haskell

#46

Earlier quoted context omitted.

What did you use to do the indenting?

Just default emacs indent behavior for python mode.

C-x h C-M-\? Or just going through hitting tab on every line? If the first, that was a bug in emacs. If the second, that was a predictable result.

Re: Reading Simple Haskell

#47
post #44

Earlier quoted context omitted.

It's as noted above: put an opening brace after the "where", "let", "do" and "of" keywords[0], put semi-colons between (or after both work) "statements" in a given "scope" e.g. declarations (in let and where blocks), clauses (in case/of blocks) and actual statements (in do blocks) module Main where { main = do { let { a :: Int; a = 8; b :: Int; b = 3; }; let { c = a `quot` b } in print c; }} You can also format it al…

Yeah, I think the real problem I have is the impossibility of opting out of the indentation style. Not using any indentation or newlines seems pretty extreme. All I want to do is write it like it was C, and that’s not possible (maybe we need yet another extension)

> Not using any indentation or newlines seems pretty extreme.

You can certainly use indentation and newlines, my examples were just demonstrating the ability to "obviously" not invoke layout since there's nowhere layout information can be.

Whether to use layout (braceless) or explicit structuring (braceful) is solely determined by a brace being present after a listed keyword, you can have any whitespace you want around it, and you can make that decision on a keyword-by-keyword basis[0] although it will apply to the entire block, so you can write

    module Main where -- no brace, layout rules

    main = do { -- brace, no layout
      let { a = 3 };
      let { b = 5 };
      print $ a + b;
    }
Now here the let statement (rather than expression) is a bit tricky because if we don't use the braces the ; will bind to the "let" which is not using layout, resulting in a parse error. An alternative — and the way do blocks normally desugar — is to use ; as a separator prefix, a style also used by e.g. Elm:

    module Main where

    main = do 
      { let a = 3
      ; let b = 5
      ; print $ a + b
      }
[0] this is very very useful when generating code which must surround user-provided code: the generated code can be braceful and the user-provided code can independently use layout without conflicts.

Re: Reading Simple Haskell

#48

Earlier quoted context omitted.

Just default emacs indent behavior for python mode.

C-x h C-M-\? Or just going through hitting tab on every line? If the first, that was a bug in emacs. If the second, that was a predictable result.

indent-buffer probably is the emacs command unless python mode overwrites that.

Re: Reading Simple Haskell

#49
post #13

This site breaks the zoom function in Firefox. Please be considerate towards the visually impaired, and don't break zoom on one of the few browsers that actually even have a somewhat useful zoom function!

While I agree STRONGLY, I just tested after seeing your comment and it led me to try the Reader mode in FF which worked perfectly and thus allows full zooming of this site.

Re: Reading Simple Haskell

#50
post #32

Earlier quoted context omitted.

> Which is partly why OCaml gets some bias from me over Haskell. Sounds like you made a mistake, then, because indentation is optional in Haskell: https://en.m.wikibooks.org/wiki/Haskell/Indentation#Explicit...

I have never seen a Haskell dev do this.

Which shows what most people prefer. None the less your concern is more than valid and a real problem. My suggestion would be that the interpreters/compilers of white-space sensitive languages should implement the beautifying operation and call it before code is executed and editors should use this function. We can't expect to not adapt editors to different code styles.
Post reply on HN