def make_instance(typeclass, cls, show): __show__ = show ** (H / "a" >> str) show = lambda self: __show__(self) build_instance(Show, cls, {"show": show}) if not is_builtin(cls): cls.__repr__ = show cls.__str__ = show return
def make_instance(typeclass, cls, show): __show__ = show**(H / "a" >> str) show = lambda self: __show__(self) build_instance(Show, cls, {"show": show}) if not is_builtin(cls): cls.__repr__ = show cls.__str__ = show return
def make_instance(typeclass, cls, eq, ne=None): def default_ne(self, other): return not eq(self, other) __eq__ = eq ** (H / "a" >> "a" >> bool) __ne__ = (default_ne if ne is None else ne) ** (H / "a" >> "a" >> bool) eq = lambda self, other: __eq__(self, other) ne = lambda self, other: __ne__(self, other) build_instance(Eq, cls, {"eq": eq, "ne": ne}) if not is_builtin(cls): cls.__eq__ = eq cls.__ne__ = ne return
def make_instance(typeclass, cls, eq, ne=None): def default_ne(self, other): return not eq(self, other) __eq__ = eq**(H / "a" >> "a" >> bool) __ne__ = (default_ne if ne is None else ne)**(H / "a" >> "a" >> bool) eq = lambda self, other: __eq__(self, other) ne = lambda self, other: __ne__(self, other) build_instance(Eq, cls, {"eq": eq, "ne": ne}) if not is_builtin(cls): cls.__eq__ = eq cls.__ne__ = ne return
def make_instance(typeclass, cls, lt, le=None, gt=None, ge=None): def_le = lambda s, o: s.__lt__(o) or s.__eq__(o) def_gt = lambda s, o: not s.__lt__(o) and not s.__eq__(o) def_ge = lambda s, o: not s.__lt__(o) or s.__eq__(o) __lt__ = lt ** (H / "a" >> "a" >> bool) __le__ = (def_le if le is None else le) ** (H / "a" >> "a" >> bool) __gt__ = (def_gt if gt is None else gt) ** (H / "a" >> "a" >> bool) __ge__ = (def_ge if ge is None else ge) ** (H / "a" >> "a" >> bool) lt = lambda self, other: __lt__(self, other) le = lambda self, other: __le__(self, other) gt = lambda self, other: __gt__(self, other) ge = lambda self, other: __ge__(self, other) attrs = {"lt": lt, "le": le, "gt": gt, "ge": ge} build_instance(Ord, cls, attrs) if not is_builtin(cls): cls.__lt__ = lt cls.__le__ = le cls.__gt__ = gt cls.__ge__ = ge return
def make_instance(typeclass, cls, lt, le=None, gt=None, ge=None): def_le = lambda s, o: s.__lt__(o) or s.__eq__(o) def_gt = lambda s, o: not s.__lt__(o) and not s.__eq__(o) def_ge = lambda s, o: not s.__lt__(o) or s.__eq__(o) __lt__ = lt**(H / "a" >> "a" >> bool) __le__ = (def_le if le is None else le)**(H / "a" >> "a" >> bool) __gt__ = (def_gt if gt is None else gt)**(H / "a" >> "a" >> bool) __ge__ = (def_ge if ge is None else ge)**(H / "a" >> "a" >> bool) lt = lambda self, other: __lt__(self, other) le = lambda self, other: __le__(self, other) gt = lambda self, other: __gt__(self, other) ge = lambda self, other: __ge__(self, other) attrs = {"lt": lt, "le": le, "gt": gt, "ge": ge} build_instance(Ord, cls, attrs) if not is_builtin(cls): cls.__lt__ = lt cls.__le__ = le cls.__gt__ = gt cls.__ge__ = ge return