[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 14:48:50 UTC 2010


The following commit has been merged in the master branch:
commit 59d3299acfe2257aa61d45635b53592c748b33e4
Author: John Goerzen <jgoerzen at complete.org>
Date:   Wed Dec 1 05:21:19 2004 +0100

    Checkpointing docs
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--0.5--patch-135)

diff --git a/ChangeLog b/ChangeLog
index 5c79263..ad3d748 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,18 @@
 # arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--0.5
 #
 
+2004-11-30 22:21:19 GMT	John Goerzen <jgoerzen at complete.org>	patch-135
+
+    Summary:
+      Checkpointing docs
+    Revision:
+      missingh--head--0.5--patch-135
+
+
+    modified files:
+     ChangeLog libsrc/MissingH/ConfigParser.hs
+
+
 2004-11-30 21:58:43 GMT	John Goerzen <jgoerzen at complete.org>	patch-134
 
     Summary:
diff --git a/libsrc/MissingH/ConfigParser.hs b/libsrc/MissingH/ConfigParser.hs
index 18ae7de..5a369f8 100644
--- a/libsrc/MissingH/ConfigParser.hs
+++ b/libsrc/MissingH/ConfigParser.hs
@@ -67,6 +67,9 @@ module MissingH.ConfigParser
      -- ** Combined Error\/IO Monad Usage
      -- $usageerroriomonad
 
+     -- ** Configuring the ConfigParser
+     -- $configuringcp
+
      -- * Types
      SectionSpec, OptionSpec, ConfigParser(..),
      CPErrorData(..), CPError, CPResult,
@@ -629,6 +632,62 @@ This returns @[\"opt1\", \"opt2\"]@.  A quite normal value.
 
 {- $usageerroriomonad
 
+You've seen a nice way to use this module in the Error monad and get an Either
+value out.  But that's the Error monad, so IO is not permitted.  
+Using Haskell's monad transformers, you can run it in the combined
+Error\/IO monad.  That is, you will get an IO result back.  Here is a full
+standalone example of doing that:
+
+import MissingH.ConfigParser
+import Control.Monad.Error
+
+>main = do
+>          rv <- runErrorT $
+>              do
+>              cp <- join $ liftIO $ readfile empty "/etc/passwd"
+>              let x = cp
+>              liftIO $ putStrLn "In the test"
+>              nb <- get x "DEFAULT" "nobody"
+>              liftIO $ putStrLn nb
+>              foo <- get x "DEFAULT" "foo"
+>              liftIO $ putStrLn foo
+>              return "done"
+>          print rv
+
+On my system, this prints:
+
+>In the test
+>x:65534:65534:nobody:/nonexistent:/bin/sh
+>Left (NoOption "foo","get")
+
+That is, my @\/etc\/passwd@ file contains a @nobody@ user but not a @foo@ user.
+
+Let's look at how that works.
+
+First, @main@ always runs in the IO monad only, so we take the result from
+the later calls and put it in @rv at .  Note that the combined block
+is started with @runErrorT $ do@ instead of just @do at .
+
+To get something out of the call to 'readfile', we use
+ at join $ liftIO $ readfile at .  This will bring the result out of the IO monad
+into the combined monad and process it like usual.  From here on,
+everything looks normal, except for IO calls.  They are all executed under
+ at liftIO@ so that the result value is properly brought into the combined
+monad.  This finally returns @\"done\"@.  Since we are in the Error monad, that means that the literal value is @Right \"done\"@.  Since we are also in the IO
+monad, this is wrapped in IO.  So the final return type after applying
+ at runErrorT@ is @IO (Either CPError String)@.
+
+In this case, there was an error, and processing stopped at that point just
+like the example of the pure Error monad.  We print out the return value,
+so you see the error displayed as a @Left@ value.
+
+It all works quite easily.
+
+-}
+
+{- $configuringcp
+
+FIXME: start here
 -}
 
 {- $reading

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list