【发布时间】:2019-12-18 17:32:51
【问题描述】:
我知道 show the function's body 是不可能的,因为 Haskell 进行了优化,但是否有可能以某种方式显示它的 名称?
我想要类似的东西
Prelude> f
[Function f]
类似于其他 REPL 的功能(Python、javascript 等)
我用 Haskell 得到的是
Prelude> f
<interactive>:2:1: error:
• No instance for (Show (Integer -> Integer)) arising from a use of ‘print’ (maybe you haven't applied a function to enough arguments?)
• In a stmt of an interactive GHCi command: print it
这对演示没有帮助。
【问题讨论】:
-
顺便说一句:如果您在前奏中输入
:i f或:t f,您会得到名称以及有关该功能的更多信息,这可能有助于您的事业吗? -
这就是我想展示的内容,在 ˋ5ˋ 上执行 ˋconst fˋ 会得到 ˋfˋ
-
它也会破坏引用透明度。因为在 Haskell 中,表达式与其计算结果之间应该没有功能上的差异。
-
@LukeCollins 出于演示目的,您可以使用具有
?src命令的lambdabot,请参阅this question。 -
函数没有名字。它们是值。变量有名字。 5的名字是什么?没有。
标签: haskell functional-programming ghc