问题标签 [ml]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
101 浏览

ml - StandardML 97 定义

实际的标准 ML 规范是标准 ML的定义(修订版) ,在 MITPress 上仅提供印刷版。

是否提供电子格式(pdf、ps、ie)?

0 投票
1 回答
506 浏览

sml - 如何在 ML 编程语言中定义一种以上类型的树

好吧,我被要求做接下来的事情:

要定义一个可以包含 2 种不同类型的二叉树: ('a,'b) abtree,这些是要求:

  1. 任何内部顶点(不是叶子)必须是 'a 或 'b 类型,并且叶子没有值。
  2. 对于树中的每条路径,所有 'a 值必须出现在 'b 值之前:路径示例:

    /li>

而且我还需要定义另一棵树,就像上面描述的那样,但现在我也有了'c,在第二个要求中,它说对于每条路径,我的 a 值都出现在 'b 值和所有 'b 值之前出现在 'c 值之前。

首先,我不确定如何将二叉树定义为具有超过 1 种类型。我的意思是最简单的二叉树是:

还有我如何定义一棵树来满足这些要求。

任何帮助将不胜感激。

谢谢。


好的,非常感谢。所以你的意思是这样的:

这就是我在上面提到的 3 类型树的情况下所做的:

我对吗?

另外,叶子的要求是什么意思?那个说叶子应该没有价值的东西?

0 投票
1 回答
674 浏览

sml - SML/ML 中的 RPAREN EQALOP 和未绑定的变量和构造函数错误

说我有 2 个 CNF 逻辑短语 a,b 并且我的 distrib 函数应该返回 a|b (a OR b) 的 CNF 形式。

替换我的规则是:

以这种方式定义的道具:

功能:

好吧,我不知道函数本身是否正确,虽然我刚刚完成了所有基本选项和替换规则,但是现在当 EQALOP 出现在 distrib1 函数之后并且构造函数错误出现 distrib 函数时,我得到了上述错误.

为什么我会收到这些错误?我不确定,但也许我应该使用 let 而不是本地的,但是我怎样才能将它转换为 let 结构?

谢谢。

0 投票
1 回答
428 浏览

sml - ML 中的序列(有限和无限)

好的,

我有序列的下一个定义:

我需要实现下一个功能:

该函数获取一个谓词函数,该函数返回真或假、n(整数)和序列。

功能:

  1. 如果 n<=0 返回相同的序列。
  2. else 返回一个 seq,它的前 n 个元素是原始 seq 中谓词为它们返回 true 的前 n 个元素,其余的将是相同的。

例如,如果谓词是 (x mod 2),seq 是 1,2,3,4,5...,n 是 3,那么新的 seq 是 2,4,6,7,8,...

此外,我应该检查另外 2 个选项:

2.1) 如果 seq 是有限的并且少于 n 个元素,谓词为它们返回 true,那么新的 seq 将包含谓词为它们返回 true 的元素。

2.2) 如果 seq 是无限的并且少于 n 个元素的谓词为它们返回 true,那么新的 seq 将包含谓词为它们返回 true 的所有元素,并且当尝试获取下一个元素时,它将进入无限循环。

我目前的代码在逻辑上是在没有考虑 2.1 和 2.2 的情况下计划的(尽管我得到了错误并且可以找到原因?)

语法错误或剧烈变化..我不确定?

(另外,对于 2.1 和 2.2,我只需要检查是否得到 (Nil and n>0) 然后返回 Nil?)

提前感谢您的帮助。

0 投票
2 回答
1385 浏览

sml - 使用 ml-lex 构建词法分析器

我需要创建一个lexer绑定到标准输入流的新实例。
但是,当我输入

我收到一个我不明白的错误:

makeLexer是我的源代码中存在的函数名称)

0 投票
1 回答
958 浏览

lex - 在 ml-lex 中使用 yyleng 函数

有人可以帮助我使用 ml-lex 的 yyleng 功能。我如何使用它来显示分析器中最近匹配文本的长度

0 投票
2 回答
810 浏览

sml - firstElement::Middle::LastElement 正则表达式

如果我想检查输入以便立即获取最后一个元素,是否可以使用正则表达式:

有趣的 someFunction (firstElement::MiddleOfList::LastElement)

所以我可以得到最后一个元素

0 投票
1 回答
482 浏览

sml - Can I expand a typedef in SMLNJ?

So I was writing up some code in standard ML, and trying to compile it with smlnj. I got the following error:

Now, this looks like it should be a type match based on my cursory inspection of the types. I'm not going to tell you them since I want a general solution, not the bug in my code.

Is it possible to expand both types into the base datatypes so I can figure out how they differ? With all these typedefs floating around things get confusing, and digging through .sml files for all the definitions and writing the expansion on paper seems like a tedious solution.

I would love to say something like:

and figure out what the heck kind of expression might produce a valid fundec.

0 投票
1 回答
378 浏览

concurrency - Standard ML / CML wrong operator - operand error

I am trying to implement a concurrent list using CML extensions of Standard ML but i am running into errors that are probably to do with my being a newbie in Standard ML. I have implemented the clist as having an input and output channel and I store the list state in a loop. However my code does not compile and gives errors below

This is the signature file

Errors I am getting:

0 投票
2 回答
3586 浏览

sml - 摆脱以下小程序中的语法错误

语法错误是