Send Beginners mailing list submissions to
[email protected]
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
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Applicative: how <*> really works (David McBride)
2. Re: Applicative: how <*> really works (Yassine)
3. Re: Applicative: how <*> really works (Jeffrey Brown)
4. Re: Applicative: how <*> really works (sasa bogicevic)
5. Re: Applicative: how <*> really works (sasa bogicevic)
----------------------------------------------------------------------
Message: 1
Date: Fri, 4 Aug 2017 14:04:55 -0400
From: David McBride <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Applicative: how <*> really works
Message-ID:
<can+tr40xruubc5phxh2ujzzbqe9yr0pr2ag8rjphydzn3_m...@mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"
This is a bit complicated for this list. You might have a bit more
luck posting this to stackoverflow.com.
On Thu, Aug 3, 2017 at 3:19 PM, Yassine <[email protected]> wrote:
> Hi,
>
> I have a question about functor applicate.
>
> I know that:
> pure (+1) <*> Just 2
>
>
> produce: Just 3
> because pure (+1) produce Just (+1) and then Just (+1) <*> Just 2
> produce Just (2+1)
>
>
> but in more complex case like:
> newtype Parser a = P (String -> [(a,String)])
>
> parse :: Parser a -> String -> [(a,String)]
> parse (P p) inp = p inp
>
>
> item :: Parser Char
> item = P (\inp -> case inp of
> [] -> []
> (x:xs) -> [(x,xs)])
>
> instance Functor Parser where
> fmap g p = P (\inp -> case p inp of
> [] -> []
> [(v, out)] -> [(g v, out)])
>
> instance Applicative Parser where
> pure v = P (\inp -> [(v, inp)])
> pg <*> px = P (\inp -> case parse pg inp of
> [] -> []
> [(g, out)] -> parse (fmap g px) out)
>
>
> When I do:
> parse (pure (\x y -> (x,y)) <*> item <*> item) "abc"
>
> The answer is:
> [(('a','b'),"c")]
>
> But I don't understand what exactly happens.
> First:
> pure (\x y -> (x,y)) => P (\inp -> [(\x y -> (x,y), inp)])
>
> Then:
> P (\inp -> [(\x y -> (x,y), inp)]) <*> item => ???
>
> Can someone explain what's happens step by step please.
>
> Thank you.
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
Message: 2
Date: Fri, 4 Aug 2017 21:04:10 +0200
From: Yassine <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Applicative: how <*> really works
Message-ID:
<cafr2bdd8g5xwtjdvtqpom0c5oao-unwquqejj+fzyf9szwg...@mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"
Ok, thanks for your answer
2017-08-04 20:04 GMT+02:00 David McBride <[email protected]>:
> This is a bit complicated for this list. You might have a bit more
> luck posting this to stackoverflow.com.
>
> On Thu, Aug 3, 2017 at 3:19 PM, Yassine <[email protected]> wrote:
>> Hi,
>>
>> I have a question about functor applicate.
>>
>> I know that:
>> pure (+1) <*> Just 2
>>
>>
>> produce: Just 3
>> because pure (+1) produce Just (+1) and then Just (+1) <*> Just 2
>> produce Just (2+1)
>>
>>
>> but in more complex case like:
>> newtype Parser a = P (String -> [(a,String)])
>>
>> parse :: Parser a -> String -> [(a,String)]
>> parse (P p) inp = p inp
>>
>>
>> item :: Parser Char
>> item = P (\inp -> case inp of
>> [] -> []
>> (x:xs) -> [(x,xs)])
>>
>> instance Functor Parser where
>> fmap g p = P (\inp -> case p inp of
>> [] -> []
>> [(v, out)] -> [(g v, out)])
>>
>> instance Applicative Parser where
>> pure v = P (\inp -> [(v, inp)])
>> pg <*> px = P (\inp -> case parse pg inp of
>> [] -> []
>> [(g, out)] -> parse (fmap g px) out)
>>
>>
>> When I do:
>> parse (pure (\x y -> (x,y)) <*> item <*> item) "abc"
>>
>> The answer is:
>> [(('a','b'),"c")]
>>
>> But I don't understand what exactly happens.
>> First:
>> pure (\x y -> (x,y)) => P (\inp -> [(\x y -> (x,y), inp)])
>>
>> Then:
>> P (\inp -> [(\x y -> (x,y), inp)]) <*> item => ???
>>
>> Can someone explain what's happens step by step please.
>>
>> Thank you.
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
Message: 3
Date: Fri, 4 Aug 2017 16:02:31 -0400
From: Jeffrey Brown <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Applicative: how <*> really works
Message-ID:
<CAEc4Ma1X27g6M1FztE74sLWEJau52PqmAAm--DN8FT0wO=2...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
If you post there, you could put the link on this thread; I'd be interested.
On Fri, Aug 4, 2017 at 3:04 PM, Yassine <[email protected]> wrote:
> Ok, thanks for your answer
>
> 2017-08-04 20:04 GMT+02:00 David McBride <[email protected]>:
> > This is a bit complicated for this list. You might have a bit more
> > luck posting this to stackoverflow.com.
> >
> > On Thu, Aug 3, 2017 at 3:19 PM, Yassine <[email protected]> wrote:
> >> Hi,
> >>
> >> I have a question about functor applicate.
> >>
> >> I know that:
> >> pure (+1) <*> Just 2
> >>
> >>
> >> produce: Just 3
> >> because pure (+1) produce Just (+1) and then Just (+1) <*> Just 2
> >> produce Just (2+1)
> >>
> >>
> >> but in more complex case like:
> >> newtype Parser a = P (String -> [(a,String)])
> >>
> >> parse :: Parser a -> String -> [(a,String)]
> >> parse (P p) inp = p inp
> >>
> >>
> >> item :: Parser Char
> >> item = P (\inp -> case inp of
> >> [] -> []
> >> (x:xs) -> [(x,xs)])
> >>
> >> instance Functor Parser where
> >> fmap g p = P (\inp -> case p inp of
> >> [] -> []
> >> [(v, out)] -> [(g v, out)])
> >>
> >> instance Applicative Parser where
> >> pure v = P (\inp -> [(v, inp)])
> >> pg <*> px = P (\inp -> case parse pg inp of
> >> [] -> []
> >> [(g, out)] -> parse (fmap g px) out)
> >>
> >>
> >> When I do:
> >> parse (pure (\x y -> (x,y)) <*> item <*> item) "abc"
> >>
> >> The answer is:
> >> [(('a','b'),"c")]
> >>
> >> But I don't understand what exactly happens.
> >> First:
> >> pure (\x y -> (x,y)) => P (\inp -> [(\x y -> (x,y), inp)])
> >>
> >> Then:
> >> P (\inp -> [(\x y -> (x,y), inp)]) <*> item => ???
> >>
> >> Can someone explain what's happens step by step please.
> >>
> >> Thank you.
> >> _______________________________________________
> >> Beginners mailing list
> >> [email protected]
> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
--
Jeff Brown | Jeffrey Benjamin Brown
Website <https://msu.edu/~brown202/> | Facebook
<https://www.facebook.com/mejeff.younotjeff> | LinkedIn
<https://www.linkedin.com/in/jeffreybenjaminbrown>(spammy, so I often miss
messages here) | Github <https://github.com/jeffreybenjaminbrown>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20170804/e48790c0/attachment-0001.html>
------------------------------
Message: 4
Date: Fri, 4 Aug 2017 22:06:45 +0200
From: sasa bogicevic <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Applicative: how <*> really works
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Hey does this even compile for you ?
I get this in the Functor instance for Parser
• Couldn't match expected type ‘String -> [(a, String)]’
with actual type ‘Parser a’
• The function ‘p’ is applied to one argument,
but its type ‘Parser a’ has none
In the expression: p inp
In the expression:
case p inp of {
[] -> []
[(v, out)] -> [(g v, out)] }
• Relevant bindings include
p :: Parser a (bound at src/Mailinglistproblem.hs:19:10)
g :: a -> b (bound at src/Mailinglistproblem.hs:19:8)
fmap :: (a -> b) -> Parser a -> Parser b
{
name: Bogicevic Sasa
phone: +381606006200
}
> On Aug 4, 2017, at 22:02, Jeffrey Brown <[email protected]> wrote:
>
> If you post there, you could put the link on this thread; I'd be interested.
>
> On Fri, Aug 4, 2017 at 3:04 PM, Yassine <[email protected]> wrote:
> Ok, thanks for your answer
>
> 2017-08-04 20:04 GMT+02:00 David McBride <[email protected]>:
> > This is a bit complicated for this list. You might have a bit more
> > luck posting this to stackoverflow.com.
> >
> > On Thu, Aug 3, 2017 at 3:19 PM, Yassine <[email protected]> wrote:
> >> Hi,
> >>
> >> I have a question about functor applicate.
> >>
> >> I know that:
> >> pure (+1) <*> Just 2
> >>
> >>
> >> produce: Just 3
> >> because pure (+1) produce Just (+1) and then Just (+1) <*> Just 2
> >> produce Just (2+1)
> >>
> >>
> >> but in more complex case like:
> >> newtype Parser a = P (String -> [(a,String)])
> >>
> >> parse :: Parser a -> String -> [(a,String)]
> >> parse (P p) inp = p inp
> >>
> >>
> >> item :: Parser Char
> >> item = P (\inp -> case inp of
> >> [] -> []
> >> (x:xs) -> [(x,xs)])
> >>
> >> instance Functor Parser where
> >> fmap g p = P (\inp -> case p inp of
> >> [] -> []
> >> [(v, out)] -> [(g v, out)])
> >>
> >> instance Applicative Parser where
> >> pure v = P (\inp -> [(v, inp)])
> >> pg <*> px = P (\inp -> case parse pg inp of
> >> [] -> []
> >> [(g, out)] -> parse (fmap g px) out)
> >>
> >>
> >> When I do:
> >> parse (pure (\x y -> (x,y)) <*> item <*> item) "abc"
> >>
> >> The answer is:
> >> [(('a','b'),"c")]
> >>
> >> But I don't understand what exactly happens.
> >> First:
> >> pure (\x y -> (x,y)) => P (\inp -> [(\x y -> (x,y), inp)])
> >>
> >> Then:
> >> P (\inp -> [(\x y -> (x,y), inp)]) <*> item => ???
> >>
> >> Can someone explain what's happens step by step please.
> >>
> >> Thank you.
> >> _______________________________________________
> >> Beginners mailing list
> >> [email protected]
> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
>
> --
> Jeff Brown | Jeffrey Benjamin Brown
> Website | Facebook | LinkedIn(spammy, so I often miss messages here)
> | Github
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
Message: 5
Date: Fri, 4 Aug 2017 22:10:39 +0200
From: sasa bogicevic <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Applicative: how <*> really works
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Ok there was a constructor missing, maybe you should create a gist so we can
help out
instance Functor Parser where
fmap g (P p) = P (\inp -> case p inp of
[] -> []
[(v, out)] -> [(g v, out)])
{
name: Bogicevic Sasa
phone: +381606006200
}
> On Aug 4, 2017, at 22:02, Jeffrey Brown <[email protected]> wrote:
>
> If you post there, you could put the link on this thread; I'd be interested.
>
> On Fri, Aug 4, 2017 at 3:04 PM, Yassine <[email protected]> wrote:
> Ok, thanks for your answer
>
> 2017-08-04 20:04 GMT+02:00 David McBride <[email protected]>:
> > This is a bit complicated for this list. You might have a bit more
> > luck posting this to stackoverflow.com.
> >
> > On Thu, Aug 3, 2017 at 3:19 PM, Yassine <[email protected]> wrote:
> >> Hi,
> >>
> >> I have a question about functor applicate.
> >>
> >> I know that:
> >> pure (+1) <*> Just 2
> >>
> >>
> >> produce: Just 3
> >> because pure (+1) produce Just (+1) and then Just (+1) <*> Just 2
> >> produce Just (2+1)
> >>
> >>
> >> but in more complex case like:
> >> newtype Parser a = P (String -> [(a,String)])
> >>
> >> parse :: Parser a -> String -> [(a,String)]
> >> parse (P p) inp = p inp
> >>
> >>
> >> item :: Parser Char
> >> item = P (\inp -> case inp of
> >> [] -> []
> >> (x:xs) -> [(x,xs)])
> >>
> >> instance Functor Parser where
> >> fmap g p = P (\inp -> case p inp of
> >> [] -> []
> >> [(v, out)] -> [(g v, out)])
> >>
> >> instance Applicative Parser where
> >> pure v = P (\inp -> [(v, inp)])
> >> pg <*> px = P (\inp -> case parse pg inp of
> >> [] -> []
> >> [(g, out)] -> parse (fmap g px) out)
> >>
> >>
> >> When I do:
> >> parse (pure (\x y -> (x,y)) <*> item <*> item) "abc"
> >>
> >> The answer is:
> >> [(('a','b'),"c")]
> >>
> >> But I don't understand what exactly happens.
> >> First:
> >> pure (\x y -> (x,y)) => P (\inp -> [(\x y -> (x,y), inp)])
> >>
> >> Then:
> >> P (\inp -> [(\x y -> (x,y), inp)]) <*> item => ???
> >>
> >> Can someone explain what's happens step by step please.
> >>
> >> Thank you.
> >> _______________________________________________
> >> Beginners mailing list
> >> [email protected]
> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
>
> --
> Jeff Brown | Jeffrey Benjamin Brown
> Website | Facebook | LinkedIn(spammy, so I often miss messages here)
> | Github
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 110, Issue 8
*****************************************