3 ms·
As someone who is still learning Ruby and would like to learn Haskell I have no idea what is going on here. Would someone be kind enough to explain? Thanks.
by dopamean 13y ago
As someone who is still learning Ruby and would like to learn Haskell I have no idea what is going on here. Would someone be kind enough to explain? Thanks.
- phaer 13y agoIt's just adding a syntactic construct to ruby which looks similar to haskells list comprehensions. Explanation for haskell: http://learnyouahaskell.com/starting-out#im-a-list-comprehension http://learnyouahaskell.com/starting-out#im-a-list-comprehen...
- dopamean 13y agoAh, I get it. Thanks dude.
- cschneid 13y agoSpecifically, it is monkey patching the unary - and + operators on array, and has a clever global method missing. The unary operators `def -@` gets called when you do something like: `-[1,2,3]`. So in the example code at the bottom, it's doing `bar =+ [x | x <- [1..3]]` that's better parsed as `bar = +[x | x <- [1..3]]` (note the spacing difference). Hacking unary operators has a long history in silliness in ruby. See also: https://github.com/jicksta/superators https://github.com/jicksta/superators