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.  Diagrams brain twister (Adrian May)
   2. Re:  Unmaybe (Adrian May)
   3. Re:  How to improve lazyness of a foldl (and memory
      footprint) (Giacomo Tesio)
   4.  Please help with this basic lexical analyzer program,
      implemented using the "Alex" tool (Costello, Roger L.)


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

Message: 1
Date: Wed, 15 May 2013 11:06:28 +0800
From: Adrian May <[email protected]>
Subject: [Haskell-beginners] Diagrams brain twister
To: "[email protected]" <[email protected]>
Message-ID:
        <cad-ubzhqjnwwsuvyma_wehq3mu_vqjxjpqoinjvgf-zcyqo...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi all,

I'm trying to draw a picture with diagrams (this isn't the gantt chart I
was talking about before.)

I have a load of objects strewn around a diagram according to their own
sweet logic, and for *some* of them, I want to draw a horizontal line going
from the right hand edge of the object to some globally fixed x coordinate,
call it the "margin". So those lines are all different lengths because the
objects are all over the place, but their right-hand ends should all be
aligned vertically.

This seems quite hard, because that sweet logic is already quite
complicated and local to a set of objects in the immediate neighbourhood of
the object in question. Somehow I have to tease out a selection of them and
process each of them into this line whose properties depend on where the
object is from the global perspective.

But how?

Adrian.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130515/001125ad/attachment-0001.htm>

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

Message: 2
Date: Wed, 15 May 2013 11:28:02 +0800
From: Adrian May <[email protected]>
Subject: Re: [Haskell-beginners] Unmaybe
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <cad-ubzhqnycj3ekebaemv2gye-43nfqz1gupw8o8fgvg2qu...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Actually, my data model with one list of tasks and another list of
dependencies could get very tedious. For the example picture I posted, I
could write something like:

openbox >> ( readmanual <|> ( attachwires >> plugin >> turnon ) ) >> use

but I'd be in trouble if, say, there was something else that could start
after "attachwires" but had no other relationships to any other tasks and
would run on into the "use" era. Is there any kind of super-monad that
could express that?

It's the same problem as trying to decompose an asymmetrical Wheatstone
Bridge into serial and parallel sub-networks. Is there any solution to that?

Adrian.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130515/efbe2975/attachment-0001.htm>

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

Message: 3
Date: Wed, 15 May 2013 09:35:34 +0200
From: Giacomo Tesio <[email protected]>
Subject: Re: [Haskell-beginners] How to improve lazyness of a foldl
        (and memory footprint)
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <CAHL7psHNzVGNbXddvQzafkZSRH8kp8LdC=fA9P25q7=v75w...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thanks a lot!

Yesterday on freenode's #haskell channel Cane noted how my laziness problem
reside in the foldl use in foldTradingSample.
I have to turn it into a foldr (but I'm still unsure how...)


Giacomo


On Wed, May 15, 2013 at 12:46 AM, Henk-Jan van Tuyl <[email protected]>wrote:

> On Tue, 14 May 2013 11:22:27 +0200, Giacomo Tesio <[email protected]>
> wrote:
>
>  Hi, I'm trying to improve a small haskell program of mine.
>>
> :
>
> Some remarks:
>
> 0) Use hlint (available on Hackage) for improvement suggestions
> 1) You don't have to write the module heading in Main.hs, it is not a
> library (why export main?)
> 2) Change "print" to "putStrLn" if you want to display messages without
> quotes
> 2) switchArgs is only partially defined, add something like:
>      switchArgs [x] = putStrLn $ "Unknown tool: " ++ x
> 3) Use shorter lines, for example change:
>
>   importTrades outDir csvFile = transformFile csvFile (foldTradingSample.*
> *getTickWriteTrades)   (saveTradingSamples outDir)
>
> to:
>
>   importTrades outDir csvFile =
>     transformFile
>       csvFile
>       (foldTradingSample.**getTickWriteTrades)
>       (saveTradingSamples outDir)
> 4) It is considered good practice, to write the function
>    composition operator between spaces (change f.g to f . g)
>
> I have analyze your software further to see how sufficient laziness can be
> reached.
>
> Regards,
> Henk-Jan van Tuyl
>
>
> --
> Folding@home
> What if you could share your unused computer power to help find a cure? In
> just 5 minutes you can join the world's biggest networked computer and get
> us closer sooner. Watch the video.
> http://folding.stanford.edu/
>
>
> http://Van.Tuyl.eu/
> http://members.chello.nl/**hjgtuyl/tourdemonad.html<http://members.chello.nl/hjgtuyl/tourdemonad.html>
> Haskell programming
> --
>
> ______________________________**_________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/**mailman/listinfo/beginners<http://www.haskell.org/mailman/listinfo/beginners>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130515/4952d730/attachment-0001.htm>

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

Message: 4
Date: Wed, 15 May 2013 09:44:19 +0000
From: "Costello, Roger L." <[email protected]>
Subject: [Haskell-beginners] Please help with this basic lexical
        analyzer program, implemented using the "Alex" tool
To: "[email protected]" <[email protected]>
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="us-ascii"

Hi Folks,

I am learning how to use the Haskell lexical analyzer tool called "Alex" [1].

I am trying to implement a lexical analyzer for this string (an email "From:" 
header):

        From: "John Doe" <[email protected]>

I want to break it up into this list of tokens:

[
  From,
  DisplayName "John Doe",
  Email,
  LocalName "john",
  Domain "doe.org"
]

Below is my implementation. It works fine if the string doesn't contain a 
display name. That is, this works fine:

let s = "From: <[email protected]>"
alexScanTokens s

However, when I include a display name, I get this error message:

[From*** Exception: lexical error

That is, this results in an error:

let s = "From: \"John Doe\" <[email protected]>"
alexScanTokens s

I am guessing that this part of my "Alex" program is causing the error:

\"[a-zA-Z ]+\"          { \s -> DisplayName (init (tail s)) }

In Alex the left side is a regular expression:

        \"[a-zA-Z ]+\"

and the right side is the action to be taken when a string is found that 
matches the regular expression:

        { \s -> DisplayName (init (tail s)) }

Any thoughts on what the problem might be?

Here is my lexical analyzer program:
-------------------------------------------------
{
module Main (main) where
}

%wrapper "basic"

$digit = 0-9                    -- digits
$alpha = [a-zA-Z]               -- alphabetic characters

tokens :-

  $white+                               ;
  From:                                 { \s -> From }
  \"[a-zA-Z ]+\"                                { \s -> DisplayName (init (tail 
s)) }
  \<                                            { \s -> Email }
  [$alpha]+@                            { \s -> LocalPart (init s) }
  [$alpha\.]+>                          { \s -> Domain (init s) }

{
-- Each action has type :: String -> Token

-- The token type:
data Token =
        From                    |
        DisplayName String      |
        Email                   |
        LocalPart String        |
        Domain String           
        deriving (Eq,Show)

main = do
  s <- getContents
  print (alexScanTokens s)
}
-------------------------------------------------            
[1] The "Alex" lexical analyzer tool may be found at this URL: 
http://www.haskell.org/alex/doc/html/introduction.html



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

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


End of Beginners Digest, Vol 59, Issue 15
*****************************************

Reply via email to