Agda: type isn't simplified in `with` block -


i'm trying solve bonus exercise on page 23 of this tutorial, can't fill in hole:

lem-all-filter : {a : set}(xs : list a)(p : -> bool)               -> (satisfies p) (filter p xs) lem-all-filter [] p = all[] lem-all-filter (x :: xs) p p x ... | true = {! !} :all: lem-all-filter xs p ... | false = lem-all-filter xs p 

if type c-c c-, in hole message:

goal: istrue (p x) -------------------------------- xs : list .a p  : .a -> bool x  : .a .a : set 

but expect goal have type true, since p x true , istrue true = true. missing something?

when pattern match on p x, p x gets rewritten pattern everywhere in context, hole not in context @ time of rewriting: appears later , hence p x in type doesn't rewritten. can remember p x equal true using inspect idiom (deprecated in favour of inspect on steroids) described later in paper, can following:

lem-all-filter : {a : set}(xs : list a)(p : -> bool)               -> (satisfies p) (filter p xs) lem-all-filter [] p = all[] lem-all-filter (x :: xs) p p x | λ (y : istrue (p x)) -> y :all: lem-all-filter xs p ... | true  | ontrue = ontrue _ ... | false | ontrue = lem-all-filter xs p 

here explicitly introduce type of argument :all: in context , hence when p x gets rewritten true, type of ontrue reduces true -> (satisfies p) (x :: filter p xs) needed.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -