rocq-community / rocq-community/parseque
Problem with bind and contexts
Nobody has claimed this yet.
- Dominant language
- Rocq Prover
- Stars
- 51
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Description
I have the following code right now:
Require Import Category.
Require Import Sized.
Require Import Combinators.
Require Import Numbers.
Require Import NEList.
Require Import Coq.NArith.NArith.
Require Import Coq.QArith.QArith.
Require Import Ascii.
Local Open Scope char.
Require Import Coq.Lists.List.
Import ListNotations.
Section Helpers.
Context
{M : Type -> Type}
`{RF : RawFunctor M}
`{RA : RawApplicative M}
`{RM : RawMonad M}
`{RT : RawAlternative M}
{Chars : nat -> Type} `{Sized Chars ascii}
{n : nat}.
Definition decimal_digit_N : Parser Chars ascii M N n :=
alts ((0 <$ exact "0")%N
:: (1 <$ exact "1")%N
:: (2 <$ exact "2")%N
:: (3 <$ exact "3")%N
:: (4 <$ exact "4")%N
:: (5 <$ exact "5")%N
:: (6 <$ exact "6")%N
:: (7 <$ exact "7")%N
:: (8 <$ exact "8")%N
:: (9 <$ exact "9")%N
:: nil).
Definition decimal_N : Parser Chars ascii M N n :=
let convert ds := foldl (fun ih d => 10 * ih + d)%N ds 0%N
in Combinators.map convert (nelist decimal_digit_N).
Definition float_Q : Parser Chars ascii M Q n :=
decimal_N >>= fun x : N =>
match x return Parser Chars ascii M Q n with
| N0 => (Qmake <$> decimal_int) <*> pure 1%positive
| Npos p => (Qmake <$> decimal_int) <*> pure p
end.
End Helpers.
When I tried to type check float_Q, I get:
Error:
Unable to satisfy the following constraints:
In environment:
M : Type -> Type
RF, H : RawFunctor M
RA : RawApplicative M
H0 : RawFunctor M
H1 : RawApplicative M
RM : RawMonad M
H2 : RawFunctor M
H3 : RawApplicative M
RT : RawAlternative M
Chars : nat -> Type
H4 : Sized Chars ascii
n : nat
x : N
?F : "Type -> Type"
?H : "RawFunctor ?F"
?H0 : "RawApplicative ?F"
As you can see, there are somehow three RawFunctor M instances in scope, which I don't quite understand. I've tried various combinations of explicit arguments, but I was wondering if you could help me understand what I'm doing wrong here?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the type-checking failure in float_Q after loading the listed imports, then inspect the inferred context around the bind expression and its match branches. Compare the RawFunctor and RawApplicative constraints introduced by decimal_N and the branch parsers; done means explaining the extra instances and identifying a type-checking resolution.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100