haskell / vector

An efficient implementation of Int-indexed arrays (both mutable and immutable), with a powerful loop optimisation framework .
Other
367 stars 139 forks source link

Why is `Data.Vector.Generic.New.New` not a newtype? #453

Closed konsumlamm closed 1 year ago

konsumlamm commented 1 year ago

The New type in Data.Vector.Generic.New is currently defined as

data New v a = New (forall s. ST s (Mutable v s a))

Is there any reason this isn't a newtype?

konsumlamm commented 1 year ago

Apprently it was a newtype originally, but it was changed in https://github.com/haskell/vector/commit/82fe1c94509d6de08fb4d2d03a81b0a63e05ae32, although without explanation.

lehins commented 1 year ago

@konsumlamm It must be a data type instead of newtype otherwise the rewrite rules will not fire. I can try add a comment later on to the definition with explanation why it must be a data type. I'll keep this ticket around to track this task of explaining in the code.