2016-08-19 27 views
4

我一直在嘗試使用Haskell來運行簡單的生產過程。像許多生產過程一樣,它涉及改變各地的狀態。出於這個原因,這將是非常方便的,讓我有一個腳本文件,在那裏我可以跟蹤的東西,有選擇地運行命令爲互動哈斯克爾,像Haskell/Intero - 將行發送到Intero REPL緩衝區

-- to start the process 
process <- startProcess 

-- to stop process 
stopProcess 

-- to check how things are going 
summary <- checkStuff 
summary 

-- optionally restart bad processes 
restartProcesses (getBadProcesses summary) 

-- send summary emails 
sendSummaryEmails summary ["[email protected]", "[email protected]", 
          "[email protected]" "[email protected]", 
          "[email protected]"] 

-- set up something big that I don't want to have to retype/paste every time 
studentGrades <- getStudentGrades "John Peterson" 
gen <- getStdGen 
let (randomTest, gen') = generateRandomTest studentGrades gen 
compilePdf randomTest 
answers <- getAnswers 
gradeTest randomTest answers "John Peterson" 

這將是,如果真的很酷,喜歡與ESS (Emacs講統計數據)在R中,如果你可以按下按鈕將這些行發送到repl進程。也許分隔線,段落,地區的按鈕。有沒有辦法做到這一點?

例如用ESS,C-Ret發送一行,C-c C-c發送一個段落,C-c C-r發送一個區域。

+0

什麼使您無法使用正確的命令和參數將文件加載到repl中?什麼讓你無法用合適的'main'函數編譯代碼? – MarLinn

+0

我不想一次全部運行這段代碼,我想根據當前的進程狀態選擇性地將其加載到repl中,並且通過一次按鍵('C-Ret')做到這一點是一個數量級與鍵入(10-60個擊鍵)相比性能提升,比emacs中的複製粘貼(約5個按鍵)效率高5倍。 –

+0

我也可能想要自定義如何在線運行這些線,因此將它們編碼爲單個命令,然後重新加載模塊的效率也低於僅更改腳本中的行並將其加載到緩衝區中的效率。 –

回答

1

此的Emacs Lisp功能將命令發送到Haskell的REPL

(defun haskell-send-command (cmd) 
    (process-send-string (inferior-haskell-process) (concat cmd "\n"))) 

,這將調用前一個與當前選擇

(defun haskell-send-selection() 
    (interactive) 
    (haskell-send-command (x-selection))) 

你可以用global-set-key分配的鍵盤快捷鍵。然後你需要弄清楚如何快速選擇你想發送的內容。例如M-h是標記段落。或者只是重新編碼你喜歡的ESS功能:

(defun haskell-send-paragraph() 
    (interactive) 
    (mark-paragraph) 
    (haskell-send-selection)) 

我實際使用那些建立在Emacs Haskell的一個小的調試GUI。我有設置斷點和步進的捷徑,調試器的位置直接在haskell代碼中突出顯示。

相關問題