Guessing game: Haskell style
13 points by kqr
13 points by kqr
What a nice Haskell tutorial :-)
I kind of like using do-notation for Maybe as well as IO, but I’m not sure whether it’s more newbie-friendly or less newbie-friendly to do things like
mkSmallInteger i = do
guard (i>=1 && i<=100)
pure (SmallInteger i)
readSmallInteger input = do
i <- readMaybe input
mkSmallInteger i
vs having to learn $>
and >>=
I’m also trying to wean myself off <$>
– it’s not that much harder to fmap (foo . bar) (get thing)
but I think it may be less off-putting to outsiders.
This has always been my sticking point when trying to learn Haskell; many many unfamiliar idioms. Just reading the types of the operators doesn’t help b/c haven’t internalized the difference between Functor
/Appllicative
just starting out.
To the author’s credit https://entropicthoughts.com/non-obvious-haskell-idiom-guard-sequence (linked in article) is very helpful for understanding what $>
is used to do at least.
This has always been my sticking point when trying to learn Haskell; many many unfamiliar idioms. Just reading the types of the operators doesn’t help b/c haven’t internalized the difference between Functor/Appllicative just starting out.
If you come across more of these, please let me know! I’d be more than happy to write more “non-obvious idioms” articles, but since I have some experience I don’t always recognise which they are. (I do have two more of these articles queued up, but I’m sure there are 25 more idioms to be covered.)
I personally prefer <&>
over <$>
most of the time. In my experience, anglophone Haskell beginners appreciate when the code feels left-to-right.
Very interesting post. I’m trying to learn Haskell in my free time and this was very useful.
The purity of the language for me is the main perk. I think it makes it so interesting and fascinating