Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/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: Noobie attempt to process log output into dependency
graph (John Lusk)
2. Re: Noobie attempt to process log output into dependency
graph (Imants Cekusins)
3. Re: Noobie attempt to process log output into dependency
graph (Magnus Therning)
4. Re: Noobie attempt to process log output into dependency
graph (John Lusk)
----------------------------------------------------------------------
Message: 1
Date: Thu, 15 Dec 2016 08:44:08 -0500
From: John Lusk <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Noobie attempt to process log output
into dependency graph
Message-ID:
<CAJQkMbYKtjMRTPRWJpn7qnRHy-XavHXoFad0=svyxmo6nvf...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I have not, but I might. This was a little work project that I've now run
out of time for.
I was really hoping for a deeper discussion of state management than "just
use this package." This seems kind of like receiving a stream of inputs
from a user and needing to keep track of several items of state that are
changing independently (as opposed to the neat problems usually used in
basic FP education).
Should I be taking a more monadic approach?
On Thu, Dec 15, 2016 at 5:17 AM, Magnus Therning <[email protected]>
wrote:
>
> John Lusk <[email protected]> writes:
>
> > Hi, all,
> [.. cut ..]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
> If I understand you correctly you want to parse a set of lines and keep
> track of indentation. This is not entirely unlike parsing a programming
> language where indentation is significant, like Haskell :) Is that
> correct?
>
> A quick look at Hackage gives several libs with combinators dealing with
> indentaion-aware parsers. Have you looked at any of them?
>
> /M
>
> --
> Magnus Therning OpenPGP: 0x927912051716CE39
> email: [email protected] jabber: [email protected]
> twitter: magthe http://therning.org/magnus
>
> For a successful technology, reality must take precedence over public
> relations, for nature cannot be fooled.
> — R.P. Feynman
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20161215/d7b257bb/attachment-0001.html>
------------------------------
Message: 2
Date: Thu, 15 Dec 2016 16:18:37 +0100
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Noobie attempt to process log output
into dependency graph
Message-ID:
<CAP1qinYS2Q73kM0-W-aEEHNvPYXS=4c3ajvgqv2fnr24ago...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
> https://github.com/JohnL4/DependencyGraph
A graph library of your choice + State monad would do the trick.
e.g.: fgl Data-Graph-Inductive-Monad
<https://hackage.haskell.org/package/fgl-5.5.3.0/docs/Data-Graph-Inductive-Monad.html>
Or you could store Graph state in an MVar and work as you would with
stateful approach
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20161215/3c53a00f/attachment-0001.html>
------------------------------
Message: 3
Date: Thu, 15 Dec 2016 20:38:37 +0100
From: Magnus Therning <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Noobie attempt to process log output
into dependency graph
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
John Lusk <[email protected]> writes:
> I have not, but I might. This was a little work project that I've now run
> out of time for.
>
> I was really hoping for a deeper discussion of state management than
> "just use this package." This seems kind of like receiving a stream of
> inputs from a user and needing to keep track of several items of state
> that are changing independently (as opposed to the neat problems
> usually used in basic FP education).
>
> Should I be taking a more monadic approach?
Well, we have to start somewhere :)
Anyway, you don't necessarily have to resort to the state monad. I
believe, based you your other code that you quite easily can go from
your list of lines to a list of `(Int, String)`, where the integer
indicates the indentation level. Then you can look at `Data.Tree` (in
containers) and `Data.Tree.Zipper` (in rosezipper) to build your tree.
This is my quick hack:
~~~
buildTree _ zipPos [] = zipPos
buildTree n zipPos xx@((lvl, s):xs)
| lvl > n =
let newZipPos = children zipPos
node = Node s []
in buildTree lvl (insert node newZipPos) xs
| lvl == n =
let newZipPos = nextSpace zipPos
node = Node s []
in buildTree lvl (insert node newZipPos) xs
| lvl < n =
let (Just newZipPos) = parent zipPos
in buildTree (n - 1) newZipPos xx
~~~
With the following definitions in place:
~~~
ils = [ (1, "The root")
, (2, "Child 1")
, (3, "Child 1.1")
, (4, "Child 1.1.1")
, (3, "Child 1.2")
, (2, "Child 2")
]
zipRoot = fromTree $ Node "absolute top" []
~~~
I build the tree, and print it, like this:
~~~
putStrLn $ drawTree $ toTree $ buildTree 0 zipRoot ils
top
|
`- The root
|
+- Child 1
| |
| +- Child 1.1
| | |
| | `- Child 1.1.1
| |
| `- Child 1.2
|
`- Child 2
~~~
Whether this is usable for you depends a lot on how big your logs are, I
suppose.
If this was something that I'd keep around for a while I'd probably
look into rewriting `buildTree` so that it would fit for use with
`mapAccumL`.
/M
--
Magnus Therning OpenPGP: 0x927912051716CE39
email: [email protected] jabber: [email protected]
twitter: magthe http://therning.org/magnus
The British have "the perfect temperament to be hackers—technically
skilled, slightly disrespectful of authority, and just a touch of
criminal behavior".
— Mary Ann Davidson, Oracle's Security Chief
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20161215/9a653ef6/attachment-0001.sig>
------------------------------
Message: 4
Date: Thu, 15 Dec 2016 16:09:49 -0500
From: John Lusk <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Noobie attempt to process log output
into dependency graph
Message-ID:
<CAJQkMbYdWNgRe=x46LqXZ0oFZ9BkzaaqpvQqhvcryW=q2ms...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Thanks, all, that gives me something to chew on.
It occurred to me (during my 45-minute commute to work) that all Haskell
programs (listen to the noob <eyeroll/>) have the following structure
(modulo my fractured syntax):
main :: IO()
main = do
inputs <- getInputs
doOutput $ f inputs initialState
f :: [input] -> state -> outputs
f [] state =
transformToOutputs state
f (input:inputs) state =
f inputs (newState state input)
doOutput :: [output] -> IO()
doOutput outputs = do
putStr $ unlines outputs
So all I have to do is write newState and I'm good! ^_^
(transformToOutputs will, of course, be a snap.)
Right?
John.
On Thu, Dec 15, 2016 at 2:38 PM, Magnus Therning <[email protected]>
wrote:
>
> John Lusk <[email protected]> writes:
>
> > I have not, but I might. This was a little work project that I've now run
> > out of time for.
> >
> > I was really hoping for a deeper discussion of state management than
> > "just use this package." This seems kind of like receiving a stream of
> > inputs from a user and needing to keep track of several items of state
> > that are changing independently (as opposed to the neat problems
> > usually used in basic FP education).
> >
> > Should I be taking a more monadic approach?
>
> Well, we have to start somewhere :)
>
> Anyway, you don't necessarily have to resort to the state monad. I
> believe, based you your other code that you quite easily can go from
> your list of lines to a list of `(Int, String)`, where the integer
> indicates the indentation level. Then you can look at `Data.Tree` (in
> containers) and `Data.Tree.Zipper` (in rosezipper) to build your tree.
>
> This is my quick hack:
>
> ~~~
> buildTree _ zipPos [] = zipPos
> buildTree n zipPos xx@((lvl, s):xs)
> | lvl > n =
> let newZipPos = children zipPos
> node = Node s []
> in buildTree lvl (insert node newZipPos) xs
> | lvl == n =
> let newZipPos = nextSpace zipPos
> node = Node s []
> in buildTree lvl (insert node newZipPos) xs
> | lvl < n =
> let (Just newZipPos) = parent zipPos
> in buildTree (n - 1) newZipPos xx
> ~~~
>
> With the following definitions in place:
>
> ~~~
> ils = [ (1, "The root")
> , (2, "Child 1")
> , (3, "Child 1.1")
> , (4, "Child 1.1.1")
> , (3, "Child 1.2")
> , (2, "Child 2")
> ]
>
> zipRoot = fromTree $ Node "absolute top" []
> ~~~
>
> I build the tree, and print it, like this:
>
> ~~~
> putStrLn $ drawTree $ toTree $ buildTree 0 zipRoot ils
> top
> |
> `- The root
> |
> +- Child 1
> | |
> | +- Child 1.1
> | | |
> | | `- Child 1.1.1
> | |
> | `- Child 1.2
> |
> `- Child 2
> ~~~
>
> Whether this is usable for you depends a lot on how big your logs are, I
> suppose.
>
> If this was something that I'd keep around for a while I'd probably
> look into rewriting `buildTree` so that it would fit for use with
> `mapAccumL`.
>
> /M
>
> --
> Magnus Therning OpenPGP: 0x927912051716CE39
> email: [email protected] jabber: [email protected]
> twitter: magthe http://therning.org/magnus
>
> The British have "the perfect temperament to be hackers—technically
> skilled, slightly disrespectful of authority, and just a touch of
> criminal behavior".
> — Mary Ann Davidson, Oracle's Security Chief
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20161215/0d9a5275/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 102, Issue 8
*****************************************