我开始像这样在 Haskell 中写项目欧拉问题的答案
problem1 = ...
problem2 = ...
一起显示它们我一直在使用这样的东西
problems x = "print $ zip [1..] [" ++ intercalate "," (take x stringList) ++ "]"
where
stringList = map ("fromIntegral problem"++) stringInts
stringInts = map show [1..]
main = print $ zip [1..] [fromIntegral problem1,fromIntegral problem2,...] (copy-pasta from ghci'ing problems string)
有没有办法在不复制粘贴的情况下做到这一点?
我研究了用 m4 定义宏,但我无法将问题转换为问题 1。m4 也有中缀运算符反引号的问题,例如
x `mod` 3 == 0
所以我不得不将整个文档的其余部分包装在 m4 块注释中
我研究了定义 c 预处理器宏,但据我所知,不支持 for 循环(或根本不支持循环)
我希望有一种 Haskell 方法可以做到这一点