packages feed

phino-0.0.156: test-resources/evaluate-packs/upcasts-a-bare-symbol-to-the-tuple-of-the-other-branch.yaml

# SPDX-FileCopyrightText: Copyright (c) 2025 Objectionary.com
# SPDX-License-Identifier: MIT
---
# yamllint disable rule:line-length
# The fork of 'bytes.array' from #1914: one branch is a bare symbol, the other
# a tuple holding three symbols, so a lenient join cannot tell which of them
# the bare one pairs with. A 'rewrite' line spells the tuple as the call
# 'Ξ¦.tuple( … )' it was made of, and the 'upcast' block takes '𝜎1' and that
# call as one pair. It casts the smaller of the two, the bare '𝜎1', into a
# copy of the call whose every symbol is read off '𝜎1' by a path, and passes
# the call through as it is (#1921). The 'join' line then pairs the two metas
# the block wrote symbol by symbol, through their arguments. The program reads 'length' off the answer and gets the symbol
# standing for either length.
symbolic: |
  - Ξ»: L_fork
    morph:
      𝑛1: $.a
      𝑛2: $.b
    rewrite:
      𝑛3:
        of: 𝑛2
        rules:
          - name: called
            pattern: ⟦ tail ↦ 𝑒1, head ↦ 𝑒2, length ↦ 𝑒3, !B ⟧
            result: Ξ¦.tuple( tail ↦ 𝑒1, head ↦ 𝑒2, length ↦ 𝑒3 )
    upcast:
      𝑛4: 𝑛1
      𝑛5: 𝑛3
    join:
      𝑛6: [𝑛4, 𝑛5]
    𝑛: 𝑛6
location: 'Q.y'
input: |
  ⟦
    tuple(tail, head, length) ↦ ⟦ empty ↦ ⟦⟧ ⟧,
    y ↦ ⟦
      a ↦ ⟦ Ξ» ‍ 𝜎1 ⟧,
      b ↦ Ξ¦.tuple( tail ↦ ⟦ Ξ» ‍ 𝜎2 ⟧, head ↦ ⟦ Ξ» ‍ 𝜎3 ⟧, length ↦ ⟦ Ξ» ‍ 𝜎4 ⟧ ),
      λ ‍ L_fork
    ⟧.length
  ⟧
result: '𝜎10:λ'
protocol: |
  𝕄(Ξ¦.y):
    𝔼(L_fork):
      𝑛1Β·1 := 𝜎1:Ξ»  # 𝕄(ΞΎ.a)
      𝕄(Ξ¦.a🌡1):
        𝑛·1Β·1 := Ξ¦.tuple( tail ↦ 𝜎2:Ξ» )
        𝑛·1Β·2 := 𝑛·1Β·1( head ↦ 𝜎3:Ξ» )
        𝑛·1Β·3 := 𝑛·1Β·2( length ↦ 𝜎4:Ξ» )
      𝑛2Β·1 := 𝑛·1Β·3  # 𝕄(ΞΎ.b)
      𝑛3Β·1 := 𝑛·1Β·3  # 𝑛2
      upcast(𝜎1) := Ξ¦.tuple( tail ↦ 𝜎5:Ξ», head ↦ 𝜎6:Ξ», length ↦ 𝜎7:Ξ» )
        𝜎5 := 𝜎1.tail
        𝜎6 := 𝜎1.head
        𝜎7 := 𝜎1.length
      𝑛4Β·1 := Ξ¦.tuple( tail ↦ 𝜎5:Ξ», head ↦ 𝜎6:Ξ», length ↦ 𝜎7:Ξ» )  # 𝑛1
      𝑛5Β·1 := 𝑛·1Β·3  # 𝑛3
      𝔻(𝜎8:Ξ») ∈ { 𝔻(𝜎5:Ξ»), 𝔻(𝜎2:Ξ») }
      𝔻(𝜎9:Ξ») ∈ { 𝔻(𝜎6:Ξ»), 𝔻(𝜎3:Ξ») }
      𝔻(𝜎10:Ξ») ∈ { 𝔻(𝜎7:Ξ»), 𝔻(𝜎4:Ξ») }
      𝑛6Β·1 := Ξ¦.tuple( tail ↦ 𝜎8:Ξ», head ↦ 𝜎9:Ξ», length ↦ 𝜎10:Ξ» )  # [𝑛4, 𝑛5]
      𝑛·1Β·4 := Ξ¦.tuple( tail ↦ 𝜎8:Ξ», head ↦ 𝜎9:Ξ», length ↦ 𝜎10:Ξ» )  # 𝑛
      𝕄(𝑛·1Β·4):
        𝑛·1Β·5 := Ξ¦.tuple( tail ↦ 𝜎8:Ξ» )
        𝑛·1Β·6 := 𝑛·1Β·5( head ↦ 𝜎9:Ξ» )
        𝑛·1Β·7 := 𝑛·1Β·6( length ↦ 𝜎10:Ξ» )
      𝑛·1Β·8 := 𝑛·1Β·7  # 𝕄(𝑛·1Β·4)