Types 在标准ML中搜索BST
要求很简单-给定一个根节点和一个要查找的整数,返回值是否在树中 以下是数据结构:Types 在标准ML中搜索BST,types,binary-search-tree,sml,Types,Binary Search Tree,Sml,要求很简单-给定一个根节点和一个要查找的整数,返回值是否在树中 以下是数据结构: datatype either = ImAString of string | ImAnInt of int; datatype eitherTree = Internal of {data: either, left: eitherTree, right: eitherTree} | Leaf of either 以下是树结构: datatype either = I
datatype either = ImAString of string | ImAnInt of int;
datatype eitherTree =
Internal of {data: either, left: eitherTree, right: eitherTree}
| Leaf of either
以下是树结构:
datatype either = ImAString of string | ImAnInt of int;
datatype eitherTree =
Internal of {data: either, left: eitherTree, right: eitherTree}
| Leaf of either
到目前为止,我的职能是:
fun eitherSearch (Leaf (ImAnInt i)) find =
if i = find then true else false
| eitherSearch (Internal {left, right, (ImAnInt i)}) find =
....
我已经单独测试了第一个子句,类型提取似乎有效
很好,但是当我试图从第二个子句中提取(ImAnInt I)时,我得到了一个错误
有什么想法吗?看起来您的记录模式匹配语法有点不正确
| eitherSearch(内部{data=x,left=left,right=right})查找
看起来您的记录模式匹配语法有点不正确| eitherSearch(内部{data=x,left=left,right=right})查找