ml

    0热度

    1回答

    如何将下面的ML代码转换为尾递归函数?我盯着它,试图弄清楚几个小时,我看不出如何。 datatype Tree = NULL | NODE of Tree*Tree | VAL of int; fun dup(NULL) = NULL | dup(VAL(y)) = NODE(VAL(y),VAL(y)) | dup(NODE(y1,y2)) = NODE(dup(y1), dup(y2))

    3热度

    2回答

    ML中可能允许ML中的变量有多种类型吗? 例如,如果我想树中的一个节点只是一个int或一个字符串。 Node of int * string 我试过这个,但它只是产生(int,string)的元组类型。我不希望它是一个元组,只是一个int或一个字符串。这是否允许?

    1热度

    1回答

    比方说,我有以下的树数据类型: datatype 'a tree = Empty | Node of 'a * 'a tree * 'a tree; val x = Node(10, Node(20, Empty, Empty), Node(30, Empty, Empty)); 这里,x是int类型树的变量。我想知道的是如何解析和评估树的不同部分只有变量x? 例如,在此功能: fun ad

    0热度

    1回答

    我建立一个功能: val recur = fn : string * int -> string; 它得到一个字符串,它的大小,并返回它扭转; 但有点不为我工作,我建的,任何人可以点我的问题,也许给一点修正: fun recur (s:string, sz:int) = if sz = 1 then substring(s,sz-1,sz-1) else substring(s,sz-1,sz

    1热度

    2回答

    没有使用大小写表达式(在类的下一节出现),我看不出为什么以下不做快速排序。它在某个地方进入循环,永远不会结束。 splitAt和append已经过测试,但这里是他们的代码。 fun append(xs, ys) = if null xs then ys else (hd xs) :: append(tl xs, ys) fun splitAt(xs : int list, x : int

    -3热度

    1回答

    我从概念上理解了所有这些,我只是希望了解如何在ML和Haskell中实现它们的一些代码示例。

    0热度

    1回答

    你能不能帮我下一个任务: 我应该有一个功能 fun eval (fn : (string * int) list -> expression -> int) 那得到一个元组列表(变量名,值)的表达式。该函数使用currying并返回表达式的评估值。它至少应该支持运营商+, -, *, /, %表示加,减,乘,整数除法和余 对于接下来的数据类型: datatype expression = Co

    0热度

    1回答

    这段代码有什么问题? fun expd s:string = if size(s) > 0 then true else false; 错误我收到: - fun exnd s:string = if size(s) > a then true else false; stdIn:657.1-837.8 Error: unbound variable or constructor: a Erro

    1热度

    2回答

    我注意到在SML中有两种定义函数的方法。例如,如果你把add函数,这是两个方面: val add = fn : int -> int -> int 第二个创建函数类型: fun add x y = x+y; fun add(x,y) = x+y; 与第一种方法创建函数类型 val add = fn : int * int -> int 这两种类型对于相同功能有什么区别?还有为什么有

    1热度

    1回答

    三叉树类型被定义为: datatype ’a tree = Leaf of ’a | Node of ’a tree * ’a tree * ’a tree 我需要修改功能映射&与foldl相匹配的三叉树... fun tree_map (f : ’a -> ’b) (t : ’a tree) : ’b tree = f,nil) = nil | map (f,x::xs) = f(x