The docs on lambdas in Agda provide two forms of lambda: a curly brace based version, and the where syntax. But while writing some programs, I stumbled across a third version: one pattern, no braces, no where. I thought it would behave the same as a single pattern and braces, but here's a counter example to that:
natid : ℕ → ℕ
natid = λ x → x
g0 : ( λ x → natid x ) ≡ ( λ x → natid x )
g0 = refl
g1 : ( λ { x → natid x } ) ≡ ( λ x → natid x )
g1 = refl
g2 : ( λ x → natid x ) ≡ ( λ { x → natid x } )
g2 = refl
g3 : _≡_ {_} {_ → _} ( λ { x → natid x } ) ( λ { x → natid x } )
g3 = refl
-- g4 : ( λ { x → natid x } ) ≡ ( λ { x → natid x } )
-- this fails with error message:
_a_91 : Agda.Primitive.Level [ at /Users/olekgierczak/repos/plfa/src/plfa/part1/Connectives.lagda.md:278,28-29 ]
_A_92 : Set _a_91 [ at /Users/olekgierczak/repos/plfa/src/plfa/part1/Connectives.lagda.md:278,28-29 ]
_94 : _A_92 [ at /Users/olekgierczak/repos/plfa/src/plfa/part1/Connectives.lagda.md:278,8-25 ]
———— Errors ————————————————————————————————————————————————
Unsolved constraints
So my question is, what does a lambda with no braces around a single pattern mean, and why does the type inference of Agda treat g1/g2/g4 differently.
where
) appears to be missing. $\endgroup$--cubical
flag, then all of thegn
's types go yellow! That's what I'd have expected from a bidirectional perspective, but I guess in standard Agda there's some heuristic that lets normal λ-abstractions synthesise a (simple?) function type. (In cubical Agda, normal λ-abstractions also construct paths, so it would be non-canonical to synthesise a function type.) $\endgroup$