ML语法函数程序 [英] ML syntax function program

查看:365
本文介绍了ML语法函数程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的函数foo,其类型为

What could be the possible function foo, which has a type

’a * ’a -> int

即具有以下类型输出的函数

in ML. i.e. a function which has the following type of the output

推荐答案

这似乎是作业,所以我给你一个部分解决方案,一些提示。你想要的类型是'a *'a - > int ,所以一个合适的函数的骨架可能是这样的(我假设你使用标准ML):

This seems to be homework, so I give you a partial solution and some hints only. The type you want is a 'a * 'a -> int, so the skeleton of a suitable function could be something like this (I assume you are using Standard ML):

fun foo(x, y) = ???

??? 需求:它必须包含一个强制 x y 具有相同类型的表达式,并且必须返回一个整数。后者不应该是硬的。对于前者,在SML中有很多可能性,例如,将它们放在同一个列表中,或者如果或从相同的 case 句柄

The ??? needs to meet two requirements: it must contain an expression that forces x and y to have the same type, and it must return an integer. The latter shouldn't be hard. For the former, there are many possibilities in SML, e.g., putting them in the same list, or returning them from the branches of the same if or case or handle.

这篇关于ML语法函数程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