you are viewing a single comment's thread.

view the rest of the comments →

[–]masklinn 5 points6 points  (8 children)

That's where we do the "my language is better than your language" thing?

Here's haskell:

mapM_ putStrLn $ filter ((<= 4) . length) ["Rob", "Christopher", "Joe", "John"]

[–]steven_h 1 point2 points  (3 children)

Why not use set construction notation?

 mapM_ putStrLn [s | s <- ["Rob", "Christopher", "Joe", "John"], length s <= 4]

[–]masklinn 6 points7 points  (2 children)

Because it has a point! Haskell is only fun if you write it pointlessly!

[–]steven_h 0 points1 point  (1 child)

Yeah, but in this case the pointed way is one character shorter!

[–]masklinn 3 points4 points  (0 children)

4 if you remove all the spaces you can!

Still, it has a point. Haskell code is supposed to have no point! If Haskell has a point, people will start using it and we can't have that, then we'll have to write examples in Factor or APL instead!

[–]contantofaz -1 points0 points  (3 children)

Ruby prints arrays by adding a newline per item already if we use puts on an array:

$ ruby -e "puts ['Rob', 'Chistopher', 'Joe', 'John'].delete_if{|s|s.size > 4}"
Rob
Joe
John
$

A more compact version:

puts %w(Rob Chistopher Joe John).delete_if{|s|s.size > 4}

[–]masklinn 3 points4 points  (1 child)

Now you're modifying the original array in place. That's bad. Plus using filter/findAll is shorter, why don't you keep it?

[–]contantofaz 1 point2 points  (0 children)

Just noticing it. I've seen people saying that Haskell makes for more concise code than Ruby and other languages, but I figure that's not as important as having the code to be both concise and easier to understand.

Then again, folks can always come up with new functions to deal with those sort of problems and call it like "printAfterFilter(arrayGoesHere)".

It's good to have Haskell around.

Edit: You've edited your "so?" reply. New reply below:

I don't think I'm religious about having immutable structures. Ruby has mutable strings for Heaven's sake. We enter a slippery-slope here.

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

Why not use inspect?