2

I'm programming Haskell (GHC 9.2.8) in Emacs 29.1 with haskell-mode 17.4 on Arch Linux, which works fine; including the REPL. However, I recently got frustrated a bit when working with effects, i.e. I'm trying to type in this dummy program:

getCmd :: IO String
getCmd  = do
  c <- getChar
  if c == 'n' then
    return "next"
  else
    return "previous"

However, as I'm typing, my cursor is stuck on the new line after the else keyword. When I press tab, nothing happens, and I have to indent the second return manually using spaces:

Cursor stuck on new line after else keyword

Am I using unidiomatic syntax, or is it an issue with my setup? How am I supposed to type this code?

Patrick Bucher
  • 1,302
  • 2
  • 14
  • 36
  • although not an answer to your question, this is equivalent to `getCmd = bool "previous" "next" . ('n' ==) <$> getChar`. – Willem Van Onsem Aug 29 '23 at 08:21
  • 1
    If you see the same thing when you start Emacs using `emacs -Q` (and you load Haskell mode), then consider filing a bug report with the maintainer of Haskell mode. If not, bisect your init file to find the culprit. – Drew Aug 29 '23 at 15:34
  • @Drew When I run `emacs -Q Hello.cs` and type `M-x` `haskell-mode`, the mode cannot be loaded (`[No match]`). – Patrick Bucher Aug 29 '23 at 15:47
  • *You* need to load the library using `load-library` or `require` or whatever... The point is to test with a virgin Emacs, with only support for Haskell mode loaded - nothing else from your init file. – Drew Aug 29 '23 at 17:09
  • 2
    In ancient times, `else` needed to be indented more than `if` to avoid an indentation error. (Maybe the mode is still assuming that? No idea.) Nowadays, the extra indentation is no longer required by GHC. – chi Aug 31 '23 at 12:54
  • @chi When I put `then` on the next line, everything works; but `then` is indented by one additional level, same for `else`, as you described it. – Patrick Bucher Sep 01 '23 at 14:59

1 Answers1

1

The use of then on the same line caused the issue. This notation works:

enter image description here

So I can work with that and won't file a bug.

Patrick Bucher
  • 1,302
  • 2
  • 14
  • 36