User Tools

Site Tools


codesnippets:filesystemioandstreams

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
codesnippets:filesystemioandstreams [2021/04/22 11:43] f2b216codesnippets:filesystemioandstreams [2025/10/08 00:48] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +~~DISCUSSION ~~
 ====== Filesystem IO and streams ====== ====== Filesystem IO and streams ======
  
Line 146: Line 147:
     * compiles, error and warning free, with compiler: GHC 8.10.4, using compiler option -Wall     * compiles, error and warning free, with compiler: GHC 8.10.4, using compiler option -Wall
     * executes with output as file copy of "a.txt" to "b.txt", ''stdout'', and ''stderr''     * executes with output as file copy of "a.txt" to "b.txt", ''stdout'', and ''stderr''
 +  * example, with conversions
 +    * code:<code Haskell>
 +import qualified FileSystem as FS
 +import qualified System.IO as SysIo
 +import qualified Data.Char as Ch
 +
 +main :: IO ()
 +main = 
 +        FS.processData
 +            (FS.DataReader (FS.FileInp ".\\test\\a.txt") hGetToUpper)
 +            [
 +                FS.DataWriter (FS.FileOut ".\\test\\b.txt") SysIo.hPutStr, 
 +                FS.DataWriter FS.StdOut hPutToLower, 
 +                FS.DataWriter FS.StdErr SysIo.hPutStr
 +            ]
 +
 +hGetToUpper :: SysIo.Handle -> IO String
 +hGetToUpper h = 
 +    do
 +        s <- SysIo.hGetContents h
 +        return (fmap Ch.toUpper s)
 +
 +hPutToLower :: SysIo.Handle -> String -> IO ()
 +hPutToLower h s = SysIo.hPutStr h (fmap Ch.toLower s)
 +</code>
 +    * input, file "a.txt"<code>
 +The quick brown fox jumps over the lazy dog.
 +</code>
 +    * output, in terminal:<code>
 +the quick brown fox jumps over the lazy dog.
 +THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.
 +</code>
 +    * output, file "b.txt":<code>
 +THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.
 +</code>
 +
 +
 +===== ✎ =====
 +~~DISCUSSION~~
codesnippets/filesystemioandstreams.1619084627.txt.gz · Last modified: (external edit)

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki