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:  print all days of calendar ([email protected])
   2. Re:  inserting tupels inside list as tupels in    list
      (Chadda? Fouch?)
   3.  expression parser (John Moore)
   4. Re:  expression parser (Daniel Fischer)
   5.  Re: Pure Regex.PCRE Possible? (PLEAC, Fix Style) (Volkan YAZICI)
   6.  Re: Pure Regex.PCRE Possible? (PLEAC, Fix Style) (Chadda? Fouch?)
   7.  Einstein's Problem (Patrick LeBoutillier)
   8.  Performance of parallel mergesort (Jon Harrop)
   9. Re:  Performance of parallel mergesort (Antoine Latter)


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

Message: 1
Date: Mon, 21 Dec 2009 23:02:04 +0100
From: [email protected]
Subject: Re: [Haskell-beginners] print all days of calendar
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"


-------- Original-Nachricht --------
> Datum: Mon, 21 Dec 2009 22:00:58 +0100
> Von: Daniel Fischer <[email protected]>
> An: [email protected]
> CC: [email protected]
> Betreff: Re: [Haskell-beginners] print all days of calendar

> Am Montag 21 Dezember 2009 21:39:38 schrieb [email protected]:
> > -------- Original-Nachricht --------
> >
> > > Datum: Mon, 21 Dec 2009 21:12:48 +0100
> > > Von: Daniel Fischer <[email protected]>
> > > An: [email protected]
> > > CC: [email protected]
> > > Betreff: Re: [Haskell-beginners] print all days of calendar
> > >
> > > Am Montag 21 Dezember 2009 20:47:38 schrieb [email protected]:
> > > > > Does (==) ring a few bells?
> > > >
> > > > not really...
> > >
> > > Prelude> let okay k = k^3 `mod` 13 == 5 in filter okay [1 .. 30]
> > > [7,8,11,20,21,24]
> > >
> > > Now, you don't want the numbers between 1 and 30 inclusive whose cube
> > > modulo 13 is 5, but
> > > the dates in a given month.
> > >
> > > getMonth :: Month -> Calendar -> Calendar
> > > getMonth month [(1,Jan,y),(2,Jan,y) ... (31,Dec,y)]
> >
> > more like this:
> > getMonth month calendar = calendar filter ([1..31], month, year)
> > but it doesn't make sense
> 
> No.
> type Calendar = [Date]
> type Day = Int
> data Month = Jan | Feb | Mar | Apr | May | Jun | Jul | Ago | Sep | Oct |
> Nov | Dec 
> deriving (Eq,Enum,Show)
> type Year = Int
> type Date = (Day,Month,Year)
> 
> So the calendar in "getMonth month calendar" is a list of date-triples as
> illustrated 
> above.
> 
> Prelude> :t filter
> filter :: (a -> Bool) -> [a] -> [a]
> 
> So filter takes
> 1) a predicate (a function of type (a -> Bool))
> 2) a list
> as arguments.
> 
> getMonth :: Month -> [Date] -> [Date]
> 
> One of the arguments to getMonth is a list, and the result should be a
> list of the same 
> type, thus it's natural to pass that list unchanged to filter.
> 
> getMonth month calendar = filter predicateThatYouNeed calendar
> 
> What remains is to define predicateThatYouNeed. It will somehow involve
> the other argument 
> to getMonth, namely month. And it must map (Day,Month,Year) triples to
> Bool.

so I have to say that it have to match (Day, month, Year), but how...

-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01


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

Message: 2
Date: Tue, 22 Dec 2009 10:31:22 +0100
From: Chadda? Fouch? <[email protected]>
Subject: Re: [Haskell-beginners] inserting tupels inside list as
        tupels in       list
To: [email protected]
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Mon, Dec 21, 2009 at 5:10 PM,  <[email protected]> wrote:
> issn't there a way to manage this event list easily?

Sure there is, on the other hand you already had a lot of help on this
mainling list, maybe you could try to finish this by yourself ?
Some pointers though :
- first I would like to point that while Day/Month/Year is the
convention in some countries, (Year,Month,Day) makes a lot more sense
from an informatic point of view given that the lexicographic order on
that corresponds to the date order (add Ord to the derivation for your
Month type)

