I had a few questions about Haskell at work, and now I’ve been (sort of1) writing Haskell at work for a year, I’d like to answer my own questions.
People who want to work with Haskell, are probably already capable of learning it. It is not an easy language, it took me a long time to build enough confidence to look for a Haskell job, if someone is confident enough to suggest it, I think their ability of learning is capable enough not to slowing down development. And after all, just like every other language, there are always ways to compromise code quality for development speed, whether it worths is another question, but it isn’t anything like The only way to implement a certain function, is to understand the Advanced-type-level-category-theory-thing.
We all know the benefit of pure functions, easy to test, easy to debug, concurrency etc. That’s true for every language, what makes Haskell special is the explicitness of impurity. “Impure” value has a different type, it’s easy to tell and enforce the purity of a function, I quoted “Impure” because it’s technically pure, it just looks impure. Haskell has a clever way to encode side effects into pure values for composition, which means it’s totally possible to code in an imperative style like this
greet :: IO () greet = do now <- getCurrentTime putStrLn "Hello, what's your name" name <- readLn putStrLn ("Welcome, " ++ name ++ ", it's now " ++ (show now)) -- Very imperative code
In fact, quite a lot of Haskell code in our company is imperative, that makes me question whether purity is really helping us or not. At HERP, one of our servers is written in Haskell mostly because we like it, and to be honest it is just an ordinary HTTP server, taking requests and sending responses, it’s by nature impure. It’s not a parser, compiler, or theorem prover that Haskell is famous for. Coding in such imperative style means we cannot enjoy the benefits of purity. It’s not very easy to test, I cannot easily mock the code that gets the current time, I cannot easily follow code path because the monad may exit earlier than expected, I cannot find where does the state come from because it’s hidden somewhere in the monad. The last bug I fixed, is by swapping two lines, it was a state management issue, something that isn’t supposed to happen in the pure world. Haskell is a general purpose language, but unfortunately our tasks are not pure, purity is not helping us a lot, it’s just like any other general purpose language.
Quite a lot. Types are like guarantees, it’s like a truth enforced by the type checker about data. I find types similar to communications, like a programmer trying to explain to others about the behaviour of some code. A powerful type system (like Haskell’s) allows programmers to express concisely what they mean, I personally find it more trustworthy and comfortable than communicating verbosely (probably because there are lots of ambiguity in the Japanese culture and language). Types give me confidence.
Most of our servers and frontend are written in TypeScript, while it’s not close to Haskell, I find my TS development experience surprisingly similar in some ways. For example, we do not use side effects freely whenever we can even though it’s possible, we make sure some functions are pure during code review. We create types and use them extensively for safer code, for annotating our intents. Languages help, but it’s the people who decide whether to accept the help or not. On the other hand, it’s totally possible to type badly in Haskell, e.g. you can make
indexOf :: a -> [a] -> Int, returning
-1 as a special number for not found, instead of using
Maybe Int. You can write FORTRAN in any language.
2 years ago I went to an interview, the company mentioned about Haskell usage on their website. It turned out they don’t use Haskell at all, they put it on because “We think mentioning Haskell attracts better people”. I don’t like their lie, but I now kind of understand why.
By the way if you are recruiting and trying to attract people with Haskell, please be aware that Haskellers are, in my view, more opinionated than average. You can make a JS developer writes PHP, Haskeller? Much harder.
At HERP, Haskell is used in one (an ordinary HTTP server) of many microservices, most of them are written in TypeScript, but I do spend quite some time writing Haskell.