I'm curious about the relationship between static typing and lazy functional languages. Is it possible to have a dynamic lazy functional language, for instance? It seems as if all of the lazy functional languages out there are statically typed (Haskell, Miranda, etc), and all of the dynamic functional languages use strict evaluation (Clojure, Scheme, etc).
In particular, the Wikipedia article on Lazy evaluation reads:
However, with lazy evaluation, it is difficult to combine with imperative features such as exception handling and input/output, because the order of operations becomes indeterminate. Lazy evaluation can introduce space leaks.
What is the role that static typing plays in preventing space leaks?
There are two main differences between dynamic typing and static typing that you should be aware of when writing transformation scripts. First, dynamically-typed languages perform type checking at runtime, while statically typed languages perform type checking at compile time.
Haskell is a lazy language. This means that the evaluation of expressions is delayed until their values are actually needed. The opposite is eager evaluation, which is what most programming languages implement, like C, Java, and Python.
Python is a dynamically typed language which means checking of the variable is done at the runtime. Whereas in the Statically typed language the checking of the variables or any other is done at the compile time.
Statically typed languages: each variable and expression is already known at compile time. Dynamically typed languages: variables can receive different values at runtime and their type is defined at run time.
I don't believe that static types play a role at all. For example, consider the untyped lazy language, Lazy Racket. I haven't heard any indication that it leaks space in a way that Haskell (for example) does not.
Side effects, on the other hand, are a problem because humans find the order of evaluation of strict evaluation to be (relatively) natural, and call-by-need is much harder to mentally predict.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With