crislanio_macedo Posted April 19, 2015 at 07:13 PM Report Share #581502 Posted April 19, 2015 at 07:13 PM (edited) Olá a todos, estou a fazer um programa bem simples onde tenho que listar o número de palavras e linhas de um arquivo dado como entrada. Seque o código abaixo para verificaçaõ. module Main where -- ghc teste.hs -o teste -- cat arquivo.txt | ./teste main = do linhas <- interact (show.length.lines) palavras <- interact (show.length.words) putStrLn $ "Numero de linhas: " ++ show linhas ++ " " putStrLn $ "Numero de palavras: " ++ show palavras ++ " " contudo quando execulto: ghc teste.hs -o teste cat arquivo.txt | ./teste acontece o sequinte: $ cat arquivo.txt | ./teste 2teste: : hGetContents: illegal operation (handle is closed) Me ajudem, nesse assunto de IO, pois ainda estou a ter sérias dificuldades em alguns aspectos. http://www.crislaniomacedo.zz.vc/ Edited April 19, 2015 at 07:14 PM by crislanio_macedo Link to comment Share on other sites More sharing options...
pdfrod Posted April 19, 2015 at 07:27 PM Report Share #581504 Posted April 19, 2015 at 07:27 PM O interact consome todo o input, portanto não podes usar duas vezes. À segunda utilização dá erro pois já não há mais input para consumir. Link to comment Share on other sites More sharing options...
crislanio_macedo Posted April 19, 2015 at 08:03 PM Author Report Share #581507 Posted April 19, 2015 at 08:03 PM O interact consome todo o input, portanto não podes usar duas vezes. À segunda utilização dá erro pois já não há mais input para consumir. entao como faria para que mostrasse o total de linhas e palavras ? Ou seja como faria para que o interact mostrasse isso Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now