chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] permissive checking of sum types


From: Peter Bex
Subject: Re: [Chicken-users] permissive checking of sum types
Date: Sun, 3 Dec 2017 12:04:42 +0100
User-agent: NeoMutt/20170113 (1.7.2)

On Sat, Dec 02, 2017 at 08:56:52PM -0500, David Goffredo wrote:
> Hello everyone,
> 
> I've been playing around with Chicken for about a month now, and so far
> really enjoy it. Even got it building and (mostly) working on crusty old AIX
> and Solaris machines.

Hi David,

Cool!  That's very good to hear.

> I'm new to Scheme in general. My current project will involve some record
> types, and I'd like to use Chicken's type information as documentation and
> to catch simple programming mistakes.

Please be mindful that CHICKEN's type system accepts declared types as
gospel, which means you may run into issues when the types don't match
the declared types.  In other words, procedures should always check their
argument types.

> This is where I noticed something. I can compile, without producing any
> warnings, a program that passes a variable declared as "(or T U)" (where "U"
> and "T" are different) as an argument to a function whose argument at that
> position is declared as "T". I feel like this should be a type violation,
> since the input value could be a "T" or a "U", which is not a "T".
> 
> Is this a bug that I should look into fixing, or do I misunderstand the type
> system? Or maybe I'm wrong for some other reason.

The reason this will not produce a warning is that Scheme is not purely
functional; you can always set!  a variable to a new value which might
have a different type, and you don't want procedures to be specialised
incorrectly for the type of the "current value", as the type may change
later.

>   ; Example 4 (!)
>   (: value4 (or string false))
>   (define value4 #f)
>   (printed value4)
(set! value4 "hi")
(printed value4)

The same goes for using fluid-let to temporarily rebind a variable
to a new value: this should be possible at any time.

I hope this clarifies things a bit.  I'm not the most knowledgeable
person when it comes to type systems, so if anyone wants to correct
me on any specific points, please do!

Cheers,
Peter

Attachment: signature.asc
Description: PGP signature


reply via email to

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