4 ms·
Here's a page for Haskell: http://www.haskell.org/haskellwiki/Blow_your_mind http://www.haskell.org/haskellwiki/Blow_your_mind It isn't exactly the same--some
by tikhonj 15y ago
Here's a page for Haskell: http://www.haskell.org/haskellwiki/Blow_your_mind http://www.haskell.org/haskellwiki/Blow_your_mind
It isn't exactly the same--some examples are two or three lines and it's more about coolness than practicality--but it's in a similar spirit, and, more importantly, also interesting.
- scrame 15y agoThe first example: -- split at whitespace -- "hello world" -> ["hello","world"] words unfoldr (\b -> fmap (const . (second $ drop 1) . break (==' ') $ b) . listToMaybe $ b) takeWhile (not . null) . evalState (repeatM $ modify (drop 1) >> State (break (== ' '))) . (' ' :) where repeatM = sequence . repeat fix (\f l -> if null l then [] else let (s,e) = break (==' ') l in s:f (drop 1 e)) Not really in the same spirit at all.
- stouset 15y agoThat blows my mind, but certainly not in a good way. Ruby: $ echo 'hello world' | ruby -e 'p STDIN.read.split'
- nemetroid 15y agoBe aware that those are four separate examples made to showcase features of the language, the simplest of which being just `words`. split.hs: main = interact (show . words) $ echo hello world | runhaskell split.hs
- scrame 15y agoOK, thats not really clear from the layout. Your example is clearer, but if you have to put it in a script and pipe stuff to it, its not really a 1-liner.