Skip to content

Commit

Permalink
code for hw8ex4 of edx fp101 course
Browse files Browse the repository at this point in the history
  • Loading branch information
PotHix committed Dec 8, 2015
1 parent 51c6f11 commit 5a2a267
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions haskell/functional-programming-101-edx/interactive_programs/ex4.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
putStr' :: String -> IO ()
putStr' [] = return ()
putStr' (x : xs) = putChar x >> putStr' xs

putStrLn' :: String -> IO ()
putStrLn' [] = putChar '\n'
putStrLn' xs = putStr' xs >> putStrLn' ""

getLine' = getc []
getc :: String -> IO String
getc xs = do x <- getChar
case x of
'\n' -> return xs
_ -> getc (xs ++ [x])

interact'a :: (String -> String) -> IO ()
interact'a f = do input <- getLine'
putStrLn' (f input)

interact'b :: (String -> String) -> IO ()
interact'b f = do input <- getLine'
putStrLn' input

-- interact'c :: (String -> String) -> IO ()
-- interact'c f = do input <- getChar
-- putStrLn' (f input)

interact'd :: (String -> String) -> IO ()
interact'd f = do input <- getLine'
putStr' (f input)

0 comments on commit 5a2a267

Please sign in to comment.