3 ms·
To indulge in fisking a tiny bit - > HKP is practically unavoidable on the road to understanding a Haskell program that prints Hello World. main :: IO ()
by sullyj3 7y ago
To indulge in fisking a tiny bit -
> HKP is practically unavoidable on the road to understanding a Haskell program that prints Hello World.
main :: IO ()
main = putStrLn "Hello World"
Doesn't require an understanding of HKP at all. There isn't even any LKP. I do agree that it's necessary for a productive employed Haskeller, but not a beginner playing around with simple command line apps. There's a distinction to be made between understanding enough to make it run (Just label the IO bits with IO and think of 'do' as kind of like imperative programming but not really) and understanding more deeply, which only becomes necessary later.
> With HKP you now need to decide: should it actually take a List, or is it better to take a Functor/Semigroup/Monoid/Applicative/Monad instead?
It doesn't seem like a decision that would involves a lot of cognitive overhead. In general I'd probably just go with whatever type GHC infers. Failing that, it kind of arises naturally from like, what the function is about. Is it about reducing the List to a single value? Use Foldable. Is it about transforming the elements of the list? Use Functor. Is it about nondeterminism, but the code isn't necessarily specific to that computational context? Use Applicative if there are no sequential dependencies (which the type checker knows anyway) and Monad otherwise. Ok, maybe it seems a little complex when you write it out, but it's really fairly instinctual.