[Haskell-cafe] A tale of Project Euler
jmaessen at alum.mit.edu
Thu Nov 29 18:33:07 EST 2007
On Nov 29, 2007, at 6:19 PM, Stefan O'Rear wrote:
> On Thu, Nov 29, 2007 at 09:10:16PM +0000, Andrew Coppin wrote:
>> Sebastian Sylvan wrote:
>>> On Nov 29, 2007 6:43 PM, Andrew Coppin <andrewcoppin at btinternet.com>
>>>> I don't understand the ST monad.
> ...[and ST uses language extensions Andrew doesn't understand.]
> (As far as ST goes, runST is unsafePerformIO renamed. The only tricky
> bit is proving safety.)
To put it another way, runST is unsafePerformIO where somebody has
already done the safety proof for you (so you know it's 100% safe).
The "strange" extensions are simply a device to make the safety proof
work. Indeed, if you drop the extensions it can all be made to work
(just say runST :: ST () a -> a) but you lose the safety proof and
it's equivalent to unsafePerformIO.
[The trick used in runST is one of my all-time favorite bits of type
theory, and is what convinced me we wanted second-order types back
before the first Haskell workshop.]
More information about the Haskell-Cafe