strict functions (semantics)?
According to this article on denotational semantics in haskell All types have bottom, and a function f:A->B is strict if it maps the bottom of type A to the bottom of type B, it is called non-strict other-wise.
(This is reminiscent of a pointed category where morphisms preserve the basepoint).
Why does Haskell have non-strict functions, whereas Standard ML doesn't?
Every programming language with recursion has at least one non-strict function, often in the form of a conditional ( if-then-else
). Otherwise all recursions would denote bottom (non-termination). Essential as non-strict functions are, however, most of these languages do not let you define your own! Some languages make up for this limitation by offering macros--a somewhat function-like mechanism that transforms syntax instead of values.
Why does Haskell have non-strict functions, whereas Standard ML doesn't?
Haskell has non-strict functions -- typically lazy ones -- because they are a useful programming feature to have.
They improve equational reasoning, make it easier to compose code, and make it possible to write more kinds of programs.
Simon Peyton-Jones gave some good responses to this in his set of slides, Wearing the Hair Shirt.
Laziness is jolly convenient
Recursive values are jolly useful
Laziness keeps you honest [regarding purity]
The last reason is the most important to me. Haskell's computational purity and tight control of effects are due in large part to its non-strictness.
Every call-by-value language has given into the siren call of side effects
Programmers want to write C-like code, which I think is the "siren call" that lures in most languages. In Haskell, interleaving effects willy-nilly just doesn't make sense, because non-strictness means that you wouldn't be sure when an effect will be performed.
链接地址: http://www.djcxy.com/p/7502.html上一篇: 从Int到Int的严格函数?
下一篇: 严格的函数(语义)?