From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fd63afa4dc364b7e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-17 17:00:04 PST Path: supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!newsfeed.mesh.ad.jp!sjc-peer.news.verio.net!news.verio.net!sea-read.news.verio.net.POSTED!not-for-mail Newsgroups: comp.lang.ada From: Brian Rogoff Subject: Re: Static typing (Was Re: Better support for garbage collection) In-Reply-To: Message-ID: References: <98m938$2iod0$1@ID-25716.news.dfncis.de><98pgs1$32up7$1@ID-25716.news.dfncis.de> <98umc6$39coj$1@ID-25716.news.dfncis.de> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Date: Sun, 18 Mar 2001 00:58:55 GMT NNTP-Posting-Host: 206.184.139.136 X-Complaints-To: abuse@verio.net X-Trace: sea-read.news.verio.net 984877135 206.184.139.136 (Sun, 18 Mar 2001 00:58:55 GMT) NNTP-Posting-Date: Sun, 18 Mar 2001 00:58:55 GMT Organization: Verio Xref: supernews.google.com comp.lang.ada:5821 Date: 2001-03-18T00:58:55+00:00 List-Id: On Sat, 17 Mar 2001, Robert A Duff wrote: > Brian Rogoff writes: > > > # let rec len l = match l with [] -> 0 | x::xs -> 1 + len xs;; > > > > Hey, where are the types? Is this like Lisp? No, not really, here is what > > the top level says when I enter that > > > > val len : 'a list -> int = > > > > So the system *infers* the type, and a very general type, for that > > function. It takes a list of anything to an integer. I didn't even need > > to instantiate a generic for that. Pretty spiffy, huh? > > No. I don't find it spiffy to have to read down into the guts of that > function to find out that it returns an 'int'. If you have a problem with this, you have at least two options. (1) Use module interfaces and put the type of the function there. In "real" sized programs that's what I do. In OCaml, the type is inferred and then checked against the explicit type. In Haskell, the type is used in the checking, and this allows you to get polymorphic recursion. Type inference is undecidable in the presence of PR, though Mercury does infer it and just has an iteration limit in the type checker. I think I like the Haskell approach better. (2) You can put the type declaration right there, like this let rec (len : 'a list -> int) = fun l -> match l with [] -> 0 | x::xs -> 1 + len xs;; So you can program entirely with explicit types in ML if you wish. Of course Nick's complaint is about all of the extra code with explicit types, and its that argument I responded to. While I agree with you that inference shouldn't be used everywhere, I think Ada goes way too far in having redundant types, and explicit instantiation everywhere. For all of its egregious flaws, I think C++ got this right with implicit instantiation of templated functions. I think trying to duplicate the STL in Ada convinced me of that, though rather than go to C++ (which I find awful) or a dynamically typed language I started looking at ML and kin. > Nor do I find it spiffy that the type of a literal is determined by > what it looks like. I think the type of a literal should be determined > from context. I don't understand what you mean. Are you complaining about the fact that '0' is an int, for instance? > I think type inference is spiffy within (small) expressions, but I think > interfaces should have explicitly declared types, including functions > like the above 'len'. Module interfaces do consist of explicitly declared types in ML. > I understand that in ML you *can* declare signatures, *if you like*. > I don't know OCaml, unfortunately. OCaml is a dialect of ML, so if you know SML it shouldn't be too hard to switch. My beef with {OCa,S}ML vis-a-vis Ada is the lack of overloading in ML dialects. Of course, many people will claim that overloading lessens readability. Haskell sort of has a kind of overloading (type classes) but it's not exactly the same. Mercury has overloading. Fergus Henderson used to post here, and Mercury is his project. Nice language, but I'm not familiar enough with logic programming to try and use it at work yet. While my manager acknowledges that Ada is much better than C++ or Java, it's a tough sell against a modern high level language. -- Brian