Thorsten Altenkirch
2018-03-07 13:58:12 UTC
Using coinductive types as records I can write
record Stream (A : Set) : Set where
coinductive
field
hd : A
tl : Stream A
and then use copatterns to define cons (after open Stream)
_â·_ : {A : Set} â A â Stream A â Stream A
hd (x â· xs) = x
tl (x â· xs) = xs
Actually I wouldn't mind writing
record Stream (A : Set) : Set where
coinductive
field
hd : Stream A â A
tl : Stream A â Stream A
as in inductive definitions we also write the codomain even though we know what it has to be. However, this is more interesting for families because we should be able to write
record Vec (A : Set) : â â Set where
coinductive
field
hd : â{n} â Vec A (suc n) â A
tl : â{n} â Vec A (suc n) â Vec A n
and we can derive [] and cons by copatterns:
[] : Vec A zero
[] ()
_â·_ : {A : Set} â A â Vec A n â Vec A (suc n)
hd (x â· xs) = x
tl (x â· xs) = xs
here [] is defined as a trivial copattern (no destructor applies). Actually in this case the inductive and the coinductive vectors are isomorphic. A more interesting use case would be to define coinductive vectors indexed by conatural numbers. And I have others. :-)
Maybe this has been discussed already? I haven't been able to go to AIMs for a while.
Thorsten
This message and any attachment are intended solely for the addressee
and may contain confidential information. If you have received this
message in error, please contact the sender and delete the email and
attachment.
Any views or opinions expressed by the author of this email do not
necessarily reflect the views of the University of Nottingham. Email
communications with the University of Nottingham may be monitored
where permitted by law.
record Stream (A : Set) : Set where
coinductive
field
hd : A
tl : Stream A
and then use copatterns to define cons (after open Stream)
_â·_ : {A : Set} â A â Stream A â Stream A
hd (x â· xs) = x
tl (x â· xs) = xs
Actually I wouldn't mind writing
record Stream (A : Set) : Set where
coinductive
field
hd : Stream A â A
tl : Stream A â Stream A
as in inductive definitions we also write the codomain even though we know what it has to be. However, this is more interesting for families because we should be able to write
record Vec (A : Set) : â â Set where
coinductive
field
hd : â{n} â Vec A (suc n) â A
tl : â{n} â Vec A (suc n) â Vec A n
and we can derive [] and cons by copatterns:
[] : Vec A zero
[] ()
_â·_ : {A : Set} â A â Vec A n â Vec A (suc n)
hd (x â· xs) = x
tl (x â· xs) = xs
here [] is defined as a trivial copattern (no destructor applies). Actually in this case the inductive and the coinductive vectors are isomorphic. A more interesting use case would be to define coinductive vectors indexed by conatural numbers. And I have others. :-)
Maybe this has been discussed already? I haven't been able to go to AIMs for a while.
Thorsten
This message and any attachment are intended solely for the addressee
and may contain confidential information. If you have received this
message in error, please contact the sender and delete the email and
attachment.
Any views or opinions expressed by the author of this email do not
necessarily reflect the views of the University of Nottingham. Email
communications with the University of Nottingham may be monitored
where permitted by law.