I've been spending my Copious Free Time lately trying to implement a simple dynamically-typed language in Haskell, both because I like this kind of programming and to make me a better Haskell programmer. Learning Haskell isn't like learning most other programming languages. With most programming languages, you work with the language for a few
(
Read more... )
Comments 3
Reply
Also, ST and State are slightly different than what you describe. The ST monad lets you write imperative code (which is why it runs in the IO monad). You can create and manipulate arrays and memory references. The State monad is completely different - it's a pure, I/O free monad that simply saves you the time of passing arguments in and then reading them back out. State is really just a convenient way of passing a small piece of data between functions - it's not really mutation.
Reply
As for ST and State, again, you're right but I stand by my way of describing them. State is as you say purely functional, whereas ST is no more functional than IO is. Nevertheless, the reason you choose to use State rather than ST (at least, the reason I have done so) is because the stateful data you're passing around is fixed (a small bounded number of stateful items), whereas with ST you can create e.g. all the STRefs you like. OTOH I can imagine situations where you might pick ST over State for efficiency reasons, or alternatively you could use e.g. a list in the State monad to accumulate an unbounded number of items.
Reply
Leave a comment