Showing posts with label Haskell. Show all posts
Showing posts with label Haskell. Show all posts

20090531

Workaround for sendtorepl and ghci

Judah, the author of haskeline, says:
"This was probably caused by a bug which has been fixed in the latest
release of Haskeline (0.6.1.6).

That fix should ship with ghc-6.10.4"
In the meantime, he gave me this solution, which works here:
cabal update && cabal install ghci-haskeline
Then, you should not interact with your 6.10.3 ghci; rather, you should interact with the executable ghci-haskeline, which is probably here:
~/.cabal/bin/ghci-haskeline
So now, when I start my screen session that I plan to interact with, I use this line:
screen -S haskellSession -t haskellSession ~/.cabal/bin/ghci-haskeline
Ghc-6.10.4 should not require this simple workaround.

20090506

Send text from vim to any REPL

Like I said back in April, I'd been looking for a convenient way to interact with any REPL from vim. Nothing had been satisfactory until I found Mr. Martinez's vicle.vim, which is in turn based on Jonathan Palardy's slime.vim. Thanks to both of them! I really learned a lot. Vicle was a great starting point. However, I wanted a little different behavior from it. It needed modification to play well with GHCi and literate Haskell.

Now I have a decent initial version. I've tried single lines with GHCi, Python, and the shell. I've done blocks in GHCi. All seem to work fine. I guess any REPL works for single lines: Octave, R, maybe an ftp session, etc. Multiple lines with a REPL other than GHCi will require modification of the script. Please try it and let me know if it has problems or if you have any suggestions on how it could be improved. it requires GNU Screen. The biggest problem I know of with it is the 4096 byte limitation mentioned by Mr. Martinez. It would be nice to find a way around that.

Like vicle.vim and slime.vim, you will need GNU Screen. I start it with something like this:
screen -S haskellSession -t haskellSession ghci
Map the commands at the bottom to convenient keys in your .vimrc. I use Enter for :SendtoreplSend and in visual mode also Enter for :SendtoreplSendBlock. For blocks, it's also convenient to do something like map F10 to the command sequence "vip".

Download sendtorepl.vim: http://www.srl.im.dendai.ac.jp/renick/sendtorepl.vim

It's time to get busy using this.

20090504

For editline, don't bind jj to vi-command-mode!

I've hesitated posting my version of vicle because I was having what I thought was a weird bug. Somehow, only things with "j" in them were not working. It seemed like "j" and the next character were always omitted from the input to ghci. Finally it occurred to me to try sending the output to bash rather than ghci, and suddenly there was no problem. So the problem was in ghci. Then I remembered that I had done some things in .ghci and .editrc. The latter is where I found I had a line "bind jj vim-command-mode". That turned out to be really bad choice.

And here's where I got that from:
bind -v
bind \\t rl_complete
bind ^L ed-clear-screen
bind jj vi-command-mode <<<--- DON'T DO THIS!!! Esc is good enough! Remap the Windows key or CapsLock to Esc if necessary.

http://www.nabble.com/example-editrc-td21152004.html

I'm grateful to Brian for that message, because it showed me how to get vi bindings in ghci. However, that jj line cost me at least a couple of hours! That's a lesson to myself not to blindly copy and paste without understanding what I'm copying and pasting.

*slaps self upside the head*


Now I can finish cleaning up my version of vicle and post it.

20090323

Using Glade and Gtk2Hs with Haskell on Debian Sid

I wanted to try this tutorial:

http://haskell.org/gtk2hs/docs/tutorial/glade/

For me, there were many difficulties. Actually, it seems that the problems were user error on my part, discovered after trying to repeat the process on a second computer. You need to install the dependencies:

apt-get install gtk2hs-doc libghc6-cairo-dev libghc6-gconf-dev libghc6-glade-dev libghc6-glib-dev libghc6-gnomevfs-dev libghc6-gstreamer-dev libghc6-gtk-dev libghc6-gtkglext-dev libghc6-soegtk-dev libghc6-sourceview-dev libghc6-svgcairo-dev

All of this works, except for:

E: Couldn't find package libghc6-sourceview-dev

Then I had to adjust my .hs file to match the contents of the XML file generated by Glade. For instance, I changed line 9 to read:

window <- xmlGetWidget xml castToWindow "HelloGTK2hs"

CORRECTION: This was my mistake. I typed "HelloGTK2hs" in the "name" field rather than the "window title" field. Be careful!

A note to myself: it might be wise to try a process a second time on another computer before writing a blog post!