我的意思是这样的:
echo 'main = print 1' | ghc > executable
Run Code Online (Sandbox Code Playgroud)
GHC回复: ghc: no input files
我错过了什么吗?这有可能吗?
据我所知,答案是否定的.我的尝试:
$ echo 'main = print 1' | ghc
ghc: no input files
$ echo 'main = print 1' | ghc -
ghc: unrecognised flag: -
$ echo 'main = print 1' | ghc /dev/stdin
target ‘/dev/stdin’ is not a module name or a source file
$ ln -s /dev/stdin stdin.hs; echo 'main = print 1' | ghc stdin.hs
stdin.hs: hFileSize: inappropriate type (not a regular file)
问题:光耀使用后缀像.hs,.lhs或.o以决定如何处理的一个文件(这就是为什么#3失败).即使你讨厌它(#4),ghc真的希望stat()文件获得它的大小,这在管道上失败了.
尽管这对于正常的进程替换是不可能的,但 zsh 提供了一种特殊的类似进程替换的行为,它允许“文件”比传统的进程替换更像一个真实的文件(通过创建一个实际的临时文件) :
% ghc -o Main -x hs =( echo 'main = print 1' )
[1 of 1] Compiling Main ( /tmp/zshjlS99o, /tmp/zshjlS99o.o )
Linking Main ...
% ./Main
1
%
Run Code Online (Sandbox Code Playgroud)
该-x hs选项告诉ghc像给定的文件名以.hs.
总的来说,这本质上是手动创建和删除临时文件的快捷方式。
我不确定是否有其他 shell 支持这种事情。我不认为 bash 至少。
| 归档时间: |
|
| 查看次数: |
405 次 |
| 最近记录: |