A point-free implementation of a one-layer transformer in Coconut.
See the full highlighted source here.
Some help for those that don't read Coconut:
..>
is forward function composition (sof ..> g
isg . f
in Haskell)f$(<args>)
is partial application (sof$(<args>)
isfunctools.partial(f, <args>)
in Python)lift
“lifts” a function so that all of its arguments become unary functions (for a binary function,lift
is the S' combinator, orliftA2
in Haskell—e.g.lift(f)(g, h)
is equivalent tolambda x: f(g(x), h(x))
in Python)(<op>)
is the operator function for<op>
(so(+)
isoperator.add
in Python)(. <op> <arg>)
is equivalent to<op>$(?, <arg>)
(?
is a placeholder that means that argument isn't partially applied).method(<args>)
is equivalent tolambda x: x.method(<args>)
in Python
Also, einsum
here is better_einsum.einsum
.