- second, a list may not be the most appropriate  for associating date
and event, a Map (from Data.Map) may be better.

-- 
Jedaï


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

Message: 3
Date: Tue, 22 Dec 2009 20:48:11 +0000
From: John Moore <[email protected]>
Subject: [Haskell-beginners] expression parser
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Hi,
   Could some one point out what I'm doing wrong below. This is a parser
which takes an arithmetic expression built up from single digits. Turns
3*4+2 into (3*4)+2 etc.It giving me the last expression in a do statement or
parse error on ->

(+++) :: Parser a -> Parser a -> Parser a
expr :: term( '+' expr |"")
term -> factor('*' term |"")

expr :: Parser Int
expr  = do t <- term
   do char '+'
      e <- expr
      return (t + e)
    +++ return t

term :: Parser Int
term = do f <- factor
      do char '*'
         t <- term
      return (f * t)
   +++ return f

factor :: Parser Int
factor = do d <- digit
             return (digitToInt d)
  +++ do char '('
         e <- expr
      char ')'
      return e

eval :: String -> Int
eval xs = fst(head(parse expr xs))


John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20091222/14484e65/attachment-0001.html

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

Message: 4
Date: Tue, 22 Dec 2009 22:10:22 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] expression parser
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="iso-8859-15"

Am Dienstag 22 Dezember 2009 21:48:11 schrieb John Moore:
> Hi,
>    Could some one point out what I'm doing wrong below. This is a parser
> which takes an arithmetic expression built up from single digits. Turns
> 3*4+2 into (3*4)+2 etc.It giving me the last expression in a do statement
> or parse error on ->
>
> (+++) :: Parser a -> Parser a -> Parser a
> expr :: term( '+' expr |"")
> term -> factor('*' term |"")

What's happened here?
A part of your grammar seems to have slipped into the code.
>
> expr :: Parser Int
> expr  = do t <- term
>    do char '+'
>       e <- expr
>       return (t + e)
>     +++ return t
>
> term :: Parser Int
> term = do f <- factor
>       do char '*'
>          t <- term
>       return (f * t)
>    +++ return f
>
> factor :: Parser Int
> factor = do d <- digit
>              return (digitToInt d)
>   +++ do char '('
>          e <- expr
>       char ')'
>       return e
>
> eval :: String -> Int
> eval xs = fst(head(parse expr xs))


