Skip to content

Add Append/HAppend type class pages explaining why ++ is used instead of +#2525

Merged
Seasawher merged 4 commits into
mainfrom
copilot/fix-string-concatenation-issue
Jul 20, 2026
Merged

Add Append/HAppend type class pages explaining why ++ is used instead of +#2525
Seasawher merged 4 commits into
mainfrom
copilot/fix-string-concatenation-issue

Conversation

Copilot AI commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Lean uses ++ (not +) for string/list concatenation because + carries an expectation of commutativity (a + b = b + a), while concatenation is explicitly non-commutative. Mixing the two notations would create confusion.

New pages

  • TypeClass/Append.lean — homogeneous ++ operator class; explains the commutativity distinction with concrete examples:

    -- 文字列の連結は非可換: 順序が違うと結果が異なる
    #guard ("Hello, " ++ "world!""world!" ++ "Hello, ")
    -- 一方、自然数の足し算は可換
    #guard 2 + 3 = 3 + 2

    Also shows a custom Append MyList instance and the internal expansion to HAppend.

  • TypeClass/HAppend.lean — heterogeneous ++ operator class (parallel to existing HAdd/HMul); demonstrates custom HAppend (List Nat) Nat (List Nat) and the stdlib's HAppend (Array α) (List α) (Array α) instance.

Updated pages

  • SUMMARY.lean — adds Append and HAppend in alphabetical order within the TypeClass section
  • Type/String.lean, Type/List.lean — links Append instead of just mentioning the name inline

Copilot AI changed the title [WIP] Fix string concatenation representation issue Add Append/HAppend type class pages explaining why ++ is used instead of + Jul 8, 2026
Copilot AI requested a review from Seasawher July 8, 2026 09:23
@Seasawher
Seasawher marked this pull request as ready for review July 20, 2026 10:20
@Seasawher
Seasawher merged commit 55eaf83 into main Jul 20, 2026
3 checks passed
@Seasawher
Seasawher deleted the copilot/fix-string-concatenation-issue branch July 20, 2026 10:20
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.

文字列結合はなぜ+ではなくて++で表現されるのか

2 participants