标准机器学习:如何在函数内执行另一个函数?
目前,我的代码如下所示:
fun gradImage () =
let val iImg = Gdimage.image(640,480) (0,0,0);
val void = mapi gradient iImg;
in
Gdimage.toPng iImg "gradient.png"
end;
mapi 是一个类型为 intint->intint*int->image->unit 的函数。本质上它对提供的图像进行操作。
该函数看起来很难看 val void = ...
我怎样才能消除它?
Currently, my code looks like this:
fun gradImage () =
let val iImg = Gdimage.image(640,480) (0,0,0);
val void = mapi gradient iImg;
in
Gdimage.toPng iImg "gradient.png"
end;
mapi is a function with type intint->intint*int->image->unit. Essentially it operates on the image supplied.
The function looks ugly with val void = ...
How could I eliminate that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在
let
表达式中的in
和end
之间拥有一个表达式列表。因此,您可以将代码重写为我假设
mapi
修改了iImg
,因为代码似乎是这样编写的。这听起来不太实用;让mapi
返回修改后的image
会感觉更自然,但从我对 Gdimage 接口的了解来看,它看起来像是在那里完成的,我理解它是从效率的角度来看可能更好。You can have a list of expressions between
in
andend
in alet
expression. So you could rewrite your code toI assume
mapi
modifiesiImg
in place, as the code seems to be written that way. That doesn't sound very functional; it would feel more natural to havemapi
return the modifiedimage
, but from what I can see of the Gdimage interface, it looks like how it's done there, and I understand it's probably better from efficiency perspective.我使用 SML 已有十年了,但我相信您正在寻找的是:
It's been a decade since I've used SML, but I believe what you're looking for is this:
实际上,我更喜欢提供的额外类型检查。
如果这看起来很难看,它应该是这样的——它不是很实用,而标准 ML 绝对是一种函数式语言。
I actually prefer the additional type-checking offered by
If this looks ugly, it should—it's not very functional, and Standard ML is definitely a functional language.