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-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Expose every Function of a wrapped type (Francesco Ariis)


----------------------------------------------------------------------

Message: 1
Date: Fri, 15 Nov 2019 15:11:12 +0100
From: Francesco Ariis <fa...@ariis.it>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Expose every Function of a wrapped
        type
Message-ID: <20191115141112.ga15...@x60s.casa>
Content-Type: text/plain; charset=iso-8859-1

Hello Leonardh,
    a couple of ideas:

On Fri, Nov 15, 2019 at 11:36:03AM +0000, Leonhard Applis wrote:
> I currently have a newtype definition of a typed Data.Map. 
> 
> newtype G = G Data.Map String Values 
> 
> [...]
> 
> However, if I have 
> 
> type G2 = Data.Map String Values 

`Map k v` is already an instance of `Monoid` (when `v` is an instance
of `Ord`), are you sure you need to write another one? If the answer
is "yes", you can write a small helper:

    withG :: (M.Map String a -> M.Map String a) -> G a -> G a
    withG mf (G m) = G $ mf m

or use GeneralizedNewtypeDeriving to ease some pain:

    {-# Language GeneralizedNewtypeDeriving #-}

    module Prova where

    import Data.Map as M
    import GHC.Exts

    newtype G a = G { unwrapG :: M.Map String a }
        deriving (Eq, Show, Functor, Foldable)


------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 137, Issue 3
*****************************************

Reply via email to