<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hello, CLC and haskell-libraries,<br>
<br>
I am opening a proposal process to consider the integration of
several helper functions in `base`, operating on Newtypes, and all
based on `coerce`.<br>
<br>
My motivations are that we ought to provide a minimum set of tools
in order to work effectively with one of our most beloved and
ubiquitous language features.<br>
<br>
Now, these functions that I am about to present to you all do not
come out of nowhere. They have been integrated to Kowainik's
alternative prelude "Relude", and seem<br>
to have found their use amongst their users, me included.<br>
Their documentation can be found here =>
<a class="moz-txt-link-freetext" href="https://hackage.haskell.org/package/relude-0.7.0.0/docs/Relude-Extra-Newtype.html">https://hackage.haskell.org/package/relude-0.7.0.0/docs/Relude-Extra-Newtype.html</a>
<br>
but I am reproducing them below for convenience:<br>
<br>
---<br>
<a id="v:un" class="def">un :: forall a n. Coercible a n => n
-> a<br>
<br>
Unwraps value from newtype.<br>
<br>
```<br>
>>> newtype Size = Size Int deriving Show<br>
>>> un @Int (Size 5)<br>
5<br>
>>> un (Size 5) == length ['a', 'x', 'b']<br>
False<br>
```<br>
<br>
</a>---<br>
wrap :: forall n a. Coercible a n => a -> n <br>
<br>
Wraps value to newtype. Behaves exactly as 'un' but has more
meaningful name in case you need to convert some value to newtype.<br>
<br>
```<br>
>>> newtype Flag = Flag Bool deriving (Show, Eq)<br>
>>> wrap False == Flag True<br>
False<br>
```<br>
</p>
<p>---<br>
under :: forall n a. Coercible a n => (n -> n) -> a ->
a<br>
<br>
Applies function to the content of newtype. This function is not
supposed to be used on newtypes that are created with the help of
smart constructors.<br>
<br>
```<br>
>>> newtype Foo = Foo Bool deriving Show<br>
>>> under not (Foo True)<br>
Foo False<br>
>>> newtype Bar = Bar String deriving Show<br>
>>> under (filter (== 'a')) (Bar "abacaba")<br>
Bar "aaaa"<br>
```<br>
<br>
As well as the coerced composition operator:<br>
<br>
(#.) :: Coercible b c => (b -> c) -> (a -> b) -> (a
-> c)<br>
(#.) _f = coerce<br>
{-# INLINE (#.) #-}<br>
<br>
Which currently lives in
<a class="moz-txt-link-freetext" href="https://hackage.haskell.org/package/base-4.14.0.0/docs/src/Data.Functor.Utils.html#%23">https://hackage.haskell.org/package/base-4.14.0.0/docs/src/Data.Functor.Utils.html#%23</a>
but is not exported.<br>
<br>
<br>
Regarding the location of these functions, I either see them
living in their own "Data.Newtype", or they could join
Data.Coerce.<br>
I would personally create a new module as to avoid "polluting"
Data.Coerce with non-class functions, but this is my personal
preference.<br>
<br>
<br>
Thank you for reading.<br>
<br>
</p>
<pre class="moz-signature" cols="72">--
Hécate ✨
🐦: @TechnoEmpress
IRC: Uniaika
WWW: <a class="moz-txt-link-freetext" href="https://glitchbra.in">https://glitchbra.in</a>
RUN: BSD</pre>
</body>
</html>