Polymorphic higher-order functions limited by type system #297
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
refactor
rust
technical-debt
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
navicore/patch-seq#297
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Polymorphic higher-order functions limited by type system
Summary
Seq's type system cannot unify concrete types (like
Int, quotations) withVariantwhen calling higher-order functions. This prevents idiomaticfunctional patterns like
fold/reducefrom being fully generic.Example
Error:
The Gap
Seq has all the building blocks for functional programming:
But the type system can't express "this function is polymorphic in the accumulator and element types."
Potential Approaches
Current Workaround
Implement concrete recursive functions instead of using generic HOF:
This is idiomatic and works well, but requires reimplementing the recursion pattern for each use case rather than abstracting it once.
Context
This came up while creating a functional programming paradigm example (examples/paradigms/functional/lists.seq). The example can be completed with direct
recursion, but generic map/filter/fold would make it more expressive.
Case for "won't do":
workaround - it's the natural way to express this in a concatenative language.
The LLVM codegen would need to handle monomorphization or boxing, and the complexity could destabilize what currently works well.
that identity.