Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Tomas Andersson

Tomas Andersson Tirpen

Niner since 2009

A mathematician, programmer, and general ubergeek currently looking for work.
  • C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals, Chapter 2 of 13

    Well, I did say it was a nonsensical example. Wink

    And you are of course correct that the pointfree version is better and is what I would write as well in actual code, but I was just trying to show the use of the $ operator specifically in that example.

  • C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals, Chapter 2 of 13

    Regarding the $-operator:

     

    I've never heard any Haskell programmer say that the $-operator is used to save letters, because as Erik says, you only save at most one. The purpose is to avoid having expressions that end with a huge mountain of parenthesises. Compare the two following, slightly nonsensical, snippets.

     

     

    print (take 10 (sort (map (\x -> x + 17) (filter isPrime xs)))))
     
    print $ take 10 $ sort $ map (\x -> x + 17) $ filter isPrime xs

     

     

    Notice how the second version reads alot more similar to when you write pipes in Unix or when you chain together method calls in an OO language.

     

    Did you even notice that there was one end parenthesis to much in the first version?

     

     So the $ is not about saving characters, it's about clarity. But I agree that there is a general tendency among Haskellers to be overly clever (read: obscure) to write shorter code.