小编kks*_*kai的帖子

为什么可以优化尾递归Modulo Cons?

例如,这不是尾调用:

map _ [] = []
map f (x : xs) = f x : map f xs
Run Code Online (Sandbox Code Playgroud)

(:)数据构造函数保护的递归调用,因此它不会像其他语言中的等价物那样构建巨大的堆栈。它是这样工作的:

map (+1) (1 : 2 : 3 : [])
2 : map (+1) (2 : 3 : [])
2 : 3 : map (+1) (3 : [])
2 : 3 : 4 : map (+1) []
2 : 3 : 4 : []
Run Code Online (Sandbox Code Playgroud)

为什么不

map (+1) (1 : 2 : 3 : [])
2 : map (+1) (2 : …
Run Code Online (Sandbox Code Playgroud)

recursion haskell functional-programming lazy-evaluation tailrecursion-modulo-cons

6
推荐指数
1
解决办法
221
查看次数

_??_?_ Agda 标准库在哪里?

我在plfa读到这样一段代码。

import Relation.Binary.PropositionalEquality as Eq
open Eq using (_?_; refl; cong; sym)
open Eq.?-Reasoning using (begin_; _???_; _??_?_; _?)
Run Code Online (Sandbox Code Playgroud)

_??_?_不在命题平等中

The module Eq.?-Reasoning doesn't export the following: _??_?_
when scope checking the declaration
  open Eq.?-Reasoning using (begin_; _???_; _??_?_; _?)
Run Code Online (Sandbox Code Playgroud)

我只在Function.Related和 中找到它Relation.Binary.HeterogeneousEquality。怎么了?

agda

4
推荐指数
1
解决办法
186
查看次数