Skip to content

Instantly share code, notes, and snippets.

@Fuuzetsu
Created November 29, 2013 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fuuzetsu/7700214 to your computer and use it in GitHub Desktop.
Save Fuuzetsu/7700214 to your computer and use it in GitHub Desktop.
insert type of Haskell functions
(defun haskell-insert-type ()
"Insert the type of the function on the previous line.
You have to be be on the first line of the function.
Use `haskell-insert-type-infix' for infix functions.
It uses the Haskell inferior process in order to get the class constraints
as well"
(interactive)
(save-excursion
(beginning-of-line)
(zap-up-to-char 1 ?\s)
(yank)
(let ((func-type (inferior-haskell-type (yank-peek))))
(beginning-of-line)
(newline)
(previous-line)
(insert func-type))))
(defun haskell-insert-type-infix ()
"Insert a type of the infix function on the previous line.
Also see `haskell-insert-type'. Note that this works by using the spaces between
arguments to determine the of function so it will fail if your first argument
contains a space, for example when matching on a String.
It uses the Haskell inferior process in order to get the class constraints
as well. Make sure you have loaded the file using `inferior-haskell-load-file'."
(interactive)
(save-excursion
(beginning-of-line)
(zap-up-to-char 1 ?\s)
(yank)
(forward-char)
(zap-up-to-char 1 ?\s)
(yank)
(let ((func-type (inferior-haskell-type
(concat "(" (yank-peek) ")"))))
(beginning-of-line)
(newline)
(previous-line)
(insert func-type))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment