[Haskell-cafe] Happy outputs "parE" - ideas on what to change in my .y file?

2007-01-27 Thread Mark Wassell
Sometimes happy outputs 'parE' when I run it on my .y file? I believe it 
is coming from a part of Grammer.lhs which has the comment line


"This bit is a real mess, mainly because of the error message support."

Are there any suggestions on what to change in my .y file to get over this?

Thanks

Mark
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type infer

2007-01-27 Thread David House

On 26/01/07, Marco Túlio Gontijo e Silva <[EMAIL PROTECTED]> wrote:

But if I can't write this type signature without -fglasgow-exts, I
thought that it couldn't infer this type. For me it's strange that it's
ok to have a very generic function if I don't have a type signature, but
if I write it the function will not be so generic. Shouldn't it infer
only types that could be written?


It doesn't really infer the types of put/get at runtime; it pulls them
from the interface file for Control.Monad.State, which _was_ built
with -fglasgow-exts. Hence SPJ mentioning that it was more of a UI bug
than a typing bug.

--
-David House, [EMAIL PROTECTED]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] getting started with hsc (supercollider)

2007-01-27 Thread alex

Hi all,

I'm trying to get started on using Rohan Drape's Hsc library, excited
about the prospect of parsing things straight into synthesis graphs, but
progress is slow.  There is good library documentation with examples,
but no overview of how things fit together that I can find.  Would
anyone have some illustrative example code, and perhaps a couple of tips
for how to get things working well in emacs?

Once I get up to speed I would hope to contribute a beginner's guide
back.  Perhaps I should be addressing this email just to Rohan, but
thought others might be able to help.

alex


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Channel9 Interview: Software Composability and the Future of Languages

2007-01-27 Thread Jacques Carette

Tim Newsham wrote:

 I have to write:

  > do {
  >x <- getSomeNum
  >y <- anotherWayToGetANum
  >return (x + y)
  > }

even if the computation of x and y are completely independant of
each other.


I too have really missed a "parallel composition" operator to do 
something like the above.  Something like


do {
   { x <- getSomeNum || y <- anotherWayToGetANum}
   return (x+y)
}

Actually, that syntax is rather hideous.  What I would _really_ like to 
write is

do {
   (x,y) <- getSomeNum || anotherWayToGetANum
   return (x+y)
}

I would be happy to tell Haskell explicitly that my computations are 
independent (like the above), to expose parallelization opportunities.  
Right now, not only can I NOT do that, I am forced to do the exact 
opposite, and FORCE sequentiality.


Jacques
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Channel9 Interview: Software Composability and the Future of Languages

2007-01-27 Thread Chris Kuklewicz
Jacques Carette wrote:
> Tim Newsham wrote:
>>  I have to write:
>>
>>   > do {
>>   >x <- getSomeNum
>>   >y <- anotherWayToGetANum
>>   >return (x + y)
>>   > }
>>
>> even if the computation of x and y are completely independant of
>> each other.
> 
> I too have really missed a "parallel composition" operator to do
> something like the above.  Something like
> 
> do {
>{ x <- getSomeNum || y <- anotherWayToGetANum}
>return (x+y)
> }
> 
> Actually, that syntax is rather hideous.  What I would _really_ like to
> write is
> do {
>(x,y) <- getSomeNum || anotherWayToGetANum
>return (x+y)
> }
> 
> I would be happy to tell Haskell explicitly that my computations are
> independent (like the above), to expose parallelization opportunities. 
> Right now, not only can I NOT do that, I am forced to do the exact
> opposite, and FORCE sequentiality.
> 
> Jacques

What is wanted is a specific relation of the ordering required by the Monad's
structure.  For pure computation Control.Parallel.Strategies may be helpful.  If
what was wanted was to keep sequencing but lose binding then the new
Control.Applicative would be useful.

It almost looks like we want your pair combinator:

do { (x,y) <- parallelPair getSomeNum anotherWayToGetANum
 return (x+y)
   }

This is principled only in a Monad that can supply the same "RealWorld" to both
operations passed to parallelPair.  After they execute, this same "RealWold" is
the context for the "return (x+y)" statement.

This ability to run three computations from the same "RealWorld" seems (nearly)
identical to backtracking in a nondeterministic monad, which is usually exposed
by a MonadPlus instance.

The use of pairs looks alot like the arrow notation.  And
parallelPair a b = a &&& b
looks right for arrows.  And since monads are all arrows this works, but Kleisli
implies ordering like liftM2.

For a specific Monads you can write instances of a new class which approximate
the semantics you want.

