Can anyone provide me with less than five lines of code that I can save as .hs and run as a haskell program and see the magic happen? The internet is so complicated sometimes.
main = putStrLn "Hello, World!"
From http://www.haskell.org/haskellwiki/Haskell_in_5_steps
The internet isn't so bad!
Someone should have mentioned interact
which is simple and actually practical:
main = interact reverse
$ cat interact.hs | runhaskell interact.hs esrever tcaretni = niam
and thus with
main = interact (unwords . reverse . words)
$ cat interact.hs | runhaskell interact.hs words) . reverse . (unwords interact = main
or with an import
import Data.List
main = interact (intersperse '\n')
$ echo "hello" | runhaskell interact.hs h e l l o
or, now compiling:
main = interact showCharcount
where showCharcount str = show (length str) ++ "\n"
$ ghc --make -O2 interact.hs -o charcount $ echo "hello world" | ./charcount 12
In which case it makes sense to start doing a bit of poor man's benchmarking:
$ time cat /usr/share/dict/words | ./charcount 2486813 real 0m0.096s
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With