3 ms·
In all cases, this means that a function called twice in a row from the same point in a program may return two different values--and that's exactly what the aut
by doty 17y ago
In all cases, this means that a function called twice in a row from the same point in a program may return two different values--and that's exactly what the author is saying is a flaw of imperative languages.
For Haskell, this is false. In order to get two different results from the invocation of the same function you must pass in two different arguments. The monadic functions work by yielding a new version of the world, as it were.
Here's a nice explanation of Haskell IO that makes sense to me: http://www.haskell.org/haskellwiki/IO_inside http://www.haskell.org/haskellwiki/IO_inside
- Xichekolas 17y agoJust to chip in a link, this explanation was the one that made Monads click for me: http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html http://blog.sigfpe.com/2006/08/you-could-have-invented-monad...
- jrockway 17y agoNot if you use IORefs, foreign calls, unsafePerformIO, MVars, TVars, etc. In all cases except unsafePerformIO, though, the type system ensures that you are prepared to handle this unusual behavior. That's the primary difference between Haskell and the imperative languages. (In Haskell, it's easy to not accidentally use effectful code. In most imperative languages I've used, it is impossible to control your use of side effects.)
- derefr 17y agoWhen people say "Haskell is a functional language," I believe they actually mean "the subset of Haskell that doesn't include unsafePerformIO et all is a functional language." (The fact that standard library functions call those functions is an implementation detail.)