[plt-scheme] Typed Scheme and match with struct patterns

From: Paulo J. Matos (pocmatos at gmail.com)
Date: Mon Mar 23 22:09:43 EDT 2009

Hi all,

Even though I already submitted this as a bug (10153) I wonder if
someone has a workaround in the meantime:
Check the following program:
#lang typed-scheme

(require scheme/match)

(define-type-alias mytypes (U foobar foo bar))

(define-struct: foobar
  ((useless : Integer)))

(define-struct: foo
  ((name : Symbol)))

(define-struct: (bar foo)
  ((val : String)))

(: match-bug (mytypes -> Void))
(define (match-bug f)
  (match f
    ((struct foobar (i))
     (display i))
    ((struct foo _)
     (printf "Name : ~a\n" (foo-name f))
     (when (bar? f)
       (printf "Val : ~a\n" (bar-val f))))))

Running it returns:
typecheck: Wrong function argument type, expected foo, got mytypes for
argument 1 in: f

even though it is pretty obvious f in that case is a foo.

Besides, the following works so I guess the problem is in the
interaction between the struct pattern of match and typed-scheme:
#lang typed-scheme

(require scheme/match)

(define-struct: foo
  ((name : Symbol)))

(define-struct: (bar foo)
  ((val : String)))

(: match-bug (foo -> Void))
(define (match-bug f)
  (match f
    ((struct foo _)
     (printf "Name : ~a\n" (foo-name f))
     (when (bar? f)
       (printf "Val : ~a\n" (bar-val f))))))

Any suggestions for a workaround [besides dumping typed-scheme for this module]?

Cheers,

-- 
Paulo Jorge Matos - pocmatos at gmail.com
Webpage: http://www.personal.soton.ac.uk/pocm


Posted on the users mailing list.