From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA04162 for caml-red; Mon, 21 Aug 2000 23:29:40 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA30387 for ; Mon, 21 Aug 2000 19:16:30 +0200 (MET DST) Received: from localhost.localdomain (brian-boitano54.zip.com.au [210.23.147.54]) by concorde.inria.fr (8.10.0/8.10.0) with ESMTP id e7LHGOf17325 for ; Mon, 21 Aug 2000 19:16:25 +0200 (MET DST) Received: from maxtal.com.au (IDENT:root@localhost [127.0.0.1]) by localhost.localdomain (8.9.3/8.8.7) with ESMTP id DAA02392 for ; Tue, 22 Aug 2000 03:17:12 +1000 Message-ID: <39A16418.A71D713D@maxtal.com.au> Date: Tue, 22 Aug 2000 03:17:12 +1000 From: John Max Skaller X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.12-20 i686) X-Accept-Language: en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Return type of procedures? Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: weis@pauillac.inria.fr I am designing a programming language (the compiler is written in ocaml) which is a procedural language with 'purely functional' expressions (using eager evaluation). Function closures can access their context, which procedural statements my change between building the closure and evaulating it. Procedural closures may mutate their environment. Procedures and functions are defined with distinct keywords 'procedure' and 'function'. I have given a procedure the functional type 'a -> unit (where 'a may sensibly be 'unit') whereas functions have signature 'a -> 'b where either 'a or 'b may be unit. Note that if 'a is unit, the function is not necessarily constant, since it may depend on the environment. OTOH, a function with 'b as unit is farily useless. However, as it stands, the type system fails to achieve separation of functions and procedures: procedure p: unit -> unit function f: unit -> unit f (p ()) // woops! Here is an expression (functional code) which has taken the result of calling a procedure (unit) as an argument. Proposal: just as unit is the trivial product (tuple, terminal object), so we say 'void' is the trivial sum (initial object), and make procedures have the signature procedure f: unit -> void Now, procedures cannot be used 'in' expressions anywhere, provided we do not allow the argument of a function or procedure to have 'void' type. We can also treat procedures uniformly from a typing view point. Comments? -- John (Max) Skaller, mailto:skaller@maxtal.com.au 10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850 checkout Vyper http://Vyper.sourceforge.net download Interscript http://Interscript.sourceforge.net