[darcs-users] Institutional knowledge: Darcs/IO.hs

Jason Dagit dagit at codersbase.com
Sun Jan 10 01:47:32 UTC 2010


Hello,

My question:
~~~~~~~~~~
Is there anyone around who remembers the purpose of the Darcs.IO module
and/or history?  I'd like to learn more about the why and how before I dive
in and make changes.


Background on my question:
~~~~~~~~~~~~~~~~~~~~~~~
I modified some of the basic darcs types like this:

\begin{code}
data Prim C(x y) where
    Move :: !FileName -> !FileName -> Prim C(x y)
    DP :: !FileName -> !(DirPatchType C(x y)) -> Prim C(x y)
    FP :: !FileName -> !(FilePatchType C(x y)) -> Prim C(x y)
    Split :: FL Prim C(x y) -> Prim C(x y)
    Identity :: Prim C(x x)
    ChangePref :: !String -> !String -> !String -> Prim C(x y)

data FilePatchType C(x y) = RmFile | AddFile
                          | Hunk !Int !HunkHandle
                          | TokReplace !String !String !String
                          | Binary !HunkHandle
                            deriving (Eq,Ord)

data DirPatchType C(x y) = RmDir | AddDir
                           deriving (Eq,Ord)

data HunkHandle = HH { hhFile      :: !FileName
                     , hhOffset    :: !Int
                     , hhOldLength :: !Int
                     , hhNewLength :: !Int
                     }
     deriving (Eq, Ord)

data HunkContent = HC { hcOffset :: !Int
                      , hcOld :: ![B.ByteString]
                      , hcNew :: ![B.ByteString]
                      }
\end{code}

This means that when you have a list of Prims you are holding only enough
information to go retrieve the HunkContent from the patch file (which
presumably has been scanned once to calculate the hunk handles).

That leads to a function like this:
\begin{code}
readHunkHandle :: HunkHandle -> IO HunkContent
\end{code}

I've made this change all throughout the code base and inserted comments and
undefined everywhere that I didn't know how to make an immediate fix.  I'm
going through and trying to fix those less obvious places.  In the Apply
class we use WriteableDirectory m instead of directly using IO in the
types.  This makes me think that readHunkHandle should have type:
\begin{code}
readHunkHandle :: WriteableDirectory m => HunkHandle -> m HunkContent
\end{code}

Does this look right to anyone else?  Since WriteableDirectory has an
instance for IO, I think the first type would work but maybe if I use IO
directly I'm violating some design principle here?

Thanks,
Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osuosl.org/pipermail/darcs-users/attachments/20100109/6a7d1900/attachment.htm>


More information about the darcs-users mailing list