[darcs-users] darcs patch: Is this Monadish?

Jason Dagit dagit at codersbase.com
Fri Aug 29 06:49:55 UTC 2008


I have a problem that is somewhat orthogonal to the type witness stuff
and I'm not sure what to do about it.  I'll see what you guys think.

withRepository :: [DarcsFlag] -> (forall p C(r u). RepoPatch p => RIO
p C(r u r r) a -> IO a) -> IO a
withRepository opts1 = withRepositoryDirectory opts1 "."

withRepositoryDirectory :: forall a. [DarcsFlag] -> String
                        -> (forall p C(r u). RepoPatch p => RIO p C(r
u r r) a -> IO a) -> IO a
withRepositoryDirectory opts1 url job =
    do Repo dir opts rf rt <- identifyDarcs1Repository opts1 url
       let rt_ = case rt of DarcsRepository t c -> DarcsRepository t c
       if format_has Darcs2 rf
         then do debugMessage $ "Identified darcs-2 repo: " ++ dir
                 unsafeUnRIO job1_ ((Repo dir opts rf rt_) ::
Repository (FL RealPatch) C(r u r))
         else do debugMessage $ "Identified darcs-1 repo: " ++ dir
                 unsafeUnRIO job2_ ((Repo dir opts rf rt) ::
Repository Patch C(r u r))
  where job1_ :: RIO (FL RealPatch) C(r u r r) a -> IO a
        job1_ = job
        job2_ :: RIO Patch C(r u r r) a -> IO a
        job2_ = job

This gives an obnoxious type error like so:
src/Darcs/Repository/Internal.lhs:740:29:
    Couldn't match expected type `RIO p r u t t1 a'
           against inferred type `RIO Patch r1 u1 r1 r1 a -> IO a'
    In the first argument of `unsafeUnRIO', namely `job2_'
    In the expression:
        unsafeUnRIO job2_ ((Repo dir opts rf rt) :: Repository Patch r u r)
    In the expression:
        if format_has Darcs2 rf then
            do debugMessage $ "Identified darcs-2 repo: " ++ dir
             undefined
        else
            do debugMessage $ "Identified darcs-1 repo: " ++ dir
             unsafeUnRIO job2_ ((Repo dir opts rf rt) :: Repository Patch r u r)

All I've changed here is adding the unsafeUnRIO and the type
signatures, and yet it worked before.

I'm a bit confused by it.

Thanks,
Jason


More information about the darcs-users mailing list