> import Control.Arrow
> import Data.Char
> import Control.Monad
> import Control.Monad.State
> import System.IO.Unsafe
> 
> type M = State Int
> 
> main = print $ runState goPar 65 -- should be ((65,'A'),65)
> 
> opA :: (MonadState Int m) => m Int
> opA = do i <- get
>  put (10+i)
>  return i
> 
> opB :: (MonadState Int m) => m Char
> opB = do i <- get
>  put (5+i)
>  return (chr i)
> 
> goPar :: State Int (Int,Char)
> goPar = opA `parallelPair` opB
> 
> class (Monad m) => MonadPar m where
>   parallelPair :: m a -> m b -> m (a,b)
> 
> instance MonadPar (State s) where
>   parallelPair a b = do s <- get
> let a' = evalState a s
> b' = evalState b s
> return (a',b')
> 
> -- No obvious way to run the inner monad (without more machinery),
> -- so we have to resort to ordering
> instance (Monad m) => MonadPar (StateT s m) where
>   parallelPair a b = do s <- get
> a' <- lift $ evalStateT a s
> b' <- lift $ evalStateT b s
> return (a',b')
> 
> -- Reader and Writer work like State
> 
> -- Use unsafeInterleaveIO to make a and b lazy and unordered...
> instance MonadPar IO where
>   parallelPair a b = do a' <- unsafeInterleaveIO a
> b' <- unsafeInterleaveIO b
> return (a',b')
>
> k :: State Int b -> Kleisli (State Int) a b
> k op = Kleisli (const op)
>
> runK :: Kleisli (State Int) a a1 -> (a1, Int)
> runK kop = runState (runKleisli kop undefined) 65
>
> go :: State Int a -> (a,Int)
> go op = runK (k op)
>
> kab :: Kleisli (State Int) a (Int, Char)
> --kab = k opA &&& k opB
> kab = proc x -> do
> a <- k opA -< x
> b <- k opB -< x
> returnA -< (a,b)
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Trouble understanding records and existential types

2007-01-27 Thread Roberto Zunino

Brian Hulley wrote:

Chris Kuklewicz wrote:

This is how I would write getLeaves, based on your GADT:


data IsLeaf
data IsBranch

newtype Node = Node { getNode :: (forall c. ANode c) }

[snip]

Thanks Chris - that's really neat!
I see it's the explicit wrapping and unwrapping of the existential that 
solves the typechecking problem,


Actually, Node is universally quantified. This makes it not inhabitated 
given the ANode GADT.  So, you can consume a Node, but you can not 
produce a non-bottom one.


Existential quantification version:

data IsLeaf
data IsBranch

data Node = forall c . Node ( ANode c )

data ANode :: * -> * where
Branch :: String -> String -> (ANode a,ANode b) -> [Node] -> ANode 
IsBranch

Leaf :: String -> String -> ANode IsLeaf

getLeaves :: ANode a -> [ANode IsLeaf]
getLeaves (Branch _ _ (l1,l2) rest) = getLeaves l1 ++ getLeaves l2 ++
  concatMap getLeaves' rest
getLeaves x@(Leaf {}) = [x]

getLeaves' :: Node -> [ANode IsLeaf]
getLeaves' (Node x) = getLeaves x


Regards,
Zun.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Channel9 Interview: Software Composability and the Future of Languages

2007-01-27 Thread Robert Dockins
On Friday 26 January 2007 22:14, Tim Newsham wrote:
> > impractical language, only useful for research. Erik Meijer at one point
> > states that programming in Haskell is too hard and compares it to
> > assembly programming!
>
> He brings up a very good point.  Using a monad lets you deal with
> side effects but also forces the programmer to specify an exact
> ordering.  This *is* a bit like making me write assembly language
>
> programming.  I have to write:
>> do {
>>x <- getSomeNum
>>y <- anotherWayToGetANum
>>return (x + y)
>> }
>
> even if the computation of x and y are completely independant of
> each other.  Yes, I can use liftM2 to hide the extra work (or
> fmap) but I had to artificially impose an order on the computation.
> I, the programmer, had to pick an order.

Humm.  While I can accept that this is a valid criticism of Haskell's monadic 
structure for dealing with I/O, I fail to see how it could drive a decision 
to prefer an imperative language like C#, where every statement has this 
property (overspecification of evaluation order).  The only mainstream-ish 
general-purpose language I know of that I know of that attempts to addresses 
this problem head-on is Fortress.  (Although, to be honest, I don't know 
enough about Fortress to know how it handles I/O to even know if it is an 
actual improvement over the situation in Haskell.)


> Ok, maybe "assembly language" is a bit extreme (I get naming, allocation
> and garbage collection!) but it is primitive and overspecifies the
> problem.
>
> Tim Newsham
> http://www.thenewsh.com/~newsham/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: proposal: HaBench, a Haskell Benchmark Suite

2007-01-27 Thread David Roundy
On Fri, Jan 26, 2007 at 05:25:13PM +, Chris Kuklewicz wrote:
> > I agree that common libraries like ByteString need to be well
> > represented, but the original request additionally included programs
> > that are representative of applications. A ray-tracer (even with a fixed
> > scene and only one type of scene primitive) is a fairly nice
> > approximation of a real numerical batch-oriented application while still
> > being small enough to understand and modify. I expect thats why Jo
> > chose it as his benchmark application in the first place.
> 
> Writing numeric code that processes Doubles is hard to optimize.  See the
> shootout example for the n-body problem:

I agree that numerics and Doubles are very important, but am of the opinion
that we'll be better off if we (try to?) restrict ourselves to code that is
really used by someone who really cares about performance enough to
optimize it.  Mostly because if the benchmark suite is going to serve as a
useful guide for compiler optimization writers, it needs to reflect the
performance of code that at least *someone* cares about.

Artificial benchmarks all too often can be improved by artificial
optimizations that only benefit artificial benchmarks.  e.g. the famous
specmark log(sqrt(x)) optimization (which is equal to 0.5*log(x), but no
decent programmer would ever write that code, and it's a special case the
compiler shouldn't bother looking for).
-- 
David Roundy
http://www.darcs.net
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANNOUNCE: binary: high performance, pure binary serialisation

2007-01-27 Thread Henning Thielemann

On Sat, 27 Jan 2007, Donald Bruce Stewart wrote:

> lemming:
> > 
> > On Fri, 26 Jan 2007, Donald Bruce Stewart wrote:
> > 
> > > 
> > > Binary: high performance, pure binary serialisation for Haskell
> > >  
> > > -- 
> > > 
> > > The Binary Strike Team is pleased to announce the release of a new,
> > > pure, efficient binary serialisation library for Haskell, now available
> > > from Hackage:
> > > 
> > >  tarball:
> > > http://hackage.haskell.org/cgi-bin/hackage-scripts/package/binary/0.2
> > >  darcs:  darcs get http://darcs.haskell.org/binary
> > >  haddocks:   http://www.cse.unsw.edu.au/~dons/binary/Data-Binary.html
> > 
> > I want to write out data in the machine's endianess, because that data 
> > will be post-processed by sox, which reads data in the machine's 
> > endianess. Is this also planned for the package?
> 
> The underlying Get and Put monads support explicit endian writes and
> reads, which you can add to your instances explicitly:
> 
> http://www.cse.unsw.edu.au/~dons/binary/Data-Binary-Get.html#5
> http://www.cse.unsw.edu.au/~dons/binary/Data-Binary-Put.html#5
> 
> So you can do that now. 

Of course, I can check for the machine's endianess, then decide whether to
use putWord16be and putWord16le. But I assume that it is more efficient,
if there would be some function putWord16native, which writes out in the
machine's native endianess.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Channel9 Interview: Software Composability andth eFu ture of Languages

2007-01-27 Thread Steve Schafer
On Fri, 26 Jan 2007 22:00:11 +0100, you wrote:

>I agree, but I think it should be pointed out that primarily it is not
>Haskell which is hard, it is Programming which is. Haskell only reflects
>this better than the mainstream imperative languages.

That's very true. Writing good software is hard, regardless of the
choice of language. Perhaps what sets Haskell apart is that, unlike most
languages, it also makes writing _bad_ software hard. ;)

Steve Schafer
Fenestra Technologies Corp.
http://www.fenestra.com/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Channel9 Interview: Software Composability and t heFu ture of Languages

2007-01-27 Thread Steve Schafer
On Fri, 26 Jan 2007 22:01:09 -0600, you wrote:

>You have a PhD in computer science from Princeton, so your measure of
>what's "hard" and what isn't in this regard is nearly worthless.
>
>I find it incredibly insulting for you to assert that people who
>complain about Haskell's difficulty are too lazy and aren't really
>interested in a better solution. Maybe they just don't want to have to
>take graduate-level classes in category theory to get their job done.
>Maybe they want a solution that meets them half-way, one that doesn't
>require that they understand how to build their own resistors and
>capacitors in order to make their TV work again (to use your analogy).
>That's what Meijer means when he says that Haskell is too hard.

I never said that people are lazy, only that they're not
interested--they'd rather devote their time to other pursuits. That's
not meant to be a criticism at all, it's an observation of The Way
Things Work. And I certainly wasn't referring to the people who actually
_complain_ about Haskell being too hard. After all, they're the ones who
are in fact trying to learn, not the ones who simply don't care to. My
comment was directed specifically at the notion that we can make Haskell
more popular by somehow making it easier. _That's_ the argument that I
believe is flawed, because the things that give value to Haskell are
precisely the things that require effort to understand. To paraphrase
Albert Einstein: make it as simple as possible, but no simpler.

This is not just a progrmaming issue; I encounter the same phenomenon
pretty much everywhere: I'm currently trying to build a house, and I've
found that most of the people who are in the business of building houses
don't want to try anything new, even if it might be a better way that
has the potential to save them money and/or result in a better end
product. They want to continue building houses the way they've always
built houses. The fraction of house builders who do want to learn new
and possibly better ways of building is, and always will be, a small
one. Again, it's not a criticism, just an observation, something that
one needs to be aware of when embarking on a house-building project.

I'm reminded of when Java first appeared on the scene a little over ten
years ago. There was a huge upswell in interest; all of the web
developers out there were going to add Java applets to their web sites.
Then the awful truth came out: Oops, you had to learn how to _program_
to create applets. Never mind; not worth it. And applets quickly and
quietly faded away.

By the way, to set the record straight, while I do have a Ph.D. from
Princeton, it's in semiconductor physics, not computer science. And lest
anyone were to misunderstand when I say Haskell is hard, while I do mean
that it's hard for _me_, I think the evidence is pretty strong that I'm
far from alone in my assessment. Whether or not it's hard for any
particular person is up to that individual to judge, of course. I stick
with Haskell because (a) I think it just might be worth it, and (b) I
can't help myself--I have an insatiable craving for new knowledge.

Steve Schafer
Fenestra Technologies Corp.
http://www.fenestra.com/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Channel9 Interview: Software Composability and the Future of Languages

2007-01-27 Thread Tim Newsham

Humm.  While I can accept that this is a valid criticism of Haskell's monadic
structure for dealing with I/O, I fail to see how it could drive a decision
to prefer an imperative language like C#, where every statement has this
property (overspecification of evaluation order).


True.. perhaps his objection was related to having a bulky syntax (one 
line per action, if one is not using a higher order function to combine 
actions) rather than having an order of evaluation rule in the language

and letting the programmer (mostly) ignore it (sometime to is own
peril).

Tim Newsham
http://www.thenewsh.com/~newsham/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Simple HTTP lib for Windows?

2007-01-27 Thread Neil Mitchell

Hi Alistair,


> Is there a simple way to get the contents of a webpage using Haskell on a
> Windows box?

