How can I set my GHCi prompt to a lambda character on Windows? How can I set my GHCi prompt to a lambda character on Windows? windows windows

How can I set my GHCi prompt to a lambda character on Windows?


Using > chcp.com 65001 worked with GHCi but opening other text files with Vim after setting that encoding returned garbled text.

Add the following to your %USERPROFILE%\.ghci. Instead of changing the encoding, you can use the Unicode escaped lambda \x03BB:

:set prompt  "\x03BB: "

If %USERPROFILE%\.ghci does not exist, create it first before making the change.


This is actually quite a simple fix, just run the following command before starting GHCi:

> chcp.com 65001

This sets Window's encoding to the 65001 code page, which lets the λ get displayed properly:

enter image description here

This will also let a lot of other Unicode characters be displayed properly in cmd.exe and other Windows shells (such as Cygwin bash), but Windows' Unicode support is still not perfect, and some fonts don't support many of the characters. Luckily, λ happens to be a supported character so we can all have the classic GHCi prompt.


Using Răzvan Flavius Panda's answer, I decided to make a configuration file that had three flags for setting the prompt. The reason for this is prompt-cont is for GHCi versions >= 8.2.0, whereas prompt2 is for older GHCi versions.

I had a look at a short tutorial about configuring GHCi to try and find out where to put the configuration file. The site says that GHCi reads configuration files in the following order:

  1. ./.ghci (Local configuration file.)

  2. Depending on your OS:

    • *nix: $HOME/.ghc/ghci.conf
    • Windows: C:\Users\<name>\AppData\Roaming\ghc\ghci.conf
  3. $HOME/.ghci (Possibly *nix only; didn't work for me.)

I chose the second option.

C:\Users\Edwin\AppData\Roaming\ghc\ghci.conf:

:set prompt "\x03BB> ":set prompt2 "\x03BB| ":set prompt-cont "\x03BB| "

Explanation:

  • \x03BB stands for λ.
  • prompt is the main prompt. So it'll be "λ> ".
  • prompt2 is for a secondary prompt (I haven't seen it yet). So it'll be "λ| ".
  • prompt-cont is the same as prompt2, and is a replacement for prompt2 in GHCi 8.2.0.