unison/unison-src/transcripts/fix2423.md
2024-06-25 11:11:07 -07:00

746 B

scratch/main> builtins.merge
structural ability Split where
  skip! : x
  both : a -> a -> a

Split.append : '{Split, g} a -> '{Split, g} a -> '{Split, g} a 
Split.append s1 s2 _ = force (both s1 s2)

force a = !a

Split.zipSame : '{Split, g} a -> '{Split, g} b -> '{Split, g} (a, b)
Split.zipSame sa sb _ = 
  go : '{Split,g2} y -> Request {Split} x ->{Split,g2} (x,y)
  go sb = cases
    { a } -> (a, !sb)
    { skip! -> _ } -> skip!
    { both la ra -> k } -> 
      handle !sb with cases
        { _ } -> skip!
        { skip! -> k } -> skip!
        { both lb rb -> k2 } -> 
          force (Split.append
            (zipSame '(k la) '(k2 lb))
             (zipSame '(k ra) '(k2 rb)))

  handle !sa with go sb