小编lui*_*oml的帖子

Haskell中的美元符号($)和id函数之间是否存在关系?

有一天我正在阅读关于Monad挑战的评论(我强烈推荐给Haskell的任何初学者,就像我一样),我最终在这个帖子中读到了这一点($) = id.

我不知道如何吓唬人,但许多编程语言的概念最好用小例子来说明,这些例子让人们说"哇".

例如,令人惊讶的是,Prolog中的append()可以从连接结果"向后"运行,以产生可以连接以生成它的所有列表.或者Haskell(>> =)中的monadic绑定运算符可以用join和fmap或($)= id来定义.

($) = id !?

<在Raskell/Ghci中尝试>

我现在明白为什么这是真的,但仍然......哇!感谢那!(......)

然后我检查了base-4.10.0.0代码,寻找的定义($)id,但就在我读这顶:

NOTA BENE: Do NOT use ($) anywhere in this module! The type of ($) is
slightly magical (it can return unlifted types), and it is wired in.
But, it is also *defined* in this module, with a non-magical type.
GHC gets terribly confused (and *hangs*) if you try to use ($) in this …

haskell

17
推荐指数
2
解决办法
582
查看次数

标签 统计

haskell ×1