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: suggestions for re-implementing mapM (Vale Cofer-Shabica)
2. Arrow vs. function (martin)
3. Re: Arrow vs. function (John Wiegley)
4. Re: Arrow vs. function (John Wiegley)
5. Mastermind (Mike Houghton)
6. Re: Mastermind (Frerich Raabe)
7. Re: Mastermind (Ngoc Dao)
----------------------------------------------------------------------
Message: 1
Date: Mon, 23 Mar 2015 15:03:15 -0400
From: Vale Cofer-Shabica <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] suggestions for re-implementing mapM
Message-ID:
<CAAzfV4QVtkne1d46L+=4hoZX_4buM=-smkvqcpe56jy3zer...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Thanks, David
I appreciate the suggestions.
vale
On Fri, Mar 20, 2015 at 4:07 PM, David McBride <[email protected]> wrote:
> Sometimes it is easier to write it with do notation and then rewrite it
> back in normal terms:
>
> mapM :: Monad m => (a -> m b) -> [a] -> m [b]
> mapM _ [] = return []
> mapM f (x:xs) = do
> x' <- f x
> xs' <- mapM f xs
> return $ x':xs'
>
> You can rewrite the second part step by step as:
>
> mapM f (x:xs) = f x >>= \x' -> mapM f xs >>= \xs' -> return (x' : xs')
>
> Also the base package does not use do notation. It defines it much more
> elegantly:
>
> mapM :: Monad m => (a -> m b) -> [a] -> m [b]mapM f as =
> sequence (map f as)
>
>
>
>
> On Fri, Mar 20, 2015 at 3:52 PM, Vale Cofer-Shabica <
> [email protected]> wrote:
>
>> Hello all,
>>
>> I've been reading through "Tackling the Awkward Squad" [1] and am
>> implementing the definitions "left as exercises" as I go. For section 2.2,
>> I define:
>>
>> putLine :: [Char] -> IO ()
>> putLine :: mapM_ putChar
>>
>> where
>>
>> mapM_ :: Monad m => (a -> m b) -> a -> m ()
>> mapM_ f [] = return ()
>> mapM_ f (x:xs) = (f x) >> (mapM_ f xs)
>>
>> which works without difficulty. For the sake of learning, I decided to
>> implement mapM as well. My definition (below) works, but seems really
>> in-elegant. I checked the prelude source and found mapM defined in terms of
>> sequence, which has some do-notation I'm not so clear on. I'm trying to
>> avoid using do notation in my implementation because it still feels like
>> magic. I'll work on de-sugaring do notation again once I have a solid
>> handle on (>>=), (>>), and return. Any suggestions for cleaning this up
>> would be much appreciated!
>>
>> mapM :: Monad m => (a -> m b) -> [a] -> m [b]
>> mapM f [] = return []
>> mapM f (x:xs) = consMM (f x) (mapM f xs)
>>
>> consMM :: Monad m => m a -> m [a] -> m [a]
>> consMM mx mxs = mx >>= ((flip consM) mxs) where
>> consM x mxs = mxs>>=(\xs -> return (x:xs))
>>
>> Thank you,
>> vale
>>
>> [1] Suggested by apfelmus in a recent email to the list:
>>
>> http://research.microsoft.com/en-us/um/people/simonpj/papers/marktoberdorf/
>>
>> _______________________________________________
>> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150323/a1c8826e/attachment-0001.html>
------------------------------
Message: 2
Date: Mon, 23 Mar 2015 21:43:24 +0100
From: martin <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Arrow vs. function
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Hello all
I skimmed several Arrow tutorial and looked at the pretty diagrams and thought
to myself "Hmm, these guys seem to take
input and produce output".
But that's what a function does. So what's the fundamental difference between
an arrow and a fuction?
------------------------------
Message: 3
Date: Mon, 23 Mar 2015 15:57:29 -0500
From: "John Wiegley" <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Arrow vs. function
Message-ID: <[email protected]>
Content-Type: text/plain
>>>>> martin <[email protected]> writes:
> But that's what a function does. So what's the fundamental difference
> between an arrow and a fuction?
Arrows abstract functions, allowing you to have constructions like Kleisli,
which are Arrows, but compose in the presence of effects using (<=<) rather
than (.).
John
------------------------------
Message: 4
Date: Mon, 23 Mar 2015 16:11:44 -0500
From: John Wiegley <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Arrow vs. function
Message-ID: <[email protected]>
Content-Type: text/plain
>>>>> John Wiegley <[email protected]> writes:
> Arrows abstract functions, allowing you to have constructions like Kleisli,
> which are Arrows, but compose in the presence of effects using (<=<) rather
> than (.).
That is, you compose them using (<<<) as you would using any other Arrow, but
the Arrow instance is using a different form of composition under the hood.
John
------------------------------
Message: 5
Date: Mon, 23 Mar 2015 22:06:15 +0000
From: Mike Houghton <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Mastermind
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Hi All,
I?m working through http://www.seas.upenn.edu/~cis194/hw/02-lists.pdf
<http://www.seas.upenn.edu/~cis194/hw/02-lists.pdf> - the homework for the CIS
194 Haskell course.
I ?stuck? on question 6!
If anyone has done this I?d really appreciate a pointer to solving it.
The problem is, given these colors
colors = [Red, Green, Blue, Yellow, Orange, Purple]
we first need to be able to generate a list of all
the codes, ie all length n combinations of the 6 colors. In general, Mastermind
games use codes of length 4, however in theory the code could be any length. We
have not yet made any assumptions about the lengths of the codes, so why start
now? Your function should take in a length and return all Codes of that length:
allCodes :: Int -> [Code]
Hint: This exercise is a bit tricky. Try using a helper function that takes in
all the codes of length n ? 1 and uses it to produce all codes of length n. You
may find the concatMap function helpful.
Now this
[ [a,b,c,d] | a<-colors, b<-colors, c<-colors, d<-colors]
will work for codes of length 4 but clearly doesn?t provide the general
solution.
I?m just not seeing it yet!!!!
Thanks
Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150323/08840e0b/attachment-0001.html>
------------------------------
Message: 6
Date: Mon, 23 Mar 2015 23:46:04 +0100
From: Frerich Raabe <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Mastermind
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
Hi Mike,
On 2015-03-23 23:06, Mike Houghton wrote:
> I?m working through http://www.seas.upenn.edu/~cis194/hw/02-lists.pdf [1] -
> the homework for the CIS 194 Haskell course.
> I ?stuck? on question 6!
> If anyone has done this I?d really appreciate a pointer to solving it.
Just thinking out loud:
Consider that to get all lists of length 2, you could add (e.g. prepend) each
of the six colors to each of the lists of length 1. And to get each of the
lists of length 1 you prepend each of the six colors to each of the lists of
length 0.
Does that help? :-)
--
Frerich Raabe - [email protected]
www.froglogic.com - Multi-Platform GUI Testing
------------------------------
Message: 7
Date: Tue, 24 Mar 2015 07:57:46 +0900
From: Ngoc Dao <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Mastermind
Message-ID:
<cahqxikksugur5q2drsdsk+u06shlaxgawt_v2whtelgf+w7...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Mike,
You may have noticed Frerich was saying about recursion.
I will provide you some more topics/keywords so that you can
investigate further:
You should practise writing the recursion in 2 ways:
normal recursion and tail recursion (to avoid stackoverflow when the
recursion depth is large)
For the tail recursion, you use the accumulator pattern, which is very
common in functional programming.
On Tue, Mar 24, 2015 at 7:46 AM, Frerich Raabe <[email protected]> wrote:
> Hi Mike,
>
> On 2015-03-23 23:06, Mike Houghton wrote:
>>
>> I?m working through http://www.seas.upenn.edu/~cis194/hw/02-lists.pdf [1]
>> - the homework for the CIS 194 Haskell course.
>> I ?stuck? on question 6!
>> If anyone has done this I?d really appreciate a pointer to solving it.
>
>
> Just thinking out loud:
>
> Consider that to get all lists of length 2, you could add (e.g. prepend)
> each of the six colors to each of the lists of length 1. And to get each of
> the lists of length 1 you prepend each of the six colors to each of the
> lists of length 0.
>
> Does that help? :-)
>
> --
> Frerich Raabe - [email protected]
> www.froglogic.com - Multi-Platform GUI Testing
> _______________________________________________
> 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 81, Issue 55
*****************************************