SML程序中的声明是如何分离的?

SML程序中的声明是如何分离的?,sml,ml,Sml,Ml,在 节目 prog ::= dec core declaration functor fctbind functor declaration signature sigbind signature declaration empty prog1 ⟨;⟩ prog2 sequence fctbind ::= id1 ( id2 : sig ) ⟨:⟨>⟩ sig⟩ = str ⟨and fctbin

节目

prog ::=   dec core declaration
           functor fctbind functor declaration
           signature sigbind signature declaration
           empty
           prog1 ⟨;⟩ prog2 sequence

fctbind ::= id1 ( id2 : sig ) ⟨:⟨>⟩ sig⟩ = str ⟨and fctbind⟩    plain
id ( spec ) ⟨:⟨>⟩ sig⟩ = str ⟨and fctbind⟩ opened
sigbind    ::= id = sig ⟨and sigbind⟩ signature
为什么

a
b
之间有错误,但两个val声明之间没有错误

$sml < main.sml
Standard ML of New Jersey v110.78 [built: Thu Aug 31 03:45:42 2017]
- val a = 1 : int
val b = 2 : int
= stdIn:4.1-5.2 Error: operator is not a function [tycon mismatch]
  operator: int
  in expression:
    a b
$sml
谢谢。

val a=1
val b=2
您所做的只是绑定两个变量,对应于规则
dec::=val⟨变量⟩(,)valbind
dec::=dec1⟨;⟩ dec2
,在顶层,
prog::=dec

然后在

a
B
实际上,您正在尝试将
a
应用于
b
exp:=exp1 exp2(应用程序)
)。将其视为等效编写的代码可能更简单

ab
但是,
a
没有函数类型,因此错误
运算符不是函数。现在还不清楚你到底想用
a
b
做什么

$sml < main.sml
Standard ML of New Jersey v110.78 [built: Thu Aug 31 03:45:42 2017]
- val a = 1 : int
val b = 2 : int
= stdIn:4.1-5.2 Error: operator is not a function [tycon mismatch]
  operator: int
  in expression:
    a b