import System.IO
--import NGramCrackers.NGramCrackers
import Data.Char (toUpper)

main = do
    inHandle   <- openFile "NGramCrackers/story.txt" ReadMode
    outHandle  <- openFile "NGramCrackers/processedStory.txt" WriteMode
--    contents <- hGetContents inHandle 
    mainLoop inHandle outHandle
    --hPutStrLn outHandle print $ bigrams contents
    hClose inHandle
    hClose outHandle

mainLoop :: Handle -> Handle -> IO ()
mainLoop inHandle outHandle = do isEnd <- hIsEOF inHandle
                                 if isEnd
                                   then return ()
                                   else do inputStr <- hGetLine inHandle
                                           hPutStrLn outHandle (map toUpper inputStr)
                                           mainLoop inHandle outHandle

import System.IO
import Text.ParserCombinators.Parsec (eof)
import NGramCrackers.NGramCrackers
import NGramCrackers.ParagraphParsers
import Data.Char (toUpper)
import Data.List (intersperse)
import Control.Monad (liftM)
import Data.Either.Unwrap (fromRight)

main = do
    inHandle   <- openFile "NGramCrackers/spacelessStory.txt" ReadMode
    outHandle  <- openFile "NGramCrackers/processedStory.txt" WriteMode
    contents <- hGetContents inHandle 
    case parseParagraph contents of 
         Left e  -> do putStrLn "Error parsing input: "
                       print e

         Right r -> mapM_ putStrLn $ liftM unwords r
    --eof

    --hPutStrLn outHandle $ (concat . intersperse "\n" . bigrams) contents
    -- putStrLn $ fromRight $ liftM concat $ liftM (intersperse "\n") $ liftM unwords $ liftM concat $ parseParagraph contents
--    putStrLn $ fromRight $ liftM unwords $ liftM (intersperse "\n") $ liftM concat $ parseParagraph contents
    hClose inHandle
    hClose outHandle

{- mainLoop :: Handle -> Handle -> IO ()
mainLoop inHandle outHandle = do isEnd <- hIsEOF inHandle
                                 if isEnd
                                   then return ()
                                   else do inputStr <- hGetLine inHandle
                                           hPutStrLn outHandle (map toUpper inputStr)
                                           mainLoop inHandle outHandle
-}

Add pattern matching for Left and Right results of parseParagraph
Add pattern matching for Left and Right results of parseParagraph

  -- The primary addition is the use of case syntax to define the
     behaviour of parseParagraph's Left and Right behaviour. Left
     prints the error to stdout.in.  Right prints each sentence on its
     own line in stdout. mapM_ is used to to map over a list to
     achieve the IO () action.

  -- Main.hs is currently very messy.

  -- It is still necessary to get this prog outputting to a new
     file.

  -- The ability to take CLI arguments would also be extremely
     helpful.

  -- I would also like to test whether it would be possible to
     output a lexemeCountProfile
