Thank you for suggesting these, Hécate.
I personally don't see much benefit in `un` and `wrap` functions, since it is quite straightforward to use coerce directly:
un @Int = coerce @_ @Int
and wrap is the same way:
wrap @SIze = coerce @_ @Size
At what point do we stop creating synonyms? Adding these two functions IMHO is a redundant mental overhead.
On the other hand `#.` operator can be quite handy and I'd be totally in favor of exposing it to the world but from a Data.Coerce module instead of a totally new module. However I would also not call it coerced composition operator, because firstly it doesn't really compose functions it just coerces them and secondly it can be made more polymorphic and then it would be useful with other things than just functions:
(#.) :: forall a b c proxy. Coercible b c => proxy b c -> (a -> b) -> (a -> c)
(#.) _proxy = coerce
With regards to `under` I am a somewhat indifferent, but if it was in base I am sure I'd use it. Naming is a bit odd, but I am not the one to bikeshed.
Sincerely,
Alexey.
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
Hello, CLC and haskell-libraries,
I am opening a proposal process to consider the integration of
several helper functions in `base`, operating on Newtypes, and all
based on `coerce`.
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.
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
to have found their use amongst their users, me included.
but I am reproducing them below for convenience:
---
wrap :: forall n a. Coercible a n => a -> n
Wraps value to newtype. Behaves exactly as 'un' but has more
meaningful name in case you need to convert some value to newtype.
```
>>> newtype Flag = Flag Bool deriving (Show, Eq)
>>> wrap False == Flag True
False
```
---
under :: forall n a. Coercible a n => (n -> n) -> a ->
a
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.
```
>>> newtype Foo = Foo Bool deriving Show
>>> under not (Foo True)
Foo False
>>> newtype Bar = Bar String deriving Show
>>> under (filter (== 'a')) (Bar "abacaba")
Bar "aaaa"
```
As well as the coerced composition operator:
(#.) :: Coercible b c => (b -> c) -> (a -> b) -> (a
-> c)
(#.) _f = coerce
{-# INLINE (#.) #-}
Regarding the location of these functions, I either see them
living in their own "Data.Newtype", or they could join
Data.Coerce.
I would personally create a new module as to avoid "polluting"
Data.Coerce with non-class functions, but this is my personal
preference.
Thank you for reading.
--
Hécate ✨
🐦: @TechnoEmpress
IRC: Uniaika
WWW: https://glitchbra.in
RUN: BSD
_______________________________________________
Libraries mailing list
Libraries@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries