Re: [Haskell-cafe] Maintaining the community
Andrew Coppin <[EMAIL PROTECTED]> writes: > Mark T.B. Carroll wrote: >> Andrew Coppin <[EMAIL PROTECTED]> writes: >> >>> Just curiose, but... what does NNTP have to do with your ISP? >> >> Someone has to provide an NNTP server for your client to connect to. >> Many ISPs don't. Things like gmane can be used, of course. Some of >> the free ones can be okay. I like http://news.individual.net/ who, >> while not free, are pretty cheap, and they carry comp.lang.haskell. > > ...and when you view a web page, your web browser has to connect to a > web server somewhere. > > I don't see your point... Very many news servers will only serve news to people on the network of whoever's running the server: i.e. a rather restricted 'customer' base. If your ISP doesn't provide a decent NNTP server, you have to find one of the less discriminating servers, and there aren't many good ones around that will serve news to just anyone. Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Maintaining the community
Andrew Coppin <[EMAIL PROTECTED]> writes: > Just curiose, but... what does NNTP have to do with your ISP? Someone has to provide an NNTP server for your client to connect to. Many ISPs don't. Things like gmane can be used, of course. Some of the free ones can be okay. I like http://news.individual.net/ who, while not free, are pretty cheap, and they carry comp.lang.haskell. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Getting debugging/logging info?
"Hugh Perkins" <[EMAIL PROTECTED]> writes: (snip) >> Maybe, with System.IO, > > Fine in main :-) Less good in a 100,000 line application. Oh, sorry, I thought your point had been about making sure the operation was done before the "did something" line got printed. (-: -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Getting debugging/logging info?
"Hugh Perkins" <[EMAIL PROTECTED]> writes: > SystemLogging.LogInfo("About to do something..."); > DoSomething(); > SystemLogging.LogInfo("Did Something"); > SystemLogging.LogInfo("x is " + x ); > > How can we do something similar in Haskell? Maybe, with System.IO, main = do log <- openFile "/tmp/log.txt" AppendMode hSetBuffering log LineBuffering hPutStrLn log "About to do something..." x <- return $! product [1 .. 65536] hPutStrLn log "did something." hPutStrLn log ("x is " ++ show x) hClose log Others may now correct me. (-: -- Mark ___ 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) > (Does anybody else on this list frequently get the feeling their IQ is > just too low for Haskell??) I do. But then, when I finally understand something, it seems easy and simple and I'm not sure why it wasn't obvious all along. -- Mark ___ 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] Haskell version of ray tracer code is much slower than the original ML
Philip Armstrong <[EMAIL PROTECTED]> writes: (snip) > Why on earth would you use -fexcess-precision if you're using Floats? > The excess precision only apples to Doubles held in registers on x86 > IIRC. (If you spill a Double from a register to memory, then you lose > the extra precision bits in the process). Some googling suggests that point 2 on http://www.haskell.org/hawiki/FasterFloatingPointWithGhc might have been what I was thinking of. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell version of ray tracer code is much slower than the original ML
Philip Armstrong <[EMAIL PROTECTED]> writes: (snip) > Because the optimisation page on the haskell wiki is very explicit > about never using Float when you can use Double, that's why. (snip) Is that still true if you use -fexcess-precision ? -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbie Q: Monad 'fail' and 'error'
"Dmitri O.Kondratiev" <[EMAIL PROTECTED]> writes: (snip) > 1) What value and type 'error' actually returns in: > error "some message" ? For the purpose of type checking, error returns whatever value is expected for that expression by whatever is 'using' the value. In practice, 'error' terminates programme execution so that it evades the trouble of figuring out how to construct a return value of the correct type. > 2) How declaration > String -> m a > matches with > String -> a ? 'a' can be any type, including 'm a'. (Those are different 'a's! So I should really rename 'm a' to 'm b' when I use them in the same sentence.) > 3) In Maybe monad: > fail = Nothing > > When and how 'fail' is used in Maybe monad? A common way to think of the Maybe monad is that it represents a thing that works only if all the parts worked. If any of the parts (bound with >>=) fail, then the Nothing is contagious across bind, as the >>= doesn't have a value to feed in to the next function as its argument, and the return value of the whole thing is Nothing. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Data.Generics
Do we have a simple example somewhere of how to use gzipWithQ ? I can get things like everything and everywhere working with mkQ and mkT, but I can't work out how to make a curried query thing for gzipWithQ - I'm sure I'm missing the obvious. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Frisby grammars that have context
apfelmus <[EMAIL PROTECTED]> writes: (snip) > It's intentionally impossible. Frisby uses a dynamic programming > approach that crucially depends on the fact that the grammar in question > is context-free (actually something related, but the effect is the > same). You're trying to parse a context-sensitive language. Aha, thanks, that makes sense: I am glad that for once I wasn't missing the obvious after all. Presumably this restriction allows it to gain other benefits. I hadn't realised that the different implementations of Frisby and Parsec had such far-reaching consequences. (snip) > This not a correct Pascal program, nevertheless the parse succeeds just > fine. The missing declaration for y will be detected when processing the > abstract syntax tree further. The key point is that the shape of the > abstract syntax tree doesn't depend on whether y is declared or not. M, indeed it was a missing-declaration sort of problem I had in mind. Thanks for the example. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Frisby grammars that have context
Actually, while I'm at it, another thing I was wondering: Text.ParserCombinators.Parsec.Char offers us nice things like `lower'. However, where's this stuff in Frisby? I could use something horrific like oneOf [filter isLower [minBound .. maxBound ]] or something, but how best to get internationalisation-aware character classes into it I'm not sure. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Frisby grammars that have context
I've been playing with Text.Parsers.Frisby to see how it stacks against other options and, while it's been great so far, I am finding that I can't encode a grammar where what's acceptable depends on what's already been parsed in some nontrivial way. To take a simple example, imagine a grammar where the only lower-case letters that are acceptable are those where their upper-case equivalent occurred earlier in the text. In Parsec I'd code this sort of thing as, nextChar = do allowed <- getState char <- oneOf $ ['A'..'Z'] ++ allowed updateState (union [toLower char]) return char test = runParser (many1 nextChar) [] "" Is this supposed to not be possible in Frisby, or (quite likely) am I missing something that allows me to? I've thought about things like trying to fmap further calls to apply runPeg to rest, but I've not figured out a trick that will actually work. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] List algorithm
"Matthew Brecknell" <[EMAIL PROTECTED]> writes: (snip) > This seems to work, but presumably only because it's a boxed array, and > the construction makes no circular references. Yes. (-: > However, I'm doubtful that memoisation is really beneficial in this > function. I think it only gains a constant-factor speedup, but loses the > ability to work in constant space. I don't know. The memoised version certainly calls the bit with the list comprehension fewer times. I'd have to think about it more. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] List algorithm
[EMAIL PROTECTED] (Mark T.B. Carroll) writes: (snip) > algMemo n m = lookupMemo m > where > memo = [[]] : map helper [1..m] > lookupMemo m = if m < 0 then [] else memo !! m > helper m' = [ x : xs | x <- [1..n], xs <- lookupMemo (m' - x) ] which, I suppose, is rather like, algMemo n m = last memo where memo = [[]] : map helper [1 .. m] helper m' = [ x : xs | x <- [1 .. min m' n], xs <- memo !! (m' - x) ] -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] List algorithm
[EMAIL PROTECTED] (Mark T.B. Carroll) writes: > alg n m = > case signum m of > -1 -> [] > 0 -> [[]] > 1 -> [ x : xs | x <- [1..n], xs <- alg n (m - x) ] FWIW it's faster if you do some memoising: algMemo n m = lookupMemo m where memo = [[]] : map helper [1..m] lookupMemo m = if m < 0 then [] else memo !! m helper m' = [ x : xs | x <- [1..n], xs <- lookupMemo (m' - x) ] -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] List algorithm
"Steffen Mazanek" <[EMAIL PROTECTED]> writes: > alg 5 1 = [[1]] > alg 5 2 = [[1,1],[2]] > alg 5 3 = [[1,1,1],[1,2],[2,1],[3]] Would this be better? alg n m = case signum m of -1 -> [] 0 -> [[]] 1 -> [ x : xs | x <- [1..n], xs <- alg n (m - x) ] -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] how can I select all the 3-element-combination out of a list efficiently
Mirko Rahn <[EMAIL PROTECTED]> writes: (snip) > Correct (and more natural): > > nOf 0 _ = [[]] > nOf n (x:xs) = map (x:) (nOf (n-1) xs) ++ nOf n xs > nOf _ [] = [] Thanks very much - in both claims you're indeed correct. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] how can I select all the 3-element-combination out of a list efficiently
geniusfat <[EMAIL PROTECTED]> writes: (snip) > the order does not matter and each object can be chosen only once. (snip) In that case, with the help of Data.List.tails, one can do: threeOf :: [a] -> [(a,a,a)] threeOf xs = [ (p,q,r) | (p:ps) <- tails xs, (q:qs) <- tails ps, r <- qs ] (the r <- qs is a simpler version of (r:rs) <- tails qs) or maybe, nOf :: Int -> [a] -> [[a]] nOf _[] = [] nOf 1xs = map return xs nOf n (x:xs) = map (x:) (nOf (n-1) xs) ++ nOf n xs (These are fairly naive versions that just took me a few minutes, but perhaps they'll do.) -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Monad pronounced like gonad?
Andrew Coppin <[EMAIL PROTECTED]> writes: (snip) > More curiosely, that (>>=) function. Why is the Haskell name for it > (>>=), and why is it pronounced "bind"? Neither of these choices make a > lot of sense to me... (snip) I don't know the answer, but it seems okay to me because I think of monads as being about sequenced computation with >> indicating the flow from return value of one going into the arguments of the next, and the = indicating that we do bother making a constant equal to that return value as an argument in the next (it's on the next's side of the >>) instead of throwing it away. The functions are bound together (hence 'bind') by the >> or >>= as being consecutive steps in the sequence of the computation we are doing. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Any Haskellers anywhere? (was Re: Any Haskellers in St Louis, MO?)
Maybe we could use a page on the wiki to note who'd be interested in meeting up and where they all live? -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Tutorial on Haskell
Bryan O'Sullivan <[EMAIL PROTECTED]> writes: > Mark T.B. Carroll wrote: > >> I'm afraid no >> examples come easily to mind, though. > > Here's a simple one: reading a flattened graph from disk. If your > flattened representation contains forward references, you have to fix > them up in a strict language. In a lazy language, you can refer to > elements you haven't yet read, eliminating that book-keeping. That's a good point. Indeed, I had used laziness in a programme that read a file that contained a series of entity definitions that could include forward references, I just couldn't remember exactly how I'd used laziness. (-: (It's also useful in some memoising, I think.) -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Tutorial on Haskell
"Neil Mitchell" <[EMAIL PROTECTED]> writes: (snip) > I think its important to cover whats different about Haskell. Things > like laziness are cool, but are harder to convince a strict programmer > that they are useful. (snip) Mmmm, it took me a while to really find laziness useful, and that was normally to let me create complex things that were mutually dependent on each other, releasing me from some housekeeping - some calculation in one would help the other creep along, and vice versa. I'm afraid no examples come easily to mind, though. BTW, I wonder if it's too much difficulty to show off STM. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: k-minima in Haskell
Dan Weston <[EMAIL PROTECTED]> writes: > Ah, but which k elements? You won't know until you've drained your > entire stream! True, but you still don't need to keep the whole stream in memory at once, just the k-least-so-far as you work your way through the stream - once you've read a part of the stream you can mostly forget it again. The question as I understood it was one of if even in Haskell there's a better way than sorting that means you need only have a fragment of the stream in memory at once. -- Mark ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why Perl is more learnable than Haskell
Sorry to hear of your struggles. There has been a lot of work lately on writing Haskell tutorials but there's still a long way to go, unfortunately, as I discovered when I tried recently to find the collection of sample code fragments on the wiki that I'm sure are around somewhere. I had the advantage of coming to Haskell after already having used ML and Common Lisp. But, FWIW, I found it worth persevering: I liked a lot of my legacy Perl scripts more after I ported them to Haskell and now I use Haskell for the sort of thing I might have used bash or perl for previously. (For instance, on the way home last night my GPS' NMEA-0183 data was odd enough that I used Haskell to write a simple daemon that sits between clients and my gpsd and rewrites their conversation; previously, I'd have used Perl for that.) Though, it helps if you get on well with Perl. It didn't suit me very well so I had more motivation to switch than you might. But, now, by choice, I do use Haskell for the kind of thing I'd have previously used a short script for instead, so there might still be light at the end of the tunnel for you. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Weaving fun
"Bas van Dijk" <[EMAIL PROTECTED]> writes: > weave [[1,1,1], [2,2,2], [3,3]] ==> [1,2,3,1,2,3,1,2] > weave [[1,1,1], [2,2], [3,3,3]] ==> [1,2,3,1,2,3,1] > > Note that 'weave' stops when a list is empty. My naive implementation is, weave [] = [] weave ([]:_) = [] weave (x:xs) = head x : weave (xs ++ [tail x]) It's at least brief! -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Lambada and connecting Haskell to a Weblogic server
Adam Megacz <[EMAIL PROTECTED]> writes: > You should check out Brian Alliet's LambdaVM: > > http://www.cs.rit.edu/~bja8464/lambdavm/ That looks very interesting. We'd been wondering if there was some route from GHC core to Scheme through Bigloo or Kawa to the JVM, but something more direct is nicer. Is it easy to create Haskell stubs (in the IO monad, presumably) for standard Java libraries so that your compiled-to-JVM Haskell code can easily use the usual Java APIs like Swing? One source of vexation for us is mapping between Java types and Haskell types. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] how to calculate the sum of list of lists?
"Miranda Kajtazi" <[EMAIL PROTECTED]> writes: > Help, > > How to calculate the sum of list of lists in Haskell? So the answer for [[1,2],[3,4]] would be 10? (Is this homework? If so, we're still happy to give hints.) -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Channel9 Interview: Software Composability and theFu ture of Languages
Magnus Therning <[EMAIL PROTECTED]> writes: > Now, correct me if I'm wrong, but you see a "natural" ordering in your > haskell expressions, right? Right. > However the compiler/interpreter > has to choose a sequence in order to arrive at a result, since that's > how today's computers work. (Choosing well can be seen as optimisation > :-) Right. Ah, I may see my confusion then - I do see a natural ordering in my Haskell expressions, and indeed evaluation order could be different so long as the end result is the same, but I don't find that different to imperative languages - I would expect modern compilers to reorder statements if they can get better results out of it without affecting the answer. (E.g., if I specify a set of assignments where some reordering leaves the answers unchanged, but clusters uses of values better so that the dataflow is such that they can stay in registers, I'd expect the compiler to go ahead - so even where I do specify evaluation order in C or whatever, I don't particularly expect the compiler to respect that in cases where I won't notice that it didn't.) -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Channel9 Interview: Software Composability and theFu ture of Languages
Magnus Therning <[EMAIL PROTECTED]> writes: (snip) > Sequential thinking would be related to procedural programming, that is > ordering of statements are important but there's no state. Functional > programming is declarative, no order and no state. So, to be strict I'd > say that sequential form _is_ non-functional. At least if FOLDOC is > correct and I read and understood things properly. (snip) You've completely lost me here. Order is /very/ important in functional programming. Consider function composition: Prelude> ((+1) . (*2)) 5 11 Prelude> ((*2) . (+1)) 5 12 There we have sequencing, and the computation has intermediate state. There's nothing non-functional about the above. (snip) > The world has state! Just see what a "stink" that has created in the > pure functional language camp! (snip) Mmmm. Monads deal with that very nicely, I think, but there's a way to go yet. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.Generics question
Hmmm. That's interesting. I have a slightly different problem and I don't know if it's relevant or not. I have nested algebraic data types for things like expressions with terms and operators and whatever too, and some of my functions do a transformation that removes all instances of particular constructors (by expressing them in other ways) but that leaves most of the data structure intact. I'd love to use the type system to enforce the constraint that the result from the transformer function has eliminated occurrences of certain constructors within the nested type, but to do that I seem to have to create a whole other near-copy of the data declarations with slightly different names and the occasional constructor missing. I wonder if there's a better way. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: A suggestion for the next high profile Haskell project
Bulat Ziganshin <[EMAIL PROTECTED]> writes: (snip) > Haskell can't provide fast execution speed unless very low-level > programming style is used (snip) Is that an intrinsic feature of the language, or could compilers' optimisation plausibly get clever enough to do well without lots of seq and explicit unboxings and suchlike? -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Stratified monads
I was interested to read David Espinosa's "Stratified Monads" paper at http://www-swiss.ai.mit.edu/~dae/papers/sm.ps.Z I'm not sure I actually understand them properly yet, but I'm already curious about if anybody's played with them in Haskell, or how useful it would be to do so. Any comments? -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Binary code
escafia <[EMAIL PROTECTED]> writes: > Hi, > > i've one fuction receiving an int . The objective is return the respective > binary code of that int. > > For example, if i receive 28 the fuction will return 011100. In GHCi, Prelude> Numeric.showIntAtBase 2 (head . show) 28 $ "" "11100" > My question is that there is any fuction in libraries that do this? > If not, anyone has any suggestion? Other alternatives include, import Data.Bits import Data.List toBinary 0 = "0" toBinary i = reverse (unfoldr nextDigit i) where nextDigit 0 = Nothing nextDigit i = Just (head (show (i .&. 1)), shiftR i 1) or maybe, as you seem to want a certain number of digits, toBinary d i = concatMap show [ fromEnum (testBit i n) | n <- reverse [0..d-1] ] or likewise will work. It's probably best to just use showIntAtBase and pad it with however many 0's you want, though. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Priority Queue?
"Ken Takusagawa" <[EMAIL PROTECTED]> writes: > Is there a Haskell implementation of an efficient priority queue > (probably heap-based) out there that I can use? I do not see it in > the GHC libraries. ISTR Okasaki's algorithms book has a suitable one. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: best Linux for GHC?
Max Vasin <[EMAIL PROTECTED]> writes: > Yes, but I wouldn't recommend installing rpms in debian-based system > (although, it can work perfectly). GHC 6.6 is in Debian unstable > (and should be in Ubuntu 6.10 or development branch). Ubuntu universe > repositiry is automatically updated from Debian repos thus being > one of the largest repos for Linux. > > PS: I'm using Debian testing/unstable. How up to date will Debian unstable's GHC be kept, though? It seems pretty good at the moment, but there have been times when we've had to install from source instead of via Debian earlier this year so that we had GHC features and bugfixes in place - the Debian version has got rather out of date at times with respect to stuff we needed. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Announcements list
"Diego Navarro" <[EMAIL PROTECTED]> writes: > There should be a separate, moderated Haskell-announcements list. I > filter out haskell-cafe into a folder and read it separately from my > main inbox, but I'd like to have important announcements directly into > my inbox, and haskell@haskell.org still has some chatty > questions-and-answers sessions. Making haskell@haskell.org moderated might be the answer? -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] split string into n parts
jim burton <[EMAIL PROTECTED]> writes: (snip) > *Main> fifths "IDOLIKETOBEBESIDETHESEASIDE" > "IDOLI KETOBE BESIDE THESEA SIDEXX" > *Main> fifths "12345" > "1 23 45" (snip) FWIW this unholy thing works for me, fifths :: String -> String fifths = splitIntoN 5 splitIntoN :: Int -> String -> String splitIntoN n string = let stringToSplit = string ++ replicate (n-1) 'X' in unwords (map fst (take n (tail (iterate (splitAt (div (length stringToSplit) n) . snd) (undefined, stringToSplit) Admittedly, a 'let' might be nice to name some intermediate computations. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] split string into n parts
jim burton <[EMAIL PROTECTED]> writes: > I want to split a string into 5 parts of equal length, with the last fifth > padded if necessary (snip) > *Main> fifths "12345" > "1 23 45" What's the correct answer for fifths "123456"? I can't figure out how to meet both your constraints. Is "12 34 56 XX XX" permitted (padding before fifth as well)? -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] cutting long strings into lines
Bertram Felgenhauer <[EMAIL PROTECTED]> writes: (snip) > I'll venture a guess: The code originally read > > | bestSplit width string = > | let wraps = options string > | in last (head wraps : takeWhile ((<= width) . length . fst) wraps) (snip) Version control agrees with you. Next time I'll try compiling whatever version I find at hand before posting. I knew it worked at one time ... (-: -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] cutting long strings into lines
I've been doing it as the enclosed. I wrote it a while ago, though, and haven't really looked too hard at it since. -- Mark module WordWrap (wrap) where import Data.Maybe options :: String -> [(String, String)] options [] = [("", "")] options (x:xs) = let rest = map (\(ys, zs) -> (x:ys, zs)) (options xs) in if x == ' ' then ("", xs) : rest else rest bestSplit :: Int -> String -> (String, String) bestSplit width string = last (head wraps : takeWhile ((<= width) . length . fst) (options string)) wrap :: Int -> String -> [String] wrap _ "" = [] wrap width string = let (x, ys) = bestSplit width string in x : wrap width ys ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Why Not Haskell? (sidenote on licensing)
Stefan Monnier <[EMAIL PROTECTED]> writes: (snip) > Doesn't sound credible. You're free to write and sell a program whose > source code is exactly the same as Emacs's (or PowerPoint for that matter) > as long as you can show it was pure accident (snip) It's kind of hard to be sure that you'll be able to show that, though, especially if the other code was available to you. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] a bunch of newbie questions
Janis Voigtlaender <[EMAIL PROTECTED]> writes: (snip) > Yes, as long as enough type information is provided for the > typechecker to decide what is the correct instance to use. (snip) I've always been a little surprised when this doesn't happen more widely for things other than instances. For instance, when IntMap.size, Map.size and Set.size (or whatever) are all in scope as "size", it should be fairly obvious what (size x) is about once we've inferred, for other reasons, that x is an IntMap. Similarly with records, if we had field names that cause functions for extracting the value of those fields, where we used the same field name in two different record types, I figure that there's usually no ambiguity because we can usually infer the type of the object to which the 'extractor' is being applied. Am I just not seeing the big picture, or would people not find this use of type information to resolve such ambiguities as nice as I would, or is it harder to do that than I'm expecting? -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Memoizing longest-common-subsequence
I wanted a longest common subsequence function and a bit of Googling failed to turn up a functional one, except for in a scary bit of darcs. So, I tried making a memoized functional version of the LCS delta algorithm on the problem's Wikipedia page. It's not the fastest, but it's simple and should be polynomial, growing with the product of input sequence lengths. I've not played with unboxing or strictness here yet, but with the help of Data.Array I have: longestCommonSubsequence xs ys = let lastIndex = (length xs, length ys) memo = array ((0, 0), lastIndex) [ ((xi, yi), deltaLCS (xi, x) (yi, y)) | (xi, x) <- zip [0..] (undefined : xs), (yi, y) <- zip [0..] (undefined : ys) ] deltaLCS (0, _) _ = (0, []) deltaLCS _ (0, _) = (0, []) deltaLCS (xl, x) (yl, y) = if (x == y) then let (xylShrunk, xysShrunk) = memo ! (xl-1, yl-1) in (xylShrunk + 1, x : xysShrunk) else let xaShrunk@(xlShrunk, _) = memo ! (xl-1, yl) yaShrunk@(ylShrunk, _) = memo ! (xl, yl-1) in if xlShrunk > ylShrunk then xaShrunk else yaShrunk in reverse (snd (memo ! lastIndex)) I haven't looked much at optimizing this further so there are probably yet some easy wins to be had - I'd be interested to see what they are. Still, I thought it worth sharing as an example of laziness making memoization easy in a simple functional longest common subsequence example. Take this as your cue to point out the much better LCS algorithm that already exists in the standard libraries, that I couldn't find. (-: -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Comma in the front
Jon Fairbairn <[EMAIL PROTECTED]> writes: > a:: > b:: > c:. > > but when I suggested this at a Haskell meeting, Simon PJ > complained that it "looks like hopscotch". I've never quite > understood that complaint! http://blogs.salon.com/0002296/myimages/hopscotch.jpg and http://www.northshield.org/officers/seneschal/moy/games/hopscotch.gif suggest to me that the pattern of : and . going up in a row is a bit like the squares along the linear 'course' (or list (-:) where sometimes you get one and sometimes two. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Infinite loop?
Barbier de Reuille Pierre <[EMAIL PROTECTED]> writes: (snip) > And how can you, in Haskell, detect symbolic links ? I use System.Posix.Files. getSymbolicLinkStatus is like lstat(2) under Unix. It returns a value to which you can apply the isSymbolicLink predicate. Of course, you can't be sure the file won't change in between you checking and you acting on that result. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Matching constructors
Creighton Hogg <[EMAIL PROTECTED]> writes: > data Patootie = Pa Int | Tootie Int > and I want to pull out the indices of all elements of a list > that have type constructor Tootie, how would I do that? x = [Pa 3, Tootie 5, Pa 7, Tootie 9, Pa 11] y = [ i |Tootie i <- x ] z = [ i | i@(Tootie _) <- x ] y or z might be helpful. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: [Haskell] Simple IO Regions
Brandon Moore <[EMAIL PROTECTED]> writes: (snip) > The term I've heard is "skolem constant", which is a freshly invented > thing distinct from everything else. (snip) There's a nice easy-going example in chapter 8 of http://www.cl.cam.ac.uk/Teaching/2000/LogicProof/notes.pdf where quantifiers are removed from first-order formulae. (this aside moved from haskell to haskell-cafe) -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learning Haskell
Jimmie Houchin <[EMAIL PROTECTED]> writes: (snip) > I have been perusing the haskell.org site and reading some of the > tutorials. I just didn't want to expend lots of time just to find out > that my math skills were woefully inadequate. I am grateful to learn (snip) Right. My math background isn't good enough for me to understand (without much effort) some of the list traffic here - there's a lot I'm still wrapping my head around. With much of the Haskell I've figured out, I've done so by studying examples of others' code. Still, the Haskell I do know is more than enough for me to do plenty of things with, and it certainly covers everything I'd normally have coming to mind from my use of other languages. > The reason I asked about programming in the small, was my desire to > spend my time and energy in a single direction. The ability to move what > I do in Python to Haskell aids in that goal. It also promotes my (snip) Yes. I've ported a number of little Perl and bash scripts to Haskell with very pleasing results. (Most recently, a little script that does AUTHINFO GENERIC authentication by MD5 to an NNTP server.) It's even quite easy to slap together little one-off programs once you're comfortable with using "do" and the IO monad (which is pretty easy for single-threaded stuff, and forkProcess works nicely too IMLE). -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Typeclass problem
On Thu, 29 Jul 2004, Bjorn Bringert wrote: (snip) > You could use asTypeOf from the Prelude: > > let foo = maxBound `asTypeOf` x Ah. I should re-read the Prelude every couple of months. (-: Thanks! > Also, Hugs and GHC both support an extension which lets you put type > annotations in patterns: > > showThings (x::c) = > let foo = maxBound :: c >in (show x, show foo) That's cool. Is it something that's likely to be in the next standard, then? Or does it make more sense to have the type variables in the function's type signature be in scope in the function definition itself? -- Mark ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Typeclass problem
I have a little programme that doesn't compile: module Example where class (Show c, Ord c, Bounded c) => MyClass c showThings :: MyClass c => c -> (String, String) showThings x = let foo = maxBound :: c in (show x, show foo) If I change that second-to-last line to, let foo = max x maxBound then it compiles. However, it's clearly silly to use "max" just to make the type of the maxBound be the same type as the x. (I'm assuming that the Ord and the Bounded instances of the type are sensibly consistent.) What should I be writing if I want foo to be the maxBound applied to the type that x is? -- Mark ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
JVM bridge
With haskell-jvm-bridge-0.2.1 I get: ghc -package javavm HelloWorld.o HelloWorld_JVM.o Class_java_io_PrintStream.o Class_java_lang_System.o -o HelloWorld gcc: unrecognized option `-rpath' gcc: unrecognized option `-rpath' gcc: unrecognized option `-rpath' /usr/bin/ld: cannot open /usr/lib/jvm-bridge/lib/: File format not recognized $ ld --version GNU ld version 2.12.90.0.1 20020307 Debian/GNU Linux Copyright 2002 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License. This program has absolutely no warranty. $ gcc --version 2.95.4 $ ghc --version The Glorious Glasgow Haskell Compilation System, version 6.2 I don't suppose anyone can hand-hold me through tracking this problem down? -- Mark ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Sets
Am I right in thinking that sets of sets don't really work with GHC's Data.Set because "Set a" things aren't instances of Ord? How should I do sets of sets with it? (e.g. Set.mkSet [Set.unitSet 1] gives "No instance for (Ord (Set a))") -- Mark ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Data structure definitions
I have a program that basically has, data Expression = Value Value | EVariable Variable | other stuff ... data Value = VNumber Number | other stuff ... data Variable = Variable { variable_name :: String, variable_time :: Expression } data Number = Number { value :: Double, dimension :: Dimension } newtype VariableCount = VariableCount (Variable, Number) The VNumber and EVariable constructors are ugly, though, so I was wondering if I should be using typeclasses - e.g., class Expression a class Expression a => Value a instance Value Number instance Expression Variable ... but I don't see how to define Variable in such a scheme. Maybe I shouldn't be using typeclasses? (Obviously, I actually have lots more type constructors in Expression and Value - dyadic expressions, booleans, etc. - the above with just numbers and variables is somewhat truncated, but should suffice.) -- Mark ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe