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:  Performance of function defined in a 'where' clause
      (Kevin Haines)
   2. Re: Re: [Haskell-beginners] SQL Lexer
      ([email protected])
   3. Re:  SQL Lexer (Jan Jakubuv)
   4. Re:  SQL Lexer (Patrick LeBoutillier)
   5.  defining 'init' in terms of 'foldr' (Michael Mossey)
   6. Re:  SQL Lexer (Haroldo Stenger)
   7. Re:  Performance of function defined in a 'where' clause
      (Brent Yorgey)
   8. Re:  A Quantity Type - Integer without the        Negative #'s
      (Chadda? Fouch?)


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

Message: 1
Date: Sun, 10 May 2009 16:33:12 +0100
From: Kevin Haines <[email protected]>
Subject: Re: [Haskell-beginners] Performance of function defined in a
        'where' clause
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

I used -O.

Also, to answer Brent's posting, the Palette list is different further 
down but I did take the tip and replace the pasted lines with replicate, 
so thanks!

Cheers

Kevin



Peter Verswyvelen wrote:
> Did you compile with -O or -O2?
> 
> On Sat, May 9, 2009 at 6:50 PM, Kevin Haines <[email protected] 
> <mailto:[email protected]>> wrote:
> 


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

Message: 2
Date: Sun, 10 May 2009 16:55:49 +0000
From: [email protected]
Subject: Re: Re: [Haskell-beginners] SQL Lexer
To: Andy Elvey <[email protected]>,    Patrick LeBoutillier
        <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"


> Hi Patrick - I like it! I'm still a Haskell beginner, but even to me,  
> your code seems very clear and easy to understand. I've been thinking of  
> doing some simple parsers too, so I was wondering - may I use this code  
> of yours as a base for them?

Sure, anyone here can use the code if they have any interest in it.

Patrick


> Well done, and thanks for doing this!

> - Andy

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20090510/62c0074c/attachment-0001.html

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

Message: 3
Date: Mon, 11 May 2009 11:33:20 +0100
From: Jan Jakubuv <[email protected]>
Subject: Re: [Haskell-beginners] SQL Lexer
To: Patrick LeBoutillier <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-1

Hello Patrick,

that's a nice one. I have two notes for you:

1) Why do you handle spaces as tokens? Can't you just skip them completely?
   It could make the parser simpler.

2) Your lexer does not provide any information about positions of tokens in
   the source code. You may want to do that in order to:

   a) report better error messages
   b) use parsec's `token` function [1] to make parsec work with your tokens.
      Note that parsec wants you to use its data type `SourcePos` to represent
      positions. See [2] for a simple example and further stuff.

[1]: http://legacy.cs.uu.nl/daan/download/parsec/parsec.html#token
[2]: http://legacy.cs.uu.nl/daan/download/parsec/parsec.html#SeperateScanners

Sincerely,
   Jan.

On Fri, May 08, 2009 at 09:53:04PM -0400, Patrick LeBoutillier wrote:
> Hi all,
> 
> In the process of writing an SQL parser I started by writing a lexer.
> The code can be found here:
> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=4736#a4736
> 
> You can run it like this in ghci:
> 
> Prelude SQL.Lexer> runLexer "select * from TABLE order by FIELD"
> [Token Reserved "select",Token Space " ",Token Operator "*",Token
> Space " ",Token Reserved "from",Token Space " ",Token Identifier
> "TABLE",Token Space " ",Token Reserved "order",Token Space " ",Token
> Reserved "by",Token Space " ",Token Identifier "FIELD"]
> 
> Since this is pretty much my first Haskell project over 10 lines long,
> I'm looking for some feedback of any kind.
> Ultimately I would like to use this lexer to build a functional SQL
> parser using Parsec.
> 
> 
> Thanks,
> 
> Patrick
> 
> -- 
> =====================
> Patrick LeBoutillier
> Rosemère, Québec, Canada
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners


-- 
Heriot-Watt University is a Scottish charity
registered under charity number SC000278.



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

Message: 4
Date: Mon, 11 May 2009 09:28:53 -0400
From: Patrick LeBoutillier <[email protected]>
Subject: Re: [Haskell-beginners] SQL Lexer
To: Jan Jakubuv <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

On Mon, May 11, 2009 at 6:33 AM, Jan Jakubuv <[email protected]> wrote:
> Hello Patrick,
>
> that's a nice one. I have two notes for you:
>
> 1) Why do you handle spaces as tokens? Can't you just skip them completely?
>   It could make the parser simpler.

I added that as a debug tool (that way I can recreate the SQL exactly
and use diff to make sure it tokenised properly). I agree that besides
that it's not very useful.

>
> 2) Your lexer does not provide any information about positions of tokens in
>   the source code. You may want to do that in order to:
>
>   a) report better error messages
>   b) use parsec's `token` function [1] to make parsec work with your tokens.
>      Note that parsec wants you to use its data type `SourcePos` to represent
>      positions. See [2] for a simple example and further stuff.
>
> [1]: http://legacy.cs.uu.nl/daan/download/parsec/parsec.html#token
> [2]: http://legacy.cs.uu.nl/daan/download/parsec/parsec.html#SeperateScanners

That's for phase 2... :). Actually I was planning on adding that in
later. Thanks a lot for the links, I'll have a look at them.


Thanks a lot for your feedback,

Patrick

>
> Sincerely,
>   Jan.
>
> On Fri, May 08, 2009 at 09:53:04PM -0400, Patrick LeBoutillier wrote:
>> Hi all,
>>
>> In the process of writing an SQL parser I started by writing a lexer.
>> The code can be found here:
>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=4736#a4736
>>
>> You can run it like this in ghci:
>>
>> Prelude SQL.Lexer> runLexer "select * from TABLE order by FIELD"
>> [Token Reserved "select",Token Space " ",Token Operator "*",Token
>> Space " ",Token Reserved "from",Token Space " ",Token Identifier
>> "TABLE",Token Space " ",Token Reserved "order",Token Space " ",Token
>> Reserved "by",Token Space " ",Token Identifier "FIELD"]
>>
>> Since this is pretty much my first Haskell project over 10 lines long,
>> I'm looking for some feedback of any kind.
>> Ultimately I would like to use this lexer to build a functional SQL
>> parser using Parsec.
>>
>>
>> Thanks,
>>
>> Patrick
>>
>> --
>> =====================
>> Patrick LeBoutillier
>> Rosemère, Québec, Canada
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>
>
> --
> Heriot-Watt University is a Scottish charity
> registered under charity number SC000278.
>
>



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


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

Message: 5
Date: Mon, 11 May 2009 07:13:36 -0700
From: Michael Mossey <[email protected]>
Subject: [Haskell-beginners] defining 'init' in terms of 'foldr'
To: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

In S. Thompson's book, problem 9.13 asks us to define 'init' in terms of 
foldr. I was baffled at first because I didn't see a natural way to do 
this. It would look something like

init xs = foldr f initialValue xs

where f would cons on each character except the rightmost.

f <when passed rightmost char> b = []
f <when passed any other char a> b = a : b

How does f "know" when it is passed the first character? initialValue has 
to signal this somehow. On #haskell, one person suggested doing it with 
some post-processing:

init xs = snd $ foldr f (True,[]) xs
   where f _  (True,_)  = (False,[])
         f a  (False,b) = (False,a:b)

I had an idea. If the initial value is the entire list, then its length can 
function as the "signal" that we are dealing with the rightmost char. This 
requires no post-processing:

init xs = foldr f xs xs
    where f a b | length b == length xs = []
                | otherwise = a:b

These seem contrived. I wonder if there is a more natural solution that 
Thompson had in mind. Any comments?

-Mike



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

Message: 6
Date: Mon, 11 May 2009 14:03:44 -0700
From: Haroldo Stenger <[email protected]>
Subject: Re: [Haskell-beginners] SQL Lexer
To: Patrick LeBoutillier <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

patrick,

i was wondering if parts of the code could be more abstract.
(i'm no genius in that area)
but how about using some high order function for the numeric literal or the
alpohanumeric literal?

maybe a lexer is a hand-wise algorithm, but maybe it can be streched somehow
:-)

comments?

best regards

haroldo

2009/5/8 Patrick LeBoutillier <[email protected]>

> Hi all,
>
> In the process of writing an SQL parser I started by writing a lexer.
> The code can be found here:
> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=4736#a4736
>
> You can run it like this in ghci:
>
> Prelude SQL.Lexer> runLexer "select * from TABLE order by FIELD"
> [Token Reserved "select",Token Space " ",Token Operator "*",Token
> Space " ",Token Reserved "from",Token Space " ",Token Identifier
> "TABLE",Token Space " ",Token Reserved "order",Token Space " ",Token
> Reserved "by",Token Space " ",Token Identifier "FIELD"]
>
> Since this is pretty much my first Haskell project over 10 lines long,
> I'm looking for some feedback of any kind.
> Ultimately I would like to use this lexer to build a functional SQL
> parser using Parsec.
>
>
> Thanks,
>
> Patrick
>
> --
> =====================
> Patrick LeBoutillier
> Rosemère, Québec, Canada
> _______________________________________________
> 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/20090511/1d87cc00/attachment-0001.html

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

Message: 7
Date: Mon, 11 May 2009 20:39:30 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Performance of function defined in a
        'where' clause
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Sun, May 10, 2009 at 04:33:12PM +0100, Kevin Haines wrote:
> I used -O.

Well, -O2 is almost always much better than -O.  (And -O3 is worse, or
at least used to be.  Don't ask why.)

-Brent


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

Message: 8
Date: Tue, 12 May 2009 05:55:24 +0200
From: Chadda? Fouch? <[email protected]>
Subject: Re: [Haskell-beginners] A Quantity Type - Integer without the
        Negative #'s
To: aditya siram <[email protected]>
Cc: Magnus Therning <[email protected]>, [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

2009/5/9 aditya siram <[email protected]>:
> Cool, that's really interesting! So is it accurate to say "predicated"
> datatypes [1] such as Int and String are provided by Haskell but you cannot
> create them or specialize on a subset of them? And there are really only two
> types of datatypes, tags [2] and the "predicated" types. Compound datatypes
> are just a combination of the two.
>
> -deech
>
>
> [1] By predicated I mean a datatype that would actually cause a compiler
> error ( not a runtime error ) if a method returned an out-of-bounds value.
> [2] By  tags I mean the data constructors, but I find it easier to think of
> them as tags because they can appear alone, eg. data Coins = Penny | Nickel
> | Dime | Quarter
> where nothing is being constructed.


I don't see where the "predicated datatype" differs from the tags type
: Int could as well be implemented as a "data Int = 0 | 1 | 2 |..."
(sparing consideration about characters authorized in a tag), String
isn't primitive at all, in fact it's just a list of characters.... You
can easily create them. To specialize on a subset of them is very easy
too, you can use newtype or data and create a smart constructor, as
well as appropriate instances. The only problem is that it is pretty
hard to get compile time guarantee on some of them but no other
classic language provides more guarantee : the only languages that can
do better are those that have dependant types (Agda, Coq, Epigram...)
and as you'll know if you tried them they're frequently harder to use
than Haskell.

NB : You can use Template Haskell to get some compile-time errors for
the constants of your code.
-- 
Jedaï


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

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


End of Beginners Digest, Vol 11, Issue 10
*****************************************

Reply via email to