No subject

Sun Sep 19 15:01:13 UTC 2010

is some confusion about type systems, in particular strict<br>
vs strong typing.<br>
Type systems can basically be mapped onto two axes;<br>
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0strong<br>
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 |<br>
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 |<br>
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 |<br>
 =A0 =A0 =A0 =A0 dynamic ----------+---------- static<br>
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 |<br>
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 |<br>
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 |<br>
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 weak<br>
Strong type systems prevent you from doing things that do not make<br>
sense like adding an integer and a list. For instance, in Python,<br>
 =A0 =A0&gt;&gt;&gt; x =3D 1<br>
 =A0 =A0&gt;&gt;&gt; y =3D [ 1 , 2 ]<br>
 =A0 =A0&gt;&gt;&gt; x + y<br>
gives an error like &quot;unsupported operand type(s) for +: &#39;int&#39; =
and &#39;list&#39;&quot;.<br>
Weak type systems allow things that don&#39;t make sense (possibly with<br>
a user provided type cast). For instance in C:<br>
 =A0 =A0 =A0 float test (GLIst *list)<br>
 =A0 =A0 =A0 { =A0 =A0int x =3D 10 ;<br>
 =A0 =A0 =A0 =A0 =A0 =A0return x + (int) list ;<br>
 =A0 =A0 =A0 }<br>
the above makes no sense whatsoever, but the compiler accepts the<br>
programmers word that this is in fact what the programmer wants.<br>
Purely static type systems are ones where all the types are checked at<br>
compile time and the run time objects contain no type information<br>
and no type checking is done at run time.<br>
Purely dyanmic type systems are ones where every run time data<br>
object carries around its type and all the type checking is done<br>
at run time.<br>
With the above axes set up you can have languages like C with<br>
weak static types, Haskell with strong static types and Python<br>
with strong dynamic types. I don&#39;t know of any language that<br>
can really be said to have weak dynamic types.<br>
Furthermore, most dynamically types languages have a small amount<br>
of static type checking built in, but this is usually a by product<br>
of syntax checking.<br>
Similarly, in a statically typed langauge its possible to implement<br>
a library with an object type where the type checking for operations<br>
on those objects is carried out at run time.<br>
Finally, many people assume that all strictly typed languages<br>
require the programmer to explicitly define the types of everything.<br>
Fortunately, this is not the case. There are a whole family of<br>
languages that use Hindley-Milner type inference to infer the types<br>
of all objects from the context. These languages include Ocaml and<br>
<font color=3D"#888888">--<br>
Erik de Castro Lopo<br>
<a href=3D"" target=3D"_blank">http://www.mega-ner=</a><br>
Linux-audio-user mailing list<br>
<a href=3D"mailto:Linux-audio-user at">Linux-audio-user at l=</a><br>
<a href=3D"" target=3D=


More information about the Linux-audio-user mailing list