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

Comments

Projects
None yet
2 participants
@ice1000
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

This comment has been minimized.

Member

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

This comment has been minimized.

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

This comment has been minimized.

Member

ice1000 commented Aug 4, 2018

Ok thanks

@ice1000 ice1000 closed this Aug 4, 2018

@ice1000

This comment has been minimized.

Member

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

This comment has been minimized.

Member

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

This comment has been minimized.

Member

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