if-statementhaskellemacshaskell-mode

emacs haskell-mode: <tab> does not work for if/then/else within do


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?


Solution

  • 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.