dhall-lang / dhall-to-cabal

Compile Dhall expressions to Cabal files
MIT License
100 stars 19 forks source link

Don't blindly walk under Lam (fixes #124) #126

Closed ocharles closed 6 years ago

ocharles commented 6 years ago

Issue #124 demonstrates a problem where an alpha-normalized expression no longer works with dhall-to-cabal. For example, a version expression is

\( Version : Type ) -> \( v : Text -> Version ) -> v "1.0.0"

The following is equivalent, because names shouldn't matter:

\( foo : Type ) -> \( bar : Text -> foo ) -> bar "1.0.0"

dhall-to-cabal would fail to extract a version from this expression, as it walks under two lambdas and then expects to find the exact variable "v".

Instead, we now take the given expression and fully saturate it with applications of the variable names we expect.

This same fix has been implied everywhere we were pattern matching on Lam. Essentially, we should never pattern match on Lam, instead we should App the variables we need and normalize.

A very tiny unit test suite has been added so we can add tests to types in the future.

ocharles commented 6 years ago

@jneira Could you give this branch a try?

jneira commented 6 years ago

@ocharles it works perfectly, thanks!