Miscellaneous

Table of Contents

  • Index
  • Repository
  • 1 Miscellaneous

    1.1 Haskell IDEs and Text Editors

    1.2 GHCI configuration file

    The ghci configuration file allows the user to create custom commands and customize the ghci shell. The file is in the directory ~/.ghci in Unix systems like Linux and OSX.

    Example: ~/.ghci

    import System.Directory ( getCurrentDirectory)
    import System.Process (readProcess)
    
    :set -hide-package mtl
    
    :set prompt "\x1b[32m>\x1b[0m " -- set the shell prompt to print λ (lambda)
    
    :def hoogle \s -> return $ ":! hoogle --count=15 \"" ++ s ++ "\""
    
    let xclip_ =  readProcess "xclip" ["-o", "-selection", "clipboard"] ""
    
    let __savePasted = do {  code <-  readProcess "xclip" ["-o", "-selection", "clipboard"] ""  ;  putStrLn 
    
    code ; writeFile "/tmp/haskTemp.hs" code}
    
    let pwd = getCurrentDirectory >>= putStrLn
    
    :def paste (\_ -> __savePasted >> return ":load /tmp/haskTemp.hs" )
    :def pwd (\_ -> pwd >> return "")
    

    It requires hoogle to be installed on Linux: (sudo apt-get install hoogle) on Ubuntu.

    Examples:

    :paste - Paste code block in clipboard and compiles it in ghci
    :pwd   - Show Current Directory
    
    > :pwd
    /home/tux/PycharmProjects/Haskell
    > 
    > 
    
    > :hoogle getCurrentDirectory
    Directory getCurrentDirectory :: IO FilePath
    System.Directory getCurrentDirectory :: IO FilePath
    > 
    
    
    > :paste
    import Data.Time.Clock
    import Data.Time.Calendar
    import Data.Time.LocalTime
    
    main = do
        now <- getCurrentTime
        timezone <- getCurrentTimeZone
        let zoneNow = utcToLocalTime timezone now
        let (year, month, day) = toGregorian $ localDay zoneNow
        putStrLn $ "Year: " ++ show year
        putStrLn $ "Month: " ++ show month
        putStrLn $ "Day: " ++ show day
    [1 of 1] Compiling Main             ( /tmp/haskTemp.hs, interpreted )
    Ok, modules loaded: Main.
    > 
    > main
    Year: 2015
    Month: 4
    Day: 26
    >
    

    1.3 Troubleshooting

    1.3.1 Importing Ambigous Modules in GHCi

    > import Control.Monad.State
    
    <no location info>:
        Ambiguous module name `Control.Monad.State':
          it was found in multiple packages: monads-tf-0.1.0.2 mtl-2.2.1
    > 
    
    > :set -hide-package mtl
    > import Control.Monad.State
    >
    

    Solution: Add the line to ~/.ghci

    :set -hide-package mtl
    

    Author: nobody

    Created: 2018-05-07 Mon 10:12

    Emacs 25.3.1 (Org mode 8.2.10)

    Validate