Created
May 11, 2017 11:06
-
-
Save HisashiQ/9e8ab1d64a4f3e928f126e84e65ba6c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Vowel IO Question -- | |
numVowels :: String -> Int | |
numVowels [] = 0 | |
numVowels (x:xs) = if elem x vowels then 1 + numVowels xs else numVowels xs | |
where vowels = ['a','e','i','o','u'] | |
vowelIO :: IO () | |
vowelIO = do | |
putStr "I'll count the vowels. Enter a word\n" | |
word <- getLine | |
let a = numVowels word | |
putStr (show a) | |
putStr "\n" | |
-- Sum up IO -- | |
sum' :: [Char] -> Int | |
sum' [] = 0 | |
sum' (x:xs) = (read [x] :: Int) + sum' xs | |
sumIO = do | |
putStr "Enter numbers to sum up without spaces\n" | |
numbers <- getLine | |
let a = sum' numbers | |
putStr (show a) | |
putStr "\n" | |
-- Get file info | |
getLines :: String -> [String] | |
getWords :: [String] -> [[String]] | |
getLines x = lines x | |
getWords [] = [] | |
getWords (x:xs) = words x : getWords xs | |
wordList :: String -> [[String]] | |
wordList x = getWords $ getLines x | |
countWords [] = 0 | |
countWords (x:xs) = length x + countWords xs | |
countLines x = length $ getLines x | |
linesIO = do | |
file <- getLine | |
a <- readFile file | |
let b = countWords $ wordList a | |
let h = countLines a | |
putStr ("Lines = " ++ (show h) ++ "\n") | |
putStr ("Words = " ++ (show b) ++ "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment