如何理解hylomorphism

時間 2021-07-14 06:48:07

1樓:knifefire

;; r5rs

;; tree:list (length tree) = 3

;; construct method :(list val left right)

;; empty tree = ()

(define (binmap f tree)

(if (null? tree) tree (list (car tree) (f (car (cdr tree))) (f (car (cddr tree))))))

(define (bincataT f) (lambda(t) (f (binmap (bincataT f) t))))

(define (bigger x y) (if (> x y) x y))

;;maybe faultful

(define (preheight x)

(cond

((null? x) 0)

(else (+ 1 (bigger (car (cdr x)) (car (cddr xdefine get-bst-height (bincataT preheight))

有點幼稚,不過畢竟是自己寫的,瓶中之舟是想寫ana,棄了

2樓:非構造性雨軒菌

newtype

Termf=

Intype

Algebrafa

=fa->

atype

Coalgebrafa

=a->fa

cata

::Functor

f=>Algebrafa

->Term

f->acata

alg=

out>>>

fmap

(cata

alg)

>>>algana

::Functor

f=>Coalgebrafa

->a->Term

fana

coalg=In

<<

(ana

coalg

)<<<

coalg

hylo

::Functor

f=>Algebrafb

->Coalgebrafa

->a->bhylo

algcoalg

=ana

coalg

>>>cata

alg就是先用anamorphism展開,然後再用catamorphism摺疊

如何理解 TCP IP, SPDY, WebSocket 三者之間的關係?

龍騰道默默地 TCP是基於IP IP是一種協議,不是IP位址 實現的,HTTP 1.1 SPDY WebSocket HTTP2.0是基於TCP實現的。IP 乙個底層網路定址協議。TCP 乙個相對可靠確保資訊送達 且按順序送達的中層資訊傳輸協議,效能相對於UDP較差。HTTP 1.1 上層網頁資訊傳...

如何理解functional programming裡的currying與partial application

李欣宜 定義乙個多參函式f arg1,arg2 argn 時,如果每個引數argi的型別為ti,這個多參函式最後的返回結果的型別為rtype,那麼可以說f的型別為 t1 t2 tn rtype 這是很多語言對於多參函式的解釋,把這些引數作為乙個tuple或者list傳入,即 t1 t2 tn 型別的...

如何理解 It make A one of Canada s most popular cities to live in ?

加拿大公共健康 這個語法有問題。It makes.A stands for a city s name. 首先,絕對是It makes.然後,回答題主的問題 1 正解 2 最高端要求有範圍的限定,所以平時一般看到的最高端都加定冠詞。但是Canada s已經是個範圍的限定,就不需要了,再舉幾個例子 o...