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

David Roundy daveroundy at gmail.com
Fri Aug 29 15:02:37 UTC 2008


On Fri, Aug 29, 2008 at 2:49 AM, Jason Dagit <dagit at codersbase.com> wrote:
> 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

I'm not certain of the error, but it looks odd that you've got two different
typecasts each to Patch/RealPatch, and I can't help but wonder if you might
do better by taking away the first ones.  i.e. something like:

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_)
       else do debugMessage $ "Identified darcs-1 repo: " ++ dir
               unsafeUnRIO job2_ (Repo dir opts rf rt)
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

I'm not certain this will work, and suspect you've already tried it, but...
doh!

I think I see the trouble! It looks like you need parens around the

     if format_has Darcs2 rf
       then do debugMessage $ "Identified darcs-2 repo: " ++ dir
               unsafeUnRIO (job1_ (Repo dir opts rf rt_))
       else do debugMessage $ "Identified darcs-1 repo: " ++ dir
               unsafeUnRIO (job2_ (Repo dir opts rf rt))

If this isn't the problem... well, let me know, and I can help debug
further.

David

> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osuosl.org/pipermail/darcs-users/attachments/20080829/106b7fdf/attachment.htm 


More information about the darcs-users mailing list