<div dir="ltr">I have a code that reads files and parses using UU.Parsing lib that returns an abstract sintax tree and shows on the screen.<br><br>I received the error message "No instance for Show" in my functions originated intokensParserToByteString and applyParser using parseIO (of UU.Parsing lib) and inherited signatures until main. I fixed the signatures but my problem is in the main function. I added the instance Show in the signature but I have the next compilation error:<br><br><br><div>No instance for (Show (IO J2s)) arising from a use of ‘main’<br>In the expression: main<br>When checking the type of the IO action ‘main’<br><br>Some idea, about the problem?<br><br>Main module<br>-----------------------------------------------------------------------<br>{-# LANGUAGE FlexibleContexts #-}<br>module Main where<br><br>import UU.Parsing<br>...<br>import Content<br><br>main :: (Show (IO J2s)) => IO()<br>main = do f <- getLine<br> let command = test f<br> command<br><br>test :: (Show (IO J2s)) => String -> IO()<br>test "testparser" = testParser<br><br>Test module<br>-----------------------------------------------------------------------<br>{-# LANGUAGE FlexibleContexts #-}<br>module J2s.Parser.Test where<br><br>import Content<br>import J2s.Ast.Sintax<br>import J2s.Parser<br>import UU.Parsing<br>...<br><br>testParser :: (Show (IO J2s)) => IO()<br>testParser = (runSafeIO $ runProxy $ runEitherK $<br> contentsRecursive "path/of/my/tests" />/ handlerParser) :: (Show (IO J2s)) => IO()<br><br>Content module<br>-----------------------------------------------------------------------<br>{-# LANGUAGE FlexibleContexts #-}<br>module Content where<br><br>import Control.Monad(forM, liftM)<br>import System.Directory (doesDirectoryExist, getDirectoryContents)<br>import System.FilePath ((</>), splitExtension, splitFileName)<br>import J2s.Parser<br>import J2s.Ast.Sintax<br>import UU.Parsing<br><br>import Control.Monad (when, unless)<br>import Control.Proxy<br>import Control.Proxy.Safe hiding (readFileS)<br><br>import J2s.Scanner.Token<br>import Text.Show<br><br>import UU.Parsing<br><br><br>contentsRecursive<br> :: (CheckP p)<br> => FilePath -> () -> Producer (ExceptionP p) FilePath SafeIO ()<br>contentsRecursive path () = loop path<br> where<br> loop path = do<br> contents path () //> \newPath -> do<br> respond newPath<br> isDir <- tryIO $ doesDirectoryExist newPath<br> let isChild = not $ takeFileName newPath `elem` [".", ".."]<br> when (isDir && isChild) $ loop newPath<br><br><br>applyParser :: (Proxy p, Show (IO J2s)) => String -> Consumer p B.ByteString IO ()<br>applyParser path = runIdentityP loop<br> where<br> loop = do<br> bs <- request ()<br> let sc = classify (initPos path) (B8.unpack bs)<br> lift $ B8.putStrLn (tokensParserToByteString sc)<br><br>tokensParserToByteString :: (Show (IO J2s)) => [Token] -> B.ByteString<br>tokensParserToByteString tokens = B8.pack(show (parseIO pJ2s tokens))<br><br><br>handlerParser :: (CheckP p, Show (IO J2s)) => FilePath -> Session (ExceptionP p) SafeIO ()<br>handlerParser path = do<br> canRead <- tryIO $ fmap readable $ getPermissions path<br> isDir <- tryIO $ doesDirectoryExist path<br> isValidExtension <- tryIO $ evaluate ((snd (splitExtension path) == ".java" || snd (splitExtension path) == ".mora") && (snd (splitFileName path) /= "EncodeTest.java") && (snd (splitFileName path) /= "T6302184.java") && (snd (splitFileName path) /= "Unmappable.java"))<br> when (not isDir && canRead && isValidExtension) $<br> (readFileSP 10240 path >-> try . applyParser) path<br><br><br>readFileSP<br>:: (CheckP p)<br>=> Int -> FilePath -> () -> Producer (ExceptionP p) B.ByteString SafeIO ()<br>readFileSP chunkSize path () =<br> bracket id (openFile path ReadMode) hClose $ \handle -> do<br> let loop = do<br> eof <- tryIO $ hIsEOF handle<br> unless eof $ do<br> bs <- tryIO $ B.hGetSome handle chunkSize<br> respond bs<br> loop<br> loop<br><br><br><br>--<br>Tatiana Andrea Moruno Rodriguez<br>
</div></div>