Beispiel #1
0
    Used in translation of L[n, n_, ..., m]
    """
    return L[Enum[start].enumFromThenTo(start, second, end)]


@sig(H/ "a" >> "a" >> ["a"])
def enumFromTo(start, end):
    """
    enumFromTo :: a -> a -> [a]

    Used in translation of L[n, ..., m]
    """
    return L[Enum[start].enumFromTo(start, end)]


instance(Enum, int).where(fromEnum=int, toEnum=int)
instance(Enum, long).where(fromEnum=int, toEnum=long)
instance(Enum, bool).where(fromEnum=int, toEnum=bool)
instance(Enum, str).where(fromEnum=ord, toEnum=chr)


#=============================================================================#
# List


class List(collections.Sequence, Hask):
    """
    Statically typed lazy sequence datatype.

    See help(L) for more information.
    """
Beispiel #2
0
    Used in translation of L[n, n_, ..., m]
    """
    return L[Enum[start].enumFromThenTo(start, second, end)]


@sig(H/ "a" >> "a" >> ["a"])
def enumFromTo(start, end):
    """
    enumFromTo :: a -> a -> [a]

    Used in translation of L[n, ..., m]
    """
    return L[Enum[start].enumFromTo(start, end)]


instance(Enum, int).where(fromEnum=int, toEnum=int)
instance(Enum, bool).where(fromEnum=int, toEnum=bool)
instance(Enum, str).where(fromEnum=ord, toEnum=chr)

if sys.version[0] == '2':
    instance(Enum, long).where(fromEnum=int, toEnum=long)


#=============================================================================#
# List


class List(collections.Sequence, Hask):
    """
    Statically typed lazy sequence datatype.
Beispiel #3
0
    @classmethod
    def make_instance(typeclass, cls, read):
        build_instance(Read, cls, {"read": read})
        return

    @classmethod
    def derive_instance(typeclass, cls):
        Read.make_instance(cls, read=eval)
        return


# =============================================================================#
# Instances for builtin types


instance(Show, str).where(show=str.__repr__)
instance(Show, int).where(show=int.__str__)
instance(Show, long).where(show=long.__str__)
instance(Show, float).where(show=tuple.__str__)
instance(Show, complex).where(show=complex.__str__)
instance(Show, bool).where(show=bool.__str__)
instance(Show, list).where(show=list.__str__)
instance(Show, tuple).where(show=tuple.__str__)
instance(Show, set).where(show=set.__str__)
instance(Show, dict).where(show=dict.__str__)
instance(Show, frozenset).where(show=frozenset.__str__)
instance(Show, slice).where(show=slice.__str__)
instance(Show, unicode).where(show=unicode.__str__)

instance(Eq, str).where(eq=str.__eq__, ne=str.__ne__)
instance(Eq, int).where(eq=int.__eq__, ne=int.__ne__)
Beispiel #4
0
    """
    @classmethod
    def make_instance(typeclass, cls, read):
        build_instance(Read, cls, {"read": read})
        return

    @classmethod
    def derive_instance(typeclass, cls):
        Read.make_instance(cls, read=eval)
        return


#=============================================================================#
# Instances for builtin types

instance(Show, str).where(show=str.__repr__)
instance(Show, int).where(show=int.__str__)
instance(Show, long).where(show=long.__str__)
instance(Show, float).where(show=tuple.__str__)
instance(Show, complex).where(show=complex.__str__)
instance(Show, bool).where(show=bool.__str__)
instance(Show, list).where(show=list.__str__)
instance(Show, tuple).where(show=tuple.__str__)

instance(Eq, str).where(eq=str.__eq__, ne=str.__ne__)
instance(Eq, int).where(eq=int.__eq__, ne=int.__ne__)
instance(Eq, long).where(eq=long.__eq__, ne=long.__ne__)
instance(Eq, float).where(eq=float.__eq__, ne=float.__ne__)
instance(Eq, complex).where(eq=complex.__eq__, ne=complex.__ne__)
instance(Eq, bool).where(eq=bool.__eq__, ne=bool.__ne__)
instance(Eq, list).where(eq=list.__eq__, ne=list.__ne__)
Beispiel #5
0
    """
    @classmethod
    def make_instance(typeclass, cls, read):
        build_instance(Read, cls, {"read": read})
        return

    @classmethod
    def derive_instance(typeclass, cls):
        Read.make_instance(cls, read=eval)
        return


#=============================================================================#
# Instances for builtin types

instance(Show, str).where(show=str.__repr__)
instance(Show, int).where(show=int.__str__)
instance(Show, float).where(show=tuple.__str__)
instance(Show, complex).where(show=complex.__str__)
instance(Show, bool).where(show=bool.__str__)
instance(Show, list).where(show=list.__str__)
instance(Show, tuple).where(show=tuple.__str__)
instance(Show, set).where(show=set.__str__)
instance(Show, dict).where(show=dict.__str__)
instance(Show, frozenset).where(show=frozenset.__str__)
instance(Show, slice).where(show=slice.__str__)

instance(Eq, str).where(eq=str.__eq__, ne=str.__ne__)
instance(Eq, int).where(eq=int.__eq__, ne=int.__ne__)
instance(Eq, float).where(eq=float.__eq__, ne=float.__ne__)
instance(Eq, complex).where(eq=complex.__eq__, ne=complex.__ne__)
    @classmethod
    def make_instance(typeclass, cls, read):
        build_instance(Read, cls, {"read":read})
        return

    @classmethod
    def derive_instance(typeclass, cls):
        Read.make_instance(cls, read=eval)
        return


#=============================================================================#
# Instances for builtin types


instance(Show, str).where(show=str.__repr__)
instance(Show, int).where(show=int.__str__)
instance(Show, long).where(show=long.__str__)
instance(Show, float).where(show=tuple.__str__)
instance(Show, complex).where(show=complex.__str__)
instance(Show, bool).where(show=bool.__str__)
instance(Show, list).where(show=list.__str__)
instance(Show, tuple).where(show=tuple.__str__)

instance(Eq, str).where(eq=str.__eq__, ne=str.__ne__)
instance(Eq, int).where(eq=int.__eq__, ne=int.__ne__)
instance(Eq, long).where(eq=long.__eq__, ne=long.__ne__)
instance(Eq, float).where(eq=float.__eq__, ne=float.__ne__)
instance(Eq, complex).where(eq=complex.__eq__, ne=complex.__ne__)
instance(Eq, bool).where(eq=bool.__eq__, ne=bool.__ne__)
instance(Eq, list).where(eq=list.__eq__, ne=list.__ne__)