Skip to content

Why is maybe2 needed? #627

Answered by TimWhiting
osa1 asked this question in Q&A
Dec 18, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

I could be wrong, but my understanding is that value types are themselves stored as C structs, but any polymorphic fields are boxed.
Thus a tuple is represented by a C struct containing two boxed fields, and the maybe type is a C struct containing the constructor tag and a union of nothing and the field for the just constructor (i.e. a tagged union). However, a tuple in order to be stored in the just constructor would involve the tuple itself needing to be boxed to fit in the polymorphic field (which is just a pointer). Koka doesn't specialize datatypes currently and I know of no plans for that.

TLDR; value types are not entirely value types in the presence of polymorphism. They don't nee…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@osa1
Comment options

Answer selected by osa1
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