Search code examples
haskellghciwinghci

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?


Solution

  • 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!