Last active
December 5, 2023 00:19
-
-
Save chshersh/9111d97578413323ba1b191299c54235 to your computer and use it in GitHub Desktop.
Config for GHCi with pretty output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- To run: | |
-- cabal repl -b pretty-simple | |
-- | |
-- Colorizing and pretty-printing ghci output | |
-- requires: pretty-simple | |
:set -interactive-print=Text.Pretty.Simple.pPrint | |
-- green bold lambdas and multiline mode | |
:set prompt "\ESC[1;32mλ: \ESC[m" | |
:set prompt-cont "\ESC[1;32mλ| \ESC[m" | |
-- useful flags | |
:set -fprint-explicit-foralls | |
:set +m | |
-- useful extensions by default | |
:set -XTypeApplications -XKindSignatures | |
-- useful default imports | |
import Data.Kind (Type, Constraint) | |
-- helpful macros | |
:def package \ m -> return $ ":! ghc-pkg --simple-output find-module " ++ m | |
:def no-pretty \_ -> return (":set -interactive-print=System.IO.print") | |
:def rr \_ -> return ":script ~/.ghc/ghci.conf" |
Hi @AurevoirXavier, I no longer use this particular GHCi config. My new global GHCi config is much smaller. Also, I'm now using cabal
almost all the time for development instead of stack
. Cabal doesn't have such an issue, I can run cabal repl -b pretty-simple
from any place and any project and it will work automatically. I've updated this gist to reflect my latest config and not confuse people in the future 🙂
I found the problem. The :load
will drop pre define things something like ghciColor
.
pretty-simple
sounds like a good solution.
Here's my modification. It also works for stack, whatever you're under a stack project or not.
Thanks @chshersh
:def pretty \_ -> return (":set -interactive-print=Text.Pretty.Simple.pPrint")
:def no-pretty \_ -> return (":set -interactive-print System.IO.print")
:def package \m -> return $ ":! ghc-pkg --simple-output find-module " ++ m
:def rr \_ -> return ":script ~/.ghci"
:set prompt "\ESC[1;32mλ \ESC[m"
:set +m
:set +s
:set +t
:set -package pretty-simple
:set -fprint-explicit-foralls
:set -interactive-print=Text.Pretty.Simple.pPrint
:set -XTypeApplications -XKindSignatures
import Data.Kind (Type, Constraint)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can I use this in a project?
I have to specify the package.
stack ghci --package pretty-show --package hscolour --package heredoc
And I run
stack ghci
, it will be override.Loaded GHCi configuration from /tmp/haskell-stack-ghci/f00796c9/ghci-script