【问题标题】:Standard ML binary tree datatype标准 ML 二叉树数据类型
【发布时间】:2011-12-20 15:55:32
【问题描述】:

我知道以前有人问过这个问题,但以前的问题中没有一个答案对我有用,所以我会尝试不同的方法。

我已经这样做了:

> datatype which = STRING of string | INT of int;
datatype which = INT of int | STRING of string
> datatype whichTree = Empty | Leaf of which | Node of whichTree*whichTree;
datatype whichTree = Empty | Leaf of which | Node of whichTree * whichTree

但是当我尝试构建一棵树时

> val mytree = Node(Leaf(which 2), Leaf(which 6));

我收到错误。

Error-Value or constructor (which) has not been declared   Found near
Node( Leaf(which(2)), Leaf(which(6)))
Error-Value or constructor (which) has not been declared   Found near
Node( Leaf(which(2)), Leaf(which(6)))
Static errors (pass2)

【问题讨论】:

    标签: binary-tree sml ml


    【解决方案1】:

    which 是数据类型的名称;它不是构造函数。相反,您必须按如下方式创建树:

    > val mytree = Node(Leaf(INT 2), Leaf(STRING "6"));
    

    【讨论】:

    • 啊,谢谢你的帮助。我想我还有很多东西要学 ML
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-03
    • 1970-01-01
    • 2015-10-19
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多