[英]Leftmost-Innermost and Outermost (Haskell)
我必须显示Haskell需要计算多少步骤(两种方法-最左侧的最内层和最左侧的最外层)。 用于功能
minimum [7,4,2,8]
最小值定义为
minimum xs = head (isort xs)
因此,最里面的步骤是:
1. minimum [7,4,2,8]
2. head (isort [7,4,2,8])
3. head (isort [4,7,2,8])
4. head (isort [2,4,7,8])
5. head [2:4:7:8]
6. (The output) => 2
我对吗? 我看不到另一种解决方法..但是应该有一种..?
(对不起,英语不好。)
感谢帮助。
您(可能)忘记了
4. head (isort [2,4,7,8])
4.1 head (2 : isort [4,7,8])
4.2 head (2 : 4 : isort [7,8])
4.3 head (2 : 4 : 7 : isort [8])
4.4 head (2 : 4 : 7 : 8 : isort [])
4.4 head (2 : 4 : 7 : 8 : [])
(only now is head's argument a value)
5. 2
通过最外部的评估
4. head (isort [2,4,7,8])
4.1 head (2 : isort [4,7,8])
5 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.