gpt4 book ai didi

sml - 不带参数的函数声明

转载 作者:行者123 更新时间:2023-12-05 00:50:21 25 4
gpt4 key购买 nike

我如何在签名中声明一个不带参数的函数?

我只见过带有如下参数的函数签名:leq:item*item->bool我希望为这样的函数创建一个签名:

initBTree = E   (* where empty is of type tree *)

这不起作用:val initBTree:->tree

最佳答案

您可以创建一个以单位为参数的函数,如下所示:

fun initBTree () = E

然后这样调用它:

initBTree ()

有类型

fn : unit -> tree

如果 E 的类型为 tree

不过,这有点毫无意义。你不妨直接说E,或者如果你真的希望它被称为initBTree:

val initBTree = E

关于sml - 不带参数的函数声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14700245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com