首页 > 解决方案 > 当使用 -F -pgmF 调用时,给 Haskell 自定义预处理器的前两个参数有什么区别?

问题描述

来自GHC 8.6.5 用户指南 $10.11.3

使用 -pgmF cmd 选择要用作预处理器的程序。调用时,cmd 预处理器在其命令行上至少有三个参数:第一个参数是原始源文件的名称,第二个是保存输入的文件的名称,第三个是名称cmd 应该将其输出写入的文件。

我试图编写一个示例预处理器,以查看传递给预处理器的三个参数之间的区别。

我有以下两个文件:

主文件

{-# OPTIONS_GHC -F -pgmF preprocess.sh #-}

预处理.sh

#!/bin/sh

echo $1 " -- the original source file"
echo $2 " -- file holding the input"
echo $3 " -- the file where cmd should write its output to"

echo "{-# LINE 1 \"$2\" #-}\nmain = return ()" > $3

当我使用 编译 Haskell 文件ghc时,我得到以下输出:

Main.hs  -- the original source file
Main.hs  -- file holding the input
/tmp/ghc13496_0/ghc_1.hspp  -- the file where cmd should write its output to

前两个参数是否应该始终相同?在哪些情况下它们可以具有不同的值?

标签: haskellghc

解决方案


推荐阅读