【发布时间】:2014-06-19 14:24:12
【问题描述】:
如何将树转换为列表: 到目前为止,我有以下代码,但它给出了几个问题:
type 'a tree = Lf | Br of 'a * 'a tree * 'a tree;;
let rec elementRight xs = function
| LF ->false
| Br(m,t1,t2) -> if elementRight xs t1 = false then t1::xs else element xs t1;; //cannot find element
let rec elementLeft xs = function
| LF ->false
| Br(m,t1,t2) -> if elementLeft xs t2 = false then t2::xs else element xs t2 ;; //cannot find element
let rec element xs = function
| LF ->[]
| Br(m,t1,t2) -> xs::(elementRight xs t1)::(elementRight xs t2)::(elementLeft xs t1)::(elementLeft xs t2);;
【问题讨论】:
-
你能告诉我们什么问题吗?
-
问题 1. 在 t2::xs 和 t1::xs 上,预期的表达式是 bool 并且有 'a list 2. on element xs t2 ;;找不到元素
标签: recursion tree f# f#-interactive