Created
June 8, 2011 22:21
-
-
Save LeifW/1015583 to your computer and use it in GitHub Desktop.
Comparison of languages.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Earlier I said Haskell/Scala/Python/Ruby/CoffeeScript are all pretty much the same. | |
| By that I meant you can write much the same code in all of them, just the syntax might look a bit more weird or arbitrary in some cases. | |
| Of course there are fundamental differences in the type of things you write in static versus dynamic languages, just as there are fundamental differences between what you write in a lazy vs eager language. | |
| Print the numbers one through ten: | |
| Python: | |
| for i in range(1,11): | |
| print(i) | |
| Ruby: | |
| (1..10).each {|i| puts i} | |
| CoffeeScript: | |
| [1..10].forEach (x)=>console.log(x) | |
| Scala: | |
| 1 to 10 foreach println | |
| Haskell: | |
| mapM_ print [1..10] | |
| See? Just some syntax futzing, but same damned thing (ok, the idiomatic Python is different, and some don't permit eta reduction, but close 'nuff). | |
| Of course, Haskell also lets you sequence your IO with things like: | |
| foldr ((>>) . print) (return ()) [1..10] | |
| A dumbed-down explanation of that line: | |
| It could also be written: | |
| foldl (\f i-> f >> print i) (return ()) [1..10] | |
| which you could squint and think of as: | |
| foldl( {(f, i)-> f(); print(i) }, noop, [1..10] ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You forgot JavaScript! How could you forget the greatest language ever! But JS you can do it whatever way you want:
or
Or, i guess: