Send Beginners mailing list submissions to
[email protected]
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
[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: Parallel mutation (Erik de Castro Lopo)
2. Re: scope for variables (David Virebayre)
3. how to use regex replace (Kui Ma)
4. Re: how to use regex replace (Adolfo Builes)
5. Re: how to use regex replace (Tom Tobin)
6. Re: how to use regex replace (Jan Jakubuv)
7. Is there a function to determine if a date is a business
day? (Hong Yang)
8. Re: Is there a function to determine if a date is a business
day? (Colin Paul Adams)
9. Re: Is there a function to determine if a date is a business
day? (Andy Elvey)
----------------------------------------------------------------------
Message: 1
Date: Thu, 10 Dec 2009 12:00:55 +1100
From: Erik de Castro Lopo <[email protected]>
Subject: Re: [Haskell-beginners] Parallel mutation
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
Erik de Castro Lopo wrote:
> So why not look at Data Parallel Haskell:
>
> http://www.haskell.org/haskellwiki/GHC/Data_Parallel_Haskell
Quicksort example:
http://darcs.haskell.org/ghc-6.10/packages/dph/examples/qsort/
I haven't tested this.
Erik
--
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/
------------------------------
Message: 2
Date: Thu, 10 Dec 2009 09:17:47 +0100
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] scope for variables
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
Forgot to post the list :(
On Wed, Dec 9, 2009 at 10:40 PM, legajid <[email protected]> wrote:
> Hello,
> i wrote the following (very simplified) program :
>
> word :: [Char]
> word="initial"
> letters=['a'..'z']
>
> myloop = do
> myloop2
>
> myloop2 = do
> putStrLn word
> putStrLn letters
>
> main = do
> putStrLn "Enter the word"
> word <- enter_word
> myloop
> enter_word= do
> return("abcdefghij")
>
Remind that a haskell function depends only on its parameters. Unless you
use an unsafe trick, often frowned upon, mutable global variables don't
exist.
So normally you have to modify your functions to pass the string as a
parameter. While it may seem tedious at first, perhaps you will realise that
having the type signature mention that you need a string is a precious
information. Also, start by modifying only myloop2, ghc will complain about
every function that use the new myloop2 the wrong way, so refactoring is not
that hard.
In the case you have a more complicated program where state is an important
part, you can use the State monad, or more specifically in your example a
State transformer that uses IO as the underlying monad. Your program would
look like : ( you can copy and paste this in a source file, then play with
it in ghci )
module Main where
import Control.Monad.State
word :: [Char]
word="initial"
letters=['a'..'z']
myloop = do
myloop2
myloop2 = do
word <- get -- récupère l'état.
liftIO $ do
putStrLn word
putStrLn letters
main = runStateT mafonction word
mafonction = do
liftIO $ putStrLn "Enter the word"
w <- enter_word
put w -- enregistre l'état
myloop
enter_word= do
return("abcdefghij")
Note how the myloop function wasn't modified. On the other hand, have a look
at the type signatures using ghci. Your function now is in the StateT String
IO monad. So that's why every time you use IO you have to use liftIO to
reach the underlying IO monad. So there's still some rewriting.
David.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20091210/7682d3c4/attachment-0001.html
------------------------------
Message: 3
Date: Thu, 10 Dec 2009 18:50:11 +0800
From: Kui Ma <[email protected]>
Subject: [Haskell-beginners] how to use regex replace
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="gb2312"
Hi,
Can anyone introduce me how to use regex replace or give me web page links
about this topic? thank you in advance!
Regards
_________________________________________________________________
Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail
you.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20091210/487039e0/attachment-0001.html
------------------------------
Message: 4
Date: Thu, 10 Dec 2009 12:20:40 -0500
From: Adolfo Builes <[email protected]>
Subject: Re: [Haskell-beginners] how to use regex replace
To: Kui Ma <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi,
Bryan O'Sullivan has an excellent blog post about regex [1]. You could also
check Real World Haskell [2].
[1]-
http://www.serpentine.com/blog/2007/02/27/a-haskell-regular-expression-tutorial/
[2]-
http://book.realworldhaskell.org/read/efficient-file-processing-regular-expressions-and-file-name-matching.html#glob.regex
2009/12/10 Kui Ma <[email protected]>
> Hi,
>
> Can anyone introduce me how to use regex replace or give me web page links
> about this topic? thank you in advance!
>
> Regards
>
> ------------------------------
> Windows Live: Friends get your Flickr, Yelp, and Digg updates when they
> e-mail
> you.<http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20091210/d28c7f48/attachment-0001.html
------------------------------
Message: 5
Date: Thu, 10 Dec 2009 11:56:56 -0600
From: Tom Tobin <[email protected]>
Subject: Re: [Haskell-beginners] how to use regex replace
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Thu, Dec 10, 2009 at 11:20 AM, Adolfo Builes
<[email protected]> wrote:
> Hi,
> Bryan O'Sullivan has an excellent blog post about regex [1]. You could also
> check Real World Haskell [2].
>
> [1]-
> http://www.serpentine.com/blog/2007/02/27/a-haskell-regular-expression-tutorial/
> [2]-
> http://book.realworldhaskell.org/read/efficient-file-processing-regular-expressions-and-file-name-matching.html#glob.regex
I'd actually recommend the pcre-light package:
http://hackage.haskell.org/package/pcre-light
Not only does it give you Perl-compatible regexes, but it also
*doesn't* force you through the IO monad. It's good stuff.
------------------------------
Message: 6
Date: Thu, 10 Dec 2009 17:57:59 +0000
From: Jan Jakubuv <[email protected]>
Subject: Re: [Haskell-beginners] how to use regex replace
To: Kui Ma <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Hi,
Would Text.Regex.subRegex do? It is in package regex-compat. Usage is
easy, see [1].
Sincerely,
jan.
[1]:
http://hackage.haskell.org/packages/archive/regex-compat/0.92/doc/html/Text-Regex.html
On Thu, Dec 10, 2009 at 06:50:11PM +0800, Kui Ma wrote:
>
> Hi,
>
> Can anyone introduce me how to use regex replace or give me web page links
> about this topic? thank you in advance!
>
> Regards
>
--
Heriot-Watt University is a Scottish charity
registered under charity number SC000278.
------------------------------
Message: 7
Date: Thu, 10 Dec 2009 23:25:02 -0600
From: Hong Yang <[email protected]>
Subject: [Haskell-beginners] Is there a function to determine if a
date is a business day?
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20091210/064cc6fc/attachment-0001.html
------------------------------
Message: 8
Date: Fri, 11 Dec 2009 06:20:46 +0000
From: Colin Paul Adams <[email protected]>
Subject: Re: [Haskell-beginners] Is there a function to determine if a
date is a business day?
To: Hong Yang <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
You will need to write it, as it depends upon your definition of what
a business day is.
This tends to be country-specific (at least).
--
Colin Adams
Preston Lancashire
------------------------------
Message: 9
Date: Fri, 11 Dec 2009 19:43:52 +1300
From: Andy Elvey <[email protected]>
Subject: Re: [Haskell-beginners] Is there a function to determine if a
date is a business day?
To: Colin Paul Adams <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Colin Paul Adams wrote:
> You will need to write it, as it depends upon your definition of what
> a business day is.
> This tends to be country-specific (at least).
>
Agreed.
I'm a Haskell-newbie so I can't give the Haskell code for this, but in
"pseudo-code" it would be something like this -
holidays_list = ["09JAN", "06FEB", ..... ] ( This will vary depending
on country )
if myday not in holidays_list and day(myday) in ["Mon", "Tue", "Wed",
"Thu", "Fri"]
then business_day(myday) = "Yes"
else business_day(myday) = "No"
Some countries have a "Holidays Act" or similar legislation which
specifies the holidays for the current year and the next few years.
Hope this helps.... :)
- Andy
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 18, Issue 8
****************************************