Skip to content

Instantly share code, notes, and snippets.

@Isweet
Last active December 30, 2015 05:04
Show Gist options
  • Save Isweet/1ed5663ef40af3b24769 to your computer and use it in GitHub Desktop.
Save Isweet/1ed5663ef40af3b24769 to your computer and use it in GitHub Desktop.
Baby Haskell examples for Sean
#! /bin/bash
cat << EOF > ./RandAscii.hs
module Main (main) where
import Control.Monad
import System.Random
import qualified Data.Char as Char
main :: IO ()
main = forever $ randomRIO (97, 122) >>= (\ r -> putChar $ Char.chr r)
EOF
cat << EOF > ./Upper.hs
module Main (main) where
import qualified Data.Char as Char
main :: IO ()
main = interact (\ s -> map Char.toUpper s)
EOF
cat << EOF > ./Count.hs
module Main (main) where
import qualified Data.List.Split as Split
main :: IO ()
main = interact (\s -> show $ length $ filter ((==) "SEAN") $ Split.chunksOf 4 s)
EOF
ghc RandAscii.hs &> /dev/null
ghc Upper.hs &> /dev/null
ghc Count.hs &> /dev/null
for i in `seq 1 10`; do
./RandAscii | ./Upper | head -c 10000000 | ./Count && echo
done
rm -rf *.hs *.hi *.o ./RandAscii ./Upper ./Count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment