chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] Correct type declarations for (call-with-... <thunk>) pr


From: Alaric Snell-Pym
Subject: [Chicken-users] Correct type declarations for (call-with-... <thunk>) procedures
Date: Sat, 15 Nov 2014 18:27:41 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20140704 Thunderbird/17.0.11

Hello folks!

I've been trying to get into the habit of putting type declarations on
everything I write in Chicken, to get the benefits of the lovely
scrutinizer: type checks, specialisations, etc!

I've also found that it's nice as documentation - I went around
switching various bits of Ugarit to use typed records, and kept finding
that some fields of structures were actually (or boolean ...), because
I'd forgotten some things were optional. But now that's clear in the
record definitions.

I can certainly recommend using typed records and (: ...)-ing all your
global definitions! It's being a worthwhile experience.

Anyway, I have a question, as I can't figure out how to type one of my
procedures.

It's a (call-with-... <thunk>) wrapper. Indeed, it's this:

(define (call-with-context-support global-rules thunk)
   (let ((top-level-context (parse-top-level-context global-rules)))
      (parameterize ((*context* top-level-context)) (thunk))))

So I typed it:

(: call-with-context-support (list (-> *) -> *))

However, I ran into trouble when I used it like so:

(define-values (dir-key dir-reused? files bytes)
 (call-with-context-support
    (vault-global-directory-rules vault)
    (lambda () (store-directory! vault fspath))))


(store-directory! ...) returns four values, and as
call-with-context-support tail-calls the thunk, that works in practice.
But the type checker doesn't like it, and complains that an anonymous
lambda called tmp<some number> expects four arguments but is called with
one!

So: What type should I give call-with-context-support to make it clear
that it returns whatever the thunk passed to it returns, multiple values
and all? I could figure out how to do it with forall if I knew how many
values to expect, but I want it to work for any number of arguments!

Ta,

ABS

-- 
Alaric Snell-Pym
http://www.snell-pym.org.uk/alaric/

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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