Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I insert a backtick in GHCi?

I'm trying out Haskell in GHCi on Windows. In the tutorial I'm following, a function name is enclosed in backticks: x `mod` 7. However, I can't enter the character in GHCi.

The backtick character has ASCII value 096, but GHCI does not allow Alt + number to insert any character. Copying/pasting doesn't work either. What should I do?

like image 754
Martin Avatar asked Sep 26 '15 19:09

Martin


2 Answers

I don't know how send a backtick to ghci if your keyboard doesn't have it. But this little technical issue shouldn't stop you from trying out Haskell!

  • You can program in Haskell without backticks by using f a b instead of a `f` b. In your example, mod x 7.

  • You can set your keyboard layout to us-american for programming. While it takes some practice to find the keys with the wrong labels on the physical keyboard, it can be convenient to have [, ], { and } more accessible, and in your case, have the backtick at all.

  • You can paste the backtick from the clipboard. (Activate "quick-edit mode" and "paste mode" from the command window's settings, and then use the right mouse button to paste).

  • Maybe using a wrapper around the command window helps? I sometimes use Console2 and sometimes M-x shell in Emacs.

  • Maybe WinGHCi helps? It supports copy and paste, at least.

  • See Ørjan Johansen's answer for how to add a custom keybinding to ghci.

Good luck with Haskell!

like image 80
Toxaris Avatar answered Nov 02 '22 17:11

Toxaris


@Toxaris gave several suggestions in his answer, but in a comment he also mentioned the possibility of configuring GHCi's version of readline (which is called haskeline). And indead it allows custom keybindings. So I decided to test that out.

The documentation says to put the customizations in ~/.haskeline, which is not a Windows path, but it presumably translates to .haskeline in whatever directory System.Directory.getHomeDirectory returns. (vim can also edit that path directly on Windows, but I only realized that afterwards.) So I put the following in C:\Users\Ørjan\.haskeline:

bind: meta-' `

Now I can get ` in GHCi by pressing alt-' !

like image 6
Ørjan Johansen Avatar answered Nov 02 '22 19:11

Ørjan Johansen