Re: [Haskell-cafe] some algorithm help with jhc
John Meacham >I have started working on jhc more recently and have come across some >places where I think my algorithms could be improved but was not sure >exactly where to start so thought I would ask the list since perhaps >someone here has some insight. > >After a long time of trying various methods of speeding up the fixpoint >iteration of my points-to analysis (the current main bottleneck) I >decided to step back and look at the basic problem again. It turns out I >can express the problem as one of constraint satisfaction resulting in >much smaller code (600 lines vs 2000) and 10fold speedups with my >unoptimized first draft solver. > >It is much faster but still not as fast as I'd like. I don't know a lot >about constraint problems, but my intuiton says this particular problem >is of a type that should be particularly easy to solve but am uncertain >where to start in my searching to find a fast algorithm. My constraints >come in two types of rules. Hi, check out the book Principles of Program Analysis by Nielson, Nielson, Hankin (http://www2.imm.dtu.dk/~riis/PPA/ppa.html). It has quite some on constraint solving for program analysis. There are algorithms in that book for set constraint problems that look quite similar to your problem. Björn Lisper ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Functional vs Imperative
I apologise for the duplicate messages -- GMail was having issues, and told me that the message couldn't be sent the first time I'd attempted it. - Cale ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] some algorithm help with jhc
I have started working on jhc more recently and have come across some places where I think my algorithms could be improved but was not sure exactly where to start so thought I would ask the list since perhaps someone here has some insight. After a long time of trying various methods of speeding up the fixpoint iteration of my points-to analysis (the current main bottleneck) I decided to step back and look at the basic problem again. It turns out I can express the problem as one of constraint satisfaction resulting in much smaller code (600 lines vs 2000) and 10fold speedups with my unoptimized first draft solver. It is much faster but still not as fast as I'd like. I don't know a lot about constraint problems, but my intuiton says this particular problem is of a type that should be particularly easy to solve but am uncertain where to start in my searching to find a fast algorithm. My constraints come in two types of rules. the rules are of the form (where a and b are variables to be solved for and x and y are values in my domain) * a >= f(b) where x >= y implies f(x) >= f(y) * enforce g(a) as a new set of rules where if x >= y then g(x) subsumes g(y) f and g are typed thusly. f :: domain -> domain g :: domain -> set of rules the following useful derived rules can be expressed by the above. a >= b a == b if z(a) then b >= c now, the reason my intuiton says there should be a fast solution is that there is no way for the variables to decrease. every added rule can only add to the least solution and not shrink any set. so, my basic question is, is this a known form of constraint satisfaction problem? does it admit a particulary fast solution as my intuition tells me? does it have a name I can search for on scholar.google.com? my current first draft implementation represents each rule as an IO action taking a difference set that propegates said difference set and then adds it to the current set for each var. The second problem I am facing is one of debugging. my code dealing with jhc core and all the optimizations that are performed on it has gone through a lot of evolution. over time, bugs have been introduced that are very hard to track down, the symptom would be suddenly having core that doesn't typecheck or has an unknown identifier or worse a segfault in the generated program. backtracking to find the error is quite tedious, mainly involving commenting out transformations until I find the offending one, then rederiving the correct code and comparing it to what I have written. I have decided to remedy the situation and start using QuickCheck to verify all my transformations are meaning and type preserving. however, the problem arrises in how to come up with a meaningful instance of Arbitrary for expressions in jhc core. It is not clear at all how to come up with code that generates random yet "interesting", well typed, convergent, terms in the extended lambda calculus with things like recursive definitons and primitives. even if I solved that, the problem of deciding whether two expressions (which might be functions) do the 'same thing' is undecidable, so how do I even test if the transformations are meaning preserving? Ideally, someone would have written a paper on this. I have seen several papers on generating suitable random graphs for testing graph algorithms, but have not come across one on creating typed lambda calculus terms. perhaps someone else has come across this same problem and has some insights? I am interested in ideas, brainstorming and pointers to papers or terms to search for as much as ready made solutions. In any case, I think they are interesting problems to begin with... hopefully someone out there thinks so too :) John -- John Meacham - ⑆repetae.net⑆john⑈ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Functional vs Imperative
On 13/09/05, Dhaemon <[EMAIL PROTECTED]> wrote: > Hello, > I'm quite interested in haskell, but there is something I don't > understand(intuitively). I've been crawling the web for an answer, but > nothing talks to me... > So I was hoping I could find some help here: > "How is evaluating an expression different from performing action?" > I'm puzzled... Doesn't it amount to the same thing? Maybe I have a wrong > definition of "evaluating"(determine the value of an expression)? > Examples would be appreciated. > Also, just for kicks, may I had this: I read the code of some haskell-made > programs and was astonished. Yes! It was clean and all, but there were "do"s > everywhere... Why use a function language if you use it as an imperative > one?(i.e. most of the apps in > http://haskell.org/practice.html) > > Thanks in advance > It should be made clear that the only IO action which is ever actually performed in a Haskell program is main (short of loading the code up in an interactive environment and getting it to run other actions separately). IO actions themselves are described in a pure functional, referentially transparent way. Evaluation of an expression is different from performing an IO action in the various things which can occur as a result. Essentially the only thing which should be able to occur (without some major cheating) as the result of evaluating a Haskell expression, is the production of a value, and this value will always be the same for a given expression. It should not print things to the screen, fire packets over the network, read from the random number generator or read or write to files. (There are instances where IO is lazily delayed until a result is demanded, so that evaluation of what looks like a pure list results in reading from a file, but one can only construct these situations so that they occur inside the execution of an IO action anyway. The lists aren't really pure.) The upshot of this is that if one has a Haskell expression, within time and memory constraints, one can evaluate it on any computer, under any ordinary circumstances, and get the same result. One can't make that claim about performing an IO action. IO actions when performed may read from the keyboard or network or filesystem (as well as write to the screen, etc.). However, evaluation of an expression which represents an IO action always yields the same action (even if that action may not do the same thing when it is actually performed in the end). That's the distinction that's being made. As it has been pointed out in other posts, do notation is pure, in the sense that do blocks are expressions which evaluate to the same thing every time. This thing may be an IO action, but it may also be a list, a Maybe value, a binary tree, a function of type s -> (a, s) (called a state computation), a graph, or any number of other monadic types. Most monads m are not "one-way" in that one can extract results from the monadic containers - there usually exist functions (m a -> a) -- IO is a major example of a case where this doesn't hold, but it's by far not the only example of a monad. - Cale ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Functional vs Imperative
On 13/09/05, Dhaemon <[EMAIL PROTECTED]> wrote: > Hello, > I'm quite interested in haskell, but there is something I don't > understand(intuitively). I've been crawling the web for an answer, but > nothing talks to me... > So I was hoping I could find some help here: > "How is evaluating an expression different from performing action?" > I'm puzzled... Doesn't it amount to the same thing? Maybe I have a wrong > definition of "evaluating"(determine the value of an expression)? > Examples would be appreciated. > Also, just for kicks, may I had this: I read the code of some haskell-made > programs and was astonished. Yes! It was clean and all, but there were "do"s > everywhere... Why use a function language if you use it as an imperative > one?(i.e. most of the apps in > http://haskell.org/practice.html) > > Thanks in advance > It should be made clear that the only IO action which is ever actually performed in a Haskell program is main (short of loading the code up in an interactive environment and getting it to run other actions separately). IO actions themselves are described in a pure functional, referentially transparent way. Evaluation of an expression is different from performing an IO action in the various things which can occur as a result. Essentially the only thing which should be able to occur (without some major cheating) as the result of evaluating a Haskell expression, is the production of a value, and this value will always be the same for a given expression. It should not print things to the screen, fire packets over the network, read from the random number generator or read or write to files. (There are instances where IO is lazily delayed until a result is demanded, so that evaluation of what looks like a pure list results in reading from a file, but one can only construct these situations so that they occur inside the execution of an IO action anyway. The lists aren't really pure.) The upshot of this is that if one has a Haskell expression, within time and memory constraints, one can evaluate it on any computer, under any ordinary circumstances, and get the same result. One can't make that claim about performing an IO action. IO actions when performed may read from the keyboard or network or filesystem (as well as write to the screen, etc.). However, evaluation of an expression which represents an IO action always yields the same action (even if that action may not do the same thing when it is actually performed in the end). That's the distinction that's being made. As it has been pointed out in other posts, do notation is pure, in the sense that do blocks are expressions which evaluate to the same thing every time. This thing may be an IO action, but it may also be a list, a Maybe value, a binary tree, a function of type s -> (a, s) (called a state computation), a graph, or any number of other monadic types. Most monads m are not "one-way" in that one can extract results from the monadic containers - there usually exist functions (m a -> a) -- IO is a major example of a case where this doesn't hold, but it's by far not the only example of a monad. - Cale ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Doing Windows Programming
Brian McQueen <[EMAIL PROTECTED]> writes: > How can I use Haskell to do general Windows programming, like you > would be able to do if you were using one of those Windows IDEs: You may find H/Direct would help with this. Unfortunately, there isn't a binary build that I can find, you need to build from source (which I've not managed to achieve). If you can get a binary version, though, it's worth a look... Paul. -- It is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that. -- G. H. Hardy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Binary parser combinators and pretty printing
On Tue, Sep 13, 2005 at 06:03:00PM +0300, Einar Karttunen wrote: > We will use the following Haskell datatype: > > data Packet = Packet Word32 Word32 Word32 [FastString] > > 1) Simple monadic interface > > [...] > > This works but writing the code gets tedious and dull. > > 2) Using better combinators > > packet = w32be <> w32be <> w32be <> lengthPrefixList w32be (lengthPrefixList > w32be bytes) > getPacket = let (mid,sid,rid,vars) = getter packet in Packet mid sid rid vars > putPacket (Packet mid sid rid vars) = setter packet mid sid rid vars > > Maybe even the tuple could be eliminated by using a little of TH. > Has anyone used combinators like this before and how did it work? No need for TH. If you have monadic interface, you can write getPacket as: getPacket = (return Packet) `ap` w32be `ap` w32be `ap` w32be `ap` lengthPrefixList w32be (lengthPrefixList w32be bytes) There's more trouble with putPacket though. > 3) Using TH entirely > > $(getAndPut 'Packet "w32 w32 w32 lengthPrefixList (w32 bytes)") > > Is this better than the combinators in 2)? Also what sort of > syntax would be best for expressing nontrivial dependencies - > e.g. a checksum calculated from other fields. How about all these points together?: a) Simple monadic interface b) Using better combinators c) Using TH to generate code for the simple cases d) Using type-classes Having a monadic interface doesn't prevent you from introducing other combinators. In fact, every useful monad should have some combinators other than >>= and return. There are already some generic monadic combinators that can simplify your code, as shown in the getPacket example. Points c) and d) are closely related - you can introduce a type class for Binary decodable/encodable datatypes and then generate instances with TH. The code for these instances is generated directly from the structure of a datatype and it is quite simple, because it's mostly recursively using the type-class methods - this can greatly simplify TH code. So, assuming that you have instances of Binary for Word32 and FastString and [], making Packet an instance of Binary would amount to writing data Packet = Packet Word32 Word32 Word32 [FastString] $(deriveBinary 'Packet) Manually written instances for Packet would look like this: instance Binary Packet where decode = f $ f $ f $ f $ return Packet encode (Packet mid sid rid vars) = do encode mid encode sid encode rid encode vars f x = x `ap` decode Unfortunately the world is not that simple, so you'll probably a bit more complicated framework to handle varying endianness, varying encodings for the same types, strange encoding schemas (like DNS packet compression, fields far away from the record sequences, etc). To some degree it can be solved by introducing newtypes or making more complicated typeclasses. I've played with such frameworks a couple of times and I feel it's time to make a library useful for others. If you're interested, we could cooperate. > 4) Using a syntax extension If there is any extension that would help here, I think it should be something more general than merely a syntax for specifying binary format. This problem seems like a good use for generics and TH. Best regards Tomasz ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Functional vs Imperative
On 9/13/05, Dhaemon <[EMAIL PROTECTED]> wrote: > Hello, > I'm quite interested in haskell, but there is something I don't > understand(intuitively). I've been crawling the web for an answer, but > nothing talks to me... > So I was hoping I could find some help here: > "How is evaluating an expression different from performing action?" > I'm puzzled... Doesn't it amount to the same thing? Maybe I have a wrong > definition of "evaluating"(determine the value of an expression)? > Examples would be appreciated. > Also, just for kicks, may I had this: I read the code of some haskell-made > programs and was astonished. Yes! It was clean and all, but there were "do"s > everywhere... Why use a function language if you use it as an imperative > one?(i.e. most of the apps in > http://haskell.org/practice.html) > Well, most of the code is still "functional" in nature, only some of it is "imperative". And even if you're writing a very IO heavy program writing IO in Haskell is still much nicer than in traditional imperative languages since all actions are first class citizens etc. It's better to have a nice clean way of doing IO that's completely separated away from pure code than to have everything be done in a less clean imperative style always. In Haskell you have it both ways. When a functional approach is cleaner, use it, when stuff should be evaluated in sequence (not just IO, but other monads like Maybe and State as well) you do that. It all works out in a sane and clean way. /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Template Haskell and Types
Simon Peyton-Jones wrote: | > putStrLn $(mysplice ''MyData) | > | | Thanks for responses. Is there any up-to-date documentation avaliable? Template Haskell is, alas, poorly documented. I would really welcome someone to volunteer to help write better documentation. Meanwhile, as the user manual says, the stuff about quoting names is described in a design note http://research.microsoft.com/~simonpj/tmp/notes2.ps Thanks. With haddoc documentation it is quite easy to translate old names to new names and guess the meanning of others. Next quiestion is: how do I debug my macros? When I make some error in my program, I get coredump (or the windows equivalent)? -- Gracjan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Functional vs Imperative
Am Dienstag, 13. September 2005 15:45 schrieb Dhaemon: > [...] > Also, just for kicks, may I had this: I read the code of some haskell-made > programs and was astonished. Yes! It was clean and all, but there were > "do"s everywhere... Why use a function language if you use it as an > imperative one?(i.e. most of the apps in http://haskell.org/practice.html) Note that do expressions are not expressions whose evaluation has side-effects. The evaluation of a do expression doesn't yield the result of the action it describes, causing side-effects, but it yields the action itself. Evaluation of this action is done seperately. > Thanks in advance, Best wishes, Wolfgang ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Haskell poker server
On 28 August 2005 20:00, Joel Reymont wrote: > I get a message from Erlang once data arrives over TCP and the > message is a {tcp, Socket, Bin} tuple where Bin is binary data. I can > easily extract what I need using Erlang binary pattern matching: > > read(<<24, GID:32, Seq:16>>) -> > {24, GID, Seq}. I didn't see anyone mention this (apologies if I missed it), but the House project does parsing of network packets and has some useful combinators for parsing binary data: http://www.cse.ogi.edu/~hallgren/House/ Cheers, Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Functional vs Imperative
On 13 Sep 2005, at 16:22, David Roundy wrote: On Tue, Sep 13, 2005 at 01:45:52PM +, Dhaemon wrote: Also, just for kicks, may I had this: I read the code of some haskell-made programs and was astonished. Yes! It was clean and all, but there were "do"s everywhere... Why use a function language if you use it as an imperative one?(i.e. most of the apps in http://haskell.org/practice.html) Monadic code isn't synonymous with imperative code, and "do" only indicates that you're looking at monadic code. The Maybe monad is an example of a very useful, very non-imperative monad that can be used to cleanly write functional code. On the other hand, IO is always monadic, so perhaps you're looking at IO code. But I'd assert that even monadic IO code isn't quite the same as true "imperative" code. I'd probably say that the difference has to do with whether you create modifiable "variables". When you start doing that, whether you're in the ST monad or the IO monad, I think you're writing imperative-style code. But I think that that sort of usage is actually pretty uncommon. I would tend to argue that even in those monads you aren't really writing imperative style code -- you still can't have side effects. The point of the monad is that it preserves referential transparency while doing something ordered. Bob ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Weak hashtable memoization code?
On 28 August 2005 16:39, Bulat Ziganshin wrote: > Hello David, > > Sunday, August 28, 2005, 4:19:07 PM, you wrote: > >> Hi all, > >> Does anyone have a nice bit of example code to implement memoization >> using weak pointers and hash tables? It would be nice to have a >> pre-packaged module that I could just use, which has already been >> tested. The contents of Data.WeakPtr seem a bit lower-level than >> I'd rather work with. > > http://www.haskell.org/~simonmar/papers/weak.pdf There's the memo table implementation in the util package: hslibs/util/Memo.lhs. Note that this is scheduled for demolition in GHC 6.6. Cheers, Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Binary parser combinators and pretty printing
Einar Karttunen writes: > I am trying to figure out the best interface to binary parser > and pretty printing combinators for network protocols. > > 2) Using better combinators > > packet = w32be <> w32be <> w32be <> lengthPrefixList w32be (lengthPrefixList > w32be bytes) > Has anyone used combinators like this before and how did it work? Yes, the nhc98 Binary library has a "<<" combinator, in very much the style you outline. It is only used in pure code, but it permits some very concise descriptions of the binary layout. The library is described here: ftp://ftp.cs.york.ac.uk/pub/malcolm/ismm98.html but unfortunately that paper has only the tiniest examples of the usage of "<<". However, in my experience the style worked well and was pleasant to use. Regards, Malcolm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Functional vs Imperative
On Tue, Sep 13, 2005 at 01:45:52PM +, Dhaemon wrote: > Also, just for kicks, may I had this: I read the code of some haskell-made > programs and was astonished. Yes! It was clean and all, but there were "do"s > everywhere... Why use a function language if you use it as an imperative > one?(i.e. most of the apps in http://haskell.org/practice.html) Monadic code isn't synonymous with imperative code, and "do" only indicates that you're looking at monadic code. The Maybe monad is an example of a very useful, very non-imperative monad that can be used to cleanly write functional code. On the other hand, IO is always monadic, so perhaps you're looking at IO code. But I'd assert that even monadic IO code isn't quite the same as true "imperative" code. I'd probably say that the difference has to do with whether you create modifiable "variables". When you start doing that, whether you're in the ST monad or the IO monad, I think you're writing imperative-style code. But I think that that sort of usage is actually pretty uncommon. -- David Roundy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Functional vs Imperative
Small point, From: Thomas Davie <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] CC: Haskell-Cafe@haskell.org Subject: Re: [Haskell-cafe] Functional vs Imperative Date: Tue, 13 Sep 2005 14:55:14 +0100 On 13 Sep 2005, at 14:45, Dhaemon wrote: Hello, I'm quite interested in haskell, but there is something I don't understand(intuitively). I've been crawling the web for an answer, but nothing talks to me... So I was hoping I could find some help here: "How is evaluating an expression different from performing action?" I'm puzzled... Doesn't it amount to the same thing? Maybe I have a wrong definition of "evaluating"(determine the value of an expression)? Examples would be appreciated. Also, just for kicks, may I had this: I read the code of some haskell-made programs and was astonished. Yes! It was clean and all, but there were "do"s everywhere... Why use a function language if you use it as an imperative one?(i.e. most of the apps in http:// haskell.org/practice.html) The difference is all about referential transparency -- in short, a function given the same inputs will always give the same result. This is not the same as in imperative languages, where functions/ methods/actions can have 'side-effects' that change the behavior of the rest of the program. Take this example: C program: #define square(x) ((x) * (x)) #define inc(x) ((x)++) int myFunc (int *x) { return square(inc(*x)); } the C preprocessor will re-write the return line to: return x)++)) * (((x)++))); Shouldn't that be: return *x)++)) * (((*x)++))); this will be performed in sequence, so, x will be incremented (changing the value of x), and that result will be multiplied by x incremented again. so if we run myFunc(&y), where y is 5, what we get is 5 incremented to 6, and them multiplied by 6 incremented to 7. So the result of the function is 42 (when you might reasonably expect 36), and y is incremented by 2, when you might reasonably expect it to be incremented by 1. Haskell program: square x = x * x inc = (+1) myFunc = square . inc and we now call myFunc 5, we get this evaluation: myFunc 5 is reduced to (square . inc) 5 (square . inc) 5 is reduced to square (inc 5) square (inc 5) is reduced to square ((+1) 5) square ((+1) 5) is reduced to square 6 square 6 is reduced to 6 * 6 6 * 6 is reduced to 36 If you want to study these reductions on a few more examples, you might want to download the Hat tracer, and use hat-anim to display reductions step by step. Bob ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe _ The new MSN Search Toolbar now includes Desktop search! http://toolbar.msn.co.uk/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Binary parser combinators and pretty printing
Hello I am trying to figure out the best interface to binary parser and pretty printing combinators for network protocols. I am trying to find the most natural syntax to express these parsers in Haskell and would like opinions and new ideas. As an example I will use a protocol with the following packet structure: 0 message-id 4 sender-id 8 receiver-id 12 number of parameters 16 parameters. Each parameter is prefixed by 32bit length followed by the data. We will use the following Haskell datatype: data Packet = Packet Word32 Word32 Word32 [FastString] 1) Simple monadic interface getPacket = do mid <- getWord32BE sid <- getWord32BE rid <- getWord32BE nmsg<- getWord32BE vars<- replicateM (fromIntegral nmsg) (getWord32BE >>= getBytes) return $ Packet mid sid rid nmsg vars putPacket (Packet mid sid rid vars) = do mapM_ putWord32BE [mid, sid, rid, length vars] mapM_ (\fs -> putWord32BE (length fs) >> putBytes fs) vars This works but writing the code gets tedious and dull. 2) Using better combinators packet = w32be <> w32be <> w32be <> lengthPrefixList w32be (lengthPrefixList w32be bytes) getPacket = let (mid,sid,rid,vars) = getter packet in Packet mid sid rid vars putPacket (Packet mid sid rid vars) = setter packet mid sid rid vars Maybe even the tuple could be eliminated by using a little of TH. Has anyone used combinators like this before and how did it work? 3) Using TH entirely $(getAndPut 'Packet "w32 w32 w32 lengthPrefixList (w32 bytes)") Is this better than the combinators in 2)? Also what sort of syntax would be best for expressing nontrivial dependencies - e.g. a checksum calculated from other fields. 4) Using a syntax extension Erlang does this with the bit syntax (http://erlang.se/doc/doc-5.4.8/doc/programming_examples/bit_syntax.html) and it is very nifty for some purposes. getPacket = do << mid:32, sid:32, rid:32, len:32 rest:len/binary >> ... The list of lists gets nontrivial here too... - Einar Karttunen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Functional vs Imperative
On 13 Sep 2005, at 14:45, Dhaemon wrote: Hello, I'm quite interested in haskell, but there is something I don't understand(intuitively). I've been crawling the web for an answer, but nothing talks to me... So I was hoping I could find some help here: "How is evaluating an expression different from performing action?" I'm puzzled... Doesn't it amount to the same thing? Maybe I have a wrong definition of "evaluating"(determine the value of an expression)? Examples would be appreciated. Also, just for kicks, may I had this: I read the code of some haskell-made programs and was astonished. Yes! It was clean and all, but there were "do"s everywhere... Why use a function language if you use it as an imperative one?(i.e. most of the apps in http:// haskell.org/practice.html) The difference is all about referential transparency -- in short, a function given the same inputs will always give the same result. This is not the same as in imperative languages, where functions/ methods/actions can have 'side-effects' that change the behavior of the rest of the program. Take this example: C program: #define square(x) ((x) * (x)) #define inc(x) ((x)++) int myFunc (int *x) { return square(inc(*x)); } the C preprocessor will re-write the return line to: return x)++)) * (((x)++))); this will be performed in sequence, so, x will be incremented (changing the value of x), and that result will be multiplied by x incremented again. so if we run myFunc(&y), where y is 5, what we get is 5 incremented to 6, and them multiplied by 6 incremented to 7. So the result of the function is 42 (when you might reasonably expect 36), and y is incremented by 2, when you might reasonably expect it to be incremented by 1. Haskell program: square x = x * x inc = (+1) myFunc = square . inc and we now call myFunc 5, we get this evaluation: myFunc 5 is reduced to (square . inc) 5 (square . inc) 5 is reduced to square (inc 5) square (inc 5) is reduced to square ((+1) 5) square ((+1) 5) is reduced to square 6 square 6 is reduced to 6 * 6 6 * 6 is reduced to 36 If you want to study these reductions on a few more examples, you might want to download the Hat tracer, and use hat-anim to display reductions step by step. Bob ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Functional vs Imperative
Hello, I'm quite interested in haskell, but there is something I don't understand(intuitively). I've been crawling the web for an answer, but nothing talks to me... So I was hoping I could find some help here: "How is evaluating an _expression_ different from performing action?" I'm puzzled... Doesn't it amount to the same thing? Maybe I have a wrong definition of "evaluating"(determine the value of an _expression_)? Examples would be appreciated. Also, just for kicks, may I had this: I read the code of some haskell-made programs and was astonished. Yes! It was clean and all, but there were "do"s everywhere... Why use a function language if you use it as an imperative one?(i.e. most of the apps in http://haskell.org/practice.html) Thanks in advance, ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] RE: [Haskell] mailing list headaches
On 08 September 2005 17:53, Glynn Clements wrote: > Frederik Eaton wrote: > >> However, threading by "References", which RFC 2822 says >> SHOULD be possible, and which works on my other folders, doesn't work >> well on Haskell mailing lists. Presumably the issue is that there are >> a large number of Windows users with strange mail clients which don't >> insert "References" headers. > > It isn't so much that there are a large number of such users, but that > two of the core developers are among them (and are both employed by > Microsoft, so RFC-conformance probably isn't an option). Yes, this is partially our fault. When using Outlook through Exchange, the In-Reply-To header isn't generated at all. Outlook via SMTP works fine, though. I reported the bug several years ago, let's see if Office 12 fixes it :) Cheers, Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] RE: [Haskell] ANNOUNCE: ghc-src version 0.2.0
On 30 August 2005 12:05, Arthur Baars wrote: > Daan is right, I wrote a parser for GHC using Doaitse Swierstra's > parsing combinator library > (http://www.cs.uu.nl/groups/ST/Software/UU_Parsing/index.html). > I needed a drop-in replacement for GHC's Happy parser, to make a > prototype for syntax macros. Syntax Macros allow a programmer to > extend a language with new syntax. Combinator based parsers parsers > can be dynamically extended, making them suitable for implementing > syntax macros. Unfortunately, I never had time to really finish the > syntax macro implementation. > > But I did finish the combinator based parser for GHC. I tested it by > having GHC( with combinator parser) compile itself and all the > libraries. This took about 10% longer than with the original GHC, so > in practice its speed is acceptable. With all due respect, a 10% increase in compile time isn't acceptable at all! And when you consider that parsing is less than 10% of compile time overall (probably much less), a 10% increase represents at least a factor of 2 in the parser. I'm not criticising the work at all - far from it, just the notion that we would consider adding 10% to GHC's compile times "acceptable". I've recently been struggling to shave a few percent off GHC's compile times, BTW :-) Cheers, Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Language Workbenches - First attempt
source = "#123456789012345678901234567890123456789012345678901234567890\n\ \SVCLFOWLER 10101MS0120050313.\n\ \SVCLHOHPE 10201DX0320050315\n\ \SVCLTWO x10301MRP220050329..\n\ \USGE10301TWO x50214..7050329..." type ConfigLine = (String, [(String, (Int, Int))]) type Configuration = [ConfigLine] type KeyVal = (String, String) type Header = String type Entry = (Header, [KeyVal]) config :: Configuration config = [("SVCL", [("CustomerName", (4, 18)), ("CustomerID", (19, 23)), ("CallTypeCode", (24, 27)), ("DateOfCallString", (28, 35))]), ("USGE", [("CustomerID", (4, 8)), ("CustomerName", (9, 22)), ("Cycle", (30, 30)), ("ReadDAte", (31, 36))])] getRange :: Int -> Int -> [a] -> [a] getRange a b l = take (b-a+1) $ drop a l lineToFields :: String -> [(Int,Int)] -> [String] lineToFields line points = map (fieldFromTo line) points where fieldFromTo line (x,y) = getRange x y line lineType :: String -> String lineType = getRange 0 3 applyConfig :: String -> ConfigLine -> [KeyVal] applyConfig line (ckey, cval) = if lineType line == ckey then zip names $ lineToFields line points else [] where part = unzip cval names = fst part points = snd part parseLine :: Configuration -> String -> Entry parseLine cnf line = (header, parsed) where rawData :: [[KeyVal]] rawData = map (applyConfig line) cnf parsed :: [KeyVal] parsed = head $ dropWhile null rawData header = lineType line parse :: Configuration -> [String] -> [Entry] parse cnf lines = map (parseLine cnf) lines run = parse config $ filter noComment $ lines source where noComment = \x -> (head x) /= '#' == Output *Main> run [("SVCL",[("CustomerName","FOWLER "),("CustomerID","10101"),("CallTypeCode","MS01"),("DateOfCallString","20050313")]),("SVCL",[("CustomerName","HOHPE "),("CustomerID","10201"),("CallTypeCode","DX03"),("DateOfCallString","20050315")]),("SVCL",[("CustomerName","TWO x"),("CustomerID","10301"),("CallTypeCode","MRP2"),("DateOfCallString","20050329")]),("USGE",[("CustomerID","10301"),("CustomerName","TWO x"),("Cycle","7"),("ReadDAte","050329")])] *Main> Yoel Jacobsen wrote: It seems that Martin Fowler's article "Language Workbenches: The killer-App for Domain Specific Languages?" - http://www.martinfowler.com/articles/languageWorkbench.html - has generated some nice dynamic solution where a configuration file is written in the same language as the program. Notable examples are lisp - http://lispm.dyndns.org/news?ID=NEWS-2005-07-08-1 and python - http://billionairebusinessman.blogspot.com/2005/09/drop-that-schema-and-put-your-hands-in.html I'm trying to create an _elegant_ solution in Haskell. But I'm stuck. Since the native record-like access in Haskell syntax is using labelled fields in datatype decleration but the later are strictly compile-time. Therefore, if I compile my program and add a field in the configuration file (written in Haskell, using, for instance hs-plugins), I'll need to recompile the data declaration as well. Further, what is the type of the parser? Consider the following implementation: source = "#123456789012345678901234567890123456789012345678901234567890\n\ \SVCLFOWLER 10101MS0120050313.\n\ \SVCLHOHPE 10201DX0320050315\n\ \SVCLTWO x10301MRP220050329..\n\ \USGE10301TWO x50214..7050329..." data Configuration = Config String [(String, Int, Int)] config = [ Config "SVCL" [("CustomerName", 4, 18), ("CustomerID", 19, 23), ("CallTypeCode", 24, 27), ("DateOfCallString", 28, 35)], Config "USGE" [("CustomerID", 4, 8), ("CustomerName", 9, 22), ("Cycle", 30, 30), ("ReadDAte", 31, 36)]] -- parse takes the configuration, a line from the source string and generate a record parse :: Configuration -> String -> Record What is the type of Record? Anyway, any elegant solution or a hint towards one are most welcome. Thanks, Yoel ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Template Haskell and Types
On Tuesday 13 September 2005 09:16, Gracjan Polak wrote: > Tomasz Zielonka wrote: > > On Mon, Sep 12, 2005 at 12:08:14PM +0200, Gracjan Polak wrote: > >>Probably very simple question about template haskell: How do I make > >> a type for an argument to splice? Example: > >> > >>data MyData = MyData1 | MyData2 > >> > >>mysplice mytype = > >> [| litE $ stringL $ show mytype |] > >> > >>main = do > >> putStrLn $(mysplice MyData) > > > > Cale explained how you can quote types in general. In the special > > case when you simply want the Name of a type-constructor, you can > > use the '' quoting syntax: > > > > putStrLn $(mysplice ''MyData) > > Thanks for responses. Is there any up-to-date documentation > avaliable? The only I know of is the TH 'update' paper, where e.g. the single ('a) and double (''a) quote syntax is explained: http://research.microsoft.com/~simonpj/tmp/notes2.ps Ben ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Template Haskell and Types
| > putStrLn $(mysplice ''MyData) | > | | Thanks for responses. Is there any up-to-date documentation avaliable? Template Haskell is, alas, poorly documented. I would really welcome someone to volunteer to help write better documentation. Meanwhile, as the user manual says, the stuff about quoting names is described in a design note http://research.microsoft.com/~simonpj/tmp/notes2.ps Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Language Workbenches - the Haskell solution?
Correction - I wrote: > If you want a GUI for configuration, you could, > for example, write a fairly simple transformation > of the master XML into a .NET dialog, or glade > file for GTK, or whatever. We never did that, > though. Actually, Yael Weinbach wrote a beautiful GUI for this configuration scheme. I apologize to Yael for the omission. Regards, Yitz ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Template Haskell and Types
Tomasz Zielonka wrote: On Mon, Sep 12, 2005 at 12:08:14PM +0200, Gracjan Polak wrote: Probably very simple question about template haskell: How do I make a type for an argument to splice? Example: data MyData = MyData1 | MyData2 mysplice mytype = [| litE $ stringL $ show mytype |] main = do putStrLn $(mysplice MyData) Cale explained how you can quote types in general. In the special case when you simply want the Name of a type-constructor, you can use the '' quoting syntax: putStrLn $(mysplice ''MyData) Thanks for responses. Is there any up-to-date documentation avaliable? Best regards Tomasz ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Template Haskell and Types
On Mon, Sep 12, 2005 at 12:08:14PM +0200, Gracjan Polak wrote: > > Probably very simple question about template haskell: How do I make a > type for an argument to splice? Example: > > data MyData = MyData1 | MyData2 > > mysplice mytype = >[| litE $ stringL $ show mytype |] > > main = do >putStrLn $(mysplice MyData) Cale explained how you can quote types in general. In the special case when you simply want the Name of a type-constructor, you can use the '' quoting syntax: putStrLn $(mysplice ''MyData) Best regards Tomasz ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe