Пример #1
0
 def zip_cmp(self, other, fn):
     """
     Compare the data constructor and all of the fields of two ADTs.
     """
     if self.__ADT_slot__ == other.__ADT_slot__:
         if len(nt_to_tuple(self)) == 0:
             return fn((), ())
         return fn(nt_to_tuple(self), nt_to_tuple(other))
     return fn(self.__ADT_slot__, other.__ADT_slot__)
Пример #2
0
 def zip_cmp(self, other, fn):
     """
     Compare the data constructor and all of the fields of two ADTs.
     """
     if self.__ADT_slot__ == other.__ADT_slot__:
         if len(nt_to_tuple(self)) == 0:
             return fn((), ())
         return fn(nt_to_tuple(self), nt_to_tuple(other))
     return fn(self.__ADT_slot__, other.__ADT_slot__)
Пример #3
0
        def show(self):
            if len(self.__class__._fields) == 0:
                return self.__class__.__name__

            nt_tup = nt_to_tuple(self)
            if len(nt_tup) == 1:
                tuple_str = "(%s)" % Show[nt_tup[0]].show(nt_tup[0])
            else:
                tuple_str = Show[nt_tup].show(nt_tup)

            return "{0}{1}".format(self.__class__.__name__, tuple_str)
Пример #4
0
        def show(self):
            if len(self.__class__._fields) == 0:
                return self.__class__.__name__

            nt_tup = nt_to_tuple(self)
            if len(nt_tup) == 1:
                tuple_str = "(%s)" % Show[nt_tup[0]].show(nt_tup[0])
            else:
                tuple_str = Show[nt_tup].show(nt_tup)

            return "{0}{1}".format(self.__class__.__name__, tuple_str)
Пример #5
0
 def __eq__(self, other):
     return self.__class__ == other.__class__ and nt_to_tuple(self) == nt_to_tuple(other)
Пример #6
0
 def __ne__(self, other):
     return self.__class__ != other.__class__ or nt_to_tuple(self) != nt_to_tuple(other)
Пример #7
0
 def __ne__(self, other):
     return self.__class__ != other.__class__ or  \
         nt_to_tuple(self) != nt_to_tuple(other)
Пример #8
0
 def __eq__(self, other):
     return self.__class__ == other.__class__ and \
         nt_to_tuple(self) == nt_to_tuple(other)