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:  Dynamic Programming in Haskell (Tom Doris)
   2. Re:  Dynamic Programming in Haskell (Ali Razavi)
   3.  reading and playing music openAL (Maria Gabriela Valdes)
   4.  Some beginning questions for Haskell (Liu shuping)
   5.  type of pattern matching (Michael Mossey)
   6. Re:  type of pattern matching (Stephen Tetley)


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

Message: 1
Date: Tue, 6 Jul 2010 20:53:33 +0100
From: Tom Doris <[email protected]>
Subject: Re: [Haskell-beginners] Dynamic Programming in Haskell
To: Ali Razavi <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Is there an online version of the book, or failing that could you post the
full problem statement?

On 6 July 2010 17:45, Ali Razavi <[email protected]> wrote:

> In order to practice Haskell, I decided to program some algorithms from the
> CLRS book. Particularly, I tried to implement the Matrix Chain Order from
> Chapter 15 on Dynamic Programming.
> Here is my code. It seems to work, however, it looks ugly and it was a
> nightmare to debug. I appreciate comments about a more elegant solution, and
> generally the best way to implement these kinds of algorithms in Haskell.
> Style improvement suggestions are also welcome.
>
> Best,
> Ali
>
>
> import Data.Array
>
>
> pp = [30,35,15,5,10,20,25]
>
> para p = let n = length p - 1
>              msij =  array ((1,1),(n,n))
>                            ([((i,j), (0,0)) | i <-[1..n], j <-[1..n]] ++
>                             [((i,j), (m, s))| l<-[2..n]
>                                                      , i<-[1..n-l+1]
>                                                      , let j = i + l - 1
>                                                      , let qs =
> [q|k<-[i..j-1]
>                                                                    , let q
> = fst (msij!(i,k)) + fst (msij!(k+1, j)) + p!!(i-1)*p!!k*p!!j]
>                                                      , let (m, s, c) =
> foldl (\(mz,sz,ind) x-> if x < mz then (x,ind,ind+1) else (mz,sz,ind+1))
> (head qs, i, i) qs ])
>          in msij
>
>
>
> chainSolve p = let sol = para p
>                    n = length p - 1 in
>                 do
>                     print $ fst $ sol!(1,n)
>                     putStrLn $ printSol sol 1 n ""
>                 where
>                     printSol s i j o =
>                         if i == j then
>                             o ++ "A" ++ (show i)
>                         else
>                             o ++ "(" ++
>                             (printSol s i (snd (s!(i,j))) o) ++
>                             (printSol s ((snd (s!(i,j)))+1) j o) ++ ")"
>
>
>
>
>
> _______________________________________________
> 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/20100706/5f2335fa/attachment-0001.html

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

Message: 2
Date: Tue, 6 Jul 2010 16:32:59 -0400
From: Ali Razavi <[email protected]>
Subject: Re: [Haskell-beginners] Dynamic Programming in Haskell
To: Tom Doris <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Sorry, I just assumed everyone has a copy of CLRS :) The following link
describes the problem and has the imperative pseudo-code of the solution.

http://www.columbia.edu/~cs2035/courses/csor4231.F09/matrix-chain.pdf



On Tue, Jul 6, 2010 at 3:53 PM, Tom Doris <[email protected]> wrote:

