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:  Thompson Exercise 9.13 (Daniel Fischer)
   2.  Re: Having fun with yesod,       and a few questions  came up. (Gour)
   3.  question about fclabels - libnova port project (Michael Litchard)
   4. Re:  Re: Having fun with yesod, and a few         questions came up.
      (Michael Snoyman)
   5. Re:  Re: Having fun with yesod, and a few         questions came up.
      (Michael Litchard)


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

Message: 1
Date: Thu, 15 Jul 2010 21:27:27 +0200
From: Daniel Fischer <daniel.is.fisc...@web.de>
Subject: Re: [Haskell-beginners] Thompson Exercise 9.13
To: Patrick LeBoutillier <patrick.leboutill...@gmail.com>
Cc: beginners@haskell.org
Message-ID: <201007152127.28073.daniel.is.fisc...@web.de>
Content-Type: text/plain;  charset="iso-8859-1"

On Thursday 15 July 2010 16:06:01, Patrick LeBoutillier wrote:
> Hi,
>
> >> *last* :: [a] -> a
> >> last xs = head $ foldr f [] xs
> >>  where f :: a -> [a] -> [a]
> >>        f x [] = [x]
> >>        f x ys = ys ++ [x]
> >
> > a) in the second branch of f, you don't actually need to concatenate,
> >
> > f x [] = [x]
> > f _ ys = ys
> >
> > works too, but is faster.
>
> Why is it faster? I thought that the laziness would cause the
> concatenation not to be evaluated at all since we are taking the head
> of the list.
> Is that not the case?

That is (almost) the case (otherwise the performance of the first version 
would be worse), but for each list element, the pattern match in the folded 
function forces one evaluation step of a (++)-application [and for that, 
one further pattern match], thus it has to do more work.

Remember,

[] ++ ys = ys
(x:xs) ++ ys = x : (xs ++ ys)

If we look at what happens with

f1 x [] = [x]
f1 x ys = ys ++ [x]

in a generic step:

f1 x (f1 y zs)
~> case f1 y zs of { [] -> [x]; w:ws -> (w:ws) ++ [x] }
~> case (case zs of { [] -> [y]; v:vs -> (v:vs) ++ [y] }) of
        { [] -> [x]; w:ws -> (w:ws) ++ [x] }
-- let's assume zs is not null
~> case (v:vs) ++ [y] of { [] -> [x]; w:ws -> (w:ws) ++ [x] }
~> case (case (v:vs) of { [] -> [y]; u:us -> u:(us ++ [y]) }) of
        { [] -> [x]; w:ws -> (w:ws) ++ [x] }
~> case v:(vs ++ [y]) of
        { [] -> [x]; w:ws -> (w:ws) ++ [x] }
~> (v:(vs ++ [y])) ++ [x]

and with

f2 x [] = [x]
f2 _ ys = ys

f2 x (f2 y zs)
~> case f2 y zs of { [] -> [x]; w:ws -> (w:ws) }
~> case (case zs of { [] -> [y]; v:vs -> (v:vs) }) of
        { [] -> [x]; w:ws -> (w:ws) }
-- again, assume zs is not null
~> case v:vs of
        { [] -> [x]; w:ws -> (w:ws) }
~> v:vs

