code: def merge_alleles(alleles):
      from hail.expr.functions import _num_allele_type, _allele_ints
  
      return hl.rbind(
          alleles.map(lambda a: hl.or_else(a[0], "")).fold(
              lambda s, t: hl.if_else(hl.len(s) > hl.len(t), s, t), ""
          ),
          lambda ref: hl.rbind(
              alleles.map(
                  lambda al: hl.rbind(
                      al[0],
                      lambda r: hl.array([ref]).extend(
                          al[1:].map(
                              lambda a: hl.rbind(
                                  _num_allele_type(r, a),
                                  lambda at: hl.if_else(
                                      (_allele_ints["SNP"] == at)
                                      | (
                                          _allele_ints["Insertion"]
                                          == at
                                      )
                                      | (_allele_ints["Deletion"] == at)
                                      | (_allele_ints["MNP"] == at)
                                      | (_allele_ints["Complex"] == at),
                                      a + ref[hl.len(r) :],
                                      a,
                                  ),
                              )
                          )
                      ),
                  )
              ),
              lambda lal: hl.struct(
                  globl=hl.array([ref]).extend(
                      hl.array(hl.set(hl.flatten(lal)).remove(ref))
                  ),
                  local=lal,
              ),
          ),
      )
  
imports: import math
  from typing import Collection, Optional, Set, Union, List, Tuple, Dict
  import hail
  from hail import MatrixTable, Table
  from hail.experimental.function import Function
  from hail.expr import StructExpression, unify_all, construct_expr
  from hail.expr.expressions import expr_bool, expr_str
  from hail.genetics.reference_genome import reference_genome_type
  from hail.ir import Apply, TableMapRows
  from hail.typecheck import oneof, sequenceof, typecheck
  from ..variant_dataset import VariantDataset
label_desc: Use image node_id 18 for calling a global function with example usage: merge_alleles(alleles) and returns: hl