Skip to content

Add specialized sconcat implementation for Data.Semigroup.First #246

@cbrt-x

Description

@cbrt-x

The default implementation of sconcat is strict in its spine.
This means that even though in the instance of First a we have the lazy x <> _ = x, sconcat $ First () :| undefined outputs First {getFirst = *** Exception: Prelude.undefined....

I think this should be changed, by having a non-default implementation of sconcat as

sconcat (x :| _) = x

This will also have performance benefits when the spine takes time to compute.

This is 'breaking' in the sense that a program that might previously have errored would work fine now. No program that previously worked would not work with this change unless the strictness in the spine triggered a side-effect, which would only be possible with unsafePerformIO I believe.

This would make this instance more in line with other Semigroup instances like () which also provides a custom sconcat implementation for laziness.

Metadata

Metadata

Assignees

No one assigned

    Labels

    approvedApproved by CLC votebase-4.20Implemented in base-4.20 (GHC 9.10)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions