Ad
  • Custom User Avatar

    last is O(n) anyway, so whether that's in reverse or in something else doesn't really matter.

    (If I'm wrong, please call me on it.)

  • Custom User Avatar

    other than spacing, this is what I did!

  • Custom User Avatar

    The entire list is not reversed due to laziness. Unfortunately, I cannot assess to what extent the optimizer discards the overhead...

  • Default User Avatar

    How is this a best practice?

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    You do not need to be good at haskell to consider this idiomatic.
    In my mind this is more about understanding how folds work and not writing their definitions for each individual case.
    Similar thing is using map instead of defining your function to iterate over lists in a way that map does it. (I mean writing f = map g instead of f [] = [] and f (x:xs) = g x : f xs)
    You get used to it after a while :)

  • Custom User Avatar

    I wouldn't mix idiomatic with something that was used as an implementation standard. The fact that it's short and does the job does not mean it is readable when making a quick code review. I suppose I'll refrain from taking a strong stance untill I'm actually good at haskell

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Isn't this more code golf than best practice?
    I'm new so it might be it but it doesn't seem too obvious whats happening

  • Default User Avatar

    Very nicely done!

  • Custom User Avatar

    I am a beginner myself but I have seen (.) used far more widely, probably because it's similar to math that way.

    That's almost certainly true... although I've met Category theorists who've mixed up R○S and S○R in the category of relations.


    The tradition in Clojure is to use the thrush macro:

    (-> 1
        (+ 2)
        (* 3))
    ; => 9
    

    It's pretty easy, think Unix pipes

    find . -name "*.xml" | grep Test | sed -e 's/Test/test/g'
    

    As far as I can tell, Haskell is the only programming language where ($) is used more widely than its conceptual reverse...

  • Default User Avatar

    Maybe it comes down to whether you prefer right or left associativity? I am a beginner myself but I have seen (.) used far more widely, probably because it's similar to math that way. However I think (>>=) is also more used than (=<<) and tbh I find this mix up confusing.

  • Custom User Avatar

    So... I'm admittedly more of a Clojure programmer at heart than a Haskell programmer, but I think (>>>) from Control.Arrow is a bit more readable than the little C combinator (.) from Prelude...