This isn't exactly what you want, but it gets you partway there. Not
sure if LineBuffering or NoBuffering is the best option. Line
buffering should be fine for just text output, but if you request a
binary object (like an image) then you have to read exactly the number
of bytes specified, and no more.


This works great for haskell.org, unfortunately it doesn't work as
well with the rest of the web universe.

With www.google.com I get: Program error: : IO.hGetChar:
illegal operation

With www.slashdot.org I get: 501 Not Implemented returned

www.msnbc.msn.com works fine.

Any ideas why? Are there any alternatives to read in a file off the
internet (i.e. wget but as a library)

Thanks

Neil
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Simple HTTP lib for Windows?

2007-01-27 Thread Daniel McAllansmith
On Sunday 28 January 2007 09:14, Neil Mitchell wrote:
> Hi Alistair,
>
> > > Is there a simple way to get the contents of a webpage using Haskell on
> > > a Windows box?
> >
> > This isn't exactly what you want, but it gets you partway there. Not
> > sure if LineBuffering or NoBuffering is the best option. Line
> > buffering should be fine for just text output, but if you request a
> > binary object (like an image) then you have to read exactly the number
> > of bytes specified, and no more.
>
> This works great for haskell.org, unfortunately it doesn't work as
> well with the rest of the web universe.
>
> With www.google.com I get: Program error: : IO.hGetChar:
> illegal operation
>
> With www.slashdot.org I get: 501 Not Implemented returned
>
> www.msnbc.msn.com works fine.
>
> Any ideas why? 

At the very least it's missing the HTTP version on the request line, and you 
almost always need to send a Host header.

For a start you could try changing client to:

client server port page = do
  h <- connectTo server (PortNumber port)
  hSetBuffering h NoBuffering
  putStrLn "send request"
  hPutStrLn h ("GET " ++ page ++ " HTTP/1.1\r")
  hPutStrLn h ("Host: " ++ server ++ "\r")
  hPutStrLn h "\r"
  hPutStrLn h "\r"
  putStrLn "wait for response"
  readResponse h
  putStrLn ""

Note that I haven't tried this, or the rest of Alistair code at all, so the 
usual 30 day money back guarantee doesn't apply.  It certainly won't handle 
redirects.


> Are there any alternatives to read in a file off the 
> internet (i.e. wget but as a library)

The http library sort of works most of the time, but there are several bugs 
that cause it to fail on many 'in the wild' webservers.

HXT has a wrapper around a command line invocation of cURL.  It works better.  
There is still a problem with redirects, but thats an easy enough fix.
I doubt that it would be very easy to extract it from the surrounding HXT 
framework though.
It would be nice to have a binding to libcurl.

Daniel
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANNOUNCE: binary: high performance, pure binary serialisation

2007-01-27 Thread Duncan Coutts
On Sat, 2007-01-27 at 19:11 +0100, Henning Thielemann wrote:
> On Sat, 27 Jan 2007, Donald Bruce Stewart wrote:

> > The underlying Get and Put monads support explicit endian writes and
> > reads, which you can add to your instances explicitly:
> > 
> > http://www.cse.unsw.edu.au/~dons/binary/Data-Binary-Get.html#5
> > http://www.cse.unsw.edu.au/~dons/binary/Data-Binary-Put.html#5
> > 
> > So you can do that now. 
> 
> Of course, I can check for the machine's endianess, then decide whether to
> use putWord16be and putWord16le. But I assume that it is more efficient,
> if there would be some function putWord16native, which writes out in the
> machine's native endianess.

Note that actually taking advantage of aligned word reads/writes is not
especially simple since one has to guarantee alignment. So that means no
byte writes, everything, chars, bools, record tags would have to be word
sized. While it's not so hard to arrange alignment for writes (since we
get to allocate the buffers) for reads we have no guarantee since the
user supplies the byte string input and they could have uses say 'tail'
so the data may be all unaligned. Dealing with both aligned and
unaligned makes it more complex.

We did a performance experiment with this and found that it gained us
very little. There are bigger performance bottlenecks at the moment than
the penalty of always doing byte reads/writes.

Duncan

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Simple HTTP lib for Windows?

2007-01-27 Thread Neil Mitchell

Hi Daniel


Note that I haven't tried this, or the rest of Alistair code at all, so the
usual 30 day money back guarantee doesn't apply.  It certainly won't handle
redirects.


Thanks, it certainly gets more things, but has a nasty habit of taking
a very long time in Hugs on certain URLs:

research.microsoft.com/, www.cs.york.ac.uk/

And on some urls, ie http://research.microsoft.com/~simonpj/, it still
ends up with IO.hGetChar: illegal operation

Any ideas why?

Thanks

Neil
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: ANNOUNCE: binary: high performance, pure binary serialisation

2007-01-27 Thread Duncan Coutts
On Fri, 2007-01-26 at 15:40 +0100, Arie Peterson wrote:
> Hello,
> 
> 
> Donald Bruce Stewart wrote:
> 
> > Ok, I forgot one point. It is possible to automatically derive instances
> > of Binary for your custom types, if they inhabit Data and Typeable,
> > using an SYB trick. Load tools/derive/BinaryDerive.hs into ghci, and
> > bring your type into scope, then run:
> >
> > *Main> mapM_ putStrLn . lines $ derive (undefined :: Drinks)
> 
> It would seem that one needs to rerun the script every time the type is
> changed. That would be unfortunate. Perhaps I could have a go at writing a
> template haskell function to derive those instances?
> 
> I also fear that the existing script does not handle types with more than
> 256 constructors correctly. While uncommon, those are not unrealistic.

