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: having trouble with helloworld style program
(Ertugrul Soeylemez)
2. Re: making function problem (chapter 6 of Programming in
Haskell) (KC)
3. Re: making function problem (chapter 6 of Programming in
Haskell) (Roelof Wobben)
4. Re: Conciseness question (KC)
5. Re: making function problem (chapter 6 of Programming in
Haskell) (Ertugrul Soeylemez)
6. Re: Parse string with optional entries [Parsec]
([email protected])
7. Re: making function problem (chapter 6 of Programming in
Haskell) (Roelof Wobben)
8. Re: [Haskell-cafe] For class Monoid; better names than
mempty & mappend might have been: mid (mident) & mbinop (KC)
9. Re: Parse string with optional entries [Parsec] (Stephen Tetley)
10. Re: Parse string with optional entries [Parsec] (Antoine Latter)
----------------------------------------------------------------------
Message: 1
Date: Mon, 8 Aug 2011 15:57:41 +0200
From: Ertugrul Soeylemez <[email protected]>
Subject: Re: [Haskell-beginners] having trouble with helloworld style
program
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
Sukumaran A <[email protected]> wrote:
> Ohh, I missed to see reply from others. Anyway I am putting one more
> method just from my side
>
> module Main where
> import Prelude
>
> stringToInt::String->Int
> stringToInt str = read str
>
> main =do
> x<-getLine
> y<-return x
> print $ stringToInt y
This is exactly equivalent to the other methods, but has the additional
'return', which is a no-op. Please do not suggest such a style. To be
honest, I think the best coding style for this particular example is not
to use do-notation at all:
module Main where
main :: IO ()
main =
let stringToInt :: String -> Int
stringToInt = read
in fmap stringToInt getLine >>=
print
Greets,
Ertugrul
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/
------------------------------
Message: 2
Date: Mon, 8 Aug 2011 07:26:45 -0700
From: KC <[email protected]>
Subject: Re: [Haskell-beginners] making function problem (chapter 6 of
Programming in Haskell)
To: [email protected]
Message-ID:
<camlkxymfu9tvpppyh2nes2lao+em5b20+96bs03e3nikqrs...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Besides the programming problem for (^) for natural numbers; there is
also the algorithmic question in that can the recursive case be done
better than m ^ n = m * m ^ (n -1)?
--
--
Regards,
KC
------------------------------
Message: 3
Date: Mon, 8 Aug 2011 14:28:28 +0000
From: Roelof Wobben <[email protected]>
Subject: Re: [Haskell-beginners] making function problem (chapter 6 of
Programming in Haskell)
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
----------------------------------------
> To: [email protected]
> From: [email protected]
> Date: Mon, 8 Aug 2011 13:26:14 +0200
> Subject: Re: [Haskell-beginners] making function problem (chapter 6 of
> Programming in Haskell)
>
> Roelof Wobben <[email protected]> wrote:
>
> > I don't think I want that.
> > I want to type this 2^3 and then the outcome will be 8.
> > So next try
> >
> > (^) :: Int -> Int -> Int
> >
> > Because the first and second numbers are integers and the outcome also
> > will be a integer.
>
> This looks more like it. Now forget about programming for a moment and
> think about how you can express the exponentiation operation in terms of
> simple equations. Let me show you how you would do that for addition of
> natural numbers, if you have only successor (succ) and predecessor
> (pred) functions available:
>
> x + 0 = x
> x + y = succ x + pred y
>
> Evaluation shows:
>
> 3 + 2 = succ 3 + pred 2
> = 4 + 1
> = succ 4 + pred 1
> = 5 + 0
> = 5
>
> A similarly simple ruleset can express exponentiation, too.
Hello,
I think you mean something like this :
2 ^ 3 =
= 2 * 2 ^ 2
= 2 * 2 * 2 ^1
= 2 * 2 * 2 * 2 ^ 0
= 2 * 2 * 2 * 1
= 2 * 2 * 2
= 4 * 2
= 8
Roelof
------------------------------
Message: 4
Date: Mon, 8 Aug 2011 07:31:32 -0700
From: KC <[email protected]>
Subject: Re: [Haskell-beginners] Conciseness question
To: Manfred Lotz <[email protected]>, [email protected],
haskell-cafe <[email protected]>
Message-ID:
<CAMLKXy=KsWEYt3ESP0XZNoRw4Mg8MEpM4fptvuG7+CwU17=4...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Sorry, I haven't read all the replies so I don't know if you have
completely described the problem you're trying to solve; however, it
might be better for people in future to say they want O(1) for
insertions, O(lg n) for searching, etc.
If they don't want to completely describe what their problem is.
--
--
Regards,
KC
------------------------------
Message: 5
Date: Mon, 8 Aug 2011 16:36:18 +0200
From: Ertugrul Soeylemez <[email protected]>
Subject: Re: [Haskell-beginners] making function problem (chapter 6 of
Programming in Haskell)
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
Roelof Wobben <[email protected]> wrote:
> I think you mean something like this :
>
> 2 ^ 3 =
> = 2 * 2 ^ 2
> = 2 * 2 * 2 ^1
> = 2 * 2 * 2 * 2 ^ 0
> = 2 * 2 * 2 * 1
> = 2 * 2 * 2
> = 4 * 2
> = 8
Yes, but that's not a rule system. Try to come up with a rule system to
express exponentiation. You need two rules for the algorithm you want
to implement.
Greets,
Ertugrul
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/
------------------------------
Message: 6
Date: Mon, 8 Aug 2011 14:44:44 +0000
From: <[email protected]>
Subject: Re: [Haskell-beginners] Parse string with optional entries
[Parsec]
To: <[email protected]>
Cc: [email protected]
Message-ID:
<d51f81ac58698f4c9f3819136bfada3f03748...@mucse504.eu.infineon.com>
Content-Type: text/plain; charset="iso-8859-1"
Ah, thanks. The next step would then be to replace empty strings with Nothing,
and the others with
Just Value
I forgot to mention that the values are Double.
I tried the following:
numberP :: Parser Double -- From RWH
numberP = do
s <- getInput
case readSigned readFloat s of
[(n, s')] -> n <$ setInput s'
_ -> empty
<?> "number"
valueP :: Parser [Double]
valueP = do
(many numberP) `sepBy` (char '\t')
<?> "value list"
It type checks, but raises an exception:
Main> parseTest valueP "1\t\t3.3"
*** Exception: Text.ParserCombinators.Parsec.Prim.many: combinator 'many' is
applied to a parser that accepts an empty string.
Is there another way to parse Double values?
Thanks a lot so far.
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of David McBride
Sent: Monday, August 08, 2011 3:53 PM
To: Lukasser Stefan (IFAT IMM PSD D TEC / EE)
Cc: [email protected]; [email protected]
Subject: Re: [Haskell-beginners] Parse string with optional entries [Parsec]
Read up on the sepBy combinator.
parse (sepBy (many digit) (char ',')) "" "123,321,,2321"
Right ["123","321","","2321"]
On Mon, Aug 8, 2011 at 7:53 AM, <[email protected]> wrote:
> Hi,
>
> I have something similar to the CSV-Parser in RWH, chapter 16.
> The problem are the possible empty cells, i.e. consecutive '\t'-Characters.
>
>
> -----Original Message-----
> From: Antoine Latter [mailto:[email protected]]
> Sent: Monday, August 08, 2011 1:44 PM
> To: Lukasser Stefan (IFAT IMM PSD D TEC / EE)
> Cc: [email protected]
> Subject: Re: [Haskell-beginners] Parse string with optional entries [Parsec]
>
> On Mon, Aug 8, 2011 at 6:39 AM, ?<[email protected]> wrote:
>> Hi all,
>>
>> I'm trying to parse a string in one of the following forms using Parsec:
>>
>> "1\t1\t123\t456" -> desired output: [Just 1, Just 1, Just 123, Just 456]
>>
>> or
>>
>> "1\t\1\t\t456" ?-> desired output: [Just 1, Just 1, Nothing, Just 456]
>>
>> i.e., the input is a list of numbers, separated by '\t' characters, with the
>> possibility of missing entries.
>> I'm having troubles with the backtracking in case of missing numbers. Can
>> anybody give me a hint?
>>
>
> What do you have so far?
>
>> Thanks in advance,
>> Stefan
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 7
Date: Mon, 8 Aug 2011 14:53:30 +0000
From: Roelof Wobben <[email protected]>
Subject: Re: [Haskell-beginners] making function problem (chapter 6 of
Programming in Haskell)
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
----------------------------------------
> To: [email protected]
> From: [email protected]
> Date: Mon, 8 Aug 2011 16:36:18 +0200
> Subject: Re: [Haskell-beginners] making function problem (chapter 6 of
> Programming in Haskell)
>
> Roelof Wobben <[email protected]> wrote:
>
> > I think you mean something like this :
> >
> > 2 ^ 3 =
> > = 2 * 2 ^ 2
> > = 2 * 2 * 2 ^1
> > = 2 * 2 * 2 * 2 ^ 0
> > = 2 * 2 * 2 * 1
> > = 2 * 2 * 2
> > = 4 * 2
> > = 8
>
> Yes, but that's not a rule system. Try to come up with a rule system to
> express exponentiation. You need two rules for the algorithm you want
> to implement.
>
>
> Greets,
> Ertugrul
>
>
> --
> nightmare = unsafePerformIO (getWrongWife >>= sex)
> http://ertes.de/
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
Maybe this :
x ^ 0 = 1
x ^ y = x * (y-1)
Roelof
------------------------------
Message: 8
Date: Mon, 8 Aug 2011 07:56:27 -0700
From: KC <[email protected]>
Subject: Re: [Haskell-beginners] [Haskell-cafe] For class Monoid;
better names than mempty & mappend might have been: mid (mident) &
mbinop
To: Henning Thielemann <[email protected]>,
haskell-cafe <[email protected]>, [email protected]
Message-ID:
<CAMLKXy=eqthh+lexynpkemp-drbwo9-jl385lk1spjdunt8...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
> As pointed out earlier in this list, the name of the class and the methods
> are inconsistent.
> Monoid refers to a general algebraic structure, whereas
> mempty and mappend refer to certain instances like lists.
>
Thank you for articulating what I was trying to get at.
--
--
Regards,
KC
------------------------------
Message: 9
Date: Mon, 8 Aug 2011 15:57:00 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Parse string with optional entries
[Parsec]
Cc: [email protected]
Message-ID:
<CAB2TPRDezcD=dnffkaiqgukronekrjua9f0t1s1vdn6jqsh...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
> Is there another way to parse Double values?
Yes the `float` parser.
Note that this is a Token parser - you have to follow a particular
pattern to "instantiate" parsers in this module using a "LanguageDef".
There should be examples around showing how to do this.
------------------------------
Message: 10
Date: Mon, 8 Aug 2011 10:17:16 -0500
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] Parse string with optional entries
[Parsec]
To: [email protected]
Cc: [email protected], [email protected]
Message-ID:
<cakjsnqhmouxtaqtpxfujxntq0jbgbcdys5xgcd74x2ura4t...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
On Mon, Aug 8, 2011 at 9:44 AM, <[email protected]> wrote:
> Ah, thanks. The next step would then be to replace empty strings with
> Nothing, and the others with
> Just Value
>
> I forgot to mention that the values are Double.
> I tried the following:
>
> numberP :: Parser Double ?-- From RWH
> numberP = do
> ? ?s <- getInput
> ? ?case readSigned readFloat s of
> ? ? ? ?[(n, s')] -> n <$ setInput s'
> ? ? ? ?_ ? ? ? ? -> empty
> ?<?> "number"
>
> valueP :: Parser [Double]
> valueP = do
> ? ?(many numberP) `sepBy` (char '\t')
> ?<?> "value list"
>From looking at your types, I'm not sure how it type checks. Shouldn't
this just be:
> numbersP `sepBy` (char '\t')
Or, in your case:
> optionMaybe numbersP `sepBy` char '\t'
(The second solution should have type Parser [Maybe Double])
Although the error given confuses me - I'm not sure why the 'numbersP'
parser should succeed with no input.
Antoine
>
> It type checks, but raises an exception:
>
> Main> parseTest valueP "1\t\t3.3"
> *** Exception: Text.ParserCombinators.Parsec.Prim.many: combinator 'many' is
> applied to a parser that accepts an empty string.
>
>
> Is there another way to parse Double values?
>
> Thanks a lot so far.
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of David McBride
> Sent: Monday, August 08, 2011 3:53 PM
> To: Lukasser Stefan (IFAT IMM PSD D TEC / EE)
> Cc: [email protected]; [email protected]
> Subject: Re: [Haskell-beginners] Parse string with optional entries [Parsec]
>
> Read up on the sepBy combinator.
>
> parse (sepBy (many digit) (char ',')) "" "123,321,,2321"
> Right ["123","321","","2321"]
>
> On Mon, Aug 8, 2011 at 7:53 AM, ?<[email protected]> wrote:
>> Hi,
>>
>> I have something similar to the CSV-Parser in RWH, chapter 16.
>> The problem are the possible empty cells, i.e. consecutive '\t'-Characters.
>>
>>
>> -----Original Message-----
>> From: Antoine Latter [mailto:[email protected]]
>> Sent: Monday, August 08, 2011 1:44 PM
>> To: Lukasser Stefan (IFAT IMM PSD D TEC / EE)
>> Cc: [email protected]
>> Subject: Re: [Haskell-beginners] Parse string with optional entries [Parsec]
>>
>> On Mon, Aug 8, 2011 at 6:39 AM, ?<[email protected]> wrote:
>>> Hi all,
>>>
>>> I'm trying to parse a string in one of the following forms using Parsec:
>>>
>>> "1\t1\t123\t456" -> desired output: [Just 1, Just 1, Just 123, Just 456]
>>>
>>> or
>>>
>>> "1\t\1\t\t456" ?-> desired output: [Just 1, Just 1, Nothing, Just 456]
>>>
>>> i.e., the input is a list of numbers, separated by '\t' characters, with
>>> the possibility of missing entries.
>>> I'm having troubles with the backtracking in case of missing numbers. Can
>>> anybody give me a hint?
>>>
>>
>> What do you have so far?
>>
>>> Thanks in advance,
>>> Stefan
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
> _______________________________________________
> 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 38, Issue 18
*****************************************