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:  Mastermind (Mike Houghton)
   2. Re:  Arrow vs. function (Michael Orlitzky)
   3. Re:  Mastermind (Ngoc Dao)
   4. Re:  Dipping Toes Into Haskell (Timothy Washington)


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

Message: 1
Date: Mon, 23 Mar 2015 23:13:46 +0000
From: Mike Houghton <[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

Thanks guys - I think the light has just gone on!
;)

> On 23 Mar 2015, at 22:57, Ngoc Dao <[email protected]> wrote:
> 
> 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
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



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

Message: 2
Date: Mon, 23 Mar 2015 19:53:25 -0400
From: Michael Orlitzky <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Arrow vs. function
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8

On 03/23/2015 04:43 PM, martin wrote:
> 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?

They're basically functions, and you won't steer yourself wrong thinking
about them like that.

By analogy, in Haskell, if you wanted to add two floating point numbers
you would need to define a floating point addition:

  floatAdd :: Float -> Float -> Float

Then if you wanted to add two integers, you'd need a second function:

  intAdd :: Int -> Int -> Int

The prelude already abstracts this away for you -- both Int and Float
are instances of the Num class, which gives you,

  (+) :: (Num a) => a -> a -> a

So at that point, you might ask yourself, what's the point of a Num?
Aren't they just (floating point, int, etc.) numbers? The answer is
"yes," and you don't want to have twenty different addition functions
for everything that is some kind of number, so it makes sense to group
all number-things into one typeclass.

Likewise, all function-things are grouped into the Arrow typeclass so
that you can compose them without worrying about the exact type.
Everything in the Arrow typeclass is some kind of function, and you can
compose them with the Arrow class methods.



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

Message: 3
Date: Tue, 24 Mar 2015 10:15:47 +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:
        <CAHqXiK=oa721euhs_hsz0rjuvjud5ndjosoe7+unrqe0h7s...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Conceptually, you can think like this:
* Recursion is the only way to loop in functional programming.
* Things like map, filter, the sexy list comprehension etc. are just nice
helpers to help you loop without having to write the recursion yourself.
* When you can't see a straight forward way to use the helpers, you can
always fall back to write the recursion yourself.

It's a good exercise to spend about an hour to try to implement the map,
filter etc. yourself, using recursion, to see what their
implementations look like.


On Tuesday, March 24, 2015, Mike Houghton <[email protected]>
wrote:

> Thanks guys - I think the light has just gone on!
> ;)
>
> > On 23 Mar 2015, at 22:57, Ngoc Dao <[email protected]
> <javascript:;>> wrote:
> >
> > 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]
> <javascript:;>> 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] <javascript:;>
> >> www.froglogic.com - Multi-Platform GUI Testing
> >> _______________________________________________
> >> Beginners mailing list
> >> [email protected] <javascript:;>
> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> > _______________________________________________
> > Beginners mailing list
> > [email protected] <javascript:;>
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
> _______________________________________________
> Beginners mailing list
> [email protected] <javascript:;>
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150324/69963aae/attachment-0001.html>

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

Message: 4
Date: Mon, 23 Mar 2015 19:38:24 -0700
From: Timothy Washington <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Dipping Toes Into Haskell
Message-ID:
        <CAADtM-a7rEN-5p50DY2+zovsVd-++M3qAAmqQt5caZ4W=qc...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hey man...


On Mon, Mar 23, 2015 at 4:57 AM, Bob Hutchison <[email protected]>
wrote:

> Hi Tim,
>
> Straying from clojure? :-)
>
>
Lol, love it!! I'm a free spirit. Can't hold me down :)



> On Mar 22, 2015, at 12:33 PM, Timothy Washington <[email protected]>
> wrote:
>
> So I've finally had a chance to revisit my tictactoe game.
>
>
> import Control.Lens
>
> data Piece = X | O | E deriving Show
> type Row = [Piece]
> type Board = [Row]
> *data Position = Int Int deriving Show*
>
> -- put an X or O in a position
> *move :: Board -> Piece -> Position -> Board*
> move board piece position = board
>
> main :: IO ()
> main = putStrLn "Hello World"
>
> Now, if I want to make a move, I'll want to set a *piece* on a *position*,
> on a *board*. Let's assume the board has the following shape.
>
> ?> let r1 = (E,E,E)
> ?> let r2 = (E,E,E)
> ?> let r3 = (E,E,E)
> ?> let board = (r1,r2,r3)
> ((E,E,E),(E,E,E),(E,E,E))
>
>
> To return an updated board, I dug around and *i)* couldn't find a core
> Haskell equivalent to Clojure's update-in
> <http://clojuredocs.org/clojure.core/update-in>. *ii)* Zippers only deal
> with trees of left / right nodes. *iii)* So that left me with Control.Lens
> <https://github.com/ekmett/lens/wiki/Examples>. Now I can easily inspect
> and update the board like so.
>
>
> Or you could use an two dimensional array of Positions instead
> (Data.Array).
>

Hmm, probably. But the function's type signature below, seem to be the
first order of business, no?



> ?> board^*._**2._1*
> E
> ?> set (*_2._1*) 42 board
> ((E,E,E),(42,E,E),(E,E,E))
>
>
> I can then parameterize _2 or _1 like so.
>
> ?> let a = _2
> ?> board ^. a
> (E,E,E)
>
>
> You can probably find the type of _1, _2, _3 in the repl, and use that in
> your code below.
>

The types (:t ...) of both of these are:

   - a :: (Field2 s t a b, Functor f) => (a -> f b) -> s -> f t
   - _2 :: (Field2 s t a b, Functor f) => (a -> f b) -> s -> f t



> But I can't figure out how to include that parameter's type into a
> *Position* type definition. I've tried these unsuccessfully.
>
> *data Position = Int Int deriving Show  -- original type definition*
> *data Position = Simple Lens (Int a) (Int a) deriving Show  -- failing try
> 1*
>
>
> These are very suspicious. Did you intend to define constructors ?Int? and
> ?Simple?? Maybe you meant something like:
>
> data Position = Position Int Int deriving Show
>
> In which case you?ll have a type called ?Position? and a constructor with
> the same name.
>
> Cheers,
> Bob
>
>
So ultimately I want a function signature that lets me pass in a lens
position.

-- 1. these 2 don't compile together

data Position = Position Int Int deriving Show

move :: Board -> Piece -> Position -> Board
move board piece position = set (position) piece board



-- 2. and using the (:t ...) type definition abouve, none of these work

move :: Board -> Piece -> ((Field2 s t a b, Functor f) => (a -> f b) -> s
-> f t) -> Board
-- move :: Board -> Piece -> ((a -> f b) -> s -> f t) -> Board
-- move :: Board -> Piece -> (a -> f b) -> Board
-- move :: Board -> Piece -> (s -> f t) -> Board

move board piece position = set (position) piece board


-- 3. so the below code compiles, but doesn't do me much good... I need
Position to be a lens, such that I can use A) *set (position) piece board*
, instead of B) *set (_2._1) 42 board*

module Main where

import Control.Lens

data Piece = X | O | E deriving Show
type Row = [Piece]
type Board = [Row]
*data Position = Int Int deriving Show*

*move :: Board -> Piece -> Position -> Board*
move board piece position = board

main :: IO ()
main = putStrLn "Hello World"




Cheers mate :)

Tim Washington
Interruptsoftware.com <http://interruptsoftware.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150323/13089df0/attachment.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 81, Issue 56
*****************************************

Reply via email to