Hacker News new | ask | show | jobs
by d2v 2145 days ago
Types in Haskell are generally used to describe the structure of the data. Defining a type in Haskell is like writing documentation and a test all in one. I can mentally offload certain concerns to the compiler, which will tell me whether or not the shape of the data in my head matches the code I'm writing. I pretty frequently use the compiler to guide my development, especially with a tool ghcid, which gives instantaneous feedback as I'm programming. It's also like a million times easier to refactor, I tweak a type signature and the compiler will basically give me a list of things I need to update. No need to hunt for and test every instance of that kind of input, the compiler just tells me where it is, and what is wrong.

You also don't have to write out type signatures 99.9% of the time after declaring a type, the compiler can infer them. People in the Haskell community tend to write out signatures for functions because it makes it easier to understand, but it's pretty rare to see a type signature in the body of a function.

That's not to say thinking in Haskell is always as natural or more natural than Python, but I'd argue that immutability and laziness more than types can require a lot more mental effort that can feel like fitting square pegs into round holes for certain problems. When it comes to types (at least Haskell vs. Python), I'd say it's much more a matter of personal taste.

1 comments

That's not relevant unless you can do all of the above instinctively and without involving the higher faculties of the brain.