1lab/mikan
13
52
Fork
You've already forked mikan
9

Make λ arguments always interpreted as patterns? #79

Open
opened 2026年05月06日 00:00:33 +02:00 by jeanas · 1 comment

This tripped up a number of my students in the tutorial I was giving today:

open import Data.Product
open import Data.Empty
open import Relation.Binary.PropositionalEquality
-- OK
foo : {A B : Set} → A ×ばつ B → A
foo = λ (a , b) → a
-- OK
bar : {A : Set} → ⊥ → A
bar = λ ()
-- KO
baz : {A : Set} {x y : A} → x ≡ y → y ≡ x
baz = λ refl → refl

In λ refl → ..., the refl is just interpreted as a variable name, not as a constructor name as it would be in pattern matching, unlike a definition by clauses and also unlike λ {refl → refl}. I don't quite get why, but if you're going to do a backwards compatibility break, maybe changing this is something to consider?

This tripped up a number of my students in the tutorial I was giving today: ``` open import Data.Product open import Data.Empty open import Relation.Binary.PropositionalEquality -- OK foo : {A B : Set} → A ×ばつ B → A foo = λ (a , b) → a -- OK bar : {A : Set} → ⊥ → A bar = λ () -- KO baz : {A : Set} {x y : A} → x ≡ y → y ≡ x baz = λ refl → refl ``` In `λ refl → ...`, the `refl` is just interpreted as a variable name, not as a constructor name as it would be in pattern matching, unlike a definition by clauses and also unlike `λ {refl → refl}`. I don't quite get why, but if you're going to do a backwards compatibility break, maybe changing this is something to consider?

This is definitely a common point of confusion! Unfortunately, this will not be possible to implement in Mikan. We elaborate pattern lambdas to top-level pattern matching definitions, so this would have some some unwanted consequences for most parts of the system. Lambdas like λ (a , b) → a are a bit more delicate as we can elaborate to a normal lambda + projections (this elaboration is quite leaky, if you've ever seen .patternInTele0 in goals this is why).

I think the real issue here is documentation/ux; once we get around to #3 this is something to keep in mind. This also feels like a good place to put a warning: if a user tries to λ-bind a constructor name, we should probably give them a heads up and then point to the docs.

This is definitely a common point of confusion! Unfortunately, this will not be possible to implement in Mikan. We elaborate pattern lambdas to top-level pattern matching definitions, so this would have some some unwanted consequences for most parts of the system. Lambdas like `λ (a , b) → a` are a bit more delicate as we can elaborate to a normal lambda + projections (this elaboration is quite leaky, if you've ever seen `.patternInTele0` in goals this is why). I think the real issue here is documentation/ux; once we get around to #3 this is something to keep in mind. This also feels like a good place to put a warning: if a user tries to `λ`-bind a constructor name, we should probably give them a heads up and then point to the docs.
Sign in to join this conversation.
No Branch/Tag specified
main
aliao/occurs-opt
aliao/rec-con
fix-license
aliao/oopsie
aliao/strengthen-iapply
No results found.
Labels
Clear labels
1 - scope
language
Backwards-compatible changes to the surface language, such as adding new features.
1 - scope
language change
Breaking changes to a documented part of the surface language. These should be documented and specifically called out in the changelog.
1 - scope
performance
Semantics-preserving performance work.
1 - scope
task
Changes that are not apparent to the user, e.g. developer documentation and refactors, which do not need to be documented.
A: dead-code
Dead code elimination and --save-metas.
A: errors
Reporting of error and warning messages.
A: highlighting
Highlighting during interaction & literate compilation
A: imports
Handling of imports and interface file de/serialization.
A: infra
Iinfrastructure (e.g. CI, developer documentation, the build system, or the repository itself)
A: instance
Instance declarations, arguments, and resolution
A: lhs
LHS checking, coverage checking, and clause compilation
A: modules
Declaration and instantiation of parametrised modules.
A: parallel
Parallel typechecking.
A: positivity
Positivity checking
A: printing
Pretty-printing, display forms, and the wording of diagnostic messages
A: records
Record declarations, record expressions and copattern matching
A: scoping
Scope checking (ConcreteToAbstract)
A: termination
Termination checking
0 - type
bug
Issues describing an incorrect behaviour in the project, typos in the documentation, etc.
0 - type
discussion
An issue raised to gather opinions on a proposed change, or a suggested language change.
0 - type
question
An issue raised to ask a question.
9 - status
duplicate
This issue or pull request already exists.
9 - status
info needed
More information is needed from the submitter to decide how to proceed with the issue report.
9 - status
invalid
The issue report or pull request does not describe an actual bug, or does otherwise does not meet the contributing guidelines.
good first issue
Interested in contributing? Get started here.
upstream
Related to an upstream repository, already reported there
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
1lab/mikan#79
Reference in a new issue
1lab/mikan
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?