[Haskell-beginners] literate programming

Francisco Gutierrez fgutiers2002 at yahoo.com
Mon Apr 16 22:45:46 CEST 2012


Dear friends:
I am an ULTRA-ULTRA Haskell beginner, just started literally yesterday.
 
I am just toying around with Cordelia Hall and John O'Donnell excellent book on dicrete mathematics with Haskell. Well, they have a program, stdm,
to accompany the book. It happens that it is in literate style. In theory, this should be very easy to work with, but after saving it with lhs extension, I try
to load it, without success. Could somebody out there help me with this?
Best regards,
Francisco Gutiérrez

From: "beginners-request at haskell.org" <beginners-request at haskell.org>
To: beginners at haskell.org 
Sent: Monday, April 16, 2012 2:45 PM
Subject: Beginners Digest, Vol 46, Issue 23

Send Beginners mailing list submissions to
    beginners at 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-request at haskell.org

You can reach the person managing the list at
    beginners-owner at 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:  splitAt implementation (using foldr) and infinite lists
      (Lorenzo Bolla)
  2. Re:  splitAt implementation (using foldr) and infinite lists
      (Ozgur Akgun)
  3. Re:  Design of Webmachine in Haskell (Petar Radosevic)
  4. Re:  Design of Webmachine in Haskell (Michael Snoyman)
  5. Re:  splitAt implementation (using foldr) and infinite lists
      (Dmitriy Matrosov)
  6.  Training tasks (Nikita Beloglazov)
  7.  Cross-platform .hs files on Linux and Windows (Vinay Sajip)
  8. Re:  Cross-platform .hs files on Linux and    Windows (Lorenzo Bolla)


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

Message: 1
Date: Mon, 16 Apr 2012 15:21:55 +0100
From: Lorenzo Bolla <lbolla at gmail.com>
Subject: Re: [Haskell-beginners] splitAt implementation (using foldr)
    and infinite lists
Cc: beginners at haskell.org
Message-ID: <20120416142155.GC30186 at dell>
Content-Type: text/plain; charset=us-ascii

On Mon, Apr 16, 2012 at 12:52:02PM +0400, Dmitriy Matrosov wrote:
> Hi all.
> 
> If i implement take using foldr
> 
> take'      :: Int -> [a] -> [a]
> take' n    =  foldr (\x z -> if fst x <= n then snd x : z else []) []
>                . zip [1..]
> 
> it'll work fine with infinite lists. But if i implement splitAt similarly
> 
> splitAt'    :: Int -> [a] -> ([a], [a])
> splitAt' n  = foldr (\x (z1, z2) -> if fst x <= n then  (snd x : z1, z2)
>                                      else              ([], snd x : z2))
>                    ([], [])
>                    . zip [1..]
> 
> and call it like this
> 
> *Main> fst $ splitAt' 4 [1..]
> ^CInterrupted.

Try something like this:
splitAt' n  = foldr (\x zs  -> if fst x <= n then  (snd x : fst zs, snd zs) else              ([], snd x : snd zs)) ([], []) . zip [1..]

I'm no Haskell expert, but I suspect that when pattern-matching z2, it
tries to evaluate it and it hangs...

My version does not hang...

hth,
L.


-- 
Lorenzo Bolla
http://lbolla.info



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

Message: 2
Date: Mon, 16 Apr 2012 15:55:20 +0100
From: Ozgur Akgun <ozgurakgun at gmail.com>
Subject: Re: [Haskell-beginners] splitAt implementation (using foldr)
    and infinite lists
To: Lorenzo Bolla <lbolla at gmail.com>
Cc: beginners at haskell.org
Message-ID:
    <CALzazPAs7X+JXD5nu4+E+HiyCeQhbMwJ7qJ+beC0uCzips6gFA at mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

You can also use lazy pattern matching.

http://en.wikibooks.org/wiki/Haskell/Laziness#Lazy_pattern_matching

On 16 April 2012 15:21, Lorenzo Bolla <lbolla at gmail.com> wrote:

> > splitAt'    :: Int -> [a] -> ([a], [a])
> > splitAt' n  = foldr (\x ~(z1, z2) -> if fst x <= n then  (snd x : z1,
> z2)
> >                                      else              ([], snd x : z2))
> >                    ([], [])
> >                    . zip [1..]
>

