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. Applicative: how <*> really works (Yassine)
2. Password Program Questions (Casey Newsome)
3. Re: Password Program Questions (David McBride)
----------------------------------------------------------------------
Message: 1
Date: Thu, 3 Aug 2017 21:19:49 +0200
From: Yassine <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Applicative: how <*> really works
Message-ID:
<CAFr2bdC3ts9z6wkWEfenpAXdE5_cTVuL4n=drk-zzlr3z28...@mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"
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.
------------------------------
Message: 2
Date: Thu, 3 Aug 2017 22:59:27 +0000 (UTC)
From: Casey Newsome <[email protected]>
To: "[email protected]" <[email protected]>
Subject: [Haskell-beginners] Password Program Questions
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
I am very new to Haskell and I am attempting to make a simple password program
as my first program. I have ran into a problem and I am not very sure on how to
fix it. I do not know how to make a second section for the passwords. My
guessing attempts have failed so I am asking for help.
Here is my code
main = do putStrLn "Hello, Who are you?" name <- getLine --User
Input putStrLn ("Hey " ++ name ++ ", What's the password?") pass <-
getLine if pass == "12345" then putStrLn ("Welcome") pw
else do putStrLn "That is wrong!" mainpw = do
putStrLn "What Password do you need?"
Thanks in advance, Casey :D
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20170803/f475ee36/attachment-0001.html>
------------------------------
Message: 3
Date: Thu, 3 Aug 2017 19:39:04 -0400
From: David McBride <[email protected]>
To: Casey Newsome <[email protected]>, The Haskell-Beginners
Mailing List - Discussion of primarily beginner-level topics related
to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Password Program Questions
Message-ID:
<can+tr40zyqzqd4kzwv8fkgq0gfvavzuob8wirt8v7ah980m...@mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"
Remember that haskell is whitespace delimited. You probably intended
putStrLn "Welcome" to line up with pw, in its own do.
if pass == "12345"
then do
putStrLn "welcome"
pw
else do
putStrLn "wrong"
main
On Thu, Aug 3, 2017 at 6:59 PM, Casey Newsome <[email protected]> wrote:
> I am very new to Haskell and I am attempting to make a simple password
> program as my first program. I have ran into a problem and I am not very
> sure on how to fix it. I do not know how to make a second section for the
> passwords. My guessing attempts have failed so I am asking for help.
>
>
>
>
>
>
> Here is my code
>
> main = do
> putStrLn "Hello, Who are you?"
> name <- getLine --User Input
> putStrLn ("Hey " ++ name ++ ", What's the password?")
> pass <- getLine
> if pass == "12345"
> then putStrLn ("Welcome")
> pw
> else do
> putStrLn "That is wrong!"
> main
> pw = do
> putStrLn "What Password do you need?"
>
>
>
>
>
>
> Thanks in advance, Casey :D
>
>
> _______________________________________________
> 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 7
*****************************************