chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] permissive checking of sum types


From: David Goffredo
Subject: [Chicken-users] permissive checking of sum types
Date: Sat, 2 Dec 2017 20:56:52 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0

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.

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. Using the version of defstruct provided by the typed-records egg, I noticed that since the generated constructor takes field values as keyword arguments, any fields not specified take the default value #f. This means if I declare a field as having type "string", really it behaves as "(or string false)". That's fine, since I can just declare it as "(or string false)".

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.

    $ csc -version
    (c) 2008-2016, The CHICKEN Team
    (c) 2000-2007, Felix L. Winkelmann
    Version 4.11.0 (rev ce980c4)
    linux-unix-gnu-x86-64 [ 64bit manyargs dload ptables ]
    compiled 2016-05-28 on yves.more-magic.net (Linux)

Here are some code examples demonstrating what I'm talking about:


    (: printed (string -> string))
    (define (printed what)
      (print what)
      what)

    ; Example 1
    (printed "this is a string")

    ; Example 2 (warning)
    (printed 42)

    ; Example 3 (!)
    (: value3 (or string false))
    (define value3 "also a string")
    (printed value3)

    ; Example 4 (!)
    (: value4 (or string false))
    (define value4 #f)
    (printed value4)

    ; Example 5 (warning)
    (: value5 (or number false))
    (define value5 #f)
    (printed value5)

    ; Example 6 (!)
    (: value6 (or string number))
    (define value6 24)
    (printed value6)

In my opinion, those examples marked with exclamation points should emit a warning by the compiler, but they don't.

Let me know what you think.

Thanks,
    David




reply via email to

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