Haskell examples often don't work

I am new to haskell and am using the latest GHCi 2011.2.0.1. One disappointment that I often encounter is that very often examples on the Internet and books (even from the haskell.org official site, for example example-2 http://www.haskell.org/haskellwiki/State_Monad ) do not compile. And it takes several rounds of hunting and posting questions to figure out what the problem is. Even some of the examples from the RWH book do not work.

Is this a problem with the new version of haskell or the haskell platform? Are languages ​​/ platform evolving and unstable, or are only examples out of date? In any case, what is the best way for a new student to find the right examples to learn?

In particular, can you help correct the example of the state monad mentioned above?

+4
source share
1 answer

In this case, the problem is that the State constructor has been removed in the latest version of the Monad Transformer Library. If you replace the use of State in the definition of getNext with State , then the program works fine. (This is due to the fact that State was redefined as StateT Identity , i.e., a state transformer on a monodate monad, and therefore a separate data type was deleted. If you do not know what this means, do not worry about it just means that you should replace State with State whenever you see it.)

Most problems with existing examples on the Internet or in RWH are simply due to newer versions of the libraries. (I think the main problem with RWH examples is that Parsec examples are written for Parsec 2, Parsec 3 has been changed quite a bit, so at least you probably have to add some imports.)

All in all, Haskell really suffers from a lack of modern useful resources; that the HaskellWiki page is simply not supported. (Although HaskellWiki is indeed an official site of haskell.org, the pages are written and maintained by users, therefore simply because something on the wiki does not necessarily mean its relevance or high quality.)

The release of the Monad Transformer library, which State removed, was released in October 2010, so it’s a shame that there is still a lot of code that does not work with the new version because of this. Fortunately, the fix is ​​simple.

+9
source

Source: https://habr.com/ru/post/1393095/


All Articles