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: Closing a channel (Lyndon Maydwell)
2. Re: Network.Curl POST body not showing up (Michael Xavier)
3. Re: Genetic algorithm for knapsack problem (Federico Mastellone)
4. Takusen and inserting type Maybe with sqlite3 (Neil Jensen)
5. Re: Takusen and inserting type Maybe with sqlite3 (Neil Jensen)
6. do-notation question ([email protected])
7. Re: do-notation question (aditya siram)
----------------------------------------------------------------------
Message: 1
Date: Fri, 13 May 2011 22:39:10 +0800
From: Lyndon Maydwell <[email protected]>
Subject: Re: [Haskell-beginners] Closing a channel
To: [email protected]
Cc: Biginners Haskell Mailinglist <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
Ah yes of course. I was just wondering if there was a way to do it
without the overhead of using Maybe. I guess it makes sense that there
isn't.
On Fri, May 13, 2011 at 4:03 PM, Christopher Done
<[email protected]> wrote:
> On 12 May 2011 12:20, Lyndon Maydwell <[email protected]> wrote:
>>
>> Hi Beginners.
>>
>> I'm trying to implement a program that accumulates a list of items
>> through many IO actions, then use these in another part of the program
>> as a list.
>>
>> I've found Control.Concurrent.Chan which seems to provide a nice
>> abstraction with getChanContents :: Chan a -> IO [a], but there
>> doesn't seem to be a way for the source to close the channel.
>>
>> Are channels the right abstraction for something like this? Should
>> look in to (itter|enumer)at(or|ee)s instead... They seem to encompass
>> this model, but look quite involved.
>
> For what it's worth you can implement this abstraction ontop of channels.
> module Control.Concurrent.Chan.Closeable where
> import ? ? ? ? ? Control.Concurrent.Chan (Chan)
> import qualified Control.Concurrent.Chan as C
> import ? ? ? ? ? Data.Maybe
> getChanWhileJust :: Chan (Maybe a) -> IO [a]
> getChanWhileJust ch = fmap (catMaybes . takeWhile isJust) (C.getChanContents
> ch)
> -- ?> chan <- newChan :: IO (Chan (Maybe Integer))
> -- ?> writeList2Chan chan (map Just [1..10] ++ [Nothing])
> -- ?> getChanWhileJust chan
> -- [1,2,3,4,5,6,7,8,9,10]
------------------------------
Message: 2
Date: Fri, 13 May 2011 08:09:54 -0700
From: Michael Xavier <[email protected]>
Subject: Re: [Haskell-beginners] Network.Curl POST body not showing up
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Wow, you guys work fast!
Thanks for all your help. I will probably be switching back to
http-enumerator in the next few days.
--
Michael Xavier
http://www.michaelxavier.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110513/949021d0/attachment-0001.htm>
------------------------------
Message: 3
Date: Fri, 13 May 2011 12:10:30 -0300
From: Federico Mastellone <[email protected]>
Subject: Re: [Haskell-beginners] Genetic algorithm for knapsack
problem
To: Karol Samborski <[email protected]>
Cc: Biginners Haskell Mailinglist <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
When I was a student I built genetic algorithms in C and Java. I know
that building them in Haskell would be easy, with some little and very
descriptive code, but I have no experience with Haskell's performance.
It would be easy to tweak the algorithm and that's were you should
make you first attempts towards a faster implementation, but the
difficult part may be memory consumption, strict and lazy evaluation
strategies, etc (see
http://users.aber.ac.uk/afc/stricthaskell.html#seq).
On Fri, May 13, 2011 at 3:43 AM, Karol Samborski <[email protected]> wrote:
> Thank you for your answer.
> I'll try it and then put some code for comments ;)
>
> Best regards,
> Karol Samborski
>
> 2011/5/12 AJ Sherbondy <[email protected]>:
>> Karol,
>> I don't know if you have looked at this module on Hackage or whether it will
>> even help you, but there is an evolution algorithm the individual functions
>> of which might be useful to you and is described as follows:
>> AI.SimpleEA
>>
>> A framework for simple evolutionary algorithms. Provided with a function for
>> evaluating a genome's fitness, a function for probabilistic selection among
>> a pool of genomes, and recombination and mutation operators,?runEA?will run
>> an EA that lazily produces an infinite list of generations.
>>
>> AI.SimpleEA.Utils?contains utilitify functions that makes it easier to write
>> the genetic operators.
>>
>> ajsher
>>
>> On Thu, May 12, 2011 at 10:24 AM, Karol Samborski <[email protected]>
>> wrote:
>>>
>>> Hi all,
>>>
>>> I'm a student and I got recently a task to do (and I want to do it in
>>> haskell). I have to implement "genetic algorithm for knapsack problem"
>>> and it would be nice if it will be fast. ?So my question is: what
>>> haskell datatypes, modules etc. should I use for this algorithm to
>>> achieve this goal? I mean fast as compared to implementation in
>>> imperative languages like C.
>>>
>>> Any advices ?
>>>
>>> Best regards,
>>> Karol Samborski
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>>
>> --
>> AJ Sherbondy
>>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
--
Federico Mastellone
Computer Science Engineer - ITBA
".. there are two ways of constructing a software design: One way is
to make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
Tony Hoare, 1980 ACM Turing Award Lecture.
------------------------------
Message: 4
Date: Fri, 13 May 2011 14:35:28 -0700
From: Neil Jensen <[email protected]>
Subject: [Haskell-beginners] Takusen and inserting type Maybe with
sqlite3
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hello, I'm stumped on using Takusen to insert values of type Maybe into a
sqlite database when the underlying database has a field type of REAL.
When I bind a Maybe to an underlying sqlite field of type DATETIME or
INTEGER, the value is stored correctly. However, when I bind a Maybe value
to a database field of type REAL, the value is inserted as "Just ..." or
"Nothing".
I thought bindP would coerce the Maybe type either into the value or a
database null. What am I missing?
Here is an example of an inserted record in the database:
sqlite> select * from summary;
20110331|100002|Just 0.37427717861180376|Just 2.198753718609092|Just
9.402720712996771|Just 17.50143032492688|Just
8.250653601136904|Nothing|Nothing|Just 6.190434991035554
Here is the function:
storeSummary date account returns = do
dbh <- openDb
withSession dbh (do
execDML(cmdbind "REPLACE INTO summary
(date,account_id,one_mo,three_mo,one_yr,two_yr,three_yr,four_yr,five_yr,incept)
\
\VALUES
(?,?,?,?,?,?,?,?,?,?)" [bindP (Just date), bindP (Just account),
bindP (returns !! 0),bindP (returns !! 1),bindP (returns !! 2),bindP
(returns !! 3),
bindP (returns !! 4),bindP (returns !! 5),bindP (returns !! 6),bindP
(returns !! 7) ])
)
And the database:
sqlite>.schema summary
CREATE TABLE "SUMMARY" ("DATE" DATETIME NOT NULL ,"ACCOUNT_ID" INTEGER NOT
NULL ,"ONE_MO" REAL,"THREE_MO" REAL,"ONE_YR" REAL,"TWO_YR" REAL,"THREE_YR"
REAL,"FOUR_YR" REAL,"FIVE_YR" REAL,"INCEPT" REAL, PRIMARY KEY
("DATE","ACCOUNT_ID") )
Thanks in advance,
Neil
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110513/f437e8cd/attachment-0001.htm>
------------------------------
Message: 5
Date: Fri, 13 May 2011 14:43:11 -0700
From: Neil Jensen <[email protected]>
Subject: Re: [Haskell-beginners] Takusen and inserting type Maybe with
sqlite3
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
I just answered my own question... I had forgotten the type signature on the
storeSummary function. When I added the type signature below, it coerced the
Maybe RoR (which is a Double) into a REAL in sqlite3.
storeSummary :: ISODateInt -> AccountId -> [Maybe RoR] -> IO Int
Problem solved.
Neil
On Fri, May 13, 2011 at 2:35 PM, Neil Jensen <[email protected]> wrote:
> Hello, I'm stumped on using Takusen to insert values of type Maybe into a
> sqlite database when the underlying database has a field type of REAL.
>
> When I bind a Maybe to an underlying sqlite field of type DATETIME or
> INTEGER, the value is stored correctly. However, when I bind a Maybe value
> to a database field of type REAL, the value is inserted as "Just ..." or
> "Nothing".
>
> I thought bindP would coerce the Maybe type either into the value or a
> database null. What am I missing?
>
> Here is an example of an inserted record in the database:
>
> sqlite> select * from summary;
> 20110331|100002|Just 0.37427717861180376|Just 2.198753718609092|Just
> 9.402720712996771|Just 17.50143032492688|Just
> 8.250653601136904|Nothing|Nothing|Just 6.190434991035554
>
>
> Here is the function:
>
> storeSummary date account returns = do
> dbh <- openDb
> withSession dbh (do
> execDML(cmdbind "REPLACE INTO summary
> (date,account_id,one_mo,three_mo,one_yr,two_yr,three_yr,four_yr,five_yr,incept)
> \
> \VALUES
> (?,?,?,?,?,?,?,?,?,?)" [bindP (Just date), bindP (Just account),
>
> bindP (returns !! 0),bindP (returns !! 1),bindP (returns !! 2),bindP
> (returns !! 3),
>
> bindP (returns !! 4),bindP (returns !! 5),bindP (returns !! 6),bindP
> (returns !! 7) ])
> )
>
>
> And the database:
>
> sqlite>.schema summary
> CREATE TABLE "SUMMARY" ("DATE" DATETIME NOT NULL ,"ACCOUNT_ID" INTEGER NOT
> NULL ,"ONE_MO" REAL,"THREE_MO" REAL,"ONE_YR" REAL,"TWO_YR" REAL,"THREE_YR"
> REAL,"FOUR_YR" REAL,"FIVE_YR" REAL,"INCEPT" REAL, PRIMARY KEY
> ("DATE","ACCOUNT_ID") )
>
> Thanks in advance,
> Neil
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110513/bb64f442/attachment-0001.htm>
------------------------------
Message: 6
Date: Fri, 13 May 2011 19:55:14 -0700
From: [email protected]
Subject: [Haskell-beginners] do-notation question
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
In The Yesod Book, I see the following code:
defaultLayout contents = do
PageContent title headTags bodyTags <- widgetToPageContent $ do
addCassius ...
How does this work? Is bodyTags drawn from widgetToPageContent and
then used as the third argument to PageContent?
tia,
Lee
------------------------------
Message: 7
Date: Fri, 13 May 2011 22:10:03 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] do-notation question
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
My guess is widgetToPageContent is a function that takes "do addCassius ..."
and returns a value in the monad "m T" where "T" is some datatype like "data
T = PageContent x y z | ..." . The "<-" removes the "m" from "m T" and
pattern matches "x", "y" and "z" to "title", "headTags" and "bodyTags".
-deech
On Fri, May 13, 2011 at 9:55 PM, <[email protected]> wrote:
> In The Yesod Book, I see the following code:
>
> defaultLayout contents = do
> PageContent title headTags bodyTags <- widgetToPageContent $ do
> addCassius ...
>
> How does this work? Is bodyTags drawn from widgetToPageContent and then
> used as the third argument to PageContent?
>
> tia,
> Lee
>
>
> _______________________________________________
> 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/20110513/9102eace/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 35, Issue 26
*****************************************