Hello, We are two students from the University of Utrecht (the Netherlands) working on a project in Haskell. During work on the project, we encountered a problem with the 'readFile' IO Monad. readFile stops reading a file when it encounters ASCII character 26, as the following piece of coding shows. We've tested this with both the Hugs interpreter and the GHC compiler, but both encounter the same problem. Are there any known solutions for this? Regards, Richard Nieuwenhuis and Niels Reyngoud ------------ module Main where main = do let output = problemtext putStr output putStr "\n\n" writeFile "outputfile.txt" output text <- readFile "outputfile.txt" putStr text problemtext :: String problemtext = "strange\SUBstrange"
Niels Reyngoud <nreijngo@cs.uu.nl> writes:
During work on the project, we encountered a problem with the 'readFile' IO Monad. readFile stops reading a file when it encounters ASCII character 26, as the following piece of coding shows.
Hmm...let me try: % ghci ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Inter[..], v[..] 5.04.2, for H[..] 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \____/\/ /_/\____/|_| Type :? for help. [...] Prelude> writeFile "test.txt" ("1234567890"++ Char.chr 26 : "abcdefgh") Prelude> readFile "test.txt" Prelude> it "1234567890\SUBabcdefgh" Prelude> map Char.ord it [49,50,51,52,53,54,55,56,57,48,26,97,98,99,100,101,102,103,104] Seems to work fine for me. What GHC version/OS/architecture are you using? -kzm -- If I haven't seen further, it is by standing in the footprints of giants
Hi all, since the content of this list is in general so completely beyond my feeble Haskell comprehension, I feel I must make a nuisance of myself with some inane criticism of the GHCi ASCII art ... !
% ghci ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Inter[..], v[..] 5.04.2, for H[..] 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \____/\/ /_/\____/|_| Type :? for help.
Aaaargh... Surley there is an arty type out there who can improve on that illegible mess which is believe, supposed to be "GHCi" ! John
[23.05.03] jss:
Hi all,
since the content of this list is in general so completely beyond my feeble Haskell comprehension, I feel I must make a nuisance of myself with some inane criticism of the GHCi ASCII art ... !
% ghci ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Inter[..], v[..] 5.04.2, for H[..] 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \____/\/ /_/\____/|_| Type :? for help.
Aaaargh...
Surley there is an arty type out there who can improve on that illegible mess which is believe, supposed to be "GHCi" !
Yup: $ alias ghci="echo ; figlet -f smshadow GHCi ; ghci -v0" $ ghci __| | | __|_) (_ | __ | ( | \___|_| _|\___|_| Prelude> -- Don ;)
not sure about the numbers, but this sounds like the old windows ms-dos mess. for backwards compatability with dos, windows won't read text files past a certain character (which might be Ctrl-Z). most languages let you specify that a file should be opened for binary rather than text reading (which has no effect in unix, but is necessary to avoid this problem on win32). haskell doesn't (afaik) support binary io in the standard (although ghc has appropriate extensions), but maybe there's some parameter you can specify when opening the file? andrew Niels Reyngoud <nreijngo@cs.uu.nl> writes:
We are two students from the University of Utrecht (the Netherlands) working on a project in Haskell. During work on the project, we encountered a problem with the 'readFile' IO Monad. readFile stops reading a file when it encounters ASCII character 26, as the following piece of coding shows. We've tested this with both the Hugs interpreter and the GHC compiler, but both encounter the same problem. Are there any known solutions for this?
Hi. Well I have no idea which is the ASCII character 26 but remember that it will stop if it encounters a EOF character (Although that doesn't seem to be the case). Why don't you try Openfile to see if it gives same error?? Something like: main = do let output = problemtext putStr output putStr "\n\n" writeFile "outputfile.txt" output text <- openFile "outputfile.txt" ReadMode y <- hGetContents text PutStr y If problem persists you could use the IOExts Library (I believe that it is only found in ghc) and read it in binary mode. Something like: Import IOExts main = do let output = problemtext putStr output putStr "\n\n" writeFile "outputfile.txt" output text <- openFileEx "outputfile.txt" (BinaryMode ReadMode) y <- hGetContents text PutStr y Remember to use lang package in case you compile it. Let us know how you get on. Best Regards NooK ----- Original Message ----- From: "Niels Reyngoud" <nreijngo@cs.uu.nl> To: <haskell@haskell.org> Sent: Friday, May 23, 2003 10:07 AM Subject: Problems with 'readFile'
Hello,
We are two students from the University of Utrecht (the Netherlands) working on a project in Haskell. During work on the project, we encountered a problem with the 'readFile' IO Monad. readFile stops reading a file when it encounters ASCII character 26, as the following piece of coding shows. We've tested this with both the Hugs interpreter and the GHC compiler, but both encounter the same problem. Are there any known solutions for this?
Regards, Richard Nieuwenhuis and Niels Reyngoud
------------
module Main where
main = do let output = problemtext putStr output putStr "\n\n" writeFile "outputfile.txt" output text <- readFile "outputfile.txt" putStr text
problemtext :: String problemtext = "strange\SUBstrange"
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
participants (6)
-
Alexandre Weffort Thenorio -
andrew cooke -
dons@cse.unsw.edu.au -
John Sincock -
ketil@ii.uib.no -
Niels Reyngoud