Skip to content

Add Unit #105

@meooow25

Description

@meooow25

Please consider adding a Unit type:

newtype Unit = Unit { runUnit :: () }

instance Semigroup Unit where
  (<>) = seq

instance Monoid Unit where
  mempty = Unit ()

This makes it possible to writes instances conveniently using folds. Some examples:

instance NFData1 [] where
  liftRnf f = runUnit . foldMap (Unit . f)

-- from containers
instance NFData2 Map where
  liftRnf2 f g = runUnit . foldMapWithKey (\k x -> Unit (f k `seq` g x))

See related: #18
Unit here is the UnitLTR type defined there. However, #18 only uses it internally. This issue is about exporting the type so users can use it freely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions