Beginners Digest, Vol 17, Issue 11

2009-11-09 Thread beginners-request
Send Beginners mailing list submissions to
beginners@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-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than Re: Contents of Beginners digest...


Today's Topics:

   1.  parse String - Expression (John Moore)
   2. Re:  parse String - Expression (Felipe Lessa)
   3. Re:  parse String - Expression (Felipe Lessa)
   4. Re:  parse String - Expression (Daniel Fischer)
   5.  Re: Installing packages in Ubuntu (Nathan M. Holden)
   6.  Re: Installing packages in Ubuntu (Maur??cio CA)
   7.  Simple haskell problem ! Help please (Denis Firsov)
   8. Re:  Simple haskell problem ! Help please (Joe Fredette)
   9.  Re: Simple haskell problem ! Help please (Tim Attwood)


--

Message: 1
Date: Sun, 8 Nov 2009 17:53:48 +
From: John Moore john.moor...@gmail.com
Subject: [Haskell-beginners] parse String - Expression
To: beginners@haskell.org
Message-ID:
4f7ad1ad0911080953t17ffd10co237995d6a6ce5...@mail.gmail.com
Content-Type: text/plain; charset=iso-8859-1

Hi,
I'm trying to find a way to parseRPN (Reverse Polish Numbers) to
expressions rather than to just numbers. e.g. I want the answer to be in the
form

(Multiply (Val 2) (Val 3)) rather than just the answer.



Are these anyway near the steps
parseRPN :: String-Expression

This is a lot more complicated then I thought.!!!

First do we have to read in a string is this (IsString)

 fromString :: String - a

Then this goes on a stack

pushStack :: a - Stack - Stack (Takes a value and puts in on a stack)

Later we pop it off

popStack :: Stack - (a,Stack) -- takes the value of the stack and leaves
the stack

Do we also have to define taking off the stack such as head(popstack) or
fst(popstack) if we do we would probably have  one for putting it onto a
stack.

Do we then turn the value into an Expression.?
-- next part --
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20091108/4fec4429/attachment-0001.html

--

Message: 2
Date: Sun, 8 Nov 2009 16:49:37 -0200
From: Felipe Lessa felipe.le...@gmail.com
Subject: Re: [Haskell-beginners] parse String - Expression
To: beginners@haskell.org
Message-ID: 20091108184937.ga22...@kira.casa
Content-Type: text/plain; charset=us-ascii

On Sun, Nov 08, 2009 at 05:53:48PM +, John Moore wrote:
 Hi,
 I'm trying to find a way to parseRPN (Reverse Polish Numbers) to
 expressions rather than to just numbers. e.g. I want the answer to be in the
 form

 (Multiply (Val 2) (Val 3)) rather than just the answer.

You don't need to code all the parser by hand.  You can use, for
example, Parsec parsers.

Spoilers ahead!!!






If your data type is

data Expr a = Multiply (Expr a) (Expr a)
| Val a

then you may write something like

expression :: Parser a - Parser (Expr a)
expression valParser = spaces  (mult | val)
  where
expr = expression valParser
mult = char *  (Multiply $ expr * expr)
val  = Val $ valParser

using Parsec for a concrete example.

HTH,

--
Felipe.


--

Message: 3
Date: Sun, 8 Nov 2009 16:53:00 -0200
From: Felipe Lessa felipe.le...@gmail.com
Subject: Re: [Haskell-beginners] parse String - Expression
To: beginners@haskell.org
Message-ID: 20091108185300.gb22...@kira.casa
Content-Type: text/plain; charset=us-ascii

On Sun, Nov 08, 2009 at 04:49:37PM -0200, Felipe Lessa wrote:
 You don't need to code all the parser by hand.  You can use, for
 example, Parsec parsers.

IOW, you may use the language's implicit stack instead of
building your own.

--
Felipe.


--

Message: 4
Date: Sun, 8 Nov 2009 20:00:10 +0100
From: Daniel Fischer daniel.is.fisc...@web.de
Subject: Re: [Haskell-beginners] parse String - Expression
To: beginners@haskell.org
Message-ID: 200911082000.11449.daniel.is.fisc...@web.de
Content-Type: text/plain;  charset=iso-8859-15

Am Sonntag 08 November 2009 18:53:48 schrieb John Moore:
 Hi,
 I'm trying to find a way to parseRPN (Reverse Polish Numbers) to
 expressions rather than to just numbers. e.g. I want the answer to be in
 the form

 (Multiply (Val 2) (Val 3)) rather than just the answer.


I'd suggest using something like

type Stack = [Expression]

parseRPN :: Parser Expression
parseRPN = rpn []

parseVal :: Parser Expression
parseVal = do
num - parseNumber
return (Val num)

