我试图了解如何在 Haskell 中将函数转换为无点表示法。我看到了这个例子,但它比我要找的更复杂。我觉得我理解它背后的逻辑,但是当我尝试在代码中执行一些简单的示例时,我遇到了编译错误。我想尝试以无点风格编写此函数:
f x = 5 + 8/x
我重新排列为f x = (+) 5 $ (/) 8 x
所以,我认为它可能是这样的:
f = (+) 5 $ (/) 8
但是当我在 ghci 中运行它时,我会收到以下消息:
No instance for (Num (a0 -> a0))
arising from the literal `5' at Test.hs:3:9
Possible fix: add an instance declaration for (Num (a0 -> a0))
In the first argument of `(+)', namely `5'
In the first argument of `($)', namely `(+) 5'
In the expression: (+) 5 $ (/) 8
Failed, modules loaded: none.
我不明白“没有实例...”消息。我需要做什么才能以无点样式编写此函数?