如何在racket中编写返回字符串或#f(false)的声明?
我在球拍中有以下功能:(
:search-stack:Symbol KeyStack -> String) (define (search-stack s stack)
该函数在堆栈中搜索特定字符串并返回匹配的符号。如果未找到该字符串,则该函数返回“#f”。如何修改返回类型以允许返回字符串或布尔类型(仅限 false)?
I have the following function in racket:
( : search-stack : Symbol KeyStack -> String)
(define (search-stack s stack)
This function searches the stack for a specific string and returns the matching symbol. If the string is not found, the function returns "#f". How do I modify the return type to allow for returning either a string or boolean type (false only)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑更简单的函数 match,它只检查一对(可以是
堆栈的一个元素)。使用签名(非正式类型作为注释),这可能是:
在类型化的racket中,在参数上带有类型注释,这就是:
现在只需在DrRacket交互中输入
match
即可面积和类型归纳将显示返回类型:
Consider the simpler function match, which just checks a pair (which could be
one element of a stack). With signature (informal type as a comment) this could be:
In typed-racket, with type annotations on the arguments, this is:
Now just type
match
into the DrRacket interactions area, and type inductionwill reveal the return type: