Skip to content

Intersection type example not typechecking, but it (probably?) should #1190

@rfindler

Description

@rfindler
Member

This program:

#lang typed/racket
(: g (∩ (-> Integer Integer)
        (-> Boolean Boolean)))
(define (g x)
  (if (exact-integer? x)
      5
      #f))

produces this error:

Welcome to DrRacket, version 8.3.900 [cs].
Language: typed/racket, with debugging; memory limit: 128 MB.
. Type Checker: type mismatch
  expected: (∩ (-> Boolean Boolean) (-> Integer Integer))
  given: (-> Any (U False Positive-Byte) : Integer) in: (define (g x) (if (exact-integer? x) 5 #f))

but it seems like, if the rule for intersection types is this,

 e : τ1      e : τ2
 ------------------
   e : τ1 ∩ τ2

then it should, because these two programs both type check:

#lang typed/racket
(: g (-> Integer Integer))
(define (g x)
  (if (exact-integer? x)
      5
      #f))
#lang typed/racket
(: g (-> Boolean Boolean))
(define (g x)
  (if (exact-integer? x)
      5
      #f))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @rfindler@capfredf

        Issue actions

          Intersection type example not typechecking, but it (probably?) should · Issue #1190 · racket/typed-racket