Skip to content

Commit 10043af

Browse files
committed
Align -> and => with :: in type declaration
1 parent 9f43a93 commit 10043af

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

haskell-indentation.el

+4-4
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ the current buffer."
603603
;; tokens in type declarations
604604
(defconst haskell-indentation-type-list
605605
'(("::" . (lambda () (haskell-indentation-with-starter
606-
(lambda () (haskell-indentation-separated #'haskell-indentation-type "->")))))
606+
(lambda () (haskell-indentation-separated #'haskell-indentation-type '("->" "=>"))))))
607607
("(" . (lambda () (haskell-indentation-list #'haskell-indentation-type ")" ",")))
608608
("[" . (lambda () (haskell-indentation-list #'haskell-indentation-type "]" ",")))
609609
("{" . (lambda () (haskell-indentation-list #'haskell-indentation-type "}" ",")))))
@@ -634,7 +634,7 @@ the current buffer."
634634
("where" . (lambda () (haskell-indentation-with-starter
635635
#'haskell-indentation-declaration-layout nil t)))
636636
("::" . (lambda () (haskell-indentation-with-starter
637-
(lambda () (haskell-indentation-separated #'haskell-indentation-type "->")))))
637+
(lambda () (haskell-indentation-separated #'haskell-indentation-type '("->" "=>"))))))
638638
("=" . (lambda () (haskell-indentation-statement-right #'haskell-indentation-expression)))
639639
("<-" . (lambda () (haskell-indentation-statement-right #'haskell-indentation-expression)))
640640
("(" . (lambda () (haskell-indentation-list #'haskell-indentation-expression ")" '(list "," "->"))))
@@ -699,7 +699,7 @@ the current buffer."
699699
((eq current-token 'end-tokens)
700700
(when (member following-token
701701
'(value operator no-following-token
702-
"->" "(" "[" "{" "::"))
702+
"(" "[" "{" "::"))
703703
(haskell-indentation-add-indentation current-indent))
704704
(throw 'return nil))
705705
(t (let ((parser (assoc current-token haskell-indentation-type-list)))
@@ -1164,7 +1164,7 @@ the current buffer."
11641164
(match-string-no-properties 1))
11651165
((looking-at "[][(){}[,;]")
11661166
(match-string-no-properties 0))
1167-
((looking-at "\\(\\\\\\|->\\|→\\|<-\\|←\\|::\\|∷\\|=\\||\\)\\([^-:!#$%&*+./<=>?@\\\\^|~]\\|$\\)")
1167+
((looking-at "\\(\\\\\\|->\\|=>\\|\\|<-\\|←\\|::\\|∷\\|=\\||\\)\\([^-:!#$%&*+./<=>?@\\\\^|~]\\|$\\)")
11681168
(match-string-no-properties 1))
11691169
((looking-at "\\(→\\|←\\|∷\\)\\([^-:!#$%&*+./<=>?@\\\\^|~]\\|$\\)")
11701170
(let ((tok (match-string-no-properties 1)))

tests/haskell-indentation-tests.el

+29
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,32 @@ Example of lines:
195195
(haskell-indentation-check
196196
"fun = \x ->"
197197
" ^"))
198+
199+
(ert-deftest haskell-indentation-check-17a ()
200+
"A type for a function"
201+
(haskell-indentation-check
202+
"fun :: Int"
203+
" -> Int"
204+
" ^"))
205+
206+
(ert-deftest haskell-indentation-check-17b ()
207+
"A type for a function with context"
208+
(haskell-indentation-check
209+
"fun :: Monad m"
210+
" => Int"
211+
" ^"))
212+
213+
(ert-deftest haskell-indentation-check-17c ()
214+
"A type for a function with complicated context"
215+
(haskell-indentation-check
216+
"fun :: (Monad m, MonadBaseControl IO m, MyMonad (A v) m)"
217+
" => MyMonad (A v) m"
218+
" ^"))
219+
220+
(ert-deftest haskell-indentation-check-17d ()
221+
"A type for a function with param and a complicated context"
222+
(haskell-indentation-check
223+
"fun :: (Monad m, MonadBaseControl IO m, MyMonad (A v) m)"
224+
" => MyMonad (A v) m"
225+
" -> m (Maybe a)"
226+
" ^"))

0 commit comments

Comments
 (0)