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.  How to make instance of MonoFunctor (Baa)
   2. Re:  How to make instance of MonoFunctor (Michael Snoyman)
   3. Re:  How to make instance of MonoFunctor (Baa)


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

Message: 1
Date: Thu, 10 Aug 2017 11:35:52 +0300
From: Baa <aqua...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] How to make instance of MonoFunctor
Message-ID: <20170810113552.08831716@Pavel>
Content-Type: text/plain; charset=UTF-8

Hello, Dear List!

I want to make functor of my type like

  newtype UserName = UserName { unName :: Text }

sure, it's impossible, so I will make MonoFunctor instead of (from
library mono-traversable). So, I try:

  instance MonoFunctor UserName where
    omap fn (UserName n) = UserName $ fn $ n

but I get error

        • Couldn't match expected type ‘Element UserName’
                      with actual type ‘Text’
        • In the second argument of ‘($)’, namely ‘unName an’
          In the second argument of ‘($)’, namely ‘fn $ unName an’
          In the expression: UserName $ fn $ unName an

interesting is that Text "type Element Text" of "type family Element
mono" (instance?). So, how to make mono-functor for such `UserName`
structure?


--
Best regards, Paul


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

Message: 2
Date: Thu, 10 Aug 2017 11:58:04 +0300
From: Michael Snoyman <mich...@snoyman.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] How to make instance of MonoFunctor
Message-ID:
        <CAKT9ecN0ORwDAa=8-DJk87jZtk=nsdln5qgk6c3+orjzjch...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

What do you want the type of `omap` to be for `UserName`? There are two
reasonable definitions:

omap :: (Text -> Text) -> (UserName -> UserName)
omap :: (Char -> Char) -> (UserName -> UserName)

The first one is saying that a UserName is a container of a single Text
value. The second is that a UserName is a container of a sequence of Char
values. Once you figure out what the answer to this question is, you'll
need to use an associated type called Element to specify what you intend,
e.g.:

type Element UserName = Char

On Thu, Aug 10, 2017 at 11:35 AM, Baa <aqua...@gmail.com> wrote:

> Hello, Dear List!
>
> I want to make functor of my type like
>
>   newtype UserName = UserName { unName :: Text }
>
> sure, it's impossible, so I will make MonoFunctor instead of (from
> library mono-traversable). So, I try:
>
>   instance MonoFunctor UserName where
>     omap fn (UserName n) = UserName $ fn $ n
>
> but I get error
>
>         • Couldn't match expected type ‘Element UserName’
>                       with actual type ‘Text’
>         • In the second argument of ‘($)’, namely ‘unName an’
>           In the second argument of ‘($)’, namely ‘fn $ unName an’
>           In the expression: UserName $ fn $ unName an
>
> interesting is that Text "type Element Text" of "type family Element
> mono" (instance?). So, how to make mono-functor for such `UserName`
> structure?
>
>
> --
> Best regards, Paul
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20170810/b45d143e/attachment-0001.html>

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

Message: 3
Date: Thu, 10 Aug 2017 12:34:30 +0300
From: Baa <aqua...@gmail.com>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] How to make instance of MonoFunctor
Message-ID: <20170810123430.77e47a39@Pavel>
Content-Type: text/plain; charset=UTF-8

Aha, so I missed:

  type instance Element UserName = Text

and now this is right:

  instance MonoFunctor UserName where
    omap fn n = UserName $ fn $ unName n

Yes, this will be omap :: (Text -> Text) -> (UserName -> UserName).

Many thanks!!


> What do you want the type of `omap` to be for `UserName`? There are
> two reasonable definitions:
> 
> omap :: (Text -> Text) -> (UserName -> UserName)
> omap :: (Char -> Char) -> (UserName -> UserName)
> 
> The first one is saying that a UserName is a container of a single
> Text value. The second is that a UserName is a container of a
> sequence of Char values. Once you figure out what the answer to this
> question is, you'll need to use an associated type called Element to
> specify what you intend, e.g.:
> 
> type Element UserName = Char
> 
> On Thu, Aug 10, 2017 at 11:35 AM, Baa <aqua...@gmail.com> wrote:
> 
> > Hello, Dear List!
> >
> > I want to make functor of my type like
> >
> >   newtype UserName = UserName { unName :: Text }
> >
> > sure, it's impossible, so I will make MonoFunctor instead of (from
> > library mono-traversable). So, I try:
> >
> >   instance MonoFunctor UserName where
> >     omap fn (UserName n) = UserName $ fn $ n
> >
> > but I get error
> >
> >         • Couldn't match expected type ‘Element UserName’
> >                       with actual type ‘Text’
> >         • In the second argument of ‘($)’, namely ‘unName an’
> >           In the second argument of ‘($)’, namely ‘fn $ unName an’
> >           In the expression: UserName $ fn $ unName an
> >
> > interesting is that Text "type Element Text" of "type family Element
> > mono" (instance?). So, how to make mono-functor for such `UserName`
> > structure?
> >
> >
> > --
> > Best regards, Paul
> > _______________________________________________
> > Beginners mailing list
> > Beginners@haskell.org
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >  



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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 110, Issue 13
******************************************

Reply via email to