我正在尝试理解如何将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.
我不理解"No instance for..."的信息。我需要怎么做才能以点无形式编写此函数?
$
和.
运算符之间的区别感到困惑。这里有更多信息。 - hammar