Skip to content

Expand literate Haskell semantics#1127

Merged
Gabriella439 merged 4 commits intomasterfrom
gabriel/literate_semantics_2
Jan 5, 2021
Merged

Expand literate Haskell semantics#1127
Gabriella439 merged 4 commits intomasterfrom
gabriel/literate_semantics_2

Conversation

@Gabriella439
Copy link
Copy Markdown
Contributor

… to include:

  • Binary encoding
  • α-normalization
  • β-normalization
  • Equivalence checking

Related to: #959

Note that this does not include binary decoding. I was mainly
focused on completing all the dependencies for equivalence checking,
and binary decoding was not necessary for that, yet.

… to include:

* Binary encoding
* α-normalization
* β-normalization
* Equivalence checking

Related to: #959

Note that this does not include binary decoding.  I was mainly
focused on completing all the dependencies for equivalence checking,
and binary decoding was not necessary for that, yet.
@Nadrieril
Copy link
Copy Markdown
Member

I didn't read through all of it but it looks very clean. Were you able to read this at all? It seems we don't have a parser yet.

@Gabriella439
Copy link
Copy Markdown
Contributor Author

@Nadrieril: I haven't actually tested that the code works, yet. I can begin work on the parser for the next step.

The main reason I focused on this part first is that I wanted to flush out some non-trivial code (e.g. the β-normalization logic) to make sure that people are okay with the coding style before I proceed further.

(Application
(Application
(Application
(Application (Builtin NaturalFold)
Copy link
Copy Markdown
Member

@Nadrieril Nadrieril Dec 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pile of Applications is a bit hard to follow. Could we do

let (@) = Application
in  betaNormalize (g @ (NaturalFold @ (NaturalLiteral (m - 1)) @ _B @ g @ b))

or something like that?

Copy link
Copy Markdown
Member

@Nadrieril Nadrieril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the impressive work! Looks good to me. Normalization of builtins can be hard to follow, but I'm not sure we can do much better anyways

@Gabriella439
Copy link
Copy Markdown
Contributor Author

@Nadrieril: I took a stab at your suggestion by using GHC's support for pattern synonyms, like this:

{-| Convenient synonym for `Application` so that β-normalization code is easier
    to read
-}
pattern (:@) :: Expression -> Expression -> Expression
pattern f :@ x = Application f x

infixl :@

… which does make the code much clearer, but as I was applying the change the type-checking began to slow down significantly until I hit this warning:

BetaNormalization.lhs:(103,1)-(2577,68): error: [-Werror]
    Pattern match checker exceeded (2000000) iterations in
    an equation for ‘betaNormalize’. (Use -fmax-pmcheck-iterations=n
    to set the maximum number of iterations to n)
    |
103 | betaNormalize (Constant c) = Constant c
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

… so I think I'll avoid using the pattern synonym for now until we begin using GHC 8.10 to build the literate Haskell semantics, which appears to have fixed the performance issue (See: https://gitlab.haskell.org/ghc/ghc/-/issues/11822)

@Gabriella439 Gabriella439 merged commit 59fdad8 into master Jan 5, 2021
@Gabriella439 Gabriella439 deleted the gabriel/literate_semantics_2 branch January 5, 2021 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants