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

Jason Dagit dagit at codersbase.com
Fri Aug 29 15:10:41 UTC 2008


On Fri, Aug 29, 2008 at 8:02 AM, David Roundy <daveroundy at gmail.com> wrote:
> 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:

Right, I've tried it with and without the extra type signatures.
Usually when something doesn't type check I find adding explicit
signatures improves the error messages by bringing them closer to the
problem...

>
> 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.

I just checked:
GHCi> :t Darcs.Repository.InternalTypes.unsafeUnRIO
Darcs.Repository.InternalTypes.unsafeUnRIO :: forall (p :: * -> * -> *)
                                                     r
                                                     u
                                                     t
                                                     t1
                                                     a.

Darcs.Repository.InternalTypes.RIO p r u t t1 a
                                              ->
Darcs.Repository.InternalTypes.Repository p r u t
                                              -> IO a

That's a mess to read, but basically,
unsafeUnRIO :: RIO p r u t t1 a -> Repository p r u t -> IO a

Therefore, I don't think the parens are right.  Could the problem be
with the type of unsafeUnRIO and not the instance of p?  I thought the
problem was with the instance of p, but maybe it's having issues with
unifying r and t.

Thanks,
Jason


More information about the darcs-users mailing list