From dmytro.kondratiuk at iohk.io Thu Oct 1 21:49:04 2020 From: dmytro.kondratiuk at iohk.io (Dmytro Kondratiuk) Date: Fri, 2 Oct 2020 02:49:04 +0700 Subject: [Agda-dev] Fwd: Agda as a target language In-Reply-To: References: Message-ID: Hi agda-devs! I'd like to use Agda as a target language in a code generator. Here's a short description of the problem: I have logic (written in Haskell) that allows me to generate business rules in a given target language, which is currently an embedded DSL. I'd like to prove certain properties about those rules, but I'd prefer to avoid rewriting them manually in Agda (it is a large ever growing specification with tons of formulas from the financial domain). Instead my goal is to generate Agda code automatically and then create proofs on top of the generated code. Is there a convenient API in Agda's compiler that would allow me to safely generate Agda syntax tree and pretty-print it into .agda file? Any examples? P.S. Agda.Syntax.Concrete.Pretty seems like a good candidate, though I'm not sure if it is the right way to do it. Thanks in advance, Dmytro Kondratiuk -------------- next part -------------- An HTML attachment was scrubbed... URL: From ulfn at chalmers.se Thu Oct 1 22:17:15 2020 From: ulfn at chalmers.se (Ulf Norell) Date: Thu, 1 Oct 2020 22:17:15 +0200 Subject: [Agda-dev] Fwd: Agda as a target language In-Reply-To: References: Message-ID: Yes, probably Agda.Syntax.Concrete(.Pretty) is your best bet. This is the AST before desugaring, scope checking and type checking, so it will give you the most flexibility. / Ulf On Thu, Oct 1, 2020 at 9:49 PM Dmytro Kondratiuk wrote: > Hi agda-devs! > > I'd like to use Agda as a target language in a code generator. Here's a > short description of the problem: > I have logic (written in Haskell) that allows me to generate business > rules in a given target language, which is currently an embedded DSL. > > I'd like to prove certain properties about those rules, but I'd prefer to > avoid rewriting them manually in Agda (it is a large ever growing > specification with tons of formulas from the financial domain). > Instead my goal is to generate Agda code automatically and then create > proofs on top of the generated code. > > Is there a convenient API in Agda's compiler that would allow me to safely > generate Agda syntax tree and pretty-print it into .agda file? Any examples? > > P.S. Agda.Syntax.Concrete.Pretty seems like a good candidate, though I'm > not sure if it is the right way to do it. > > Thanks in advance, > Dmytro Kondratiuk > > _______________________________________________ > Agda-dev mailing list > Agda-dev at lists.chalmers.se > https://lists.chalmers.se/mailman/listinfo/agda-dev > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dmytro.kondratiuk at iohk.io Thu Oct 1 22:27:09 2020 From: dmytro.kondratiuk at iohk.io (Dmytro Kondratiuk) Date: Fri, 2 Oct 2020 03:27:09 +0700 Subject: [Agda-dev] Fwd: Agda as a target language In-Reply-To: References: Message-ID: Thanks for quick reply - I?ll try that one then. On Fri, Oct 2, 2020 at 3:17 AM Ulf Norell wrote: > Yes, probably Agda.Syntax.Concrete(.Pretty) is your best bet. This is the > AST before desugaring, scope checking and type checking, so it will give > you the most flexibility. > > / Ulf > > On Thu, Oct 1, 2020 at 9:49 PM Dmytro Kondratiuk < > dmytro.kondratiuk at iohk.io> wrote: > >> Hi agda-devs! >> >> I'd like to use Agda as a target language in a code generator. Here's a >> short description of the problem: >> I have logic (written in Haskell) that allows me to generate business >> rules in a given target language, which is currently an embedded DSL. >> >> I'd like to prove certain properties about those rules, but I'd prefer to >> avoid rewriting them manually in Agda (it is a large ever growing >> specification with tons of formulas from the financial domain). >> Instead my goal is to generate Agda code automatically and then create >> proofs on top of the generated code. >> >> Is there a convenient API in Agda's compiler that would allow me to >> safely generate Agda syntax tree and pretty-print it into .agda file? Any >> examples? >> >> P.S. Agda.Syntax.Concrete.Pretty seems like a good candidate, though I'm >> not sure if it is the right way to do it. >> >> Thanks in advance, >> Dmytro Kondratiuk >> >> _______________________________________________ >> Agda-dev mailing list >> Agda-dev at lists.chalmers.se >> https://lists.chalmers.se/mailman/listinfo/agda-dev >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From effectfully at gmail.com Mon Oct 26 03:03:08 2020 From: effectfully at gmail.com (Roman) Date: Mon, 26 Oct 2020 05:03:08 +0300 Subject: [Agda-dev] A tutorial on inference in Agda Message-ID: Hi folks, I wrote a painfully long tutorial on the way Agda does unification: https://htmlpreview.github.io/?https://github.com/effectfully/unification-in-agda/blob/master/UnificationInAgda.html It targets the users of Agda, so it doesn't cover advanced topics like higher-order unification. I'd like to hear your opinion before I share the link with a general audience. Is there something horribly wrong there? What can be improved? Are there any missing parts of the unification engine that would be nice to cover? Is the tutorial readable in general? Any kind of feedback would be highly appreciated. Please don't share the link publicly yet. BTW, I generate such HTMLs in an absolutely awful way. Does Agda support generating an HTML page (with all the coloring) from an Agda file when that file contains warnings, unresolved metas etc? And is there a flag to make Agda accept ill-typed code, show a warning and proceed with type checking? And color ill-typed code in red or something, like unresolved metas are colored in yellow. Best regards. From abela at chalmers.se Mon Oct 26 12:07:14 2020 From: abela at chalmers.se (Andreas Abel) Date: Mon, 26 Oct 2020 12:07:14 +0100 Subject: [Agda-dev] A tutorial on inference in Agda In-Reply-To: References: Message-ID: <95d4c091-c60c-f56d-5b04-a35352a361b8@chalmers.se> Hello Roman, > I wrote a painfully long tutorial on the way Agda does unification: Indeed, ;-) took my whole morning to read. But this is a very nice and comprehensive tutorial, thanks for writing all this up! I learned a few new tricks/perspectives, which I hope to remember e.g.: - _? - dependent K - Promote Below there are some comments on your text. Cheers, Andreas # Section "Implicit arguments": Exceptions to eager implicit argument insertion are so called "aliases" (x = e) like _? = _?_ which you mention in the "Basics" section. Here, we insert implicit arguments lazily (because they would **always** be unsolved otherwise, by absence of a type signature). You could mention this exception here in the text. # Arguments of data types / Comparison to Haskell I couldn't read this relative sentence at my usual speed (limits my parser stack) so I gave up on trying to comprehend it: > because it elaborates to > ... > (due to eager insertion of implicits) and the fact that there's a variable of type ? bound in the current scope (regardless of whether it's bound explicitly or implicitly) does not have any effect on how implicits get resolved in the body of the definition as metavariable resolution does not come up with instantiations for metavariables at random by looking at the local or global scope, it only determines what instantiations are bound to be by solving unification problems that arise during type checking. # Under the hood / Example 3 Small inaccuracy in > List _A (this time the type of the result that listId returns) also gets unified with the expected type, which is ? -> ?, rather: List (? -> ?) # Nicer notation Remark: > We'll denote "X uniquely determines Y" (the notation comes from the bidirectional typechecking discipline) as X ? Y. So List A ? A. Without ever having dived deeply into the technical details, this matches my intuition about Haskell's FunctionalDependencies. Unfortunately, Haskell's type constructors are not injective in that sense, due to some weird corner cases involving infinite type expressions. I always bump my head into this weakness of FunctionalDependencies, they just defy my intuition. # Type functions > Therefore, F A (where F is a bound variable) uniquely determines neither F nor A, i.e. F A !? F , A. Here you could point to the difference between first-order and higher unification. The user often expects that Agda performs first-order unification here (this is why Coq chose to facilitate also first-order unification, leading to non-unique solutions). Agda, however, only does higher-unification, and there are many solutions (as you explained). Future research could improve on unification via an analysis in which situation the chosen solution does not matter. (However, I never got around to do this research.) The example you give is such an instance: It does not matter how we solve _F _A = List Nat, because the solutions of _F and _A can never flow out of the expression fId _F _A (1 ? 2 ? []) : _F _A # Reduction Formatting problem in > head??-wrong is a contrived example, but this problem can arise in real cases, for example consider a naive attempt to define thereversefunction overVec` using an accumulator, # Pattern Matching > weird definition of the plus operator This is the accumulator-version of plus, I seem to recall it was used in the standard library (at least at some point) in connection with reverse for vectors (or something else). > So we have the following rule of thumb: whenever the type of function h mentions function f at the type level, every argument that gets pattern matched on in f (including any internal function calls) should be made explicit in h and every other argument can be left implicit (there are a few exceptions to this rule, which we'll consider below, but it applies in most cases). +1. My experience confirms this rule. # Constructor/argument-headed functions / Example 2: polyvariadic zipWith: list-based > Omitting an argument results in metas not being resolved in the version of Agda that I'm using Might be worthwhile stating the version. > _ : zipWithN _+_ (1 ?? 2 ?? 3 ?? []?) _ ? (5 ?? 7 ?? 9 ?? []?) > _ = refl > This is something that I can't explain The remaining meta is (recent master) _xs_2474 : Vec ? 0 It might stem from the laziness of `[] ?_` _?_ : ? {n} ? Vec (A ? B) n ? Vec A n ? Vec B n [] ? _ = [] (f ? fs) ? (x ? xs) = f x ? (fs ? xs) Maybe if you make it stricter, constructor-headedness kicks in. [] ? [] = [] This could be an issue to consider for the library maintainers. # (Close to the end) typo: dependenty-typed On 2020-10-26 03:03, Roman wrote: > Hi folks, > > I wrote a painfully long tutorial on the way Agda does unification: > https://htmlpreview.github.io/?https://github.com/effectfully/unification-in-agda/blob/master/UnificationInAgda.html > > It targets the users of Agda, so it doesn't cover advanced topics like > higher-order unification. > > I'd like to hear your opinion before I share the link with a general > audience. Is there something horribly wrong there? What can be > improved? Are there any missing parts of the unification engine that > would be nice to cover? Is the tutorial readable in general? Any kind > of feedback would be highly appreciated. > > Please don't share the link publicly yet. > > BTW, I generate such HTMLs in an absolutely awful way. Does Agda > support generating an HTML page (with all the coloring) from an Agda > file when that file contains warnings, unresolved metas etc? And is > there a flag to make Agda accept ill-typed code, show a warning and > proceed with type checking? And color ill-typed code in red or > something, like unresolved metas are colored in yellow. > > Best regards. > _______________________________________________ > Agda-dev mailing list > Agda-dev at lists.chalmers.se > https://lists.chalmers.se/mailman/listinfo/agda-dev > -- Andreas Abel <>< Du bist der geliebte Mensch. Department of Computer Science and Engineering Chalmers and Gothenburg University, Sweden andreas.abel at gu.se http://www.cse.chalmers.se/~abela/ From effectfully at gmail.com Mon Oct 26 21:04:54 2020 From: effectfully at gmail.com (Roman) Date: Mon, 26 Oct 2020 23:04:54 +0300 Subject: [Agda-dev] A tutorial on inference in Agda In-Reply-To: <95d4c091-c60c-f56d-5b04-a35352a361b8@chalmers.se> References: <95d4c091-c60c-f56d-5b04-a35352a361b8@chalmers.se> Message-ID: Andreas, thanks a lot for your very helpful comments! I've fixed the typos and added the acknowledgements section. I'll incorporate the rest of your feedback once I have some spare time (this weekend most likely). > Maybe if you make it stricter, constructor-headedness kicks in. > [] ? [] = [] I tried it and can confirm that the unresolved meta goes away. Which makes perfect sense, I'll reflect this in the document. Thanks again! 2020-10-26 14:07 GMT+03:00, Andreas Abel : > Hello Roman, > > > I wrote a painfully long tutorial on the way Agda does unification: > > Indeed, ;-) took my whole morning to read. > > But this is a very nice and comprehensive tutorial, thanks for writing > all this up! > > I learned a few new tricks/perspectives, which I hope to remember e.g.: > - _? > - dependent K > - Promote > > Below there are some comments on your text. > > Cheers, > Andreas > > > # Section "Implicit arguments": > > Exceptions to eager implicit argument insertion are so called "aliases" > (x = e) like > > _? = _?_ > > which you mention in the "Basics" section. Here, we insert implicit > arguments lazily (because they would **always** be unsolved otherwise, > by absence of a type signature). > > You could mention this exception here in the text. > > > # Arguments of data types / Comparison to Haskell > > I couldn't read this relative sentence at my usual speed (limits my > parser stack) so I gave up on trying to comprehend it: > > > because it elaborates to > > ... > > (due to eager insertion of implicits) and the fact that there's a > variable of type ? bound in the current scope (regardless of whether > it's bound explicitly or implicitly) does not have any effect on how > implicits get resolved in the body of the definition as metavariable > resolution does not come up with instantiations for metavariables at > random by looking at the local or global scope, it only determines what > instantiations are bound to be by solving unification problems that > arise during type checking. > > > # Under the hood / Example 3 > > Small inaccuracy in > > > List _A (this time the type of the result that listId returns) also > gets unified with the expected type, which is ? -> ?, > > rather: List (? -> ?) > > > # Nicer notation > > Remark: > > > We'll denote "X uniquely determines Y" (the notation comes from the > bidirectional typechecking discipline) as X ? Y. So List A ? A. > > Without ever having dived deeply into the technical details, this > matches my intuition about Haskell's FunctionalDependencies. > Unfortunately, Haskell's type constructors are not injective in that > sense, due to some weird corner cases involving infinite type > expressions. I always bump my head into this weakness of > FunctionalDependencies, they just defy my intuition. > > > # Type functions > > > Therefore, F A (where F is a bound variable) uniquely determines > neither F nor A, i.e. F A !? F , A. > > Here you could point to the difference between first-order and higher > unification. The user often expects that Agda performs first-order > unification here (this is why Coq chose to facilitate also first-order > unification, leading to non-unique solutions). Agda, however, only does > higher-unification, and there are many solutions (as you explained). > > Future research could improve on unification via an analysis in which > situation the chosen solution does not matter. (However, I never got > around to do this research.) > > The example you give is such an instance: It does not matter how we > solve _F _A = List Nat, because the solutions of _F and _A can never > flow out of the expression > > fId _F _A (1 ? 2 ? []) : _F _A > > > # Reduction > > Formatting problem in > > > head??-wrong is a contrived example, but this problem can arise in > real cases, for example consider a naive attempt to define > thereversefunction overVec` using an accumulator, > > > # Pattern Matching > > > weird definition of the plus operator > > This is the accumulator-version of plus, I seem to recall it was used in > the standard library (at least at some point) in connection with reverse > for vectors (or something else). > > > So we have the following rule of thumb: whenever the type of function > h mentions function f at the type level, every argument that gets > pattern matched on in f (including any internal function calls) should > be made explicit in h and every other argument can be left implicit > (there are a few exceptions to this rule, which we'll consider below, > but it applies in most cases). > > +1. My experience confirms this rule. > > > # Constructor/argument-headed functions / Example 2: polyvariadic > zipWith: list-based > > > Omitting an argument results in metas not being resolved in the > version of Agda that I'm using > > Might be worthwhile stating the version. > > > _ : zipWithN _+_ (1 ?? 2 ?? 3 ?? []?) _ ? (5 ?? 7 ?? 9 ?? []?) > > _ = refl > > > This is something that I can't explain > > The remaining meta is (recent master) > > _xs_2474 : Vec ? 0 > > It might stem from the laziness of `[] ?_` > > _?_ : ? {n} ? Vec (A ? B) n ? Vec A n ? Vec B n > [] ? _ = [] > (f ? fs) ? (x ? xs) = f x ? (fs ? xs) > > Maybe if you make it stricter, constructor-headedness kicks in. > > [] ? [] = [] > > This could be an issue to consider for the library maintainers. > > > # (Close to the end) > > typo: dependenty-typed > > > On 2020-10-26 03:03, Roman wrote: >> Hi folks, >> >> I wrote a painfully long tutorial on the way Agda does unification: >> https://htmlpreview.github.io/?https://github.com/effectfully/unification-in-agda/blob/master/UnificationInAgda.html >> >> It targets the users of Agda, so it doesn't cover advanced topics like >> higher-order unification. >> >> I'd like to hear your opinion before I share the link with a general >> audience. Is there something horribly wrong there? What can be >> improved? Are there any missing parts of the unification engine that >> would be nice to cover? Is the tutorial readable in general? Any kind >> of feedback would be highly appreciated. >> >> Please don't share the link publicly yet. >> >> BTW, I generate such HTMLs in an absolutely awful way. Does Agda >> support generating an HTML page (with all the coloring) from an Agda >> file when that file contains warnings, unresolved metas etc? And is >> there a flag to make Agda accept ill-typed code, show a warning and >> proceed with type checking? And color ill-typed code in red or >> something, like unresolved metas are colored in yellow. >> >> Best regards. >> _______________________________________________ >> Agda-dev mailing list >> Agda-dev at lists.chalmers.se >> https://lists.chalmers.se/mailman/listinfo/agda-dev >> > > -- > Andreas Abel <>< Du bist der geliebte Mensch. > > Department of Computer Science and Engineering > Chalmers and Gothenburg University, Sweden > > andreas.abel at gu.se > http://www.cse.chalmers.se/~abela/ > _______________________________________________ > Agda-dev mailing list > Agda-dev at lists.chalmers.se > https://lists.chalmers.se/mailman/listinfo/agda-dev > From abela at chalmers.se Tue Oct 27 02:05:59 2020 From: abela at chalmers.se (Andreas Abel) Date: Tue, 27 Oct 2020 02:05:59 +0100 Subject: [Agda-dev] Release candidate for Agda 2.6.1.2 Message-ID: There is now a hackage candidate release for Agda 2.6.1.2 at https://hackage.haskell.org/package/Agda-2.6.1.2/candidate Please let me know if you see something that's wrong, or this Agda fails to install... Otherwise I'll release to hackage soon and then apply for addition to Stackage nightly. Agda 2.6.1.2 is basically 2.6.1.1 with some version bumps to be compatible with Stackage nightly. Best, Andreas -- Andreas Abel <>< Du bist der geliebte Mensch. Department of Computer Science and Engineering Chalmers and Gothenburg University, Sweden andreas.abel at gu.se http://www.cse.chalmers.se/~abela/ From asr at eafit.edu.co Tue Oct 27 21:46:34 2020 From: asr at eafit.edu.co (=?UTF-8?B?QW5kcsOpcyBTaWNhcmQtUmFtw61yZXo=?=) Date: Tue, 27 Oct 2020 15:46:34 -0500 Subject: [Agda-dev] Release candidate for Agda 2.6.1.2 In-Reply-To: References: Message-ID: On Mon, 26 Oct 2020 at 20:06, Andreas Abel wrote: > > Please let me know if you see something that's wrong The `2.6.1.1.md` file is not in `doc/release-notes/`. Best, -- Andr?s From abela at chalmers.se Tue Oct 27 23:26:06 2020 From: abela at chalmers.se (Andreas Abel) Date: Tue, 27 Oct 2020 23:26:06 +0100 Subject: [Agda-dev] Release candidate for Agda 2.6.1.2 In-Reply-To: References: Message-ID: <9e66951e-d916-31d3-2fce-7f3afb6660aa@chalmers.se> Good catch, Andr?s! I added it and updated the candidate. On 2020-10-27 21:46, Andr?s Sicard-Ram?rez wrote: > On Mon, 26 Oct 2020 at 20:06, Andreas Abel wrote: >> >> Please let me know if you see something that's wrong > > The `2.6.1.1.md` file is not in `doc/release-notes/`. > > Best, > -- Andreas Abel <>< Du bist der geliebte Mensch. Department of Computer Science and Engineering Chalmers and Gothenburg University, Sweden andreas.abel at gu.se http://www.cse.chalmers.se/~abela/ From abela at chalmers.se Wed Oct 28 10:55:54 2020 From: abela at chalmers.se (Andreas Abel) Date: Wed, 28 Oct 2020 10:55:54 +0100 Subject: [Agda-dev] Mysteries of the GHC recompilation checker Message-ID: <3d12f16b-94e9-9d72-a8a1-3c3258b81bf2@chalmers.se> Do you also see the "missing old dependency" for exactly two files when you recompile Agda? (Mac, GHC 8.10.2) [201 of 386] Compiling Agda.Interaction.Base ( src/full/Agda/Interaction/Base.hs, dist-2.6.2-ghc-8.10.2/build/Agda/Interaction/Base.o, dist-2.6.2-ghc-8.10.2/build/Agda/Interaction/Base.dyn_o ) [missing old dependency] [349 of 386] Compiling Agda.TypeChecking.Rules.Builtin ( src/full/Agda/TypeChecking/Rules/Builtin.hs, dist-2.6.2-ghc-8.10.2/build/Agda/TypeChecking/Rules/Builtin.o, dist-2.6.2-ghc-8.10.2/build/Agda/TypeChecking/Rules/Builtin.dyn_o ) [missing old dependency] Agda.Interaction.Base and Agda.TypeChecking.Rules.Builtin are always recompiled on my machine. Luckily, this is not infective, files depending on these are not recompiled. Any explanation for this phenomenon? -- Andreas Abel <>< Du bist der geliebte Mensch. Department of Computer Science and Engineering Chalmers and Gothenburg University, Sweden andreas.abel at gu.se http://www.cse.chalmers.se/~abela/