SML 函数调用不会将参数解析为参数

发布于 2024-07-16 15:29:34 字数 633 浏览 5 评论 0原文

我在调用 SML 函数时遇到了似乎是优先级问题,替代:

fun substitute v new (typevar q) = ...

我从另一个函数调用它:

fun new_type_vars (typevar v) non_gens = 
  substitute v new_var() (typevar v)

但我得到一个错误:

C:/sml/type_checker.sml:22.48-23.44 Error: operator and operand don't agree [tycon mismatch]
  operator domain: type_exp
  operand:         unit -> string
  in expression:
    (substitute v) new_var

这似乎表明它正在尝试调用 (替代 v),然后使用参数 new_var 调用该调用的结果。

我尝试在整个事情周围添加括号,但这没有帮助,当我在像 (v new_var...) 这样的参数周围添加括号时,它认为 v 是一个函数应用程序new_var。 这个函数调用发生了什么?

I'm getting what seems to be a precedence issue in calling an SML function, substitute:

fun substitute v new (typevar q) = ...

And I am calling this from another function:

fun new_type_vars (typevar v) non_gens = 
  substitute v new_var() (typevar v)

But I get an error:

C:/sml/type_checker.sml:22.48-23.44 Error: operator and operand don't agree [tycon mismatch]
  operator domain: type_exp
  operand:         unit -> string
  in expression:
    (substitute v) new_var

Which seems to suggest that it's trying to call (substitute v), and then call the result of that call with argument new_var.

I've tried adding parentheses around the whole thing, but that doesn't help, and when I add parenthesis around the arguments like (v new_var...) it thinks that v is a function application on new_var. What's going on with this function call?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没企图 2024-07-23 15:29:34

您可能想更改

substitute v new_var() (typevar v)

substitute v (new_var()) (typevar v)

(布塔的回答解释了原因。)

You probably want to change

substitute v new_var() (typevar v)

to

substitute v (new_var()) (typevar v)

(boutta's answer explains why.)

沧笙踏歌 2024-07-23 15:29:34

我不明白一切,因为您没有给出不同操作和变量的所有类型。

但您遇到的一般问题是,正如您已经猜到的,SML 从左侧执行函数调用(并绑定变量)。 这里有一个例子:

fun f a:int b:int c:string = ...

f 因此是 int 类型的函数 -> 整数-> 字符串 -> ...并隐式添加括号 fun (((fa:int) b:int) c:int) = ...

这意味着您可以像这样使用它:

var f2 = f 3;

并且 f2 现在的类型为 int -> 字符串 -> ...

I don't understand everything, since you don't give all the types of the different operations and variables.

But the general problem you've got is as you already guessed, SML executes the function calls (and binds the variables) from the left side. Here an example:

fun f a:int b:int c:string = ...

f is thus a function of the type int -> int -> string -> ... and implicitly adds the parentheses fun (((f a:int) b:int) c:int) = ...

This means you can use it for example like this:

var f2 = f 3;

And f2 has now the type int -> string -> ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文