def make_data_const(name, fields, type_constructor, slot_num):
    """
    Build a data constructor given the name, the list of field types, and the
    corresponding type constructor.

    The general approach is to create a subclass of the type constructor and a
    new class created with `namedtuple`, with some of the features from
    `namedtuple` such as equality and comparison operators stripped out.

    Args:
        name: the name of the data constructor (a string)
        fields: the list of fields that the data constructor will have (a list
                of strings and types)
        type_constructor: the type constructor for the data constructor's type
        slot_num: the position of the data constructor in the `data` statement
                  defining the new type (e.g., Nothing=0, Just=1)

    Returns:
        The new data constructor
    """
    # create the data constructor
    base = namedtuple(name, [i % "i%s" for i, _ in enumerate(fields)])
    cls = type(name, (type_constructor, base), {})
    cls.__type_constructor__ = type_constructor
    cls.__ADT_slot__ = slot_num

    if len(fields) == 0:
        # If the data constructor takes no arguments, create an instance of it
        # and return that instance rather than returning the class
        cls = cls()
    else:
        # Otherwise, modify __type__ so that it matches up fields from the data
        # constructor with type params from the type constructor
        def __type__(self):
            args = [typeof(self[fields.index(p)]) \
                    if p in fields else TypeVariable()
                    for p in type_constructor.__params__]
            return TypeOperator(type_constructor, args)
        cls.__type__ = __type__

    type_constructor.__constructors__ += (cls,)
    return cls
dataset/ETHPy150Open billpmurphy/hask/hask/lang/type_system.py/make_data_const/swapped operands of `%`