Summary

Support parameterised hash table type declarations

Metadata

Attachments

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.

Changes and comments

[2018-02-19 06:40:24 UTC] evhan set difficulty to medium

[2018-02-19 06:40:24 UTC] evhan changed component from unknown to scrutinizer

[2018-02-19 07:17:18 UTC] megane attached parameterized-struct-type-style-2.patch (description=#f)

[2018-02-19 07:17:28 UTC] megane attached example.scm (description=#f)

[2018-02-19 07:18:12 UTC] megane wrote:

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.

[2018-02-22 20:46:21 UTC] megane wrote:

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.

[2018-02-22 20:46:43 UTC] megane attached parameterized-struct-type-version3-with-smashing.patch (description=#f)