Personal tools


From HaskellWiki

Revision as of 15:54, 9 November 2007 by Lemming (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Sharing means that temporary data is physically stored, if it is used multiple times.


let x = sin 2
in  x*x
is used twice as factor in the product

Due to Referential transparency it does not play a role,

sin 2
is computed twice or

whether it is computed once and the result is stored and reused.

However, when you write
the Haskell compiler will certainly decide to store the result.

This can be the wrong way, if a computation is cheap but its result is huge. Consider

[0..1000000] ++ [0..1000000]

where it is much cheaper to compute the list of numbers than to store it with full length.

Because the sharing property cannot be observed in Haskell, it is hard to transfer the sharing property to foreign programs when you use Haskell as an Embedded domain specific language. You must design a monad or use unsafePerformIO hacks, which should be avoided.