Ozgur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120416/528b7ede/attachment-0001.htm>

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

Message: 3
Date: Mon, 16 Apr 2012 17:05:23 +0200
From: Petar Radosevic <petar at wunki.org>
Subject: Re: [Haskell-beginners] Design of Webmachine in Haskell
To: Michael Snoyman <michael at snoyman.com>
Cc: beginners at haskell.org
Message-ID: <87aa2blnt8.fsf at mbp.wunki.org>
Content-Type: text/plain

Hi Michael,

Michael Snoyman <michael at snoyman.com> writes:

> When I was at QCon, I heard a talk from Steve Vinoski on Webmachine,
> and I was surprised to hear how close webmachine was to Haskell
> already, The concept is basically sticking a state monad on top of
> WAI. My guess is you would want to use a record type for a Resource,
> not a typeclass, to make it easier to swap out behaviors. But
> honestly, I haven't given this any thought since I saw the
> presentation 6 months ago.

Thanks for your insight, I didn't even consider using record types for a
resource. Will also read up upon state monads. I believe that Webmachine
passes a dictionary to every function in the HTTP graph[1]. Do you see
the state monad having this purpose?

[1]: https://bitbucket.org/justin/webmachine/wiki/BigHTTPGraph
-- 
Petar Radosevic | @wunki



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

Message: 4
Date: Mon, 16 Apr 2012 18:36:11 +0300
From: Michael Snoyman <michael at snoyman.com>
Subject: Re: [Haskell-beginners] Design of Webmachine in Haskell
To: Petar Radosevic <petar at wunki.org>
Cc: beginners at haskell.org
Message-ID:
    <CAKA2JgLUQ1+ZMsUWk-FmyPAFHg1RVPauXLUd_2Fsq8yzONq3DA at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

On Mon, Apr 16, 2012 at 6:05 PM, Petar Radosevic <petar at wunki.org> wrote:
> Hi Michael,
>
> Michael Snoyman <michael at snoyman.com> writes:
>
>> When I was at QCon, I heard a talk from Steve Vinoski on Webmachine,
>> and I was surprised to hear how close webmachine was to Haskell
>> already, The concept is basically sticking a state monad on top of
>> WAI. My guess is you would want to use a record type for a Resource,
>> not a typeclass, to make it easier to swap out behaviors. But
>> honestly, I haven't given this any thought since I saw the
>> presentation 6 months ago.
>
> Thanks for your insight, I didn't even consider using record types for a
> resource. Will also read up upon state monads. I believe that Webmachine
> passes a dictionary to every function in the HTTP graph[1]. Do you see
> the state monad having this purpose?
>
> [1]: https://bitbucket.org/justin/webmachine/wiki/BigHTTPGraph
> --
> Petar Radosevic | @wunki

IIRC, each function is passed a dictionary and returns a new
dictionary. That's the very essence of a state monad, which is why it
could be such a perfect fit here. Of course, I may *not* be
remembering correctly.

Michael



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

Message: 5
Date: Mon, 16 Apr 2012 20:12:54 +0400
From: Dmitriy Matrosov <sgf.dma at gmail.com>
Subject: Re: [Haskell-beginners] splitAt implementation (using foldr)
    and infinite lists
To: beginners at haskell.org
Message-ID: <4F8C4506.9000605 at gmail.com>
Content-Type: text/plain; charset="utf-8"; Format="flowed"

On 04/16/12 18:21, Lorenzo Bolla wrote:
> Try something like this:
> splitAt' n  = foldr (\x zs  ->  if fst x<= n then  (snd x : fst zs, snd zs) else              ([], snd x : snd zs)) ([], []) . zip [1..]
>
> I'm no Haskell expert, but I suspect that when pattern-matching z2, it
> tries to evaluate it and it hangs...
>
> My version does not hang...
>
> hth,
> L.
>
Thanks, Lorenzo! It works now.