rpn :: Stack - Parser Expression
rpn stack = (do
char '+'
case stack of
(x:y:ts) - rpn (Add x y:ts)
_ - parsecFail BinOp requires two values on Stack)
| (do
char '*'
case stack of
(x:y:ts) - rpn 

Beginners Digest, Vol 17, Issue 12

2009-11-09 Thread beginners-request
 = unsafePerformIO (getWrongWife = sex)
http://blog.ertes.de/




--

Message: 5
Date: Mon, 09 Nov 2009 22:00:02 +0100
From: Nicolas Pouillard nicolas.pouill...@gmail.com
Subject: Re: [Haskell-beginners] Re: Either Monadic Trouble
To: Ertugrul Soeylemez e...@ertes.de
Cc: beginners beginners@haskell.org
Message-ID: 1257800088-sup-1...@peray
Content-Type: text/plain; charset=UTF-8

Excerpts from Ertugrul Soeylemez's message of Mon Nov 09 21:44:44 +0100 2009:
 Nicolas Pouillard nicolas.pouill...@gmail.com wrote:
 
   Either is not a monad, you can check this by typing
  :i Either
   in GHCi; you will not see a line like
  instance Monad Either
   in the result. Compare this to
  :i Maybe
 
  In fact the Either Monad instance is defined in the 'transformers' (or
  'mtl') packages.
 
 Either is still not a monad.  Have a look at its kind.

OK, right Either is not but (Either e), where e must be in
the Error type class.

-- 
Nicolas Pouillard
http://nicolaspouillard.fr


--

Message: 6
Date: Mon, 09 Nov 2009 22:46:19 +0100
From: legajid lega...@free.fr
Subject: [Haskell-beginners] What is the best practice for code]
To: beginners@haskell.org
Message-ID: 4af88dab.7000...@free.fr
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hello,

i wanted to write a program that searches for all combinations of some 
numbers, the sum of which is a given value.
So, i started writing my program, creating a function for each separate 
phase : creating list of triples, selecting valuable ones, filtering the 
result.

Looking at my code, i've reduced it several ways; the last version holds 
on one single line of code.

Please, from the 3 versions i established, which one is  better? What 
are the criterias of a good code ?
What about using many anonymous functions?
I think there are other solutions than those i propose.

Following is my code

{-First solution -}
nombres=[9,8..1]
-- all combinations
ftoutes xx = [(x, y, z) | x - xx, y - xx, z - xx]
-- keep valuable ones
futiles xyz = [(x, y, z) | (x,y,z) - xyz, y  x, z  y ]
-- filter
f_flt (x,y, z) = (x+y+z) == 19
-- final result
f = filter (f_flt) (futiles (ftoutes nombres ))

{-Second solution   -}
futiles2 xx = [(x, y, z) | x - xx, y - xx, z - xx, y  x, z  y]
f2 = filter (\(x,y,z) - (x+y+z)==19) (futiles2 nombres )

{-Third solution  -}
f3 = filter (\(x,y,z) - (x+y+z)==19) ((\ xx - [(x, y, z) | x - xx, y 
- xx, z - xx, y  x, z  y]) nombres )

Thanks for your advice

Didier.





--

Message: 7
Date: Mon, 9 Nov 2009 22:05:43 +
From: John Moore john.moor...@gmail.com
Subject: [Haskell-beginners] turning a value into an expression
To: beginners@haskell.org
Message-ID:
4f7ad1ad0911091405i58bfc339g1776768243fa7...@mail.gmail.com
Content-Type: text/plain; charset=iso-8859-1

Hi,
   How do I turn a value into an expression
I want to do for e.g. 8 - 1 turn it into (subtract (Val8) (Val1)

Any ideas

J
-- next part --
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20091109/973318cf/attachment-0001.html

--

Message: 8
Date: Mon, 9 Nov 2009 23:48:38 +0100
From: Deniz Dogan deniz.a.m.do...@gmail.com
Subject: Re: [Haskell-beginners] turning a value into an expression
To: John Moore john.moor...@gmail.com
Cc: beginners@haskell.org
Message-ID:
7b501d5c0911091448mff920c2m1048d25968960...@mail.gmail.com
Content-Type: text/plain; charset=ISO-8859-1

2009/11/9 John Moore john.moor...@gmail.com:
 Hi,
    How do I turn a value into an expression
 I want to do for e.g. 8 - 1 turn it into (subtract (Val8) (Val1)

 Any ideas

 J
 ___
 Beginners mailing list
 Beginners@haskell.org
 http://www.haskell.org/mailman/listinfo/beginners



import Prelude hiding ((-))

data Val a = Val a
  deriving Show

data Expr a b = Subtract a b
  deriving Show

(-) :: Num a = a - a - Expr (Val a) (Val a)
x - y = Subtract (Val x) (Val y)



 4 - 3
Subtract (Val 4) (Val 3)

-- 
Deniz Dogan


--

Message: 9
Date: Mon, 09 Nov 2009 18:05:04 -0500
From: i?fai iae...@me.com
Subject: Re: [Haskell-beginners] Re: Either Monadic Trouble
To: Nicolas Pouillard nicolas.pouill...@gmail.com
Cc: Beginners@haskell.org
Message-ID: 97c85097-db8e-4ef2-aafd-7edda7618...@me.com
Content-Type: text/plain; charset=iso-8859-1; format=flowed; delsp=yes

This is all very confusing. You say that it is defined in the  
transformers. Does this mean it is possible to use the code I am  
trying to get to work to do what I want?

You also mention the attempt package, I must admit that I am not  
entirely sure how to use it either. Note that I haven't done a lot of  
error handling in haskell (the extent usually involved Maybe)

- iæfai.


On 2009-11-09, at 4:00 PM, Nicolas Pouillard wrote:

 Excerpts from Ertugrul Soeylemez's message of Mon Nov 09 21:44