🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #3246

Re: Dynamic typing (part 3)

#3246
From: Lennart Augustsson
Date: Thu, 28 Mar 1991 12:46
37 lines
1766 bytes
In article <1991Mar27.161304.17666@daffy.cs.wisc.edu> quale@saavik.cs.wisc.edu (Douglas E. Quale) writes:
>In Common Lisp,
>
>(defun compose (f g)
>  (lambda (&rest) (funcall f (apply g &rest))))
>
>I think it looks better in Scheme,
>
>(define (compose f g)
>  (lambda x (f (apply g x))))
>
>These definitions use dynamic typing to obtain polymorphism.
>
Yes, in LISP it's dynamic typing that gives you the polymorphism, but
you don't have to have dynamic typing.  Let's do the same definition
in ML, which is statically typed:
  - fun compose(f,g) x = f(g x);
  > val compose = fn : (('a -> 'b) * ('c -> 'a)) -> ('c -> 'b)
(I wrote the line starting with '-', the system responded with the the
line starting with '>'.)
This compose function is typed and still polymorphic.  Some examples:
  - fun inc x = x+1;
  > val inc = fn : int -> int
  - compose(not,not) true;
  > true : bool
  - compose(inc,compose(inc,inc)) 0;
  > 3 : int
  - compose(inc,not) true;
  Type clash  in:  (compose (inc,not))
  Looking  for a:  int
  I have found a:  bool




	-- Lennart Augustsson
[This signature is intentionally left blank.]
Technical Details
Message-ID: <1991Mar28.124634.28106@mathrt0.math.chalmers.se>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!chalmers.se!mathrt0.math.chalmers.se!augustss
References: <602@optima.cs.arizona.edu> <2400035@otter.hpl.hp.com> <1991Mar27.161304.17666@daffy.cs.wisc.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!chalmers.se!mathrt0.math.chalmers.se!augustss
From: augustss@cs.chalmers.se (Lennart Augustsson)
Newsgroups: comp.lang.misc
Subject: Re: Dynamic typing (part 3)
Message-ID: <1991Mar28.124634.28106@mathrt0.math.chalmers.se>
Date: 28 Mar 91 12:46:34 GMT
References: <602@optima.cs.arizona.edu> <2400035@otter.hpl.hp.com> <1991Mar27.161304.17666@daffy.cs.wisc.edu>
Sender: news@mathrt0.math.chalmers.se (Evald Nyhetsson)
Organization: Dep of Computer Sciences, Chalmers, Gothenburg
Lines: 37