[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] [PATCH][5] Change procedure argument type relation to

From: megane
Subject: [Chicken-hackers] [PATCH][5] Change procedure argument type relation to contravariant
Date: Fri, 30 Mar 2018 19:14:01 +0300
User-agent: mu4e 0.9.18; emacs 25.1.1

Hello again,

this fixes #1446 I reported earlier.

The patch applies after the other patch I posted today.

Here's a simple example showing the issue:

(define-type T (or string boolean))
(: foo ((T T -> any) T -> any))
(define (foo f a) (f a "foo"))

(: bar (string string -> any))
(define (bar a b)
  (string-length a))

(print (foo bar #t))

;; $ csc -O3 func-args.scm && ./func-args
;; Error: (string-length) bad argument type: #t
;;      Call history:
;;      func-args.scm:9: string-length          <--

Same example in Typed Racket:

#lang typed/racket
(define-type T (U String Boolean))
(: foo (-> (-> T T Any) T Any))
(define (foo f a) (f a "foo"))

(: bar (-> String String Any))
(define (bar a b)
  (string-length a))
(print (foo bar #t))

;; $ racket function-args.rkt
;; function-args.rkt:9:12: Type Checker: type mismatch
;;   expected: (-> T T Any)
;;   given: (-> String String Any)
;;   in: bar
;;   context...:
;;    /usr/share/racket/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:82:0: 
;;    /usr/share/racket/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:24:4


Attachment: procedure-argument-contravariance.patch
Description: patch

reply via email to

[Prev in Thread] Current Thread [Next in Thread]