Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/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. Re:  A Week in and Clueless (Kim-Ee Yeoh)
   2. Re:  A Week in and Clueless (Ertugrul S?ylemez)
   3. Re:  A Week in and Clueless (KC)
   4. Re:  A Week in and Clueless (mukesh tiwari)


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

Message: 1
Date: Fri, 11 Jan 2013 12:50:20 +0700
From: Kim-Ee Yeoh <k...@atamo.com>
Subject: Re: [Haskell-beginners] A Week in and Clueless
To: Philip Cote <cote...@gmail.com>
Cc: "beginners@haskell.org" <beginners@haskell.org>
Message-ID:
        <CAPY+ZdQpKnkTUjy1v2e4MXo1PdddfyThZG7=o-bbypauacx...@mail.gmail.com>
Content-Type: text/plain; charset="windows-1252"

Hey Philip,

Could it be that if you get some feedback, whether from your peers or from
an instructor, you'd overcome this block?

Learning can be a lot more effective in a group.

There's a ureddit course on haskell just announced here [1]. You may want
to take a look at it.

Whether during the course or after it's over, please provide feedback here!

(Disclaimer: I'm not affiliated with it in any way. Just supporting the
community, 's all.)

[1]
http://www.reddit.com/r/haskell/comments/169k67/im_teaching_an_introductory_12week_class_on/

-- Kim-Ee


On Fri, Jan 11, 2013 at 9:44 AM, Philip Cote <cote...@gmail.com> wrote:

>  So a week into Haskell, I still seem to be not ?getting? it which is
> kind of weird in my case. I came in with knowledge of a lot of functional
> ideas from using them in Javascript and Python.  Or at least I thought I
> knew them.
>
>
> 5 chapters into "Learn You a Haskell", I admit it's not really sinking in
> for me even after typing in and running all the examples.  I acknowledge
> that I don't know jack.  Any ideas or exercises that might help me along?
>
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130111/82b59090/attachment-0001.htm>

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

Message: 2
Date: Fri, 11 Jan 2013 07:23:45 +0100
From: Ertugrul S?ylemez <e...@ertes.de>
Subject: Re: [Haskell-beginners] A Week in and Clueless
To: beginners@haskell.org
Message-ID: <20130111072345.3189f...@tritium.streitmacht.eu>
Content-Type: text/plain; charset="utf-8"

Philip Cote <cote...@gmail.com> wrote:

> So a week into Haskell, I still seem to be not ?getting? it which is
> kind of weird in my case. I came in with knowledge of a lot of
> functional ideas from using them in Javascript and Python.  Or at
> least I thought I knew them.
>
> 5 chapters into "Learn You a Haskell", I admit it's not really sinking
> in for me even after typing in and running all the examples.  I
> acknowledge that I don't know jack.

This is going to be a somewhat long mail, in which I'm attempting to
give you an introduction of my own.  Be brave and read it. =)

Well, despite popular belief JavaScript and Python are not anywhere near
functional.  JS just uses callbacks and passes them around through
higher order functions, but that's just the regular event-handling
imperative style.  There is really nothing functional about that.

Functional style in JS starts when you start using things like 'each'
from jQuery, i.e. you're not just defining event handlers.  You are
actually passing /behavior/ to a function.  This is basically what a
functional language takes to its conclusion.  You have an action (like
putStrLn "Hello world"), and you want to perform it n times.  Let me
give this example in both JavaScript and Haskell:

    function timesHello(n) {
        while (n > 0) {
            print("Hello world");
            n--;
        }
    }

    timesHello 0 = return ()
    timesHello n = putStrLn "Hello world" >> nTimes (n - 1)

But why should we be constrained to printing hello world?  On the other
hand, how could we abstract it?  The complicated answer is to use a
complicated OO solution, but functional programmers can do a lot better:

    function times(n, action) {
        while (n > 0) {
            action();
            n--;
        }
    }

    times 0 action = return ()
    times n action = action >> times (n - 1) action

Unfortunately JavaScript has quite a heavy syntax for anonymous
functions, which makes this style a lot less useful:

    times(3, function() { print("Hello world"); });

But in Haskell we can write this elegantly:

    3 `times` putStrLn "Hello world"

This is the very fundamental idea.  Since Haskell programs are lazily
evaluated you can stretch this idea to entirely new dimensions, where
the line between data and control structures disappears.  A common
statement is that lists in Haskell correspond to 'for' loops in other
languages, which is quite true, but can only be seen when you ask
yourself, "how would I solve this?".

