strong/weak typing and pointers

Diez B. Roggisch deetsNOSPAM at web.de
Thu Nov 4 19:17:27 EST 2004


Steven Bethard wrote:

> Michael Hobbs <mike <at> hobbshouse.org> writes:
>> 
>> One word: union
>> 
> 
> Interestingly, unions can be well-defined even in a strongly-typed
> language, e.g. OCaml:
> 
> # type int_or_list = Int of int | List of int list;;
> type int_or_list = Int of int | List of int list
> # Int 1;;
> - : int_or_list = Int 1
> # List [1; 2];;
> - : int_or_list = List [1; 2]

Unions in functional languages are also known as direct sums of types (as
opposed to products, which form tuples). And trying to access a union that
holds an int as list will yield an error - runtime, most probably. So there
is no way of reinterpreting an int as list, which still satisfies the
paragdigms of a strong typed language.
-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list