racket / racket/typed-racket

"Nothing" as produced by intersection types does not always propagate outwards

Open
#552 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Racket
Stars
575
Forks
106
Avg merge
2h 1m
Merged PRs (30d)
2

Description

@pnwamk You seem to be on a bugfix spree concerning intersection type, thanks a lot 😄 ! Here's another one (which fortunately already has a simple workaround).

What version of Racket are you using?

6.9.0.4

What program did you run?
#lang typed/racket
(define-type τ1 (U (Pairof (∩ Integer String) Any)
                  'other))
;; (:type τ1)
;; ⇒ (U (Pairof Nothing Any) 'other)
;; But should be simplified to:
;; ⇒ 'other

Currently, a trick to achieve the desired result is to re-intersect with a polymorphic type variable, instantiated in a way that does not change the final type:

#lang typed/racket
(define-type (τ2 A) (U (∩ (Pairof (∩ Integer String) Any) A)
                       'other))

(define-type τ2-cleaned (τ2 (Pairof Integer Any)))
;; (:type τ2-cleaned)
;; ⇒ 'other

Literally writing an empty intersection usually does not make much sense. The bug is more noticeable when using intersections to "select" parts of a type:

#lang typed/racket
(define-type (τ3 Select) (U (Pairof (∩ 'foo Select) Integer)
                            (Pairof (∩ 'bar Select) String)))

;; (:type (τ3 'foo))
;; ⇒ (U (Pairof 'foo Integer) (Pairof Nothing String))
;; But should be simplified to:
;; ⇒ (Pairof 'foo Integer)

;; (:type (τ3 'bar))
;; ⇒ (U (Pairof 'bar String) (Pairof Nothing Integer))
;; But should be simplified to:
;; ⇒ (Pairof 'bar String)

The same workaround/trick can be applied in this case too:

#lang typed/racket
(define-type (τ4 Select A) (U (∩ (Pairof (∩ 'foo Select) Integer) A)
                              (∩ (Pairof (∩ 'bar Select) String) A)))
;; (:type (τ4 'foo (Pairof Symbol Any)))
;; ⇒ (Pairof 'foo Integer)
;; (:type (τ4 'foo (Pairof Symbol Any)))
;; ⇒ (Pairof 'bar String)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no source files or tests; start by running its three Typed Racket reproductions and tracing how intersection types containing Nothing are simplified through pairs and unions. Done means the shown :type results reduce to the expected types, including the 'other and selected-pair cases.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.