Skip to content

Add 'Relude.Extra.Newtype' module #43

@chshersh

Description

@chshersh

Just an experiment to have something like this:

class Newtype t where
    type Un t :: Type
    un   :: t -> Un t
    wrap :: Un t -> t
    -- un . wrap = id
    -- wrap . un = id

instance Newtype (Identity a) where
    type Un (Identity a) = a
    un = runIdentity
    wrap = Identity

newtype Bar = Bar Int
  deriving Newtype via (Identity Int)

And then we can write functions like these:

under :: Newtype t => (Un t -> Un t) -> t -> t
under f = wrap . f . un

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestnewBring something new into library (add function or type or interface)

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions