Learning Haskell

COMPUTING-BLOG
haskell programming

Tips

collection of notes and links

Random Notes about Haskell II

--
-- Copy a file in Haskell
--
import System.Directory(copyFile)

main :: IO ()
main = do 
    putStr "Enter the filename:" 
    name <- getLine 
    putStr "Enter the copy name:" 
    c_name <- getLine
    copyFile name c_name
    
--
-- Copy a file in Haskell by read it and write it again
--

import System.Environment

main = do
      [f,g] <- getArgs
      s     <- readFile f
      writeFile g s
--
-- Count file lenght string in Haskell
--
-- We use interact
-- interact    ::  (String -> String) -> IO ()
-- interact f = do s <- getContents
--                putStr (f s)

main    = interact count
count s = show (length s) ++ "\n"
--
-- Count lines in file in Haskell
--
-- We use interact and lines functions
--

main = interact (count . lines)

Useful packages in Haskell

Up to table of contents