Feel free to send in a patch. All it needs to do is check if there are
more than 2^8 constructors and if so encode the tag in a Word16 rather
than Word8.

Duncan

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: ANNOUNCE: binary: high performance, pure binary serialisation

2007-01-27 Thread Neil Mitchell

Hi


> I also fear that the existing script does not handle types with more than
> 256 constructors correctly. While uncommon, those are not unrealistic.

Feel free to send in a patch. All it needs to do is check if there are
more than 2^8 constructors and if so encode the tag in a Word16 rather
than Word8.


I've already fixed this and sent some new code to you. As long as you
have less than 4 billion constructors you should be fine now.

Thanks

Neil
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ANN: regex-tdfa 0.56

2007-01-27 Thread Chris Kuklewicz
Greetings,

  My new regular expression backend "regex-tdfa" is passing all the tests I have
been throwing at it, so it is time to share the good news.

First up: Where is it? Version 0.56 is in my "stable" location at
> darcs get --partial darcs.haskell.org:/home/darcs/packages/regex-tdfa
The version that will get updated and broken more often is "unstable" at
> darcs get --partial 
> darcs.haskell.org:/home/darcs/packages/regex-unstable/regex-tdfa

It needs a slightly updated regex-base package (version >= 0.80) at
> darcs get --partial 
> darcs.haskell.org:/home/darcs/packages/regex-unstable/regex-base

It has only been tested (on Max OS X) with GHC 6.6 and depends on base >= 2.0
for Data.ByteString, Data.ByteString.Lazy, and Data.Sequence.

** What does regex-tdfa do?

  It runs POSIX regular expression searches correctly.  No other regular
expression backend for Haskell does this correctly.  The regular expression can
be chosen to be from a String, ByteString, ByteString.Lazy, or (Data.Seq Char).
 Independent of that choice the searched text can also be any of those types.

** Properties and benefits of regex-tdfa:

  It follows a known standard: POSIX. (If you find that it disagrees with the
standard then I will fix it.)

  It is written in Haskell, so there is no C library to compile and install.
Though it is currently only written for GHC 6.6, it could be ported to any other
compiler with only minor changes.  (I expect that if you drop the polymorphic
MPTC interface of regex-base it could be made Haskell98).

  It works with Unicode since it can be used on [Char] (and it works if there
are '\NUL' characters around).

  It is lazy in the regular expression: it only builds the DFA if you use it,
and only builds the state it needs, which are memoized in a lazy Trie.

  It is lazy in the searched text, and the pure function that searches the text
only evaluates the text until the next match is done and does not hold onto the
initial text.  Thus you could efficiently search a [Char] up to the size of the
Position type, which is an Int for now.

  It is free, the regex-tdfa library is under a BSD-3 license.

** Does it work?

  Yes.

  The regex-posix backend that come with GHC does not run all the searches
correctly: it is buggy (example at end of announcement).  And the regex-posix
backend is also impossibly slow -- the slowest backend by far -- orders of
magnitude slower.  The regex-tre backend that wraps the TRE library has exposed
this very fast library to the harsh gaze of QuickCheck.  The lesson from
QuickCheck is to never use regex-tre because the TRE library (version 0.7.4) is
buggy.

  For regex-tdfa backend I took/stole ideas from Ville Laurikari's Master thesis
which describes the algorithm that TRE uses.  And I made a pure Haskell
implementation that now passes all the tests at
http://www.research.att.com/~gsf/testregex/testregex.html and follows the notes
at http://www.research.att.com/~gsf/testregex/re-interpretation.html
and passes those tests as well.  And it "passes" QuickCheck tests which actually
just compare the answers that regex-posix, regex-tre, and regex-tdfa since I do
not have a bug free reference implementation to compare against.

** Why the name TDFA?

  Tagged Deterministic Finite Automata.  The Tagged part is from Ville
Laurikari's thesis work.

** Speed:

  If you do not care only about the match as a whole and not about subexpression
matching then you can set the captureGroups ExecOption to False:

makeMyRegex = makeRegex defaultCompOpt myExecOpt
  where myExecOpt = defaultExecOpt { captureGroups = False }

And redefine (=~) and (=~~) to use makeMyRegex instead of makeRegex:

(=~) :: (RegexMaker Regex CompOption ExecOption source,RegexContext Regex
source1 target) => source1 -> source -> target
(=~) s r = let re = makeMyRegex r :: Regex in match re s

(=~~) :: (RegexMaker Regex CompOption ExecOption source,RegexContext Regex
source1 target,Monad m)=> source1 -> source -> m target
(=~~) s r = let re = makeMyRegex r :: Regex in match re s

The benefit to this is speed, as it then proceeds to run all matches of
"b(..?c)?d" against a large test file *faster* than the the TRE C library
backend.  My compliments to those who worked on ghc and -O2.  It even runs
nearly as fast as regex-dfa in this mode.  Thus regex-dfa is (mostly) obsolete.

If you use the default and capture the subgroups then the speed is reduced by a
factor of about 4.  This is because of the very simple data structures that keep
track of the run time state.  I intend to improve this aspect of the design now
that I have a working algorithm.

I have not benchmarked the speed of compiling the regular expression from the
String. This compiling is done with very lazy data structures, so the DFA size
is really only as big as you actually explore while running the match.

** Examples of bugs in regex-posix and regex-tre:

An example for regex-posix:

