我的目标是通过管道传递一些步骤ghci
从 bash 脚本运行,然后干净地退出。网上的评论says https://stackoverflow.com/a/8676361/15441 to use runhaskell
为了这。
这是command http://learnyouahaskell.com/input-and-output#randomness我正在尝试运行:
ghci> import System.Random
ghci> random (mkStdGen 100) :: (Int, StdGen)
预期结果类似于:
(-3633736515773289454,693699796 2103410263)
当我将其放入文件中时randomtest.hs
并执行它runhaskell
我收到以下错误:
randomtest.hs:3:1: error:
Invalid type signature: random (mkStdGen 100) :: ...
Should be of form <variable> :: <type>
看来我不能使用runhaskell
盲目执行的方法ghci
inputs.
现在解决这个问题的方法是向传递给的文件添加额外的命令runhaskell
:
main = do print (random (mkStdGen 100) :: (Int, StdGen))
我的目标是自动运行我正在使用的 haskell 课程的 ghci 工作。我希望能够从 bash 脚本运行 ghci 命令 - 以 ghci 期望的格式运行,并让它从 ghci (或运行它的任何程序)干净退出。
我的问题是:有没有办法编写 ghci 会话脚本?