Let me give you an example:  You are searching for the smallest square
natural number that has a digit sum greater than 20.  First we need a
function to calculate digit sums.  This would be a 'for' loop in an
imperative language, wouldn't it?  In Haskell we do something different:
Our function starts iterating division by 10:

    digitSum = iterate (`div` 10)
    digitSum 357 = [357, 35, 3, 0, 0, 0, ...

Then we want to get rid of the zeroes.  Starting with the first zero all
following numbers will be zeroes, so we stop before the first zero:

    digitSum = takeWhile (> 0) . iterate (`div` 10)
    digitSum 357 = [357, 35, 3]

As you can see we have already used two higher order functions that take
behavior as arguments.  Next we need to take everything modulo 10:

    digitSum = map (`mod` 10) . takeWhile (> 0) . iterate (`div` 10)
    digitSum 357 = [7, 5, 3]

Finally we take the sum:

    digitSum = sum . map (`mod` 10) . takeWhile (> 0) . iterate (`div` 10)
    digitSum 357 = 15

Ok, let's solve the original problem.  Again this would be another 'for'
loop in other languages, but there is a Haskell solution as well:  The
smallest square natural number...  "smallest natural" sounds a lot like
we want to search from 0 upwards, so let's just capture our search space
as a list:

    [0..] = [0, 1, 2, 3, 4, ...

But we want squares:

    map (^2) [0..] = [0, 1, 4, 9, 16, ...

And we want only the numbers with a digit sum greater than 20:

    filter (\x -> digitSum x > 20) . map (^2) $ [0..]

The natural number 44944 is a square, and its digit sum is greater than
20, so this list is certainly nonempty.  So there must be a smallest
number in that list, which will be just the first entry, because the
list is sorted by construction.  In other words, it's safe to use
'head':

    head . filter (\x -> digitSum x > 20) . map (^2) $ [0..]

And that gives us the solution 1849, which has a digit sum of 22 and
meets our specification.


> Any ideas or exercises that might help me along?

Yes.  Pick a small task and solve it.  Write code.  If you get stuck,
just visit us at #haskell on Freenode or ask here.

I hope this helped.


Greets,
Ertugrul

-- 
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130111/c845b7dc/attachment-0001.pgp>

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

Message: 3
Date: Fri, 11 Jan 2013 01:19:21 -0800
From: KC <kc1...@gmail.com>
Subject: Re: [Haskell-beginners] A Week in and Clueless
To: Philip Cote <cote...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <CAMLKXy=z5vbpDP4Gm14k1EevFOPNNHcW=2E1y3OR5r=duhk...@mail.gmail.com>
Content-Type: text/plain; charset=windows-1252

Please state what kind of exercises you would be interested in.
If you are interested in the exercises that would provide more motivation.

If you are in a state; that is very un-Haskell-ish! :D


On Thu, Jan 10, 2013 at 6:44 PM, Philip Cote <cote...@gmail.com> wrote:
> So a week into Haskell, I still seem to be not ?getting? it which is kind of
> weird in my case. I came in with knowledge of a lot of functional ideas from
> using them in Javascript and Python.  Or at least I thought I knew them.
>
>
> 5 chapters into "Learn You a Haskell", I admit it's not really sinking in
> for me even after typing in and running all the examples.  I acknowledge
> that I don't know jack.  Any ideas or exercises that might help me along?
>
>
>
>
>


-- 
--
Regards,
KC



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

Message: 4
Date: Fri, 11 Jan 2013 15:11:44 +0530
From: mukesh tiwari <mukeshtiwari.ii...@gmail.com>
Subject: Re: [Haskell-beginners] A Week in and Clueless
To: Philip Cote <cote...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <cafhzve9tgtoucj2cbgf3hpfunyrs1pssqksmv0ooeq-_rxc...@mail.gmail.com>
Content-Type: text/plain; charset="windows-1252"

Hi Philip
When I started learning Haskell, it took me couple of months ( I guess 3 to
4 ) to write some thing valuable although I had prior experience of  C ,
C++ , python  and Java so just keep trying because It's one of the best
language. If you have interest in problem solving then try solving some
easy problems of Project Euler <http://projecteuler.net/problems> (
probably first 50 problems are good enough ). After finishing the "Learn
you Haskell", you can try Real World
Haskell<http://book.realworldhaskell.org/read/index.html>and this book
 contains lots of examples so you can try
reading/writing/modification of given codes.

Good luck,
Mukesh


On Fri, Jan 11, 2013 at 8:14 AM, Philip Cote <cote...@gmail.com> wrote:

> So a week into Haskell, I still seem to be not ?getting? it which is kind
> of weird in my case. I came in with knowledge of a lot of functional ideas
> from using them in Javascript and Python.  Or at least I thought I knew
> them.
>
>
> 5 chapters into "Learn You a Haskell", I admit it's not really sinking in
> for me even after typing in and running all the examples.  I acknowledge
> that I don't know jack.  Any ideas or exercises that might help me along?
>
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130111/14153ab8/attachment-0001.htm>

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

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 55, Issue 12
*****************************************

Reply via email to