The Joy and Agony of Haskell in Production
I am not a professional developer (never gotten paid to write software) but now do some prototyping code in Haskell so real engineers can pick it up from me later.<p>For me, Haskell has been a huge productivity booster. It forces me to write good code and 90% of mistakes that I normally make are all caught at compile time. I use <i>servant</i> for creating my API server and it is pleasure to use (being able to create APIs declaratively is very easy for me to understand as a non professional). I recently had to write some front-end code in JavaScript and I noticed how simple mistakes can take 1&#x2F;2 hour to debug (you pass in an array of objects instead of an object and you will wonder why `for (k in obj)` logic is not working.<p>I refactor huge parts of my code - can gut a particular API endpoint response and rewrite it without worrying about introducing more bugs. This allows me to start writing code without a lot of planning and refactor as I go instead of spending a lot of time upfront thinking through the implications.<p>Using Hoogle or Hayoo to search for functions based on types is just simply awesome. If you want a function that returns the index of a list that satisfies a predicate, you don&#x27;t need to come up with search words instead you just look for it based on the types like so: <a href="http:&#x2F;&#x2F;hayoo.fh-wedel.de&#x2F;?query=(a+->+Bool)+->+[a]+->+Maybe+Int" rel="nofollow">http:&#x2F;&#x2F;hayoo.fh-wedel.de&#x2F;?query=(a+->+Bool)+->+[a]+-...</a>. This does not mean you can solve all problems this way but it is very quick to get easy answers than Googling or putting it on SO.<p>Most developers write their APIs and need to spend more time documenting it. With <i>servant</i> I just derive documentation directly from the types so my documentation moves in lock step with my code.<p>That said, using Haskell has its challenges (especially as a beginner).<p>* Compile-refresh cycle is frustrating. With Python or Go, you make a change and refresh the page, it is there. With Haskell, the 30s wait can become painful. My code is organized into modules but it is hard to avoid dependency related compile issues -- I tend to put most of my data records (mostly related by business logic) in a module and if you add anything to this module, you will end up recompiling everything that depends on it (which is most of the code). I am sure a pro-Haskeller would do it differently but whatever suggestions available online is not steering me in the right direction.<p>* Starting out with a fresh framework is not trivial for a beginner. <i>servant</i> is really nice because it came with very good documentation and also a tutorial by someone on how to use it with <i>wai</i> (http server) and <i>persistent</i> (an ORM). Without it, I would not have been able to get to where I am now.<p>* Not all libraries are created equal -- some of the common use cases are well documented or has enough documentation that you will be ok. But once you venture beyond common use cases, trying to use a library is not easy. Most of the time, types help and being able to test it in the REPL is nice but it can only take you so far. I recently looked at a library for creating a MIME string but got lost in some undocumented library.<p>* Haskell&#x27;s community is great. You will always find someone to help you. However, as the author was saying, you want to get some work done and you cannot wait 2 days for an answer on Reddit or SO. IRC is great for specific libraries (say servant or Yesod) but general #haskell can be daunting -- 90% of the people seem to be discussing Lenses or Free Monads and your stupid type error is not going to get any attention.<p>* Easy parts of Haskell are very easy to pickup and the hard parts seem impossible to fully comprehend (I will think I understand Monad Transformers and will try to implement some logic but will get stuck in type check hell and quickly give up).<p>Btw, I did not know about <i>fieldLabelModifier</i> until now and it will cut down a lot of boiler plate. That said, I cannot wait for GHC 8 and its Duplicate Record Fields! Records are really annoying for writing business logic driven API servers.