【发布时间】:2018-07-28 12:37:51
【问题描述】:
我需要编写我自己的数据类型 - 和 anyTree,它们都有自己的类型。有了这些,我需要创建一个函数,它接受一个 int 和一个 anyTree 作为参数,它在树中搜索,如果值存在于树中则返回 true。类型必须是:everyTree -> int -> bool
到目前为止我有:
datatype either = ImAString of string | ImAnInt of int
datatype eitherTree = eLEAF of either | eINTERIOR of (either*eitherTree*eitherTree)
fun eitherSearch v1 (eLEAF((v2)) = if v1 = v2 then true
else false
| eitherSearch v1 (eINTERIOR(e1, et1, et2)) = if v1 = e1 then true
else if (eitherSearch v1 et1) = true
then true
else if (eitherSearch v1 et1) = true
then true else false
“技巧”似乎是将 ImAnInt / int 相互转换,以便我可以比较它们。谁有想法? 谢谢。
【问题讨论】:
标签: types tree pattern-matching sml smlnj