コード例 #1
0
def test_applicative_law_interchange(appl):
    # u <*> pure y = pure ($ y) <*> u
    y = object()
    u = tc.pure(appl, str)

    left = tc.apply(tc.pure(appl, y), u)
    right = tc.apply(u, tc.pure(appl, lambda a: a(y)))
    assert left == right
コード例 #2
0
def test_applicative_law_interchange(datas):
    # u <*> pure y = pure ($ y) <*> u
    y, appl, funcs = datas
    u = tc.pure(appl, funcs[0])

    left = tc.apply(tc.pure(appl, y), u)
    right = tc.apply(u, tc.pure(appl, lambda a: a(y)))
    assert left == right
コード例 #3
0
def test_applicative_law_interchange(datas):
    # u <*> pure y = pure ($ y) <*> u
    y, appl, funcs = datas
    u = tc.pure(appl, funcs[0])

    left = tc.apply(tc.pure(appl, y), u)
    right = tc.apply(u, tc.pure(appl, lambda a: a(y)))
    assert left == right
コード例 #4
0
def test_applicative_law_composition(appl):
    # pure (.) <*> u <*> v <*> w = u <*> (v <*> w)
    u = tc.pure(appl, lambda a: [a])
    v = tc.pure(appl, str)
    w = appl

    def compose(f1):
        return lambda f2: lambda a: f1(f2(a))

    left = tc.apply(w, tc.apply(v, tc.apply(u, tc.pure(appl, compose))))
    right = tc.apply(tc.apply(w, v), u)
    assert left == right
コード例 #5
0
def test_applicative_law_composition(datas):
    # pure (.) <*> u <*> v <*> w = u <*> (v <*> w)
    _, appl, funcs = datas
    u = tc.pure(appl, funcs[0])
    v = tc.pure(appl, funcs[1])
    w = appl

    def compose(f1):
        return lambda f2: lambda a: f1(f2(a))

    left = tc.apply(w, tc.apply(v, tc.apply(u, tc.pure(appl, compose))))
    right = tc.apply(tc.apply(w, v), u)
    assert left == right
コード例 #6
0
def test_applicative_law_composition(datas):
    # pure (.) <*> u <*> v <*> w = u <*> (v <*> w)
    _, appl, funcs = datas
    u = tc.pure(appl, funcs[0])
    v = tc.pure(appl, funcs[1])
    w = appl

    def compose(f1):
        return lambda f2: lambda a: f1(f2(a))

    left = tc.apply(w, tc.apply(v, tc.apply(u, tc.pure(appl, compose))))
    right = tc.apply(tc.apply(w, v), u)
    assert left == right
コード例 #7
0
def test_applicative_law_homomorphism(appl):
    # pure f <*> pure x = pure (f x)
    x = object()
    f = id

    left = tc.apply(tc.pure(appl, x), tc.pure(appl, f))
    right = tc.pure(appl, f(x))
    assert left == right
コード例 #8
0
def test_applicative_law_homomorphism(datas):
    # pure f <*> pure x = pure (f x)
    x, appl, funcs = datas
    f = funcs[0]

    left = tc.apply(tc.pure(appl, x), tc.pure(appl, f))
    right = tc.pure(appl, f(x))
    assert left == right
コード例 #9
0
def test_applicative_law_homomorphism(datas):
    # pure f <*> pure x = pure (f x)
    x, appl, funcs = datas
    f = funcs[0]

    left = tc.apply(tc.pure(appl, x), tc.pure(appl, f))
    right = tc.pure(appl, f(x))
    assert left == right
コード例 #10
0
def test_applicative_law_identity(data):
    # pure id <*> v = v
    def identity(a):
        return a

    assert tc.apply(data, tc.pure(data, identity)) == data
コード例 #11
0
def test_applicative_law_identity(data):
    # pure id <*> v = v
    def identity(a):
        return a

    assert tc.apply(data, tc.pure(data, identity)) == data