Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not parse with pattern #3172

Closed
ice1000 opened this issue Aug 4, 2018 · 6 comments
Closed

Could not parse with pattern #3172

ice1000 opened this issue Aug 4, 2018 · 6 comments
Labels
faq User question (not in changelog) scope Issues relating to scope checking with Problems with the "with" abstraction

Comments

@ice1000
Copy link
Member

ice1000 commented Aug 4, 2018

Simple, minimum code to reproduce the error:

parseF : List ℂ  List Fmt
parseF [] = []
parseF (x ∷ xs) with xs | x ≟ '%'
...         | '%' ∷ xss | (yes y) = {!!}

The code above uses these declarations:

open import Data.List using (List; _∷_; [])
open import Data.Char renaming (Char to ℂ; show to showℂ)

data Fmt : Set where
  fmt : Fmt
  lit : Fmt

If I change (yes y) to y, the parser works. But I need to pattern match on x ≟ '%', how can I do that?

@ice1000
Copy link
Member Author

ice1000 commented Aug 4, 2018

And of course use C-c C-c to do a case split on y causes a parse error:

parseF : List ℂ  List Fmt
parseF [] = []
parseF (x ∷ xs) with xs | x ≟ '%'
parseF (x ∷ xs) | '%' ∷ xss | .Relation.Nullary.Dec.yes p = ?
parseF (x ∷ xs) | '%' ∷ xss | .Relation.Nullary.Dec.no ¬p = ?

@gallais
Copy link
Member

gallais commented Aug 4, 2018

You need to open import Relation.Nullary so that yes is in scope. Otherwise Agda
does not know about yes and thinks you are trying to declare a pattern of the form
(function argument) which is illegal.

@ice1000
Copy link
Member Author

ice1000 commented Aug 4, 2018

Ok thanks

@ice1000 ice1000 closed this as completed Aug 4, 2018
@gallais gallais added faq User question (not in changelog) with Problems with the "with" abstraction scope Issues relating to scope checking labels Aug 4, 2018
@ice1000
Copy link
Member Author

ice1000 commented Aug 4, 2018

@gallais And BTW why Agda complains about the termination of this function?

parseF : List ℂ  List Fmt
parseF [] = []
parseF (x ∷ xs) with xs | x ≟ '%'
...         | '%' ∷ xss | yes _ = lit '%' ∷ parseF xss
...         |  c  ∷ xss | yes _ = fmt c ∷ parseF xss
...         | [] | yes _ = lit '%' ∷ []
...         | _  | no  _ = lit x ∷ parseF xs

image

@ice1000
Copy link
Member Author

ice1000 commented Aug 4, 2018

While the normal form checks:

parseF : List ℂ  List Fmt
parseF [] = []
parseF ('%''%' ∷ cs) = lit '%' ∷ parseF cs
parseF ('%' ∷  c  ∷ cs) = fmt c ∷ parseF cs
parseF ( c  ∷  cs) = lit c ∷ parseF cs

@ice1000
Copy link
Member Author

ice1000 commented Aug 4, 2018

Moved discussion to #3173

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
faq User question (not in changelog) scope Issues relating to scope checking with Problems with the "with" abstraction
Projects
None yet
Development

No branches or pull requests

2 participants