You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wonder why F# has not generalized the pattern matching over lists to a generalization version for sequences and generated optimized code based on the type use?
it is not uncommon to traverse a collection like you would do with a list to do something depending on the order of the items of the collection appears.
This is not that hard to implement in the compiler since a sequence s like a list either is empty, or has a head and tail which again is a sequence, hence substitute/inline the isEmpty function body with the check for [], and substitute/inline x :: xs with let x = head s; let xs = tail s. for det specific implementation of isEmpty, head and tail for the used collection. it would lead to a better chance that the compiler can recognize doublications of sub-patterns of the matching and merge them leading to more performant code.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I wonder why F# has not generalized the pattern matching over lists to a generalization version for sequences and generated optimized code based on the type use?
it is not uncommon to traverse a collection like you would do with a list to do something depending on the order of the items of the collection appears.
This is not that hard to implement in the compiler since a sequence s like a list either is empty, or has a head and tail which again is a sequence, hence substitute/inline the isEmpty function body with the check for [], and substitute/inline x :: xs with let x = head s; let xs = tail s. for det specific implementation of isEmpty, head and tail for the used collection. it would lead to a better chance that the compiler can recognize doublications of sub-patterns of the matching and merge them leading to more performant code.
Beta Was this translation helpful? Give feedback.
All reactions