Skip to content

Why is the type based on slice #46

@lzap

Description

@lzap

Hello,

I cannot wrap my head around the type being implemented as a slice, can you explain the motivation for this? A slice takes three words in memory while a struct with a pointer to the value takes one word, that saves 66%:

struct {
	V *T
}

I thought for a moment it solves comparable and ordered problem, but slices are neither comparable nor ordered whereas structs can be comparable (as long as all fields are) and not ordered. Unfortunately, both struct and slice implementations are suffering from a major problem - types which use this optional type looses both comparable and ordered constraints. There are many libraries which will no longer work like mergo or cmp (Google comparing library not the built-in cmp package).

Is there a particular reason for using slices? Thanks.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions