Xref: utzoo comp.object:3278 comp.lang.misc:7561 comp.lang.eiffel:1523 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!mintaka!bloom-beacon!eru!hagbard!sunic!mcsun!hp4nl!charon!guido From: guido@cwi.nl (Guido van Rossum) Newsgroups: comp.object,comp.lang.misc,comp.lang.eiffel Subject: Re: A Hard Problem for Static Type Systems Message-ID: <3378@charon.cwi.nl> Date: 21 Apr 91 17:13:43 GMT References: <1991Apr20.010347.28984@leland.Stanford.EDU> Sender: news@cwi.nl Followup-To: comp.object Lines: 66 craig@leland.Stanford.EDU (Craig Chambers) writes: >Consider the general min function (written in a dynamically-typed >C-like language): >[...] >Here's the problem: we'd like to describe the type of the min >function, so that this one piece of source code can be used to compute >the minimum of two numbers or of two collections of numbers or of two >collections of collections of numbers, etc. This can be done in ABC, a statically typed interpreted language developed at CWI [1]. ABC knows a single type "number" which can hold a float or arbitrary-precision rational, and "lists" that are sorted collections of values with the same type; list items may be lists if their types are the same, etc.; lists are sorted lexicographically. If you don't want the items sorted there is a "table" type that lets you determine the order; tables are really associative arrays. The function you describe is written in ABC as follows: HOW TO RETURN min(x, y): IF x < y: RETURN x RETURN y and now you will have min(3.14, 1) = 1, min({1;2;3}, {1;2}) = {1;2}, etc., and min(3.14, {}) will not type-check. [2] --Guido van Rossum, CWI, Amsterdam Founder of the Royal Society for Prevention of Cruelty to Amoebae [1] %T ABC Programmer's Handbook %A Leo Geurts %A Lambert Meertens %A Steven Pemberton %I Prentice-Hall %C London %D 1990 %O ISBN 0-13-000027-2 [2] ABC is implemented; I typed the example in and here's the session log: piring& abc ABC Release 1.02.01. Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1989. Type '?' for help. >first >>> HOW TO RETURN min(x, y): HOW TO RETURN min(x, y): IF x < y: RETURN x RETURN y >>> WRITE min(3.14, 1) 1 >>> WRITE min({1; 2; 3}, {1; 2}) {1; 2} >>> WRITE min(1, {}) *** Cannot reconcile the types in your command WRITE min(1, {}) *** The problem is: I found type EG (0, list or table) where I expected (?, ?) >>> QUIT piring&