Sml 在定义curry样式函数时,是否可以声明参数的类型?

Sml 在定义curry样式函数时,是否可以声明参数的类型?,sml,Sml,如果我使用元组样式参数定义函数,我可以定义参数类型和返回类型: fun hello(name:String, code:int):String = "hello!" 但如果我使用咖喱风格,我只能这样做: fun hello name code = "hello!" 是否可以为后面的类型添加参数类型或返回类型?确实可以: fun hello (name : string) (code : int) : string = "hello!" 但是,在标准ML中很少需要或使用类型注释,因此最常用的

如果我使用元组样式参数定义函数,我可以定义参数类型和返回类型:

fun hello(name:String, code:int):String = "hello!"
但如果我使用咖喱风格,我只能这样做:

fun hello name code = "hello!"
是否可以为后面的类型添加参数类型或返回类型?

确实可以:

fun hello (name : string) (code : int) : string = "hello!"

但是,在标准ML中很少需要或使用类型注释,因此最常用的方法是省略它们。

如果不使用函数,另一种方法是指定完整的函数类型,即la Haskell

val hello : string * int -> string = 
  fn (name, code) => "hello!"
您也可以使用递归函数来实现这一点

val rec hello : string * int -> string = 
  fn (name, code) => hello ("hello!", 5)
未载波函数有点混乱,尽管类型描述仍然更好

val hello : name -> int -> string = 
  fn name => fn code => "hello!"

或者,可以在后面使用
val\uu=hello:string*int->string