小编sai*_*imn的帖子

Haskell多态树和

我编写了以下用于处理Haskell中的多态二叉树的代码,作为下周函数式编程考试的准备:

data ITree t = Leaf | Node t (ITree t) (ITree t) 
             deriving (Eq, Ord, Show)

treeSum :: ITree t -> Int
treeSum Leaf = 0
treeSum (Node n t1 t2) = n + (treeSum t1) + (treeSum t2)
Run Code Online (Sandbox Code Playgroud)

现在我遇到了问题,代码无法编译:

...\tree.hs:8:26:
Couldn't match type `t' with `Int'
  `t' is a rigid type variable bound by
      the type signature for treeSum :: ITree t -> Int
      at ...\tree.hs:7:1
In the first argument of `(+)', namely `n'
In the first argument …
Run Code Online (Sandbox Code Playgroud)

polymorphism tree haskell functional-programming sum

10
推荐指数
1
解决办法
1769
查看次数

系统如何选择正确的页面表?

让我们关注单处理器计算机系统.创建进程时,据我所知,页面表会被设置,将虚拟地址映射到物理内存地址空间.每个进程都有自己的页表,存储在内核地址空间中.但是MMU如何为流程选择正确的页面表,因为不仅有一个流程在运行,而且会发生许多上下文切换?

任何帮助表示赞赏!

最好,西蒙

x86 computer-science processor process computer-architecture

7
推荐指数
2
解决办法
3396
查看次数