检查和比较两个球拍合同? [英] checking and comparing two Racket contracts?

查看:26
本文介绍了检查和比较两个球拍合同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法比较它们?例如,这不起作用:

Is there a way to compare them? This doesn't work for instance:

(equal? (flat-contract integer?) (flat-contract integer?))

推荐答案

  1. 首先,请注意 flat-contract 函数是为了向后兼容,所以你可能不应该使用它.来自文档:

  1. First of all, note that the function flat-contract is for backward-compatibility, so you probably should not use it. From the documentation:

这个函数是可以使用谓词之前的保留直接作为平面合同.它的存在是为了倒退兼容性.

This function is a holdover from before predicates could be used directly as flat contracts. It exists today for backwards compatibility.

  • 所以你的问题实际上是问两个谓词是否相同.一般来说,由于暂停问题,这个问题是不可判定的.但是,就您的目的而言,您或许可以避免引用平等.

  • So your question is really to ask if two predicates are the same or not. In general this problem is undecidable due to the halting problem. However, for your purpose, you might be able to get away with referential equality.

    > ;; both are in the same memory address
      (eq? integer? integer?) 
    #t
    > ;; obviously not in the same memory address
      (eq? integer? real?)
    #f
    

    请注意其警告

    > ;; although they look the same syntactically, 
      ;; the function objects are in different memory address
      (eq? (lambda (x) x) (lambda (x) x))
    #f
    > (define x (lambda (x) x))
    > (define y x)
    > ;; both are in the same memory address
      (eq? x y)
    #t
    > ;; flat-contract creates a function in a new memory address
      (eq? (flat-contract integer?) (flat-contract integer?))
    #f
    

  • 这篇关于检查和比较两个球拍合同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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