How can I send a haskell expression programmatically to the current current ghci session

I am working on the Haskell presentation engine Howerpoint . He works at GHCi. I would like to create a function that displays the statement in the current GHCi session. It should work on Linux and Mac, Windows is not required. The function will probably be of type

executeStatement :: String -> IO ()

I already tried:

  • getProcessIDand getParentProcessIDand then sending something like

    echo 'xxx' > /proc/92856/fd/1
    -bash: /proc/92856/fd/1: No such file or directory
    
  • I also tried runCommand, but it executes the command in Bash and not in GHCi, so I got an error that the command was not found

  • xdotool not working on mac

+4
source share
2 answers

ghcid . , , . :

import Language.Haskell.Ghcid

main :: IO ()
main = do 
    (g, _) <- startGhci "ghci" (Just ".") True 
    let executeStatement = exec g
    executeStatement "let x = 33"
    executeStatement "x + 8" >>= print . head
    executeStatement "print x" >>= print . head
    stopGhci g

"41" "33" g ghci.

ghci, - startGhci , , std_in, std_out std_err.

+2

, tmux, ghci , tmux, ghci.

tmux load-buffer tmux ( -, stdin).

# from within tmux
$ echo foo | tmux load-buffer -
$ tmux show-buffer
foo

tmux paste-buffer tmux :

$ tmux list-panes
0: [127x24] [history 1850/2000, 1343570 bytes] %0
1: [127x24] [history 0/2000, 0 bytes] %2 (active)
$ tmux paste-buffer -t %0

, , process, ghci, .

, process-streaming ( , ). stdin , stdout stderr :

{-# LANGUAGE OverloadedStrings #-}

import System.Process.Streaming -- from process-streaming
import Pipes (lift,yield) -- from pipes
import Control.Concurrent (threadDelay)

main :: IO ()
main = executeInteractive program (feedProducer (do
    let delay = lift (threadDelay (1000000*6))
    delay
    yield "4 + 3\n"
    delay
    yield "5 + 3\n"))
  where
    program = (shell "ghci"){ std_in = CreatePipe }

:

$ ./Main
GHCi, version 7.10.2: http://www.haskell.org/ghc/  :? for help
Prelude> 7
Prelude> 8
Prelude> Leaving GHCi.
+2

Source: https://habr.com/ru/post/1628244/


All Articles