Maybe it's just the mail programme, but what arrived here had wrong indentation.
In expr, the inner do-block isn't aligned with "t <- term".
In term, the "return (f * t)" isn't aligned with "char '*'" and "t <- term" and 
the whole 
inner dop-block isn't aligned with "f <- factor".
In factor,  "return (digitToInt d)" isn't aligned with "d <- digit" and in the 
second 
block, "char ')'" and "return e" aren't aligned with "char'('" and "e <- expr".

Properly aligned and with an implementation of (+++) instead of grammar 
productions, it 
should work.
>
>
> John



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

Message: 5
Date: Wed, 23 Dec 2009 15:02:12 +0200
From: Volkan YAZICI <[email protected]>
Subject: [Haskell-beginners] Re: Pure Regex.PCRE Possible? (PLEAC, Fix
        Style)
To: Chadda? Fouch? <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8

On Sun, 20 Dec 2009, Chaddaï Fouché <[email protected]> writes:
> On Sat, Dec 19, 2009 at 2:37 PM, Volkan YAZICI <[email protected]> wrote:
>> However, if I'm not mistaken, above functions _should_ be absolutely
>> pure. Is it possible to encapsulate impure PCRE functions into their
>> pure equivalents?
>>
>> BTW, why are PCRE functions impure?
>
> Mainly because they _are_ the core that _is_ encapsulated as you
> suggested : regex-pcre as many other regex library, provides the same
> basic mostly pure interface which is in regex-base.
>
> That interface comes with many specific pure function (matchText,
> matchOnce, matchAll and so on, as well as makeRegex and others) and
> some "magic" operators like =~ which decides what kind of matching you
> want to do depending on the type of the result.
>
> See this tutorial for some example of usage :
> http://www.serpentine.com/blog/2007/02/27/a-haskell-regular-expression-tutorial/

Am I missing something, or Text.Regex.Posix no more ships with Haskell,
particularly 6.12.1 version?


Regards.


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

Message: 6
Date: Wed, 23 Dec 2009 14:18:00 +0100
From: Chadda? Fouch? <[email protected]>
Subject: [Haskell-beginners] Re: Pure Regex.PCRE Possible? (PLEAC, Fix
        Style)
To: Volkan YAZICI <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Wed, Dec 23, 2009 at 2:02 PM, Volkan YAZICI <[email protected]> wrote:
>> See this tutorial for some example of usage :
>> http://www.serpentine.com/blog/2007/02/27/a-haskell-regular-expression-tutorial/
>
> Am I missing something, or Text.Regex.Posix no more ships with Haskell,
> particularly 6.12.1 version?

You didn't miss anything (I think it was even true with 6.10), that is
because the GHC developers have decided to get out of the library
business. In other words they decided to restrain themselves to the
absolute core of the Haskell libraries necessary to get GHC running
and nothing else. So, what should an Haskell developer do, when he
don't absolutely need the _latest_ GHC release, the _latest_ libraries
in all domain, and so on ? The Haskell Platform is the project that is
supposed to replace the old big GHC release from the past, with
regular releases of an integrated package with a stable and useful
library set and a compiler version that are supposed to work nicely
together :
http://hackage.haskell.org/platform/

_This_ is what most Haskell developer should use, especially if
they're beginners !

It contains regex-posix and regex-base (which is the common interface
of most regex-* package, regex-pcre included).
-- 
Jedaï


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

Message: 7
Date: Wed, 23 Dec 2009 14:46:51 -0500
From: Patrick LeBoutillier <[email protected]>
Subject: [Haskell-beginners] Einstein's Problem
To: beginners <[email protected]>
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hi all,

I've been working hard at trying to solve Einstein's problem
(http://www.davar.net/MATH/PROBLEMS/EINSTEIN.HTM) if an efficient
manner using Haskell.

I have posted my solution here: http://haskell.pastebin.com/m3ff1973a

This exercise has been a real eye opener for me, especially for
learning to work with the Maybe and List monads.

I'm looking for suggestions for making the "test" function nicer. In
order to make my solution fast, I generate my test cases
incrementally,
thereby elimating most of the cases early on. However the function
looks funny (deeply nested).

I'm also open to any comments about making better use of the different
Haskell idioms.


Thanks a lot,

Patrick
-- 
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada


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

Message: 8
Date: Wed, 23 Dec 2009 21:14:24 +0000
From: Jon Harrop <[email protected]>
Subject: [Haskell-beginners] Performance of parallel mergesort
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="us-ascii"


I took the parallel merge sort described here:

  http://martin.sulzmann.googlepages.com/AMP-Spring2008-intro.pdf

and added a simple test:

main :: IO ()
main = do
    putStrLn $ show $ sum $ mergesort $ [sin x | x <- [1.0 .. 1000000.0]]

Compiled it with GHC 6.8.2 from Debian testing and ran it with various 
+RTS -N<n> arguments to measure its performance and obtained the following 
results on an 8 core:

$ ghc --make -O2 -threaded mergesort.hs -o mergesort
[1 of 1] Compiling Main             ( mergesort.hs, mergesort.o )
Linking mergesort ...
$ time ./mergesort +RTS -N1
-0.117109518058233

real    0m9.723s
user    0m9.461s
sys     0m0.232s
$ time ./mergesort +RTS -N2
-0.117109518058233

real    0m13.574s
user    0m15.225s
sys     0m0.140s
$ time ./mergesort +RTS -N3
-0.117109518058233

real    0m13.185s
user    0m15.529s
sys     0m0.184s
$ time ./mergesort +RTS -N4
-0.117109518058233

real    0m13.251s
user    0m15.829s
sys     0m0.336s
$ time ./mergesort +RTS -N5
-0.117109518058233

real    0m13.093s
user    0m16.929s
sys     0m0.164s
$ time ./mergesort +RTS -N6
Segmentation fault

real    0m5.711s
user    0m7.408s
sys     0m0.136s

That segfault must be due to a bug in GHC so I thought perhaps a newer version 
of GHC might fix the segfault but I installed GHC 6.10.4 from Sid and now I 
get:

$ ghc --make -O2 -threaded mergesort.hs -o mergesort
Binary: Int64 truncated to fit in 32 bit Int
ghc: panic! (the 'impossible' happened)
  (GHC version 6.10.4 for i386-unknown-linux):
        Prelude.chr: bad argument

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

I'll try the haskell-platform package next. Are these known problems?

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e


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

Message: 9
Date: Thu, 24 Dec 2009 00:16:19 +0000
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] Performance of parallel mergesort
To: Jon Harrop <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

Hi Jon,

You're more likely to get a useful response over on the
glasgow-haskell-users mailing list, as it looks like this is a GHC
specific bug: http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Running this at -N6 doesn't want to complete for me, so I'm not sure
if it would segfault. I'm on a 64-bit Intel Mac OS X using GHC 6.12,
dual core.

With such a small example as this your best bet would be to file a bug report:

http://hackage.haskell.org/trac/ghc/

You'll need to use the login guest/guest to file a new ticket.

Antoine

On Wed, Dec 23, 2009 at 9:14 PM, Jon Harrop <[email protected]> wrote:
>
> I took the parallel merge sort described here:
>
>  http://martin.sulzmann.googlepages.com/AMP-Spring2008-intro.pdf
>
> and added a simple test:
>
> main :: IO ()
> main = do
>    putStrLn $ show $ sum $ mergesort $ [sin x | x <- [1.0 .. 1000000.0]]
>
> Compiled it with GHC 6.8.2 from Debian testing and ran it with various
> +RTS -N<n> arguments to measure its performance and obtained the following
> results on an 8 core:
>
> $ ghc --make -O2 -threaded mergesort.hs -o mergesort
> [1 of 1] Compiling Main             ( mergesort.hs, mergesort.o )
> Linking mergesort ...
> $ time ./mergesort +RTS -N1
> -0.117109518058233
>
> real    0m9.723s
> user    0m9.461s
> sys     0m0.232s
> $ time ./mergesort +RTS -N2
> -0.117109518058233
>
> real    0m13.574s
> user    0m15.225s
> sys     0m0.140s
> $ time ./mergesort +RTS -N3
> -0.117109518058233
>
> real    0m13.185s
> user    0m15.529s
> sys     0m0.184s
> $ time ./mergesort +RTS -N4
> -0.117109518058233
>
> real    0m13.251s
> user    0m15.829s
> sys     0m0.336s
> $ time ./mergesort +RTS -N5
> -0.117109518058233
>
> real    0m13.093s
> user    0m16.929s
> sys     0m0.164s
> $ time ./mergesort +RTS -N6
> Segmentation fault
>
> real    0m5.711s
> user    0m7.408s
> sys     0m0.136s
>
> That segfault must be due to a bug in GHC so I thought perhaps a newer version
> of GHC might fix the segfault but I installed GHC 6.10.4 from Sid and now I
> get:
>
> $ ghc --make -O2 -threaded mergesort.hs -o mergesort
> Binary: Int64 truncated to fit in 32 bit Int
> ghc: panic! (the 'impossible' happened)
>  (GHC version 6.10.4 for i386-unknown-linux):
>        Prelude.chr: bad argument
>
> Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
>
> I'll try the haskell-platform package next. Are these known problems?
>
> --
> Dr Jon Harrop, Flying Frog Consultancy Ltd.
> http://www.ffconsultancy.com/?e
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>


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

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 18, Issue 22
*****************************************

Reply via email to