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

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
Send Beginners mailing list submissions to beginners@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@haskell.org
You can reach the person managing the list at beginners-owner@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
To: "beginners@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
participants (1)
-
鲍凯文