Why is maybe2
needed?
#627
-
Since Lines 204 to 208 in 21089c1 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I could be wrong, but my understanding is that value types are themselves stored as C structs, but any polymorphic fields are boxed. TLDR; value types are not entirely value types in the presence of polymorphism. They don't need heap allocation for the datatype themself if used directly, but do need boxing to fit into polymorphic containers. (And the same goes for higher order function parameters that are polymorphic). |
Beta Was this translation helpful? Give feedback.
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…