sml

    2热度

    1回答

    比方说,我有以下数据类型 datatype mytype = Foo | Bar | Baz ,并希望写像下面 fun myfun ((Foo|Bar), (Foo|Bar)) = something | myfun (Baz, _) = somethingelse | ... 的功能有没有一种方法来创建模式Foo|Bar一个别名,这样我可以写它出来一次,避免重复自己?

    0热度

    2回答

    我是SML的新手。我写了一个函数,它接受2个int和一个元组列表作为输入。 fun move(x,y,mylist:(int * int)list): NOxNO = let val counter = ref y-1 in if y=1 then (x,y) else ( while !counter > 0 do (

    4热度

    2回答

    霍纳规则用于简化在特定变量值下评估多项式的​​过程。 https://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation#Standard_ML 我容易地应用于使用SML的方法中,到一个变量多项式,表示为int列表: fun horner coeffList x = foldr (fn (a, b) => a + b * x

    1热度

    2回答

    我有以下两个“功能”:is_three和SOME fun is_three(number) = case numbers of 3 => true | _ => false 当我在下面的两个语句写我得到这个: is_three; val it = fn : int -> bool SOME; val it = fn : 'a -> 'a option

    0热度

    2回答

    SML中是否有一个运算符,它允许我追加到列表而无需创建新列表?例如 我不能做到这一点: [1,2,3]::1 ,但我可以这样做: [1,2,3]@[1] 这是奇怪的,因为我必须创建一个有1名单。有没有更好的方法来做到这一点?

    0热度

    1回答

    如何拥有多个不相互交错的陈述陈述? 例如玩具例子: fun multi_cases(xs) = case xs of [] => 5 | x::ys => case x of 1 => 2 |_ => 3 | x::[] => case x of 1 => 5 | _ => 7

    -1热度

    1回答

    我已经在SML中编写了下面的代码,但遇到了编译错误。 fun getTransIndex(t : TRANSACTION, (h::L) : TRANSLIST) : int = let val i=0 in if (h=t) then i else if (getTransIndex(t,L)<>~1 then getTransIndex(

    0热度

    1回答

    鉴于这些声明我有在SML无法理解流牵引件: exception Bad of string; fun from seed next = Cons(seed,fn() => from (next seed) next); fun head (Nil) = raise Bad("got nil in head") | head (Cons(a,b)) = a; fun tail (N

    -1热度

    2回答

    我试图通过一个数据类型,SET,包含其他数据类型,包括本身,并打印出使用循环函数,循环这些数据类型。 fun printEXP(SET(hd::tl::[])) = let fun loop (hd::tl) = printEXP(hd):: loop tl | loop [] = []; in() end; ... 我得到tycon不匹配错误,我不知道如何解

    2热度

    1回答

    datatype 'a stream = Nil | Cons of 'a * (unit -> 'a stream); exception Bad of string; fun from seed next = Cons (seed, fn() => from (next seed) next); fun head (Nil) = raise Bad "got n