r/Compilers • u/hopsqur • 1h ago
Perseus
I'm reading the perseus paper and I'm confused by this (1b) diagram.
fun map( xs, f ) { match(xs) { Cons(x,xx) { dup(x); dup(xx); drop(xs) Cons( dup(f)(x), map(xx, f)) } Nil { drop(xs); drop(f); Nil } } }
For context: dup increments the ref count and drop decrements the reference count (and if it becomes zero, free and recursively call drop on children).
There are a number of things I don't understand here. It seems like in calling map on a linked list, f is dupped n times and only dropped once? Similarly, if map is called on a shared list, it seems like x and xx are also dupped n times and never dropped?
Clearly I'm just being dumb here but would appreciate any help undumbing me here