A little Winter demo
The work-in-progress inlining pass in Winter, combined with the closure and first-class function support described earlier, allows this program:
def compose(function<float, float> f, function<float, float> g) : \(float x) : f(g(x)) def addOne(float x) : x + 1.0 def mulByTwo(float x) : x * 2.0 def main(float x) float : let z = compose(addOne, mulByTwo) in z(x)
To compile to this:
.LCPI0_0: .long 1065353216 # float 1 .text .globl main_float_ .align 16, 0x90 .type main_float_,@function main_float_: # @main_float_ # BB#0: # %decr_function<float, float>.exit40 vaddss %xmm0, %xmm0, %xmm0 movabsq $.LCPI0_0, %rax vaddss (%rax), %xmm0, %xmm0 retq
The compose function isn't as pretty as in Haskell, but it works, and as you can see it can be inlined to result in fast code.