我有这个我不明白的功课问题。我不知道从哪里开始,或者这个问题的目的是什么,它应该做什么。如果有人能帮助我做得好,因为我是Haskell的新手。以下是问题:
identity x = x. Your definition must have the form identity = e
where e mentions *only* ap and proj and parentheses.
ap f g x = f x (g x)
proj x y = x
identity :: a -> a
identity =
以上identity
函数假设在给出输入后完成或执行的内容是什么?
谢谢!
答案 0 :(得分:4)
身份函数返回其输入不变,正如作业问题的规范identity x = x
所给出的那样。
答案 1 :(得分:0)
一种方法是identity = (ap proj proj)
。这使identity x = proj x (proj x)
这里(proj x)
是一个函数,但这并不重要,因为它被抛弃,给你平等identity x = proj x _ = x
。