Opened 7 months ago

Last modified 7 months ago

#1445 new enhancement

Support parameterised hash table type declarations

Reported by: evhan Owned by:
Priority: not urgent at all Milestone: someday
Component: scrutinizer Version: 5.0
Keywords: scrutiniser, srfi-69 Cc:
Estimated difficulty: medium

Description

As suggested by megane on chicken-hackers.

Support specifying the types of hash table keys and values:

(define t (the (hash-table fixnum symbol) ...))

(hash-table-ref t 'foo) ; warning "expected argument #2 of type `fixnum' but was given an argument of type `symbol'"

(hash-table-ref t 42) ; result would be known to be a symbol

And so on.

Attachments (3)

parameterized-struct-type-style-2.patch (5.7 KB) - added by megane 7 months ago.
example.scm (679 bytes) - added by megane 7 months ago.
parameterized-struct-type-version3-with-smashing.patch (7.6 KB) - added by megane 7 months ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 7 months ago by evhan

  • Component changed from unknown to scrutinizer
  • Estimated difficulty set to medium

Changed 7 months ago by megane

Changed 7 months ago by megane

comment:2 Changed 7 months ago by megane

Btw, I was not targeting specifically hash-tables, but general user defined types.


Here's an alternative patch.


This codes the parameters into a list in the third element,
(struct name (param ...)).


Some features of the matcher:


  • (struct foo #f) == (struct foo)


  • (struct foo (* ...)) is simplified into (struct foo)


  • (struct foo #f) matches with (struct foo any-list)


  • If A and B are lists, then (struct foo A) and (struct foo B) only match if (= (length A) (length B)) and all the elements of A and B match.


For example, giving (struct foo (a)) where (struct foo (* b)) is
expected causes a type warning.

comment:3 Changed 7 months ago by megane

Here's another prototype.

These stay same:

  • (struct foo #f) == (struct foo)
  • (struct foo #f) matches with (struct foo any-list)
  • If A and B are lists, then (struct foo A) and (struct foo B) only match if (= (length A) (length B)) and all the elements of A and B match.


New things

  • does not simplify (struct foo (* * ...))
  • smashes (struct foo (A B ...)) into (struct foo (* * ...))

I think hash-table-set! cannot be #:clean. For example vector-set! is not. So you cannot get key/value related type warnings from setters, unless -strict-types is used.

Note: See TracTickets for help on using tickets.