Revision cf57f778 autotools/convert-constants

b/autotools/convert-constants
109 109
      lines.append("%s = (%s)" % (hs_name, tvals))
110 110
    else:
111 111
      lines.append("-- Skipped tuple %s, cannot convert all elements" % name)
112
  elif isinstance(value, (list, set, frozenset)):
113
    # Lists and frozensets are handled the same in Haskell: as lists,
114
    # since lists are immutable and we don't need for constants the
115
    # high-speed of an actual Set type. However, we can only convert
116
    # them if they have the same type for all elements (which is a
117
    # normal expectation for constants, our code should be well
118
    # behaved); note that this is different from the tuples case,
119
    # where we always (for some values of always) can convert
120
    tvs = [HaskellTypeVal(elem) for elem in value]
121
    if compat.all(e is not None for e in tvs):
122
      ttypes, tvals = zip(*tvs)
123
      uniq_types = set(ttypes)
124
      if len(uniq_types) == 1:
125
        lines.append("-- | Converted from Python list or set %s" % name)
126
        lines.append("%s :: [%s]" % (hs_name, uniq_types.pop()))
127
        lines.append("%s = [%s]" % (hs_name, ", ".join(tvals)))
128
      else:
129
        lines.append("-- | Skipped list/set %s, is not homogeneous" % name)
130
    else:
131
      lines.append("-- | Skipped list/set %s, cannot convert all elems" % name)
112 132
  else:
113 133
    lines.append("-- Skipped %s, %s not handled" % (name, type(value)))
114 134
  return lines

Also available in: Unified diff