On 04/16/12 18:55, Ozgur Akgun wrote:
> You can also use lazy pattern matching.
>
> http://en.wikibooks.org/wiki/Haskell/Laziness#Lazy_pattern_matching
>
> On 16 April 2012 15:21, Lorenzo Bolla <lbolla at gmail.com 
> <mailto:lbolla at gmail.com>> wrote:
>
>    > splitAt'    :: Int -> [a] -> ([a], [a])
>    > splitAt' n  = foldr (\x ~(z1, z2) -> if fst x <= n then  (snd x
>    : z1, z2)
>    >                                      else              ([], snd
>    x : z2))
>    >                    ([], [])
>    >                    . zip [1..]
>
>
> Ozgur
Thanks, Ozgur!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120416/ac7270c5/attachment-0001.htm>

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

Message: 6
Date: Mon, 16 Apr 2012 19:46:04 +0300
From: Nikita Beloglazov <nikita at taste-o-code.com>
Subject: [Haskell-beginners] Training tasks
To: beginners at haskell.org
Message-ID:
    <CAJDg_ptSc07N5vuwRJACKnNhvf34J5GQJ9vka6XXUhH0RM502g at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hi.
I'm building website where people can try and "taste" new languages by
solving small or mediums size tasks. Tasks are language specific and should
show best features of the language. Website is not meant to teach new
language but to give idea what is this language good for.
Now I want to add Haskell. I need about 7-10 tasks for now. First three of
four tasks are introductory, they should show/check basics of haskell. E.g.
given n, return sum of squares of first n even numbers. Other tasks are
more complicated and show advantages of functional programming in general
or some specific haskell features.
I don't have any experience with haskell and I need you help. Could you
help me with ideas for tasks?

Thank you,
Nikita Beloglazov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120416/17509069/attachment-0001.htm>

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

Message: 7
Date: Mon, 16 Apr 2012 18:23:57 +0000 (UTC)
From: Vinay Sajip <vinay_sajip at yahoo.co.uk>
Subject: [Haskell-beginners] Cross-platform .hs files on Linux and
    Windows
To: beginners at haskell.org
Message-ID: <loom.20120416T202250-92 at post.gmane.org>
Content-Type: text/plain; charset=us-ascii

I've been given a set of .hs files which contain the shebang line

#!/usr/bin/env runhaskell

and I would like them to work on Windows, but none of the Windows binaries seem
to be able to process them without a

<script.hs>:1:1: parse error on input `#!'

These files came from a Linux machine, where they run without trouble. Is there
any way I can get the Windows executables to run these files? I asked on IRC and
it was suggested that I change the files to literate Haskell, but I'd rather
have some way of having cross-platform operation which does not involve making
changes to the scripts themselves. Is there something that can be done e.g. by
using particular command line options or configuration settings?

Thanks & regards,

Vinay Sajip




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

Message: 8
Date: Mon, 16 Apr 2012 20:49:02 +0100
From: Lorenzo Bolla <lbolla at gmail.com>
Subject: Re: [Haskell-beginners] Cross-platform .hs files on Linux and
    Windows
Cc: beginners at haskell.org
Message-ID: <20120416194902.GA3533 at dell.home>
Content-Type: text/plain; charset="us-ascii"

Check this out:
http://stackoverflow.com/questions/6818031/use-shebang-hashbang-in-windows-command-prompt

hth,
L.


On Mon, Apr 16, 2012 at 06:23:57PM +0000, Vinay Sajip wrote:
> I've been given a set of .hs files which contain the shebang line
> 
> #!/usr/bin/env runhaskell
> 
> and I would like them to work on Windows, but none of the Windows binaries seem
> to be able to process them without a
> 
> <script.hs>:1:1: parse error on input `#!'
> 
> These files came from a Linux machine, where they run without trouble. Is there
> any way I can get the Windows executables to run these files? I asked on IRC and
> it was suggested that I change the files to literate Haskell, but I'd rather
> have some way of having cross-platform operation which does not involve making
> changes to the scripts themselves. Is there something that can be done e.g. by
> using particular command line options or configuration settings?
> 
> Thanks & regards,
> 
> Vinay Sajip
> 
> 
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners

-- 
Lorenzo Bolla
http://lbolla.info
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120416/ec2325bf/attachment.pgp>

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

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


End of Beginners Digest, Vol 46, Issue 23
*****************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120416/17a667cb/attachment-0001.htm>


More information about the Beginners mailing list