strong/weak typing and pointers
Dave Benjamin
ramen at lackingtalent.com
Fri Nov 5 17:43:25 EST 2004
In article <cmegqg$ea2$03$1 at news.t-online.com>, Diez B. Roggisch wrote:
> 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.
Just FYI:
In OCaml, the error will be at compile time, and the compiler will warn you
if you do not deal with all possible cases for a given union type.
--
.:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:.
"talking about music is like dancing about architecture."
More information about the Python-list
mailing list