开发者

GHCi usage question

开发者 https://www.devze.com 2023-01-18 03:13 出处:网络
I am studying Haskell and use Emacs+Haskell mode as my editor. After playing some simple expressions in GHCi, I am wondering whether these IDE/edit开发者_如何学Pythonor functionalitythat exist in Vi

I am studying Haskell and use Emacs+Haskell mode as my editor.

After playing some simple expressions in GHCi, I am wondering whether these IDE/edit开发者_如何学Pythonor functionality that exist in Visual Stuido for F#:

  1. Can I send the content in the clipboard into the interpreter? Currently I can only :load the file into the interpreter. This is inconvienent when I gradually write functions in a script file. Like 'Alt+Enter' in visual stuido.

  2. After compiling, I hope to see the signature of the function, e.g.

    let double x = x + x

so that I can better understand the type inference mechanism in Haskell.


  1. On Windows, there's WinGHCi, a gui including (poor, but often sufficient) support for copy and paste. Dunno about the command line version.

  2. Use :type double (or the shortcut :t double) to get the type signature of double. There's also :info which applies to values (including functions) as well as types and typeclasses (e.g. :info Bool lists the definition of Bool and all typeclasses it is an instance of) and says where it was defined.


Regarding question 2, to see the inferred type of an expression every time you type one in, you can give inside ghci :set +t . I think you could also put that in a .ghci file, inside your home directory, as described in http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/ghci-dot-files.html .


As far as I know, there is no support for sending the clipoards to the interpreter "out of the box", but it should not take more than couple of lines of elisp. I'd look in the support modes for other languages and copied it from there if I were you.

Regarding the types, you could type C-c C-t or C-c C-i on any symbol in your code, which would trigger ":t <symbol>" and ":i <symbol>" commands in the ghci process


TAIM claims to send selected expressions in vim to ghci(haven't tried it)

I'm not sure about function signatures inside the editor but in ghci its ":t func"

Actually looking at their youtube video it looks like TAIM may be able to select ":t func" in vim and send it to interpreter.

0

精彩评论

暂无评论...
验证码 换一张
取 消