Re: [Haskell-cafe] ANN: FallingBlocks 0.1
bwsanders: Hello, I just uploaded fallingblocks to Hackage. It is another Tetris clone, but it uses SDL, and I thought there could be more SDL examples. Any and all comments and suggestions will be extremely appreciated! There is a darcs repo at http://patch-tag.com/publicrepos/fallingblocks screenshots and a wiki page plz? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: about Haskell code written to be too smart
2009/3/27 Achim Schneider bars...@web.de: wren ng thornton w...@freegeek.org wrote: Colin Adams wrote: 2009/3/25 wren ng thornton w...@freegeek.org: when I look up the Haddock-generated documentation for a function, I DON'T appreciate it if that is in the form of a hyperlink to a research paper. And that occurs in several of the libraries shipped with GHC for instance. A reference to a research paper is fine to show where the ideas came from, but that is not where the library documentation should be. Yeah, that's bad. 'Documentation' like that should be corrected with Extreme Prejudice. I think I agree with that (I say I think, as I'm not sure what Extreme Prejuidice means). The main problem with research papers as documentation is the papers usually being outdated wrt. the current library version: Literate Haskell is utterly underused. That's surely a problem, and a significant one. But what irks me is the time taken to find one small piece of information (how to use a single function). I would guess on average about the time to read 1/3 of the paper (since the back matter needn't be examined). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Grouping - Map / Reduce
Well, this approach has the problem that the running sum of key k blocks until a new value for that k arrives in the input stream. If you wanted to know the sum of the values of each key after you got nelements in the input stream, we could change the valuesWithKey inner function into: runningSumsOfValuesPerKey :: (Eq k, Num v) = [k] - [(k, v)] - [[v]] runningSumsOfValuesPerKey allPossibleKeys = runningSums . allValuesPerKey where runningSums = map (scanl (+) 0) allValuesPerKey pairs = [ valuesWithKey key pairs | key - allPossibleKeys ] valuesWithKey key = map (\(k,v) - if k==key then v else 0) then map (!!n) on the result of runningSumsOfValuesPerKey gives you the sum after n elements arrived. I think if you now generalize this so you don't use 0 but mempty, mconcat and other Monoid methods, that you might get something like Luke's trie solution, not sure, Luke is a fair bit smarter than I am :-) But this code is very inefficient I'm afraid, I guess the blueprint stuff that was posted really builds a map incrementally, but I don't understand that yet. Ik spreek Nederlands ja ('t is te zeggen, Antwerps). Yes I'm still learning Haskell, but I think with Haskell this is a never ending process, since there's soo much stuff to discover and the language evolves (which makes it both exciting and frustrating, but that's the dilemma of knowledge anyway, the more you know the better you realize the vast amount of knowledge that you don't know yet :-) On Fri, Mar 27, 2009 at 12:53 AM, Guenther Schmidt gue.schm...@web.dewrote: Dear Peter, wow, thanks, this is a very ... interesting ... approach, I hadn't thought about that yet ;) Ben je nederlands? In case you'd be interested to share the road to Haskell experience with another newbie just ask. Günther Peter Verswyvelen schrieb: I'm also learning Haskell so the solution below might be (1) inefficient and (2) incorrect, but hey, let's give it a try :-) For simplicity, in the testing code, I assume an infinite list of key/value pairs where they keys are of type Char between 'a' and 'z' and the values are Integers (the code also seems to work for keys with just a lower bound but no upper bound) I think the code speaks for itself import System.Random runningSumsOfValuesPerKey :: (Eq k, Num v) = [k] - [(k, v)] - [[v]] runningSumsOfValuesPerKey allPossibleKeys = runningSums . allValuesPerKey where runningSums = map (scanl (+) 0) allValuesPerKey pairs = [ valuesWithKey key pairs | key - allPossibleKeys ] valuesWithKey key = map snd . filter ((==key) . fst) -- Testing randomPairs :: [(Char, Integer)] randomPairs = zip keys values where keys= randomRs ('a','z') rnd1 values = randomRs (0,9) rnd2 (rnd1,rnd2) = split (mkStdGen 0) test = map (take 10) [rs `atKey` 'c', rs `atKey` 'z'] where rs = runningSumsOfValuesPerKey ['a'..] randomPairs xs `atKey` k = xs !! (fromEnum k - fromEnum 'a') ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Exception handling in numeric computations
Thanks a lot for the answer! On Thu, Mar 26, 2009 at 4:36 PM, John Lato jwl...@gmail.com wrote: Languages with checked exceptions usually use them for two purposes: 1. Exceptional conditions - disk full, CPU on fire, etc. 2. Error handling - invalid arguments to a function, attempt to invert non-invertible matrix, etc. Is there any good rule someone can use to decide whether it is error or exception? For me, this is the most important thing, because IMHO you (as library writer) often can't say what is it, it's up to client of your code to decide. Henning T., FYI your constant advocacy has gotten at least one person around to this view. Can you please provide me some links about error/exception separation? Gregory ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Grouping - Map / Reduce
Hello What do you think of this? There is perhaps a recursive call that should be made tail recursive but it seems to work. The 'group' function takes the list of pairs as input and outputs a list of maps from key to sums. The nth element of the list of maps corresponds to the grouping applied for the elements 0n of the input list of pairs. Thus, that also works on infinite list. Unless I am missing sth... import Data.Map (Map) import qualified Data.Map as Map group :: [(Int,Int)] - Map Int Int - [Map Int Int] group [] amap = [] group ((k, v):t) amap = newmap : group t newmap where newmap = (Map.insertWith (+) k v amap) l = [(1,1), (2,10), (1,2), (2,11), (1,3), (2,12)] r = group l Map.empty rr = take 2 r li = concat [ [(1,i), (2, 10*i)] | i - [0..] ] ri = group li Map.empty rri = take 20 ri Regards J-C ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Use unsafePerformIO to catch Exception?
On Thu, 26 Mar 2009, wren ng thornton wrote: Functions like uncons and viewL are nicer (because they're safe), but they can have overhead because they're unnecessarily complete (e.g. the Maybe wrapper can be avoided if we know a-priori that Just will be the constructor used). If you know, it's always Just, then don't use Maybe. There must be some point in your program, from where it is sure, that it is always Just and that is the point where to leave Maybe. When I searched my old code for fromJust and head and review it carefully, I could eliminate them in most cases. In another thread (Grouping - Map/Reduce) there was a zipWithInf function which needed a lazy pattern match on (a:as). This indicates to me, that lists are the wrong data structure and it would be better to replace it by an always infinite list type with only one 'cons' constructor. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Use unsafePerformIO to catch Exception?
wren ng thornton wrote: The type of head should not be [a] - a + Error, it should be (a:[a]) - a. With the latter type the compiler can ensure the precondition will be proved before calling head, thus eliminating erroneous calls. Yes, but you know and I know that's not haskell. I'm talking about haskell. In haskell - a language which does not fully support dependent types - head is both necessary and useful. It's a static error, detectable statically, and yet it's deferred to the runtime. I'd much rather the compiler catch my errors than needing to create an extensive debugging suite and running it after compilation. It is not detectable statically. It is only detectable statically for a class for programs. Admittedly, for that class of programs, ndm's fine tool Catch is a very clever thing. Is this not the promise of purity? No. Purity and partiality are orthogonal. Nobody promised pure languages would be total. Functions like uncons and viewL are nicer (because they're safe), but they can have overhead because they're unnecessarily complete (e.g. the Maybe wrapper can be avoided if we know a-priori that Just will be the constructor used). uncons and viewL are totally irrelevant. They're just a convenient syntax around case matching. Jules ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Exception handling in numeric computations
Jonathan Cast wrote: Sure. Which also points out that the original safeDiv wasn't actually safe, since there's no guarantee of what evaluate will do with x and y. (Actually, there's not much guarantee of what evaluate does anyway --- just that any errors in e's definition get turned into exceptions by the time evaluate e finishes running, or don't turn into exceptions at all). That is not true if you mean any errors as any and all errors. The 'evaluate' operation only forces the argument into weak head normal form (WHNF) not normal form (NF). Thus 'evaluate' may succeed and then its return value could be examined further and only then trigger an exception. I could easily define a new Integral type where WHNF is not NF and demonstrate the problem. The solution is to use 'evaluate' only on known primitive types like Int, or on polymorphic data constrained to be NFDATA and use the 'rnf' strategy within the call to 'evaluate'. -- Chris ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] toSelem takes no format parameter
Sterling, the toSElem function of ToSElem does not take a parameter that allows specification of e.g. the locale that shall be used for rendering a specific attribute. If one wants to change this, one also has to change setAttribute and the like. Do you have any plans to extend HStringTemplate in this way? Schöne Grüße Torsten Kemps-Benedix (Geschäftsführer) SKS Unternehmensberatung GmbH Co KG Geheimrat-Hummel-Platz 4 D-65239 Hochheim am Main Germany M +49.163.36017.01 T +49.700.36017.000 F +49.700.36017.011 torsten.kemps-bene...@sks-ub.de blocked::mailto:torsten.kemps-bene...@sks-ub.de http://www.sks-ub.de blocked::http://www.sks-ub.de/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: about Haskell code written to be too smart
Colin Adams colinpaulad...@googlemail.com wrote: 2009/3/27 Achim Schneider bars...@web.de: wren ng thornton w...@freegeek.org wrote: Colin Adams wrote: A reference to a research paper is fine to show where the ideas came from, but that is not where the library documentation should be. Yeah, that's bad. 'Documentation' like that should be corrected with Extreme Prejudice. I think I agree with that (I say I think, as I'm not sure what Extreme Prejuidice means). Shoot err... rewrite before asking. If in doubt, annihilate. Considering all options, just do it. Pity is a thing for judges, not hackers. Something along those lines. The main problem with research papers as documentation is the papers usually being outdated wrt. the current library version: Literate Haskell is utterly underused. That's surely a problem, and a significant one. But what irks me is the time taken to find one small piece of information (how to use a single function). I would guess on average about the time to read 1/3 of the paper (since the back matter needn't be examined). Hm. Yes. OTOH, I very much appreciate background information, it usually contains very insightful information about the overall idea and behaviour of a library. I'm by no means a domain expert for any and every library I want to use. In school, we were required to write both user[1] as well as developer[2] documentation alongside to commenting our code. I tended to loathe it, but it's very, very sensible in retrospect. There was some discussion a while back here on the cafe about enabling users to write additional documentation into a wikised hackage; together with an #haskell-doc-tutor irc channel, we could have an excellent solution to both lacking documentation as well as newbies not being sure were to start and/or intimidated by pointless usage of (.). Additionally, you get the chance of earning credits and naming and shaming Haskell's godfathers[1]. [1] In the sense of using the code, either as app or library [2] In the sense of editing/reading the code. Understanding [2] usually involves understanding [1]. [3] Judging from his code, I guess dons' apartment looks just like mine: Lots of left-over bits lying around that you tend to stumble over and are unsure about why they are still there. I swear, someday I'm going to use those two 5 1/4 floppy drives... -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or quoting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Exception handling in numeric computations
On Fri, Mar 27, 2009 at 10:01 AM, Gregory Petrosyan gregory.petrosyan+hask...@gmail.com wrote: Thanks a lot for the answer! On Thu, Mar 26, 2009 at 4:36 PM, John Lato jwl...@gmail.com wrote: Languages with checked exceptions usually use them for two purposes: 1. Exceptional conditions - disk full, CPU on fire, etc. 2. Error handling - invalid arguments to a function, attempt to invert non-invertible matrix, etc. Is there any good rule someone can use to decide whether it is error or exception? For me, this is the most important thing, because IMHO you (as library writer) often can't say what is it, it's up to client of your code to decide. An exception is caused by some sort of interaction with the run-time system (frequently a hardware issue). The programmer typically can't check for these in advance, but can only attempt to recover after they've happened. An error is some sort of bug that should be fixed by the programmer. There is some overlap for certain cases, notably divide by 0. Dividing by 0 is an error, because it's something that the program should never do, and it can be detected and dealt with by the programmer in advance. However most systems allow the divide function to be called with a 0 denominator. The function has a precondition, meaning the onus is on the programmer to not do it, however this is not enforced by the language. If a program does this in error, the result is an exception because the result is not a valid number (this is codified with NaN for IEEE floats). In this case, a programming error results in an exception. The proper solution is to fix the source of the problem, the error, instead of trying to clean up the results. Henning T., FYI your constant advocacy has gotten at least one person around to this view. Can you please provide me some links about error/exception separation? http://haskell.org/haskellwiki/Error http://haskell.org/haskellwiki/Exception ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Exception handling in numeric computations
On Fri, 2009-03-27 at 12:24 +, Chris Kuklewicz wrote: Jonathan Cast wrote: Sure. Which also points out that the original safeDiv wasn't actually safe, since there's no guarantee of what evaluate will do with x and y. (Actually, there's not much guarantee of what evaluate does anyway --- just that any errors in e's definition get turned into exceptions by the time evaluate e finishes running, or don't turn into exceptions at all). That is not true if you mean any errors as any and all errors. No, that's not what I mean. I just couldn't think of a good phrasing for `errors that would prevent e from being evaluated to HNF'. Which is still a lousy phrasing. jcc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] typeOf for polymorphic value
Hi Lennart, This is not a real solution, but maybe helpful. The hint package (wrapping the ghc API) has its typeOf: cabal install hint import Language.Haskell.Interpreter runInterpreter (typeOf \\x - x) Right t - t Best, Roland On Wed, Mar 25, 2009 at 7:33 PM, Lennart Augustsson lenn...@augustsson.net wrote: Using Data.Typeable.typeOf we can get a representation of the the type of a monomorphic value, for instance Prelude Data.Typeable typeOf not Bool - Bool But if we try using it on a polymorphic value it fails Prelude Data.Typeable typeOf id interactive:1:0: Ambiguous type variable `a' in the constraint: `Typeable a' arising from a use of `typeOf' at interactive:1:0-8 Probable fix: add a type signature that fixes these type variable(s) And understandably so. Does anyone know of a trick to accomplish `typeOf id'? Using something else than TypeRep as the representation, of course. Any tricks and existing language extensions are welcome. (As ghc moves towards first class polymorphic values this question gets more interesting.) -- Lennart ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- http://roland.zumkeller.googlepages.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Really need some help understanding a solution
Guys, I appreciate the contribution but I'm now more confused than ever :) On the Co-Induction-whatever thingy: Thanks, that's certainly something interesting and I'll try to find out more about it. But it looks like none of all the proposals offers a true solution, at least none from start to finish. The amount of data is large, but finite. So for now, I'll just stick with my initial approach as I'm running out of time. Günther ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: wxAsteroids 1.0
On Thu, 26 Mar 2009 20:41:57 +0100, Henk-Jan van Tuyl hjgt...@chello.nl wrote: Your space ship enters an asteroid belt, try to avoid collisions! wxAsteroids is a game demonstrating the wxHaskell GUI. More about this at: http://www.haskell.org/haskellwiki/wxAsteroids Maybe I should add more informationn to this: The main purpose of this game is to learn how to use wxHaskell; it also shows, in the main function, how a cabalized program can find its data files. I don't want to take the credit for this program; I took the source code and images from the paper: wxHaskell - A Portable and Concise GUI Library for Haskell [1] by Daan Leijen. If you want to learn how to use wxHaskell, I can advise you to read this paper. Daan gave me permission to publish the code with a BSD license. [1] http://legacy.cs.uu.nl/daan/download/papers/wxhaskell.pdf -- Met vriendelijke groet, Henk-Jan van Tuyl -- http://functor.bamikanarie.com http://Van.Tuyl.eu/ -- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Really need some help understanding a solution
How do you plan to consume the running sums of these data? How many different keys do you have? If all pure stuff fails, you can always revert to imperative techniques, using a mutable arrayhttp://www.haskell.org/ghc/docs/6.6.1/html/libraries/base/Data-Array-ST.htmlor something :) On Fri, Mar 27, 2009 at 3:18 PM, GüŸnther Schmidt gue.schm...@web.dewrote: Guys, I appreciate the contribution but I'm now more confused than ever :) On the Co-Induction-whatever thingy: Thanks, that's certainly something interesting and I'll try to find out more about it. But it looks like none of all the proposals offers a true solution, at least none from start to finish. The amount of data is large, but finite. So for now, I'll just stick with my initial approach as I'm running out of time. Günther ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Conditional compilation
I am writing some code for citation support in gitit, and all the #ifdefs I'm using to do conditional compilation are a bit tiresome. Suppose you have the requirement that a certain feature of your software be disable-able at compile time, to avoid having to pull in certain dependencies (which may not be available on all platforms). Disabling a feature may entail removing certain fields from certain constructors (again, to avoid pulling in certain dependencies), and/or removing certain functions from certain modules. What is the best way to do this in Haskell? This problem description suggests that perhaps insights from Aspect-Oriented Programming and/or Software Product Lines may be relevant. However, I haven't heard of much work that relates these concepts to Haskell. Maybe this would be a good topic for an enterprising student? -- Robin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] typeOf for polymorphic value
Oleg, You rock! And you're a star! So you must be a rock star. :) Thanks! -- Lennart On Thu, Mar 26, 2009 at 5:33 AM, o...@okmij.org wrote: Does anyone know of a trick to accomplish `typeOf id'? Using something else than TypeRep as the representation, of course. Yes. The analysis of polymorphic types has been used in the inverse type-checker http://okmij.org/ftp/Haskell/types.html#de-typechecker The enclosed code computes TypeRep of polymorphic values. The code returns real TypeRep. Here are a few examples: tt2 = mytypof not -- Bool - Bool tt3 = mytypof [True] -- [Bool] tt4 = mytypof id -- any1 - any1 tt5 = mytypof [] -- [any1] tt6 = mytypof const -- any1 - any2 - any1 tt7 = mytypof Just -- any1 - Maybe any1 tt8 = mytypof map -- (any1 - any2) - [any1] - [any2] tt9 = mytypof maybe -- any1 - (any2 - any1) - Maybe any2 - any1 The code was tested on GHC 6.8.2. I don't have access to any computer with GHC 6.10, so I can't say how it works with that version of GHC. {-# LANGUAGE ScopedTypeVariables, EmptyDataDecls #-} {-# LANGUAGE FlexibleInstances, FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE OverlappingInstances #-} {-# LANGUAGE IncoherentInstances #-} module Typeof where import Data.Typeable -- tests tt1 = mytypof True -- Bool tt2 = mytypof not -- Bool - Bool tt3 = mytypof [True] -- [Bool] tt4 = mytypof id -- any1 - any1 tt5 = mytypof [] -- [any1] tt6 = mytypof const -- any1 - any2 - any1 tt7 = mytypof Just -- any1 - Maybe any1 tt8 = mytypof map -- (any1 - any2) - [any1] - [any2] tt9 = mytypof maybe -- any1 - (any2 - any1) - Maybe any2 - any1 class MyTypeable a where mytypof :: a - TypeRep -- Gamma is the sequence of type varaibles. It is used to assign -- different indices to different type variables instance (Analyze a result, MyTypeable' HNil gout result) = MyTypeable a where mytypof a = fst $ mytypof' HNil (analyze a) class MyTypeable' gin gout classification | gin classification - gout where mytypof' :: gin - classification - (TypeRep,gout) instance Typeable a = MyTypeable' gin gin (TAtomic a) where mytypof' gin _ = (typeOf (undefined::a), gin) instance Typeable a = MyTypeable' gin gin (TAtomic1 a) where mytypof' gin _ = (typeOf (undefined::a), gin) instance (MyTypeable' gin g a, MyTypeable' g gout b) = MyTypeable' gin gout (TFunction a b) where mytypof' gin _ = let (tr1,g) = mytypof' gin (undefined::a) (tr2,gout) = mytypof' g (undefined::b) in (mkFunTy tr1 tr2,gout) instance (MyTypeable' gin g c, MyTypeable' g gout a) = MyTypeable' gin gout (TConstructed c a) where mytypof' gin _ = let (tr1,g) = mytypof' gin (undefined::c) (tr2,gout) = mytypof' g (undefined::a) in (mkTyConApp (typeRepTyCon tr1) [tr2],gout) instance (HIndex a gin n, MyTypeable'' n gin gout (TVariable a)) = MyTypeable' gin gout (TVariable a) where mytypof' = mytypof'' (undefined::n) class MyTypeable'' n gin gout classification | n gin classification -gout where mytypof'' :: n - gin - classification - (TypeRep,gout) instance HLen gin n1 = MyTypeable'' Z gin (HCons a gin) (TVariable a) where mytypof'' _ gin _ = (mkany (undefined::S n1), HCons (undefined::a) gin) instance Nat n = MyTypeable'' (S n) gin gin (TVariable a) where mytypof'' _ gin _ = (mkany (undefined::S n), gin) mkany :: Nat n = n - TypeRep mkany n = mkTyConApp (mkTyCon ts) [] where ts = any ++ show (nat n) -- Lookup the index of an item x in the list l -- The index is 1-based. If not found, return 0 class Nat n = HIndex x l n | x l - n instance HIndex x HNil Z instance (Nat n, TypeEq x a f, HIndex' f x (HCons a l) n) = HIndex x (HCons a l) n class HIndex' f x l n | f x l - n instance HLen l n = HIndex' HTrue x l n instance HIndex x l n = HIndex' HFalse x (HCons a l) n -- Length of a list class Nat n = HLen l n | l - n instance HLen HNil Z instance HLen l n = HLen (HCons a l) (S n) -- Analyze a type -- Result of the type analysis data TAtomic a data TVariable a data TFunction a b data TConstructed c a -- only one level: kind * - * data TAtomic1 a data TVariable1 a data Level1 a data W a = W a -- We can have more levels, cf Typeable2, etc. class Analyze a b | a - b analyze:: Analyze a b = a - b analyze = undefined instance TypeCast f (TAtomic Int) = Analyze Int f instance TypeCast f (TAtomic Bool) = Analyze Bool f instance TypeCast f (TAtomic Char) = Analyze Char f instance TypeCast f (TAtomic Int) = Analyze (W Int) f instance TypeCast f (TAtomic Bool) = Analyze (W Bool) f instance TypeCast f (TAtomic Char) = Analyze (W Char) f instance (Analyze (c x) rx, Analyze (d y) ry, TypeCast f (TFunction rx ry)) = Analyze (c
Re: [Haskell-cafe] Conditional compilation
Hi Robin, On Fri, Mar 27, 2009 at 16:13, Robin Green wrote: Suppose you have the requirement that a certain feature of your software be disable-able at compile time, to avoid having to pull in certain dependencies (which may not be available on all platforms). Disabling a feature may entail removing certain fields from certain constructors (again, to avoid pulling in certain dependencies), and/or removing certain functions from certain modules. What is the best way to do this in Haskell? I don't know, but... This problem description suggests that perhaps insights from Aspect-Oriented Programming and/or Software Product Lines may be relevant. However, I haven't heard of much work that relates these concepts to Haskell. Maybe this would be a good topic for an enterprising student? I would love to see Haskell SPLs developed with feature-oriented programming concepts [1,2]. Only it would be much better if compositions were type-safe. I don't want aspects as they are presented in AspectJ (i.e. dynamic, hazardous). But everybody has their own definition of aspect these days. Regards, Sean [1] http://en.wikipedia.org/wiki/Feature_Oriented_Programming [2] http://www.cs.utexas.edu/users/schwartz/search.cgi ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Arch Linux now provides more than 1000 Haskell libraries and apps
A small milestone in the packaging business: http://archhaskell.wordpress.com/2009/03/27/arch-haskell-news-mar-14-2009-1000-haskell-packages/ More than 1000 Haskell packages packaged up for Arch Linux. Hackage now has 1163 (+41) Haskell packages, of which 1007 (+33) have been natively packaged for Arch in AUR. That’s 33 new packages in two weeks, and lots of updates as well. Read this week's updates on the blog. -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Exception handling in numeric computations
Quoth John Lato jwl...@gmail.com, An exception is caused by some sort of interaction with the run-time system (frequently a hardware issue). The programmer typically can't check for these in advance, but can only attempt to recover after they've happened. An error is some sort of bug that should be fixed by the programmer. I have never felt that I really understood that one. What about invalid inputs? Say someone encounters a disk full error, and the resulting partly written file is now unreadable data for its intended application because of an invalid file encoding? Is that an exception, or a bug that should be fixed? My guess is that you'll say it's a bug, i.e., that application's file decoding result should be an Either type that anticipates that the file encoding may be invalid. I will also guess if the file is unreadable because of an external I/O problem like no read access to file or filesystem, you would similarly expect this to be treated like that - I mean, ideally, e.g., hGetLine :: Handle - IO (Either IOError String) Does that make sense so far? Donn ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Darcs - dependencies between repositories (aka forests)
With Cabal we have this nice dependency system: when you install a package, it installs missing but requires packages. How do you solve this with Darcs? I hate it that I must manually figure out the dependencies, and then do a darcs get on them individually. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] about Haskell code written to be too smart
Continuing our adventures into stylistic and semantic differences:-) Can you write this analysis on the wiki? Hmm, we tried that in the past, and I haven't seen any indication that people search for those things, let alone find them (one particular example I recalled I still haven't been able to find on the wiki..). So I'll try a different approach this time: instead of copying emails to the wiki, I've created a page for collecting and documenting examples of equational reasoning in practice. Please add your favourites!-) Hopefully, the description of the examples will provide sufficient search keywords to make this page findable, and the linked examples from there; there are category links as well. Over to you, wiki style!-) Claus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Exception handling in numeric computations
On Fri, 2009-03-27 at 09:31 -0700, Donn Cave wrote: Quoth John Lato jwl...@gmail.com, An exception is caused by some sort of interaction with the run-time system (frequently a hardware issue). The programmer typically can't check for these in advance, but can only attempt to recover after they've happened. An error is some sort of bug that should be fixed by the programmer. I have never felt that I really understood that one. What about invalid inputs? Say someone encounters a disk full error, and the resulting partly written file is now unreadable data for its intended application because of an invalid file encoding? Is that an exception, or a bug that should be fixed? NB: Of course it's a bug: if the disk is full, the partially written file should be discarded and the previous version retained. I'm not going to hold you accountable for Unix's bugs, though. My guess is that you'll say it's a bug, I think you mean `exception' here. i.e., that application's file decoding result should be an Either type that anticipates that the file encoding may be invalid. This is pretty standard, I thought. Do people write Haskell file input methods that are undefined (`throw exceptions') on invalid inputs (e.g., do people use read to parse input from users or the file system[1])? I will also guess if the file is unreadable because of an external I/O problem like no read access to file or filesystem, you would similarly expect this to be treated like that - I mean, ideally, e.g., hGetLine :: Handle - IO (Either IOError String) IO is an exception monad already. I don't think there's an objection to throwing exceptions with throwIO and catching them in IO; my objection, at least, is to designing your program to throw exceptions from (ostensibly...) *pure* code and catch those in IO, in a live environment. Does that make sense so far? jcc [1] This post should not be taken as an endorsement of the use of the Read class for any purpose, nor as an endorsement of its continued existence in the standard library. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Exception handling in numeric computations
On Fri, Mar 27, 2009 at 7:31 PM, Donn Cave d...@avvanta.com wrote: Quoth John Lato jwl...@gmail.com, An exception is caused by some sort of interaction with the run-time system (frequently a hardware issue). The programmer typically can't check for these in advance, but can only attempt to recover after they've happened. An error is some sort of bug that should be fixed by the programmer. I have never felt that I really understood that one. Me too :-) BTW, John, how often do you encounter _hardware_ issues compared to errors? Is an out of memory thing an error or exception? You will say exception, for sure, wouldn't you? :-) And if it is a result of applying known-to-be-very-memory-hungry algorithms to non-trivial input? Looks like programmer's error, doesn't it? And I think I can provide lots of similar examples. If there exists separation between errors and exceptions, it should be very strong and evident — otherwise casual programmers like myself will need to stare at the ceiling every time they write something to decide what suits best. Gregory ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Exception handling in numeric computations
On Fri, 2009-03-27 at 20:38 +0300, Gregory Petrosyan wrote: On Fri, Mar 27, 2009 at 7:31 PM, Donn Cave d...@avvanta.com wrote: Quoth John Lato jwl...@gmail.com, An exception is caused by some sort of interaction with the run-time system (frequently a hardware issue). The programmer typically can't check for these in advance, but can only attempt to recover after they've happened. An error is some sort of bug that should be fixed by the programmer. I have never felt that I really understood that one. Me too :-) BTW, John, how often do you encounter _hardware_ issues compared to errors? Can't speak for anyone else, but I usually encounter hardware issues just before I replace the hardware... Is an out of memory thing an error or exception? You will say exception, for sure, wouldn't you? :-) No. GHC possesses an out-of-memory exception that (IIRC) it never throws, because it's simply not worth trying to recover from heap exhaustion. Maybe 20 years ago it was, but these days a program that manages to exhaust space is almost certainly either buggy or poorly optimized. An `error' is any condition where the correct response is for the programmer to change the source code :) And if it is a result of applying known-to-be-very-memory-hungry algorithms to non-trivial input? Looks like programmer's error, doesn't it? See above. And I think I can provide lots of similar examples. If there exists separation between errors and exceptions, it should be very strong and evident — otherwise casual programmers like myself will need to stare at the ceiling every time they write something to decide what suits best. Protip: try pacing instead of staring at the ceiling. jcc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] wxHaskell
Hello, I've just installed wxHaskell as follow: - Download wxHaskell from the following page: http://haskell.org/haskellwiki/WxHaskell/Download and downloaded the binairy version for Windows XP. - Registered using the batch file provided. Now I have this small program from my education page that I want to run just to make sure my installation is correct. ( http://www.cs.uu.nl/wiki/pub/FP/Practicum/Balls.hs) I've also got Helium (2003) and winHugs (sept 2006) (I'm so sorry for using the old versions, but I just can't find new versions) My GHC compiler is version: GHC 6.10.1 and my wxHaskell is named like: wxhaskell-bin-msw2.8.9-ghc6.10.1-0.11.0-0.zip. (If you need more information just contact me) Now my error message in winHugs is: And if ERROR file:.\Balls.hs - Can't find imported module Graphics.UI.WX And if I run that in Helium I get some error message that the . in Graphics.UI.WX is unexpected. (Which means by my views that it didn't import wxHaskell.) And if I run it in ghci it compiles perfect. So I thought let's type in main to start it in a interpreter. So I get the following: http://img10.imageshack.us/img10/5118/testzrs.jpg. I don't think that program is running correctly. Can someone point out what went wrong or what I am doing wrong? And some small question, do I always have to compile those programs in order for it to run correctly? Thanks for your time and effort! Tsunkiet Man ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Exception handling in numeric computations
Quoth Jonathan Cast jonathancc...@fastmail.fm, An `error' is any condition where the correct response is for the programmer to change the source code :) That's a broad category, that overlaps with conditions where there are one or more correct responses for the original program as well. If I throw exceptions within the type system, using IO or whatever, and at some later time observe that I have caught one that would have been better handled closer to its source, for example. I've already technically satisfied my requirement, since everything is in an exception monad, but the exception is still a bug. Or if I catch an non-IO error using Control.Exception.catch (if I were using ghc), and take advantage of the opportunity to release locks, post various notices, etc. - I evidently have a bug, but I also may need to have a programmed response for it. Donn ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANN: HackMail 0.0 -- Procmail + Monads = Awesome!
I'm happy to announce my very second Hackage upload!* HackMail is a Procmail-alike, though it doesn't (yet) support promail syntax. It dynamically loads a haskell source file (literate or vanilla, eithers okay) and then sits as a daemon watching a directory for new emails. The source file contains a function which sorts email and delivers it to some directory. As well as some configuration data. Not everything is working just yet -- the program is operational, but still lacking some of the features I want, namely a pipe mode, and some other things. It also uses a homebrew email parser, and lacks Haddock and Tests, but I wanted to release it mostly for comments/questions/helpful criticism from interested parties. Also, I wanted to upload something to hackage... It's a good feeling. Questions/Comments/Donations of Money, Vestal Virgins, or Cookies welcome! Package is on Hackage @ http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HackMail Source is on Patch-tag @ http://patch-tag.com/repo/Hackmail /Joe Fredette * (I uploaded a little tool called addLicenseInfo to test out the procedure, so... yah.) begin:vcard fn:Joseph Fredette n:Fredette;Joseph adr:Apartment #3;;6 Dean Street;Worcester;Massachusetts;01609;United States of America email;internet:jfred...@gmail.com tel;home:1-508-966-9889 tel;cell:1-508-254-9901 x-mozilla-html:FALSE url:lowlymath.net, humbuggery.net version:2.1 end:vcard ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] wxHaskell
On Fri, 27 Mar 2009 19:35:05 +0100, Tsunkiet Man temp.t...@gmail.com wrote: Hello, I've just installed wxHaskell as follow: - Download wxHaskell from the following page: http://haskell.org/haskellwiki/WxHaskell/Download and downloaded the binairy version for Windows XP. - Registered using the batch file provided. Now I have this small program from my education page that I want to run just to make sure my installation is correct. ( http://www.cs.uu.nl/wiki/pub/FP/Practicum/Balls.hs) I've also got Helium (2003) and winHugs (sept 2006) (I'm so sorry for using the old versions, but I just can't find new versions) My GHC compiler is version: GHC 6.10.1 and my wxHaskell is named like: wxhaskell-bin-msw2.8.9-ghc6.10.1-0.11.0-0.zip. (If you need more information just contact me) Now my error message in winHugs is: And if ERROR file:.\Balls.hs - Can't find imported module Graphics.UI.WX And if I run that in Helium I get some error message that the . in Graphics.UI.WX is unexpected. (Which means by my views that it didn't import wxHaskell.) And if I run it in ghci it compiles perfect. So I thought let's type in main to start it in a interpreter. So I get the following: http://img10.imageshack.us/img10/5118/testzrs.jpg. I don't think that program is running correctly. Can someone point out what went wrong or what I am doing wrong? And some small question, do I always have to compile those programs in order for it to run correctly? Thanks for your time and effort! Tsunkiet Man You have installed wxHaskell for GHC only; I don't know how to install it for the other implementations. The window seems OK, to see balls dropping, click on the window. -- Met vriendelijke groet, Henk-Jan van Tuyl -- http://functor.bamikanarie.com http://Van.Tuyl.eu/ -- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] A bit of a shock - Memoizing functions
Hi, um, well, I'm not even sure if I have correctly understood this. Some of the memoizing functions, they actually remember stuff *between* calls? Günther ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A bit of a shock - Memoizing functions
Hello Gü?nther, Friday, March 27, 2009, 11:30:41 PM, you wrote: Some of the memoizing functions, they actually remember stuff *between* calls? what i've seen in haskell - functions relying on lazy datastructures that ensure computation on first usage so this looks exactly like as memoizing: power 2 n | n=0 n100 = powersOfTwo!n power x y = x^y powersOfTwo = array (0,99) [2^n | n - [0..99] ] it's almost exact definition from ghc Prelude -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] want to upgrade to 6.10.1 ghc
Hello, I am running Ubuntu Linux. I have forgotten what is the preferred means of upgrading. Download the source and compile it using my current compiler .. 6.8.2? Regards, Vasili ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: A bit of a shock - Memoizing functions
Hi Bulat, that is so cool! Günther Bulat Ziganshin schrieb: Hello Gü?nther, Friday, March 27, 2009, 11:30:41 PM, you wrote: Some of the memoizing functions, they actually remember stuff *between* calls? what i've seen in haskell - functions relying on lazy datastructures that ensure computation on first usage so this looks exactly like as memoizing: power 2 n | n=0 n100 = powersOfTwo!n power x y = x^y powersOfTwo = array (0,99) [2^n | n - [0..99] ] it's almost exact definition from ghc Prelude ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] want to upgrade to 6.10.1 ghc
Vasili I. Galchin wrote: I am running Ubuntu Linux. I have forgotten what is the preferred means of upgrading. Download the source and compile it using my current compiler .. 6.8.2? I would recommend to download the binary distribution for your architecture, unpack it and install it. http://www.haskell.org/ghc Regards, -- Jochem Berndsen | joc...@functor.nl GPG: 0xE6FABFAB ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: A bit of a shock - Memoizing functions
It seems there is a very close correspondence between data structures and functions in Haskell. Your powersOfTwo function, since it gets memoized automatically (is this the case for all functions of zero arguments?), seems exactly like a data structure. This harks back to my Scheme days when we learned about the close relationship between code and data. I wonder: does the converse exist? Haskell data constructors which are really functions? How and for what might one use those? Thanks, Kirk On Fri, Mar 27, 2009 at 1:58 PM, GüŸnther Schmidt gue.schm...@web.dewrote: Hi Bulat, that is so cool! Günther Bulat Ziganshin schrieb: Hello Gü?nther, Friday, March 27, 2009, 11:30:41 PM, you wrote: Some of the memoizing functions, they actually remember stuff *between* calls? what i've seen in haskell - functions relying on lazy datastructures that ensure computation on first usage so this looks exactly like as memoizing: power 2 n | n=0 n100 = powersOfTwo!n power x y = x^y powersOfTwo = array (0,99) [2^n | n - [0..99] ] it's almost exact definition from ghc Prelude ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Use unsafePerformIO to catch Exception?
From: Jules Bean ju...@jellybean.co.uk wren ng thornton wrote: The type of head should not be [a] - a + Error, it should be (a:[a]) - a. With the latter type the compiler can ensure the precondition will be proved before calling head, thus eliminating erroneous calls. Yes, but you know and I know that's not haskell. I'm talking about haskell. In haskell - a language which does not fully support dependent types - head is both necessary and useful. I could follow the rest of this, but I don't understand why 'head' is necessary. Couldn't you always replace it with a case statement, with undefined on [] if necessary? I won't deny that it's extremely useful, though! John Lato ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: A bit of a shock - Memoizing functions
On Fri, 2009-03-27 at 14:26 -0700, Kirk Martinez wrote: Your powersOfTwo function, since it gets memoized automatically (is this the case for all functions of zero arguments?), It is the case for all functions which have zero arguments *at the time they are presented to the code generator*. The infamous evil monomorphism restriction arises from the fact that overloaded expressions, such as negative_one = exp(pi * sqrt(-1)) look like functions of zero arguments, but are not, and hence do not get memoized. This behavior was considered sufficiently surprising, when it was discovered in early Haskell compilers, that the construct was outlawed from the language entirely. jcc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Use unsafePerformIO to catch Exception?
2009/03/27 John Lato jwl...@gmail.com: From: Jules Bean ju...@jellybean.co.uk wren ng thornton wrote: The type of head should not be [a] - a + Error, it should be (a:[a]) - a. With the latter type the compiler can ensure the precondition will be proved before calling head, thus eliminating erroneous calls. Yes, but you know and I know that's not haskell. I'm talking about haskell. In haskell - a language which does not fully support dependent types - head is both necessary and useful. I could follow the rest of this, but I don't understand why 'head' is necessary. Couldn't you always replace it with a case statement, with undefined on [] if necessary? How would that be any different from head? -- Jason Dusek ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] wxHaskell
Oh yes, it works. I'm sorry for not noticing how this application works. Now I really wonder how I can implement that into winHugs and other GUI's =) Thank you for your response. 2009/3/27 Henk-Jan van Tuyl hjgt...@chello.nl On Fri, 27 Mar 2009 19:35:05 +0100, Tsunkiet Man temp.t...@gmail.com wrote: Hello, I've just installed wxHaskell as follow: - Download wxHaskell from the following page: http://haskell.org/haskellwiki/WxHaskell/Download and downloaded the binairy version for Windows XP. - Registered using the batch file provided. Now I have this small program from my education page that I want to run just to make sure my installation is correct. ( http://www.cs.uu.nl/wiki/pub/FP/Practicum/Balls.hs) I've also got Helium (2003) and winHugs (sept 2006) (I'm so sorry for using the old versions, but I just can't find new versions) My GHC compiler is version: GHC 6.10.1 and my wxHaskell is named like: wxhaskell-bin-msw2.8.9-ghc6.10.1-0.11.0-0.zip. (If you need more information just contact me) Now my error message in winHugs is: And if ERROR file:.\Balls.hs - Can't find imported module Graphics.UI.WX And if I run that in Helium I get some error message that the . in Graphics.UI.WX is unexpected. (Which means by my views that it didn't import wxHaskell.) And if I run it in ghci it compiles perfect. So I thought let's type in main to start it in a interpreter. So I get the following: http://img10.imageshack.us/img10/5118/testzrs.jpg. I don't think that program is running correctly. Can someone point out what went wrong or what I am doing wrong? And some small question, do I always have to compile those programs in order for it to run correctly? Thanks for your time and effort! Tsunkiet Man You have installed wxHaskell for GHC only; I don't know how to install it for the other implementations. The window seems OK, to see balls dropping, click on the window. -- Met vriendelijke groet, Henk-Jan van Tuyl -- http://functor.bamikanarie.com http://Van.Tuyl.eu/ http://van.tuyl.eu/ -- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Use unsafePerformIO to catch Exception?
On Fri, Mar 27, 2009 at 9:51 PM, Jason Dusek jason.du...@gmail.com wrote: 2009/03/27 John Lato jwl...@gmail.com: From: Jules Bean ju...@jellybean.co.uk wren ng thornton wrote: The type of head should not be [a] - a + Error, it should be (a:[a]) - a. With the latter type the compiler can ensure the precondition will be proved before calling head, thus eliminating erroneous calls. Yes, but you know and I know that's not haskell. I'm talking about haskell. In haskell - a language which does not fully support dependent types - head is both necessary and useful. I could follow the rest of this, but I don't understand why 'head' is necessary. Couldn't you always replace it with a case statement, with undefined on [] if necessary? How would that be any different from head? That's what I'm asking. It was claimed that 'head' is a necessary function, but I don't see why. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: A bit of a shock - Memoizing functions
2009/3/27 Kirk Martinez kirk.marti...@gmail.com: It seems there is a very close correspondence between data structures and functions in Haskell. Your powersOfTwo function, since it gets memoized automatically (is this the case for all functions of zero arguments?), seems exactly like a data structure. That's because it is. It's an array whose elements are computed on demand. This harks back to my Scheme days when we learned about the close relationship between code and data. I wonder: does the converse exist? Haskell data constructors which are really functions? How and for what might one use those? Sure. You can use Church encoding to represent any Haskell data type as a function. -- Dave Menendez d...@zednenem.com http://www.eyrie.org/~zednenem/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Internationalization of Haskell code
In my blog http://progandprog.blogspot.com/2009/03/i18n-and-haskell.html, I've described process of internationalization Haskell programms using GNU GetText. I wrote hgettext tool and Text.I18N.GetText library to help with internationalization (latest sources on http://hgettext.googlecode.com/files/hgettext-0.1.2.tar.gz). A bit later I plan to put it to hackage and wiki (waiting for account). -- Best regards, Vasyl Pasternak ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: A bit of a shock - Memoizing functions
2009/3/27 Kirk Martinez kirk.marti...@gmail.com: I wonder: does the converse exist? Haskell data constructors which are really functions? How and for what might one use those? You might enjoy reading about the use of tries for memoisation. Conal Elliott explains nicely how you can an isomorphism between certain types of function and certain types of tree structure: http://conal.net/blog/posts/elegant-memoization-with-functional-memo-tries/ It's neat because the rules for constructing the isomorphism are just like some well known rules of high school algebra, but interpreted in a new way. -- Dan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A bit of a shock - Memoizing functions
Hello, I've seen it done explicitly as is shown in the code below. 'f' in 'longest' is the function which is being memoized by the 'dp'. It's pretty slick, IMO. (not sure where this code came from. Also I may have broken it, but you get the idea): module Diff where import Data.Array -- * Dynamic Programming dp :: (Ix a) = (a,a) - ((a-b) - a - b) - a - b dp bounds f = (memo!) where memo = tabulate bounds (f (memo!)) tabulate :: (Ix a) = (a,a) - (a - b) - Array a b tabulate bounds f = array bounds [(i,f i) | i - range bounds] -- * Two-way diff -- NOTE: I copied lcs/longest off the web somewhere, not sure what the license is lcs :: Ord a = [a] - [a] - [(Int, Int)] lcs xs ys = snd $ longest lenx leny xarr yarr (0,0) where lenx = length xs leny = length ys xarr = listArray (0,lenx-1) xs yarr = listArray (0,leny-1) ys longest :: Ord a = Int - Int - Array Int a - Array Int a - (Int, Int) - (Int, [(Int, Int)]) longest a b c d| a `seq` b `seq` c `seq` d `seq` False = undefined longest lenx leny xarr yarr = dp ((0,0),(lenx,leny)) f where f rec (x,y) | x'ge'lenx y'ge'leny = (0, []) | x'ge'lenx = y' | y'ge'leny = x' | xarr ! x == yarr ! y = max (match $ rec (x+1,y+1)) m | otherwise = m where m = max y' x' x'ge'lenx = x = lenx y'ge'leny = y = leny y' = miss (rec (x,y+1)) x' = miss (rec (x+1,y)) match (n,xs) = (n+1, (x,y):xs) miss = id --miss z (n,xs) = (n,z:xs) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: toSelem takes no format parameter
If you have a type that requires a format string, the proper place to pass that string in is not the toSElem method. Rather, one should construct a ToSElem instance that wraps the item in an (STSH . STShow) constructor. The item itself then should be made an instance of StringTemplateShows, with an appropriate stringTemplateFormattedShow method. It's a bit of plumbing, I'll grant, but allows for setting the format where it should be -- in the template itself. If, on the other hand, you simply want to apply the locale to the attribute as you pass it in to the template, then you can just pack them together in a tuple or a record, and write a ToSElem instance for that. Cheers, S. On Mar 27, 2009, at 8:41 AM, Kemps-Benedix Torsten wrote: Sterling, the toSElem function of ToSElem does not take a parameter that allows specification of e.g. the locale that shall be used for rendering a specific attribute. If one wants to change this, one also has to change setAttribute and the like. Do you have any plans to extend HStringTemplate in this way? Schöne Grüße Torsten Kemps-Benedix (Geschäftsführer) SKS Unternehmensberatung GmbH Co KG Geheimrat-Hummel-Platz 4 D-65239 Hochheim am Main Germany M +49.163.36017.01 T +49.700.36017.000 F +49.700.36017.011 torsten.kemps-bene...@sks-ub.de http://www.sks-ub.de ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: A bit of a shock - Memoizing functions
Hi Dan, yep, I've come across that one too and wouldn't you know it, the by now infamous Luke Palmer has left an interesting insight on that blog too :). So I reckon here the cycle closes. Günther Dan Piponi schrieb: 2009/3/27 Kirk Martinez kirk.marti...@gmail.com: I wonder: does the converse exist? Haskell data constructors which are really functions? How and for what might one use those? You might enjoy reading about the use of tries for memoisation. Conal Elliott explains nicely how you can an isomorphism between certain types of function and certain types of tree structure: http://conal.net/blog/posts/elegant-memoization-with-functional-memo-tries/ It's neat because the rules for constructing the isomorphism are just like some well known rules of high school algebra, but interpreted in a new way. -- Dan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: A bit of a shock - Memoizing functions
Kirk Martinez wrote: It seems there is a very close correspondence between data structures and functions in Haskell. Your powersOfTwo function, since it gets memoized automatically (is this the case for all functions of zero arguments?), seems exactly like a data structure. This harks back to my Scheme days when we learned about the close relationship between code and data. You might also find Neil's blog post about CAFs interesting: http://neilmitchell.blogspot.com/2009/02/monomorphism-and-defaulting.html Fijne avond, Martijn. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Internationalization of Haskell code
On Sat, 28 Mar 2009, Vasyl Pasternak wrote: In my blog http://progandprog.blogspot.com/2009/03/i18n-and-haskell.html, I've described process of internationalization Haskell programms using GNU GetText. I wrote hgettext tool and Text.I18N.GetText library to help with internationalization (latest sources on http://hgettext.googlecode.com/files/hgettext-0.1.2.tar.gz). Thanks for working on that issue! The German translation is fine. I have recently written a Wiki article on how to avoid IO in Haskell code without resorting to unsafePerformIO where I incidentally chose gettext as an example: http://progandprog.blogspot.com/2009/03/i18n-and-haskell.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Internationalization of Haskell code
2009/3/28 Henning Thielemann lemm...@henning-thielemann.de: On Sat, 28 Mar 2009, Vasyl Pasternak wrote: In my blog http://progandprog.blogspot.com/2009/03/i18n-and-haskell.html, I've described process of internationalization Haskell programms using GNU GetText. I wrote hgettext tool and Text.I18N.GetText library to help with internationalization (latest sources on http://hgettext.googlecode.com/files/hgettext-0.1.2.tar.gz). Thanks for working on that issue! The German translation is fine. I have recently written a Wiki article on how to avoid IO in Haskell code without resorting to unsafePerformIO where I incidentally chose gettext as an example: http://progandprog.blogspot.com/2009/03/i18n-and-haskell.html Hi Henning, Did you mean to paste the link to the wiki here ? Thu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] The infamous evil monomorphism restriction (was: A bit of a shock - Memoizing functions)
From a previous email in the beginners list I more or less understood that the monomorphism restriction will not exist anymore in Haskell Prime. Is this correct? On Fri, Mar 27, 2009 at 10:32 PM, Jonathan Cast jonathancc...@fastmail.fmwrote: On Fri, 2009-03-27 at 14:26 -0700, Kirk Martinez wrote: Your powersOfTwo function, since it gets memoized automatically (is this the case for all functions of zero arguments?), It is the case for all functions which have zero arguments *at the time they are presented to the code generator*. The infamous evil monomorphism restriction arises from the fact that overloaded expressions, such as negative_one = exp(pi * sqrt(-1)) look like functions of zero arguments, but are not, and hence do not get memoized. This behavior was considered sufficiently surprising, when it was discovered in early Haskell compilers, that the construct was outlawed from the language entirely. jcc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: The infamous evil monomorphism restriction (was: A bit of a shock - Memoizing functions)
I kind a mention this because it might be easy for a polymorphic CAF to do memoization so its value gets computed maximum once per type, e.g (quick and dirty code follows) import Data.Typeable import Data.IORef import qualified Data.IntMap as M import System.IO.Unsafe import Debug.Trace fooCache :: IORef (M.IntMap a) fooCache = unsafePerformIO $ newIORef M.empty foo :: (Typeable a, Num a) = a foo = unsafePerformIO $ do key - typeRepKey (typeOf value) atomicModifyIORef fooCache (updateCache key) where value = trace foo is computed $ 42 updateCache key cache = case key `M.lookup` cache of Just n - (cache, trace foo was cached n) Nothing - (M.insert key value cache, value) A compiler (and Haskellers more clever than myself) could certainly come up with something much more efficient here. On Sat, Mar 28, 2009 at 12:51 AM, Peter Verswyvelen bugf...@gmail.com wrote: From a previous email in the beginners list I more or less understood that the monomorphism restriction will not exist anymore in Haskell Prime. Is this correct? On Fri, Mar 27, 2009 at 10:32 PM, Jonathan Cast jonathancc...@fastmail.fm wrote: On Fri, 2009-03-27 at 14:26 -0700, Kirk Martinez wrote: Your powersOfTwo function, since it gets memoized automatically (is this the case for all functions of zero arguments?), It is the case for all functions which have zero arguments *at the time they are presented to the code generator*. The infamous evil monomorphism restriction arises from the fact that overloaded expressions, such as negative_one = exp(pi * sqrt(-1)) look like functions of zero arguments, but are not, and hence do not get memoized. This behavior was considered sufficiently surprising, when it was discovered in early Haskell compilers, that the construct was outlawed from the language entirely. jcc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Internationalization of Haskell code
On Sat, Mar 28, 2009 at 12:20:04AM +0200, Vasyl Pasternak wrote: In my blog http://progandprog.blogspot.com/2009/03/i18n-and-haskell.html, I've described process of internationalization Haskell programms using GNU GetText. I wrote hgettext tool and Text.I18N.GetText library to help with internationalization (latest sources on http://hgettext.googlecode.com/files/hgettext-0.1.2.tar.gz). That's just plain awesome. It's getting harder to avoid success. -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Exception handling in numeric computations
Jonathan Cast schrieb: i.e., that application's file decoding result should be an Either type that anticipates that the file encoding may be invalid. This is pretty standard, I thought. Do people write Haskell file input methods that are undefined (`throw exceptions') on invalid inputs (e.g., do people use read to parse input from users or the file system[1])? With case reads str of [(x, )] - Just x _ - Nothing you are safe. (I think it's now available as maybeRead.) In general, relying on a well-formed input file is an error. However, if your program detects a format error in file input, it could throw an exception. But this means that your program must be prepared for these problems. I will also guess if the file is unreadable because of an external I/O problem like no read access to file or filesystem, you would similarly expect this to be treated like that - I mean, ideally, e.g., hGetLine :: Handle - IO (Either IOError String) IO is an exception monad already. I don't think there's an objection to throwing exceptions with throwIO and catching them in IO; my objection, at least, is to designing your program to throw exceptions from (ostensibly...) *pure* code and catch those in IO, in a live environment. Actually, I really object to have exception handling built into IO monad. Especially with extensible-exceptions package you can hide which kinds of exceptions can occur in a piece of code, which is a bad thing. When it comes to lazy I/O, which is problematic in itself, it is better to have explicit exceptions (i.e. IO (Either IOError String)) on top of exception-free IO. See the recent thread on safe lazy I/O: http://www.haskell.org/pipermail/haskell-cafe/2009-March/058205.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Exception handling in numeric computations
On Thu, 26 Mar 2009, John Lato wrote: Henning T., FYI your constant advocacy has gotten at least one person around to this view. I'm glad that it is not (only) perceived as annoyance. :-) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Use unsafePerformIO to catch Exception?
On Fri, 2009-03-27 at 12:26 +0100, Henning Thielemann wrote: On Thu, 26 Mar 2009, wren ng thornton wrote: Functions like uncons and viewL are nicer (because they're safe), but they can have overhead because they're unnecessarily complete (e.g. the Maybe wrapper can be avoided if we know a-priori that Just will be the constructor used). If you know, it's always Just, then don't use Maybe. There must be some point in your program, from where it is sure, that it is always Just and that is the point where to leave Maybe. When I searched my old code for fromJust and head and review it carefully, I could eliminate them in most cases. In another thread (Grouping - Map/Reduce) Yes, grouping is the one where I most often find the need for head or partial patterns. The function group produces a list of non-empty lists but that is not reflected in the type. On the other hand, actually reflecting it in the type would make it more awkward: group :: Eq a = [a] - [(a,[a])] Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Exception handling in numeric computations
On Fri, 27 Mar 2009, Donn Cave wrote: Quoth Jonathan Cast jonathancc...@fastmail.fm, An `error' is any condition where the correct response is for the programmer to change the source code :) That's a broad category, that overlaps with conditions where there are one or more correct responses for the original program as well. If I throw exceptions within the type system, using IO or whatever, and at some later time observe that I have caught one that would have been better handled closer to its source, for example. I've already technically satisfied my requirement, since everything is in an exception monad, but the exception is still a bug. I don't understand this one. Or if I catch an non-IO error using Control.Exception.catch (if I were using ghc), and take advantage of the opportunity to release locks, post various notices, etc. - I evidently have a bug, but I also may need to have a programmed response for it. The usual example against clear separation of exceptions and errors is the web server which catches 'error's in order to keep running. However, the web server starts its parts as threads, and whenever one thread runs into an 'error', it is terminated, just like an external shell program, that terminates with a segmentation fault. So, yes an error might be turned into an exception, but these are rare cases. In general it is hard or impossible to correctly clean up after an error, because the error occured due to something that you as programmer didn't respect. The error handler could well make things worse by freeing memory that is already deallocated and so on. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Conditional compilation
On Fri, 27 Mar 2009, Robin Green wrote: I am writing some code for citation support in gitit, and all the #ifdefs I'm using to do conditional compilation are a bit tiresome. I live well without CPP in Haskell. When I need conditional compilation I create two directories with modules of the same names in it. Then I set Hs-Source-Dirs conditionally in Cabal. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] is there any reason why Language.C.Syntax.AST.CTranslUnit doesn't derive show?
is there any reason why Language.C.Syntax.AST.CTranslUnit doesn't derive show? I would like to look at the data structure it generates. It's a lot easier to experiment it when i can write a template C file, print out the AST and then modify that data structure directly, instead of trying to grok the library. Thanks for your great work btw, the parser is pretty sweet. Anatoly ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Use unsafePerformIO to catch Exception?
On Fri, 27 Mar 2009, Jason Dusek wrote: 2009/03/27 John Lato jwl...@gmail.com: I could follow the rest of this, but I don't understand why 'head' is necessary. Couldn't you always replace it with a case statement, with undefined on [] if necessary? How would that be any different from head? The psychological advantage is, that you had to do something with the case [] and programmers hopefully hesitate more to write 'error' than to write 'head'. :-) Practically, if you have no better idea than writing 'error', you would write an error message that is more specific than head: empty list, which makes debugging easier.___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Really need some help understanding a solution
On Thu, 26 Mar 2009, wren ng thornton wrote: Thomas Hartman wrote: Luke, does your explanation to Guenther have anything to do with coinduction? -- the property that a producer gives a little bit of output at each step of recursion, which a consumer can than crunch in a lazy way? It has more to do with tying the knot (using laziness to define values in terms of themselves), though there are similarities. Take the function: infZipWith f ~(x:xs) ~(y:ys) = f x y : infZipWith f xs ys What about using a custom list type, that has only one constructor like (:), that is, a type for infinite lists? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: is there any reason why Language.C.Syntax.AST.CTranslUnit doesn't derive show?
ah, i am guessing its because you can use Data.Generics.gshow to do the same thing. Seems like that library will come in handy when manipulating the AST, pretty cool stuff. On Fri, Mar 27, 2009 at 5:53 PM, Anatoly Yakovenko aeyakove...@gmail.com wrote: is there any reason why Language.C.Syntax.AST.CTranslUnit doesn't derive show? I would like to look at the data structure it generates. It's a lot easier to experiment it when i can write a template C file, print out the AST and then modify that data structure directly, instead of trying to grok the library. Thanks for your great work btw, the parser is pretty sweet. Anatoly ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Really need some help understanding a solution
On Fri, Mar 27, 2009 at 7:03 PM, Henning Thielemann lemm...@henning-thielemann.de wrote: On Thu, 26 Mar 2009, wren ng thornton wrote: Thomas Hartman wrote: Luke, does your explanation to Guenther have anything to do with coinduction? -- the property that a producer gives a little bit of output at each step of recursion, which a consumer can than crunch in a lazy way? It has more to do with tying the knot (using laziness to define values in terms of themselves), though there are similarities. Take the function: infZipWith f ~(x:xs) ~(y:ys) = f x y : infZipWith f xs ys What about using a custom list type, that has only one constructor like (:), that is, a type for infinite lists? Yes, that would be more correct. However, the lazy pattern match would still be necessary, because single-constructor types are lifted. And as long as you're doing that, you might as well go all the way to an infinite binary trie. Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Haxr doesn't compile from cabal (HTTP 4000 breaks it)
Most breakage caused by new HTTP package is due to the renaming from Response to Response_String and Request to Request_String. I think it was not a good idea to do that. There could have well be two types named Response from different modules, one with a type parameter and the other one without. Or the parametrized variant could have be named ResponseGeneric or so. That would have allowed packages to work both with version 3001 and 4000. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Exception handling in numeric computations
From: Donn Cave d...@avvanta.com Quoth John Lato jwl...@gmail.com, An exception is caused by some sort of interaction with the run-time system (frequently a hardware issue). The programmer typically can't check for these in advance, but can only attempt to recover after they've happened. An error is some sort of bug that should be fixed by the programmer. I have never felt that I really understood that one. Honestly, me neither, until recently. I'm only barely starting to understand it, and I do think there's a great deal of overlap. Even if an error is a bug that can be fixed by the programmer, certain exceptional situations can also be fixed by the programmer by handling the exception, even if they can't be detected in advance. In general I would say that I agree with JCC's responses. What about invalid inputs? Say someone encounters a disk full error, and the resulting partly written file is now unreadable data for its intended application because of an invalid file encoding? Is that an exception, or a bug that should be fixed? My guess is that you'll say it's a bug, i.e., that application's file decoding result should be an Either type that anticipates that the file encoding may be invalid. Not necessarily. I would be satisfied with a Maybe :) I've encountered malformed data frequently enough that any decoders I write (and I have done so recently) would anticipate invalid data. I will also guess if the file is unreadable because of an external I/O problem like no read access to file or filesystem, you would similarly expect this to be treated like that - I mean, ideally, e.g., hGetLine :: Handle - IO (Either IOError String) Not necessarily, but possibly. The big difference, of course, is that decoding can be a pure operation, while reading never is. I personally wouldn't mind if hGetLine had the type you give. The way I see it, there are two advantages to exceptions in this case. The first is that it's very easy for exceptions to trickle up and be handled at a higher level. The second 'advantage' is that the programmer doesn't need to explicitly handle exceptions, whereas an Either would require at least a pattern match to use the resulting value. John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Exception handling in numeric computations
Henning Thielemann lemm...@henning-thielemann.de wrote: The usual example against clear separation of exceptions and errors is the web server which catches 'error's in order to keep running. However, the web server starts its parts as threads, and whenever one thread runs into an 'error', it is terminated, just like an external shell program, that terminates with a segmentation fault. So, yes an error might be turned into an exception, but these are rare cases. In general it is hard or impossible to correctly clean up after an error, because the error occured due to something that you as programmer didn't respect. The error handler could well make things worse by freeing memory that is already deallocated and so on. I don't see that as an argument against 'clear separation', really. Having _some_ way of dealing an error (from within a program), in special circumstances doesn't preclude clearly separating how it's done from exception handling. I always find it jarring when an HUnit test I've run tells me it encountered an 'exception', when I'm testing pure code (nevertheless I'd also find it annoying if the entire test run terminated because of a failed pattern match). With respect to the last point - isn't proving that a given program can't corrupt its own RTS possible, even in the presence of errors? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haddock GSoC project
Okay, I've written a draft Haddock-GSOC application: would any of you like to review it / suggest how it could be improved? (or should I just submit it to Google?) I'm particularly wondering whether my proposed time-line seems realistic. -Isaac * What is the goal of the project you propose to do? To improve Haddock, the Haskell documentation tool, both substantively in the short term and to be better factored in the long term. * Can you give some more detailed design of what precisely you intend to achieve? Resolve many Haddock Trac tickets. Specific projects: Make cross-package documentation work; and refactor the comment-parsing out of GHC and into the Haddock code-base. * What deliverables do you think are reasonable targets? Can you outline an approximate schedule of milestones? In the first week I will get Haddock and GHC compilation and patch-making set up, fix some minor bugs and send/apply the fixes. Next I will start to determine and converse about the implementation difficulties with making Haddock work across packages. At the same time, I'll continue working on more minor bugs/features (increasing my familiarity with the code and with the coding process). By the end of June I hope to get cross-module docs working. [Is this a realistic goal?] By this time, I'll have some familiarity with the parsing code (having fixed some of its bugs/infelicities), and I can confront the problem of how to refactor the comment-parsing out of GHC. I can imagine I might only be able to find a partial solution easily, but I'll do whatever I have time for. Optimistic timeline to finish this by the end of July; if I get ahead of schedule, I'm sure I'll know enough about Haddock's infelicities by then to know other mini-projects that would be worth doing. For example, I could improve the layout of the index page Haddock generates (Python docs do it better, for reference, according to http://trac.haskell.org/haddock/ticket/70.) Due to the process of testing my changes, I might even write some documentation, if I see an atrociously documented function in some library :-) * In what ways will this project benefit the wider Haskell community? Better documentation (documentation that is less difficult to successfully write) makes everything flow more smoothly in source-code-land. Especially core (even Haskell-98) library documentation has broken multiple times due to Haddock deficiency, and other library authors suffer from everything from `type` annotations not working, to Haddock-2 parsing being more strict, to... every possible issue, really. The cross-package documentation failure specifically makes people reluctant to refactoring into smaller packages, even when that would increase code re-use. Making Haddock/GHC more composable should make it easier for everyone to make small improvements to Haddock, without delving into GHC as much. Perhaps it might even make possible some new tool different from Haddock that looks at information in comments, should someone desire such a thing. * What relevant experience do you have? e.g. Have you coded anything in Haskell? Have you contributed to any other open source software? Been studying advanced courses in a related topic? I substantially improved Spiderweb Software's scenario-editor for Blades of Avernum (once they made it open-source), adding 3D support and other improvements. (C programming language). I worked on Battle for Wesnoth scenarios some, and I hacked on the C++ code for lexing/parsing their markup language, and I learned my lesson when I failed to coordinate successfully with the development team. :-) They used Doxygen to document their code, though it was not used nearly as thoroughly (at least, not back a few years ago) as a lot of Haskell code is documented today. I hacked on GHC, and this code has been committed: I improved the parsing of negative unboxed literals, and I refactored several places in the code that used language extensions unnecessarily. Also I've contributed to discussions on Haskell development mailing-lists over the years (leading to at least one bug-fix), and reported several more bugs in Trac as I ran into them while hacking in Haskell. I took an advanced-level Artificial Intelligence class in which I programmed in Haskell and got an A. I've read many research papers related to Haskell or compilation. I've used Darcs; I've used Linux and followed its open-source coordination travails for four years now (formerly I used Mac OS). I know (X)HTML and CSS well enough to write my own W3C-validated webpage (and my parents work in web-design so I hear a lot about it), so I should be able to work on Haddock's HTML-generating code easily. * In what ways do you envisage interacting with the wider Haskell community during your project? e.g. How would you seek help on something your mentor wasn't able to deal with? How will you get others
[Haskell-cafe] Re: Definition of tail recursive wrt Folds
Mark Spezzano wrote: Just looking at the definitions for foldr and foldl I see that foldl is (apparently) tail recursive while foldr is not. Why? Is it because foldl defers calling itself until last whereas foldr evaluates itself as it runs? What, strictly speaking, is the definition of ”tail recursive” as opposed to just “recursive”? An application of some function f inside another function g is in 'tail position' (or a 'tail call') if the result of applying f is the result of g. Operationally speaking, calling f is the very last thing g does. Tail calls can be optimized by a compiler (or interpreter) so that the call does not use additional stack; that is, the call can be replaced by a jump. A function is called ”tail recursive” (as opposed to just “recursive”) if the recursive call to itself is in tail position. If the compiler performs tail call optimization, tail recursive functions can work with constant stack space, similar to a (imperative) loop. Looking at a definition of foldl, e.g. foldl f z0 xs0 = lgo z0 xs0 where lgo z [] = z lgo z (x:xs) = lgo (f z x) xs you see that lgo calls itself in tail position, thus is tail recursive. In contrast, foldr can be defined as foldr k z xs = go xs where go [] = z go (y:ys) = y `k` go ys where you see that the result of go is not the recursive call to go. Instead, the result is y `k` go ys . Thus, foldr is not tail recursive. So, if you are saying that foldl defers calling itself until last whereas foldr evaluates itself as it runs then you got the right idea, I think. The point is that foldr still needs to do something (namely to apply (y `k`)) to the result of applying itself. It needs to remember to do so, and thus the stack grows linearly with the size of the list. Cheers Ben ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Darcs - dependencies between repositories (aka forests)
I assume cabal install darcs isn't what you're looking for.. can you give a real-world example ? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Parallel term reduction---solution
On February 1, I sent a message to this list asking for advice on how to write a parallel term reduction system. I now have a semi-explicit parallelised version of a term reduction system that makes effective use of multiple CPUs. The enclosed code describes the solution, even though its performance on the example reduction rule does not show a speed up. In the actual reduction system. profiling shows that 99% of the runtime and 98% of the allocations occur in the equivalent of the branch function below, for a representative test case. It's no surprise that just one parallel function, parMap, is all that's needed. John module Main (main) where import System.Time (ClockTime(..), getClockTime) import Data.Tree (Tree(..), flatten) import Data.Maybe (isNothing) import Control.Parallel The reduction system takes a rule, a step count, and an initial value, and computes a tree of reductions. reduce :: (Eq a, Monad m) = (a - [a]) - Int - a - m (Tree a) reduce rule limit root = step rule limit [top] [top] where top = Item { item = root, parent = Nothing } The Item data structure stores the information about a reduction step in a form that can be used to construct the final answer as a tree. data Eq a = Item a = Item { item :: a, parent :: Maybe (Item a) } instance Eq a = Eq (Item a) where x == y = item x == item y The step function is where nearly all of the time is used. It is called as: step rule limit seen todo where seen is the items already seen, and todo is the items on the queue. The order of the items in the seen list is irrelevant, because the tree is assembled as a post processing step. step :: (Eq a, Monad m) = (a - [a]) - Int - [Item a] - [Item a] - m (Tree a) step _ _ seen [] = tree seen step rule limit seen todo = combine rule seen limit [] [] (parMap (branch rule seen) todo) Each branch of the rule derivation tree can be evaluated in parallel. Furthermore, most of the checking to see if an item has been seen before can be done in parallel. branch :: Eq a = (a - [a]) - [Item a] - Item a - Reduct a branch rule seen parent = Reduct parent (seqList kids) where kids = [ kid | kid - rule (item parent), not (dejaVu kid seen) ] This data structure ensures as much computation as possible is done in parallel. data Eq a = Reduct a = Reduct !(Item a) ![a] Has x been seen before? dejaVu :: Eq a = a - [Item a] - Bool dejaVu x seen = any (\i- x == item i) seen Combine the results of one level of the rule derivation tree. The combination function is not associative, so there are no opportunities for parallelisation. combine :: (Eq a, Monad m) = (a - [a]) - [Item a] - Int - [Item a] - [Item a] - [Reduct a] - m (Tree a) combine rule seen' limit seen todo [] = step rule limit (seen ++ seen') (reverse todo) combine _ _ limit _ _ _ | limit = 0 = fail Step limit exceeded combine rule oseen limit seen todo (Reduct p kids : reducts) = combine rule oseen (limit - 1) seen' todo' reducts where (seen', todo') = foldr f (seen, todo) kids f kid (seen, todo) = if dejaVu kid seen then (seen, todo) else (x:seen, x:todo) where x = Item { item = kid, parent = Just p } seqList :: [a] - [a] seqList xs = loop xs where loop [] = xs loop (y : ys) = seq y (loop ys) parMap :: (a - b) - [a] - [b] parMap _ [] = [] parMap f (x:xs) = par y (pseq ys (y:ys)) where y = f x ys = parMap f xs The next two functions assemble the answer into a tree. Sequential search is just fine for tree building. tree :: (Eq a, Monad m) = [Item a] - m (Tree a) tree items = case filter (isNothing . parent) items of [root] - return (build items (item root)) _ - fail bad tree build :: Eq a = [Item a] - a - Tree a build items root = Node { rootLabel = root, subForest = map (build items . item) children } where children = filter child items child i = maybe False ((== root) . item) (parent i) A silly rule rule :: Int - [Int] rule n = filter (= 0) [n - 1, n `quot` 2, n `quot` 3] secDiff :: ClockTime - ClockTime - Float secDiff (TOD secs1 psecs1) (TOD secs2 psecs2) = fromInteger (psecs2 - psecs1) / 1e12 + fromInteger (secs2 - secs1) main :: IO () main = do t0 - getClockTime t - reduce rule 2 5000 let ns = length (flatten t) t1 - getClockTime putStrLn $ length: ++ show ns putStrLn $ time: ++ show (secDiff t0 t1) ++ seconds The makefile PROG= parreduce GHCFLAGS = -Wall -package containers -package parallel -threaded \ -fno-warn-name-shadowing -O %: %.lhs ghc $(GHCFLAGS) -o $@ $ all:$(PROG) clean: -rm *.o *.hi $(PROG) ___ Haskell-Cafe mailing list
Re: [Haskell-cafe] Re: Exception handling in numeric computations
Quoth Henning Thielemann lemm...@henning-thielemann.de, On Fri, 27 Mar 2009, Donn Cave wrote: Quoth Jonathan Cast jonathancc...@fastmail.fm, An `error' is any condition where the correct response is for the programmer to change the source code :) That's a broad category, that overlaps with conditions where there are one or more correct responses for the original program as well. If I throw exceptions within the type system, using IO or whatever, and at some later time observe that I have caught one that would have been better handled closer to its source, for example. I've already technically satisfied my requirement, since everything is in an exception monad, but the exception is still a bug. I don't understand this one. A lame attempt to demonstrate that condition where [a] correct response is to change the code applies to too many cases to be useful. (And that there are no cases where [the only] correct response is to change the code.) Or if I catch an non-IO error using Control.Exception.catch (if I were using ghc), and take advantage of the opportunity to release locks, post various notices, etc. - I evidently have a bug, but I also may need to have a programmed response for it. The usual example against clear separation of exceptions and errors is the web server which catches 'error's in order to keep running. However, the web server starts its parts as threads, and whenever one thread runs into an 'error', it is terminated, just like an external shell program, that terminates with a segmentation fault. So, yes an error might be turned into an exception, but these are rare cases. In general it is hard or impossible to correctly clean up after an error, because the error occured due to something that you as programmer didn't respect. The error handler could well make things worse by freeing memory that is already deallocated and so on. But you'd have to weigh that against the consequences of not continuing. I can certainly see the attraction of the exception monad treatment for anticipated errors. It might tend to obscure a central computation for the sake of handling a lot of weird little errors that may never actually be encountered, and doesn't it occasionally have a problem with making things strict that didn't already need to be? but at least it makes it easier to reason about the code in terms that include errors. And I'm using nhc98 lately, so no Control.Exception.catch for me, but if I had it, I'd use it, just like I wear a helmet when I ride my bicycle or motorcycle. Donn ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe