<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hi David, thank you very much for pointing its existence! <br>
There are indeed very interesting helpers that are available there
that could definitely populate an independent Data.Newtype module
in base!<br>
<br>
Cheers!<br>
</p>
<div class="moz-cite-prefix">Le 10/11/2020 à 14:36, David Feuer a
écrit :<br>
</div>
<blockquote type="cite"
cite="mid:CAMgWh9vFjRUP34rjJz6ofw9YoLf4aet6p=31VbYsKoWfNOG-Dw@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="auto">If you're playing around with these ideas, you may
appreciate the coercible-utils package[*]. I basically rewrote
the package last year to get really good type inference at the
cost of some (hard to use) flexibility.
<div dir="auto"><br>
</div>
<div dir="auto">[*] <a
href="https://hackage.haskell.org/package/coercible-utils"
moz-do-not-send="true">https://hackage.haskell.org/package/coercible-utils</a><br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Tue, Nov 10, 2020, 8:23 AM
Hécate <<a href="mailto:hecate@glitchbra.in"
moz-do-not-send="true">hecate@glitchbra.in</a>> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<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
href="https://hackage.haskell.org/package/relude-0.7.0.0/docs/Relude-Extra-Newtype.html"
target="_blank" rel="noreferrer" moz-do-not-send="true">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="m_4016565528343698598v:un" rel="noreferrer"
moz-do-not-send="true">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
href="https://hackage.haskell.org/package/base-4.14.0.0/docs/src/Data.Functor.Utils.html#%23"
target="_blank" rel="noreferrer" moz-do-not-send="true">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 cols="72">--
Hécate ✨
🐦: @TechnoEmpress
IRC: Uniaika
WWW: <a href="https://glitchbra.in" target="_blank" rel="noreferrer" moz-do-not-send="true">https://glitchbra.in</a>
RUN: BSD</pre>
</div>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank"
rel="noreferrer" moz-do-not-send="true">Libraries@haskell.org</a><br>
<a
href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries"
rel="noreferrer noreferrer" target="_blank"
moz-do-not-send="true">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote>
</div>
</blockquote>
<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>