4 ms·
Haskell is one of the few pure languages, pure meaning it's entirely referentially transparent, only allowing pure functions. This is not the case with Lisp, Cl
by alexmingoia 7y ago
Haskell is one of the few pure languages, pure meaning it's entirely referentially transparent, only allowing pure functions. This is not the case with Lisp, Clojure, or many languages that are described as functional programming. Referential transparency means that a function returns the same output for given input. This is not the case in Clojure, Python, or most all programming languages, and in contrast what makes Haskell safe.
Haskell's purity combined with strong typing is what ensures its safety at runtime. In other words, it's trivial to write a program that crashes at runtime in CommonLisp, Clojure, Python, etc. Haskell eliminates this issue by construction. In these other languages, incorrectness can crash a program. Haskell intends to eliminate this.
One of the major tests of referential transparency is if you can lazily evaluate it. Only a 100% pure language can be lazily evaluated. Which Haskell is, excluding warts and historical baggage from its development as a research project.
https://en.wikipedia.org/wiki/Referential_transparency https://en.wikipedia.org/wiki/Referential_transparency
https://en.wikipedia.org/wiki/Pure_function https://en.wikipedia.org/wiki/Pure_function
Haskell functions are pure like math functions. If we have a function f(x)=x+2 then f(16) is always 18. In Python or Javascript or Lisp I can write a function where f(16) returns 18, 1000, or "foobar" depending on the time of day. In impure languages the output of a function can change even with the same input. That's why from a Haskell perspective most languages are unsafe by design and encourage programs riddled with bugs.
- crimsonalucard 7y agoThis is not the reason why haskell is "Safe" Haskell is safe because of type checking. A function in python f(x) = x / 3 will crash if you make x = "a string" because "a string" / 3 doesn't make any sense. Python won't let you know about this until the program actually calls f(x). In haskell f(x: int) -> int = x + 3 is type checked meaning that this program will never compile unless you make x = <some integer>. Haskell does not need to compile the program to know about this. At a very high level what this means is this , languages like python and closure are so expressive they allow you to write programs that will crash during runtime. Languages like haskell are restrictive. They are so restrictive that they will only allow you to write programs that compile and make sense. You will note even when using clojure or untyped lisp languages in the usual way (via functional programming with pure functions) you will still run into many runtime type errors just like python.
- deleted 7y ago[deleted]