chicken-hackers
[Top][All Lists]
Advanced

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

[Chicken-hackers] Make the struct type parameterized ?


From: megane
Subject: [Chicken-hackers] Make the struct type parameterized ?
Date: Sun, 18 Feb 2018 13:39:54 +0200
User-agent: mu4e 0.9.18; emacs 25.1.1

Hi everyone,

What do you think about this idea?

I had this idea yesterday that you could add parameters to the struct
type annotation. For example:

(struct hash-table fixnum symbol)

With this new syntax you could tweak the types.db a bit with entries like:

(hash-table-ref (forall (k v) (#(procedure #:clean #:enforce)
hash-table-ref ((struct hash-table k v) k #!optional (procedure () *))
v)))

(hash-table-set! (forall (k v) (#(procedure #:clean #:enforce)
hash-table-set! ((struct hash-table k v) k v) undefined)))

Now if you tried to compile code like this:
(: make-int-to-symbol (-> (struct hash-table fixnum symbol)))
(define (make-int-to-symbol)
(make-hash-table))

(hash-table-set! (make-int-to-symbol) 'foo 2)

You could get warnings like this:
Warning: at toplevel:
  (example.scm:5) in procedure call to `hash-table-set!', expected argument #2 
of type `fixnum' but was given an argument of type `symbol'

Warning: at toplevel:
  (example.scm:5) in procedure call to `hash-table-set!', expected argument #3 
of type `symbol' but was given an argument of type `fixnum'

Seems handy, doesn't it?

Now, what's missing is of course the implementation. This seems very
close to the (list T ...) and (vector T ...) case. That's why I thought
this could be possible at all. I made a quick proof-of-concept patch,
which you'll find attached. It's indeed mostly copy paste of the vector
and list cases.

There's at least the smashing missing.

The patch is for the 4.13.0 tarball.

Attachment: example.scm
Description: example

Attachment: parameterized-struct-type.patch
Description: patch


reply via email to

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