> *Main> "ab" Posix.=~ "((a)|(b)){2,}" :: MatchArray
> array (0,3

Re: [Haskell-cafe] ANNOUNCE: binary: high performance, pure binary serialisation

2007-01-27 Thread Donald Bruce Stewart
lemming:
> 
> On Sat, 27 Jan 2007, Donald Bruce Stewart wrote:
> 
> > lemming:
> > > 
> > > On Fri, 26 Jan 2007, Donald Bruce Stewart wrote:
> > > 
> > > > 
> > > > Binary: high performance, pure binary serialisation for Haskell
> > > >  
> > > > -- 
> > > > 
> > > > The Binary Strike Team is pleased to announce the release of a new,
> > > > pure, efficient binary serialisation library for Haskell, now available
> > > > from Hackage:
> > > > 
> > > >  tarball:
> > > > http://hackage.haskell.org/cgi-bin/hackage-scripts/package/binary/0.2
> > > >  darcs:  darcs get http://darcs.haskell.org/binary
> > > >  haddocks:   http://www.cse.unsw.edu.au/~dons/binary/Data-Binary.html
> > > 
> > > I want to write out data in the machine's endianess, because that data 
> > > will be post-processed by sox, which reads data in the machine's 
> > > endianess. Is this also planned for the package?
> > 
> > The underlying Get and Put monads support explicit endian writes and
> > reads, which you can add to your instances explicitly:
> > 
> > http://www.cse.unsw.edu.au/~dons/binary/Data-Binary-Get.html#5
> > http://www.cse.unsw.edu.au/~dons/binary/Data-Binary-Put.html#5
> > 
> > So you can do that now. 
> 
> Of course, I can check for the machine's endianess, then decide whether to
> use putWord16be and putWord16le. But I assume that it is more efficient,
> if there would be some function putWord16native, which writes out in the
> machine's native endianess.

Ah yes, I actually did have the putWord*native in the code at one point,
in my branch for doing aligned-only writes. The speed up wasn't
signficant so I didn't commit it, but the host-order primitives are useful, so
will appear in the next version of the library.

-- Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: getting started with hsc (supercollider)

2007-01-27 Thread Rohan Drape
Hello Alex,

alex <[EMAIL PROTECTED]> writes:
| Would anyone have some illustrative example code, and perhaps a
| couple of tips for how to get things working well in emacs?

Noting that Hsc is still experimental and not completely nailed down,
though I think now quite close, and assuming that SuperCollider and
ghc and emacs and the standard haskell emacs mode [1] are all
installed and working, the following should get you started.

* get hsc, or update if you have it (important, recent fixes required)

  darcs get http://slavepianos.org/rd/sw/sw-69

* compile it

  cd sw-69
  runhaskell Setup.hs configure --prefix ~
  runhaskell Setup.hs build
  runhaskell Setup.hs install --user

  (or there is a Makefile to do these three steps...)

* add an appropriately modified variant of the following to ~/.emacs

  (push "/home/rohan/sw/sw-69/emacs" load-path)
  (setq hsc-interpreter "ghci")
  (setq hsc-help-directory "/home/rohan/sw/sw-69/Help/")
  (require 'hsc)

* start the supercollider server

  scsynth -u 57110

That ought to be the end of premilinaries, this message is a 'literate
SuperCollider Haskell file', save it with a .lhs extension, open it in
emacs, make sure the Hsc menu comes up and read on.

You can start ghci and load Sound.SC3 by typing C-cC-s (Hsc -> Haskell
-> Start haskell).

If the ghci output window becomes obscured you can see it again by
typing C-cC-g (Hsc -> Haskell -> See output).

The SuperCollider convention is that ordinary graph nodes are placed
in a group with identifier 1, this node is not created when scsynth
starts, so initially we will have to make it.

The simplest way is to run the following line, and the simplest way to
run a line is to put point on the line and type C-cC-c (Hsc ->
Expression -> Run line).

> withSC3 reset

Doing this is so common there is a keybinding for it, C-cC-k (Hsc ->
SCSynth -> Reset scsynth).

To make a test sound run the following:

> audition (sinOsc AR 440 0 * 0.1)

This ought to play a quiet sine oscillator at A440.

To see the server status type C-cC-w (Hsc -> SCSynth -> Display
status).

To stop the sound reset the server, ie. type C-cC-k.

For expressions that don't fit on one line select the region and type
C-cC-e (Hsc -> Expression -> Run region).  This writes the region in a
do block in a main procedure to a temporary file [2], loads the file
and then runs main.

> let f = sinOsc AR (xLine KR 1 1000 9 RemoveSynth) 0 * 200 + 800
> audition (sinOsc AR f 0 * 0.1)

(To select a region use the mouse or place point at one end, type
C-Space and move point to the other end.)

To find help on a UGen or on a SuperCollider server command put point
over the identifier and type C-cC-h (Hsc -> Help -> Hsc help).  This
opens the help file, which ought to have working examples in it, the
above graph is in the sinOsc help file.

To stop ghci type C-cC-x (Hsc -> Haskell -> Quit haskell).

It may have been a mistake to just use .lhs as the extension, however
it is not a disaster because the Hsc mode is a derivative of the
haskell mode.  Perhaps it ought to be changed to .hsc.

Hope this is clear-ish, please send through any questions, bug reports
or patches!

Regards,
Rohan

[1] To get this loaded I have the following in ~/.emacs:

  (push "~/ext/src/haskell/fptools/fptools/CONTRIB/haskell-modes/emacs" 
load-path)
  (load "haskell-site-file.el")  
  (add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
  (add-hook 'haskell-mode-hook 'turn-on-haskell-indent)
  (add-hook 'haskell-mode-hook 'turn-on-haskell-ghci)))

[2] The file is written to /tmp/hsc.lhs, the preamble imports
the following modules, this is enough to run the help file 
examples.

import Sound.OpenSoundControl
import Sound.SC3
import Control.Monad
import System.Random

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Channel9 Interview: Software Composability and theFu ture of Languages

2007-01-27 Thread Brandon S. Allbery KF8NH


On Jan 26, 2007, at 23:01 , Collin Winter wrote:


You have a PhD in computer science from Princeton, so your measure of
what's "hard" and what isn't in this regard is nearly worthless.


Uh, I don't have a degree, and discussions about mathy stuff like  
category theory generally go flying way over my head.  Somehow I  
still managed to learn Haskell and seem to be getting fairly good at it.


--
brandon s. allbery[linux,solaris,freebsd,perl] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon universityKF8NH



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] State of OOP in Haskell

