LHBG 12. Converting a directory

Ғылым және технология

Learn Haskell by building a blog generator (free e-book): lhbg-book.link/
Part 12. Converting a directory
💡 Related links:
* Discussion board: github.com/soupi/learn-haskel...
* Chapter 6.4: lhbg-book.link/06-errors_and_...
#fp #haskell
Subscribe to Impure Pics: bit.ly/impure-youtube
More Impure Pics
🐣 / impurepics
📦 impurepics.com
👕 merch.impurepics.com
Functional Alphabet book
📗 Softcover: bit.ly/fp-abc-soft-cover
📘 Hardcover: bit.ly/fp-abc-hard-cover
Watch more Impure Pics
• Debunking Haskell Myth...
About Impure Pics
FP Advocat. Distilling functional programming for the good of all
Get in touch: zelenya.com
0:00 Let's code already!
7:48 Summary

Пікірлер: 5

  • @gregbell2117
    @gregbell2117 Жыл бұрын

    Thanks for this series! I've been studying Haskell for awhile, but still can't really write 'real' programs. One discouraging thing is that when I see code like this: -- | Returns the directory content getDirFilesAndContent :: FilePath -> IO DirContents getDirFilesAndContent inputDir = do files = filterAndReportFailures pure $ DirContents { dcFilesToProcess = txtFilesAndContent , dcFilesToCopy = otherFiles } I just think "really? That's easier to 'reason about' than the equivalent procedural code?"

  • @impurepics

    @impurepics

    Жыл бұрын

    Yeah, it takes time to get used to it. The only way to master is to write (and sometimes read) more code: doing exercises, refactoring existing snippets, or even playing with code (e.g., moving pieces around). Also, what’s the most puzzling in this snippet? The use of operators (e.g., ``)? You can try refactoring them using their named alternatives. The use of point-free style (e.g., `((== ".txt") . takeExtension`)? You can try extracting these into separate functions with a name... There’re a lot of things you can adapt to your own liking.

  • @gregbell2117

    @gregbell2117

    Жыл бұрын

    @@impurepics Great advice, thanks so much. I do a lot of reading and exercises, but probably need to refactor and play more, as you suggest. Going from knowing what I want to do (e.g. recursively list files) to what seems like a magic incantation of `map (f) g` is what gets me. I can go backwards - reason about types, substitute, unify - but going forwards is escaping me at my current level. And in the above, sometimes `let`, sometimes `>= in a do block... hmm.... Haskell just seems like endless mystery - there's no "mastering the basics then you're good" like with procedural languages.

  • @impurepics

    @impurepics

    Жыл бұрын

    @@gregbell2117 You're on the right track!

  • @impurepics

    @impurepics

    Жыл бұрын

    @@gregbell2117 I unintentionally took a longer, "simpler" path. I started doing Scala as an OOP developer and slowly mastered functional concepts in digestible chunks. At some point (a couple of years later), jumping to Haskell was a syntactical difference (I already knew major concepts and operators). (When it comes to let vs. bind, luckily, the compiler will tell you if you're using the wrong one until you get used to it)

Келесі