> Is there an online version of the book, or failing that could you post the
> full problem statement?
>
> On 6 July 2010 17:45, Ali Razavi <[email protected]> wrote:
>
>> In order to practice Haskell, I decided to program some algorithms from
>> the CLRS book. Particularly, I tried to implement the Matrix Chain Order
>> from Chapter 15 on Dynamic Programming.
>> Here is my code. It seems to work, however, it looks ugly and it was a
>> nightmare to debug. I appreciate comments about a more elegant solution, and
>> generally the best way to implement these kinds of algorithms in Haskell.
>> Style improvement suggestions are also welcome.
>>
>> Best,
>> Ali
>>
>>
>> import Data.Array
>>
>>
>> pp = [30,35,15,5,10,20,25]
>>
>> para p = let n = length p - 1
>>              msij =  array ((1,1),(n,n))
>>                            ([((i,j), (0,0)) | i <-[1..n], j <-[1..n]] ++
>>                             [((i,j), (m, s))| l<-[2..n]
>>                                                      , i<-[1..n-l+1]
>>                                                      , let j = i + l - 1
>>                                                      , let qs =
>> [q|k<-[i..j-1]
>>                                                                    , let q
>> = fst (msij!(i,k)) + fst (msij!(k+1, j)) + p!!(i-1)*p!!k*p!!j]
>>                                                      , let (m, s, c) =
>> foldl (\(mz,sz,ind) x-> if x < mz then (x,ind,ind+1) else (mz,sz,ind+1))
>> (head qs, i, i) qs ])
>>          in msij
>>
>>
>>
>> chainSolve p = let sol = para p
>>                    n = length p - 1 in
>>                 do
>>                     print $ fst $ sol!(1,n)
>>                     putStrLn $ printSol sol 1 n ""
>>                 where
>>                     printSol s i j o =
>>                         if i == j then
>>                             o ++ "A" ++ (show i)
>>                         else
>>                             o ++ "(" ++
>>                             (printSol s i (snd (s!(i,j))) o) ++
>>                             (printSol s ((snd (s!(i,j)))+1) j o) ++ ")"
>>
>>
>>
>>
>>
>> _______________________________________________
>> 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/20100706/ec5d2e10/attachment-0001.html

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

Message: 3
Date: Tue, 6 Jul 2010 21:29:54 -0430
From: Maria Gabriela Valdes <[email protected]>
Subject: [Haskell-beginners] reading and playing music openAL
To: [email protected], [email protected],
        [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Hi ! We have a question about about openAL. We would like to know if anybody
knows how to read a WAV file by chunks of a determined size, and after doing
some processing with a specific chunk send that same chunk back to the sound
card so we can play the whole WAV continiously (just like a music player).
Thanks in advance,

-- 
Maria Gabriela Valdes G.
Linux Registered User #485743
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100706/27e570d8/attachment-0001.html

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

Message: 4
Date: Wed, 7 Jul 2010 12:04:07 +0800
From: Liu shuping <[email protected]>
Subject: [Haskell-beginners] Some beginning questions for Haskell
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Hi,

I am new to Haskell, currently I am doing .Net development on windows
platform. I began to know about Haskell for the reason when I knew some C#
lambda features come from functional language. I am interested in Haskell
from the very beginning when I saw it.

For I am really a very beginner, I get some basic questions:
1. Can you have some very general information to explain why use Haskell or
functional language.
2. Is it a right choice of Haskell if I want to develop some geology
software which mainly doing some huge numerical computation which takes long
long time?
3. How about user interface, is Haskell capable to build application with
complex user interface? or should I just use Haskell to build the core
engine and user other language to build the user interface?
4. Is Haskell cross-platform? I mean if the Haskell source code is "code
once and build everywhere?"
5. Are there any successful applications built with Haskell?  they can give
me a direct scene of what Haskell can do.

I appreciated any of your information or comments.

-- 
Sincerely,

Liu Shuping

Ocean University of China
Email: [email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100706/92034e0c/attachment-0001.html

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

Message: 5
Date: Wed, 07 Jul 2010 00:19:43 -0700
From: Michael Mossey <[email protected]>
Subject: [Haskell-beginners] type of pattern matching
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

What if I want to check if a variable uses a particular constructor, but I 
don't want to unpack it. For example:

data Item = Note Int Float Rational [Int] [Float]
           | Dynamic Int

And I want to write

doSomething :: Maybe Result
doSomething item = case item of
   note@(Note _ _ _ _ _) -> Just $ process note
   _                     ->  Nothing

But I don't like writing "Note _ _ _ _ _"

Thanks,
Mike


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

Message: 6
Date: Wed, 7 Jul 2010 08:26:50 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] type of pattern matching
To: Michael Mossey <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hi Michael

Untested - maybe you can use Record puns (section 7.3.15.of the GHC
manual). Though they might only work if you have used field names in
your data type.

{} swaps for _ _ _ _ _ _  so it would be:

> doSomething :: Maybe Result
> doSomething item = case item of
>  note@(Note {}) -> Just $ process note
>  _                     ->  Nothing


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

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


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

Reply via email to