- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前被 IFPH 第 7 章中的一个问题困住了。
它是 练习 7.1.2 内容如下:
“sort
的一个定义是取 sort = foldr insert []
其中
insert x [] = [x]
insert x (y:ys) = if x <= y then x : y : ys else y : insert x ys
sort [3,4,2,1]
的急切和惰性求值缩减序列,解释它们的不同之处”
sort [3,4,2,1]
=> foldr insert [] [3,4,2,1]
=> insert 3 (foldr insert [] [4,2,1])
=> insert 3 (insert 4 (foldr insert [] [2,1]
=> insert 3 (insert 4 (insert 2 (foldr insert [] [1])))
=> insert 3 (insert 4 (insert 2 (insert 1 (foldr [] []))))
=> insert 3 (insert 4 (insert 2 (insert 1 [])))
=> insert 3 (insert 4 (insert 2 [1]))
=> insert 3 (insert 4 (1 : insert 2 []))
=> insert 3 (insert 4 (1 : [2]))
=> insert 3 (1 : insert 4 [2])
=> insert 3 (1 : 2 : insert 4 [])
=> insert 3 (1 : 2 : [4])
=> insert 3 [1,2,4]
=> 1 : insert 3 [2,4]
=> 1 : 2 : insert 2 : [4]
=> 1 : 2 : 3 : [4]
=> [1,2,3,4]
最佳答案
在包含的行上
insert 3 (1 : insert 4 [2])
insert
的第二个参数。你可以运行计算,给出下一行
if 3 <= 1 then 3 : 1 : insert 4 [2] else 1 : insert 3 (insert 4 [2])
1 : insert 3 (insert 4 [2]) -- (LAZY)
insert 3 (1 : 2 : insert 4 []) -- (EAGER)
1
在对列表的其余部分进行排序之前 - 与急切评估形成对比,后者在找出第一个元素是什么之前对列表的几乎整个尾部进行排序。
关于Haskell:插入排序的惰性求值与急切求值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10681507/
我有一个案例,在大多数情况下,对象之间的关系是这样的,因此在关系上预先配置一个渴望(加入)的负载是有意义的。但是现在我遇到了一种情况,我真的不想完成急切的加载。 我是否应该从关系中删除连接负载并将所有
在我的 Grails 项目中,我有以下类: class A { static hasMany = [cs:C] } class B { static hasMany = [cs:C]
想象一下以下简化的 DI 模型: @ApplicationScoped public class A { private B b; @Inject public A(B b)
我使用 MapLoader 将数据从数据存储初始加载到 Hazelcast (InitialLoadMode = EAGER)。我需要从一个物化 View 中加载这些数据,该 View 是为了在加载过
我使用 Hibernate Envers 4.3.10.Final。我有以下两个 JPA 类: public class Factory { private int factoryID;
EJB 似乎被延迟加载 - 每当访问时。 但是,我想急切地初始化它们 - 即每当容器启动时。这是如何实现的(尤其是在 JBoss 中) This topic给出了一些提示,但不是很令人满意。 最佳答案
我是一名优秀的程序员,十分优秀!