Re: [Haskell-cafe] let vs do?
Thomas, let x = ... in ... is only equal do x - ...; ... in the Identity monad. Also, why would do be more primitive than let. That way you would have to use monads everywhere. Also, let is treated specially by the type checker (IIRC) and there are many, many other reasons not to do that. As you already hinted at in a later message, this has to do with let- bindings being potentially polymorphic and monadic bindings being necessarily monomorphic: import Control.Monad.Identity foo = let id = \x - x in(id 'x', id 42) -- well-typed bar = runIdentity $ do id - return (\x - x) ; return (id 'x', id 42) -- ill-typed Cheers, Stefan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] let vs do?
Thomas, Stefan, Thanks for a most edifying exchange! i will reflect on this. Best wishes, --greg On 6/28/07, Stefan Holdermans [EMAIL PROTECTED] wrote: Thomas, let x = ... in ... is only equal do x - ...; ... in the Identity monad. Also, why would do be more primitive than let. That way you would have to use monads everywhere. Also, let is treated specially by the type checker (IIRC) and there are many, many other reasons not to do that. As you already hinted at in a later message, this has to do with let- bindings being potentially polymorphic and monadic bindings being necessarily monomorphic: import Control.Monad.Identity foo = let id = \x - x in(id 'x', id 42) -- well-typed bar = runIdentity $ do id - return (\x - x) ; return (id 'x', id 42) -- ill-typed Cheers, Stefan -- L.G. Meredith Managing Partner Biosimilarity LLC 505 N 72nd St Seattle, WA 98103 +1 206.650.3740 http://biosimilarity.blogspot.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: newports.hs utility for freebsd
clawsie: i have written a small haskell program to solve a problem many users of freebsd may have - knowing what ports have been updated after a daily/weekly etc cvsup. this is a trivial bit of coding hardly worth attention, but if it might be of use to you, you can find it here: http://www.b7j0c.org/content/haskell-newports.html standard disclaimers - coded tested mildly by me, a hobbyist haskeller nice brad, always good to see `scripting' work in Haskell. would you like to wrap it in a .cabal file and upload it to hackage, so people can find it in the future? details on that process here: http://www.haskell.org/haskellwiki/How_to_write_a_Haskell_program and http://cgi.cse.unsw.edu.au/~dons/blog/2006/12/11 Free the source! -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] let vs do?
Dave Bayer wrote: [...] In the Haskell do expression, every line is equally special, and type information is used to combine the lines, inserting implied combinators.[...] Desugaring do-notation is a syntactic transformation, requiring no type information. (In practice, the parts may be required to have a monadic type, but this is only to get an earlier (hence better) error message, I guess.) I see potential for a whole language that worked this way, opened up to let the programmers control this process without waiting for an implementation to take their suggestions (think history of arrows) piecemeal. How would you propose to specify such transformations? Greetings, Arie ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: newports.hs utility for freebsd
What is the advantage of using Haskell in this case? bryan is correct! i hesitated to even bother the cafe list with this, considering it is so trivial, but i just wanted to learn a bit more about haskell's file and directory functionality, and this bit of code may be something others can look at for some quickie code samples dons - i will definitely finish the job and create a .cabal file, and i will post my learning experiences with the packaging tools on my site as well so other newbies can see how easy it is to create official hackage code thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] let vs do?
On Fri, 29 Jun 2007, Dave Bayer wrote: One is immediately led back to the same idea as Haskell do expressions: Two pieces of program, juxtaposed next to each other, silently multiply to combine into a larger program, with type rules guiding the multiplication process. They don't, there's a ; between them which may or may not have been inserted by the layout rule. -- [EMAIL PROTECTED] The task of the academic is not to scale great intellectual mountains, but to flatten them. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] advice: instantiating/duplicating modules
I wrote a combination reader/writer monad (a la the RWS monad in the mtl) and I find myself wanting to use multiple instances of it in the same stack of transformers. The functional dependencies prevent this from working out. The class is called MonadRW and the transformer is called RWT. I find myself wishing I could import the same module twice, but instead of having two names for the same entity, I want the definitions proper of the module to be duplicated: I want two separate MonadRW classes and two separate RWT transformers. Since the module integrates the MonadRW and RWT transformer with the mtl, I would then only need to lift the instances of the instantiated MonadRW classes through the other RWTs. I'm rather unfamiliar with Template Haskell, but it sounds like it might fit the bill. Although, if I recall correctly, instances and type declarations splicing are yet to be implemented in GHC? Does anyone have any advice how to do this? I'm envisioning some preprocessing. I'd like to know if someone has developed a tool for this already or if this path has been attempted. Thanks for your time, Nick PS - If this doesn't work out, I'm aware that I could use type-indexed products and coproducts to pull it off, but I think that would drastically reduce the number of people who could understand/maintain the code without having to learn such cool stuff. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] let vs do?
On 29 jun 2007, at 16.26, Dave Bayer wrote: That way you would have to use monads everywhere. As you already hinted at in a later message, this has to do with let-bindings being potentially polymorphic and monadic bindings being necessarily monomorphic: Are there papers that prove this need be the case in any language, or are we simply now trapped into this for the moment by some design choices? The big design choice is to have non-strict evaluation semantics. Monads re-sequence instructions for cases where you need it. Recall that in Haskell let x = foo bar baz y = error Gotcha. in (x, y) isn't equivalent to (let ((x (foo bar baz)) (y (error Gotcha.))) (values x y) because Lisp is strict. In Lisp this would result in an error, even if y is never used, in Haskell only once y is actually used. To simulate this in Haskell you'd have to write: do x - foo bar baz y - error baz return (x, y) and choose the monad according to your semantics. I take it, your claim now is that by choosing the Identity monad, we'd get normal Haskell semantics (modulo polymorphic types?) and using any other monad we'd get any other semantics? Some problems I can see with this is: - Monads aren't transparent to the compiler. The compiler would still have to transform it into a pure intermediate form. - Most importantly, monads sequence computation. But I guess you can get around it. After all, you can simulate Haskell in strict lisp via: (let ((x (delay (foo bar baz))) (y (delay (error Gotcha (delay (values x y))) - So, I assume the big question is how not to lose type inference, and get used to the less pretty syntax ;) Maybe, others can comment on these issues. / Thomas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANNOUNCE: hiccup, a toy tcl impersonator in haskell
A while back I saw a toy tcl interpreter in 550 lines of C called 'picol'. I was looking for a simple language to implement in haskell, so I made my own toy tcl interpreter. It was surprisingly easy to make, thanks to the magic of Haskell and Bytestrings. :) It handles a few things incorrectly, and it is not feature complete, but I thought maybe somebody else might find it interesting. For the record (though it means nothing), my interpreter is about half the size of picol and runs about 30% faster in the few tests I've run, despite having a few more features. (it was certainly less than half the size of picol, but I keep tacking on functions when I get bored). Anyway, you can check it out at: http://code.google.com/p/hiccup/ I plan on making it more complete and faithful to tcl, but I'm branching into a different project for this one. However, any suggestions to make hiccup more efficient, elegant, or correct are certainly appreciated. Cheers, Kyle ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] advice: instantiating/duplicating modules
Hello Nicolas, Friday, June 29, 2007, 9:07:38 PM, you wrote: I'm rather unfamiliar with Template Haskell, but it sounds like it might fit the bill. Although, if I recall correctly, instances and type declarations splicing are yet to be implemented in GHC? instances - definitely not. i've used TH to generate Show instances http://www.haskell.org/bz/th3.htm http://www.haskell.org/bz/thdoc.htm -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] HGL on Windows
I vaguely remember to have read that HGL is (currently) not supported on Windows, but I can't find this information any more. Is this correct? It seems not to be included in GHC 6.6 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Abstraction leak
Andrew Coppin wrote, If this was Java, you would write all these compression and decompression stages as stream wrappers. So you wrap the raw input stream with an RLE decoder, have the function read the Huffman table, and then take off the RLE decoder and process the rest of the stream. Except that if the RLE decoding stream wrapper contains any internal buffering, then stripping it off would very likely result in data loss. What you actually have to do is have the RLE decoding stream wrapper build and return you a stream wrapper which delivers the remainder of the stream. Which I think shows that the abstraction isn't leaky ... where the remainder starts is very much dependent on the precise encoding of the prefix of the stream. Cheers, Miles ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Language semantics
Andrew Coppin [EMAIL PROTECTED] writes: (snip) Woah... Let me sit down and grok that for an hour or two. o_o The Haskell learning curve - including the wonderful range of useful generic stuff you can do with it - extends way higher than for many other languages, I think, though you can write lots of useful code when you're just partway up. I'm still learning things, and knowing I have much more yet to learn, and normally I can learn most of my way around a new programming language within a couple of weeks. (snip) What's Uniplate? http://www-users.cs.york.ac.uk/~ndm/uniplate/ may help to answer that question. I haven't even finished understanding SYB, yet, though; I'm still mystified by how to use Data.Generics.Twins.gzipWithQ. So, I'm not at a stage where I can usefully contrast Uniplate with the Data.Generics stuff. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Language semantics
Stefan O'Rear wrote: On Fri, Jun 29, 2007 at 07:18:00PM +0100, Andrew Coppin wrote: Well, let me show you the code - somebody will probably recognise this stuff... convert1 :: Expression - Expression convert1 S = S convert1 K = K convert1 I = I convert1 (Var v) = Var v convert1 (x :@: y) = (convert1 x) :@: (convert1 y) convert1 (Lam n e) | n `not_in` e = K :@: (convert1 e) convert1 (Lam n (Var v)) | n == v = I | otherwise = K :@: (convert1 (Var v)) convert1 (Lam n (x :@: y)) | y `is_var` n n `not_in` x = convert1 x | otherwise= S :@: (convert1 (Lam n x)) :@: (convert1 (Lam n y)) convert1 (Lam n (Lam m e)) | n `not_in` e = K :@: (convert1 (Lam m e)) | otherwise= convert1 (Lam n (convert1 (Lam m e))) This is *much* easier expressed as a bottom-up traversal. compile = transform optimize . transform eliminate eliminate (Lam v e) = transform (abstract v) e eliminate x = x abstract v (Var v') | v == v' = I abstract v (a :@ b) = S :@ a :@ b abstract v x = x optimize (S :@ (K :@ x) :@ (K :@ y)) = K :@ (x :@ y) optimize (S :@ (K :@ x) :@ I) = x optimize x = x Woah... Let me sit down and grok that for an hour or two. o_o (Hey, maybe this is why I don't develop cutting edge software for a living?) (Here using Uniplate, mostly because it is the freshest in my mind of all of them). What's Uniplate? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Abstraction leak
On Fri, Jun 29, 2007 at 07:39:28PM +0100, Andrew Coppin wrote: Now I have a problem. It's easy enough to pass the entire data stream through an RLE decoder and feed that to the Huffman table deserialize function, and it will give be back the table. But I now have *no clue* where the table ends in the original stream! Sounds to me like you want a parsing monad. Generally, when you want state, you want a monad, and the field of parsing monads is pretty mature. You can either write up a monad of your own, or use one of the existing ones (parsec, frisby, read). -- David Roundy Department of Physics Oregon State University ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Language semantics
Andrew Coppin writes: I wonder what the layout for that is... something like this? case foo of patter1 | guard1 - ... | guard2 - ... pattern2 | guard3 - ... | guard4 - ... Something like that should work. If the patterns are more indented than the 'case', and the guards are more indented than the patterns, then the layout rule should work fine. As always, once you get used to the way layout works, everything is pretty intuitive. Well, I'll have to go try it... Always a nice solution to these kinds of problems! I always thought of guards as being a nice shorthand for if-expressions - but if they can affect the order of pattern matching, clearly they are more drastically different than I realised. (Generally, I never ever use 'em!) A useful rule to remember with guards is that once you cross the equals sign, you can't go back. So if one of your patterns matches and a guard on that pattern is true, that right-hand side will be evaluated and there is no way to fall back to another guard or pattern. -- -David House, [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] formatTime %Q not working
On Thu, Jun 21, 2007 at 05:39:12PM +0300, Bit Connor wrote: now - getCurrentTime 2007-06-21 13:48:44.298699 UTC formatTime defaultTimeLocale %s now 1182433724 formatTime defaultTimeLocale %Q now %q also always gives me an empty string. It seems to work OK for me with GHC 6.6.1 and time 1.1.1. Can you please give a complete testcase, and say which version of time you are using and where you got it from? Thanks Ian ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Best idiom for avoiding Defaulting warnings with ghc -Wall -Werror ??
| By the way, using Integer for exponents really shouldn't be less | efficient - | but it seems it is. | | The code for (^) should be something like this: | | {-# INLINE ^ #-} | n ^ m = case toInteger m of | S# i - powerInt# n i | J# a p - powerGmp n a p I've done something like this now. Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Abstraction leak
On Friday 29 June 2007, Andrew Coppin wrote: ...and again today I found myself trying to do something that would be very easy in an imperative language, but I cannot think of a single good way of doing it in Haskell. Hopfully somebody can give me some hints. snip long and helpful explanation Here's my solution (drawn from a library I'll be posting Real Soon Now): import Control.Monad import Control.Monad.Trans data SPMT iota omicron m alpha = ReturnSP alpha | LiftSP (m (SPMT iota omicron m alpha)) | GetSP (iota - SPMT iota omicron m alpha)) | PutSP omicron (SPMT iota omicron m alpha) instance Monad m = Monad (SPMT iota omicron m) where return x = ReturnSP x ReturnSP x = f = f x LiftSP a = f = LiftSP (liftM (= f) a) GetSP a = f = GetSP (\ x - a x = f) PutSP x a = f = PutSP x (a = f) instance MonadTrans (SPMT iota omicron) where lift a = LiftSP (liftM ReturnSP a) getSP :: SPMT iota omicron m iota getSP = GetSP ReturnSP putSP :: omicron - SPMT iota omicron m () putSP x = PutSP x (ReturnSP ()) (^^) :: Monad m = SPMT iota omicron m alpha - SPMT omicron omicron' m beta - SPMT iota omicron' m beta a ^^ ReturnSP x = ReturnSP x a ^^ LiftSP b = LiftSP (liftM (a ^^) b) a ^^ PutSP x b = PutSP x (a ^^ b) LiftSP a ^^ GetSP b = LiftSP (liftM (^^ GetSP b) a) GetSP a ^^ GetSP b = GetSP (\ x - a x ^^ GetSP b) PutSP x a ^^ GetSP b = a ^^ b x If the signature of SPMT suffices to write decodeRLE and decodeHeader, the task of applying RLE decoding just to the header can be implemented by using decodeRLE ^^ decodeHeader in place of just decodeHeader. Extension to situations left un-implemented above I leave for your ingenuity and/or release of my library. HTH. Jonathan Cast http://sourceforge.net/projects/fid-core http://sourceforge.net/projects/fid-emacs ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HGL on Windows
Unfortunately your memory serves you well -- see: http://hackage.haskell.org/trac/ghc/ticket/742 -Paul peterv wrote: I vaguely remember to have read that HGL is (currently) not supported on Windows, but I cant find this information any more. Is this correct? It seems not to be included in GHC 6.6 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Abstraction leak
On Friday 29 June 2007, Jon Cast wrote: Here's my solution (drawn from a library I'll be posting Real Soon Now): snip solution I forgot to point out that this is 75-90% drawn from a library called Fudgets[1], which is probably the most extended practical meditation to date on programming with lazy streams in Haskell. Embedding that approach in a monadic interface seems to be my own idea, though. Jonathan Cast http://sourceforge.net/projects/fid-core http://sourceforge.net/projects/fid-emacs [1] http://www.md.chalmers.se/Cs/Research/Functional/Fudgets/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Abstraction leak
David Roundy wrote: On Fri, Jun 29, 2007 at 07:39:28PM +0100, Andrew Coppin wrote: Now I have a problem. It's easy enough to pass the entire data stream through an RLE decoder and feed that to the Huffman table deserialize function, and it will give be back the table. But I now have *no clue* where the table ends in the original stream! Sounds to me like you want a parsing monad. Generally, when you want state, you want a monad, and the field of parsing monads is pretty mature. You can either write up a monad of your own, or use one of the existing ones (parsec, frisby, read). Perhaps. But how do you run a parser on top of another parser? More importantly, how do you stack several parsers one on top of the other, get the top-most one to return the thing it parsed, and then make a completely different stack of parsers process the remainder? I'm sure it can be done, but... I'm having trouble wrapping my mind around that at this time of night... :-S ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Language semantics
On Friday 29 June 2007, Andrew Coppin wrote: Jon Cast wrote: On Wednesday 27 June 2007, Andrew Coppin wrote: Wow, wait a sec - case expressions are allowed to have guards too?? Yes. I guess I assumed you knew that, sorry. The only syntactic (or semantic) difference between function equations and case expressions (aside from the fact that case expressions require you to tuple up the values you're pattern-matching on) is the fact that case expressions use - where function bindings use =. Other than that, the two forms are exactly equivalent. I knew they were nearly identical. I didn't realise that they *were* identical! Hmm, I tried to find out 1 thing and actually found out 2 things! :-D I wonder what the layout for that is... something like this? case foo of patter1 | guard1 - ... | guard2 - ... pattern2 | guard3 - ... | guard4 - ... Just so. Jonathan Cast http://sourceforge.net/projects/fid-core http://sourceforge.net/projects/fid-emacs ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Updating haskell.org robots.txt
On Wed, Jun 27, 2007 at 09:42:29PM -0700, Justin Bailey wrote: Any feedback, let me know. Thanks! Thanks for looking at this, Justin! Looks fine to me. Ian ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] let vs do?
On Fri, Jun 29, 2007 at 07:26:21AM -0700, Dave Bayer wrote: On Jun 28, 2007, at 9:49 PM, Stefan Holdermans wrote: That way you would have to use monads everywhere. As you already hinted at in a later message, this has to do with let-bindings being potentially polymorphic and monadic bindings being necessarily monomorphic: Are there papers that prove this need be the case in any language, or are we simply now trapped into this for the moment by some design choices? Indeed, it is a requirement of the HM type inference system which haskell is based on (though, it goes well beyond HM in a lot of ways) Monads are in no way intrinsic to the language, they arn't part of core to begin with but simply sugar for applications and lambda bindings. So, asking whether we can drop 'let's in favor of 'do's is sort of meaningless, dos are just translated away immediately, before any typechecking. do x - f y; z is equivalent to f y = \x - z notice that the 'x' is bound by a lambda binding, the tradeoff made in the HM type system is that generalization (creating polymorphic types) only occurs on let bindings, not lambda bound ones. (ghc haskell has extensions that can lift this rule, at the expense of needing user specified types in some circumstances) monads are not core haskell, haskell just happens to be a really elegant language for expressing them, and they happen to be useful enough to haskell programmers that some nice syntatic sugar (do) is provided for convenience but that is as far as the relationship goes. That said, there is a precident (probably many, but this is the one I know) for a language whose core is based on monads rather than the lambda calculus, namely 'GRIN' the back end language used by jhc. However, the cost (and benefit) of this is that grin is first order, you cannot have closures or higher order functions, (you can think of it as C but with a true pure functional type system and all the goodness that implies). I have a toy mini-language called 'undo' (unboxed do) which I use sometimes to write things directly in it which might be kind of neat to expose to the haskell programmer one day... in any case, this isn't really relevant to your question, but speaking generally, no, monads are not core haskell, yes monads can be used as the core of a language, jhc actually does this, but not til very far down the line and it has been transformed enough that I wouldn't consider it core haskell. (in particular, the use of monads in grin have no coorespondence to the use of monads in the original haskell source) (I am being sloppy with my use of 'core' here... we need some more words) 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] ANNOUNCE: hiccup, a toy tcl impersonator in haskell
consalus: A while back I saw a toy tcl interpreter in 550 lines of C called 'picol'. I was looking for a simple language to implement in haskell, so I made my own toy tcl interpreter. It was surprisingly easy to make, thanks to the magic of Haskell and Bytestrings. :) It handles a few things incorrectly, and it is not feature complete, but I thought maybe somebody else might find it interesting. For the record (though it means nothing), my interpreter is about half the size of picol and runs about 30% faster in the few tests I've run, despite having a few more features. (it was certainly less than half the size of picol, but I keep tacking on functions when I get bored). Anyway, you can check it out at: http://code.google.com/p/hiccup/ I plan on making it more complete and faithful to tcl, but I'm branching into a different project for this one. However, any suggestions to make hiccup more efficient, elegant, or correct are certainly appreciated. Cheers, Great work! Would you like to upload it to hackage.haskell.org, so it can be found more easily? -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] advice: instantiating/duplicating modules
On Jun 29, 2007, at 10:07 AM, Nicolas Frisby wrote: I wrote a combination reader/writer monad (a la the RWS monad in the mtl) and I find myself wanting to use multiple instances of it in the same stack of transformers. The functional dependencies prevent this from working out. I found myself in a situation implementing two very similar algorithms where I had to really puzzle out how to get functional dependencies to work, and I ended up writing a class (I abridge): class (Num b, Real c) = Elem a b c | a - b, a - c where qr :: a - b - b - QR c and then declaring instances like data Rlist a = Rlist instance Integral a = Elem (Rlist a) a (Ratio a) where qr w x y = Yes (x % y) False When I wanted this version of qr, I'd call qr Rlist. Rlist is a dummy class parameter to get the functional dependencies to work, it does nothing besides select a version of my code. I couldn't get the functional dependencies to work out any other way, so I accepted this. Later, I realized that Haskell had named records, and I went back and rewrote stuff as follows: data (Num b, Real c) = Elem b c = Elem { qr :: b - b - Rem c } rlist :: Integral a = Elem a (Ratio a) rlist = Elem { qr = (\x y - Just (x % y, False)) } Now all I had to do was change the case from qr Rlist to qr rlist and the rest of my code worked exactly as before. (I love how often this sort of thing happens in Haskell.) I went from thinking that passing around a bunch of functions was kludgey, to thinking that a beginner like me using multi-parameter type classes unnecessarily was obfuscation. In any case, it didn't matter what I thought, the code either way was virtually identical. I've since done some experiments with Template Haskell, and I see that Arie Peterson has suggested how you could proceed. However, are you sure that you can't find a way to get this to work in vanilla Haskell without extensions? Or, for that matter, are you sure there isn't a way to get functional dependencies to work? (I felt pretty dumb for a little while before I found one for my problem, although as usual the issues are clear in hindsight.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Fwd: Re: [Haskell-cafe] avoiding command window with wxHaskell on Windows?
Date: Mon, 25 Jun 2007 20:19:50 -0400 To: Jens Fisseler [EMAIL PROTECTED] From: Dean Herington [EMAIL PROTECTED] Subject: Re: [Haskell-cafe] avoiding command window with wxHaskell on Windows? Cc: haskell-cafe@haskell.org, [EMAIL PROTECTED] At 10:10 PM +0200 6/23/07, Jens Fisseler wrote: On Sat, 23 Jun 2007, Dean Herington wrote: But if I double-click the .exe file, I get a command window that hangs around (but doesn't appear to do anything, fortunately) until the program terminates. How can I avoid this command window? With gtk2hs, using -optl-mwindows as a command line option for GHC lets me get rid of this window. Perhaps it will do the same for wxHaskell? Yes, that did the trick! Thanks a lot! But now I've discovered that using -optl-mwindows creates a program that doesn't work when invoked from a command line. Is there any way to create a program that can work when invoked either from a command line or through double-clicking? Dean ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Name Decoration and Undefined References
I have a very complex project that has to play nice with a lot of C code written by other people. My own code is half Haskell and half C. My build process is rather complex since I generate about 5 different libraries, some of them export Haskell routines. A supreme effort was made to try to make Haskell somewhat invisible, although ultimately it requires a lot of gcc command line work with a bunch of undefines and a links to Haskell static libraries. In the end I'm not sure if it's such a good idea and probably would be better off completing the final link stage just using ghc. In the process of doing all this I attempted to link one of my libraries to some test code written in Haskell and I proceeded to get a few unresolved links whilst running ghc. What happened is that I have a Haskell binary, lets say called foo.o generated from foo.hs that appears in two libraries say called libmyh.a and libmyc.a and that contains a Haskell function called bar. Library libmyh.a ultimately gets built using cabal and libmyc.a gets built using gcc directly. The binary is compiled twice (for complicated reasons) prior to linking to each library. However in the library libmyh.a, the bar symbol is prepended with an ascii string that contains the library name (say libmyh). However the other library shows that the symbol does not have this name decoration since it was linked directly with gcc. It appears however when trying to link against libmyc.a that ghc expects to see the original name decoration for bar. I presume this is due to some side information, perhaps what's contained in foo.hi that informs ghc what names to actually link to. I now ask the question, how can I control this process? Build tools such as CMake and Cabal seem to have their own ideas about what directories to place binaries. It seems like I need to somehow make sure that all files related to the compilation process of a given library are isolated in the same directory or something. Thus it's not enough to specify binaries on the command line of ghc, it's got to have access to some other files; I presume the .hi files. This makes things a bit confusing I'm afraid. -- View this message in context: http://www.nabble.com/Name-Decoration-and-Undefined-References-tf4003458.html#a11370409 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Name Decoration and Undefined References
SevenThunders wrote: perhaps what's contained in foo.hi that informs ghc what names to actually link to. I'm not so sure if this is correct or not. The truth is I have no .hi files in the directory I try to link my test code, and yet it's somehow finding them in the cabal created distribution directory even though I'm not using cabal for linking the test code. It's pretty baffling to me at this point. -- View this message in context: http://www.nabble.com/Name-Decoration-and-Undefined-References-tf4003458.html#a11370712 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Parsers are monadic?
First post. I'm a newbie, been using Haskell for about a week and love it. Anyway, this is something I don't understand. Parsers are monadic. I can see this if the parser is reading from an input stream but if there's just a block of text can't you just have the parser call itself recursively feeding the unparsed text down the recursion and tacking nodes onto the tree as the recursions return, finally returning the whole tree to the top level caller. Seems this meets the criteria for pure functionality, same result every time with same args. myParser :: [Char] - ParseTree Get the free Yahoo! toolbar and rest assured with the added security of spyware protection. http://new.toolbar.yahoo.com/toolbar/features/norton/index.php___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe