OK, I’m not sure why, but the solution is less, not more …
@data XX begin
Nil
Cons(hd, tl::XX)
end
function sum_list(lst)
@match lst begin
Nil => 0
Cons(h, t) => h + sum_list(t)
end
end
function printer(lst)
@match lst begin
Nil => println("[]")
Cons(h, t) => begin
print("$(h) . ")
printer(t)
end
end
end
function make_test_1()
return Cons(1, Cons(2, Cons(3, Nil)))
end
function make_test_2()
return Cons("A", Cons("B", Cons("C", Nil)))
end
i = make_test_1()
s = make_test_2()
println("sum_list(i) = $(sum_list(i))")
#sum_list(i) = 6
printer(i)
#1 . 2 . 3 . []
printer(s)
#A . B . C . []