【问题标题】:haskell---Command Line Argument File Passinghaskell---命令行参数文件传递
【发布时间】:2014-08-08 16:56:25
【问题描述】:

我对 Haskell 还很陌生,目前正在做一份暑期作业。我正在尝试将测试文件作为 ghci 命令行中的参数传递到我的 .hs 中。有人可以详细说明这应该如何发生吗?下面是我的 .hs 中的开始代码块,它使用 getArgs 和 readFile 来读取文件并从数据中创建一个元组。

    import Prelude
    import System.Environment ( getArgs )
    import Data.List
    import Helpers

    -- The main method that will be used for testing / command line access
    main = do
    args <- getArgs
    filename <- readFile (head args)
    checkersState <- readonemoveFile filename

当我 :load this .hs 时,我是否将文件作为参数添加到它后面?如:

    :load csce322a03p01.hs test01.onemove

我认为不会,因为这会给我一个错误:

    target `test01.onemove' is not a module name or a source file

【问题讨论】:

    标签: haskell ghci


    【解决方案1】:

    最初只加载模块文件:

    ghci> :l fileName.hs
    

    然后像这样传递参数:

    ghci> :main arg1 arg2
    

    【讨论】:

      猜你喜欢
      • 2016-03-25
      • 2017-12-18
      • 2011-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-08
      相关资源
      最近更新 更多