[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: the forward method [dynamic vs. static typing]



> Static typing can make programs more concise: I can write
> 
>     getLine >>= print . (/2) . read
> 
> or
> 
>     getLine >>= print . not . read
> 
> rather than
> 
>     getLine >>= print . (/2) . readDouble
> 
> or
> 
>     getLine >>= print . not . readBool

Am I right in saying that the above is specific to reading from the
outside world? DT systems don't need type annotations because they carry
around type metadata with the data. Of course this breaks down when the
data comes from outside.

So this is a special case where the type information is *not* redundant.
Both DT and ST need type information in order to correctly parse the
input. What is clever about the ST code above, is that the type system
is able to propagate the information from where it is known to where it
is needed, thus making the code more concise (define something once, use
it everywhere).

DT systems propagate type information around at runtime, along with
actual data, but an *expected* return type is not actual data. This is
the essential difference between ST and DT - only ST is concerned with
type information ahead of time.

Also of note - the ST code is only more concise thanks to type
inference, but can enough information be inferred? In some cases,
explicit annotation will still be needed. In the above code for example,
the function (/2) may accept a variety of numeric types: read will not
know whether to read an integer or a double.

Tom (hoping not to put his foot in his mouth in his first post :)