2007-01-27 Thread Alexy Khrabrov

Well, I'm thinking in terms of OOD/OOA/OOP -- Design, Architecture,
Programming.  That's about the only way to model a bog system.  Say I
have a stock market model -- I'll have a database of tickers, a
simulator to backtest things, a trading strategy, etc.

Do Haskell modules provide enough encapsulation to design a system in
terms of them?  What are the design/architecture units in Haskell if
not OO-based?

Cheers,
Alexy

On 1/27/07, Donald Bruce Stewart <[EMAIL PROTECTED]> wrote:

deliverable:
> ...In the tradition of the "letters of an ignorant newbie"...
>
> What's the consensus on the OOP in Haskell *now*?  There're some
> libraries such as OOHaskell, O'Haskell, and Haskell~98's own qualified
> type system with inheritance.
>
> If I have GHC, which way to do anything OOP-like is considered "right"
> today?

Using existentials and typeclasses to do some OO things wouldn't be
considered unidiomatic (particularly, using existentials to package up
interfaces to values).

In general though, using a functional approach will produce better
(simpler) Haskell code, and make it more likely others will understand it.
Personally, I run in fear from OO Haskell ;)

Concrete examples of when you think you need an OO feature might be
useful, so people can discuss the more FP solutions to the same problem.

Cheers,
  Don


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] State of OOP in Haskell

2007-01-27 Thread Alexy Khrabrov

...In the tradition of the "letters of an ignorant newbie"...

What's the consensus on the OOP in Haskell *now*?  There're some
libraries such as OOHaskell, O'Haskell, and Haskell~98's own qualified
type system with inheritance.

If I have GHC, which way to do anything OOP-like is considered "right" today?

Cheers,
Alexy
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] State of OOP in Haskell

2007-01-27 Thread Donald Bruce Stewart
deliverable:
> ...In the tradition of the "letters of an ignorant newbie"...
> 
> What's the consensus on the OOP in Haskell *now*?  There're some
> libraries such as OOHaskell, O'Haskell, and Haskell~98's own qualified
> type system with inheritance.
> 
> If I have GHC, which way to do anything OOP-like is considered "right" 
> today?

Using existentials and typeclasses to do some OO things wouldn't be
considered unidiomatic (particularly, using existentials to package up
interfaces to values).

In general though, using a functional approach will produce better
(simpler) Haskell code, and make it more likely others will understand it.
Personally, I run in fear from OO Haskell ;)

Concrete examples of when you think you need an OO feature might be
useful, so people can discuss the more FP solutions to the same problem.

Cheers,
  Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] State of OOP in Haskell

2007-01-27 Thread Donald Bruce Stewart
deliverable:
> Well, I'm thinking in terms of OOD/OOA/OOP -- Design, Architecture,
> Programming.  That's about the only way to model a bog system.  Say I
> have a stock market model -- I'll have a database of tickers, a
> simulator to backtest things, a trading strategy, etc.
> 
> Do Haskell modules provide enough encapsulation to design a system in
> terms of them?  What are the design/architecture units in Haskell if
> not OO-based?

Haskell's pretty big on encapsulation (we like our strong statically
checked guarantees after all)

Some of the encapsulation mechanisms used in large (>5k loc up to 100k +
Haskell programs I've hacked on):

modules
qualified modules
type classes to specify generic interfaces
existential types to hide implementations completely (and statically)
existentials using typeclasses to package the interface
monads for state/effect encapsulation
abstract data types
data types with smart constructors
first class modules via existentials 
purity 
laziness

So the same kind of encapsulation as OO stuff provides (existentials are
essentially OO objects), and a few more besides. Monads in particular
are perfect for encapsulating interesting effects, and having that
encapsulation statically enforced.

Probably some of the OO refugees can think of other mechanisms.

Cheers,
   Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] State of OOP in Haskell

2007-01-27 Thread Alexy Khrabrov

What about this OOHaskell:

http://homepages.cwi.nl/~ralf/OOHaskell/

-- how is it received in the café?  :)

Cheers,
Alexy
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Channel9 Interview: Software Composability and theFu ture of Languages

2007-01-27 Thread Frederick Ross

On 1/26/07, Collin Winter <[EMAIL PROTECTED]> wrote:

I find it incredibly insulting for you to assert that people who
complain about Haskell's difficulty are too lazy and aren't really
interested in a better solution. Maybe they just don't want to have to
take graduate-level classes in category theory to get their job done.
Maybe they want a solution that meets them half-way, one that doesn't
require that they understand how to build their own resistors and
capacitors in order to make their TV work again (to use your analogy).
That's what Meijer means when he says that Haskell is too hard.


