Article View: comp.lang.misc
Article #3229Re: Dynamic typing (part 3)
From: Brian Boutel
Date: Thu, 28 Mar 1991 02:55
Date: Thu, 28 Mar 1991 02:55
55 lines
2181 bytes
2181 bytes
In article <1991Mar27.161304.17666@daffy.cs.wisc.edu>,
quale@saavik.cs.wisc.edu (Douglas E. Quale) writes:
|> >typed languages are generally half to a tenth the size of programs
|> in
|> >statically typed languages" Dan Bernstein reasonably writes back.
|> >
|> >] I don't believe you. Give an example.
|> >
|>
|> 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.
|>
|> I think it would take at least two orders of magnitude (probably
|> three) to
|> do this in C.
|>
|> -- Doug Quale
|> quale@saavik.cs.wisc.edu
Why do you think this is dynamic typing? Definitions parallel to this
exist in statically typed languages like Haskell and ML.
In Haskell, write
compose f g = \ x -> f (g x)
This is even shorter than the lisp/scheme versions. Its type (in the
normal Hindley/Milner type system) is
(forall T1, T2, T3), (T1->T2) -> (T3->T1) -> (T3->T2)
This is polymorphic because any types can be (consistantly) substituted
for the type variables T1,T2 and T3.
This typing can be inferred at compile time, which is what is meant by static.
So try again.
--brian
--
Internet: brian@comp.vuw.ac.nz
Postal: Brian Boutel, Computer Science Dept, Victoria University of Wellington,
PO Box 600, Wellington, New Zealand
Phone: +64 4 721000
Technical Details
Message-ID:
<1991Mar28.025541.9078@comp.vuw.ac.nz>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!waikato.ac.nz!comp.vuw.ac.nz!brianReferences:
<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!zaphod.mps.ohio-state.edu!wuarchive!waikato.ac.nz!comp.vuw.ac.nz!brian Newsgroups: comp.lang.misc Subject: Re: Dynamic typing (part 3) Message-ID: <1991Mar28.025541.9078@comp.vuw.ac.nz> From: brian@comp.vuw.ac.nz (Brian Boutel) Date: Thu, 28 Mar 1991 02:55:41 GMT Sender: news@comp.vuw.ac.nz (News Admin) References: <602@optima.cs.arizona.edu> <2400035@otter.hpl.hp.com> <1991Mar27.161304.17666@daffy.cs.wisc.edu> Organization: Computer Science, Victoria University, Wellington, NewZealand Nntp-Posting-Host: antrim-hse.comp.vuw.ac.nz Originator: brian@antrim-hse.comp.vuw.ac.nz Lines: 55