[Haskell-beginners] Expose every Function of a wrapped type

鲍凯文 traqueofziche at gmail.com
Sat Nov 16 23:46:51 UTC 2019


Hi,

Have you considered using `Control.Lens.Wrapped` or `Control.Newtype`?
You'd have to move the wrapping/unwrapping bits to the sites in your code
at which you use underlying `Map` functions (quite repetitive), but it
could be easier than redefining all the functions you want (and definitely
easier than having to redefine a new one when you think of needing it?).

There's probably a canonical way to handle this sort of thing, but I can't
find it ATM. Good luck!

On Fri, Nov 15, 2019 at 5:00 AM <beginners-request at haskell.org> wrote:

> Send Beginners mailing list submissions to
>         beginners at haskell.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> or, via email, send a message with subject or body 'help' to
>         beginners-request at haskell.org
>
> You can reach the person managing the list at
>         beginners-owner at haskell.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Beginners digest..."
>
>
> Today's Topics:
>
>    1.  Expose every Function of a wrapped type (Leonhard Applis)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Fri, 15 Nov 2019 11:36:03 +0000
> From: Leonhard Applis <Leonhard.Applis at protonmail.com>
> To: "beginners at haskell.org" <beginners at haskell.org>
> Subject: [Haskell-beginners] Expose every Function of a wrapped type
> Message-ID:
>
> <8VyrlRTZwYrqqkI95kJ3UHQ41YSXFwhcqA4orOfVyau1ULCyCnVVkPI__Ya6rLaYFCUrVB3yM0IqT_l5NcCiMHhyfjsRg0S2xmxG3Cmvkq0=@
> protonmail.com>
>
> Content-Type: text/plain; charset="utf-8"
>
> Hi,
>
> I currently have a newtype definition of a typed Data.Map.
>
> newtype G = G Data.Map String Values
>
> I have done this because for my specific use-case, I can define G as a
> monoid and get some nice benefits.
>
> However, I find myself often just re-declaring functions of Data.Map and
> wrap/unwrap them in my Constructor G, such as
>
> singleton :: String -> Value -> G
> singleton s v = G $ (Data.Map.singleton s v)
>
> I think I do not need to limit the scope of G's functionality, I basically
> want everything from Data.Map + Bonus , like my Monoid.
> Also I want G to be a specific Data.Map, there is never any other case
> where it's not a Map String Values.
>
> However, if I have
>
> type G2 = Data.Map String Values
>
> I cannot instance Monoid.
>
> So, I am very sure that I'm not the first person ever doing this. Is there
> a language extension providing what I want? Or is what i want "bad"?
> Am I just missing a higher-order base function which does what I want?
>
> best regards & thanks
> Leonhard
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mail.haskell.org/pipermail/beginners/attachments/20191115/904e640f/attachment-0001.html
> >
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: publickey - Leonhard.Applis at protonmail.com - 0x807FDDF3.asc
> Type: application/pgp-keys
> Size: 1843 bytes
> Desc: not available
> URL: <
> http://mail.haskell.org/pipermail/beginners/attachments/20191115/904e640f/attachment-0001.key
> >
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: signature.asc
> Type: application/pgp-signature
> Size: 477 bytes
> Desc: OpenPGP digital signature
> URL: <
> http://mail.haskell.org/pipermail/beginners/attachments/20191115/904e640f/attachment-0001.sig
> >
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
> ------------------------------
>
> End of Beginners Digest, Vol 137, Issue 2
> *****************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20191116/f4d9e485/attachment.html>


More information about the Beginners mailing list