[LAU] OT: 2 minute intro to type systems (was C or C++?)

Harry Van Haaren harryhaaren at gmail.com
Thu Oct 14 21:23:53 UTC 2010


Thanks for that... Was something I wasnt exactly clear on :-)

-Harry


On Thu, Oct 14, 2010 at 9:44 PM, Erik de Castro Lopo
<mle+la at mega-nerd.com<mle%2Bla at mega-nerd.com>
> wrote:

> Erik de Castro Lopo wrote:
>
> > Python and Ruby do have a strict type system, its just that
> > the types are checked at run time. In these dynamically typed
> > languages, *every* value is an object that caries around with
> > it its type.
>
>
> From at least one message in this thread it seems that there
> is some confusion about type systems, in particular strict
> vs strong typing.
>
> Type systems can basically be mapped onto two axes;
>
>                        strong
>                           |
>                           |
>                           |
>         dynamic ----------+---------- static
>                           |
>                           |
>                           |
>                         weak
>
> Strong type systems prevent you from doing things that do not make
> sense like adding an integer and a list. For instance, in Python,
>
>    >>> x = 1
>    >>> y = [ 1 , 2 ]
>    >>> x + y
>
> gives an error like "unsupported operand type(s) for +: 'int' and 'list'".
>
> Weak type systems allow things that don't make sense (possibly with
> a user provided type cast). For instance in C:
>
>       float test (GLIst *list)
>       {    int x = 10 ;
>            return x + (int) list ;
>       }
>
> the above makes no sense whatsoever, but the compiler accepts the
> programmers word that this is in fact what the programmer wants.
>
> Purely static type systems are ones where all the types are checked at
> compile time and the run time objects contain no type information
> and no type checking is done at run time.
>
> Purely dyanmic type systems are ones where every run time data
> object carries around its type and all the type checking is done
> at run time.
>
> With the above axes set up you can have languages like C with
> weak static types, Haskell with strong static types and Python
> with strong dynamic types. I don't know of any language that
> can really be said to have weak dynamic types.
>
> Furthermore, most dynamically types languages have a small amount
> of static type checking built in, but this is usually a by product
> of syntax checking.
>
> Similarly, in a statically typed langauge its possible to implement
> a library with an object type where the type checking for operations
> on those objects is carried out at run time.
>
> Finally, many people assume that all strictly typed languages
> require the programmer to explicitly define the types of everything.
> Fortunately, this is not the case. There are a whole family of
> languages that use Hindley-Milner type inference to infer the types
> of all objects from the context. These languages include Ocaml and
> Haskell.
>
>
> HTH,
> Erik
> --
> ----------------------------------------------------------------------
> Erik de Castro Lopo
> http://www.mega-nerd.com/
> _______________________________________________
> Linux-audio-user mailing list
> Linux-audio-user at lists.linuxaudio.org
> http://lists.linuxaudio.org/listinfo/linux-audio-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxaudio.org/pipermail/linux-audio-user/attachments/20101014/5ded111c/attachment.htm>


More information about the Linux-audio-user mailing list