Can someone post some simple examples of using the Data.Graph library?
So I can define a simple graph
let g = buildG (1,2) [(1,2), (2,1)]
but how do i label my edges and nodes? i want to be able to name my
nodes, and add weights to the edges and be able to update those
weights as well.
Thanks,
Hi,
I have a list of index-value pairs and I want to get a list which is sorted
by the index and which contains index-wise sums of all the values.
Here is a function that does this (and a bit more).
---
pixelHistogram samples = let
index s t = let
x = round $ (fromIntegral imageWidth)
Hello Lauri,
Friday, May 16, 2008, 12:19:29 PM, you wrote:
pixelArray :: Array Int Color
it's boxed array which means that its elements are stored as thunks
computed only when you actually use them. try UArray instead:
http://haskell.org/haskellwiki/Modern_array_libraries
--
Best
On Thu, 2008-05-15 at 21:04 -0400, Olivier Boudry wrote:
I tried to place a length text `seq` before the mapM_ writeExport to
force the process output to be read but the result was even worst
(only one line printed). Apparently withtout the `evaluate` function
it causes more troubles than it
A couple of days ago I had need for:
concatM :: Monad m = [m [a]] - m [a]
concatM = liftM concat . sequence
but found no such thing in the std libs, except perhaps for msum (I
don't want to add instances for MonadPlus. Should I have to?). Have I
missed something trivial?
Alistair
Hello Alistair,
Friday, May 16, 2008, 2:12:45 PM, you wrote:
concatM = liftM concat . sequence
but found no such thing in the std libs, except perhaps for msum (I
don't want to add instances for MonadPlus. Should I have to?). Have I
missed something trivial?
1. it's easy to define yourself
I don't know how Haskell should behave on this. Consider this function:
elemOf (x,y) = (x,y) `elem` [ (a,b) | a - [0..], b - [0..] ]
If I try to query elemOf (1,1), the program keeps searching and searching
but it never makes it. But if I query elemOf (0,1) (or anything as long as
the first
Thanks for help. I did some tests with UArray and it does the trick.
The problem remaining is, how to implement UArray Int (Double, Double,
Double)?
UArray source code is far too cryptic for me.
Regards,
Lauri
On Fri, May 16, 2008 at 11:37 AM, Bulat Ziganshin [EMAIL PROTECTED]
wrote:
Hello
On Fri, May 16, 2008 at 04:42:31AM -0700, leledumbo wrote:
I don't know how Haskell should behave on this. Consider this function:
elemOf (x,y) = (x,y) `elem` [ (a,b) | a - [0..], b - [0..] ]
If I try to query elemOf (1,1), the program keeps searching and searching
but it never makes it.
It's not exactly a question of Haskell's behaviour. The list [ (a,b) | a -
[0..], b - [0..] ]
is such that apart from pairs starting with zero, no other pair is
associated with a finite index. In other words, [ (a,b) | a - [0..], b -
[0..] ] is not a correct 'enumeration' of all pairs of
Hello Lauri,
Friday, May 16, 2008, 3:44:19 PM, you wrote:
impossible. you can try parallel arrays
Thanks for help. I did some tests with UArray and it does the trick.
The problem remaining is, how to implement UArray Int (Double, Double,
Double)?
UArray source code is far too cryptic for
Hi,
I'm new to this, but I'll give it a shot.
import Data.Graph.Inductive
There are several ways to build a graph. Let's say, node labels are 'String's
and edge labels are 'Double's. Edge labels would be the weights.
grs :: [Gr String Double]
The below four lines generate the same graph.
Thanks again. Here is my solution in case that somebody else runs into
similar problem. This isn't very elegant and I would be interested to know
if somebody has a better solution. Surely many people have encountered this
kind of problem where you want to force evaluation of some expression at
On Fri, May 16, 2008 at 07:58:40AM -0400, Dan Doel wrote:
On Friday 16 May 2008, leledumbo wrote:
I don't know how Haskell should behave on this. Consider this function:
elemOf (x,y) = (x,y) `elem` [ (a,b) | a - [0..], b - [0..] ]
FYI: The control-monad-omega package on hackage.haskell.org
On Fri, 16 May 2008, David Roundy wrote:
On Fri, May 16, 2008 at 07:58:40AM -0400, Dan Doel wrote:
On Friday 16 May 2008, leledumbo wrote:
I don't know how Haskell should behave on this. Consider this function:
elemOf (x,y) = (x,y) `elem` [ (a,b) | a - [0..], b - [0..] ]
FYI: The
On Fri, 16 May 2008, Lauri Oksanen wrote:
Thanks for help. I did some tests with UArray and it does the trick.
The problem remaining is, how to implement UArray Int (Double, Double, Double)?
Maybe an (UArray (Int,Int) Double) could help, where the second index
range is fixed to (0,2).
Lauri Oksanen [EMAIL PROTECTED] writes:
Thanks for help. I did some tests with UArray and it does the trick.
The problem remaining is, how to implement UArray Int (Double, Double,
Double)?
As (UArray Int Double, UArray Int Double, UArray Int Double).
Or as UArray Int Double, but with a
Yes, of course. How blind of me. Here is one more question.
If you change IOUArray to IOArray and add $! in front of the two summations
in the previous code, it still works correctly.
But can you do similar trick with Array and accumArray? I have tried to put
$! in different places in the first
Hello Ketil,
Friday, May 16, 2008, 5:27:29 PM, you wrote:
I guess it would be possible to have UArray Int (# Double, Double,
Double #) - packing all three Doubles unboxed into the array, but I've
no clue how to go about automating that.
unoxed tuple doesn't have a box so it cannot be
Hello Lauri,
Friday, May 16, 2008, 5:45:50 PM, you wrote:
Yes, of course. How blind of me. Here is one more question.
If you change IOUArray to IOArray and add $! in front of the two
summations in the previous code, it still works correctly.
But can you do similar trick with Array and
All,
I've made my first code drop for a new project I'm working on (though
it's really an extension of work I've been doing for about 5 years).
Information and code can be found at
http://code.haskell.org/ChessLibrary/ . Comments and suggestions
warmly welcomed. Also, I'm looking for an
Where can I find the sources of the latest WASH? I couldn't find them in
HackageDB (and neither with Google).
--
Immanuel Normann
2008/3/6 Lars Viklund [EMAIL PROTECTED]:
On Wed, Mar 05, 2008 at 10:52:07AM -0800, Bryan O'Sullivan wrote:
Jonathan Gardner wrote:
There's also WASH, but that
Seems to be close to
sequence :: [ListT m a] - ListT m a
Hmm?
On 16 May 2008, at 14:12, Alistair Bayley wrote:
A couple of days ago I had need for:
concatM :: Monad m = [m [a]] - m [a]
concatM = liftM concat . sequence
but found no such thing in the std libs, except perhaps for msum (I
All,
Apologies for multiple listings.
It's that time again. Our growing cadre of functionally-minded north
westerners
is meeting at the
The Seattle Public Library
*University Branch* 5009 Roosevelt Way N.E. *Seattle*, WA 98105 206-684-4063
from 18:30 - 20:00 on May 28th.
Note the change
test.l (line 7, column 1):
unexpected end of input
expecting (, Lambda abstraction, Let binding, Atom, end of input or
Function application
I obviously don't know anything about Parsec's inner workings. I'm
going to investigate as soon as I stopped despairing.
--
(c) this sig last receiving
Oops, I was very wrong. Sorry.
On 16 May 2008, at 20:13, Miguel Mitrofanov wrote:
Seems to be close to
sequence :: [ListT m a] - ListT m a
Hmm?
On 16 May 2008, at 14:12, Alistair Bayley wrote:
A couple of days ago I had need for:
concatM :: Monad m = [m [a]] - m [a]
concatM = liftM
Thank you, that's exactly what i was looking for.
I don't think there is a straightforward way to tweak individual nodes and
edges other than using graph construction tools. Maybe someone could shed a
light on this.
I think i can define updateEdge in terms of insEdge and delEdge
You'd have to write a wrapper that implements an array of triples
as a triple of arrays. This isn't too hard.
There's a new library in the works that should make this a lot easier
-- Don
abhay.parvate:
As far as I know, you can't. It needs machine representable types, such as
Int,
Duncan Coutts wrote:
On Thu, 2008-05-15 at 01:01 +0400, Bulat Ziganshin wrote:
Hello Andrew,
Thursday, May 15, 2008, 12:49:32 AM, you wrote:
touch. Now, let's see what this IDE actually looks li-- oh you have GOT
to be KIDDING me! It can't find the right GTK DLL?!?
gtk2hs
Achim Schneider wrote:
test.l (line 7, column 1):
unexpected end of input
expecting (, Lambda abstraction, Let binding, Atom, end of input or
Function application
I obviously don't know anything about Parsec's inner workings. I'm
going to investigate as soon as I stopped despairing.
Don Stewart wrote:
I've written an extended post on how to understand and reliably optimise
code like this, looking at it all the way down to the assembly.
The result are some simple rules to follow for generated code as good
as gcc -O2.
Enjoy,
Andrew Coppin wrote:
Janis Voigtlaender wrote:
http://wwwtcs.inf.tu-dresden.de/~voigt/mpc08.pdf
It is well-known that trees with substitution form a monad.
...OK, I just learned something new. Hanging around Haskell Cafe can
be so illuminating! :-)
Now, if only I could actually comprehend
andrewcoppin:
Don Stewart wrote:
I've written an extended post on how to understand and reliably optimise
code like this, looking at it all the way down to the assembly.
The result are some simple rules to follow for generated code as good
as gcc -O2.
Enjoy,
Hello Andrew,
Friday, May 16, 2008, 10:56:36 PM, you wrote:
On the other hand, this is the anti-theisis of Haskell. We start with a
high-level, declarative program, which performs horribly, and end up
with a manually hand-optimised blob that's much harder to read but goes
way faster.
Andrew Coppin wrote:
On the other hand, this is the anti-theisis of Haskell. We start with a
high-level, declarative program, which performs horribly, and end up
with a manually hand-optimised blob that's much harder to read but goes
way faster.
Buh? This is hard to read?
mean n m = go 0 0
Bryan O'Sullivan wrote:
Andrew Coppin wrote:
On the other hand, this is the anti-theisis of Haskell. We start with a
high-level, declarative program, which performs horribly, and end up
with a manually hand-optimised blob that's much harder to read but goes
way faster.
Buh? This is
Andrew Coppin [EMAIL PROTECTED] wrote:
Wait... unexpected end of input; expecting [...] end of input [...]
That's just *wrong*...! ;-)
But don't despaire - show us your parser and what it's supposed to
parse, and I'm sure somebody [maybe even me] will be able to tell you
what's up.
Andrew Coppin wrote:
Bryan O'Sullivan wrote:
Andrew Coppin wrote:
On the other hand, this is the anti-theisis of Haskell. We start with a
high-level, declarative program, which performs horribly, and end up
with a manually hand-optimised blob that's much harder to read but goes
way faster.
Don Stewart wrote:
I don't understand what's ugly about:
go s l x | x m = s / fromIntegral l
| otherwise = go (s+x) (l+1) (x+1)
And the point is that it is *reliable*. If you make your money day in, day out
writing Haskell, and you don't want to rely on radical
apfelmus wrote:
Andrew Coppin wrote:
Look closer: it's hardER to read.
mean xs = sum xs / fromIntegral (length xs)
mean = go 0 0 n
where
go s l x
| x m = s / fromIntegral l
| otherwise = go (s+x) (l+1) (x+1
One version makes it instantly clear, at a glance, what is
Am Freitag, 16. Mai 2008 21:33 schrieb Achim Schneider:
Andrew Coppin [EMAIL PROTECTED] wrote:
Wait... unexpected end of input; expecting [...] end of input [...]
That's just *wrong*...! ;-)
But don't despaire - show us your parser and what it's supposed to
parse, and I'm sure
On Fri, 16 May 2008, Achim Schneider wrote:
Andrew Coppin [EMAIL PROTECTED] wrote:
Wait... unexpected end of input; expecting [...] end of input [...]
That's just *wrong*...! ;-)
But don't despaire - show us your parser and what it's supposed to
parse, and I'm sure somebody
On Fri, 16 May 2008, Philippa Cowderoy wrote:
Confusing, isn't it? It's almost the right message, too. I'm pretty sure
the misbehaviour's because eof doesn't consume - see what happens if you
put an error message on all of whiteSpace?
It is indeed, and because the error merging code can't
Daniel Fischer [EMAIL PROTECTED] wrote:
[very helpful stuff]
Please, please don't ask me for the rationale of using eof like
this, you would get the same answer as if you'd ask me why I cast a
stone into the sea.
And why did you do that?
To cast away something I don't understand.
--
Philippa Cowderoy [EMAIL PROTECTED] wrote:
On Fri, 16 May 2008, Achim Schneider wrote:
Guess who ran into that with a separate token for
layout-inserted braces?
It can't be me, as I attempted to be as lazy as possible, not going for
a tokenising pass, and ended up being too lazy.
--
(c)
Andrew Coppin [EMAIL PROTECTED] wrote:
But yeah, I get the point. Everybody wants me to be quiet and go
away. So I'll go be quiet now...
Yes and no. Everybody wants you to be quiet and go to your study,
writing a compiler that's Smart Enough(tm). We will let you out as soon
as you're finished
On Fri, 16 May 2008, Achim Schneider wrote:
Philippa Cowderoy [EMAIL PROTECTED] wrote:
On Fri, 16 May 2008, Achim Schneider wrote:
Guess who ran into that with a separate token for
layout-inserted braces?
It can't be me, as I attempted to be as lazy as possible, not going for
a
Achim Schneider wrote:
Andrew Coppin [EMAIL PROTECTED] wrote:
But yeah, I get the point. Everybody wants me to be quiet and go
away. So I'll go be quiet now...
Yes and no. Everybody wants you to be quiet and go to your study,
writing a compiler that's Smart Enough(tm). We will let
Philippa Cowderoy [EMAIL PROTECTED] wrote:
On Fri, 16 May 2008, Achim Schneider wrote:
Philippa Cowderoy [EMAIL PROTECTED] wrote:
On Fri, 16 May 2008, Achim Schneider wrote:
Guess who ran into that with a separate token for
layout-inserted braces?
It can't be me, as I
On Fri, 16 May 2008, Don Stewart wrote:
I don't understand what's ugly about:
go s l x | x m = s / fromIntegral l
| otherwise = go (s+x) (l+1) (x+1)
I suspect you've been looking at low-level code too long. How about the
total lack of domain concepts?
On Fri, 16 May 2008, Achim Schneider wrote:
My problem is that realTopLevel = expr, and that I get into an infinite
recursion, never closing enough parens, never hitting eof.
Have you run into the left-recursion trap, by any chance?
This doesn't work:
expr = do expr; ...
You can cover
On Fri, 16 May 2008, Andrew Coppin wrote:
Obviously most people would prefer to write declarative code and feel secure
that the compiler is going to produce something efficient.
Ultimately the only way to do this is to stick to Einstein's advice - make
things as simple as possible but no
Andrew Coppin [EMAIL PROTECTED] writes:
I'm more worried about what happens in less trivial examples. [Let's
face it, who wants to compute the sum of the numbers from 1 to N?]
Inspired by Don's blog post, and coincidentally working on a program
where profiling points to one particular, short
ketil:
Andrew Coppin [EMAIL PROTECTED] writes:
I'm more worried about what happens in less trivial examples. [Let's
face it, who wants to compute the sum of the numbers from 1 to N?]
Inspired by Don's blog post, and coincidentally working on a program
where profiling points to one
On Fri, May 16, 2008 at 12:03 PM, Andrew Coppin
[EMAIL PROTECTED] wrote:
Since a tree is a kind of container, yes, it should be a monad. [I'm still
not really sure whether it's useful.]
Not so much containers in general, but 'flattenable' containers. You
can flatten a list of lists to a list
Ketil Malde wrote:
mkAnn :: ByteString - Annotation
mkAnn = pick . B.words
where pick (_db:up:rest) = pick' up $ getGo rest
pick' up' (go:_:ev:_) = Ann (B.copy up') (read $ B.unpack go) (read $
B.unpack ev)
getGo = dropWhile (not . B.isPrefixOf (pack GO:))
It seems at
Dan Weston wrote:
Ketil Malde wrote:
mkAnn :: ByteString - Annotation
mkAnn = pick . B.words
where pick (_db:up:rest) = pick' up $ getGo rest
pick' up' (go:_:ev:_) = Ann (B.copy up') (read $ B.unpack
go) (read $ B.unpack ev)
getGo = dropWhile (not . B.isPrefixOf (pack
Philippa Cowderoy [EMAIL PROTECTED] wrote:
On Fri, 16 May 2008, Achim Schneider wrote:
My problem is that realTopLevel = expr, and that I get into an
infinite recursion, never closing enough parens, never hitting
eof.
Have you run into the left-recursion trap, by any chance?
This
Dan Weston [EMAIL PROTECTED] writes:
mkAnn :: ByteString - Annotation
mkAnn = pick . B.words
where pick (_db:up:rest) = pick' up $ getGo rest
pick' up' (go:_:ev:_) = Ann (B.copy up') (read $ B.unpack go)
(read $ B.unpack ev)
getGo = dropWhile (not . B.isPrefixOf
On Sat, 17 May 2008, Achim Schneider wrote:
There's at least one token before any recursion, so I guess not. After
all, it terminates. It's my state that does not succeed in directing
the parser not to mess up, so I'm reimplementing the thing as a
two-pass but stateless parser now.
In most
Philippa Cowderoy [EMAIL PROTECTED] wrote:
On Sat, 17 May 2008, Achim Schneider wrote:
Definitely the easier and clearer
thing to do: I can have an end of line token that carries the
number of trailing spaces, so I got perfect indent information
without any pain involved, at all, and
Hi,
To learn alex and happy, I'm trying to write a parser for a simple
expression language.
When I wrote my own lexer and just used happy, it was fine.
When I used the basic wrapper of alex it was also fine. However, when
I use the posn wrapper
to get position information, I get a strange
Hello,
I am running ghc and tools on Ubuntu. I seem to be running into very
strange problems between ghc-pkg and the Ubuntu package manager. Suddenly
runhaskell Setup.hs configure just stops working ... Are any other
ghc/Ubuntu users running into problems? If so, please tell me what
ghc-pkg list gives me
[EMAIL PROTECTED]:~$ ghc-pkg list
/usr/local/lib/ghc-6.8.2/package.conf:
Cabal-1.2.3.0, GLUT-2.1.1.1, HUnit-1.2.0.0, OpenGL-2.2.1.1,
QuickCheck-1.1.0.0, array-0.1.0.0, base-3.0.1.0,
bytestring-0.9.0.1, cgi-3001.1.5.1, containers-0.1.0.1,
Dan Piponi-2 wrote:
In fact, you can use the Reader monad as a fixed size container monad.
Interesting that you say that. Reader seems to me more as an anti-container
monad.
--
View this message in context:
65 matches
Mail list logo