Skip to content

Conversation

@ordinarymath
Copy link
Contributor

This slightly reduces tuple allocations.

This slightly reduces tuple allocations.
@ordinarymath
Copy link
Contributor Author

I'm wondering whether it would be clearer to just curry RM so it becomes

fun RM [] tmS tyS =

@ordinarymath
Copy link
Contributor Author

Btw I think there are a few other opportunities

e.g. you could define a pairlist datatype
`datatype ('a,'b) pairlist = Pairnil | PairCons of 'a * 'b * ('a,'b) pairlist`
 saving a pointer indirection + tuple allocation

You could make it so that it's taking

fun RM pat obj res (tmS,tyS) =
and then in the end case do
case res of
   [] => (tmS,tyS)
 | ((pat,obj)::res) => RM pat obj res (tmS,tyS)

saves a cons allocation every Abs and Comb recursion.
But probably the extra complexity isn't really that worth it.
Also most cases of calls to RM are when the pattern is already known and you can implement a way faster version which allocates a single array when checking for a match if it becomes something someone really wants to optimize.

@mn200
Copy link
Member

mn200 commented Jan 13, 2026

It's a shame that this idiom is the one that Poly/ML handles better. What impact does the change have on build times?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants