Skip to content

Polymorphic functions in Teal code? #898

Answered by hishamhm
lucillablessing asked this question in Q&A
Discussion options

You must be logged in to vote

No, it is not currently possible. Support for polymorphic functions exists for better represent Lua functions that simulate function polymorphism via manual dynamic dispatch (i.e. good ol' if statements). There is no syntax in Teal for describing true function polymorphism.

The best you could do nowadays would be to declare a record field to be a polymporphic function, but then assign to it a function with a wider type and then do the if matching yourself like you would in Lua; the compiler won't verify that your runtime checks actually match the declared polymorphic types, but the result for the callers would be that the field would look like a polymorphic function.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by hishamhm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants