 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Auto actions
+
+(defun intero-parse-comma-list (text)
+  "Parse a list of comma-separated expressions."
+  (loop for tok in (split-string text "[[:space:]\n]*,[[:space:]\n]*")
+        with acc = nil
+        append (let* ((clist (string-to-list tok))
+                      (num-open (-count (lambda (c) (or (eq c ?\() (eq c ?\[)))
+                                        clist))
+                      (num-close (-count (lambda (c) (or (eq c ?\)) (eq c ?\])))
+                                         clist)))
+                 (cond
+                  ((> num-open num-close) (progn (add-to-list 'acc tok) nil))
+                  ((> num-close num-open) (let ((tmp (reverse (cons tok acc))))
+                                            (setq acc nil)
+                                            (list (string-join tmp ", "))))
+                  (t (list tok))))))
 
 (defun intero-apply-suggestions ()
   "Prompt and apply the suggestions."

               (flycheck-mode)
               (add-to-list (make-local-variable 'company-backends) 'company-intero)
               (company-mode)
	       (set (make-local-variable 'eldoc-documentation-function) 'eldoc-intero))
      (message "Intero mode disabled."))))

(define-key intero-mode-map (kbd "C-c C-t") 'intero-type-at)

               (save-excursion
                 (goto-char (point-min))
                 (forward-line (1- (plist-get suggestion :line)))
                 (search-forward-regexp "[[:alnum:][:space:]\n]*=>")
                 (backward-sexp 2)
                 (let ((start (1+ (point))))
                   (forward-sexp)
                   (let* ((end (1- (point)))
                          (constraints (intero-parse-comma-list
                                        (buffer-substring start end)))
                          (nonredundant
                             (loop for r in (plist-get suggestion :redundancies)
                                   with nonredundant = constraints
                                   do (setq nonredundant (delete r nonredundant))
                                   finally return nonredundant)))
                     (goto-char start)
                     (delete-char (- end start))
                     (insert (string-join nonredundant ", "))))))))

        ;; Add a type signature to a top-level binding.
        (cl-loop
