Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'Relude.Extra.Newtype' module #43

Closed
chshersh opened this issue Jul 24, 2018 · 1 comment
Closed

Add 'Relude.Extra.Newtype' module #43

chshersh opened this issue Jul 24, 2018 · 1 comment
Assignees
Labels
enhancement New feature or request new Bring something new into library (add function or type or interface)

Comments

@chshersh
Copy link
Contributor

chshersh commented Jul 24, 2018

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
@chshersh chshersh added enhancement New feature or request new Bring something new into library (add function or type or interface) labels Jul 24, 2018
@chshersh
Copy link
Contributor Author

chshersh commented Aug 7, 2018

Okay, let's implement this via coerce. See my tweet:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new Bring something new into library (add function or type or interface)
Projects
None yet
Development

No branches or pull requests

1 participant