I have an odd background in programming (never took a compsci class,
did take a graduate computational physics course in my first year of
undergrad, taught by an old nuclear physicist, who used nothing but
Forth...beat that for bizarre), but since physicists represent an
interesting conglomeration of snapshots of the mainstream of
programming through the ages, I do have a bit of an archaeological
perspective on how people think about "hard."  In case the following
seems far fetched, let me assure you that four years ago I worked in a
high energy physics group on a codebase of a few hundred thousand
lines of FORTRAN 77, with no documentation.  It had GOTOs.  The folks
working on this regarded C as a newfangled, difficult language, and
some of them were still writing FORTRAN IV or RATFOR.

So here's my completely anecdotal view of the history of "hard" in
programming: In the beginning there was GOTO.  Well, actually there
was machine language, then assembler, but we'll skip that.  GOTO was
king.  And then there was this movement among the ivory tower computer
scientists called "structured programming."  It was considered
difficult and complicated, with lots of hard concepts.  And then the
compsci departments made a concerted effort, taught a generation of
students in the new style with no reference whatsoever to what came
before.  Structured programming suddenly became blasé.  How else would
you program?

And then similar, though smaller and often partial repetitions of this
break happened: designing nicer data structures when the Wirth
languages came to their height; object oriented programming (which I
regard as one of the great intellectual failures of programming).

So when the kids are presented with exercises on functors, ADTs, and
monads in intro compsci, and the professors pretend that it was always
this way, there was never any other way, then they will grow up, they
will go forth, and these will be the everyday things.  Until then, I
will continue to hear people say that map is a scary, unfamiliar
object that makes the meaning of code obscure.

--
Frederick Ross
Graduate Fellow, (|Siggia> + |McKinney>)/sqrt(2) Lab
The Rockefeller University
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANNOUNCE: binary: high performance, pure binary serialisation

2007-01-27 Thread Donald Bruce Stewart
dons:
> lemming:
> > 
> > On Sat, 27 Jan 2007, Donald Bruce Stewart wrote:
> > 
> > > lemming:
> > > > 
> > > > On Fri, 26 Jan 2007, Donald Bruce Stewart wrote:
> > > > 
> > > > > 
> > > > > Binary: high performance, pure binary serialisation for 
> > > > > Haskell
> > > > >  
> > > > > --
> > > > >  
> > > > > 
> > > > > The Binary Strike Team is pleased to announce the release of a new,
> > > > > pure, efficient binary serialisation library for Haskell, now 
> > > > > available
> > > > > from Hackage:
> > > > > 
> > > > >  tarball:
> > > > > http://hackage.haskell.org/cgi-bin/hackage-scripts/package/binary/0.2
> > > > >  darcs:  darcs get http://darcs.haskell.org/binary
> > > > >  haddocks:   http://www.cse.unsw.edu.au/~dons/binary/Data-Binary.html
> > > > 
> > > > I want to write out data in the machine's endianess, because that data 
> > > > will be post-processed by sox, which reads data in the machine's 
> > > > endianess. Is this also planned for the package?
> > > 
> > > The underlying Get and Put monads support explicit endian writes and
> > > reads, which you can add to your instances explicitly:
> > > 
> > > http://www.cse.unsw.edu.au/~dons/binary/Data-Binary-Get.html#5
> > > http://www.cse.unsw.edu.au/~dons/binary/Data-Binary-Put.html#5
> > > 
> > > So you can do that now. 
> > 
> > Of course, I can check for the machine's endianess, then decide whether to
> > use putWord16be and putWord16le. But I assume that it is more efficient,
> > if there would be some function putWord16native, which writes out in the
> > machine's native endianess.

I've added raw primitives for:

{put,get}Wordhost
{put,get}Word16host
{put,get}Word32host
{put,get}Word64host

which do unaligned, host-sized, host-endian packing of data.

Writing is some 15% faster for Words, a bit less for reading (which is a
bit unoptimised at the moment), and a bit less for other types. Needless
to say, data serialised this way is only portable to the same
architecture.

Now available from specially selected bookshops and darcs repositories.
Please enjoy responsibly!

-- Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Simple HTTP lib for Windows?

2007-01-27 Thread Daniel McAllansmith
On Sunday 28 January 2007 10:53, Neil Mitchell wrote:
> Thanks, it certainly gets more things, but has a nasty habit of taking
> a very long time in Hugs on certain URLs:
>
> research.microsoft.com/, 

Looks like IIS is waiting until it receives a Connection header, a bit of a 
variation from spec I think...
Adding in 
  hPutStrLn h ("Connection: close\r\n")
or
  hPutStrLn h ("Connection: keep-alive\r\n")
as appropriate should sort that.


> www.cs.york.ac.uk/ 

This is responding with a 302, the resource has been found but is temporarily 
at another location indicated in the responses Location header.
So, now you'll have to start parsing responses.
In this case the Location header is www.cs.york.ac.uk/public.php

>
> And on some urls, ie http://research.microsoft.com/~simonpj/, it still
> ends up with IO.hGetChar: illegal operation
>
> Any ideas why?

Hmmm, if you putStrLn the values of closed and eof it looks to be hanging 
during the eof check.  Don't know why.

Oh yeah, all the carriage-returns should be carriage-return line-feeds from 
memory.  Not that that seems to help with this problem.


The cheap and cheerful solution might be to invoke cURL.


Daniel
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe