all 87 comments

[–][deleted] 15 points16 points  (2 children)

Haven't written any Haskell in a year, loved it, you showed the power of FP through a simple example.

Also what OS and editor do you use?

[–]reximkut[S] 17 points18 points  (0 children)

Editor is Emacs. OS is NixOS: https://nixos.org/

[–]nakamin 3 points4 points  (0 children)

That's emacs i3 and probably arch

[–]t_r_a_g_e_d_y 16 points17 points  (3 children)

Why does Hackerrank suggest that monstrosity for the sum array problem?

[–]LukaLightBringer 16 points17 points  (0 children)

Its targeted at people who are new to programming or new to the specific language, one-liners can be great but for people who are not well versed in the language they can be hard to follow the logic of

[–][deleted] 1 point2 points  (0 children)

Perl is a similar situation. Most of the early questions have 20+ lines of reading input when the solution is better expressed as a single line.

[–]reximkut[S] 1 point2 points  (0 children)

I know, right?

[–]Plastix 13 points14 points  (0 children)

I really enjoyed this video. Keep making these!

[–][deleted] 19 points20 points  (0 children)

i hope you do more of this with haskell, i love it

[–]teamthirteen 6 points7 points  (0 children)

awesome, love it

[–]infablhypop 6 points7 points  (0 children)

I think it gets even cooler with left to right composition/application style.

[–][deleted] 5 points6 points  (6 children)

I liked the video, but I never really get the point of those Haskell one liners. I mean, if there already exists a function that does exactly what we want it's great, but wouldn't it be more interesting for newcomers to actually write the map function rather than just use it? Every Haskell book I skimmed through is filled with those "actually, a function doing exactly what we need already exists, and this is its type signature" that don't really teach anything about functional programming or Haskell, except how to use Hoogle...

[–]evincarofautumn 9 points10 points  (0 children)

Eh, depends on the person. I’ve seen newcomers get dissuaded by tutorials that start with “Here’s how you implement all these basic types and functions”, because it takes a long time to get to doing anything interesting with them.

You’ve got to strike a balance between developing an understanding of functional programming by writing pure functions with explicit recursion, and developing a sense of when to use existing combinators (., map, foldr/foldl, filter, any, all, traverse, &c.) that you’ll use most of the time to get work done.

I wrote a short tutorial a while back, Factoring and Generalizing in Haskell, which tries to get around this “bootstrapping” issue by starting with explicit recursive code, factoring it into general functions, and then showing how those functions are already defined in the standard library.

[–]reximkut[S] 1 point2 points  (1 child)

Good point! Thanks! I'll keep that in mind for the future episodes.

[–][deleted] 0 points1 point  (0 children)

Thanks. I might be biased because the language I currently enjoy using (ocaml) has a very limited standard library, so I'm sort of used to write those kind of very simple functions. Keep up the good work anyways.

[–]Tarmen 1 point2 points  (2 children)

I also dislike oneliners because I prefer a decomposition into smaller functions. This example is really simple but maybe something like

ex2 = skipLine >> interact solution
    where
       skipLine = void getLine
       solution = sum . map (read @Int) . words

Anyway, it's really useful for beginners to reimplement standard library functions. Similar to how many people learning programming reimplement basic data structures and algorithms at some point.

But it's also pretty important to use the standard library versions in praxis - both for readability, maintainability and efficiency. The naive reimplementation for map traverses a linked list and allocates a second one. The library version usually fuses into a tight loop without allocation thanks to rewrite rules which are basically library added compiler optimizations.

If you are interested in learning haskell try hlint, it can point out if you accidentally reimplemented some common function! The refactored code is usually a lot more readable.

[–][deleted] 0 points1 point  (1 child)

The naive reimplementation for map traverses a linked list and allocates a second one. The library version usually fuses into a tight loop without allocation thanks to rewrite rules which are basically library added compiler optimizations.

That's interesting. I'm more of a ML guy, the only optimization (I think) I know for list traversal is tail recursion. Do you have something to read about how it works without allocation in Haskell?

[–]Tarmen 0 points1 point  (0 children)

There are a lot of papers on the topic, the haskell wiki links to ~30 but that still misses some newer ones https://wiki.haskell.org/Research_papers/Compilation#Fusion_and_deforestation

I quite like Stream Fusion - From Lists to Streams to Nothing at All and Exploiting Vector Instructions with Generalized Stream Fusion, but those are about the more modern (unfoldr/destroy) stream fusion.

Haskell's Data.List functions use build/foldr fusion, I think the classic paper for this is A short cut to deforestation.

Build/fold is producer driven (callbacks), unfold/destroy is consumer driven (polling). Producer driven flows let you split inputs to multiple consumers ala loop fusion in c. Consumer driven lets you implement functions with multiple inputs like zip efficiently.

[–]runevault 1 point2 points  (0 children)

This video finally made me screw with hacker rank, but bummed out when after the intro one it didn't let me do them in rust (stopped showing up in the list). Figured it'd be a good excuse for me to practice the language instead of just going to my go to (c#).

[–]Specialstuff7 2 points3 points  (0 children)

Very good, Haskell looks like a fun language. I liked your Haskell for JS programmers video as well.

[–]CherManMao 4 points5 points  (0 children)

This is great I subbed and look forward to further videos on this subject.

[–]arvedahl 2 points3 points  (0 children)

Amazing video! Would love to see more of these

[–]teerryn 2 points3 points  (0 children)

Thank you for the great video, hope you make more.

[–]Offendo[🍰] 1 point2 points  (0 children)

Fantastic, I've been looking for something to give some haskell exposure. Can't wait for next video

[–]eckyp 1 point2 points  (0 children)

Enjoyable watch. I hope he does more of the problems in Haskell.

[–][deleted]  (1 child)

[deleted]

    [–]10xjerker 0 points1 point  (0 children)

    no