ouzo2:code$ ghci GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /Users/hallgren/.ghci Prelude> :l countWords.hs [1 of 1] Compiling Main ( countWords.hs, interpreted ) Ok, one module loaded. *Main> Leaving GHCi. ouzo2:code$ ghc -O countWords.hs [1 of 1] Compiling Main ( countWords.hs, countWords.o ) Linking countWords ... ouzo2:code$ ./countWords < example.txt is: 3 warm: 2 cold: 1 June: 1 July: 1 January: 1 ouzo2:code$ wc TheMartian.txt 8799 100795 559755 TheMartian.txt ouzo2:code$ ./countWords < TheMartian.txt | less ouzo2:code$ time ./countWords < TheMartian.txt >/tmp/words real 0m0.411s user 0m0.369s sys 0m0.027s ouzo2:code$ python Python 2.7.15 (default, Jun 17 2018, 12:46:58) [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> input() 15 15 >>> input() - input() 15 12 3 >>> ouzo2:code$ node > counter=0 0 > function next() { counter=counter+1; return counter; } undefined > next() 1 > next() 2 > next() - next() -1 > counter 4 > ouzo2:code$ ghci GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /Users/hallgren/.ghci Prelude> getLine ahlksjhdf "ahlksjhdf" Prelude> :t getLine getLine :: IO String Prelude> s = getLine Prelude> :t s s :: IO String Prelude> Leaving GHCi. ouzo2:code$ python Python 2.7.15 (default, Jun 17 2018, 12:46:58) [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> s = input >>> s >>> s() 15 15 >>> ouzo2:code$ ghci GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /Users/hallgren/.ghci Prelude> :t getLine getLine :: IO String Prelude> s <- getLine heljaslkdf Prelude> s "heljaslkdf" Prelude> s++s "heljaslkdfheljaslkdf" Prelude> reverse s "fdklsajleh" Prelude> getLine ++ getLine :6:1: error: • Couldn't match expected type ‘[a]’ with actual type ‘IO String’ • In the first argument of ‘(++)’, namely ‘getLine’ In the expression: getLine ++ getLine In an equation for ‘it’: it = getLine ++ getLine • Relevant bindings include it :: [a] (bound at :6:1) :6:12: error: • Couldn't match expected type ‘[a]’ with actual type ‘IO String’ • In the second argument of ‘(++)’, namely ‘getLine’ In the expression: getLine ++ getLine In an equation for ‘it’: it = getLine ++ getLine • Relevant bindings include it :: [a] (bound at :6:1) Prelude> :t writeFile writeFile :: FilePath -> String -> IO () Prelude> writeFile "hello.txt" "Hello Haskell!" Prelude> text <- readFile "hello.txt" Prelude> text "Hello Haskell!" Prelude> :t text text :: String Prelude> :t readFile readFile :: FilePath -> IO String Prelude> :t readLn readLn :: Read a => IO a Prelude> :l InputOutput.hs [1 of 1] Compiling Main ( InputOutput.hs, interpreted ) Ok, one module loaded. *Main> show show showList showString shows showChar showParen showTheDifference1 showsPrec *Main> showTheDifference1 Enter two numbers: 15 12 The difference is: 3 *Main> showTheDifference1 Enter two numbers: 15 alskjdf *** Exception: user error (Prelude.readIO: no parse) *Main> readLn :: IO Bool True True *Main> readLn :: IO Bool kalhjsf *** Exception: user error (Prelude.readIO: no parse) *Main> readLn :: IO String "laksjhf" "laksjhf" *Main> readLn :: IO String lkasjdf *** Exception: user error (Prelude.readIO: no parse) *Main> getLine aöslkdfj asölkdfj "a\246slkdfj as\246lkdfj" *Main> :t return return :: Monad m => a -> m a *Main> :r [1 of 1] Compiling Main ( InputOutput.hs, interpreted ) Ok, one module loaded. *Main> getTheDifference Enter two numbers: 15 12 3 *Main> diff <- getTheDifference Enter two numbers: 15 12 *Main> diff 3 *Main> :r [1 of 1] Compiling Main ( InputOutput.hs, interpreted ) Ok, one module loaded. *Main> showTheDifference2 Enter two numbers: 15 12 The difference is: 3 *Main> :r [1 of 1] Compiling Main ( InputOutput.hs, interpreted ) Ok, one module loaded. *Main> sortFile "example.txt" "example-sorted.txt" *Main> :r [1 of 1] Compiling Main ( InputOutput.hs, interpreted ) Ok, one module loaded. *Main> doTwice getLine abcde 1234 ("abcde","1234") *Main> :r [1 of 1] Compiling Main ( InputOutput.hs, interpreted ) Ok, one module loaded. *Main> getTheDifference2 Enter two numbers: 15 12 3 *Main> :r [1 of 1] Compiling Main ( InputOutput.hs, interpreted ) Ok, one module loaded. *Main> numbers 10 10 9 8 7 6 5 4 3 2 1 *Main> Leaving GHCi. ouzo2:code$ ls /usr/share/dict/ README connectives propernames web2 web2a words ouzo2:code$ less /usr/share/dict/words ouzo2:code$ wc /usr/share/dict/words 235886 235886 2493109 /usr/share/dict/words ouzo2:code$ ghci Hangman.hs [1 of 1] Compiling Main ( Hangman.hs, interpreted ) Ok, one module loaded. *Main> :t randomRIO randomRIO :: System.Random.Random a => (a, a) -> IO a *Main> randomRIO (1,10) 10 *Main> randomRIO (1,10) 7 *Main> randomRIO (1,10) 8 *Main> :r [1 of 1] Compiling Main ( Hangman.hs, interpreted ) Ok, one module loaded. *Main> getRandomWord "Ovidian" *Main> getRandomWord "improcurable" *Main> getRandomWord "gastaldo" *Main> getRandomWord "Cynodon" *Main> getRandomWord "rimple" *Main> getRandomWord "southlander" *Main> getRandomWord "uncountermandable" *Main> getRandomWord "middleweight" *Main> getRandomWord "wintered" *Main> getRandomWord "unafeared" *Main> getRandomWord "Platonic" *Main> getRandomWord "profundity" *Main> :r [1 of 1] Compiling Main ( Hangman.hs, interpreted ) Ok, one module loaded. *Main> main ____________ *Main> :r [1 of 1] Compiling Main ( Hangman.hs, interpreted ) Ok, one module loaded. *Main> :r [1 of 1] Compiling Main ( Hangman.hs, interpreted ) Ok, one module loaded. *Main> main ___________ Enter your guess: asjhdflkjashdf^?^?^?^?^?^U^U^CInterrupted. *Main> main _____ Enter your guess: e _____ Enter your guess: a _a__a Enter your guess: s _a__a Enter your guess: p _a__a Enter your guess: t _a__a Enter your guess: b _a__a Enter your guess: f fa__a Enter your guess: n fa__a Enter your guess: u fa__a You lost! Game over! The word was: facia *Main> :r [1 of 1] Compiling Main ( Hangman.hs, interpreted ) Ok, one module loaded. *Main> main ___________ Number of guesses left: 15 Enter your guess: e __e_e___e__ Number of guesses left: 14 Enter your guess: r _re_er_re__ Number of guesses left: 13 Enter your guess: g _re_ergre__ Number of guesses left: 12 Enter your guess: p pre_ergre__ Number of guesses left: 11 Enter your guess: d pre_ergre__ Number of guesses left: 10 Enter your guess: s pre_ergress Number of guesses left: 9 Enter your guess: t pretergress Number of guesses left: 8 You won! *Main> Leaving GHCi. ouzo2:code$