【问题标题】:/bin/sh: 1: ./respondPalindromes: not found - What does this mean?/bin/sh: 1: ./respondPalindromes: not found - 这是什么意思?
【发布时间】:2012-08-07 00:50:54
【问题描述】:

我可以在 respondPalindromes.hs 文件中的终端中运行下面的代码,但在 emacs 中测试失败。

respondPalindromes = unlines 。 map (\xs -> if isPalindrome xs then "palindrome" else "not a palindrome") 。线路
其中 isPalindrome xs = xs == 反向 xs
main = 交互响应回文

以下是终端详情:

optimight@optimight:~$ cat words.txt | runhaskell respondPalindromes.hs
不是回文
回文
回文
回文

以下是 Emacs haskell 模式的详细信息:

*Main> :load "/home/optimight/respondPalindromes.hs"
[1 of 1] 编译 Main(/home/optimight/respondPalindromes.hs,解释)
好的,已加载模块:Main.
*主要> :!猫话.txt | ./respondPalindromes.hs
/bin/sh: 1: ./respondPalindromes.hs: 权限被拒绝
*主要> :!猫话.txt | ./respond回文
/bin/sh: 1: ./respondPalindromes: 未找到
*主>

根据 Dietrich Epp 的回答进行编辑:

*Main> !: cat words.txt | runhaskell respondPalindromes.hs
:12:1: 解析输入错误 `!:'

*Main> cat words.txt | runhaskell respondPalindromes.hs
:13:15: 输入 `|' 解析错误
*主>

【问题讨论】:

  • 在您的编辑中,您使用了runhaskell,但切换了!:。我认为应该是:! cat words.txt | runhaskell respondPalindromes.hs,而不是!: cat words.txt | runhaskell respondPalindromes.hs
  • 如果你想在没有runhaskell的情况下也能运行./respondPalindromes.hs,添加一个shebang行;也就是说,将行 #!/usr/bin/env runhaskell 添加为文件的第一行。

标签: haskell emacs haskell-platform haskell-mode


【解决方案1】:

在常规终端窗口中,运行以下命令:

cat words.txt | runhaskell respondPalindromes.hs

但在 Haskell 窗口中,您运行以下 shell 命令:

cat words.txt | ./respondPalindromes.hs

如果第一个命令运行良好,为什么还要运行不同的命令?

这些只是普通的 shell 命令。如果您还没有将respondPalindromes.hs 设置为可执行文件,则它不会作为可执行文件运行,您必须使用runhaskell 才能执行它。

此外,如果您以这种方式运行程序(通过从 Haskell 交互式 shell 中执行 shell 命令),那么使用花哨的 Haskell shell 毫无意义。你还不如使用普通的 shell。

相反,您可能希望完全避免使用 shell,例如:

readFile "words.txt" >>= respondPalindromes >>= putStr

Haskell 中的 >>= 运算符有点像 shell 中的 | 管道。

总结::!命令执行的是一个普通的shell命令,和Haskell没有任何关系。

【讨论】:

  • 我是一个绝对的 Haskell 初学者,只是通过 LYAH 中给出的说明,并且还尝试使用 emacs haskell-mode。
【解决方案2】:

我不知道haskell,但在命令行上你正在执行runhaskell respondPalindromes.hs,但在emacs 中你正在运行./respondPalindromes.hs

很确定这是问题所在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-31
    • 2020-08-11
    • 2019-05-03
    • 2018-06-06
    • 2021-10-20
    • 2019-09-11
    • 1970-01-01
    • 2023-04-06
    相关资源
    最近更新 更多