In the former, at each step, to determine the branch of f1, an expression 
of the form (us ++ vs) has to be matched against [].
For that, us has to be matched against [].
Typically, us is of the form (u:us'), so (us ++ vs) is rewritten to
u:(us' ++ vs).
That doesn't match [], so the second branch of f1 is taken and we get
(u:(us' ++ vs)) ++ [x], again wrapping the first (:) in a (++)-application.
For each list-element, we must evaluate a (++)-application one step.

In the latter, once at the end of the list a (y:[]) is produced, all that 
happens is pattern matching and passing the value unmodified to the next 
pattern match.

>
> Thanks,
>
> Patrick


Cheers,
Daniel



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

Message: 2
Date: Thu, 15 Jul 2010 22:09:20 +0200
From: Gour <g...@gour-nitai.com>
Subject: [Haskell-beginners] Re: Having fun with yesod, and a few
        questions  came up.
To: beginners@haskell.org
Message-ID: <20100715220920.2b6c3...@gaura-nitai.no-ip.org>
Content-Type: text/plain; charset="us-ascii"

On Thu, 15 Jul 2010 11:18:39 -0700
>>>>>> "Michael" == Michael Litchard <mich...@schmong.org> wrote:

Michael> Yes, thank you. It would be useful for you to package up a
Michael> sample application with a lighttpd config file. I would
Michael> appreciate that.

+1 for cherokee config ;)


Sincerely,
Gour

-- 

Gour  | Hlapicina, Croatia  | GPG key: F96FF5F6
----------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
Url : 
http://www.haskell.org/pipermail/beginners/attachments/20100715/418024b8/signature-0001.bin

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

Message: 3
Date: Thu, 15 Jul 2010 20:28:57 -0700
From: Michael Litchard <mich...@schmong.org>
Subject: [Haskell-beginners] question about fclabels - libnova port
        project
To: beginners@haskell.org
Message-ID:
        <aanlktiktmv_aqjgf_ubt-cc-icbb0vq8_xhzhnopk...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

I'm porting libnova http://libnova.sourceforge.net/ to haskell, and
another question has arisen.

I'm starting with header files, ln_types.h to begin with. I'm turning
C structs into fclabels.


struct lnh_lnlat_posn
{
    struct ln_dms lng; /*!< longitude. Object longitude.*/
    struct ln_dms lat; /*!< latitude. Object latitude */
};

becomes


data LNH_lnlat_posn = LHN_lnlat_posn {
      _lng          :: LN_dms
     ,_lat          :: LN_dms
}

$(mkLabels [''LNH_lnlat_posn])

lng   :: LNH_lnlat_posn :-> LN_dms
lat   :: LNH_lnlat_posn :-> LN_dms


I have many, many structs to change. What would it take to write an
abstraction that encompassed all steps?

Michael


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

Message: 4
Date: Fri, 16 Jul 2010 10:02:13 +0300
From: Michael Snoyman <mich...@snoyman.com>
Subject: Re: [Haskell-beginners] Re: Having fun with yesod, and a few
        questions came up.
To: Gour <g...@gour-nitai.com>, Michael Litchard <mich...@schmong.org>
Cc: beginners@haskell.org
Message-ID:
        <aanlktine7np4eu0xxfjsnmf7gtk26kib7vjqjqvp1...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I've put together a repository on github[1] that has examples of hosting a
simple Yesod application. The nonroot variants show you how to host your
application at some place other than the domain root.

I've only included lighttpd config files, since that's all I use on a
regular basis. I'm happy to take patches from anyone having experience with
other servers.

Michael

[1] http://github.com/snoyberg/yesod-hello

On Thu, Jul 15, 2010 at 11:09 PM, Gour <g...@gour-nitai.com> wrote:

> On Thu, 15 Jul 2010 11:18:39 -0700
> >>>>>> "Michael" == Michael Litchard <mich...@schmong.org> wrote:
>
> Michael> Yes, thank you. It would be useful for you to package up a
> Michael> sample application with a lighttpd config file. I would
> Michael> appreciate that.
>
> +1 for cherokee config ;)
>
>
> Sincerely,
> Gour
>
> --
>
> Gour  | Hlapicina, Croatia  | GPG key: F96FF5F6
> ----------------------------------------------------------------
>
> _______________________________________________
> 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/20100716/70eba30d/attachment-0001.html

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

Message: 5
Date: Fri, 16 Jul 2010 08:38:25 -0700
From: Michael Litchard <mich...@schmong.org>
Subject: Re: [Haskell-beginners] Re: Having fun with yesod, and a few
        questions came up.
To: Michael Snoyman <mich...@snoyman.com>
Cc: Gour <g...@gour-nitai.com>, beginners@haskell.org
Message-ID:
        <aanlktikiycncw_1mg9gbpvkvvh5rnuyjf1z6wxzxp...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Thank you.

On Fri, Jul 16, 2010 at 12:02 AM, Michael Snoyman <mich...@snoyman.com> wrote:
> I've put together a repository on github[1] that has examples of hosting a
> simple Yesod application. The nonroot variants show you how to host your
> application at some place other than the domain root.
> I've only included lighttpd config files, since that's all I use on a
> regular basis. I'm happy to take patches from anyone having experience with
> other servers.
>
> Michael
> [1] http://github.com/snoyberg/yesod-hello
> On Thu, Jul 15, 2010 at 11:09 PM, Gour <g...@gour-nitai.com> wrote:
>>
>> On Thu, 15 Jul 2010 11:18:39 -0700
>> >>>>>> "Michael" == Michael Litchard <mich...@schmong.org> wrote:
>>
>> Michael> Yes, thank you. It would be useful for you to package up a
>> Michael> sample application with a lighttpd config file. I would
>> Michael> appreciate that.
>>
>> +1 for cherokee config ;)
>>
>>
>> Sincerely,
>> Gour
>>
>> --
>>
>> Gour  | Hlapicina, Croatia  | GPG key: F96FF5F6
>> ----------------------------------------------------------------
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners@haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>


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

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


End of Beginners Digest, Vol 25, Issue 38
*****************************************

Reply via email to