8
votes

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?

2
Have an Italian keyboard, has a \ left of 1, sorryMartin
Well, one thing to note is that backticks are never necessary. x `mod` 7 is the same as mod x 7. Backticks are just a way to use a function in an infix manner. Also, these options don't sound particularly convenient, but here is some info on typing backticks on Italian keyboards: superuser.com/questions/598135/…David Young
I would guess that this is more a problem of keyboard layouts + terminal encoding and not so much with ghci itself.JustGage
Found WinGHCi after all, (it's not in the BIN map, so not on the PATH) and it works. @David Young: formulate the answer and I'll mark it as correctMartin

2 Answers

10
votes

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!

6
votes

@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-' !