From andrew at pimlott.net Wed Nov 1 00:14:23 2006 From: andrew at pimlott.net (Andrew Pimlott) Date: Wed Nov 1 00:14:37 2006 Subject: [Haskell-cafe] there's a monster in my Haskell! Message-ID: <20061101051423.GC3798@pimlott.net> To boost the popularity of Scheme, Felleisen has argued for renaming "lambda" to "something cool, such as Funster".[1] Likewise, Haskell intimidates newcomers with the arcane term "monad". Peyton Jones's hopeful campaign to replace it with "warm fuzzy thing"[2] has so far produced few results. Inspired by Felleisen, and in the spirit of Halloween, I offer a new alternative: Meet "monsters", your computational companions in the land of lazy functional programming. To illustrate this proposal, I present here a gentle introduction to monsters. Monsters come in great variety, each type having its own special powers. But, as noted by Elmo[3], they are alike in an essential way. All monsters are capable of devouring values: devour :: Monster m => a -> m a The result of "devour x" is simply a monster that has ingested the value "x". Most monsters have a weakness and can be slain, liberating some ingested values or producing some other result. The instrument of demise varies, as do the possible outcomes, so this function is particular to a monster. If SomeMonster always yields a single value upon its demise, we would have slay :: SomeMonster a -> a The compassionate (and fastidious) programmer defers the gruesome (and messy) slaying while making use of the monster's special powers. But how to get at the monster's values short of that macabre act? Fortunately, monsters gladly contribute their values towards the creation of more monsters: (>>=) :: Monster m => m a -> (a -> m b) -> m b (>>=) should be read as the monster on the left expelling values through its rows of teeth and over its tongue at the function on the right. (Its pronunciation is a sort of bestial hissing that is difficult to describe; when you say it correctly, the terminal may become slightly moist.) Monsters range from the tame to the tumultuous, but we cannot let them run entirely amok. All therefore must obey the "monster laws". For instance, the regurgitation law states that immediately after devouring a value, a monster expels the same value: devour x >>= k === k x We have still seen none of the promised special powers. For that, we must look at a particular monster. The Either monster is defined as data Either a b = Trick a | Treat b This monster devours Treats, but if it doesn't get a Treat, it can play a Trick: playTrick :: t -> Trick t a playTrick t = Trick t This monster is commonly used as follows: takeFood :: Food -> Either Mischief Food takeFood Apple = playTrick eggHouse takeFood Raisins = playTrick tpTree takeFood CandyCorn = devour CandyCorn The divine among monsters is the mysterious and awesome IO. Its powers are vast, perhaps limitless, and beginners are taught that it cannot be slain. Like poisoned candy and release dates, this is of course a myth. The pure of spirit may, after meditation at the altar of referential transparency, cast the spell :: IO a -> a (When you are prepared to call this function, its name will be revealed.) The ST monster can be slain without esoteric ritual: slay :: (forall s. ST s a) -> a Yet philosophers whisper that there is something otherworldly about it, a kinship with IO. Eavesdropping on their debates, I hear the words "phantom type", but that gives me the chills so I leave them. [1] http://permalink.gmane.org/gmane.comp.lang.lightweight/3427 [2] http://research.microsoft.com/~simonpj/papers/haskell-retrospective/ [3] http://muppet.wikia.com/wiki/We%27re_All_Monsters From ulfn at cs.chalmers.se Wed Nov 1 02:53:13 2006 From: ulfn at cs.chalmers.se (Ulf Norell) Date: Wed Nov 1 02:52:49 2006 Subject: [Haskell-cafe] Simple GADT parser for the eval example In-Reply-To: <20061101003203.GA6172@sleepingsquirrel.org> References: <20061030170026.GA1737@sleepingsquirrel.org> <20061101003203.GA6172@sleepingsquirrel.org> Message-ID: <2A7FD85C-3B62-4CC6-B50F-B503BD69C502@cs.chalmers.se> On Nov 1, 2006, at 1:32 AM, Greg Buchholz wrote: > Thanks to everyone who replied (especially Dimitrios Vytiniotis > and > Joost Visser). I now know the standard way to write the GADT parser. > But I'm still curious if anyone has comments pertaining to the version > using type classes. It seems so close to doing what we want, and > it is > pretty straightforward to implement. The best way I can think to > describe it would be to say it uses the type system to find what it > should parse next, and dies of a pattern match failure if something > unexpected shows up, instead of checking to see if we can assemble a > type safe tree from pre-parsed parts (does that make any sense?). > > I'm curious if there could be a small change to the type system to > make the fully general "my_read" possible, or if it suffers from an > incurable defect. I'm not sure what you're asking, but it's possible to get my_read :: .. => Expr -> Term a Previously given code: > -- Give a GADT for representation types > data R a where > Rint :: R Int > Rbool :: R Bool > Rpair :: R a -> R b -> R (a,b) > > -- Give an existential type with a type representation > data TermEx where > MkTerm :: R a -> Term a -> TermEx > > my_readEx :: Expr -> TermEx > getTerm :: TermEx -> R a -> Term a Given this you can define > class Rep a where rep :: R a > instance Rep Int where rep = Rint > instance Rep Bool where rep = Rbool > instance (Rep a, Rep b) => Rep (a,b) where > rep = Rpair rep rep > > my_read :: Rep a => Expr -> Term a > my_read e = getTerm (my_readEx e) rep / Ulf From lemming at henning-thielemann.de Wed Nov 1 02:58:18 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Wed Nov 1 02:59:27 2006 Subject: [Haskell-cafe] More documentation: how to create a Haskell project In-Reply-To: References: <20061030025200.GA30685@cse.unsw.EDU.AU> <45456FF7.80208@tmorris.net> Message-ID: On Mon, 30 Oct 2006, David House wrote: > On 30/10/06, Tony Morris wrote: > > 4) If you want links to base libraries in your haddock output, do "such > > and such" (how do you do that anyway?) > > I believe you need a local copy of the library sources, whose path you > give to haddock with some flag. No, haddock needs only .haddock files of the base libraries. I added some support to Cabal. It currently fails if old style file names like Data.List.html are installed, but a new haddock version links to new style Data-List.html. From oleg at pobox.com Wed Nov 1 03:30:56 2006 From: oleg at pobox.com (oleg@pobox.com) Date: Wed Nov 1 03:31:03 2006 Subject: [Haskell-cafe] An example of dependent types [was: Simple GADT parser for the eval example] Message-ID: <20061101083056.635C6AC04@Adric.metnet.fnmoc.navy.mil> Greg Buchholz has posed an interesting problem of writing a typechecker. Given untyped terms of the form > data Expr = ELit Int > | EInc Expr > | EIsZ Expr .... we are to compute typed terms: > data Term a where > Lit :: Int -> Term Int > Inc :: Term Int -> Term Int > IsZ :: Term Int -> Term Bool That is, we need to write a function > typecheck :: Expr -> Term a Actually, Greg Buchholz posed a simpler example, of a function my_read > my_read :: Expr -> Term a Although it has the same signature, the intent is different. When the user writes "my_read exp", the user is supposed to *specify* the type of the desired result. Just as when we write "read 1", we are supposed to specify the type of the expected value: Int, Integer, etc. The function typecheck has a different intent: it *computes* the result type. It is indeed the typechecker: given the expression, we compute its type -- or report a failure if the expression is ill-typed. That is, the result *type* "Term a" is a function of the *value* Expr. Thus is truly a problem of dependent types. And Haskell is up to it: Haskell is genuinely a dependently typed language. We show the solution that uses no GADTs and no representation types. We retain however the eval function in the previous message that uses GADT. Our solution uses type classes. It seems to some the type-checking rules stated as instances of the TypeCheck class take a particular natural form. Indeed: > -- given term e, compute its type t > class TypeCheck e t | e -> t where > typecheck :: e -> Term t > instance TypeCheck FLit Int where > typecheck (FLit x) = Lit x > instance TypeCheck e Int => TypeCheck (FInc e) Int where > typecheck (FInc e) = Inc (typecheck e) > instance TypeCheck e Int => TypeCheck (FIsZ e) Bool where > typecheck (FIsZ e) = IsZ (typecheck e) > instance (TypeCheck e1 Bool, TypeCheck e2 t, TypeCheck e3 t) > => TypeCheck (FIf e1 e2 e3) t where > typecheck (FIf e1 e2 e3) = If (typecheck e1) (typecheck e2)(typecheck e3) > instance (TypeCheck e1 t1, TypeCheck e2 t2) > => TypeCheck (FPair e1 e2) (t1,t2) where > typecheck (FPair e1 e2) = Pair (typecheck e1) (typecheck e2) > instance TypeCheck e (t1,t2) => TypeCheck (FFst e) t1 where > typecheck (FFst e) = Fst (typecheck e) > instance TypeCheck e (t1,t2) => TypeCheck (FSnd e) t2 where > typecheck (FSnd e) = Snd (typecheck e) In the paper, the IsZ rule would have been written as |- e : int --------------- |- IsZ e : bool (We don't need the environment Gamma as our language has no variables). I submit the typeclass notation takes less space. The typechecking rules above operate on `lifted' terms: FLit, FInc, etc: > newtype FLit = FLit Int > newtype FInc e = FInc e > newtype FIsZ e = FIsZ e rather than the original terms Exp. The conversion is straightforward, via Template Haskell: > type F = Q TH.Exp > parse :: Expr -> F > parse (ELit x) = [e| FLit $(litE . integerL . fromIntegral $ x) |] > parse (EInc x) = [e| FInc $(parse x) |] > parse (EIsZ x) = [e| FIsZ $(parse x) |] The only inconvenience of using the Template Haskell is the necessity of splitting the whole code into two modules. we can then write: > e1 = "EIf (ELit 1) (ELit 2) (ELit 3)" > e2 = "(EIf (EIsZ (ELit 0)) " ++ > " (EInc (ELit 1)) " ++ > " (EFst (EPair (ELit 42) " ++ > " (ELit 43))))" > > t1' = $(parse . read $ e1) > t2' = $(parse . read $ e2) *G> :t t1' t1' :: FIf FLit FLit FLit *G> :t t2' t2' :: FIf (FIsZ FLit) (FInc FLit) (FFst (FPair FLit FLit)) > -- Causes the typechecking error: cannot match Int against the Bool > -- tt1 = typecheck t1' > tt2 = typecheck t2' *G> :t tt2 tt2 :: Term Int Obviously, e1 is ill-formed and so cannot be typechecked. The term e2 is well-typed, and the typechecker has figured out its type, which is Term Int. There was no need for any type annotation. The term tt2 can then be evaluated. The code: file GP.hs {-# OPTIONS -fglasgow-exts #-} module GP where import Language.Haskell.TH hiding (Exp) import qualified Language.Haskell.TH as TH (Exp) import Language.Haskell.TH.Ppr -- untyped terms, at Level 0 data Expr = ELit Int | EInc Expr | EIsZ Expr | EPair Expr Expr | EIf Expr Expr Expr | EFst Expr | ESnd Expr deriving (Read,Show) -- Untyped terms, at Level 1 type F = Q TH.Exp newtype FLit = FLit Int newtype FInc e = FInc e newtype FIsZ e = FIsZ e data FPair e1 e2 = FPair e1 e2 data FIf e1 e2 e3 = FIf e1 e2 e3 newtype FFst e = FFst e newtype FSnd e = FSnd e parse :: Expr -> F parse (ELit x) = [e| FLit $(litE . integerL . fromIntegral $ x) |] parse (EInc x) = [e| FInc $(parse x) |] parse (EIsZ x) = [e| FIsZ $(parse x) |] parse (EFst x) = [e| FFst $(parse x) |] parse (ESnd x) = [e| FSnd $(parse x) |] parse (EPair x y) = [e| FPair $(parse x) $(parse y) |] parse (EIf x y z) = [e| FIf $(parse x) $(parse y) $(parse z) |] show_code cde = runQ cde >>= putStrLn . pprint t0 = show_code . parse . read $ "EInc (EInc (ELit 1))" -- ill-typed expression e1 = "EIf (ELit 1) (ELit 2) (ELit 3)" e2 = "(EIf (EIsZ (ELit 0)) " ++ " (EInc (ELit 1)) " ++ " (EFst (EPair (ELit 42) " ++ " (ELit 43))))" t1 = show_code . parse . read $ e1 File g2.hs {-# OPTIONS -fglasgow-exts #-} {-# OPTIONS -fallow-undecidable-instances #-} module G where import GP -- Typed terms data Term a where Lit :: Int -> Term Int Inc :: Term Int -> Term Int IsZ :: Term Int -> Term Bool If :: Term Bool -> Term a -> Term a -> Term a Pair :: Term a -> Term b -> Term (a,b) Fst :: Term (a,b) -> Term a Snd :: Term (a,b) -> Term b -- Typed evaluator [elided] -- Figure out the type of the expression e -- The type-checking rules are written in the natural notation [see the TypeCheck class and instances above. Elided to save space] t0' = $(parse . read $ "EInc (EInc (ELit 1))") t1' = $(parse . read $ e1) t2' = $(parse . read $ e2) tt0 = typecheck t0' -- Causes the typechecking error: cannot match Int against the Bool -- tt1 = typecheck t1' tt2 = typecheck t2' ttt0 = eval tt0 ttt2 = eval tt2 From newhoggy at gmail.com Wed Nov 1 03:35:35 2006 From: newhoggy at gmail.com (John Ky) Date: Wed Nov 1 03:35:29 2006 Subject: [Haskell-cafe] What is the best way to preserve the order of a list Message-ID: Hi, I have a list of entities. Each entity has a priority field and an order field. The priority field contain the input values to my algorithm, the order fields contain the output value of my algorithm. My algorithm needs to assign 1 to the order field of the entity with the lowest priority value, 2 to the order field of the entity with the next lowest priority value, .... and so on. I've written a function orderByPriority that does that. However, it also does something else that is undesireable. It reorders the list. My question is, how do I preserve the ordering of entities in my list and still be able to assign the proper order values to each entity? Is there an efficient way to do this? How else might I improve my orderByPriority algorithm. Thanks -John > import Data.List > data Entity = Entity { > entityId :: Int, > priority :: Float, > order :: Int > } > initEntity = Entity { > entityId = 0, > priority = 0.0, > order = 0 > } > myList = [ > initEntity { entityId = 1, priority = 8.7 }, > initEntity { entityId = 2, priority = 5.4 }, > initEntity { entityId = 3, priority = 2.9 }, > initEntity { entityId = 4, priority = 5.4 }, > initEntity { entityId = 5, priority = 1.3 }, > initEntity { entityId = 6, priority = 3.5 }, > initEntity { entityId = 7, priority = 9.5 } > ] > comparePriority entity1 entity2 = > compare (priority entity1) (priority entity2) > orderByPriority :: [Entity] -> [Entity] > orderByPriority entities = assignOrder orderList 1 > where > orderList = sortBy comparePriority entities > assignOrder [] _ = [] > assignOrder (entity:entities) count = > (entity { order = count }):(assignOrder entities (count + 1)) > instance Show Entity where > show entity = "{" ++ > "entityId:" ++ (show $ entityId entity) ++ "," ++ > "priority:" ++ (show $ priority entity) ++ "," ++ > "order: " ++ (show $ order entity) ++ > "}" -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061101/a17dc3af/attachment.htm From bulat.ziganshin at gmail.com Wed Nov 1 03:33:39 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Wed Nov 1 03:49:01 2006 Subject: [Haskell-cafe] there's a monster in my Haskell! In-Reply-To: <20061101051423.GC3798@pimlott.net> References: <20061101051423.GC3798@pimlott.net> Message-ID: <997798823.20061101113339@gmail.com> Hello Andrew, Wednesday, November 1, 2006, 8:14:23 AM, you wrote: > produced few results. Inspired by Felleisen, and in the spirit of > Halloween, I offer a new alternative: Meet "monsters", your > computational companions in the land of lazy functional programming. > All monsters are capable of devouring values: > devour :: Monster m => a -> m a definitely, writing monad introductions becomes a large business! we already have introduction for machos, for starship builders, now for videokids. i think that in near time all will know that is monad - all except mathematicians :))) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From dmhouse at gmail.com Wed Nov 1 04:00:36 2006 From: dmhouse at gmail.com (David House) Date: Wed Nov 1 04:00:30 2006 Subject: [Haskell-cafe] there's a monster in my Haskell! In-Reply-To: <20061101051423.GC3798@pimlott.net> References: <20061101051423.GC3798@pimlott.net> Message-ID: On 01/11/06, Andrew Pimlott wrote: > I present here a gentle introduction to monsters. Absolutely brilliant. This certainly made me laugh! Perhaps a light-hearted candidate for the Monad.Reader? And do we have any artistic Haskellers out there? Could we get drawings of these monsters? I'd love to see the 'mysterious and awesome IO' in pictorial form. -- -David House, dmhouse@gmail.com From stefan at cs.uu.nl Wed Nov 1 04:29:18 2006 From: stefan at cs.uu.nl (Stefan Holdermans) Date: Wed Nov 1 04:29:13 2006 Subject: [Haskell-cafe] What is the best way to preserve the order of a list In-Reply-To: References: Message-ID: John, > My question is, how do I preserve the ordering of entities in my > list and still be able to assign the proper order values to each > entity? Is there an efficient way to do this? How else might I > improve my orderByPriority algorithm. Straightforwardly, you could do it like this: import List (sortBy) type Priority = Int type Order = Int order :: [Priority] -> [(Priority, Order)] order = unlabel . sortOnLab . assignOrder . sortOnPrio . label where label = zip [0 ..] unlabel = map snd sortOnLab = sortBy (\(l, _) (m, _) -> compare l m) sortOnPrio = sortBy (\(_, p) (_, q) -> compare p q) assignOrder = \xs -> zipWith (\(l, p) o -> (l, (p, o))) xs [0 ..] For instance: > order [5, 2, 3, 7] [(5,2),(2,0),(3,1),(7,3)] HTH, Stefan From simonpj at microsoft.com Wed Nov 1 04:42:43 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Wed Nov 1 04:43:06 2006 Subject: [Haskell-cafe] function types as instances of Num In-Reply-To: <20061026174624.GB1805@sleepingsquirrel.org> References: <20061026174624.GB1805@sleepingsquirrel.org> Message-ID: <036EAC76E7F5EC4996A3B3C3657D41160712FE15@EUR-MSG-21.europe.corp.microsoft.com> Try test' = square . (4 :: a -> (Integer,a)) Otherwise, how is the compiler to know that you want 4 to be of that type? S | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Greg | Buchholz | Sent: 26 October 2006 18:46 | To: haskell-cafe@haskell.org | Subject: [Haskell-cafe] function types as instances of Num | | | Let's say we've got a little stack language, where you compute | things by transformations of stacks, using compositions of functions | from stacks to stacks (represented here as nested tuples). (See also | Chris Okasaki's "Techniques for Embedding Postfix Languages in Haskell" | www.eecs.harvard.edu/~nr/ cs252r/archive/chris-okasaki/hw02.ps ) | | For example, the simple program below calculates the square of 4... | | > {-# OPTIONS -fglasgow-exts #-} | > | > main = print $ test () | > | > test = square . (lit 4) | > | > lit :: Integer -> a -> (Integer,a) | > lit val stack = (val, stack) | > | > dup (a, b) = (a, (a, b)) | > mult (a, (b, c)) = (b*a, c) | > square = mult . dup | | ...now let's say I find that using the function "lit" to annotation | numeric literals ugly. What I really want is something like... | | > test' = square . 4 | | ...Seems simple enough, I'll just make an appropriate instance of Num | and I'll be able to use fromInteger... | | > instance Eq (a -> (Integer, a)) | > instance Show (a -> (Integer, a)) | > instance Num (a -> (Integer, a)) where | > fromInteger = lit | | ...but now when I try it, GHC complains... | | No instance for (Num (a -> (Integer, t))) | arising from the literal `4' at final.hs:15:17 | Possible fix: | add an instance declaration for (Num (a -> (Integer, t))) | In the second argument of `(.)', namely `4' | In the expression: square . 4 | In the definition of `test'': test' = square . 4 | | ...so it seems that (a -> (Integer, t)) can't be unified with (a -> | (Integer, a)), or somesuch. Any thoughts on how to get this to work? | | | Thanks, | | Greg Buchholz | | | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe From jon.fairbairn at cl.cam.ac.uk Wed Nov 1 05:27:53 2006 From: jon.fairbairn at cl.cam.ac.uk (=?utf-8?b?SsOzbiBGYWlyYmFpcm4=?=) Date: Wed Nov 1 05:28:11 2006 Subject: [Haskell-cafe] Re: there's a monster in my Haskell! References: <20061101051423.GC3798@pimlott.net> Message-ID: "David House" writes: > On 01/11/06, Andrew Pimlott wrote: > > I present here a gentle introduction to monsters. > > Absolutely brilliant. This certainly made me laugh! Perhaps a > light-hearted candidate for the Monad.Reader? > > And do we have any artistic Haskellers out there? Could we get > drawings of these monsters? I'd love to see the 'mysterious and > awesome IO' in pictorial form. For that, an image has already (after considerable effort and expense in tracking down the beast) been created: http://tinyurl.com/yddv4z -- J?n Fairbairn Jon.Fairbairn@cl.cam.ac.uk From john at repetae.net Wed Nov 1 06:21:12 2006 From: john at repetae.net (John Meacham) Date: Wed Nov 1 06:20:50 2006 Subject: [Haskell-cafe] Re: there's a monster in my Haskell! In-Reply-To: References: <20061101051423.GC3798@pimlott.net> Message-ID: <20061101112112.GU12041@momenergy.repetae.net> On Wed, Nov 01, 2006 at 10:27:53AM +0000, J?n Fairbairn wrote: > "David House" writes: > > > On 01/11/06, Andrew Pimlott wrote: > > > I present here a gentle introduction to monsters. > > > > Absolutely brilliant. This certainly made me laugh! Perhaps a > > light-hearted candidate for the Monad.Reader? > > > > And do we have any artistic Haskellers out there? Could we get > > drawings of these monsters? I'd love to see the 'mysterious and > > awesome IO' in pictorial form. > > For that, an image has already (after considerable effort > and expense in tracking down the beast) been created: > http://tinyurl.com/yddv4z nice. John -- John Meacham - ?repetae.net?john? From mrchebas at gmail.com Wed Nov 1 08:17:01 2006 From: mrchebas at gmail.com (Alexey Rodriguez) Date: Wed Nov 1 08:16:56 2006 Subject: [Haskell-cafe] hmake and ghc-6.6 Message-ID: <4b39c80a0611010517i3b06073au1a4a6e22a16f13f8@mail.gmail.com> Hello Haskell people, I have been trying to build hmake 3.12 using ghc-6.6 on a Fedora Core Linux running on a dual 64-bit Opteron machine. However, I had the following error related to the readline library: ---- /home/t-alexer/packages/hmake-3.12/script/hmake -hc=ghc HInteractive -d/home/t-alexer/packages/hmake-3.12/targets/x86_64-Linux/obj/interpreter \ -i../hmake -package util -package base -DUSE_READLINE=1 -lreadline -lncurses Warning: package(s) util not available (according to ghc-pkg) MkProg: Can't find module Readline in user directories . ../hmake Or in installed libraries/packages at /home/simonmar/fp/lib/x86_64-unknown-linux/ghc-6.6/imports /home/simonmar/fp/lib/x86_64-unknown-linux/ghc-6.6/imports Asked for by: SimpleLineEditor.hs Fix using the -I, -P, or -package flags. Stop - hmake dependency error. ---- I googled for this error and I saw the following thread in which Malcolm suggested having a fix. http://www.nabble.com/hmake-and-GHC-6.6-t2531880.html I tried to locate hmake's repository but to no avail. There is no link to it from www.haskell.org/hmake and the hmake in the nhc repository is the same as the hmake I downloaded. I will appreciate any help you can offer. Cheers, Alexey P.S. A related question, has any of you tried to build ghc using hat? I am trying to do this to study ghc's internals -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061101/9ec1fdd2/attachment-0001.htm From fmishra at yahoo.com Wed Nov 1 11:13:53 2006 From: fmishra at yahoo.com (Farida Mishra) Date: Wed Nov 1 11:13:53 2006 Subject: [Haskell-cafe] Post mesg Message-ID: <20061101161353.1202.qmail@web35309.mail.mud.yahoo.com> Hi i would like to post mesg this list --------------------------------- Everyone is raving about the all-new Yahoo! Mail. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061101/8fc03fe3/attachment.htm From alaiyeshi025 at 163.com Wed Nov 1 11:49:21 2006 From: alaiyeshi025 at 163.com (alaiyeshi) Date: Wed Nov 1 11:48:53 2006 Subject: [Haskell-cafe]Prime Generator time limit exceeded Message-ID: <002601c6fdd5$afd1c720$8dbec1da@NOTEBOOK> Hi I'm new to Haskell. I found this site on the Haskell wiki https://www.spoj.pl. But I got some trouble on trying to solve the problem titled "Prime Generator" https://www.spoj.pl/problems/PRIME1. The online-judge system tells me "time limit excedded" Would you be so kind to tell me how to make it more faster? And any other suggestion is welcome. Thanks in advance. --------------------------------------Code begin------------------------------------------------------------ module Main where import IO import List main = do input_size<-getLine content<-get_contents (read input_size) mapM_ (\r-> do mapM_ (print) (primeGenerator (parse r)); putStrLn "") content get_contents n | n == 0 = return [] | otherwise = do content<-getLine rests<-get_contents (n-1) return ([content]++rests) primeGenerator [start,end] = [x | x<-[start..end], all (== 1) (map (gcd x) [2..(x-1)]), x/=1] parse s = unfoldr (\x-> case x of [] -> Nothing _ -> Just (head (reads x))) s -------------------------------Code ends-------------------------------------------------------------------------------- (BTW: I'm new to this mailling list also, forgive my rudeness if I am, and forgive my poor English) From haskell at sleepingsquirrel.org Wed Nov 1 12:12:46 2006 From: haskell at sleepingsquirrel.org (Greg Buchholz) Date: Wed Nov 1 12:08:22 2006 Subject: [Haskell-cafe] Re: An example of dependent types [was: Simple GADT parser for the eval example] In-Reply-To: <20061101083056.635C6AC04@Adric.metnet.fnmoc.navy.mil> References: <20061101083056.635C6AC04@Adric.metnet.fnmoc.navy.mil> Message-ID: <20061101171246.GA1742@sleepingsquirrel.org> oleg@pobox.com wrote: > > Greg Buchholz has posed an interesting problem of writing a > typechecker. Given untyped terms of the form ...snip... > We show the solution that uses no GADTs and no representation types. > We retain however the eval function in the previous message that uses > GADT. Our solution uses type classes. It seems to some the > type-checking rules stated as instances of the TypeCheck class take a > particular natural form. ...snip... > > rather than the original terms Exp. The conversion is straightforward, > via Template Haskell: > > > type F = Q TH.Exp > > parse :: Expr -> F > > parse (ELit x) = [e| FLit $(litE . integerL . fromIntegral $ x) |] > > parse (EInc x) = [e| FInc $(parse x) |] > > parse (EIsZ x) = [e| FIsZ $(parse x) |] > > > > t1' = $(parse . read $ e1) > > t2' = $(parse . read $ e2) > > *G> :t t1' > t1' :: FIf FLit FLit FLit > *G> :t t2' > t2' :: FIf (FIsZ FLit) (FInc FLit) (FFst (FPair FLit FLit)) Nice. But using TH means we have to know everthing about the strings we want to evaluate at compile time right? So you can't do something like... main = do l <- getLine print $ (eval.typecheck) ($(parse . read $ l)) ...right? (Even if you can get around GHC complaining about a 'stage restriction'). Whereas, it would be possible with with the "my_read" and other versions. Anyway, as long as we're going down that route, we might as well get rid of the GADTs and go for a pure type class version of "eval"... http://lambda-the-ultimate.org/node/1787 ...(great minds think alike, right? ;-) I guess I should have mentioned that thread in my first message. Thanks, Greg Buchholz From Malcolm.Wallace at cs.york.ac.uk Wed Nov 1 12:04:48 2006 From: Malcolm.Wallace at cs.york.ac.uk (Malcolm Wallace) Date: Wed Nov 1 12:09:49 2006 Subject: [Haskell-cafe] hmake and ghc-6.6 In-Reply-To: <4b39c80a0611010517i3b06073au1a4a6e22a16f13f8@mail.gmail.com> References: <4b39c80a0611010517i3b06073au1a4a6e22a16f13f8@mail.gmail.com> Message-ID: <20061101170448.7d1c9792.Malcolm.Wallace@cs.york.ac.uk> "Alexey Rodriguez" wrote: > I have been trying to build hmake 3.12 using ghc-6.6 on a Fedora Core > Linux running on a dual 64-bit Opteron machine. However, I had the > following error related to the readline library: > ... > I googled for this error and I saw the following thread in which > Malcolm suggested having a fix. > http://www.nabble.com/hmake-and-GHC-6.6-t2531880.html > I tried to locate hmake's repository but to no avail. There is no link > to it from www.haskell.org/hmake and the hmake in the nhc repository > is the same as the hmake I downloaded. hmake does indeed live in the nhc98 darcs repository at http://darcs.haskell.org/nhc98 >From there, you can do a 'make hmakeDist' which will package up a tarball of just the parts needed to build hmake. I will also make a proper bugfix release soon. > P.S. A related question, has any of you tried to build ghc using hat? > I am trying to do this to study ghc's internals I'm pretty sure you will not get ghc to build with Hat. The source code of ghc uses many glasgow extensions, not all of which are (yet) handled by Hat's parser. The unsupported ones include at least unboxed types, and pattern guards. (MPTC, fundeps, existentials etc are OK however). Regards, Malcolm From mrchebas at gmail.com Wed Nov 1 12:14:21 2006 From: mrchebas at gmail.com (Alexey Rodriguez) Date: Wed Nov 1 12:14:13 2006 Subject: [Haskell-cafe] hmake and ghc-6.6 In-Reply-To: <20061101170448.7d1c9792.Malcolm.Wallace@cs.york.ac.uk> References: <4b39c80a0611010517i3b06073au1a4a6e22a16f13f8@mail.gmail.com> <20061101170448.7d1c9792.Malcolm.Wallace@cs.york.ac.uk> Message-ID: <4b39c80a0611010914q69e3a32du8e4220d14199d94a@mail.gmail.com> On 11/1/06, Malcolm Wallace wrote: > > "Alexey Rodriguez" wrote: > > > I have been trying to build hmake 3.12 using ghc-6.6 on a Fedora Core > > Linux running on a dual 64-bit Opteron machine. However, I had the > > following error related to the readline library: > > ... > > I googled for this error and I saw the following thread in which > > Malcolm suggested having a fix. > > http://www.nabble.com/hmake-and-GHC-6.6-t2531880.html > > I tried to locate hmake's repository but to no avail. There is no link > > to it from www.haskell.org/hmake and the hmake in the nhc repository > > is the same as the hmake I downloaded. > > hmake does indeed live in the nhc98 darcs repository at > http://darcs.haskell.org/nhc98 > From there, you can do a 'make hmakeDist' which will package up a > tarball of just the parts needed to build hmake. I will also make a > proper bugfix release soon. Finally I got it to build with a two line change. > P.S. A related question, has any of you tried to build ghc using hat? > > I am trying to do this to study ghc's internals > > I'm pretty sure you will not get ghc to build with Hat. The source code > of ghc uses many glasgow extensions, not all of which are (yet) handled > by Hat's parser. The unsupported ones include at least unboxed types, > and pattern guards. (MPTC, fundeps, existentials etc are OK however). Oh, that's such a pity. I'll have to read the sources in the usual style. Thanks! Alexey -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061101/d257a987/attachment.htm From mrchebas at gmail.com Wed Nov 1 13:18:27 2006 From: mrchebas at gmail.com (Alexey Rodriguez) Date: Wed Nov 1 13:18:20 2006 Subject: [Haskell-cafe] Simple GADT parser for the eval example In-Reply-To: <20061030170026.GA1737@sleepingsquirrel.org> References: <20061030170026.GA1737@sleepingsquirrel.org> Message-ID: <4b39c80a0611011018x9d9c63aj64757776b158a9b6@mail.gmail.com> Hello Greg, It seems that I am late for the party but we used a "GADT parser" in the tool we built for our "Generating Generic Functions" paper[1]. It so happens that I made slides for this material so, if you're interested you can have a look at [2]. The motivation for doing this was that we needed to check whether a simply typed lambda calculus term satisfies a property or not. The road we took was software testing, but for that we needed evaluation and hence the GADT stuff. You might like the fact that these well-typed terms include binding constructs such as lambda abstractions and variables. The code uses some tricks that I borrowed from Conor McBride and company :). Cheers, Alexey [1] http://www.cs.uu.nl/wiki/Alexey/GeneratingGenericFunctions [2] http://abaris.zoo.cs.uu.nl:8080/wiki/pub/Alexey/GeneratingGenericFunctions/CompileGGF.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061101/6d99c19a/attachment.htm From haskell at sleepingsquirrel.org Wed Nov 1 14:01:07 2006 From: haskell at sleepingsquirrel.org (Greg Buchholz) Date: Wed Nov 1 13:56:41 2006 Subject: [Haskell-cafe] Simple GADT parser for the eval example In-Reply-To: <2A7FD85C-3B62-4CC6-B50F-B503BD69C502@cs.chalmers.se> References: <20061030170026.GA1737@sleepingsquirrel.org> <20061101003203.GA6172@sleepingsquirrel.org> <2A7FD85C-3B62-4CC6-B50F-B503BD69C502@cs.chalmers.se> Message-ID: <20061101190107.GB1742@sleepingsquirrel.org> Ulf Norell wrote: > I'm not sure what you're asking... Me neither probably. > , but it's possible to get > > my_read :: .. => Expr -> Term a > > Previously given code: > > >-- Give a GADT for representation types > >data R a where > > Rint :: R Int > > Rbool :: R Bool > > Rpair :: R a -> R b -> R (a,b) Yeah, I especially liked Joost Visser's version which is pretty slick. I was just wondering if it was possible to accomplish the same task in a different way, using type classes instead of GADTs, which would seem to work in a more top-downish fashion, as opposed to bottom-upish. But I'm not an expert enough with type systems to know if the... Ambiguous type variable `b' in the constraint: `MyRead b' arising from use of `my_read' at gadt_wobbly.hs:65:28-36 Probable fix: add a type signature that fixes these type variable(s) ...problem was fixable by adding a type signature or grafting on some additional type machinery. Thanks, Greg Buchholz From hjgtuyl at chello.nl Wed Nov 1 14:47:34 2006 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Wed Nov 1 14:47:28 2006 Subject: [Haskell-cafe] What is the best way to preserve the order of a list In-Reply-To: References: Message-ID: On Wed, 01 Nov 2006 10:29:18 +0100, Stefan Holdermans wrote: > sortOnLab = sortBy (\(l, _) (m, _) -> compare l m) The following does the same: sortOnLab = sort -- Met vriendelijke groet, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ -- Using Opera's revolutionary e-mail client: https://secure.bmtmicro.com/opera/buy-opera.html?AID=789433 From stefan at cs.uu.nl Wed Nov 1 14:50:29 2006 From: stefan at cs.uu.nl (Stefan Holdermans) Date: Wed Nov 1 14:50:22 2006 Subject: [Haskell-cafe] What is the best way to preserve the order of a list In-Reply-To: References: Message-ID: <4460692C-BC2A-4A9C-B7FA-10ABED96CC85@cs.uu.nl> Henk-Jan, >> sortOnLab = sortBy (\(l, _) (m, _) -> compare l m) > > The following does the same: > sortOnLab = sort It does, but I kind of liked the analogy with sortOnPrio, which could have been defined in some other ways as well, of course. Cheers, Stefan From brandonm at yahoo-inc.com Wed Nov 1 15:03:28 2006 From: brandonm at yahoo-inc.com (Brandon Moore) Date: Wed Nov 1 15:05:19 2006 Subject: [Haskell-cafe] What is the best way to preserve the order of a list In-Reply-To: References: Message-ID: <4548FD90.20502@yahoo-inc.com> Henk-Jan van Tuyl wrote: > On Wed, 01 Nov 2006 10:29:18 +0100, Stefan Holdermans > wrote: > >> sortOnLab = sortBy (\(l, _) (m, _) -> compare l m) > > The following does the same: > sortOnLab = sort Not quite, sortOnLab preserves the order of tuples with the same first element while plain sort orders them by the second. Also, only sort requires that the second element of the tuple have an Ord instance (Haskell 98 requires that sort is stable). > Test.QuickCheck.test (\xs -> sort xs == sortOnLab xs) Falsifiable, after 1 tests: [(-3,3),(-3,1)] > sortOnLab [(-3,3),(-3,1)] ==> [(-3,3),(-3,1)] but sort [(-3,3),(-3,1)] ==> [(-3,1),(-3,3)] Also, > map fst $ sortOnLab [(2,asTypeOf),(1,const)] [1,2] > map fst $ sort [(2,asTypeOf),(1,const)] :1:10: No instance for (Ord (a -> a -> a)) arising from use of `sort' at :1:10-38 Possible fix: add an instance declaration for (Ord (a -> a -> a)) In the second argument of `($)', namely `sort [(1, asTypeOf), (1, const)]' In the expression: (map fst) $ (sort [(1, asTypeOf), (1, const)]) In the definition of `it': it = (map fst) $ (sort [(1, asTypeOf), (1, const)]) Brandon From bulat.ziganshin at gmail.com Wed Nov 1 14:26:45 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Wed Nov 1 15:50:18 2006 Subject: [Haskell-cafe] class Defaults Message-ID: <7910235884.20061101222645@gmail.com> Hello haskell-cafe, just one more nice snippet of code: class Defaults a where defaultValue :: a instance Defaults Bool where defaultValue = False instance Defaults [a] where defaultValue = [] instance Defaults (a->a) where defaultValue = id instance Num a => Defaults a where defaultValue = 0 class TestDefaultValue a where isDefaultValue :: a -> Bool instance TestDefaultValue Bool where isDefaultValue = not instance TestDefaultValue [a] where isDefaultValue = null instance Num a => TestDefaultValue a where isDefaultValue = (==0) -- This function is useful for defining default values, -- such as (directory ||| ".") or (memsize ||| 10*mb) a ||| b | isDefaultValue a = b | otherwise = a -- Useful for short-cutting boolean expressions, like this: -- putStr$ (need_separator &&& "\n\n") ++ (need_attention &&& map toUpper) str a &&& b | isDefaultValue a = defaultValue | otherwise = b -- |Apply function to value only if it is not empty unlessNull f xs = xs &&& f xs -- |Recursive list processing until list end, -- for example 'recursive (splitAt n)' splits list -- into the chuunks of n elements recursive :: ([a]->(b,[a])) -> [a] -> [b] recursive f list = list &&& (x:recursive f xs) where (x,xs) = f list -- |Split list into parts whose size defined by calling len_f -- at the yet unprocessed parts of list splitByLen :: ([a]->Int) -> [a] -> [[a]] splitByLen len_f = recursive (\xs -> splitAt (len_f xs) xs) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From westondan at imageworks.com Wed Nov 1 15:50:20 2006 From: westondan at imageworks.com (Dan Weston) Date: Wed Nov 1 15:51:44 2006 Subject: [Haskell-cafe]Prime Generator time limit exceeded In-Reply-To: <002601c6fdd5$afd1c720$8dbec1da@NOTEBOOK> References: <002601c6fdd5$afd1c720$8dbec1da@NOTEBOOK> Message-ID: <4549088C.3060707@imageworks.com> I didn't see any other replies and didn't want to leave you hanging, so... Three hints: 1) you are testing every integer >= 2 as a divisor when you only need to test prime numbers <= floor(sqrt(n)) 2) Since for all n > 2, floor(sqrt(n)) < n, you can use the very primes you are generating in the test part of the function itself, confident that you won't overtake your own function. 3) The function primeGenerator [start,end] seems more efficient that primeGenerator [2,end], but the latter is (almost) always faster, because you need those primes to test for primality. A dropWhile (< start) can trim off the unneeded junk when you're done. 4) It won't make your code any faster, but it maybe more elegant to lazily calculate an infinite list of primes, then truncate with takeWhile (<= end), if only for symmetry with dropWhile (< start) SPOILER ALERT: I have appended two of my own solutions at the end of this e-mail for fun (one with list comprehensions, one in point-free notation). Whether you scroll down to look at them is up to you of course... :) alaiyeshi wrote: > Hi > > I'm new to Haskell. > > I found this site on the Haskell wiki https://www.spoj.pl. But I got some trouble on trying to solve the problem titled "Prime Generator" https://www.spoj.pl/problems/PRIME1. > > The online-judge system tells me "time limit excedded" > Would you be so kind to tell me how to make it more faster? And any other suggestion is welcome. > Thanks in advance. > > --------------------------------------Code begin------------------------------------------------------------ > module Main where > > import IO > import List > > main = > do > input_size<-getLine > content<-get_contents (read input_size) > mapM_ (\r-> do mapM_ (print) (primeGenerator (parse r)); putStrLn "") content > > get_contents n | n == 0 = return [] > | otherwise = > do > content<-getLine > rests<-get_contents (n-1) > return ([content]++rests) > > primeGenerator [start,end] = > [x | x<-[start..end], all (== 1) (map (gcd x) [2..(x-1)]), x/=1] > > parse s = > unfoldr (\x-> case x of > [] -> Nothing > _ -> Just (head (reads x))) s > > -------------------------------Code ends-------------------------------------------------------------------------------- > > (BTW: I'm new to this mailling list also, forgive my rudeness if I am, and forgive my poor English) > > > ------------------------------------------------------------------------ > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe -- Just calculate the infinite list of primes (lazily), -- then trip the range to fit primeGenerator [start,end] = takeWhile (<= end) . dropWhile (< start) $ primes -- Pointed notation with list comprehensions primes = (2 : [x | x <- [3,5..], isPrime x]) -- Efficient test presupposes the existence of primes -- This works because to determine whether p is prime you only need -- to know the primes strictly less than p (except for 2 of course!) isPrime x = null divisors where divisors = [y | y <- onlyUpToSqrtX primes, x `mod` y == 0] onlyUpToSqrtX = fst . span (<= sqrtX) sqrtX = floor (sqrt (fromIntegral x)) -- A point-free notation, as an alternative primes' = (2 : filter isPrime [3,5..]) -- indivisible n > 1 where isPrime = and -- i.e. all are . map (/= 0) -- not equal to 0, applied to . remOf -- remainders of odd ints -- where remOf n is when you remOf n = map (mod n) -- divide into n a list of . flip take primes' -- primes, but only . length -- as many as . takeWhile (<= n) -- are less than n, that is . map (^ 2) -- the square of each of the $ primes' -- primes From westondan at imageworks.com Wed Nov 1 15:58:04 2006 From: westondan at imageworks.com (Dan Weston) Date: Wed Nov 1 15:57:58 2006 Subject: [Haskell-cafe]Prime Generator time limit exceeded In-Reply-To: <4549088C.3060707@imageworks.com> References: <002601c6fdd5$afd1c720$8dbec1da@NOTEBOOK> <4549088C.3060707@imageworks.com> Message-ID: <45490A5C.9050202@imageworks.com> Two more hints I used in my code: 5) Except for 2, all primes are odd. Don't bother testing the evens. 6) sqrt(n) is (a little) costly, but I used it in my first solution for clarity. You can also create an infinite list of squares of primes, then trim the list of primes to the length of (takeWhile (<= n) squarePrimes). I haven't tested whether this is actually faster or slower than using sqrt, though! Math functions take only time, but lists require memory allocation. Dan Weston wrote: > I didn't see any other replies and didn't want to leave you hanging, so... > > Three hints: > > 1) you are testing every integer >= 2 as a divisor when you only need to > test prime numbers <= floor(sqrt(n)) > > 2) Since for all n > 2, floor(sqrt(n)) < n, you can use the very primes > you are generating in the test part of the function itself, confident > that you won't overtake your own function. > > 3) The function primeGenerator [start,end] seems more efficient that > primeGenerator [2,end], but the latter is (almost) always faster, > because you need those primes to test for primality. A dropWhile (< > start) can trim off the unneeded junk when you're done. > > 4) It won't make your code any faster, but it maybe more elegant to > lazily calculate an infinite list of primes, then truncate with > takeWhile (<= end), if only for symmetry with dropWhile (< start) > > > SPOILER ALERT: I have appended two of my own solutions at the end of > this e-mail for fun (one with list comprehensions, one in point-free > notation). Whether you scroll down to look at them is up to you of > course... :) > > alaiyeshi wrote: >> Hi >> >> I'm new to Haskell. >> >> I found this site on the Haskell wiki https://www.spoj.pl. But I got >> some trouble on trying to solve the problem titled "Prime Generator" >> https://www.spoj.pl/problems/PRIME1. >> >> The online-judge system tells me "time limit excedded" >> Would you be so kind to tell me how to make it more faster? And any >> other suggestion is welcome. >> Thanks in advance. >> >> --------------------------------------Code >> begin------------------------------------------------------------ >> module Main where >> >> import IO >> import List >> >> main = do >> input_size<-getLine >> content<-get_contents (read input_size) >> mapM_ (\r-> do mapM_ (print) (primeGenerator (parse r)); >> putStrLn "") content >> >> get_contents n | n == 0 = return [] >> | otherwise = >> do >> content<-getLine >> rests<-get_contents (n-1) >> return ([content]++rests) >> >> primeGenerator [start,end] = >> [x | x<-[start..end], all (== 1) (map (gcd x) >> [2..(x-1)]), x/=1] >> >> parse s = >> unfoldr (\x-> case x of >> [] -> Nothing >> _ -> Just (head (reads x))) s >> >> -------------------------------Code >> ends-------------------------------------------------------------------------------- >> >> >> (BTW: I'm new to this mailling list also, forgive my rudeness if I am, >> and forgive my poor English) >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe > > > > > -- Just calculate the infinite list of primes (lazily), > -- then trip the range to fit > primeGenerator [start,end] = takeWhile (<= end) > . dropWhile (< start) > $ primes > > -- Pointed notation with list comprehensions > primes = (2 : [x | x <- [3,5..], isPrime x]) > > -- Efficient test presupposes the existence of primes > -- This works because to determine whether p is prime you only need > -- to know the primes strictly less than p (except for 2 of course!) > isPrime x = null divisors > where divisors = [y | y <- onlyUpToSqrtX primes, x `mod` y == 0] > onlyUpToSqrtX = fst . span (<= sqrtX) > sqrtX = floor (sqrt (fromIntegral x)) > > -- A point-free notation, as an alternative > primes' = (2 : filter isPrime [3,5..]) -- indivisible n > 1 > where isPrime = and -- i.e. all are > . map (/= 0) -- not equal to 0, applied to > . remOf -- remainders of odd ints > -- where remOf n is when you > remOf n = map (mod n) -- divide into n a list of > . flip take primes' -- primes, but only > . length -- as many as > . takeWhile (<= n) -- are less than n, that is > . map (^ 2) -- the square of each of the > $ primes' -- primes > > From fruehr at willamette.edu Wed Nov 1 16:29:06 2006 From: fruehr at willamette.edu (Fritz Ruehr) Date: Wed Nov 1 16:29:00 2006 Subject: [Haskell-cafe] Black Haskell Hacker's t-shirt (was Re: there's a monster in my Haskell! In-Reply-To: References: <20061101051423.GC3798@pimlott.net> Message-ID: <89223812-4B8A-43AE-A9BB-5B282A7DB768@willamette.edu> I suppose this might be a good time to announce the tentative availability of BLACK t-shirts in the "Haskell Hackers" design, which in fact features a "monster". (Note that I am only responsible for the composition of elements on the shirt: the monster drawing itself comes from a dingbat font.) The design has been on the merchandise logo page for several years (see ), but several people had asked for it on a black shirt, and CafePress (our arbitrarily-preferred production house) only recently announced availability such shirts. By way of fair warning, the black shirts are still considered to be "beta" by CafePress: they are more expensive and can only be printed on one-side. Nevertheless, I made a black version of the "Haskell Hackers"/monster logo which can be ordered here: My beta-tester tells me that it washes well, but that it looks more abstract in black than it does in white, specifically that the monster is less recognizable. (Anyone ordering a shirt might want to compare the two design colors; I haven't made a white one available yet, but would be happy to do so upon request.) -- Fritz PS: as always, Haskell.org merchandise is offered on a non-profit basis. A small amount of funds accrue in the account based on link referrals, which we have used to gift shirts to a few Haskell luminaries. PPS: I wouldn't recommend ordering this design on the new red ("cardinal")-colored shirts. On Nov 1, 2006, at 1:00 AM, David House wrote: > And do we have any artistic Haskellers out there? Could we get > drawings of these monsters? I'd love to see the 'mysterious and > awesome IO' in pictorial form. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061101/cf26f67b/attachment.htm From dm.maillists at gmail.com Wed Nov 1 16:53:05 2006 From: dm.maillists at gmail.com (Daniel McAllansmith) Date: Wed Nov 1 16:52:01 2006 Subject: [Haskell-cafe] Accumulating related XML nodes using HXT In-Reply-To: <4ubqns87ym.fsf@shell.vex.net> References: <200610311010.57004.dm.maillists@gmail.com> <4ubqns87ym.fsf@shell.vex.net> Message-ID: <200611021053.05241.dm.maillists@gmail.com> Apologies if this is a duplicate, the original appears to have gone astray. On Wednesday 01 November 2006 10:57, Albert Lai wrote: > Daniel McAllansmith writes: > > Hello. > > > > I have some html from which I want to extract records. > > Each record is represented within a number of nodes, and all records > > nodes are contained by the same parent node. > > This is very poorly written HTML. The original structure of the data > is destroyed - the parse tree no longer reflects the data structure. > (If a record is to be displayed in several rows, there are proper > ways.) It is syntactically incorrect: nested , and color in
. > (Just ask http://validator.w3.org/ .) Indeed. The original is even worse, with overlapping nodes and other such treasures which makes navigation in HXT tricky at times. > I trust that you are parsing > this because you realize it is all wrong and you want to > programmatically convert it to proper markup. Yep! I sure wouldn't be doing this if I had control of the the original HTML. > > Since the file is unstructured, I choose not to sweat over restoring > the structure in an HXT arrow. The HXT arrow will return a flat list, > just as the file is a flat ensemble. I was about to write a follow-up just as your mail came in... I've ended up with the same solution as you've kindly suggested. Another option I came across is Control.Arrow.ArrowTree.changeChildren which could be used to restore a more normalised structure ready for more processing. Thanks Daniel From isto.aho at dnainternet.net Wed Nov 1 17:16:55 2006 From: isto.aho at dnainternet.net (isto) Date: Wed Nov 1 17:16:42 2006 Subject: [Haskell-cafe] How to improve speed? (MersenneTwister is several times slower than C version) Message-ID: <1162419415.26204.26.camel@localhost.localdomain> Hi all, On HaWiki was an announcement of MersenneTwister made by Lennart Augustsson. On a typical run to find out 10000000th rnd num the output is (code shown below): $ time ./testMTla Testing Mersenne Twister. Result is [3063349438] real 0m4.925s user 0m4.856s I was exercising with the very same algorithm and tried to make it efficient (by using IOUArray): now a typical run looks like (code shown below): $ time ./testMT Testing Mersenne Twister. 3063349438 real 0m3.032s user 0m3.004s The original C-version (modified so that only the last number is shown) gives typically $ time ./mt19937ar outputs of genrand_int32() 3063349438 real 0m0.624s user 0m0.616s Results are similar with 64 bit IOUArray against 64 bit C variant. C seems to work about 5 to 10 times faster in this case. I have tried to do different things but now I'm stuck. unsafeRead and unsafeWrite improved a bit the lazy (STUArray-version) and IOUArray-versions but not very much. I took a look of Core file but then, I'm not sure where the boxed values are ok. E.g. should IOUArray Int Word64 be replaced with something else? Any hints and comments on how to improve the efficiency and make everything better will be appreciated a lot! br, Isto ----------------------------- testMTla.hs (MersenneTwister, see HaWiki) module Main where -- ghc -O3 -optc-O3 -optc-ffast-math -fexcess-precision --make testMTla import MersenneTwister main = do putStrLn "Testing Mersenne Twister." let mt = mersenneTwister 100 w = take 1 (drop 9999999 mt) -- w = take 1 (drop 99 mt) putStrLn $ "Result is " ++ (show w) ----------------------------- ----------------------------- testMT.hs module Main where -- Compile eg with -- ghc -O3 -optc-O3 -optc-ffast-math -fexcess-precision --make testMT import Mersenne genRNums32 :: MT32 -> Int -> IO (MT32) genRNums32 mt nCnt = gRN mt nCnt where gRN :: MT32 -> Int -> IO (MT32) gRN mt nCnt | mt `seq` nCnt `seq` False = undefined gRN mt 1 = do (r,mt') <- next32 mt putStrLn $ (show r) return mt' gRN mt nCnt = do (r,mt') <- next32 mt gRN mt' $! (nCnt-1) main = do putStrLn "Testing Mersenne Twister." mt32 <- initialiseGenerator32 100 genRNums32 mt32 10000000 ----------------------------- ----------------------------- Mersenne.hs (sorry for linewraps) module Mersenne where import Data.Bits import Data.Word import Data.Array.Base import Data.Array.MArray import Data.Array.IO -- import System.Random data MT32 = MT32 (IOUArray Int Word32) Int data MT64 = MT64 (IOUArray Int Word64) Int last32bitsof :: Word32 -> Word32 last32bitsof a = a .&. 0xffffffff -- == (2^32-1) lm32 = 0x7fffffff :: Word32 um32 = 0x80000000 :: Word32 mA32 = 0x9908b0df :: Word32 -- == 2567483615 -- Array of length 624. initialiseGenerator32 :: Int -> IO MT32 initialiseGenerator32 seed = do let s = last32bitsof (fromIntegral seed)::Word32 mt <- newArray (0,623) (0::Word32) unsafeWrite mt 0 s iG mt s 1 mt' <- generateNumbers32 mt return (MT32 mt' 0) where iG :: (IOUArray Int Word32) -> Word32 -> Int -> IO (IOUArray Int Word32) iG mt lastNro n | n == 624 = return mt | otherwise = do let n1 = lastNro `xor` (shiftR lastNro 30) new = (1812433253 * n1 + (fromIntegral n)::Word32) unsafeWrite mt n new iG mt new (n+1) generateNumbers32 :: (IOUArray Int Word32) -> IO (IOUArray Int Word32) generateNumbers32 mt = gLoop 0 mt where gLoop :: Int -> (IOUArray Int Word32) -> IO (IOUArray Int Word32) gLoop i mt | i==623 = do wL <- unsafeRead mt 623 w0 <- unsafeRead mt 0 w396 <- unsafeRead mt 396 let y = (wL .&. um32) .|. (w0 .&. lm32) :: Word32 if even y then unsafeWrite mt 623 (w396 `xor` (shiftR y 1)) else unsafeWrite mt 623 (w396 `xor` (shiftR y 1) `xor` mA32) return mt | otherwise = do wi <- unsafeRead mt i wi1 <- unsafeRead mt (i+1) w3 <- unsafeRead mt ((i+397) `mod` 624) let y = (wi .&. um32) .|. (wi1 .&. lm32) if even y then unsafeWrite mt i (w3 `xor` (shiftR y 1)) else unsafeWrite mt i (w3 `xor` (shiftR y 1) `xor` mA32) gLoop (i+1) mt next32 :: MT32 -> IO (Word32, MT32) next32 (MT32 mt i) | i >= 624 = do mt' <- generateNumbers32 mt let m = MT32 mt' (i `mod` 624) (w,m') <- next32 m return (w,m') | otherwise = do y <- unsafeRead mt i let y1 = y `xor` (shiftR y 11) y2 = y1 `xor` ((shiftL y1 7 ) .&. 0x9d2c5680) -- == 2636928640 y3 = y2 `xor` ((shiftL y2 15) .&. 0xefc60000) -- == 4022730752 y4 = y3 `xor` (shiftR y3 18) return $ (y4, MT32 mt (i+1)) mA64 = 0xB5026F5AA96619E9 :: Word64 um64 = 0xFFFFFFFF80000000 :: Word64 lm64 = 0x7FFFFFFF :: Word64 initialiseGenerator64 :: Int -> IO (MT64) initialiseGenerator64 seed = do let s = (fromIntegral seed)::Word64 mt <- newArray (0,311) (0::Word64) unsafeWrite mt 0 s iG mt s 1 generateNumbers64 mt return (MT64 mt 0) where iG :: (IOUArray Int Word64) -> Word64 -> Int -> IO (IOUArray Int Word64) iG mt lN i | mt `seq` lN `seq` i `seq` False = undefined iG mt lastNro 312 = return mt iG mt lastNro n = do let n1 = lastNro `xor` (shiftR lastNro 62) new = (6364136223846793005 * n1 + (fromIntegral n)::Word64) unsafeWrite mt n new iG mt new $! (n+1) generateNumbers64 :: (IOUArray Int Word64) -> IO () generateNumbers64 mt = gLoop 0 where gLoop :: Int -> IO () gLoop i | i `seq` False = undefined gLoop 311 = do wL <- unsafeRead mt 311 w0 <- unsafeRead mt 0 w155 <- unsafeRead mt 155 let y = (wL .&. um64) .|. (w0 .&. lm64) :: Word64 if even y then unsafeWrite mt 311 (w155 `xor` (shiftR y 1)) else unsafeWrite mt 311 (w155 `xor` (shiftR y 1) `xor` mA64) return () gLoop i = do wi <- unsafeRead mt i wi1 <- unsafeRead mt (i+1) w3 <- unsafeRead mt ((i+156) `mod` 312) let y = (wi .&. um64) .|. (wi1 .&. lm64) if even y then unsafeWrite mt i (w3 `xor` (shiftR y 1)) else unsafeWrite mt i (w3 `xor` (shiftR y 1) `xor` mA64) gLoop $! (i+1) next64 :: MT64 -> IO (Word64, MT64) next64 (MT64 mt 312) = do generateNumbers64 mt let m = MT64 mt 0 (w,m') <- next64 m return (w,m') next64 (MT64 mt i) = do y <- unsafeRead mt i let y1 = y `xor` ((shiftR y 29) .&. 0x5555555555555555) y2 = y1 `xor` ((shiftL y1 17) .&. 0x71D67FFFEDA60000) y3 = y2 `xor` ((shiftL y2 37) .&. 0xFFF7EEE000000000) y4 = y3 `xor` (shiftR y3 43) return $! (y4, MT64 mt (i+1)) From slavomir.kaslev at gmail.com Wed Nov 1 18:06:05 2006 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Wed Nov 1 18:06:00 2006 Subject: [Haskell-cafe] Class Message-ID: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> Hello. I am new to Haskell and I am going through "Haskell: The craft of functional programming". I am trying to grasp haskell's classes and instances, so here is slightly modified code from the book: class Show a => Visible a where toString :: a -> String toString = show size :: a -> Int size = length . show instance Visible a => Visible [a] where toString = concat . map toString size = foldl (+) 0 . map size vSort :: (Visible a, Ord a) => [a] -> String vSort = toString . List.sort s = vSort [1..3] Unfortunetly in ghc it gives the following type error: Ambiguous type variable `a' in the constraints: `Visible a' arising from use of `vSort' at d:/tmp.hs:83:4-8 `Enum a' arising from the arithmetic sequence `1 .. 3' at d:/tmp.hs:83:10-15 `Num a' arising from the literal `3' at d:/tmp.hs:83:14 `Ord a' arising from use of `vSort' at d:/tmp.hs:83:4-8 Probable fix: add a type signature that fixes these type variable(s) Failed, modules loaded: none. As you can see, Visible is nothing more than an adapter to the Show class. How I got thing so far, [1..3] :: (Num a, Enum a) => [a], has a Show instance so does class Num (which 'subclasses' Show). Therefore, I can't see any reason why toString function can't call show from those instances. Can someone please enlighten my (still) C++ thinking head? -- Slavomir Kaslev From slavomir.kaslev at gmail.com Wed Nov 1 18:08:01 2006 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Wed Nov 1 18:07:51 2006 Subject: [Haskell-cafe] Re: Class In-Reply-To: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> References: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> Message-ID: <171dfd0a0611011508g7324d6beu4d75d4557bcca3c9@mail.gmail.com> Err, sorry for the meaningless mail subject. Should be 'Newbie class problem' or something like that. -- Slavomir Kaslev From dons at cse.unsw.edu.au Wed Nov 1 20:17:35 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Wed Nov 1 20:17:33 2006 Subject: [Haskell-cafe] How to improve speed? (MersenneTwister is several times slower than C version) In-Reply-To: <1162419415.26204.26.camel@localhost.localdomain> References: <1162419415.26204.26.camel@localhost.localdomain> Message-ID: <20061102011735.GB6957@cse.unsw.EDU.AU> Now, this will be hard to get close the the highly tuned C. Possibly its doable. The main tricks are documented here: http://haskell.org/haskellwiki/Performance/GHC#Unboxed_types Inspecting the Core to ensure the math is being inlined and unboxed will be the most crucial issue, I'd imagine. Then again, an FFI binding to mersenne.c is also a good idea :) -- Don isto.aho: > Hi all, > > On HaWiki was an announcement of MersenneTwister made by Lennart > Augustsson. On a typical run to find out 10000000th rnd num the output > is (code shown below): > > $ time ./testMTla > Testing Mersenne Twister. > Result is [3063349438] > > real 0m4.925s > user 0m4.856s > > > I was exercising with the very same algorithm and tried to make it > efficient (by using IOUArray): now a typical run looks like (code shown > below): > > $ time ./testMT > Testing Mersenne Twister. > 3063349438 > > real 0m3.032s > user 0m3.004s > > > The original C-version (modified so that only the last number is > shown) gives typically > > $ time ./mt19937ar > outputs of genrand_int32() > 3063349438 > > real 0m0.624s > user 0m0.616s > > Results are similar with 64 bit IOUArray against 64 bit C variant. > C seems to work about 5 to 10 times faster in this case. > > I have tried to do different things but now I'm stuck. unsafeRead > and unsafeWrite improved a bit the lazy (STUArray-version) and > IOUArray-versions but not very much. I took a look of Core file but > then, I'm not sure where the boxed values are ok. E.g. should IOUArray > Int Word64 be replaced with something else? > > Any hints and comments on how to improve the efficiency and make > everything better will be appreciated a lot! > > br, Isto > > ----------------------------- testMTla.hs (MersenneTwister, see HaWiki) > module Main where > > -- ghc -O3 -optc-O3 -optc-ffast-math -fexcess-precision --make testMTla > > import MersenneTwister > > main = do > putStrLn "Testing Mersenne Twister." > let mt = mersenneTwister 100 > w = take 1 (drop 9999999 mt) > -- w = take 1 (drop 99 mt) > putStrLn $ "Result is " ++ (show w) > ----------------------------- > > ----------------------------- testMT.hs > module Main where > > -- Compile eg with > -- ghc -O3 -optc-O3 -optc-ffast-math -fexcess-precision --make testMT > > import Mersenne > > genRNums32 :: MT32 -> Int -> IO (MT32) > genRNums32 mt nCnt = gRN mt nCnt > where gRN :: MT32 -> Int -> IO (MT32) > gRN mt nCnt | mt `seq` nCnt `seq` False = undefined > gRN mt 1 = do > (r,mt') <- next32 mt > putStrLn $ (show r) > return mt' > gRN mt nCnt = do > (r,mt') <- next32 mt > gRN mt' $! (nCnt-1) > > > main = do > putStrLn "Testing Mersenne Twister." > mt32 <- initialiseGenerator32 100 > genRNums32 mt32 10000000 > ----------------------------- > > ----------------------------- Mersenne.hs (sorry for linewraps) > module Mersenne where > > import Data.Bits > import Data.Word > import Data.Array.Base > import Data.Array.MArray > import Data.Array.IO > -- import System.Random > > > data MT32 = MT32 (IOUArray Int Word32) Int > data MT64 = MT64 (IOUArray Int Word64) Int > > > last32bitsof :: Word32 -> Word32 > last32bitsof a = a .&. 0xffffffff -- == (2^32-1) > > lm32 = 0x7fffffff :: Word32 > um32 = 0x80000000 :: Word32 > mA32 = 0x9908b0df :: Word32 -- == 2567483615 > > -- Array of length 624. > initialiseGenerator32 :: Int -> IO MT32 > initialiseGenerator32 seed = do > let s = last32bitsof (fromIntegral seed)::Word32 > mt <- newArray (0,623) (0::Word32) > unsafeWrite mt 0 s > iG mt s 1 > mt' <- generateNumbers32 mt > return (MT32 mt' 0) > where > iG :: (IOUArray Int Word32) -> Word32 -> Int -> IO (IOUArray Int > Word32) > iG mt lastNro n > | n == 624 = return mt > | otherwise = do let n1 = lastNro `xor` (shiftR lastNro 30) > new = (1812433253 * n1 + (fromIntegral n)::Word32) > unsafeWrite mt n new > iG mt new (n+1) > > > generateNumbers32 :: (IOUArray Int Word32) -> IO (IOUArray Int Word32) > generateNumbers32 mt = gLoop 0 mt > where > gLoop :: Int -> (IOUArray Int Word32) -> IO (IOUArray Int Word32) > gLoop i mt > | i==623 = do > wL <- unsafeRead mt 623 > w0 <- unsafeRead mt 0 > w396 <- unsafeRead mt 396 > let y = (wL .&. um32) .|. (w0 .&. lm32) :: Word32 > if even y > then unsafeWrite mt 623 (w396 `xor` (shiftR y 1)) > else unsafeWrite mt 623 (w396 `xor` (shiftR y 1) `xor` mA32) > return mt > | otherwise = do > wi <- unsafeRead mt i > wi1 <- unsafeRead mt (i+1) > w3 <- unsafeRead mt ((i+397) `mod` 624) > let y = (wi .&. um32) .|. (wi1 .&. lm32) > if even y > then unsafeWrite mt i (w3 `xor` (shiftR y 1)) > else unsafeWrite mt i (w3 `xor` (shiftR y 1) `xor` mA32) > gLoop (i+1) mt > > > next32 :: MT32 -> IO (Word32, MT32) > next32 (MT32 mt i) > | i >= 624 = do mt' <- generateNumbers32 mt > let m = MT32 mt' (i `mod` 624) > (w,m') <- next32 m > return (w,m') > | otherwise = do > y <- unsafeRead mt i > let y1 = y `xor` (shiftR y 11) > y2 = y1 `xor` ((shiftL y1 7 ) .&. 0x9d2c5680) -- == 2636928640 > y3 = y2 `xor` ((shiftL y2 15) .&. 0xefc60000) -- == 4022730752 > y4 = y3 `xor` (shiftR y3 18) > return $ (y4, MT32 mt (i+1)) > > > mA64 = 0xB5026F5AA96619E9 :: Word64 > um64 = 0xFFFFFFFF80000000 :: Word64 > lm64 = 0x7FFFFFFF :: Word64 > > initialiseGenerator64 :: Int -> IO (MT64) > initialiseGenerator64 seed = do > let s = (fromIntegral seed)::Word64 > mt <- newArray (0,311) (0::Word64) > unsafeWrite mt 0 s > iG mt s 1 > generateNumbers64 mt > return (MT64 mt 0) > where > iG :: (IOUArray Int Word64) -> Word64 -> Int -> IO (IOUArray Int > Word64) > iG mt lN i | mt `seq` lN `seq` i `seq` False = undefined > iG mt lastNro 312 = return mt > iG mt lastNro n = do > let n1 = lastNro `xor` (shiftR lastNro 62) > new = (6364136223846793005 * n1 + (fromIntegral > n)::Word64) > unsafeWrite mt n new > iG mt new $! (n+1) > > generateNumbers64 :: (IOUArray Int Word64) -> IO () > generateNumbers64 mt = gLoop 0 > where > gLoop :: Int -> IO () > gLoop i | i `seq` False = undefined > gLoop 311 = do > wL <- unsafeRead mt 311 > w0 <- unsafeRead mt 0 > w155 <- unsafeRead mt 155 > let y = (wL .&. um64) .|. (w0 .&. lm64) :: Word64 > if even y > then unsafeWrite mt 311 (w155 `xor` (shiftR y 1)) > else unsafeWrite mt 311 (w155 `xor` (shiftR y 1) `xor` mA64) > return () > gLoop i = do > wi <- unsafeRead mt i > wi1 <- unsafeRead mt (i+1) > w3 <- unsafeRead mt ((i+156) `mod` 312) > let y = (wi .&. um64) .|. (wi1 .&. lm64) > if even y > then unsafeWrite mt i (w3 `xor` (shiftR y 1)) > else unsafeWrite mt i (w3 `xor` (shiftR y 1) `xor` mA64) > gLoop $! (i+1) > > > next64 :: MT64 -> IO (Word64, MT64) > next64 (MT64 mt 312) = do generateNumbers64 mt > let m = MT64 mt 0 > (w,m') <- next64 m > return (w,m') > next64 (MT64 mt i) = do > y <- unsafeRead mt i > let y1 = y `xor` ((shiftR y 29) .&. 0x5555555555555555) > y2 = y1 `xor` ((shiftL y1 17) .&. 0x71D67FFFEDA60000) > y3 = y2 `xor` ((shiftL y2 37) .&. 0xFFF7EEE000000000) > y4 = y3 `xor` (shiftR y3 43) > return $! (y4, MT64 mt (i+1)) > > > > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From nuno at hotmail.co.uk Wed Nov 1 20:22:34 2006 From: nuno at hotmail.co.uk (Nuno Pinto) Date: Wed Nov 1 20:22:26 2006 Subject: [Haskell-cafe] Basic Binary IO Message-ID: Hi all! Today i was reading System.IO and didn't manage to understand how it works just by reading it. I looked the internet for some help on this, but only "advanced" information is available. Can anyone show me how to use openBinaryFile ? Just an example, like opening file "somefile" and separating it into something that can be edited in the code (like 8 bit words) then go to word nr12 and edit the last bit? Thanks! NP _________________________________________________________________ Search from any Web page with powerful protection. Get the FREE Windows Live Toolbar Today! http://www.toolbar.live.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061102/f789bb5a/attachment.htm From rootbeer at redcat.com Wed Nov 1 20:31:03 2006 From: rootbeer at redcat.com (Tom Phoenix) Date: Wed Nov 1 20:30:54 2006 Subject: [Haskell-cafe] Post mesg In-Reply-To: <20061101161353.1202.qmail@web35309.mail.mud.yahoo.com> References: <20061101161353.1202.qmail@web35309.mail.mud.yahoo.com> Message-ID: <31086b240611011731y7db153bbge7ae9a94a3bac659@mail.gmail.com> On 11/1/06, Farida Mishra wrote: > i would like to post mesg this list Your wish has been granted. Cheers! --Tom Phoenix From dons at cse.unsw.edu.au Wed Nov 1 20:31:31 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Wed Nov 1 20:31:27 2006 Subject: [Haskell-cafe] Basic Binary IO In-Reply-To: References: Message-ID: <20061102013131.GC6957@cse.unsw.EDU.AU> nuno: > > Hi all! > > Today i was reading System.IO and didn't manage to > understand how it works just by reading it. > I looked the internet for some help on this, but only > "advanced" information is available. > Can anyone show me how to use openBinaryFile ? > Just an example, like opening file "somefile" and separating > it into something that can be edited in the code (like 8 bit > words) then go to word nr12 and edit the last bit? http://haskell.org/haskellwiki/Binary_IO For flat lists of bytes, use Data.ByteString, for structured data, try NewBinary. There are other options too, documented above. openBinaryFile just sets the line ending handling on windows. I don't think it does what you think it does. -- Don From lennart at augustsson.net Wed Nov 1 20:34:04 2006 From: lennart at augustsson.net (Lennart Augustsson) Date: Wed Nov 1 20:34:45 2006 Subject: [Haskell-cafe] How to improve speed? (MersenneTwister is several times slower than C version) In-Reply-To: <20061102011735.GB6957@cse.unsw.EDU.AU> References: <1162419415.26204.26.camel@localhost.localdomain> <20061102011735.GB6957@cse.unsw.EDU.AU> Message-ID: A big problem with the Mersenne Twister is the shifts. As has been noted elsewhere, ghc doesn't do such a great job on those. -- Lennart On Nov 1, 2006, at 20:17 , Donald Bruce Stewart wrote: > Now, this will be hard to get close the the highly tuned C. > Possibly its > doable. > > The main tricks are documented here: > http://haskell.org/haskellwiki/Performance/GHC#Unboxed_types > > Inspecting the Core to ensure the math is being inlined and unboxed > will > be the most crucial issue, I'd imagine. > > Then again, an FFI binding to mersenne.c is also a good idea :) > > -- Don > > > isto.aho: >> Hi all, >> >> On HaWiki was an announcement of MersenneTwister made by Lennart >> Augustsson. On a typical run to find out 10000000th rnd num the >> output >> is (code shown below): >> >> $ time ./testMTla >> Testing Mersenne Twister. >> Result is [3063349438] >> >> real 0m4.925s >> user 0m4.856s >> >> >> I was exercising with the very same algorithm and tried to make it >> efficient (by using IOUArray): now a typical run looks like (code >> shown >> below): >> >> $ time ./testMT >> Testing Mersenne Twister. >> 3063349438 >> >> real 0m3.032s >> user 0m3.004s >> >> >> The original C-version (modified so that only the last number is >> shown) gives typically >> >> $ time ./mt19937ar >> outputs of genrand_int32() >> 3063349438 >> >> real 0m0.624s >> user 0m0.616s >> >> Results are similar with 64 bit IOUArray against 64 bit C variant. >> C seems to work about 5 to 10 times faster in this case. >> >> I have tried to do different things but now I'm stuck. unsafeRead >> and unsafeWrite improved a bit the lazy (STUArray-version) and >> IOUArray-versions but not very much. I took a look of Core file but >> then, I'm not sure where the boxed values are ok. E.g. should >> IOUArray >> Int Word64 be replaced with something else? >> >> Any hints and comments on how to improve the efficiency and make >> everything better will be appreciated a lot! >> >> br, Isto >> >> ----------------------------- testMTla.hs (MersenneTwister, see >> HaWiki) >> module Main where >> >> -- ghc -O3 -optc-O3 -optc-ffast-math -fexcess-precision --make >> testMTla >> >> import MersenneTwister >> >> main = do >> putStrLn "Testing Mersenne Twister." >> let mt = mersenneTwister 100 >> w = take 1 (drop 9999999 mt) >> -- w = take 1 (drop 99 mt) >> putStrLn $ "Result is " ++ (show w) >> ----------------------------- >> >> ----------------------------- testMT.hs >> module Main where >> >> -- Compile eg with >> -- ghc -O3 -optc-O3 -optc-ffast-math -fexcess-precision --make >> testMT >> >> import Mersenne >> >> genRNums32 :: MT32 -> Int -> IO (MT32) >> genRNums32 mt nCnt = gRN mt nCnt >> where gRN :: MT32 -> Int -> IO (MT32) >> gRN mt nCnt | mt `seq` nCnt `seq` False = undefined >> gRN mt 1 = do >> (r,mt') <- next32 mt >> putStrLn $ (show r) >> return mt' >> gRN mt nCnt = do >> (r,mt') <- next32 mt >> gRN mt' $! (nCnt-1) >> >> >> main = do >> putStrLn "Testing Mersenne Twister." >> mt32 <- initialiseGenerator32 100 >> genRNums32 mt32 10000000 >> ----------------------------- >> >> ----------------------------- Mersenne.hs (sorry for linewraps) >> module Mersenne where >> >> import Data.Bits >> import Data.Word >> import Data.Array.Base >> import Data.Array.MArray >> import Data.Array.IO >> -- import System.Random >> >> >> data MT32 = MT32 (IOUArray Int Word32) Int >> data MT64 = MT64 (IOUArray Int Word64) Int >> >> >> last32bitsof :: Word32 -> Word32 >> last32bitsof a = a .&. 0xffffffff -- == (2^32-1) >> >> lm32 = 0x7fffffff :: Word32 >> um32 = 0x80000000 :: Word32 >> mA32 = 0x9908b0df :: Word32 -- == 2567483615 >> >> -- Array of length 624. >> initialiseGenerator32 :: Int -> IO MT32 >> initialiseGenerator32 seed = do >> let s = last32bitsof (fromIntegral seed)::Word32 >> mt <- newArray (0,623) (0::Word32) >> unsafeWrite mt 0 s >> iG mt s 1 >> mt' <- generateNumbers32 mt >> return (MT32 mt' 0) >> where >> iG :: (IOUArray Int Word32) -> Word32 -> Int -> IO (IOUArray Int >> Word32) >> iG mt lastNro n >> | n == 624 = return mt >> | otherwise = do let n1 = lastNro `xor` (shiftR lastNro 30) >> new = (1812433253 * n1 + (fromIntegral n)::Word32) >> unsafeWrite mt n new >> iG mt new (n+1) >> >> >> generateNumbers32 :: (IOUArray Int Word32) -> IO (IOUArray Int >> Word32) >> generateNumbers32 mt = gLoop 0 mt >> where >> gLoop :: Int -> (IOUArray Int Word32) -> IO (IOUArray Int Word32) >> gLoop i mt >> | i==623 = do >> wL <- unsafeRead mt 623 >> w0 <- unsafeRead mt 0 >> w396 <- unsafeRead mt 396 >> let y = (wL .&. um32) .|. (w0 .&. lm32) :: Word32 >> if even y >> then unsafeWrite mt 623 (w396 `xor` (shiftR y 1)) >> else unsafeWrite mt 623 (w396 `xor` (shiftR y 1) `xor` mA32) >> return mt >> | otherwise = do >> wi <- unsafeRead mt i >> wi1 <- unsafeRead mt (i+1) >> w3 <- unsafeRead mt ((i+397) `mod` 624) >> let y = (wi .&. um32) .|. (wi1 .&. lm32) >> if even y >> then unsafeWrite mt i (w3 `xor` (shiftR y 1)) >> else unsafeWrite mt i (w3 `xor` (shiftR y 1) `xor` mA32) >> gLoop (i+1) mt >> >> >> next32 :: MT32 -> IO (Word32, MT32) >> next32 (MT32 mt i) >> | i >= 624 = do mt' <- generateNumbers32 mt >> let m = MT32 mt' (i `mod` 624) >> (w,m') <- next32 m >> return (w,m') >> | otherwise = do >> y <- unsafeRead mt i >> let y1 = y `xor` (shiftR y 11) >> y2 = y1 `xor` ((shiftL y1 7 ) .&. 0x9d2c5680) -- == >> 2636928640 >> y3 = y2 `xor` ((shiftL y2 15) .&. 0xefc60000) -- == >> 4022730752 >> y4 = y3 `xor` (shiftR y3 18) >> return $ (y4, MT32 mt (i+1)) >> >> >> mA64 = 0xB5026F5AA96619E9 :: Word64 >> um64 = 0xFFFFFFFF80000000 :: Word64 >> lm64 = 0x7FFFFFFF :: Word64 >> >> initialiseGenerator64 :: Int -> IO (MT64) >> initialiseGenerator64 seed = do >> let s = (fromIntegral seed)::Word64 >> mt <- newArray (0,311) (0::Word64) >> unsafeWrite mt 0 s >> iG mt s 1 >> generateNumbers64 mt >> return (MT64 mt 0) >> where >> iG :: (IOUArray Int Word64) -> Word64 -> Int -> IO (IOUArray Int >> Word64) >> iG mt lN i | mt `seq` lN `seq` i `seq` False = undefined >> iG mt lastNro 312 = return mt >> iG mt lastNro n = do >> let n1 = lastNro `xor` (shiftR lastNro 62) >> new = (6364136223846793005 * n1 + (fromIntegral >> n)::Word64) >> unsafeWrite mt n new >> iG mt new $! (n+1) >> >> generateNumbers64 :: (IOUArray Int Word64) -> IO () >> generateNumbers64 mt = gLoop 0 >> where >> gLoop :: Int -> IO () >> gLoop i | i `seq` False = undefined >> gLoop 311 = do >> wL <- unsafeRead mt 311 >> w0 <- unsafeRead mt 0 >> w155 <- unsafeRead mt 155 >> let y = (wL .&. um64) .|. (w0 .&. lm64) :: Word64 >> if even y >> then unsafeWrite mt 311 (w155 `xor` (shiftR y 1)) >> else unsafeWrite mt 311 (w155 `xor` (shiftR y 1) `xor` mA64) >> return () >> gLoop i = do >> wi <- unsafeRead mt i >> wi1 <- unsafeRead mt (i+1) >> w3 <- unsafeRead mt ((i+156) `mod` 312) >> let y = (wi .&. um64) .|. (wi1 .&. lm64) >> if even y >> then unsafeWrite mt i (w3 `xor` (shiftR y 1)) >> else unsafeWrite mt i (w3 `xor` (shiftR y 1) `xor` mA64) >> gLoop $! (i+1) >> >> >> next64 :: MT64 -> IO (Word64, MT64) >> next64 (MT64 mt 312) = do generateNumbers64 mt >> let m = MT64 mt 0 >> (w,m') <- next64 m >> return (w,m') >> next64 (MT64 mt i) = do >> y <- unsafeRead mt i >> let y1 = y `xor` ((shiftR y 29) .&. 0x5555555555555555) >> y2 = y1 `xor` ((shiftL y1 17) .&. 0x71D67FFFEDA60000) >> y3 = y2 `xor` ((shiftL y2 37) .&. 0xFFF7EEE000000000) >> y4 = y3 `xor` (shiftR y3 43) >> return $! (y4, MT64 mt (i+1)) >> >> >> >> >> >> _______________________________________________ >> 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 From daniel.is.fischer at web.de Wed Nov 1 20:47:19 2006 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Wed Nov 1 20:44:51 2006 Subject: [Haskell-cafe] Class In-Reply-To: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> References: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> Message-ID: <200611020244.12812.daniel.is.fischer@web.de> Am Donnerstag, 2. November 2006 00:06 schrieb Slavomir Kaslev: > Hello. > > I am new to Haskell and I am going through "Haskell: The craft of > functional programming". I am trying to grasp haskell's classes and > instances, so here is slightly modified code from the book: > > class Show a => Visible a where > toString :: a -> String > toString = show > size :: a -> Int > size = length . show > > instance Visible a => Visible [a] where > toString = concat . map toString > size = foldl (+) 0 . map size > > vSort :: (Visible a, Ord a) => [a] -> String > vSort = toString . List.sort ^^^^^^^ my ghc complained that List.sort is not in scope, did you import Data.List as List? > > s = vSort [1..3] > > Unfortunetly in ghc it gives the following type error: > Ambiguous type variable `a' in the constraints: > `Visible a' arising from use of `vSort' at d:/tmp.hs:83:4-8 > `Enum a' arising from the arithmetic sequence `1 .. 3' at > d:/tmp.hs:83:10-15 > `Num a' arising from the literal `3' at d:/tmp.hs:83:14 > `Ord a' arising from use of `vSort' at d:/tmp.hs:83:4-8 > Probable fix: add a type signature that fixes these type variable(s) > Failed, modules loaded: none. > > As you can see, Visible is nothing more than an adapter to the Show > class. How I got thing so far, [1..3] :: (Num a, Enum a) => [a], has a > Show instance so does class Num (which 'subclasses' Show). Therefore, > I can't see any reason why toString function can't call show from > those instances. First problem: class Visible has no instances yet, so even if you disambiguate the type by writing e.g. s = vSort [1 :: Int .. 3], you'll get an error message: Visible.hs:20:4: No instance for (Visible Int) arising from use of `vSort' at Visible.hs:20:4-8 Probable fix: add an instance declaration for (Visible Int) In the definition of `s': s = vSort ([1 :: Int .. 3]) And the second problem: The typechecker has no means of determining which type 1 should have. By virtue of the fact that numeric literals are overloaded in Haskell, it has type Num a => a. The use of enumFromTo adds the Enum a constraint and vSort adds Ord and Visible, however there may be many types satisfying these constraints and ghc says it's up to you to select one. And even if there is only one instance of Visible declared, ghc (nor, as far as I know, any other Haskell implementation) won't select that because there might, somewhere in a long-forgotten directory, lie a module dormant in which another instance satisfying all constraints is declared. To sum up: instance selection is left to the user, the compiler does only type _inference_. Often that determines which instance fits, but sometimes you have to give an expression type signature to tell the compiler what to choose. > > Can someone please enlighten my (still) C++ thinking head? Cheers, Daniel From lemmih at gmail.com Wed Nov 1 20:51:12 2006 From: lemmih at gmail.com (Lemmih) Date: Wed Nov 1 20:51:02 2006 Subject: [Haskell-cafe] How to improve speed? (MersenneTwister is several times slower than C version) In-Reply-To: <1162419415.26204.26.camel@localhost.localdomain> References: <1162419415.26204.26.camel@localhost.localdomain> Message-ID: On 11/1/06, isto wrote: > Hi all, > > On HaWiki was an announcement of MersenneTwister made by Lennart > Augustsson. On a typical run to find out 10000000th rnd num the output > is (code shown below): > > $ time ./testMTla > Testing Mersenne Twister. > Result is [3063349438] > > real 0m4.925s > user 0m4.856s > > > I was exercising with the very same algorithm and tried to make it > efficient (by using IOUArray): now a typical run looks like (code shown > below): > > $ time ./testMT > Testing Mersenne Twister. > 3063349438 > > real 0m3.032s > user 0m3.004s > > > The original C-version (modified so that only the last number is > shown) gives typically > > $ time ./mt19937ar > outputs of genrand_int32() > 3063349438 > > real 0m0.624s > user 0m0.616s > > Results are similar with 64 bit IOUArray against 64 bit C variant. > C seems to work about 5 to 10 times faster in this case. > > I have tried to do different things but now I'm stuck. unsafeRead > and unsafeWrite improved a bit the lazy (STUArray-version) and > IOUArray-versions but not very much. I took a look of Core file but > then, I'm not sure where the boxed values are ok. E.g. should IOUArray > Int Word64 be replaced with something else? > > Any hints and comments on how to improve the efficiency and make > everything better will be appreciated a lot! > > br, Isto Greetings, Applying a few optimations can make it about 3x faster. 1. Hoist the array out of your loops. (See generateNumbers32, initialiseGenerator32 and genRNums). 2. Don't create too many new MT32 boxes. Most of the time is spent in 'next32' and changing its type to 'IOUArray Int Word32 -> Int -> IO (Word32, Int)' makes it much faster. 3. Demand more inlining. If you're using GHC, -funfolding-use-threshold=16 will substantially improve the performance. Using 'seq' is generally a bad idea. It can worsen the performance if not used carefully and GHCs strictness analyser is usually good enough. I used the profiler and -ddump-simpl to analyse this program. Donald suggested manual unboxing. However, in this case it won't help much (if at all) since GHC is doing such an excellent job on its own. -- Cheers, Lemmih From lemmih at gmail.com Wed Nov 1 20:54:52 2006 From: lemmih at gmail.com (Lemmih) Date: Wed Nov 1 20:54:43 2006 Subject: [Haskell-cafe] How to improve speed? (MersenneTwister is several times slower than C version) In-Reply-To: References: <1162419415.26204.26.camel@localhost.localdomain> <20061102011735.GB6957@cse.unsw.EDU.AU> Message-ID: On 11/2/06, Lennart Augustsson wrote: > A big problem with the Mersenne Twister is the shifts. As has been > noted elsewhere, ghc doesn't do such a great job on those. Actually, the shifts are only evaluated once (hurrah for lazy evaluation) and with -funfolding-use-threshold=16 they're all compiled to unchecked primitives (GHC.Prim.uncheckedShiftRL#). -- Cheers, Lemmih From lennart at augustsson.net Wed Nov 1 22:04:39 2006 From: lennart at augustsson.net (Lennart Augustsson) Date: Wed Nov 1 22:05:17 2006 Subject: [Haskell-cafe] How to improve speed? (MersenneTwister is several times slower than C version) In-Reply-To: References: <1162419415.26204.26.camel@localhost.localdomain> Message-ID: The whole point of writing the Mersenne Twister was that I wanted to show how a stateful computation could be encapsulated in the ST monad and none of it showing up outside. This aspect of the code is totally gone now when everything is in the IO monad. Is there some good reason to have it in the IO monad? -- Lennart On Nov 1, 2006, at 20:51 , Lemmih wrote: > On 11/1/06, isto wrote: >> Hi all, >> >> On HaWiki was an announcement of MersenneTwister made by Lennart >> Augustsson. On a typical run to find out 10000000th rnd num the >> output >> is (code shown below): >> >> $ time ./testMTla >> Testing Mersenne Twister. >> Result is [3063349438] >> >> real 0m4.925s >> user 0m4.856s >> >> >> I was exercising with the very same algorithm and tried to make it >> efficient (by using IOUArray): now a typical run looks like (code >> shown >> below): >> >> $ time ./testMT >> Testing Mersenne Twister. >> 3063349438 >> >> real 0m3.032s >> user 0m3.004s >> >> >> The original C-version (modified so that only the last number is >> shown) gives typically >> >> $ time ./mt19937ar >> outputs of genrand_int32() >> 3063349438 >> >> real 0m0.624s >> user 0m0.616s >> >> Results are similar with 64 bit IOUArray against 64 bit C variant. >> C seems to work about 5 to 10 times faster in this case. >> >> I have tried to do different things but now I'm stuck. unsafeRead >> and unsafeWrite improved a bit the lazy (STUArray-version) and >> IOUArray-versions but not very much. I took a look of Core file but >> then, I'm not sure where the boxed values are ok. E.g. should >> IOUArray >> Int Word64 be replaced with something else? >> >> Any hints and comments on how to improve the efficiency and make >> everything better will be appreciated a lot! >> >> br, Isto > > Greetings, > > Applying a few optimations can make it about 3x faster. > > 1. Hoist the array out of your loops. (See generateNumbers32, > initialiseGenerator32 and genRNums). > 2. Don't create too many new MT32 boxes. Most of the time is spent in > 'next32' and changing its type to 'IOUArray Int Word32 -> Int -> IO > (Word32, Int)' makes it much faster. > 3. Demand more inlining. If you're using GHC, > -funfolding-use-threshold=16 will substantially improve the > performance. > > Using 'seq' is generally a bad idea. It can worsen the performance if > not used carefully and GHCs strictness analyser is usually good > enough. > I used the profiler and -ddump-simpl to analyse this program. > > Donald suggested manual unboxing. However, in this case it won't help > much (if at all) since GHC is doing such an excellent job on its own. > > -- > Cheers, > Lemmih > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From dons at cse.unsw.edu.au Wed Nov 1 22:12:37 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Wed Nov 1 22:12:36 2006 Subject: [Haskell-cafe] How to improve speed? (MersenneTwister is several times slower than C version) In-Reply-To: References: <1162419415.26204.26.camel@localhost.localdomain> Message-ID: <20061102031237.GA7942@cse.unsw.EDU.AU> lemmih: > On 11/1/06, isto wrote: > >Hi all, > > > >On HaWiki was an announcement of MersenneTwister made by Lennart > >Augustsson. On a typical run to find out 10000000th rnd num the output > >is (code shown below): > > > >$ time ./testMTla > >Testing Mersenne Twister. > >Result is [3063349438] > > > >real 0m4.925s > >user 0m4.856s > > > > > >I was exercising with the very same algorithm and tried to make it > >efficient (by using IOUArray): now a typical run looks like (code shown > >below): > > > >$ time ./testMT > >Testing Mersenne Twister. > >3063349438 > > > >real 0m3.032s > >user 0m3.004s > > > > > >The original C-version (modified so that only the last number is > >shown) gives typically > > > >$ time ./mt19937ar > >outputs of genrand_int32() > >3063349438 > > > >real 0m0.624s > >user 0m0.616s > > > >Results are similar with 64 bit IOUArray against 64 bit C variant. > >C seems to work about 5 to 10 times faster in this case. > > > >I have tried to do different things but now I'm stuck. unsafeRead > >and unsafeWrite improved a bit the lazy (STUArray-version) and > >IOUArray-versions but not very much. I took a look of Core file but > >then, I'm not sure where the boxed values are ok. E.g. should IOUArray > >Int Word64 be replaced with something else? > > > >Any hints and comments on how to improve the efficiency and make > >everything better will be appreciated a lot! > > > >br, Isto > > Greetings, > > Applying a few optimations can make it about 3x faster. > > 1. Hoist the array out of your loops. (See generateNumbers32, > initialiseGenerator32 and genRNums). > 2. Don't create too many new MT32 boxes. Most of the time is spent in > 'next32' and changing its type to 'IOUArray Int Word32 -> Int -> IO > (Word32, Int)' makes it much faster. > 3. Demand more inlining. If you're using GHC, > -funfolding-use-threshold=16 will substantially improve the > performance. > > Using 'seq' is generally a bad idea. It can worsen the performance if > not used carefully and GHCs strictness analyser is usually good > enough. > I used the profiler and -ddump-simpl to analyse this program. > > Donald suggested manual unboxing. However, in this case it won't help > much (if at all) since GHC is doing such an excellent job on its own. I wasn't suggesting manual unboxing, more that you should carefully inspect the Core, and tune with bang patterns where necessary. -funfolding-use-threshold=16 is a good idea though. or =100 ;) -- Don From newhoggy at gmail.com Wed Nov 1 23:00:49 2006 From: newhoggy at gmail.com (John Ky) Date: Wed Nov 1 23:00:40 2006 Subject: [Haskell-cafe] What is the best way to preserve the order of a list (RESOLVED) Message-ID: Thanks Stefan, -John On 11/1/06, Stefan Holdermans wrote: > > John, > > > My question is, how do I preserve the ordering of entities in my > > list and still be able to assign the proper order values to each > > entity? Is there an efficient way to do this? How else might I > > improve my orderByPriority algorithm. > > Straightforwardly, you could do it like this: > > import List (sortBy) > > type Priority = Int > type Order = Int > > order :: [Priority] -> [(Priority, Order)] > order = unlabel . sortOnLab . assignOrder . sortOnPrio . label > where > label = zip [0 ..] > unlabel = map snd > sortOnLab = sortBy (\(l, _) (m, _) -> compare l m) > sortOnPrio = sortBy (\(_, p) (_, q) -> compare p q) > assignOrder = \xs -> zipWith (\(l, p) o -> (l, (p, o))) xs [0 ..] > > For instance: > > > order [5, 2, 3, 7] > [(5,2),(2,0),(3,1),(7,3)] > > HTH, > > Stefan > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061102/92c3e54e/attachment.htm From alaiyeshi025 at 163.com Wed Nov 1 23:33:42 2006 From: alaiyeshi025 at 163.com (alaiyeshi) Date: Wed Nov 1 23:33:14 2006 Subject: [Haskell-cafe]Prime Generator time limit exceeded References: <002601c6fdd5$afd1c720$8dbec1da@NOTEBOOK> <4549088C.3060707@imageworks.com> <45490A5C.9050202@imageworks.com> Message-ID: <005101c6fe38$17ce0840$8dbec1da@NOTEBOOK> Thanks a lot. (you really spoil me;-)) What a stupid mistake I've made!(flush) I'll rewrite my code later. From sjanssen at cse.unl.edu Wed Nov 1 23:58:58 2006 From: sjanssen at cse.unl.edu (Spencer Janssen) Date: Wed Nov 1 23:59:49 2006 Subject: [Haskell-cafe]Prime Generator time limit exceeded In-Reply-To: <002601c6fdd5$afd1c720$8dbec1da@NOTEBOOK> References: <002601c6fdd5$afd1c720$8dbec1da@NOTEBOOK> Message-ID: <7F4DF84C-4AAA-4071-96EF-F80563A6D60B@cse.unl.edu> The problem with your approach is the gratuitous use of division, which tends to be very slow. In my solution, I first generate a list of "seed primes", all primes less than sqrt 1000000000. Then, for each input m and n, I generate all multiples of the seed primes between m and n. I then output each number that isn't a multiple of a seed prime. Tips: - Haskell will infer the Integer type by default, an unbounded type. Operations on Integer are often considerably slower than Int, the corresponding bounded type. - The accumArray function is a handy way to collect all the generated multiples. For maximum speed, use a UArray Int Bool. - gcd is a particularly expensive function to use here, perhaps you can use the mod function instead? - here is a handy function to generate your seed primes: sieve [] = [] sieve (x:xs) = x : [y | y <- xs, y `mod` x /= 0] Spencer Janssen On Nov 1, 2006, at 10:49 AM, alaiyeshi wrote: > Hi > > I'm new to Haskell. > > I found this site on the Haskell wiki https://www.spoj.pl. But I > got some trouble on trying to solve the problem titled "Prime > Generator" https://www.spoj.pl/problems/PRIME1. > > The online-judge system tells me "time limit excedded" > Would you be so kind to tell me how to make it more faster? And any > other suggestion is welcome. > Thanks in advance. > > --------------------------------------Code > begin------------------------------------------------------------ > module Main where > > import IO > import List > > main = > do > input_size<-getLine > content<-get_contents (read input_size) > mapM_ (\r-> do mapM_ (print) (primeGenerator (parse r)); > putStrLn "") content > > get_contents n | n == 0 = return [] > | otherwise = > do > content<-getLine > rests<-get_contents (n-1) > return ([content]++rests) > > primeGenerator [start,end] = > [x | x<-[start..end], all (== 1) (map (gcd x) [2.. > (x-1)]), x/=1] > > parse s = > unfoldr (\x-> case x of > [] -> Nothing > _ -> Just (head (reads x))) s > > -------------------------------Code > ends------------------------------------------------------------------ > -------------- > > (BTW: I'm new to this mailling list also, forgive my rudeness if I > am, and forgive my poor English) > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From dagit at eecs.oregonstate.edu Thu Nov 2 00:45:14 2006 From: dagit at eecs.oregonstate.edu (Jason Dagit) Date: Thu Nov 2 00:45:05 2006 Subject: [Haskell-cafe] Very Small Program Message-ID: Hello, I just found it (in ghci and hugs) that this is a valid haskell program: let 0 = 1 in 0 This program evaluates to 0 (to my surprise). I expected something similar to how this works: let { 1 + 1 = 3; 3 + 1 = 7 } in 1 + 1 + 1 Where you get 7. So, if the 0 is not used as an identifier (ie, defining a function or name of a value), then why doesn't this count as a parse error? And, why didn't I get to locally redefine it? Thanks, Jason From bjpop at csse.unimelb.edu.au Thu Nov 2 01:56:23 2006 From: bjpop at csse.unimelb.edu.au (Bernie Pope) Date: Thu Nov 2 01:55:05 2006 Subject: [Haskell-cafe] Very Small Program In-Reply-To: References: Message-ID: On 02/11/2006, at 4:45 PM, Jason Dagit wrote: > Hello, > > I just found it (in ghci and hugs) that this is a valid haskell > program: > let 0 = 1 in 0 > > This program evaluates to 0 (to my surprise). This is a weird example of a pattern binding, and it is surprising (to me) that the syntax is valid. Because there are no variables on the left-hand-side of the equation, the definition is much the same as: let _ = 1 in 0 The definition that you give suggests that we evaluate the expression "1", then compare it to "0", and then do nothing with the result of the comparison (because it doesn't bind any variables). Though it is weird, it is rather benign, since pattern bindings are evaluated lazily, and in this case never. > > I expected something similar to how this works: > let { 1 + 1 = 3; 3 + 1 = 7 } in 1 + 1 + 1 > > Where you get 7. In this case you are defining the function which is bound to the variable called "+". > > So, if the 0 is not used as an identifier (ie, defining a function or > name of a value), then why doesn't this count as a parse error? And, > why didn't I get to locally redefine it? In the first case the definition is pattern matching against 0, and in the second case the definition is giving the meaning of a variable. While numerical constants are a little bit special in Haskell (they are overloaded), they act much like regular data constructors. When they appear inside a pattern, you are matching against them, rather than re-defining them. One would normally expect to see at least one variable inside the pattern on the left-hand-side of a pattern binding (otherwise what point would there be to the definition?). It may very well be the case that the syntax for Haskell in the Report requires this, but I haven't bothered to check it up. If the Report does require at least one variable in the pattern, it may be the case that hugs and ghc are using a slightly more liberal interpretation of the grammar. Or it could be the case that the Haskell Report does in fact allow such pointless, but benign pattern bindings. Perhaps you could chase this up and see what the Report really does require? Cheers, Bernie. From isto.aho at dnainternet.net Thu Nov 2 02:26:37 2006 From: isto.aho at dnainternet.net (isto) Date: Thu Nov 2 02:26:22 2006 Subject: [Haskell-cafe] How to improve speed? (MersenneTwister is several times slower than C version) In-Reply-To: References: <1162419415.26204.26.camel@localhost.localdomain> Message-ID: <1162452397.5900.7.camel@localhost.localdomain> Hi, When writing IO version, I wasn't aware of other twister versions, and the only reason is/was that it was easiest to me and that I knew (believed) that plain lists would have been inefficient. I just wanted to see and learn, how close to C version this can be made. (And still do.) There were some good suggestions on this thread - next I'll try to get grasp on how to apply the suggestions and do something... br, Isto ke, 2006-11-01 kello 22:04 -0500, Lennart Augustsson kirjoitti: > The whole point of writing the Mersenne Twister was that I wanted to > show how a stateful computation could be encapsulated in the ST monad > and none of it showing up outside. This aspect of the code is > totally gone now when everything is in the IO monad. Is there some > good reason to have it in the IO monad? > From bulat.ziganshin at gmail.com Thu Nov 2 02:34:21 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Nov 2 02:36:01 2006 Subject: [Haskell-cafe] Basic Binary IO In-Reply-To: <20061102013131.GC6957@cse.unsw.EDU.AU> References: <20061102013131.GC6957@cse.unsw.EDU.AU> Message-ID: <508877100.20061102103421@gmail.com> Hello Donald, Thursday, November 2, 2006, 4:31:31 AM, you wrote: >> Just an example, like opening file "somefile" and separating >> it into something that can be edited in the code (like 8 bit >> words) then go to word nr12 and edit the last bit? > http://haskell.org/haskellwiki/Binary_IO > For flat lists of bytes, use Data.ByteString, for structured data, try > NewBinary. you can also use hGetBuf and pointers machinery -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From gale at sefer.org Thu Nov 2 04:52:42 2006 From: gale at sefer.org (Yitzchak Gale) Date: Thu Nov 2 04:52:33 2006 Subject: [Haskell-cafe] A type class puzzle In-Reply-To: <20061031094546.GA7530@lambda> References: <2608b8a80610310102i1e54092bhb04da958a3978def@mail.gmail.com> <20061031094546.GA7530@lambda> Message-ID: <2608b8a80611020152o34501a09ge04c85b1b56f8ad4@mail.gmail.com> On Tue, Oct 31, 2006 I wrote: > Consider the following sequence of functions > that replace a single element in an n-dimensional > list: > > replace0 :: a -> a -> a > replace1 :: Int -> a -> [a] -> [a] > replace2 :: Int -> Int -> a -> [[a]] -> [[a]] > > Generalize this using type classes. Thanks to everyone for the refernces about the variadic composition operator. However, that technique only provides a variable number of arguments at the end of the argument list (like in C, etc.). The puzzle as stated requires them at the beginning. Below is a proposed full solution. Unfortunately, it compiles neither in Hugs nor in GHC. But I don't understand why not. GHC says: Functional dependencies conflict between instance declarations: instance Replace Zero a a (a -> a -> a) instance (...) => Replace (Succ n) a [l] f' Not true. The type constraints on the second instance prevent any overlap. Hugs says: ERROR "./Replace.hs":63 - Instance is more general than a dependency allows *** Instance : Replace (Succ a) b [c] d *** For class : Replace a b c d *** Under dependency : a b -> c d Not true. The type constraints limit the scope to within the fundeps. Here is the program: > {-# OPTIONS_GHC -fglasgow-exts -fallow-undecidable-instances #-} We will need ordinals to count the number of initial function arguments. > data Zero = Zero > data Succ o = Succ o > class Ordinal o where > ordinal :: o > instance Ordinal Zero where > ordinal = Zero > instance Ordinal n => Ordinal (Succ n) where > ordinal = Succ ordinal Args is a model for functions with a variable number of initial arguments of homogeneous type. > data Args a b = Args0 b | ArgsN (a -> Args a b) > instance Functor (Args a) where > fmap f (Args0 x) = Args0 $ f x > fmap f (ArgsN g) = ArgsN $ fmap f . g constN is a simple example of an Args. It models a variation on const (well, flip const, actually) that ignores a variable number of initial arguments. > class Ordinal n => ConstN n where > constN :: n -> b -> Args a b > instance ConstN Zero where > constN _ = Args0 > instance ConstN n => ConstN (Succ n) where > constN (Succ o) = ArgsN . const . constN o We can convert any Args into the actual function that it represents. (The inverse is also possible, but we do not need that here.) > class Ordinal n => ArgsToFunc n a b f where > argsToFunc :: n -> Args a b -> f > instance ArgsToFunc Zero a b b where > argsToFunc _ (Args0 b) = b > instance ArgsToFunc n a b f => ArgsToFunc (Succ n) a b (a -> f) where > argsToFunc (Succ o) (ArgsN g) = argsToFunc o . g When the return type is itself a function, we will need to flip arguments of the internal function out of the Args. > flipOutArgs :: Args a (b -> c) -> b -> Args a c > flipOutArgs (Args0 f) = Args0 . f > flipOutArgs (ArgsN f) x = ArgsN $ flip flipOutArgs x . f flipInArgs is the inverse of flipOutArgs. It requires an ordinal, because we need to know how far in to flip the argument. > class Ordinal n => FlipInArgs n where > flipInArgs :: n -> (b -> Args a c) -> Args a (b -> c) > instance FlipInArgs Zero where > flipInArgs _ f = Args0 $ argsToFunc Zero . f > instance FlipInArgs n => FlipInArgs (Succ n) where > flipInArgs (Succ o) f = ArgsN $ flipInArgs o . g > where g x y = let ArgsN h = f y in h x Now we are ready to construct replace. > class ArgsToFunc n Int (a -> l -> l) f => > Replace n a l f | n a -> l f, f -> n a l > where > replaceA :: n -> Args Int a > replace :: f > instance Replace Zero a a (a -> a -> a) where > replaceA _ = Args0 const > replace = const > instance (Replace n a l f, FlipInArgs n, ConstN n, > ArgsToFunc (Succ n) Int (a -> [l] -> [l]) f') => > Replace (Succ n) a [l] f' where > replaceA (Succ o) = ArgsN mkReplace > where > mkReplace i = flipInArgs o $ flipInArgs o . mkRepl o i > mkRepl o i x xs > | null t = constN o h > | otherwise = fmap (h ++) $ fmap (: tail t) $ > flipOutArgs (flipOutArgs (replaceA o) x) xs > where (h, t) = splitAt i xs > replace = argsToFunc ordinal $ replaceA ordinal From slavomir.kaslev at gmail.com Thu Nov 2 04:57:07 2006 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Thu Nov 2 04:57:49 2006 Subject: Fwd: [Haskell-cafe] Class In-Reply-To: <171dfd0a0611020047h1344c9caqb5432936b82d5663@mail.gmail.com> References: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> <200611020244.12812.daniel.is.fischer@web.de> <171dfd0a0611020047h1344c9caqb5432936b82d5663@mail.gmail.com> Message-ID: <171dfd0a0611020157q6c3afc0blb15bfb7611485b90@mail.gmail.com> ---------- Forwarded message ---------- From: Slavomir Kaslev Date: Nov 2, 2006 10:47 AM Subject: Re: [Haskell-cafe] Class To: Daniel Fischer On 11/2/06, Daniel Fischer wrote: > Am Donnerstag, 2. November 2006 00:06 schrieb Slavomir Kaslev: > > Hello. > > > > I am new to Haskell and I am going through "Haskell: The craft of > > functional programming". I am trying to grasp haskell's classes and > > instances, so here is slightly modified code from the book: > > > > class Show a => Visible a where > > toString :: a -> String > > toString = show > > size :: a -> Int > > size = length . show > > > > instance Visible a => Visible [a] where > > toString = concat . map toString > > size = foldl (+) 0 . map size > > > > vSort :: (Visible a, Ord a) => [a] -> String > > vSort = toString . List.sort > ^^^^^^^ > my ghc complained that List.sort is not in scope, did you import Data.List as > List? Yes, I did imported Data.List. My mistake for forgetting to add it in the post. > > > > s = vSort [1..3] > > > > Unfortunetly in ghc it gives the following type error: > > Ambiguous type variable `a' in the constraints: > > `Visible a' arising from use of `vSort' at d:/tmp.hs:83:4-8 > > `Enum a' arising from the arithmetic sequence `1 .. 3' at > > d:/tmp.hs:83:10-15 > > `Num a' arising from the literal `3' at d:/tmp.hs:83:14 > > `Ord a' arising from use of `vSort' at d:/tmp.hs:83:4-8 > > Probable fix: add a type signature that fixes these type variable(s) > > Failed, modules loaded: none. > > > > As you can see, Visible is nothing more than an adapter to the Show > > class. How I got thing so far, [1..3] :: (Num a, Enum a) => [a], has a > > Show instance so does class Num (which 'subclasses' Show). Therefore, > > I can't see any reason why toString function can't call show from > > those instances. > > First problem: class Visible has no instances yet, so even if you disambiguate > the type by writing e.g. > s = vSort [1 :: Int .. 3], you'll get an error message: > Visible.hs:20:4: > No instance for (Visible Int) > arising from use of `vSort' at Visible.hs:20:4-8 > Probable fix: add an instance declaration for (Visible Int) > In the definition of `s': s = vSort ([1 :: Int .. 3]) Visible 'subclasses' Show. Doesn't this mean that Visible should be defined for all types with Show instances? I don't want to write Visible Int, if ghc has already defined a Show Int instance. > > And the second problem: > The typechecker has no means of determining which type 1 should have. > By virtue of the fact that numeric literals are overloaded in Haskell, it has > type Num a => a. The use of enumFromTo adds the Enum a constraint and vSort > adds Ord and Visible, however there may be many types satisfying these > constraints and ghc says it's up to you to select one. > And even if there is only one instance of Visible declared, ghc (nor, as far > as I know, any other Haskell implementation) won't select that because there > might, somewhere in a long-forgotten directory, lie a module dormant in which > another instance satisfying all constraints is declared. > To sum up: instance selection is left to the user, the compiler does only type > _inference_. Often that determines which instance fits, but sometimes you > have to give an expression type signature to tell the compiler what to > choose. I agree with second problem you pointed out. Thanks for mentioning it. -- Slavomir Kaslev -- Slavomir Kaslev From bulat.ziganshin at gmail.com Thu Nov 2 03:09:57 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Nov 2 05:53:57 2006 Subject: [Haskell-cafe] Class In-Reply-To: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> References: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> Message-ID: <172543329.20061102110957@gmail.com> Hello Slavomir, Thursday, November 2, 2006, 2:06:05 AM, you wrote: > Can someone please enlighten my (still) C++ thinking head? you is not alone :))) look into http://haskell.org/haskellwiki/OOP_vs_type_classes -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Thu Nov 2 03:19:17 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Nov 2 05:54:00 2006 Subject: [Haskell-cafe] Very Small Program In-Reply-To: References: Message-ID: <367021536.20061102111917@gmail.com> Hello Jason, Thursday, November 2, 2006, 8:45:14 AM, you wrote: > let 0 = 1 in 0 > let { 1 + 1 = 3; 3 + 1 = 7 } in 1 + 1 + 1 > Where you get 7. these sippets looks cool :) they may be placed in somewhat like Haskell puzzles -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Thu Nov 2 03:26:47 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Nov 2 05:54:05 2006 Subject: [Haskell-cafe] How to improve speed? (MersenneTwister is several times slower than C version) In-Reply-To: <1162419415.26204.26.camel@localhost.localdomain> References: <1162419415.26204.26.camel@localhost.localdomain> Message-ID: <1396574203.20061102112647@gmail.com> Hello isto, Thursday, November 2, 2006, 1:16:55 AM, you wrote: > I have tried to do different things but now I'm stuck. unsafeRead > and unsafeWrite improved a bit the lazy (STUArray-version) and why you think it's a lazy? :) ST monad is just the same as IO monad internally, only types are different (there is also Lazy.ST monad - this is really lazy) 10-20 times difference is typical for GHC programs. i think that better results are observed only when C version is really bound by memory speed (that is rather typical situation) use JHC if you need to generate really fast code. or use ocaml/clean -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Thu Nov 2 03:28:38 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Nov 2 05:54:11 2006 Subject: [Haskell-cafe] How to improve speed? (MersenneTwister is several times slower than C version) In-Reply-To: References: <1162419415.26204.26.camel@localhost.localdomain> <20061102011735.GB6957@cse.unsw.EDU.AU> Message-ID: <1153674273.20061102112838@gmail.com> Hello Lennart, Thursday, November 2, 2006, 4:34:04 AM, you wrote: > A big problem with the Mersenne Twister is the shifts. As has been > noted elsewhere, ghc doesn't do such a great job on those. #ifdef __GLASGOW_HASKELL__ (I# a) <<# (I# b) = (I# (a `iShiftL#` b)) (I# a) >># (I# b) = (I# (a `uncheckedIShiftRL#` b)) #else /* ! __GLASGOW_HASKELL__ */ a <<# b = a `shiftL` b a >># b = a `shiftR` b #endif /* ! __GLASGOW_HASKELL__ */ -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Thu Nov 2 03:30:04 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Nov 2 05:54:16 2006 Subject: [Haskell-cafe] How to improve speed? (MersenneTwister is several times slower than C version) In-Reply-To: References: <1162419415.26204.26.camel@localhost.localdomain> Message-ID: <18618742.20061102113004@gmail.com> Hello Lennart, Thursday, November 2, 2006, 6:04:39 AM, you wrote: > The whole point of writing the Mersenne Twister was that I wanted to > show how a stateful computation could be encapsulated in the ST monad > and none of it showing up outside. This aspect of the code is > totally gone now when everything is in the IO monad. Is there some > good reason to have it in the IO monad? i think no. ST computations internally are really the same as IO ones -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From ajb at spamcop.net Thu Nov 2 06:21:03 2006 From: ajb at spamcop.net (ajb@spamcop.net) Date: Thu Nov 2 06:20:53 2006 Subject: [Haskell-cafe] Very Small Program In-Reply-To: References: Message-ID: <20061102062103.j4u8ww4s8w0wgc00@webmail.spamcop.net> G'day all. Quoting Bernie Pope : > This is a weird example of a pattern binding, and it is surprising > (to me) that the syntax is valid. Maybe. But you wouldn't balk at this: numzeroes xs = sum [ 1 | 0 <- xs ] ...even if you wouldn't naturally express it that way. Patterns like this are useful in places other than lets. I'd find it more surprising if lets were treated as a special case. > In this case you are defining the function which is bound to the > variable called "+". Though thanks to n+k patterns, this is well-understood to be a confusing and controversial case. > One would normally expect to see at least one variable inside the > pattern on the > left-hand-side of a pattern binding (otherwise what point would there > be to the > definition?). If the pattern is demanded (as it may well be in a list comprehension generator, do block generator or a lambda), then it can be very useful. The programmer is asking for an error/empty list/monad "fail" if the conformality check fails. Cheers, Andrew Bromage From dons at cse.unsw.edu.au Thu Nov 2 06:21:31 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Thu Nov 2 06:21:22 2006 Subject: [Haskell-cafe] How to improve speed? (MersenneTwister is several times slower than C version) In-Reply-To: <1396574203.20061102112647@gmail.com> References: <1162419415.26204.26.camel@localhost.localdomain> <1396574203.20061102112647@gmail.com> Message-ID: <20061102112131.GA10992@cse.unsw.EDU.AU> bulat.ziganshin: > Hello isto, > > Thursday, November 2, 2006, 1:16:55 AM, you wrote: > > > I have tried to do different things but now I'm stuck. unsafeRead > > and unsafeWrite improved a bit the lazy (STUArray-version) and > > why you think it's a lazy? :) ST monad is just the same as IO monad > internally, only types are different (there is also Lazy.ST monad - > this is really lazy) > > 10-20 times difference is typical for GHC programs. ! It's really more like 2-4x. Sometimes better than C. Where's this huge figure coming from Bulat? If you have code that behaves like this, you should report it. -- Don From lennart at augustsson.net Thu Nov 2 08:18:45 2006 From: lennart at augustsson.net (Lennart Augustsson) Date: Thu Nov 2 08:20:00 2006 Subject: [Haskell-cafe] How to improve speed? (MersenneTwister is several times slower than C version) In-Reply-To: <1162452397.5900.7.camel@localhost.localdomain> References: <1162419415.26204.26.camel@localhost.localdomain> <1162452397.5900.7.camel@localhost.localdomain> Message-ID: Oh, sorry, I thought your version was a rewritten version of mine. :) The names are so similar, after all. On Nov 2, 2006, at 02:26 , isto wrote: > Hi, > > When writing IO version, I wasn't aware of other twister versions, > and the only reason is/was that it was easiest to me and that I knew > (believed) that plain lists would have been inefficient. I just > wanted > to see and learn, how close to C version this can be made. (And still > do.) > > There were some good suggestions on this thread - next I'll try > to get grasp on how to apply the suggestions and do something... > > br, Isto > > ke, 2006-11-01 kello 22:04 -0500, Lennart Augustsson kirjoitti: >> The whole point of writing the Mersenne Twister was that I wanted to >> show how a stateful computation could be encapsulated in the ST monad >> and none of it showing up outside. This aspect of the code is >> totally gone now when everything is in the IO monad. Is there some >> good reason to have it in the IO monad? >> > From daniel.is.fischer at web.de Thu Nov 2 08:13:02 2006 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Thu Nov 2 08:33:30 2006 Subject: Fwd: [Haskell-cafe] Class In-Reply-To: <171dfd0a0611020157q6c3afc0blb15bfb7611485b90@mail.gmail.com> References: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> <171dfd0a0611020047h1344c9caqb5432936b82d5663@mail.gmail.com> <171dfd0a0611020157q6c3afc0blb15bfb7611485b90@mail.gmail.com> Message-ID: <200611021413.02659.daniel.is.fischer@web.de> Am Donnerstag, 2. November 2006 10:57 schrieb Slavomir Kaslev: > ---------- Forwarded message ---------- > From: Slavomir Kaslev > Date: Nov 2, 2006 10:47 AM > Subject: Re: [Haskell-cafe] Class > To: Daniel Fischer > > On 11/2/06, Daniel Fischer wrote: > > Am Donnerstag, 2. November 2006 00:06 schrieb Slavomir Kaslev: > > > Hello. > > > > > > I am new to Haskell and I am going through "Haskell: The craft of > > > functional programming". I am trying to grasp haskell's classes and > > > instances, so here is slightly modified code from the book: > > > > > > class Show a => Visible a where > > > toString :: a -> String > > > toString = show > > > size :: a -> Int > > > size = length . show > > > > > > instance Visible a => Visible [a] where > > > toString = concat . map toString > > > size = foldl (+) 0 . map size > > > > > > vSort :: (Visible a, Ord a) => [a] -> String > > > vSort = toString . List.sort > > > > ^^^^^^^ > > my ghc complained that List.sort is not in scope, did you import > > Data.List as List? > > Yes, I did imported Data.List. My mistake for forgetting to add it in the > post. That was not quite what I meant. If I import Data.List, what is in scope are plain "sort" and qualified "Data.List.sort", not "List.sort". To have the latter in scope, I think you would have to import (qualified) Data.List as List > > > > s = vSort [1..3] > > > > > > Unfortunetly in ghc it gives the following type error: > > > Ambiguous type variable `a' in the constraints: > > > `Visible a' arising from use of `vSort' at d:/tmp.hs:83:4-8 > > > `Enum a' arising from the arithmetic sequence `1 .. 3' at > > > d:/tmp.hs:83:10-15 > > > `Num a' arising from the literal `3' at d:/tmp.hs:83:14 > > > `Ord a' arising from use of `vSort' at d:/tmp.hs:83:4-8 > > > Probable fix: add a type signature that fixes these type > > > variable(s) Failed, modules loaded: none. > > > > > > As you can see, Visible is nothing more than an adapter to the Show > > > class. How I got thing so far, [1..3] :: (Num a, Enum a) => [a], has a > > > Show instance so does class Num (which 'subclasses' Show). Therefore, > > > I can't see any reason why toString function can't call show from > > > those instances. > > > > First problem: class Visible has no instances yet, so even if you > > disambiguate the type by writing e.g. > > s = vSort [1 :: Int .. 3], you'll get an error message: > > Visible.hs:20:4: > > No instance for (Visible Int) > > arising from use of `vSort' at Visible.hs:20:4-8 > > Probable fix: add an instance declaration for (Visible Int) > > In the definition of `s': s = vSort ([1 :: Int .. 3]) > > Visible 'subclasses' Show. Doesn't this mean that Visible should be > defined for all types with Show instances? I don't want to write > Visible Int, if ghc has already defined a Show Int instance. No, quite reverse, that Visible is a subclass of Show means that all instances of Visible must also be instances of Show. Perhaps the notation class Show a => Visible a where mislead you, as it may be read that Show implies Visible, while it actually means that Visible _requires_ Show. > > > And the second problem: > > The typechecker has no means of determining which type 1 should have. > > By virtue of the fact that numeric literals are overloaded in Haskell, it > > has type Num a => a. The use of enumFromTo adds the Enum a constraint and > > vSort adds Ord and Visible, however there may be many types satisfying > > these constraints and ghc says it's up to you to select one. > > And even if there is only one instance of Visible declared, ghc (nor, as > > far as I know, any other Haskell implementation) won't select that > > because there might, somewhere in a long-forgotten directory, lie a > > module dormant in which another instance satisfying all constraints is > > declared. > > To sum up: instance selection is left to the user, the compiler does only > > type _inference_. Often that determines which instance fits, but > > sometimes you have to give an expression type signature to tell the > > compiler what to choose. > > I agree with second problem you pointed out. Thanks for mentioning it. > > -- > Slavomir Kaslev No sweat, Daniel From slavomir.kaslev at gmail.com Thu Nov 2 08:42:21 2006 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Thu Nov 2 08:42:11 2006 Subject: [Haskell-cafe] Class In-Reply-To: <3d96ac180611020354r6b8fcef5pa070a748a9393cef@mail.gmail.com> References: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> <200611020244.12812.daniel.is.fischer@web.de> <171dfd0a0611020047h1344c9caqb5432936b82d5663@mail.gmail.com> <171dfd0a0611020157q6c3afc0blb15bfb7611485b90@mail.gmail.com> <3d96ac180611020354r6b8fcef5pa070a748a9393cef@mail.gmail.com> Message-ID: <171dfd0a0611020542h6bdaf19dsa020276d258161eb@mail.gmail.com> On 11/2/06, Sebastian Sylvan wrote: > On 11/2/06, Slavomir Kaslev wrote: > > > > > Visible 'subclasses' Show. Doesn't this mean that Visible should be > > defined for all types with Show instances? > > No, it just means that any type that you want to instantiate in > Visible needs to also have a Show instance (is this a restriction you > really want? See below). Well, yes that's what I meant. I want class Visible for objects that have Show instance and I want to be able to use this Show instance in the definition of Visible. Again this is not some practical example, I am just trying to grasp Haskell classes and instances. > > You could do something like > > instance Show a => Visible a > > (the default implementations that you provided in the class should be > enough, you could possibly move the implementations to the "Show > instance" and remove the Show super class from the Visible class - > then you could make even non-Show types instances of Visible without > having to define their instance for Show as well). > > /S > > > -- > Sebastian Sylvan > +46(0)736-818655 > UIN: 44640862 > This doesn't work either: import List class Visible a where toString :: a -> String size :: a -> Int instance Show a => Visible a where toString = show size = length . show instance Visible a => Visible [a] where toString = concat . map toString size = foldl (+) 0 . map size vSort :: (Visible a, Ord a) => [a] -> String vSort = toString . List.sort s = vSort [1..3] gives: Illegal instance declaration for `Visible a' (The instance type must be of form (T a b c) where T is not a synonym, and a,b,c are distinct type variables) In the instance declaration for `Visible a' Failed, modules loaded: none. at instance Show a => Visible a where. Probably I should reconsider my expectations? How should something like this designed? -- Slavomir Kaslev From bulat.ziganshin at gmail.com Thu Nov 2 09:42:32 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Nov 2 09:42:48 2006 Subject: [Haskell-cafe] Class In-Reply-To: <171dfd0a0611020542h6bdaf19dsa020276d258161eb@mail.gmail.com> References: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> <200611020244.12812.daniel.is.fischer@web.de> <171dfd0a0611020047h1344c9caqb5432936b82d5663@mail.gmail.com> <171dfd0a0611020157q6c3afc0blb15bfb7611485b90@mail.gmail.com> <3d96ac180611020354r6b8fcef5pa070a748a9393cef@mail.gmail.com> <171dfd0a0611020542h6bdaf19dsa020276d258161eb@mail.gmail.com> Message-ID: <721076345.20061102174232@gmail.com> Hello Slavomir, Thursday, November 2, 2006, 4:42:21 PM, you wrote: > instance Show a => Visible a where > toString = show > size = length . show > instance Visible a => Visible [a] where > toString = concat . map toString > size = foldl (+) 0 . map size > Illegal instance declaration for `Visible a' > (The instance type must be of form (T a b c) > where T is not a synonym, and a,b,c are distinct type variables) > In the instance declaration for `Visible a' > Failed, modules loaded: none. > at instance Show a => Visible a where. > Probably I should reconsider my expectations? How should something > like this designed? 1) i'm still highly recommend you wiki i've pointed before. i'd a lot of similar problems until i realized that haskell classes are somethat different form c++ ones 2) there are some proposals that will allow one to specify anti-conditions or priority of declarations. but currently compiler has no way to distinguish that instance should be used, for example, for [Char] - both are good enough. you may use -fglasgow-exts to supress this error message and and then -fallow-incoherent-instances to allow compiler select random definition from these two. you should look into ghc documentation for more details about it in practice, i just define required function bodies and then declare all specific instances i need: toString1 = concat . map toString size1 = foldl (+) 0 . map size instance Visible [Char] where toString = toString1 size = size1 instance Visible [Int] where toString = toString1 size = size1 -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From slavomir.kaslev at gmail.com Thu Nov 2 09:47:37 2006 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Thu Nov 2 09:47:25 2006 Subject: Fwd: [Haskell-cafe] Class In-Reply-To: <171dfd0a0611020643v51a520a4v2719609e5ab6239f@mail.gmail.com> References: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> <200611020244.12812.daniel.is.fischer@web.de> <171dfd0a0611020047h1344c9caqb5432936b82d5663@mail.gmail.com> <171dfd0a0611020157q6c3afc0blb15bfb7611485b90@mail.gmail.com> <3d96ac180611020354r6b8fcef5pa070a748a9393cef@mail.gmail.com> <171dfd0a0611020542h6bdaf19dsa020276d258161eb@mail.gmail.com> <171dfd0a0611020643v51a520a4v2719609e5ab6239f@mail.gmail.com> Message-ID: <171dfd0a0611020647o5e6a17b2t35ef1d68ae55b478@mail.gmail.com> Little by little, I think I am getting closer. class Show a => Visible a where toString :: a -> String toString = show size :: a -> Int size = length . show Is just declaration, not definition. It doesn't define anything, even though it has default implementations for toString and size one still needs to define instance of it. Right? As Sebastian Sylvan proposed, I probably need something like this: class Visible a where toString :: a -> String size :: a -> Int instance Show a => Visible a where toString = show size = length . show But it seems ghc doesn't like instance definitions like 'instance Show a => Visible a where ...'. Why? -- Slavomir Kaslev From alaiyeshi025 at 163.com Thu Nov 2 09:48:39 2006 From: alaiyeshi025 at 163.com (alaiyeshi) Date: Thu Nov 2 09:48:18 2006 Subject: [Haskell-cafe]Prime Generator time limit exceeded References: <002601c6fdd5$afd1c720$8dbec1da@NOTEBOOK> <7F4DF84C-4AAA-4071-96EF-F80563A6D60B@cse.unl.edu> Message-ID: <003001c6fe8e$010fed70$8dbec1da@NOTEBOOK> Thank you for replying. Smart method! I've learned much;-) I'll have a try using UArray. Also, I guess my code still waste too much time "parsing" input (I compiled my code with -prof flag on)... Maybe ByteString may save me (or a smarter brain), What is your opinion about doing faster IO, would you please tell me? From slavomir.kaslev at gmail.com Thu Nov 2 09:51:17 2006 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Thu Nov 2 09:51:05 2006 Subject: [Haskell-cafe] Class In-Reply-To: <721076345.20061102174232@gmail.com> References: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> <200611020244.12812.daniel.is.fischer@web.de> <171dfd0a0611020047h1344c9caqb5432936b82d5663@mail.gmail.com> <171dfd0a0611020157q6c3afc0blb15bfb7611485b90@mail.gmail.com> <3d96ac180611020354r6b8fcef5pa070a748a9393cef@mail.gmail.com> <171dfd0a0611020542h6bdaf19dsa020276d258161eb@mail.gmail.com> <721076345.20061102174232@gmail.com> Message-ID: <171dfd0a0611020651q58c30dbdi405f363e7f13ccf8@mail.gmail.com> On 11/2/06, Bulat Ziganshin wrote: > Hello Slavomir, > > Thursday, November 2, 2006, 4:42:21 PM, you wrote: > > > instance Show a => Visible a where > > toString = show > > size = length . show > > > instance Visible a => Visible [a] where > > toString = concat . map toString > > size = foldl (+) 0 . map size > > > > Illegal instance declaration for `Visible a' > > (The instance type must be of form (T a b c) > > where T is not a synonym, and a,b,c are distinct type variables) > > In the instance declaration for `Visible a' > > Failed, modules loaded: none. > > > at instance Show a => Visible a where. > > > Probably I should reconsider my expectations? How should something > > like this designed? > > 1) i'm still highly recommend you wiki i've pointed before. i'd a lot > of similar problems until i realized that haskell classes are somethat > different form c++ ones I am on it. Thanks for pointing it to me. =-) > > 2) there are some proposals that will allow one to specify > anti-conditions or priority of declarations. but currently compiler > has no way to distinguish that instance should be used, for example, > for [Char] - both are good enough. > > you may use -fglasgow-exts to supress this error message and and then > -fallow-incoherent-instances to allow compiler select random > definition from these two. you should look into ghc documentation for > more details about it > > in practice, i just define required function bodies and then declare > all specific instances i need: > > toString1 = concat . map toString > size1 = foldl (+) 0 . map size > > instance Visible [Char] where > toString = toString1 > size = size1 > > instance Visible [Int] where > toString = toString1 > size = size1 > I wouldn't like to manually define instances of Visible for all types that have Show instances. I think I need something like that: class Visible a where toString :: a -> String size :: a -> Int instance Show a => Visible a where toString = show size = length . show Which still doesn't work. Any ideas? -- Slavomir Kaslev From Sven.Biedermann at Biedermann-Consulting.de Thu Nov 2 10:43:37 2006 From: Sven.Biedermann at Biedermann-Consulting.de (Sven Biedermann) Date: Thu Nov 2 10:41:56 2006 Subject: [Haskell-cafe] Towards an IO-Comonad that preserves referential integry (was: "comonads, io" Jan 02, 2003) Message-ID: <0A7EAB42-437B-4C68-A908-9E4859525286@Biedermann-Consulting.de> Dear Haskellers, The OI Comonad in Richard Kieburtz' paper does break referential integrity, but he worte, that the implementation is just something "...to experiment with". In this papers he states, that a real OI needs special properties. For instance enableOI needs "...to have the effect of copying pointers to currently accessible IO resources, in effect duplicating the current IO environment." So, I wrote a simple OI-Comonad for stdin/stdout only, that preserves referential integrity. At least, my reasoning and the tests I made didn't reveal anything different. The code and some explanations are presented at the end of this mail. Haskellers: Could you review the solution, please? Does it really preserves referential integrity? Or am I completely wrong? Do you have any suggestions on generalizing the idea? I would be glad to hear from you! Best regards Sven Biedermann ---------------------------------------------------------------- The implementation is based on two ideas: 1) The OI outside world is modeled an infinite structure (OIReality) that keeps track effects created in the outside world. All "futures" of a reality at a point of "time" are remembered in a lazy fashion. So, if one probes on referential integrity, the structure will be re-iterated through, playing back already computed results. If a reality at some point of "time" isn't referenced any more, that reality will be reclaimed by the garbage collector. The following statement is an example, that no space leaks occur as long as a specific reality isn't remembered (stdPutStr builds on basic stdPutChar using the standard operators .>> and =>>): extract $ mkOI 'x' .>> (cycle ['A'..'z']) =>> oiPutStr Amazingly, extract $ mkOI 'x' .>> (cycle ['A'..'z']) =>> oiPutStrLn produces a space leak, because the implementation isn't lazy enough, yet. 2) The OI-Comonad is a pointer to the current reality, together with the value, that can be extracted from OI. Whenever an OI ist rememberable by the user, the pointer will be duplicated. This is crucial for referential integrity. Comain, as defined by Andrew Bromage in : comain :: OI a -> () comain w = extract (w .>> show (a,b) =>> oiPutStrLn) where a = extract (w .>> () =>> oiGetChar) b = extract (w .>> () =>> oiGetChar) now works as intended and delivers, if 'x' is typed in on standard input: ('x','x') "a = ..." runs on reality w, yielding 'x' . "b = ..." is just a play back of "a = ...". "extract (w.>> show (a,b) =>> stdPutStrLn)" is another future of w, which just prints ('x','x'). module SimpleOI where import Control.Monad.Instances import System.IO.Unsafe import Data.Char import Data.IORef -------------------------------------- -- copied from http://www.eyrie.org/~zednenem/2004/hsce/ class Functor w => Comonad w where extract :: w a -> a duplicate :: w a -> w (w a) extend :: (w a -> b) -> (w a -> w b) extend f = fmap f . duplicate duplicate = extend id -- | 'fmap' defined in terms of 'extend' liftW :: Comonad w => (a -> b) -> (w a -> w b) liftW f = extend (f . extract) -- | 'extend' with the arguments swapped. Dual to '>>=' for monads. (=>>) :: Comonad w => w a -> (w a -> b) -> w b (=>>) = flip extend -- | Injects a value into the comonad. (.>>) :: Comonad w => w a -> b -> w b w .>> b = extend (\_ -> b) w -- end of copy ------------------------------------- data OIReality = OIReality GetChar [PutChar] Char data GetChar = GetChar Char OIReality data PutChar = PutChar () OIReality constructReality :: Char -> OIReality constructReality c = let r = OIReality (constructGet r) (constructPuts r) c in r constructGet :: OIReality -> GetChar constructGet r = let c = unsafePerformIO $ seq r getChar in GetChar c (constructReality c) constructPut :: OIReality -> Char -> PutChar constructPut r c = let v = unsafePerformIO $ seq r $ putChar c in PutChar v (constructReality c) constructPuts :: OIReality -> [PutChar] constructPuts r = map (constructPut r.chr) [0..255] nextGetCharReality :: OIReality -> OIReality nextGetCharReality (OIReality (GetChar c r) _ _) = r nextPutCharReality :: Char -> OIReality -> OIReality nextPutCharReality c (OIReality _ puts _) = let PutChar v r = puts !! (ord c) in seq v r data OIComonad a = OI (IORef OIReality) a -- extract OI _ a = a instance Functor OIComonad where fmap f (OI ref a) = seq a $ OI (unsafeDuplicateRef ref) (f a) -- too many seq's at the moment instance Comonad OIComonad where duplicate w = fmap (const w) w extract (OI _ a) = a mkOI :: Char -> OIComonad Char mkOI c = OI (unsafePerformIO $ newIORef $ constructReality c) c oiGetChar :: OIComonad a -> Char oiGetChar (OI ref _) = unsafePerformIO $ do { modifyIORef ref nextGetCharReality; OIReality _ _ c <- readIORef ref; return (c) } oiPutChar :: OIComonad Char -> () oiPutChar (OI ref c) = unsafePerformIO $ do { modifyIORef ref (nextPutCharReality c); OIReality _ _ d <- readIORef ref; -- not!? modified without further read return $ seq d ()} unsafeDuplicateRef :: IORef OIReality -> IORef OIReality unsafeDuplicateRef ref = unsafePerformIO $ do { r <- readIORef ref; newIORef r; } oiPutStrLn w = extract $ w =>> oiPutStr .>> '\n' =>> oiPutChar -- space leak if input string is suffiently long -- too many seqs in code oiPutStr w = extract $ oiPutStrS w .>> () oiPutStrS :: OIComonad String -> OIComonad String oiPutStrS w = case (extract w) of [] -> w (c:cs) -> oiPutStrS (w .>> c =>> oiPutChar .>> cs) oiGetLine = "t.b.d. using oiGetChar" -- adapted from http://www.mail-archive.com/haskell-cafe@haskell.org/ msg02408.html comain w = extract (w .>> show (a,b) =>> oiPutStr) where a = extract (w .>> () =>> oiGetChar) b = extract (w .>> () =>> oiGetChar) {- Original from http://www.mail-archive.com/haskell-cafe@haskell.org/ msg02408.html -- Bootstrap into the OI comonad main :: IO () main = return $! comain stdOI -- The following are the OI functions which we use. -- stdGetChar :: OI () -> Char -- stdPutStrLn :: OI String -> () comain :: OI a -> () comain w = coeval (w .>> show (a,b) =>> stdPutStrLn) where a = coeval (w .>> () =>> stdGetChar) b = coeval (w .>> () =>> stdGetChar) -} From dagit at codersbase.com Thu Nov 2 12:32:10 2006 From: dagit at codersbase.com (Jason Dagit) Date: Thu Nov 2 12:31:58 2006 Subject: [Haskell-cafe] Very Small Program In-Reply-To: <20061102062103.j4u8ww4s8w0wgc00@webmail.spamcop.net> References: <20061102062103.j4u8ww4s8w0wgc00@webmail.spamcop.net> Message-ID: On 11/2/06, ajb@spamcop.net wrote: > G'day all. > > Quoting Bernie Pope : > > > This is a weird example of a pattern binding, and it is surprising > > (to me) that the syntax is valid. > > Maybe. But you wouldn't balk at this: > > numzeroes xs = sum [ 1 | 0 <- xs ] > > ...even if you wouldn't naturally express it that way. Patterns like > this are useful in places other than lets. I'd find it more surprising > if lets were treated as a special case. Actually, I had to try it out to see if it would work. That's a neat little trick. I had known that this similar one worked but it uses pattern matching on a data constructor so I never questioned it: numJusts xs = sum [ 1 | Just x <- xs ] thanks, Jason From chad.scherrer at gmail.com Thu Nov 2 12:49:17 2006 From: chad.scherrer at gmail.com (Chad Scherrer) Date: Thu Nov 2 12:49:07 2006 Subject: [Haskell-cafe] Re: Haskell-Cafe Digest, Vol 39, Issue 6 In-Reply-To: <20061102043317.75C9C3244F3@www.haskell.org> References: <20061102043317.75C9C3244F3@www.haskell.org> Message-ID: Lemmih wrote: > Using 'seq' is generally a bad idea. It can worsen the performance if > not used carefully and GHCs strictness analyser is usually good > enough. Is GHC.Conc.pseq any better? Usually the whole point of making things more strict is to optimize performance for pieces you know will be evaluated anyway. It's frustrating if there's not a consistent way to do this that works well. Lately, I've been using lots of strictness annotations and bang patterns - are there non-obvious places this could slow things down? Would it be possible for the type system to distinguish at compile time whether something would need to be evaluated, and optimize away redundant `seq`s? Maybe this is what the strictness analyzer does already. Chad From sjanssen at cse.unl.edu Thu Nov 2 13:04:05 2006 From: sjanssen at cse.unl.edu (Spencer Janssen) Date: Thu Nov 2 13:05:01 2006 Subject: [Haskell-cafe]Prime Generator time limit exceeded In-Reply-To: <003001c6fe8e$010fed70$8dbec1da@NOTEBOOK> References: <002601c6fdd5$afd1c720$8dbec1da@NOTEBOOK> <7F4DF84C-4AAA-4071-96EF-F80563A6D60B@cse.unl.edu> <003001c6fe8e$010fed70$8dbec1da@NOTEBOOK> Message-ID: <203D789F-C8F2-4926-9D52-A070AE1AB869@cse.unl.edu> On Nov 2, 2006, at 8:48 AM, alaiyeshi wrote: > Also, I guess my code still waste too much time "parsing" input (I > compiled my code with -prof flag on)... > Maybe ByteString may save me (or a smarter brain), What is your > opinion about doing faster IO, would you please tell me? ByteString will likely make this problem go faster, but sadly SPOJ doesn't have the FPS library or GHC 6.6. My submission doesn't use any fancy IO tricks and manages to complete in 2.28 seconds. There is one major problem with your IO code. get_contents will read every line of input before doing any other processing or output. This could potentially eat up a ton of memory, and thereby make your program slow. A better approach is to interleave reading input and printing output. Here is the input code from my submission: \begin{code} main = do cases <- readLn replicateM_ cases $ do s <- getLine let [m, n] = map read $ words s {- fill in the blank! -} \end{code} Cheers, Spencer Janssen From alaiyeshi025 at 163.com Thu Nov 2 13:26:37 2006 From: alaiyeshi025 at 163.com (alaiyeshi) Date: Thu Nov 2 13:26:09 2006 Subject: [Haskell-cafe]Prime Generator time limit exceeded References: <002601c6fdd5$afd1c720$8dbec1da@NOTEBOOK> <7F4DF84C-4AAA-4071-96EF-F80563A6D60B@cse.unl.edu> <003001c6fe8e$010fed70$8dbec1da@NOTEBOOK> <203D789F-C8F2-4926-9D52-A070AE1AB869@cse.unl.edu> Message-ID: <000b01c6feac$6fd55600$8dbec1da@NOTEBOOK> Thank you so much! I've met replicateM_ for the first time;-) This could be a "template" for doing online-judge exercises I guess. And it's very useful for newbies like me. Again many Thanks:-) From dagit at codersbase.com Thu Nov 2 13:44:51 2006 From: dagit at codersbase.com (Jason Dagit) Date: Thu Nov 2 13:44:40 2006 Subject: [Haskell-cafe]Prime Generator time limit exceeded In-Reply-To: <203D789F-C8F2-4926-9D52-A070AE1AB869@cse.unl.edu> References: <002601c6fdd5$afd1c720$8dbec1da@NOTEBOOK> <7F4DF84C-4AAA-4071-96EF-F80563A6D60B@cse.unl.edu> <003001c6fe8e$010fed70$8dbec1da@NOTEBOOK> <203D789F-C8F2-4926-9D52-A070AE1AB869@cse.unl.edu> Message-ID: On 11/2/06, Spencer Janssen wrote: > On Nov 2, 2006, at 8:48 AM, alaiyeshi wrote: > > Also, I guess my code still waste too much time "parsing" input (I > > compiled my code with -prof flag on)... > > Maybe ByteString may save me (or a smarter brain), What is your > > opinion about doing faster IO, would you please tell me? > > ByteString will likely make this problem go faster, but sadly SPOJ > doesn't have the FPS library or GHC 6.6. My submission doesn't use > any fancy IO tricks and manages to complete in 2.28 seconds. > > There is one major problem with your IO code. get_contents will read > every line of input before doing any other processing or output. > This could potentially eat up a ton of memory, and thereby make your > program slow. A better approach is to interleave reading input and > printing output. Here is the input code from my submission: > > \begin{code} > main = do > cases <- readLn > replicateM_ cases $ do > s <- getLine > let [m, n] = map read $ words s > {- fill in the blank! -} > \end{code} Wouldn't this be the same as: \begin{code} main = do cases <- readLn -- probably don't need this anymore c <- getContents -- this should be lazy let ls = lines c -- lazy too flip mapM_ ls $ \s -> do let [m, n] = map read $ words s {- fill in the blank! -} \end{code} Initially I was thinking this version might be preferable, but now I see it's actually more lines (although could be condensed). Jason From slavomir.kaslev at gmail.com Thu Nov 2 13:59:38 2006 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Thu Nov 2 13:59:25 2006 Subject: [Haskell-cafe] Class In-Reply-To: <3d96ac180611021051ybd612a5vebec2d5c3a175c43@mail.gmail.com> References: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> <200611020244.12812.daniel.is.fischer@web.de> <171dfd0a0611020047h1344c9caqb5432936b82d5663@mail.gmail.com> <171dfd0a0611020157q6c3afc0blb15bfb7611485b90@mail.gmail.com> <3d96ac180611020354r6b8fcef5pa070a748a9393cef@mail.gmail.com> <171dfd0a0611020542h6bdaf19dsa020276d258161eb@mail.gmail.com> <171dfd0a0611020643v51a520a4v2719609e5ab6239f@mail.gmail.com> <3d96ac180611021051ybd612a5vebec2d5c3a175c43@mail.gmail.com> Message-ID: <171dfd0a0611021059v5bf13e42g2adffc49ea015262@mail.gmail.com> On 11/2/06, Sebastian Sylvan wrote: > On 11/2/06, Slavomir Kaslev wrote: > > Little by little, I think I am getting closer. > > > > class Show a => Visible a where > > toString :: a -> String > > toString = show > > size :: a -> Int > > size = length . show > > > > Is just declaration, not definition. It doesn't define anything, even > > though it has default implementations for toString and size one still > > needs to define instance of it. Right? > > > > As Sebastian Sylvan proposed, I probably need something like this: > > > > class Visible a where > > toString :: a -> String > > size :: a -> Int > > > > instance Show a => Visible a where > > toString = show > > size = length . show > > > > But it seems ghc doesn't like instance definitions like 'instance Show > > a => Visible a where ...'. Why? > > This is not Haskell98 since instance declarations of this form could > cause the type checker to go into an infinite loop. This particular > one is okay, though, but you have to start ghc with > -fallow-undecidable-instances and -fglasgow-exts I'm afraid. > > > -- > Sebastian Sylvan > +46(0)736-818655 > UIN: 44640862 > Thanks, Sebastian. That was helpful. Are there any papers on the subject? -- Slavomir Kaslev From Sven.Biedermann at Biedermann-Consulting.de Thu Nov 2 14:02:22 2006 From: Sven.Biedermann at Biedermann-Consulting.de (Sven Biedermann) Date: Thu Nov 2 14:00:38 2006 Subject: [Haskell-cafe] Towards an IO-Comonad that preserves referential transparency (was: "comonads, io" Jan 02, 2003) In-Reply-To: <0A7EAB42-437B-4C68-A908-9E4859525286@Biedermann-Consulting.de> References: <0A7EAB42-437B-4C68-A908-9E4859525286@Biedermann-Consulting.de> Message-ID: <09B524F3-D817-4231-95DB-5F637B6EB5F5@Biedermann-Consulting.de> I just realized that I mixed up data bases and functional programming and apologize for this. Of course, I meant "referential transparency"! Sven Biedermann Am 02.11.2006 um 16:43 schrieb Sven Biedermann: > Dear Haskellers, > > The OI Comonad in Richard Kieburtz' paper does break referential > integrity, but he worte, that the implementation is just something > "...to experiment with". In this papers he states, that a real > OI needs special properties. For instance enableOI needs "...to > have the > effect of copying pointers to currently accessible IO resources, in > effect duplicating the current IO environment." > > So, I wrote a simple OI-Comonad for stdin/stdout only, that preserves > referential integrity. At least, my reasoning and the tests I made > didn't reveal anything different. > The code and some explanations are presented at the end of this mail. > > Haskellers: Could you review the solution, please? Does it really > preserves referential integrity? Or am I completely wrong? > Do you have any suggestions on generalizing the idea? > > I would be glad to hear from you! > > Best regards > > Sven Biedermann > > > ---------------------------------------------------------------- > > The implementation is based on two ideas: > > 1) The OI outside world is modeled an infinite structure (OIReality) > that keeps track effects created in the outside world. All > "futures" of > a reality at a point of "time" are remembered in a lazy fashion. > So, if > one probes on referential integrity, the structure will be re-iterated > through, playing back already computed results. If a reality at some > point of "time" isn't referenced any more, that reality will be > reclaimed by the garbage collector. > > The following statement is an example, that no space leaks occur as > long > as a specific reality isn't remembered (stdPutStr builds on basic > stdPutChar using the standard operators .>> and =>>): > > extract $ mkOI 'x' .>> (cycle ['A'..'z']) =>> oiPutStr > > Amazingly, > > extract $ mkOI 'x' .>> (cycle ['A'..'z']) =>> oiPutStrLn > > produces a space leak, because the implementation isn't lazy > enough, yet. > > 2) The OI-Comonad is a pointer to the current reality, together > with the > value, that can be extracted from OI. Whenever an OI ist > rememberable by > the user, the pointer will be duplicated. This is crucial for > referential integrity. > > Comain, as defined by Andrew Bromage in : > > comain :: OI a -> () > comain w = extract (w .>> show (a,b) =>> oiPutStrLn) > where a = extract (w .>> () =>> oiGetChar) > b = extract (w .>> () =>> oiGetChar) > > > now works as intended and delivers, if 'x' is typed in on standard > input: > > ('x','x') > > "a = ..." runs on reality w, yielding 'x' . "b = ..." is just a play > back of "a = ...". "extract (w.>> show (a,b) =>> stdPutStrLn)" is > another future of w, which just prints ('x','x'). > > > > > > module SimpleOI where > > import Control.Monad.Instances > import System.IO.Unsafe > import Data.Char > import Data.IORef > > -------------------------------------- > -- copied from http://www.eyrie.org/~zednenem/2004/hsce/ > > class Functor w => Comonad w where > extract :: w a -> a > duplicate :: w a -> w (w a) > extend :: (w a -> b) -> (w a -> w b) > > extend f = fmap f . duplicate > duplicate = extend id > > -- | 'fmap' defined in terms of 'extend' > liftW :: Comonad w => (a -> b) -> (w a -> w b) > liftW f = extend (f . extract) > > -- | 'extend' with the arguments swapped. Dual to '>>=' for monads. > (=>>) :: Comonad w => w a -> (w a -> b) -> w b > (=>>) = flip extend > > -- | Injects a value into the comonad. > (.>>) :: Comonad w => w a -> b -> w b > w .>> b = extend (\_ -> b) w > > -- end of copy > ------------------------------------- > > data OIReality = OIReality GetChar [PutChar] Char > data GetChar = GetChar Char OIReality > data PutChar = PutChar () OIReality > > constructReality :: Char -> OIReality > constructReality c = let r = OIReality (constructGet r) > (constructPuts r) c > in r > > constructGet :: OIReality -> GetChar > constructGet r = let c = unsafePerformIO $ seq r getChar in GetChar > c (constructReality c) > > > constructPut :: OIReality -> Char -> PutChar > constructPut r c = let v = unsafePerformIO $ seq r $ putChar c in > PutChar v (constructReality c) > > constructPuts :: OIReality -> [PutChar] > constructPuts r = map (constructPut r.chr) [0..255] > > nextGetCharReality :: OIReality -> OIReality > nextGetCharReality (OIReality (GetChar c r) _ _) = r > > nextPutCharReality :: Char -> OIReality -> OIReality > nextPutCharReality c (OIReality _ puts _) = let PutChar v r = > puts !! (ord c) in seq v r > > > > data OIComonad a = OI (IORef OIReality) a > > -- extract OI _ a = a > instance Functor OIComonad where > fmap f (OI ref a) = seq a $ OI (unsafeDuplicateRef ref) (f a) -- > too many seq's at the moment > > instance Comonad OIComonad where > duplicate w = fmap (const w) w > extract (OI _ a) = a > > mkOI :: Char -> OIComonad Char > mkOI c = OI (unsafePerformIO $ newIORef $ constructReality c) c > > oiGetChar :: OIComonad a -> Char > oiGetChar (OI ref _) = unsafePerformIO $ do { > modifyIORef ref nextGetCharReality; > OIReality _ _ c <- readIORef ref; > return (c) } > > oiPutChar :: OIComonad Char -> () > oiPutChar (OI ref c) = unsafePerformIO $ do { > modifyIORef ref (nextPutCharReality c); > OIReality _ _ d <- readIORef ref; -- not!? modified without > further read > return $ seq d ()} > > unsafeDuplicateRef :: IORef OIReality -> IORef OIReality > unsafeDuplicateRef ref = unsafePerformIO $ do { > r <- readIORef ref; > newIORef r; } > > oiPutStrLn w = extract $ w =>> oiPutStr .>> '\n' =>> oiPutChar -- > space leak if input string is suffiently long > -- > too many seqs in code > > oiPutStr w = extract $ oiPutStrS w .>> () > > oiPutStrS :: OIComonad String -> OIComonad String > oiPutStrS w = case (extract w) of > [] -> w > (c:cs) -> oiPutStrS (w .>> c =>> oiPutChar .>> cs) > > oiGetLine = "t.b.d. using oiGetChar" > > > -- adapted from http://www.mail-archive.com/haskell- > cafe@haskell.org/msg02408.html > comain w = extract (w .>> show (a,b) =>> oiPutStr) > where > a = extract (w .>> () =>> oiGetChar) > b = extract (w .>> () =>> oiGetChar) > > > {- Original from http://www.mail-archive.com/haskell- > cafe@haskell.org/msg02408.html > > -- Bootstrap into the OI comonad > main :: IO () > main = return $! comain stdOI > > -- The following are the OI functions which we use. > -- stdGetChar :: OI () -> Char > -- stdPutStrLn :: OI String -> () > > comain :: OI a -> () > comain w > = coeval (w .>> show (a,b) =>> stdPutStrLn) > where > a = coeval (w .>> () =>> stdGetChar) > b = coeval (w .>> () =>> stdGetChar) > > -} > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From isto.aho at dnainternet.net Thu Nov 2 14:09:21 2006 From: isto.aho at dnainternet.net (isto) Date: Thu Nov 2 14:09:40 2006 Subject: [Haskell-cafe] How to improve speed? (MersenneTwister is several times slower than C version) In-Reply-To: References: <1162419415.26204.26.camel@localhost.localdomain> <1162452397.5900.7.camel@localhost.localdomain> Message-ID: <1162494562.13653.28.camel@localhost.localdomain> Hi & no problems (I didn't tell it clearly right away), I modified the code along the comments given by Lemmih and things improved a lot. mod-operator can be removed by two loops as in C version, which still further improved the speed. I tried this with the old version and the speed-up was next to nothing. The new version can be found below. Now, the results are comparable to the C version. On the second run it was even better, but usually it is about 0.78 on my machine. $ time ./testMT Testing Mersenne Twister. 3063349438 real 0m0.791s user 0m0.776s sys 0m0.008s $ time ./testMT Testing Mersenne Twister. 3063349438 real 0m0.414s user 0m0.400s Can somebody tell, why this happens? There were similar timings with ST-version and with the old version (so that it sometimes runs almost twice as fast or twice as slow than normally). Is this something system dependent (amd64/ubuntu)? C version seems to be within 10% that is between 0.60 and 0.66. Anyhow, this random generator now seems to randomly outperform this particular C version :) C version is located at http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html About Lemmih's proposals. Did I follow them correctly? I'm using ghc and there the inlining demanding seemed to work. With =100 there are more often 0.4 timings than with =16, but also =100 gives 0.78 seconds often (majority of runs). And can something still be done? At this point I would leave FFI and other languages out as one goal here is to learn Haskelling and somehow solutions that require writing code only in one language sounds nicer. br, Isto to, 2006-11-02 kello 08:18 -0500, Lennart Augustsson kirjoitti: > Oh, sorry, I thought your version was a rewritten version of mine. :) > The names are so similar, after all. -------------------------- Mersenne.hs (64bit version removed) module Mersenne where import Data.Bits import Data.Word import Data.Array.Base import Data.Array.MArray import Data.Array.IO data MT32 = MT32 (IOUArray Int Word32) Int last32bitsof :: Word32 -> Word32 last32bitsof a = a .&. 0xffffffff -- == (2^32-1) lm32 = 0x7fffffff :: Word32 um32 = 0x80000000 :: Word32 mA32 = 0x9908b0df :: Word32 -- == 2567483615 -- Array of length 624. initialiseGenerator32 :: Int -> IO MT32 initialiseGenerator32 seed = do let s = last32bitsof (fromIntegral seed)::Word32 mt <- newArray (0,623) (0::Word32) unsafeWrite mt 0 s mtLoop mt s 1 generateNumbers32 mt return (MT32 mt 0) mtLoop :: (IOUArray Int Word32) -> Word32 -> Int -> IO (IOUArray Int Word32) mtLoop mt lastNro n = loop lastNro n where loop :: Word32 -> Int -> IO (IOUArray Int Word32) loop lastNro n | n == 624 = return mt | otherwise = do let n1 = lastNro `xor` (shiftR lastNro 30) new = (1812433253 * n1 + (fromIntegral n)::Word32) unsafeWrite mt n new loop new $! (n+1) generateNumbers32 :: (IOUArray Int Word32) -> IO () generateNumbers32 mt = do gLoop1 0 gLoop2 227 wL <- unsafeRead mt 623 w0 <- unsafeRead mt 0 w396 <- unsafeRead mt 396 let y = (wL .&. um32) .|. (w0 .&. lm32) :: Word32 if even y then unsafeWrite mt 623 (w396 `xor` (shiftR y 1)) else unsafeWrite mt 623 (w396 `xor` (shiftR y 1) `xor` mA32) return () where gLoop1 :: Int -> IO () gLoop1 227 = return () gLoop1 i = do wi <- unsafeRead mt i wi1 <- unsafeRead mt (i+1) -- w3 <- unsafeRead mt ((i+397) `mod` 624) w3 <- unsafeRead mt (i+397) let y = (wi .&. um32) .|. (wi1 .&. lm32) if even y then unsafeWrite mt i (w3 `xor` (shiftR y 1)) else unsafeWrite mt i (w3 `xor` (shiftR y 1) `xor` mA32) gLoop1 $! (i+1) gLoop2 :: Int -> IO () gLoop2 623 = return () gLoop2 i = do wi <- unsafeRead mt i wi1 <- unsafeRead mt (i+1) -- w3 <- unsafeRead mt ((i+397) `mod` 624) w3 <- unsafeRead mt (i-227) let y = (wi .&. um32) .|. (wi1 .&. lm32) if even y then unsafeWrite mt i (w3 `xor` (shiftR y 1)) else unsafeWrite mt i (w3 `xor` (shiftR y 1) `xor` mA32) gLoop2 $! (i+1) {- gLoop :: Int -> IO () gLoop 623 = do wL <- unsafeRead mt 623 w0 <- unsafeRead mt 0 w396 <- unsafeRead mt 396 let y = (wL .&. um32) .|. (w0 .&. lm32) :: Word32 if even y then unsafeWrite mt 623 (w396 `xor` (shiftR y 1)) else unsafeWrite mt 623 (w396 `xor` (shiftR y 1) `xor` mA32) return () gLoop i = do wi <- unsafeRead mt i wi1 <- unsafeRead mt (i+1) w3 <- unsafeRead mt ((i+397) `mod` 624) let y = (wi .&. um32) .|. (wi1 .&. lm32) if even y then unsafeWrite mt i (w3 `xor` (shiftR y 1)) else unsafeWrite mt i (w3 `xor` (shiftR y 1) `xor` mA32) gLoop $! (i+1) -} -- next32 :: MT32 -> IO (Word32, MT32) -- next32 (MT32 mt 624) = do -- next32 (MT32 mt i) = do next32 :: IOUArray Int Word32 -> Int -> IO (Word32, Int) next32 mt 624 = do generateNumbers32 mt -- let m = MT32 mt 0 -- (w,m') <- next32 m -- return (w,m') (w,iN) <- next32 mt 0 return (w,iN) next32 mt i = do y <- unsafeRead mt i let y1 = y `xor` (shiftR y 11) y2 = y1 `xor` ((shiftL y1 7 ) .&. 0x9d2c5680) -- == 2636928640 y3 = y2 `xor` ((shiftL y2 15) .&. 0xefc60000) -- == 4022730752 y4 = y3 `xor` (shiftR y3 18) return $ (y4, (i+1)) -- return $ (y4, MT32 mt (i+1)) -------------------------- -------------------------- testMT.hs module Main where -- Compile eg with -- ghc -O3 -optc-O3 -optc-ffast-math -fexcess-precision -- -funfolding-use-threshold=16 --make testMT import Mersenne import GHC.Prim -- genRNums32 :: MT32 -> Int -> IO Int -- genRNums32 mt nCnt = gRN mt nCnt genRNums32 :: MT32 -> Int -> IO MT32 genRNums32 (MT32 mt pos) nCnt = gRN nCnt pos where gRN :: Int -> Int -> IO MT32 gRN 1 iCurr = do (r,iNew) <- next32 mt iCurr putStrLn $ (show r) return (MT32 mt iNew) gRN nCnt iCurr = do (_,iNew) <- next32 mt iCurr gRN (nCnt-1) $! iNew main = do putStrLn "Testing Mersenne Twister." mt32 <- initialiseGenerator32 100 genRNums32 mt32 10000000 -------------------------- From sylvan at student.chalmers.se Thu Nov 2 14:25:45 2006 From: sylvan at student.chalmers.se (Sebastian Sylvan) Date: Thu Nov 2 14:25:42 2006 Subject: [Haskell-cafe] Class In-Reply-To: <171dfd0a0611021059v5bf13e42g2adffc49ea015262@mail.gmail.com> References: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> <200611020244.12812.daniel.is.fischer@web.de> <171dfd0a0611020047h1344c9caqb5432936b82d5663@mail.gmail.com> <171dfd0a0611020157q6c3afc0blb15bfb7611485b90@mail.gmail.com> <3d96ac180611020354r6b8fcef5pa070a748a9393cef@mail.gmail.com> <171dfd0a0611020542h6bdaf19dsa020276d258161eb@mail.gmail.com> <171dfd0a0611020643v51a520a4v2719609e5ab6239f@mail.gmail.com> <3d96ac180611021051ybd612a5vebec2d5c3a175c43@mail.gmail.com> <171dfd0a0611021059v5bf13e42g2adffc49ea015262@mail.gmail.com> Message-ID: <3d96ac180611021125v16e1bba7x8dc78352814e0ae3@mail.gmail.com> On 11/2/06, Slavomir Kaslev wrote: > On 11/2/06, Sebastian Sylvan wrote: > > On 11/2/06, Slavomir Kaslev wrote: > > > Little by little, I think I am getting closer. > > > > > > class Show a => Visible a where > > > toString :: a -> String > > > toString = show > > > size :: a -> Int > > > size = length . show > > > > > > Is just declaration, not definition. It doesn't define anything, even > > > though it has default implementations for toString and size one still > > > needs to define instance of it. Right? > > > > > > As Sebastian Sylvan proposed, I probably need something like this: > > > > > > class Visible a where > > > toString :: a -> String > > > size :: a -> Int > > > > > > instance Show a => Visible a where > > > toString = show > > > size = length . show > > > > > > But it seems ghc doesn't like instance definitions like 'instance Show > > > a => Visible a where ...'. Why? > > > > This is not Haskell98 since instance declarations of this form could > > cause the type checker to go into an infinite loop. This particular > > one is okay, though, but you have to start ghc with > > -fallow-undecidable-instances and -fglasgow-exts I'm afraid. > > > > > > -- > > Sebastian Sylvan > > +46(0)736-818655 > > UIN: 44640862 > > > > Thanks, Sebastian. That was helpful. Are there any papers on the subject? > The users guid to GHC explains it quite clearly, in my opinion, though I'm sure there are some papers on the subject as well (I can't think of any right now, though). /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862 From steve at fenestra.com Thu Nov 2 14:36:47 2006 From: steve at fenestra.com (Steve Schafer) Date: Thu Nov 2 14:36:33 2006 Subject: [Haskell-cafe] Decorating a list of strings Message-ID: <06ikk25ilu2mkikh9oikm5d2g1ebbqr9d4@4ax.com> I have a list of text strings: ["Alice", "Bob", "Cindy", "Bob", "Bob", "Dave", "Cindy"] As you can see, some of the strings occur only once; others appear two or more times. I would like to end up with a new list, according to the following rules: 1) If a string occurs only once in the original list, then that string appears unchanged in the new list. 2) If a string occurs more than once in the original list, then each occurrences of that string is "decorated" with a numerical suffix indicating its relative position among its peers. In the case of the above list, the result of applying these rules would be: ["Alice", "Bob:1", "Cindy:1", "Bob:2", "Bob:3", "Dave", "Cindy:2"] So, how do we do this? The straightforward approach is to traverse the list twice, once to build a table of repeat counts for the different strings, and a second time to generate the new list, based on the old list plus the table of repeat counts. Of course, it's possible to streamline this into a single traversal by building up a list of thunks at the same time as the table of repeat counts is generated, and then to resolve those thunks by applying them in one fell swoop to the table. But while this does _conceptually_ streamline the problem, it doesn't offer any practical improvement; it takes at least as much processing effort to resolve the thunks as it would to make a second pass through the list. Can we do better? I can't think of a way to do better, and my gut feeling is that there isn't one (in general, it's impossible to know whether the first element of the new list will be "Alice" or "Alice:1" until the entire original list has been traversed), but I thought I'd put the question out to the community to see if anyone had any brilliant insights. Steve Schafer Fenestra Technologies Corp. http://www.fenestra.com/ From nicolas.frisby at gmail.com Thu Nov 2 14:51:16 2006 From: nicolas.frisby at gmail.com (Nicolas Frisby) Date: Thu Nov 2 14:51:07 2006 Subject: [Haskell-cafe] Towards an IO-Comonad that preserves referential transparency (was: "comonads, io" Jan 02, 2003) In-Reply-To: <09B524F3-D817-4231-95DB-5F637B6EB5F5@Biedermann-Consulting.de> References: <0A7EAB42-437B-4C68-A908-9E4859525286@Biedermann-Consulting.de> <09B524F3-D817-4231-95DB-5F637B6EB5F5@Biedermann-Consulting.de> Message-ID: <5ce89fb50611021151sf155e85td2c800d4bae7b67b@mail.gmail.com> OI has been lingering in the back of my mind during my own comonadic adventures. One thing that's bothered me is the signature of comain. comain :: OI () -> () If the OI comonad is to represent values "in the context of the RealWorld", and yet we can have multiple and differing copies of the RealWorld context, then this seems to match the multiple worlds perspective (which is why I think Kieburtz' experimental implementation was doomed to violate referential transparency). That is I want any deterministic program to be of top-level type: comain :: OI () -> OI () The intuition is that the program as a whole receives the initial world description, then is allowed to duplicate and manipulate that world in any number of ways, but it has to choose one final world as its choice. All other real worlds are discarded. The OI () -> () signature doesn't allow for the program to tell me what the resulting RealWorld ought to be. An implementation of this doesn't seem impossible (as opposed to improbable) for file IO or references (your filesystem/cell store would have to be transactional and "multi-ported"). It does become a bit mind boggling for concurrency or any other multi-agent paradigm (networking, screen and keyboard IO, etc.)--it seems that the other agents would have to be savvy to the multiple worlds perspective. Transactional systems certainly seem like a ripe application area for the Product comonad with a RealWorld abstract data type as the carried context. My apologies for not actually commenting on your code. Nick On 11/2/06, Sven Biedermann wrote: > I just realized that I mixed up data bases and functional programming > and apologize for this. Of course, I meant "referential transparency"! > > Sven Biedermann > > Am 02.11.2006 um 16:43 schrieb Sven Biedermann: > > > Dear Haskellers, > > > > The OI Comonad in Richard Kieburtz' paper does break referential > > integrity, but he worte, that the implementation is just something > > "...to experiment with". In this papers he states, that a real > > OI needs special properties. For instance enableOI needs "...to > > have the > > effect of copying pointers to currently accessible IO resources, in > > effect duplicating the current IO environment." > > > > So, I wrote a simple OI-Comonad for stdin/stdout only, that preserves > > referential integrity. At least, my reasoning and the tests I made > > didn't reveal anything different. > > The code and some explanations are presented at the end of this mail. > > > > Haskellers: Could you review the solution, please? Does it really > > preserves referential integrity? Or am I completely wrong? > > Do you have any suggestions on generalizing the idea? > > > > I would be glad to hear from you! > > > > Best regards > > > > Sven Biedermann > > > > > > ---------------------------------------------------------------- > > > > The implementation is based on two ideas: > > > > 1) The OI outside world is modeled an infinite structure (OIReality) > > that keeps track effects created in the outside world. All > > "futures" of > > a reality at a point of "time" are remembered in a lazy fashion. > > So, if > > one probes on referential integrity, the structure will be re-iterated > > through, playing back already computed results. If a reality at some > > point of "time" isn't referenced any more, that reality will be > > reclaimed by the garbage collector. > > > > The following statement is an example, that no space leaks occur as > > long > > as a specific reality isn't remembered (stdPutStr builds on basic > > stdPutChar using the standard operators .>> and =>>): > > > > extract $ mkOI 'x' .>> (cycle ['A'..'z']) =>> oiPutStr > > > > Amazingly, > > > > extract $ mkOI 'x' .>> (cycle ['A'..'z']) =>> oiPutStrLn > > > > produces a space leak, because the implementation isn't lazy > > enough, yet. > > > > 2) The OI-Comonad is a pointer to the current reality, together > > with the > > value, that can be extracted from OI. Whenever an OI ist > > rememberable by > > the user, the pointer will be duplicated. This is crucial for > > referential integrity. > > > > Comain, as defined by Andrew Bromage in : > > > > comain :: OI a -> () > > comain w = extract (w .>> show (a,b) =>> oiPutStrLn) > > where a = extract (w .>> () =>> oiGetChar) > > b = extract (w .>> () =>> oiGetChar) > > > > > > now works as intended and delivers, if 'x' is typed in on standard > > input: > > > > ('x','x') > > > > "a = ..." runs on reality w, yielding 'x' . "b = ..." is just a play > > back of "a = ...". "extract (w.>> show (a,b) =>> stdPutStrLn)" is > > another future of w, which just prints ('x','x'). > > > > > > > > > > > > module SimpleOI where > > > > import Control.Monad.Instances > > import System.IO.Unsafe > > import Data.Char > > import Data.IORef > > > > -------------------------------------- > > -- copied from http://www.eyrie.org/~zednenem/2004/hsce/ > > > > class Functor w => Comonad w where > > extract :: w a -> a > > duplicate :: w a -> w (w a) > > extend :: (w a -> b) -> (w a -> w b) > > > > extend f = fmap f . duplicate > > duplicate = extend id > > > > -- | 'fmap' defined in terms of 'extend' > > liftW :: Comonad w => (a -> b) -> (w a -> w b) > > liftW f = extend (f . extract) > > > > -- | 'extend' with the arguments swapped. Dual to '>>=' for monads. > > (=>>) :: Comonad w => w a -> (w a -> b) -> w b > > (=>>) = flip extend > > > > -- | Injects a value into the comonad. > > (.>>) :: Comonad w => w a -> b -> w b > > w .>> b = extend (\_ -> b) w > > > > -- end of copy > > ------------------------------------- > > > > data OIReality = OIReality GetChar [PutChar] Char > > data GetChar = GetChar Char OIReality > > data PutChar = PutChar () OIReality > > > > constructReality :: Char -> OIReality > > constructReality c = let r = OIReality (constructGet r) > > (constructPuts r) c > > in r > > > > constructGet :: OIReality -> GetChar > > constructGet r = let c = unsafePerformIO $ seq r getChar in GetChar > > c (constructReality c) > > > > > > constructPut :: OIReality -> Char -> PutChar > > constructPut r c = let v = unsafePerformIO $ seq r $ putChar c in > > PutChar v (constructReality c) > > > > constructPuts :: OIReality -> [PutChar] > > constructPuts r = map (constructPut r.chr) [0..255] > > > > nextGetCharReality :: OIReality -> OIReality > > nextGetCharReality (OIReality (GetChar c r) _ _) = r > > > > nextPutCharReality :: Char -> OIReality -> OIReality > > nextPutCharReality c (OIReality _ puts _) = let PutChar v r = > > puts !! (ord c) in seq v r > > > > > > > > data OIComonad a = OI (IORef OIReality) a > > > > -- extract OI _ a = a > > instance Functor OIComonad where > > fmap f (OI ref a) = seq a $ OI (unsafeDuplicateRef ref) (f a) -- > > too many seq's at the moment > > > > instance Comonad OIComonad where > > duplicate w = fmap (const w) w > > extract (OI _ a) = a > > > > mkOI :: Char -> OIComonad Char > > mkOI c = OI (unsafePerformIO $ newIORef $ constructReality c) c > > > > oiGetChar :: OIComonad a -> Char > > oiGetChar (OI ref _) = unsafePerformIO $ do { > > modifyIORef ref nextGetCharReality; > > OIReality _ _ c <- readIORef ref; > > return (c) } > > > > oiPutChar :: OIComonad Char -> () > > oiPutChar (OI ref c) = unsafePerformIO $ do { > > modifyIORef ref (nextPutCharReality c); > > OIReality _ _ d <- readIORef ref; -- not!? modified without > > further read > > return $ seq d ()} > > > > unsafeDuplicateRef :: IORef OIReality -> IORef OIReality > > unsafeDuplicateRef ref = unsafePerformIO $ do { > > r <- readIORef ref; > > newIORef r; } > > > > oiPutStrLn w = extract $ w =>> oiPutStr .>> '\n' =>> oiPutChar -- > > space leak if input string is suffiently long > > -- > > too many seqs in code > > > > oiPutStr w = extract $ oiPutStrS w .>> () > > > > oiPutStrS :: OIComonad String -> OIComonad String > > oiPutStrS w = case (extract w) of > > [] -> w > > (c:cs) -> oiPutStrS (w .>> c =>> oiPutChar .>> cs) > > > > oiGetLine = "t.b.d. using oiGetChar" > > > > > > -- adapted from http://www.mail-archive.com/haskell- > > cafe@haskell.org/msg02408.html > > comain w = extract (w .>> show (a,b) =>> oiPutStr) > > where > > a = extract (w .>> () =>> oiGetChar) > > b = extract (w .>> () =>> oiGetChar) > > > > > > {- Original from http://www.mail-archive.com/haskell- > > cafe@haskell.org/msg02408.html > > > > -- Bootstrap into the OI comonad > > main :: IO () > > main = return $! comain stdOI > > > > -- The following are the OI functions which we use. > > -- stdGetChar :: OI () -> Char > > -- stdPutStrLn :: OI String -> () > > > > comain :: OI a -> () > > comain w > > = coeval (w .>> show (a,b) =>> stdPutStrLn) > > where > > a = coeval (w .>> () =>> stdGetChar) > > b = coeval (w .>> () =>> stdGetChar) > > > > -} > > > > > > _______________________________________________ > > 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 > From mattcbro at earthlink.net Thu Nov 2 15:02:13 2006 From: mattcbro at earthlink.net (Matthew Bromberg) Date: Thu Nov 2 15:01:59 2006 Subject: [Haskell-cafe] Finding Memory Leaks Message-ID: <454A4EC5.4020601@earthlink.net> I have a rather complex Haskell program that performs an engineering simulation using a lot of large complex valued matrices. The imperative components of the simulation are written in C and interfaced into Haskell which handles the higher level logic. This has served me fairly well, and I've been pleased with both the development style and the performance of my code. However I've run into a fairly major issue with an unresolvable memory leak in the Haskell code. The memory leak is apparent since both private allocated bytes and page file bytes associated with the process increase linearly over time while the process is running. Eventually it causes the process to crash. I believe it's in the Haskell code because I have replaced malloc, free, realloc etc. in the C code with a memory leak detector and the C code appears to free all allocated resources. I also know that the memory leak is due to unmatched free's from a call to malloc from one of the windows XP system libraries. Unfortunately GHC's heap profiler does not reveal the memory leak. All my code is compiled using the -prof -auto flag and then run using +RTS -hc -RTS. The resulting plots do not show a linear increase in heap usage, although the Windows XP operating system does report such an increase. This leaves me in a difficult position in terms of finding the offending code. I am currently resorting to commenting out code line by line, but it's very tedious since I have to preserve the state functionality of the code to get it to run. Is there a way to compile Haskell into C using GHC and then forcing the C code to hook up to the memory leak detecting versions of malloc? I know that GHC can produce intermediary C code, but I have no idea how to access it and how to setup all the run time libraries etc, so that I can compile the C code separately. Any advice for me in this situation would be appreciated. From brandonm at yahoo-inc.com Thu Nov 2 15:20:55 2006 From: brandonm at yahoo-inc.com (Brandon Moore) Date: Thu Nov 2 15:21:14 2006 Subject: [Haskell-cafe] Decorating a list of strings In-Reply-To: <06ikk25ilu2mkikh9oikm5d2g1ebbqr9d4@4ax.com> References: <06ikk25ilu2mkikh9oikm5d2g1ebbqr9d4@4ax.com> Message-ID: <454A5327.3060409@yahoo-inc.com> Steve Schafer wrote: > I have a list of text strings: > > ["Alice", "Bob", "Cindy", "Bob", "Bob", "Dave", "Cindy"] > > As you can see, some of the strings occur only once; others appear two > or more times. > > I would like to end up with a new list, according to the following > rules: > > 1) If a string occurs only once in the original list, then that string > appears unchanged in the new list. > > 2) If a string occurs more than once in the original list, then each > occurrences of that string is "decorated" with a numerical suffix > indicating its relative position among its peers. > > In the case of the above list, the result of applying these rules would > be: > > ["Alice", "Bob:1", "Cindy:1", "Bob:2", "Bob:3", "Dave", "Cindy:2"] > > So, how do we do this? The straightforward approach is to traverse the > list twice, once to build a table of repeat counts for the different > strings, and a second time to generate the new list, based on the old > list plus the table of repeat counts. It seems you only need a table of counts of the number of times the string has occurred previously, which you can have available on the first pass. e.g, import Data.List import Data.Map as Map mark strings = snd $ mapAccumL (\counts str -> (Map.insertWith (+) str 1 counts, str++maybe "" (\n -> ':':show n) (Map.lookup str counts))) Map.empty strings this works on your example, and also handles ["Alice", "Bob", "Cindy", "Bob", "Bob", "Dave", "Cindy"] ++ repeat "Tim" giving ["Alice","Bob","Cindy","Bob:1","Bob:2","Dave","Cindy:1","Tim","Tim:1","Tim:2",...] > Of course, it's possible to > streamline this into a single traversal by building up a list of thunks > at the same time as the table of repeat counts is generated, and then to > resolve those thunks by applying them in one fell swoop to the table. > But while this does _conceptually_ streamline the problem, it doesn't > offer any practical improvement; it takes at least as much processing > effort to resolve the thunks as it would to make a second pass through > the list. > If your result data structure is sufficiently lazy, you can start forcing some thunks before the list has been completely processed. For example, suppose you want to instead what to tag all but the last string in a list with an asterisk, like ["Alice", "Bob", "Cindy", "Bob", "Bob", "Dave", "Cindy"] ==> ["Alice", "Bob*", "Cindy*", "Bob*", "Bob", "Dave", "Cindy"] You can start to get results before the list has been processed, if you have a set implementation with the laziness property member x set --> Set.member x (set `union` undefined) (you can get this if you use a trie) Then you can use define something like tag = foldr (\(x (xs, xsAsSet) -> ((x++if member x xsAsSet then "*" else ""):xs, insert x xsAsSet)) empty Then, you can force the results of examples like repeat "Ted" before the (infinite) list has been completely scanned, as long as no value is the last. Maybe there's a more interesting example? Brandon From steve at fenestra.com Thu Nov 2 15:27:58 2006 From: steve at fenestra.com (Steve Schafer) Date: Thu Nov 2 15:27:45 2006 Subject: [Haskell-cafe] Decorating a list of strings In-Reply-To: <454A5327.3060409@yahoo-inc.com> References: <06ikk25ilu2mkikh9oikm5d2g1ebbqr9d4@4ax.com> <454A5327.3060409@yahoo-inc.com> Message-ID: On Thu, 02 Nov 2006 12:20:55 -0800, you wrote: >It seems you only need a table of counts of the number of times >the string has occurred previously, which you can have available >on the first pass. > >e.g, >import Data.List >import Data.Map as Map >mark strings = snd $ mapAccumL >(\counts str -> >(Map.insertWith (+) str 1 counts, >str++maybe "" (\n -> ':':show n) (Map.lookup str counts))) >Map.empty >strings > >this works on your example, and also handles > >["Alice", "Bob", "Cindy", "Bob", "Bob", "Dave", "Cindy"] ++ repeat "Tim" >giving > >["Alice","Bob","Cindy","Bob:1","Bob:2","Dave","Cindy:1","Tim","Tim:1","Tim:2",...] No, you missed a part of the second rule: If there are multiple occurrences of a string, the _first_ occurrence has to be tagged, too, not just the second through n'th occurrences. The result of the above would have to be: ["Alice","Bob:1","Cindy:1","Bob:2","Bob:3","Dave","Cindy:2","Tim:1","Tim:2","Tim:3",...] Steve Schafer Fenestra Technologies Corp. http://www.fenestra.com/ From briqueabraque at yahoo.com Thu Nov 2 15:56:18 2006 From: briqueabraque at yahoo.com (=?ISO-8859-1?Q?Maur=ED=ADcio?=) Date: Thu Nov 2 16:57:59 2006 Subject: [Haskell-cafe] Non-integer part of a Double Message-ID: Hi, Is there a function to get that? I'm using \x -> x - fromIntegral(floor x) since I was not able to find something better, but I guess I have missed something in the standard library since there are functions with similar funcionality. Thanks, Maur?cio From sylvan at student.chalmers.se Thu Nov 2 17:04:10 2006 From: sylvan at student.chalmers.se (Sebastian Sylvan) Date: Thu Nov 2 17:04:03 2006 Subject: [Haskell-cafe] Non-integer part of a Double In-Reply-To: References: Message-ID: <3d96ac180611021404n277559cao3b614d577e6decf8@mail.gmail.com> On 11/2/06, Maur??cio wrote: > Hi, > > Is there a function to get that? I'm using > > \x -> x - fromIntegral(floor x) > > since I was not able to find something better, but I guess I have missed > something in the standard library since there are functions with similar > funcionality. How about frac :: RealFrac a => a -> a frac = snd . properFraction /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862 From bjpop at csse.unimelb.edu.au Thu Nov 2 21:32:02 2006 From: bjpop at csse.unimelb.edu.au (Bernie Pope) Date: Thu Nov 2 21:30:44 2006 Subject: [Haskell-cafe] Very Small Program References: <881F529F-2CEC-4BC4-925C-6D5D348594F9@csse.unimelb.edu.au> Message-ID: <5E39F694-70E0-48A3-B021-AC8BE2522B8B@csse.unimelb.edu.au> On 02/11/2006, at 9:56 PM, ajb@spamcop.net wrote: > G'day all. > > Quoting Bernie Pope : > >> This is a weird example of a pattern binding, and it is surprising >> (to me) that the syntax is valid. > > Maybe. But you wouldn't balk at this: > > numzeroes xs = sum [ 1 | 0 <- xs ] > > ...even if you wouldn't naturally express it that way. Patterns like > this are useful in places other than lets. I'd find it more > surprising > if lets were treated as a special case. > >> In this case you are defining the function which is bound to the >> variable called "+". > > Though thanks to n+k patterns, this is well-understood to be a > confusing and controversial case. > >> One would normally expect to see at least one variable inside the >> pattern on the >> left-hand-side of a pattern binding (otherwise what point would there >> be to the >> definition?). > > If the pattern is demanded (as it may well be in a list comprehension > generator, do block generator or a lambda), then it can be very > useful. > The programmer is asking for an error/empty list/monad "fail" if the > conformality check fails. I agree with what you say. When I said "pattern binding", I was using the terminology of the Haskell Report, which means only declarations of the form "pat = exp". Generator statements and lambdas are a different story, as you rightly point out. Nonetheless, I still believe that it is surprising for "pattern bindings" that this syntax is allowed, since there doesn't seem to be any purpose to them. (A cursory glance at the Report suggests that this kind of pattern binding is allowed). Then again, since the bindings are benign, maybe one could argue that it is better to have one less rule in the language definition? Then again, such a declaration could be the sign of a buggy program, and it might be better to give a compile time error. Cheers, Bernie. From mattcbro at earthlink.net Thu Nov 2 21:46:56 2006 From: mattcbro at earthlink.net (SevenThunders) Date: Thu Nov 2 21:46:43 2006 Subject: [Haskell-cafe] Finding Memory Leaks In-Reply-To: <454A4EC5.4020601@earthlink.net> References: <454A4EC5.4020601@earthlink.net> Message-ID: <7150682.post@talk.nabble.com> SevenThunders wrote: > > All my code is compiled using the -prof -auto > flag and then run using +RTS -hc -RTS. The resulting plots do not show > a linear increase in heap usage, although the Windows XP operating > system does report such an increase. > > This is either a bug in GHC or a bug in the profiler or both unless I am mistaken. The bug seems to arise when using FFI and using the wrapper mode for a Haskell callback. A pointer to the Haskell wrapper is created on the fly and then supposedly released by freeHaskellFunPtr. Unfortunately, at least under Windows XP 64 on my amd x2 3800 box, memory grows without bound. Even worse, however is the fact that profiling this function does not reveal the leak at all. It shows a constant memory profile. Here is the Haskell program. The actual c program containing cfunc is not really used in this snippet. (and I can't quite get that to work in this case for some reason.) module Main where import Foreign import Foreign.Ptr import Foreign.Storable -- | A convenient type synonym for storable arrays type Darr = Ptr (Double) -- | Function type for mapping doubles to doubles type Dfunc = Double -> Double -- | A convenient type synonym for monad containing storable arrays type IODarr = IO (Darr) foreign import ccall "wrapper" mkDfunc :: Dfunc -> IO (FunPtr Dfunc) foreign import ccall "cleaky.h cfunc" cfunc :: (FunPtr Dfunc) -> IO ( Double ) dadd :: Dfunc dadd x = x + 1.0 getleaky :: Dfunc -> IO () getleaky cf = do pcf <- mkDfunc cf -- pd <- cfunc pcf print pcf freeHaskellFunPtr pcf main = sequence_ [getleaky dadd | q <- [1..500000]] I compile this with ghc -c cleaky.c ghc -fglasgow-exts -fffi -prof -auto -I. --make leaky.hs cleaky.o and run it with leaky +RTS -hc -RTS #include #include #include "cleaky.h" double state = 1.0 ; double cfunc(DFptr fptr) { // printf("In cfunc, fptr: %p\n", fptr) ; state = (*fptr) (state) ; // printf("state: %g\n", state) ; return(state) ; } and typedef double (*DFptr) (double) ; double cfunc(DFptr) ; The C code as I said isn't really used. Is there a workaround for this? Perhaps some other way to free the function pointer? -- View this message in context: http://www.nabble.com/Finding-Memory-Leaks-tf2563630.html#a7150682 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From dagit at codersbase.com Thu Nov 2 22:05:44 2006 From: dagit at codersbase.com (Jason Dagit) Date: Thu Nov 2 22:05:31 2006 Subject: [Haskell-cafe] Finding Memory Leaks In-Reply-To: <7150682.post@talk.nabble.com> References: <454A4EC5.4020601@earthlink.net> <7150682.post@talk.nabble.com> Message-ID: On 11/2/06, SevenThunders wrote: > > > SevenThunders wrote: > > > > All my code is compiled using the -prof -auto > > flag and then run using +RTS -hc -RTS. The resulting plots do not show > > a linear increase in heap usage, although the Windows XP operating > > system does report such an increase. > > > > > > This is either a bug in GHC or a bug in the profiler or both unless I am > mistaken. > The bug seems to arise when using FFI and using the wrapper mode for a > Haskell callback. > A pointer to the Haskell wrapper is created on the fly and then supposedly > released by freeHaskellFunPtr. > > Unfortunately, at least under Windows XP 64 on my amd x2 3800 box, memory > grows without bound. Even worse, however is the fact that profiling this > function does not reveal the leak at all. It shows a constant memory > profile. Do any memory leaks show up if you compile with -caf-all when you profile? Jason From mattcbro at earthlink.net Thu Nov 2 22:26:32 2006 From: mattcbro at earthlink.net (SevenThunders) Date: Thu Nov 2 22:26:19 2006 Subject: [Haskell-cafe] Finding Memory Leaks In-Reply-To: References: <454A4EC5.4020601@earthlink.net> <7150682.post@talk.nabble.com> Message-ID: <7151020.post@talk.nabble.com> Jason Dagit-2 wrote: > > > > Do any memory leaks show up if you compile with -caf-all when you profile? > > Jason > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > It doesn't seem to make any difference, although I do not know what this flag does. I compiled the code using ghc -fglasgow-exts -fffi -prof -auto -caf-all -I. --make leaky.hs cleaky.o and did not see the steady ramp up in memory that one sees with the windows xp performance tool. -- View this message in context: http://www.nabble.com/Finding-Memory-Leaks-tf2563630.html#a7151020 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From dons at cse.unsw.edu.au Thu Nov 2 22:28:46 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Thu Nov 2 22:28:38 2006 Subject: [Haskell-cafe] Finding Memory Leaks In-Reply-To: <7151020.post@talk.nabble.com> References: <454A4EC5.4020601@earthlink.net> <7150682.post@talk.nabble.com> <7151020.post@talk.nabble.com> Message-ID: <20061103032846.GB13133@cse.unsw.EDU.AU> mattcbro: > > > > Jason Dagit-2 wrote: > > > > > > > > Do any memory leaks show up if you compile with -caf-all when you profile? > > > > Jason > > _______________________________________________ > > Haskell-Cafe mailing list > > Haskell-Cafe@haskell.org > > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > > > > It doesn't seem to make any difference, although I do not know what this > flag does. > I compiled the code using > ghc -fglasgow-exts -fffi -prof -auto -caf-all -I. --make leaky.hs cleaky.o > > and did not see the steady ramp up in memory that one sees with the windows > xp performance tool. Hmm, are you missing a -O ? Does that help at all? -- Don From Sven.Biedermann at biedermann-consulting.de Fri Nov 3 02:53:56 2006 From: Sven.Biedermann at biedermann-consulting.de (Sven Biedermann) Date: Fri Nov 3 02:52:08 2006 Subject: [Haskell-cafe] Towards an IO-Comonad that preserves referential transparency (was: "comonads, io" Jan 02, 2003) In-Reply-To: <5ce89fb50611021151sf155e85td2c800d4bae7b67b@mail.gmail.com> References: <0A7EAB42-437B-4C68-A908-9E4859525286@Biedermann-Consulting.de> <09B524F3-D817-4231-95DB-5F637B6EB5F5@Biedermann-Consulting.de> <5ce89fb50611021151sf155e85td2c800d4bae7b67b@mail.gmail.com> Message-ID: <6589199A-D6B3-4404-AC41-04DDC335301E@biedermann-consulting.de> Hello Nick, Am 02.11.2006 um 20:51 schrieb Nicolas Frisby: > OI has been lingering in the back of my mind during my own > comonadic adventures. Did you enjoy them? > > One thing that's bothered me is the signature of comain. > > comain :: OI () -> () > > If the OI comonad is to represent values "in the context of the > RealWorld", and yet we can have multiple and differing copies of the > RealWorld context, then this seems to match the multiple worlds > perspective (which is why I think Kieburtz' experimental > implementation was doomed to violate referential transparency). That > is I want any deterministic program to be of top-level type: > > comain :: OI () -> OI () > > The intuition is that the program as a whole receives the initial > world description, then is allowed to duplicate and manipulate that > world in any number of ways, but it has to choose one final world as > its choice. All other real worlds are discarded. The OI () -> () > signature doesn't allow for the program to tell me what the resulting > RealWorld ought to be. I think of signature OI a -> b as a constraint: there's no hidden agenda inside the comonad. The future of the comonad doesn't depend on its history. In a comonad using OI a -> OI b, anything can be hidden. So, if the comonad hasn't a hidden agenda, there's no point in choosing a final world. Hence, OI a -> b seems adequate to me. > > An implementation of this doesn't seem impossible (as opposed to > improbable) for file IO or references (your filesystem/cell store > would have to be transactional and "multi-ported"). It does become a > bit mind boggling for concurrency or any other multi-agent paradigm > (networking, screen and keyboard IO, etc.)--it seems that the other > agents would have to be savvy to the multiple worlds perspective. > What is "multi-ported"? > Transactional systems certainly seem like a ripe application area for > the Product comonad with a RealWorld abstract data type as the carried > context. > > My apologies for not actually commenting on your code. Thank you for use comments. > > Nick > From haskell at list.mightyreason.com Fri Nov 3 04:47:03 2006 From: haskell at list.mightyreason.com (Chris Kuklewicz) Date: Fri Nov 3 04:47:02 2006 Subject: [Haskell-cafe] Decorating a list of strings In-Reply-To: <06ikk25ilu2mkikh9oikm5d2g1ebbqr9d4@4ax.com> References: <06ikk25ilu2mkikh9oikm5d2g1ebbqr9d4@4ax.com> Message-ID: <454B1017.60103@list.mightyreason.com> Steve Schafer wrote: > I have a list of text strings: > > ["Alice", "Bob", "Cindy", "Bob", "Bob", "Dave", "Cindy"] > > As you can see, some of the strings occur only once; others appear two > or more times. > > I would like to end up with a new list, according to the following > rules: > > 1) If a string occurs only once in the original list, then that string > appears unchanged in the new list. > > 2) If a string occurs more than once in the original list, then each > occurrences of that string is "decorated" with a numerical suffix > indicating its relative position among its peers. > > In the case of the above list, the result of applying these rules would > be: > > ["Alice", "Bob:1", "Cindy:1", "Bob:2", "Bob:3", "Dave", "Cindy:2"] > > So, how do we do this? The straightforward approach is to traverse the > list twice, once to build a table of repeat counts for the different > strings, and a second time to generate the new list, based on the old > list plus the table of repeat counts. Of course, it's possible to > streamline this into a single traversal by building up a list of thunks > at the same time as the table of repeat counts is generated, and then to > resolve those thunks by applying them in one fell swoop to the table. > But while this does _conceptually_ streamline the problem, it doesn't > offer any practical improvement; it takes at least as much processing > effort to resolve the thunks as it would to make a second pass through > the list. The processing effort is a matter of optimization. It is entirely possible that for small lists that fit in the CPU cache that a double traversal is very cheap, where for a large lists that spills into swap space on disk that a second traversal is very expensive. So the obvious thing to do is just write the easiest to maintain version and if the performance benchmarks are bad then try the other method. > Can we do better? no. From bulat.ziganshin at gmail.com Thu Nov 2 16:30:35 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Nov 3 04:50:37 2006 Subject: [Haskell-cafe] Re: Haskell-Cafe Digest, Vol 39, Issue 6 In-Reply-To: References: <20061102043317.75C9C3244F3@www.haskell.org> Message-ID: <1613425423.20061103003035@gmail.com> Hello Chad, Thursday, November 2, 2006, 8:49:17 PM, you wrote: > Would it be possible for the type system to distinguish at compile > time whether something would need to be evaluated, and optimize away > redundant `seq`s? Maybe this is what the strictness analyzer does > already. afaik, seq cost is zero (except for evaluating expressions, of course) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Fri Nov 3 04:59:02 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Nov 3 04:59:23 2006 Subject: [Haskell-cafe] Class In-Reply-To: <171dfd0a0611020651q58c30dbdi405f363e7f13ccf8@mail.gmail.com> References: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> <200611020244.12812.daniel.is.fischer@web.de> <171dfd0a0611020047h1344c9caqb5432936b82d5663@mail.gmail.com> <171dfd0a0611020157q6c3afc0blb15bfb7611485b90@mail.gmail.com> <3d96ac180611020354r6b8fcef5pa070a748a9393cef@mail.gmail.com> <171dfd0a0611020542h6bdaf19dsa020276d258161eb@mail.gmail.com> <721076345.20061102174232@gmail.com> <171dfd0a0611020651q58c30dbdi405f363e7f13ccf8@mail.gmail.com> Message-ID: <1681841964.20061103125902@gmail.com> Hello Slavomir, Thursday, November 2, 2006, 5:51:17 PM, you wrote: > I wouldn't like to manually define instances of Visible for all types > that have Show instances. believe it or not but i had the same problems > I think I need something like that: > class Visible a where > instance Show a => Visible a where > Which still doesn't work. Any ideas? this will work. with addition of instance Visible a => Visible [a] where this will not work. it's a mission impossible -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From lemming at henning-thielemann.de Fri Nov 3 05:40:20 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Fri Nov 3 05:43:04 2006 Subject: [Haskell-cafe] Non-integer part of a Double In-Reply-To: <3d96ac180611021404n277559cao3b614d577e6decf8@mail.gmail.com> References: <3d96ac180611021404n277559cao3b614d577e6decf8@mail.gmail.com> Message-ID: On Thu, 2 Nov 2006, Sebastian Sylvan wrote: > On 11/2/06, Maur??cio wrote: > > Hi, > > > > Is there a function to get that? I'm using > > > > \x -> x - fromIntegral(floor x) > > > > since I was not able to find something better, but I guess I have missed > > something in the standard library since there are functions with similar > > funcionality. > > How about > frac :: RealFrac a => a -> a > frac = snd . properFraction However, this leaves the type of the integral part unspecified. From bulat.ziganshin at gmail.com Fri Nov 3 05:23:21 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Nov 3 05:52:23 2006 Subject: [Haskell-cafe] Class In-Reply-To: <171dfd0a0611021059v5bf13e42g2adffc49ea015262@mail.gmail.com> References: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> <200611020244.12812.daniel.is.fischer@web.de> <171dfd0a0611020047h1344c9caqb5432936b82d5663@mail.gmail.com> <171dfd0a0611020157q6c3afc0blb15bfb7611485b90@mail.gmail.com> <3d96ac180611020354r6b8fcef5pa070a748a9393cef@mail.gmail.com> <171dfd0a0611020542h6bdaf19dsa020276d258161eb@mail.gmail.com> <171dfd0a0611020643v51a520a4v2719609e5ab6239f@mail.gmail.com> <3d96ac180611021051ybd612a5vebec2d5c3a175c43@mail.gmail.com> <171dfd0a0611021059v5bf13e42g2adffc49ea015262@mail.gmail.com> Message-ID: <535469889.20061103132321@gmail.com> Hello Slavomir, Thursday, November 2, 2006, 9:59:38 PM, you wrote: >> one is okay, though, but you have to start ghc with >> -fallow-undecidable-instances and -fglasgow-exts I'm afraid. > Thanks, Sebastian. That was helpful. Are there any papers on the subject? i recommend you to read in the following sequence: 1) The paper that at first time introduced type classes and their implementation using dictionaries was Philip Wadler and Stephen Blott "How to make ad-hoc polymorphism less ad-hoc" (http://homepages.inf.ed.ac.uk/wadler/papers/class/class.ps.gz) 2) http://haskell.org/haskellwiki/OOP_vs_type_classes 3) Ralf Lammel and Klaus Ostermann paper "Software Extension and Integration with Type Classes" (http://homepages.cwi.nl/~ralf/gpce06/) which prompts me to start thinking about differences between OOP and type classes instead of their similarities 4) ghc user's guide, chapter 7 describes Haskell language extensions 5) You can find more papers on the http://haskell.org/haskellwiki/Research_papers/Type_systems#Type_classes page. Of those papers i found a most interesting "exporing the design space" one 6) The best paper on type level arithmetic using type classes i've seen is "Faking it: simulating dependent types in Haskell" ( http://www.cs.nott.ac.uk/~ctm/faking.ps.gz ) 7) The great demonstration of type-level arithmetic is TypeNats package which "defines type-level natural numbers and arithmetic operations on them including addition, subtraction, multiplication, division and GCD" ( darcs get --partial --tag '0.1' http://www.eecs.tufts.edu/~rdocki01/typenats/ ) 8) I should also mention here Oleg Kiselyov page on class-based type-level programming in Haskell: http://okmij.org/ftp/Haskell/types.html -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Fri Nov 3 05:24:59 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Nov 3 05:52:33 2006 Subject: Fwd: [Haskell-cafe] Class In-Reply-To: <171dfd0a0611020647o5e6a17b2t35ef1d68ae55b478@mail.gmail.com> References: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> <200611020244.12812.daniel.is.fischer@web.de> <171dfd0a0611020047h1344c9caqb5432936b82d5663@mail.gmail.com> <171dfd0a0611020157q6c3afc0blb15bfb7611485b90@mail.gmail.com> <3d96ac180611020354r6b8fcef5pa070a748a9393cef@mail.gmail.com> <171dfd0a0611020542h6bdaf19dsa020276d258161eb@mail.gmail.com> <171dfd0a0611020643v51a520a4v2719609e5ab6239f@mail.gmail.com> <171dfd0a0611020647o5e6a17b2t35ef1d68ae55b478@mail.gmail.com> Message-ID: <413828826.20061103132459@gmail.com> Hello Slavomir, Thursday, November 2, 2006, 5:47:37 PM, you wrote: > class Show a => Visible a where > toString :: a -> String > toString = show > size :: a -> Int > size = length . show it's not that you need. it's definition of subclass, say class Set a => OrderedSet a -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Fri Nov 3 05:27:56 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Nov 3 05:52:45 2006 Subject: [Haskell-cafe]Prime Generator time limit exceeded In-Reply-To: <000b01c6feac$6fd55600$8dbec1da@NOTEBOOK> References: <002601c6fdd5$afd1c720$8dbec1da@NOTEBOOK> <7F4DF84C-4AAA-4071-96EF-F80563A6D60B@cse.unl.edu> <003001c6fe8e$010fed70$8dbec1da@NOTEBOOK> <203D789F-C8F2-4926-9D52-A070AE1AB869@cse.unl.edu> <000b01c6feac$6fd55600$8dbec1da@NOTEBOOK> Message-ID: <469039658.20061103132756@gmail.com> Hello alaiyeshi, Thursday, November 2, 2006, 9:26:37 PM, you wrote: > I've met replicateM_ for the first time;-) This could be a > "template" for doing online-judge exercises I guess. And it's very useful for newbies like me. make an date for 'interact' :))) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Fri Nov 3 05:50:18 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Nov 3 05:52:55 2006 Subject: [Haskell-cafe] How to improve speed? (MersenneTwister is several times slower than C version) In-Reply-To: <20061102112131.GA10992@cse.unsw.EDU.AU> References: <1162419415.26204.26.camel@localhost.localdomain> <1396574203.20061102112647@gmail.com> <20061102112131.GA10992@cse.unsw.EDU.AU> Message-ID: <1777312766.20061103135018@gmail.com> Hello Donald, Thursday, November 2, 2006, 2:21:31 PM, you wrote: >> 10-20 times difference is typical for GHC programs. > It's really more like 2-4x. Sometimes better than C. > Where's this huge figure coming from Bulat? If you have code that > behaves like this, you should report it. are you analyzed the cases where performance is close or even better? i does. it's either because C version is limited by memory performance or just use different, less efficient algorithm the cases which shows slowness of ghc-generated code is factorial algorithm and the program attached. despite that Haskell code is far uglier, C version outperforms it 20 times. run both programs with arrays of about 10k elements to see the difference: a.out 10000 elements 100000 iterations in February i've written detailed explanation (in ghc-users) of why this comes and made some suggestions on improving it. of course, main problem is ghc's own code generator which is far away from gcc or even ocaml ones -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: full.c Type: application/octet-stream Size: 893 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061103/e73fad84/full.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: newest.hs Type: application/octet-stream Size: 1284 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061103/e73fad84/newest.obj From slavomir.kaslev at gmail.com Fri Nov 3 06:02:17 2006 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Fri Nov 3 06:02:02 2006 Subject: [Haskell-cafe] Class In-Reply-To: <535469889.20061103132321@gmail.com> References: <171dfd0a0611011506y2ad9c14ev33b126d9cc4160be@mail.gmail.com> <200611020244.12812.daniel.is.fischer@web.de> <171dfd0a0611020047h1344c9caqb5432936b82d5663@mail.gmail.com> <171dfd0a0611020157q6c3afc0blb15bfb7611485b90@mail.gmail.com> <3d96ac180611020354r6b8fcef5pa070a748a9393cef@mail.gmail.com> <171dfd0a0611020542h6bdaf19dsa020276d258161eb@mail.gmail.com> <171dfd0a0611020643v51a520a4v2719609e5ab6239f@mail.gmail.com> <3d96ac180611021051ybd612a5vebec2d5c3a175c43@mail.gmail.com> <171dfd0a0611021059v5bf13e42g2adffc49ea015262@mail.gmail.com> <535469889.20061103132321@gmail.com> Message-ID: <171dfd0a0611030302h7284bd0bu4bbf26c0cf851df6@mail.gmail.com> On 11/3/06, Bulat Ziganshin wrote: > Hello Slavomir, > > Thursday, November 2, 2006, 9:59:38 PM, you wrote: > > >> one is okay, though, but you have to start ghc with > >> -fallow-undecidable-instances and -fglasgow-exts I'm afraid. > > > Thanks, Sebastian. That was helpful. Are there any papers on the subject? > > i recommend you to read in the following sequence: > > 1) The paper that at first time introduced type classes and their > implementation using dictionaries was Philip Wadler and Stephen Blott > "How to make ad-hoc polymorphism less ad-hoc" > (http://homepages.inf.ed.ac.uk/wadler/papers/class/class.ps.gz) > > 2) http://haskell.org/haskellwiki/OOP_vs_type_classes > > 3) Ralf Lammel and Klaus Ostermann paper > "Software Extension and Integration with Type Classes" > (http://homepages.cwi.nl/~ralf/gpce06/) which prompts me to start > thinking about differences between OOP and type classes instead of > their similarities > > 4) ghc user's guide, chapter 7 describes Haskell language extensions > > 5) You can find more papers on the > http://haskell.org/haskellwiki/Research_papers/Type_systems#Type_classes page. > Of those papers i found a most interesting "exporing the design space" > one > > 6) The best paper on type level arithmetic using type classes i've seen > is "Faking it: simulating dependent types in Haskell" > ( http://www.cs.nott.ac.uk/~ctm/faking.ps.gz ) > > 7) The great demonstration of type-level arithmetic is TypeNats package > which "defines type-level natural numbers and arithmetic operations on > them including addition, subtraction, multiplication, division and GCD" > ( darcs get --partial --tag '0.1' http://www.eecs.tufts.edu/~rdocki01/typenats/ ) > > 8) I should also mention here Oleg Kiselyov page on class-based type-level > programming in Haskell: http://okmij.org/ftp/Haskell/types.html > > > -- > Best regards, > Bulat mailto:Bulat.Ziganshin@gmail.com > > Wow. Thank you for the comprehensive list. I feel almost obligated reading =-) Cheers. -- Slavomir Kaslev From briqueabraque at yahoo.com Fri Nov 3 05:48:03 2006 From: briqueabraque at yahoo.com (=?ISO-8859-15?Q?Maur=ED=ADcio?=) Date: Fri Nov 3 06:48:26 2006 Subject: [Haskell-cafe] Re: Non-integer part of a Double In-Reply-To: References: <3d96ac180611021404n277559cao3b614d577e6decf8@mail.gmail.com> Message-ID: Henning Thielemann wrote: > On Thu, 2 Nov 2006, Sebastian Sylvan wrote: > >> On 11/2/06, Maur??cio wrote: >>> Hi, >>> >>> Is there a function to get that? I'm using >>> >>> \x -> x - fromIntegral(floor x) >>> >>> since I was not able to find something better, but I guess I have missed >>> something in the standard library since there are functions with similar >>> funcionality. >> How about >> frac :: RealFrac a => a -> a >> frac = snd . properFraction > > However, this leaves the type of the integral part unspecified. I've just found mod', a version of mod that works with reals (so I could use mod' x 1.0), in module Data.Fixed. However, trying to load Data.Fixed in ghci says that module doesn't exist (ghc 6.6). Maur?cio From alaiyeshi025 at 163.com Fri Nov 3 08:23:40 2006 From: alaiyeshi025 at 163.com (alaiyeshi) Date: Fri Nov 3 08:23:10 2006 Subject: [Haskell-cafe]Prime Generator time limit exceeded References: <002601c6fdd5$afd1c720$8dbec1da@NOTEBOOK> <7F4DF84C-4AAA-4071-96EF-F80563A6D60B@cse.unl.edu> <003001c6fe8e$010fed70$8dbec1da@NOTEBOOK> <203D789F-C8F2-4926-9D52-A070AE1AB869@cse.unl.edu> <000b01c6feac$6fd55600$8dbec1da@NOTEBOOK> <469039658.20061103132756@gmail.com> Message-ID: <001101c6ff4b$4c0d7be0$8dbec1da@NOTEBOOK> Wow! Thank you for your suggestion. But I guess in this problem the first input line and the other are different in their meaning. Thus if I use interact I should "parse" the input(again), I guess. From chad.scherrer at gmail.com Fri Nov 3 09:40:37 2006 From: chad.scherrer at gmail.com (Chad Scherrer) Date: Fri Nov 3 09:40:24 2006 Subject: [Haskell-cafe] Cost of seq (sorry about the old subject) Message-ID: On 11/2/06, Bulat Ziganshin wrote: > Hello Chad, > > Thursday, November 2, 2006, 8:49:17 PM, you [Chad] wrote: > > Would it be possible for the type system to distinguish at compile > > time whether something would need to be evaluated, and optimize away > > redundant `seq`s? Maybe this is what the strictness analyzer does > > already. > > afaik, seq cost is zero (except for evaluating expressions, of course) > So if x has already been evaluated, does x `seq` y evaluate just as quickly as y alone, or does it require extra cycles to make sure x has been evaluated? -- Chad Scherrer "Time flies like an arrow; fruit flies like a banana" -- Groucho Marx From Malcolm.Wallace at cs.york.ac.uk Fri Nov 3 09:51:09 2006 From: Malcolm.Wallace at cs.york.ac.uk (Malcolm Wallace) Date: Fri Nov 3 09:54:15 2006 Subject: [Haskell-cafe] Cost of seq (sorry about the old subject) In-Reply-To: References: Message-ID: <20061103145109.744e3ea7.Malcolm.Wallace@cs.york.ac.uk> "Chad Scherrer" wrote: > > afaik, seq cost is zero (except for evaluating expressions, of > > course) > > So if x has already been evaluated, does x `seq` y evaluate just as > quickly as y alone, or does it require extra cycles to make sure x has > been evaluated? My understanding is that `seq` does indeed cost extra cycles at runtime _if it is actually executed_. But of course, the fact that it appears in your source code does not guarantee that it is executed at runtime. If the compiler can determine statically (through strictness analysis) that x is already in evaluated form, then it is at liberty to remove the `seq` from the code. Regards, Malcolm From bulat.ziganshin at gmail.com Fri Nov 3 11:50:55 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Nov 3 11:51:07 2006 Subject: [Haskell-cafe]Prime Generator time limit exceeded In-Reply-To: <001101c6ff4b$4c0d7be0$8dbec1da@NOTEBOOK> References: <002601c6fdd5$afd1c720$8dbec1da@NOTEBOOK> <7F4DF84C-4AAA-4071-96EF-F80563A6D60B@cse.unl.edu> <003001c6fe8e$010fed70$8dbec1da@NOTEBOOK> <203D789F-C8F2-4926-9D52-A070AE1AB869@cse.unl.edu> <000b01c6feac$6fd55600$8dbec1da@NOTEBOOK> <469039658.20061103132756@gmail.com> <001101c6ff4b$4c0d7be0$8dbec1da@NOTEBOOK> Message-ID: <1852327596.20061103195055@gmail.com> Hello alaiyeshi, Friday, November 3, 2006, 4:23:40 PM, you wrote: > But I guess in this problem the first input line and the other are > different in their meaning. Thus if I use interact I should "parse" the input(again), I guess. it seems that you don't understand that functional programming has just the same power as imperative one: process (header:rest) = process2 header rest -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From mattcbro at earthlink.net Fri Nov 3 12:49:12 2006 From: mattcbro at earthlink.net (SevenThunders) Date: Fri Nov 3 12:48:59 2006 Subject: [Haskell-cafe] Finding Memory Leaks In-Reply-To: <20061103032846.GB13133@cse.unsw.EDU.AU> References: <454A4EC5.4020601@earthlink.net> <7150682.post@talk.nabble.com> <7151020.post@talk.nabble.com> <20061103032846.GB13133@cse.unsw.EDU.AU> Message-ID: <7163358.post@talk.nabble.com> Donald Bruce Stewart wrote: > > > > Hmm, are you missing a -O ? Does that help at all? > > -- Don > > > Adding the -O does not stop the memory leak problem. As for the profiler, it does make the CAF:main function show more erratic memory spikes, however no memory ramping is revealed even though the operating system performance monitors in windows XP show this ramping effect quite dramatically. By the way I have verified that the memory leaks occur both in windows XP 64 and in ordinary 32 bit windows XP. -- View this message in context: http://www.nabble.com/Finding-Memory-Leaks-tf2563630.html#a7163358 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From ndmitchell at gmail.com Fri Nov 3 17:03:23 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Fri Nov 3 17:03:07 2006 Subject: [Haskell-cafe] Re: [Haskell] GHC inferred type different for pointed/point-free defs? In-Reply-To: <454BBB0F.5030404@imageworks.com> References: <454BBB0F.5030404@imageworks.com> Message-ID: <404396ef0611031403vdaed0d8uc8a5b20ea380a128@mail.gmail.com> Hi, You probably want to read up on: Monomorphism restriction (I don't think this applies here, but I'm never too sure!): http://www.haskell.org/hawiki/MonomorphismRestriction Defaulting: http://www.haskell.org/onlinereport/decls.html#sect4.3.4 I don't understand either to any great degree, but when points free starts changing things, its usually one of those two kicking in. And as a side note, haskell@ tends to be used more for announcements, and haskell-cafe@ is used more for asking questions etc. Thanks Neil On 11/3/06, Dan Weston wrote: > Help! One of two things is going on: > > 1) I don't understand what I'm doing > 2) GHC is inferring different types for pointed and > point-free function definition. > > I wanted to define Haskell equivalents to the C ternary operator. > Basically, predicate ??? doIfTrue ||| doIfFalse > > For some reason, though, in GHC 6.4 and 6.7, the types > inferred for abs1 and ab2 (defined below) are different: > > *Main> :t abs1 > abs1 :: (Num a, Ord a) => a -> a > > *Main> :t abs2 > abs2 :: Integer -> Integer > > How is abs2 less general just because I use point-free > notation instead of pointed notation? They should have the same > type, no? I'm stumped... > > > import Control.Arrow > > import Data.Either > > > > infix 1 ?, ??, ???, ???? > > > > (?) True = Left > > (?) False = Right > > > > (??) True = Left . fst > > (??) False = Right . snd > > > > p ??? q = (p &&& arr id) >>> uncurry (?) >>> q > > p ???? q = (p &&& arr id) >>> uncurry (??) >>> q > > > > abs1 x = (< 0) ??? negate ||| id $ x > > abs2 = (< 0) ??? negate ||| id > > > > checks :: [Bool] > > checks = > > [ > > (True ? 3 ) == (Left 3), > > (False ? 4 ) == (Right 4), > > (True ?? (3,4)) == (Left 3), > > (False ?? (3,4)) == (Right 4), > > (even ??? (`div` 2) ||| (+1).(*3) $ 3 ) == ( 10), > > (even ??? (`div` 2) ||| (+1).(*3) $ 4 ) == ( 2), > > (uncurry (==) ???? (+1) ||| (*3) $ (3,3)) == ( 4), > > (uncurry (==) ???? (+1) ||| (*3) $ (3,4)) == ( 12), > > (uncurry (==) ???? (+1) +++ (*3) $ (3,3)) == (Left 4), > > (uncurry (==) ???? (+1) +++ (*3) $ (3,4)) == (Right 12), > > (abs1 5 ) == ( 5), > > (abs1 (-5) ) == ( 5), > > (abs2 5 ) == ( 5), > > (abs2 (-5) ) == ( 5) > > ] > > > > main = print (and checks) > > _______________________________________________ > Haskell mailing list > Haskell@haskell.org > http://www.haskell.org/mailman/listinfo/haskell > From westondan at imageworks.com Fri Nov 3 21:07:15 2006 From: westondan at imageworks.com (Dan Weston) Date: Fri Nov 3 21:07:03 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: <984680831.20061016195414@gmail.com> References: <002001c6efa4$c8372510$1cf52950@osmet> <22523.213.84.177.94.1161000771.squirrel@webmail.xs4all.nl> <5ce89fb50610160731ja2de0d8l23903e914dcfe8da@mail.gmail.com> <984680831.20061016195414@gmail.com> Message-ID: <454BF5D3.60705@imageworks.com> Here's an idea that (I think) is useful and backwards compatible: fractional and negative fixity. There have been 3 separate times where I've wanted an operator just above 0 ($) but less than 1 (>>= or >>>), or else just below 0 (like a superlow $$) infix 0.5 ??? infix -1 $$ The only change would be internal to compiler, wouldn't it? Since fixity is just syntactic sugar, there should be no semantic difficulties. Dan From lemmih at gmail.com Sat Nov 4 11:22:31 2006 From: lemmih at gmail.com (Lemmih) Date: Sat Nov 4 11:22:13 2006 Subject: [Haskell-cafe] Re: Haskell-Cafe Digest, Vol 39, Issue 6 In-Reply-To: References: <20061102043317.75C9C3244F3@www.haskell.org> Message-ID: On 11/2/06, Chad Scherrer wrote: > Lemmih wrote: > > Using 'seq' is generally a bad idea. It can worsen the performance if > > not used carefully and GHCs strictness analyser is usually good > > enough. > > Is GHC.Conc.pseq any better? Usually the whole point of making things > more strict is to optimize performance for pieces you know will be > evaluated anyway. It's frustrating if there's not a consistent way to > do this that works well. pseq is just as bad. The problem is excessive use of strictness annotations in the hope of a magical performance improvement. Strictness annotations should be used with care and only placed where they're needed. > Lately, I've been using lots of strictness annotations and bang > patterns - are there non-obvious places this could slow things down? In the case of the MersenneTwister, forcing 'y4' from 'next32' would evaluate it almost 10,000,000 times more than needed. > Would it be possible for the type system to distinguish at compile > time whether something would need to be evaluated, and optimize away > redundant `seq`s? Maybe this is what the strictness analyzer does > already. Evaluating the seq's isn't costly, afaik. -- Cheers, Lemmih From slavomir.kaslev at gmail.com Sat Nov 4 14:39:39 2006 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Sat Nov 4 14:39:20 2006 Subject: [Haskell-cafe] Module visibility of data type constructors Message-ID: <171dfd0a0611041139r732cee51w1a1b88cc43700be5@mail.gmail.com> Hello. I have a simple question for data type constructors visibility. Take a look: module Foo (Bar) where data Bar = Bar In ghc this allows me to use Bar, the type constructor, in another module, although it shouldn't be visible outside Foo. On the other hand, if I change Bar's definition as: data Bar = Baz Baz isn't visible outside Foo. Is this the correct behavior or is it bug in ghc? Cheers. -- Slavomir Kaslev From fis at wiwi.hu-berlin.de Sat Nov 4 15:35:10 2006 From: fis at wiwi.hu-berlin.de (Matthias Fischmann) Date: Sat Nov 4 15:39:49 2006 Subject: [Haskell-cafe] Module visibility of data type constructors In-Reply-To: <171dfd0a0611041139r732cee51w1a1b88cc43700be5@mail.gmail.com> References: <171dfd0a0611041139r732cee51w1a1b88cc43700be5@mail.gmail.com> Message-ID: <20061104203510.GJ8178@localhost.localdomain> On Sat, Nov 04, 2006 at 09:39:39PM +0200, Slavomir Kaslev wrote: > To: haskell-cafe@haskell.org > From: Slavomir Kaslev > Date: Sat, 4 Nov 2006 21:39:39 +0200 > Subject: [Haskell-cafe] Module visibility of data type constructors > > Hello. I have a simple question for data type constructors visibility. > Take a look: > > module Foo (Bar) where > data Bar = Bar > > In ghc this allows me to use Bar, the type constructor, in another > module, although it shouldn't be visible outside Foo. On the other > hand, if I change Bar's definition as: > > data Bar = Baz > > Baz isn't visible outside Foo. > > Is this the correct behavior or is it bug in ghc? It's not the correct behavior. The question is whether the bug is in your code or in ghc (with me it's usually the former :-). I can't reproduce this with my ghc 6.4. Which version are you using? Can you post the other module you are talking about? matthias -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061104/3e87740f/attachment.bin From slavomir.kaslev at gmail.com Sat Nov 4 16:19:08 2006 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Sat Nov 4 16:18:49 2006 Subject: [Haskell-cafe] Module visibility of data type constructors In-Reply-To: <20061104203510.GJ8178@localhost.localdomain> References: <171dfd0a0611041139r732cee51w1a1b88cc43700be5@mail.gmail.com> <20061104203510.GJ8178@localhost.localdomain> Message-ID: <171dfd0a0611041319y444bb942l9a80dbd4dc37ded@mail.gmail.com> On 11/4/06, Matthias Fischmann wrote: > > On Sat, Nov 04, 2006 at 09:39:39PM +0200, Slavomir Kaslev wrote: > > To: haskell-cafe@haskell.org > > From: Slavomir Kaslev > > Date: Sat, 4 Nov 2006 21:39:39 +0200 > > Subject: [Haskell-cafe] Module visibility of data type constructors > > > > Hello. I have a simple question for data type constructors visibility. > > Take a look: > > > > module Foo (Bar) where > > data Bar = Bar > > > > In ghc this allows me to use Bar, the type constructor, in another > > module, although it shouldn't be visible outside Foo. On the other > > hand, if I change Bar's definition as: > > > > data Bar = Baz > > > > Baz isn't visible outside Foo. > > > > Is this the correct behavior or is it bug in ghc? > > It's not the correct behavior. The question is whether the bug is in > your code or in ghc (with me it's usually the former :-). > > I can't reproduce this with my ghc 6.4. Which version are you using? > Can you post the other module you are talking about? > > > matthias > > > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.1 (GNU/Linux) > > iD8DBQFFTPl+TXPx/Y0ym6oRAibjAJ9uG6ZP37xOnCRRRAaraewnCn/tmQCgkZB/ > xLL/q1iDHAhBUCuojOZsvuA= > =jWQR > -----END PGP SIGNATURE----- > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > Actually you're right. It was my mistake, I don't know what tricked me. I was evaluating in ghci, not noticing even (silly me) *Foo>. Sorry for the noise. I probably need some more coffe in this time of the day. -- Slavomir Kaslev From bulat.ziganshin at gmail.com Sat Nov 4 01:59:38 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sat Nov 4 16:44:59 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: <454BF5D3.60705@imageworks.com> References: <002001c6efa4$c8372510$1cf52950@osmet> <22523.213.84.177.94.1161000771.squirrel@webmail.xs4all.nl> <5ce89fb50610160731ja2de0d8l23903e914dcfe8da@mail.gmail.com> <984680831.20061016195414@gmail.com> <454BF5D3.60705@imageworks.com> Message-ID: <706781845.20061104095938@gmail.com> Hello Dan, Saturday, November 4, 2006, 5:07:15 AM, you wrote: > Here's an idea that (I think) is useful and backwards compatible: > fractional and negative fixity. yes, i think the same. for example, once i've tried to define postfix 'when' operator like those in perl/ruby print msg `on` mode==debug but failed because my code frequently contains '$' and there is no way to define operation with a lower precedence really, there is another alternative to solve my particular problem: make `op` applications having fixed -1 precedence. such applications look "heavyweight" and once i have a wonderful debugging story just because for my eyes it was obvious that (a `div` b+1) means "do add before div" -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Sat Nov 4 02:11:00 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sat Nov 4 16:45:04 2006 Subject: [Haskell-cafe] Re[2]: [Haskell] GHC inferred type different for pointed/point-free defs? In-Reply-To: <454BE389.8080209@imageworks.com> References: <454BBB0F.5030404@imageworks.com> <199321607.20061104024530@gmail.com> <454BE389.8080209@imageworks.com> Message-ID: <878345026.20061104101100@gmail.com> Hello Dan, Saturday, November 4, 2006, 3:49:13 AM, you wrote: > You might want to rename your (&&&) and (|||), though, since they clash > with those defined in Control.Arrow. > I found that by defining (???) then way I did, I could use > (Control.Arrow.|||) as-is for the second part. i just not use arrows because i don't understand them. my definitions of "&&&" and "|||" is like those in C/perl/ruby and most times i use them alone: debugging &&& debug_info, first_time ||| putStrLn "" in the far future, i will be glad to see && and || redefined in this way (or some like this; it should just provide ruby's look&feel plus extensibility). although for my own program this may be solved by just not importing Prelude. hmmm, i should think about it.. but && and || functions is not exactly the same as ?: operator (nor in C, nor in standard Haskell, nor in my implementation). with these operations condition is tested _twice_ and if second argument has "false" value, third one will be returned anyway: True && False || True => True True ? False : True => False btw, it may be extended slightly more by adding application version: a &&. f = a &&& (f a) example: str &&. ("debug info: "++) now such function named unlessNull that is not so neat -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From jbapple+haskell-cafe at gmail.com Sat Nov 4 16:54:46 2006 From: jbapple+haskell-cafe at gmail.com (Jim Apple) Date: Sat Nov 4 16:54:29 2006 Subject: [Haskell-cafe] A type class puzzle In-Reply-To: <2608b8a80611020152o34501a09ge04c85b1b56f8ad4@mail.gmail.com> References: <2608b8a80610310102i1e54092bhb04da958a3978def@mail.gmail.com> <20061031094546.GA7530@lambda> <2608b8a80611020152o34501a09ge04c85b1b56f8ad4@mail.gmail.com> Message-ID: On 11/2/06, Yitzchak Gale wrote: > GHC says: > > Functional dependencies conflict between instance declarations: > instance Replace Zero a a (a -> a -> a) > instance (...) => Replace (Succ n) a [l] f' > > Not true. The type constraints on the second instance > prevent any overlap. GHC doesn't take constraints into account when checking fundeps. You're looking for Sulzmann's Chameleon, which does all sorts of constraint magic. http://www.comp.nus.edu.sg/~sulzmann/chameleon/ Also, I'd be surprized if Oleg didn't have a work-around in GHC. Jim From sven.panne at aedion.de Sun Nov 5 08:32:40 2006 From: sven.panne at aedion.de (Sven Panne) Date: Sun Nov 5 08:33:49 2006 Subject: [Haskell-cafe] A restricted subset of CPP included in a revision of Haskell 98 In-Reply-To: References: Message-ID: <200611051432.41208.sven.panne@aedion.de> [ I'm just working through a large backlog of mails, so the original message is a bit old... :-) ] Am Sonntag, 20. August 2006 22:37 schrieb Henning Thielemann: > On Thu, 17 Aug 2006, Brian Smith wrote: > [...] > I think there should be more effort to avoid CPP completely. My > experiences with Modula-3 are, that you can nicely separate > special-purpose stuff into modules which are included depending on some > conditions. Say you want the same module both for Windows and Unix, you > provide directories WIN32 and POSIX containing implementations with the > same interface and then the make system can choose the appropriate > directory. [...] That's a nice theory, but this doesn't work in practice, at least not for me. The problem in my OpenGL/GLUT/... bindings is that the calling convention to the native libraries is different on Windows, and there is no "Haskell way" to parametrize this. Therefore using a preprocessor is the only sane way I see here. Having to duplicate e.g. 567 "foreign imports" just to avoid CPP in the OpenGL package is a rather bad tradeoff IMHO. Almost everything is better than redundancy, even CPP... Another use of CPP in the OpenGL package is to access OpenGL extension entry points. Here CPP is used to generate a 'foreign import "dynamic"' and two Haskell functions per extension entry. Perhaps this could be done via TH, but this would limit the portability, again a bad tradeoff. I would be glad if there were other ways to achieve these things, but I fail to see them. Cheers, S. From pupeno at pupeno.com Sun Nov 5 13:17:07 2006 From: pupeno at pupeno.com (Pupeno) Date: Sun Nov 5 13:17:39 2006 Subject: [Haskell-cafe] Unicode strings Message-ID: <200611051817.13553.pupeno@pupeno.com> Skipped content of type multipart/mixed-------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 198 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061105/3a300f61/attachment.bin From sjanssen at cse.unl.edu Sun Nov 5 13:28:54 2006 From: sjanssen at cse.unl.edu (Spencer Janssen) Date: Sun Nov 5 13:29:34 2006 Subject: [Haskell-cafe] Unicode strings In-Reply-To: <200611051817.13553.pupeno@pupeno.com> References: <200611051817.13553.pupeno@pupeno.com> Message-ID: The problem is that GHC's output functions only print the lowest 8 bits of each code point. To print these higher code points, you'll need to translate your [Char] into a byte encoding that your terminal will understand (most likely UTF-8). I know there are several of these floating around in the wild, hopefully someone will chime in with a code snippet soon. Also, I seem to remember that Bulat's Streams library supports some Unicode encodings, perhaps you can check there? Cheers, Spencer Janssen On Nov 5, 2006, at 12:17 PM, Pupeno wrote: > Hello, > I am trying to make a program that outputs some Unicode characters > but the > output doesn't match what I try to print. > Attached is a little test program. It tries to print the arrows > "????" but > instead it outputs "\220\221\222\223" (that is, character number > 220, then > 221, then 222). I've also tried writing the Unicode code points > (although GHC > 6.6 should deal just fine with Unicode source code) and I get the same > result. In case anybody wants to try, this would be the > string: "\8592\8593\8594\8595". > I am also attaching the output file, you can see that the contents > are not > right. > Any ideas what am I doing wrong here ? > Thank you. > -- > Pupeno (http://pupeno.com) > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From pitkali at gmail.com Sun Nov 5 13:43:08 2006 From: pitkali at gmail.com (Piotr Kalinowski) Date: Sun Nov 5 13:42:48 2006 Subject: [Haskell-cafe] Unicode strings In-Reply-To: References: <200611051817.13553.pupeno@pupeno.com> Message-ID: <57dfc5df0611051043p5d4bdc41ue97360985dd4d459@mail.gmail.com> Hello, http://repetae.net/repos/jhc/UTF8.hs has some nice functions for UTF-8 - unicode conversions. Regards, -- Intelligence is like a river: the deeper it is, the less noise it makes -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061105/6b49bc58/attachment.htm From luis at arjox.org Sun Nov 5 13:46:43 2006 From: luis at arjox.org (Luis F. Araujo) Date: Sun Nov 5 13:47:24 2006 Subject: [Haskell-cafe] Unicode strings In-Reply-To: <200611051817.13553.pupeno@pupeno.com> References: <200611051817.13553.pupeno@pupeno.com> Message-ID: <454E3193.3070407@arjox.org> Pupeno wrote: > Hello, > I am trying to make a program that outputs some Unicode characters but the > output doesn't match what I try to print. > Attached is a little test program. It tries to print the arrows "????" but > instead it outputs "\220\221\222\223" (that is, character number 220, then > 221, then 222). I've also tried writing the Unicode code points (although GHC > 6.6 should deal just fine with Unicode source code) and I get the same > result. In case anybody wants to try, this would be the > string: "\8592\8593\8594\8595". > I am also attaching the output file, you can see that the contents are not > right. > Any ideas what am I doing wrong here ? > Thank you. > > ------------------------------------------------------------------------ > > import qualified System.IO as IO > > main = do > let str = "????" > putStrLn str > h <- IO.openFile "test.output" IO.WriteMode > IO.hPutStrLn h str > > > The problem is with the output of putStrLn. You need to encode the string into utf8. You can find several modules on the web, i have been using this one: http://www.haskell.org/pipermail/haskell-i18n/2004-February/000127.html From hthiel.char at zonnet.nl Sun Nov 5 14:24:21 2006 From: hthiel.char at zonnet.nl (Hans van Thiel) Date: Sun Nov 5 15:04:19 2006 Subject: [Haskell-cafe] Glade Gtk2Hs Tutorial Message-ID: <1162754661.4447.10.camel@localhost.localdomain> Hello, The Haskell Gtk2Hs adaptation of the 'Developing Gnome Apps with Glade' tutorial for beginners is now also on http://eddy.writelinux.com/ Note there are translations there of the original version for C in French, Dutch, Spanish, Turkish and Korean. Native speakers of those languages who are interested could use these and check out the Haskell Gtk2Hs listings later. Thanks, Hans van Thiel From isto.aho at dnainternet.net Sun Nov 5 15:47:34 2006 From: isto.aho at dnainternet.net (isto) Date: Sun Nov 5 15:47:03 2006 Subject: [Haskell-cafe] 64bit code output is less optimized than 32bit in ghc? Message-ID: <1162759655.10183.20.camel@localhost.localdomain> Hi again, Still playing with the Mersenne Twister and here is the updated 64 bit version so that there are not so many constructor calls on next64 (together with updated compiling flags). I was wondering why different runs can have such different run times and the cause was found to be my system: also the C version running times can vary (usually 0.65 but sometimes 0.3). The 64 bit version took usually about 1.1 or 1.2 seconds while 32bit version required only 0.78 (against 0.65 with C for both 32 and 64 bit versions). Since the real work horse here is the next64 function, I took a look of Core. There seems to be an extra case-statement in 64bit version and this might explain the performance drop (about 6 or 7 lines below _DEFAULT text on both versions below). Relevant parts of the Core below, code attached. It is very possible that I'm missing something obvious here. So what is happening here? :) Thanks again for any comments! br, Isto -------------------------------------------- Core (32 and 64 nexts) Rec { Mersenne.$wnext64 :: Data.Array.IO.Internals.IOUArray GHC.Base.Int GHC.Word.Word64 -> GHC.Prim.Int# -> GHC.Prim.State# GHC.Prim.RealWorld -> (# GHC.Prim.State# GHC.Prim.RealWorld, (GHC.Word.Word64, GHC.Base.Int) #) [GlobalId] [Arity 3 Str: DmdType LLL] Mersenne.$wnext64 = \ (w_s2Zq :: Data.Array.IO.Internals.IOUArray GHC.Base.Int GHC.Word.Word64) (ww_s2Zt :: GHC.Prim.Int#) (w1_s2Zv :: GHC.Prim.State# GHC.Prim.RealWorld) -> case ww_s2Zt of ds_X2F1 { __DEFAULT -> case w_s2Zq of wild_a2Pp { Data.Array.Base.STUArray ds2_a2Pr ds3_a2Ps marr#_a2Pt -> case GHC.Prim.readWord64Array# @ GHC.Prim.RealWorld marr#_a2Pt ds_X2F1 w1_s2Zv of wild2_a2PA { (# s2#_a2PC, e#_a2PD #) -> (# s2#_a2PC, ((case lit_r34C of wild1_a2Ol { GHC.Word.W64# y#_a2On -> let { ww1_a2NY [Just L] :: GHC.Prim.Word# [Str: DmdType] ww1_a2NY = GHC.Prim.xor# e#_a2PD (GHC.Prim.and# (GHC.Prim.uncheckedShiftRL# e#_a2PD 29) __word 6148914691236517205) } in let { ww2_X2Q0 [Just L] :: GHC.Prim.Word# [Str: DmdType] ww2_X2Q0 = GHC.Prim.xor# ww1_a2NY (GHC.Prim.and# (GHC.Prim.uncheckedShiftL# ww1_a2NY 17) __word 8202884508482404352) } in let { ww3_X2QE [Just L] :: GHC.Prim.Word# [Str: DmdType] ww3_X2QE = GHC.Prim.xor# ww2_X2Q0 (GHC.Prim.and# (GHC.Prim.uncheckedShiftL# ww2_X2Q0 37) y#_a2On) } in GHC.Word.W64# (GHC.Prim.xor# ww3_X2QE (GHC.Prim.uncheckedShiftRL# ww3_X2QE 43)) }), (GHC.Base.I# (GHC.Prim.+# ds_X2F1 1))) #) } }; 312 -> case Mersenne.generateNumbers64 w_s2Zq w1_s2Zv of wild_a2DL { (# new_s_a2DN, a87_a2DO #) -> case Mersenne.$wnext64 w_s2Zq 0 new_s_a2DN of wild1_X2Fy { (# new_s1_X2FB, a871_X2FD #) -> case a871_X2FD of wild2_Xar { (w2_aU2, iN_aU3) -> (# new_s1_X2FB, wild2_Xar #) } } } } end Rec } Mersenne.next64 :: Data.Array.IO.Internals.IOUArray GHC.Base.Int GHC.Word.Word64 -> GHC.Base.Int -> GHC.IOBase.IO (GHC.Word.Word64, GHC.Base.Int) [GlobalId] [Arity 3 Worker Mersenne.$wnext64 Str: DmdType LU(L)L] Mersenne.next64 = __inline_me (\ (w_s2Zq :: Data.Array.IO.Internals.IOUArray GHC.Base.Int GHC.Word.Word64) (w1_s2Zr :: GHC.Base.Int) (w2_s2Zv :: GHC.Prim.State# GHC.Prim.RealWorld) -> case w1_s2Zr of w3_X30R { GHC.Base.I# ww_s2Zt -> Mersenne.$wnext64 w_s2Zq ww_s2Zt w2_s2Zv }) Rec { Mersenne.$wnext32 :: Data.Array.IO.Internals.IOUArray GHC.Base.Int GHC.Word.Word32 -> GHC.Prim.Int# -> GHC.Prim.State# GHC.Prim.RealWorld -> (# GHC.Prim.State# GHC.Prim.RealWorld, (GHC.Word.Word32, GHC.Base.Int) #) [GlobalId] [Arity 3 NoCafRefs Str: DmdType LLL] Mersenne.$wnext32 = \ (w_s2YJ :: Data.Array.IO.Internals.IOUArray GHC.Base.Int GHC.Word.Word32) (ww_s2YM :: GHC.Prim.Int#) (w1_s2YO :: GHC.Prim.State# GHC.Prim.RealWorld) -> case ww_s2YM of ds_X2CS { __DEFAULT -> case w_s2YJ of wild_a2Hd { Data.Array.Base.STUArray ds2_a2Hf ds3_a2Hj marr#_a2Hk -> case GHC.Prim.readWord32Array# @ GHC.Prim.RealWorld marr#_a2Hk ds_X2CS w1_s2YO of wild2_a2Hr { (# s2#_a2Ht, e#_a2Hu #) -> (# s2#_a2Ht, ((let { ww1_a2Fr [Just L] :: GHC.Prim.Word# [Str: DmdType] ww1_a2Fr = GHC.Prim.xor# e#_a2Hu (GHC.Prim.uncheckedShiftRL# e#_a2Hu 11) } in let { ww2_X2GX [Just L] :: GHC.Prim.Word# [Str: DmdType] ww2_X2GX = GHC.Prim.xor# ww1_a2Fr (GHC.Prim.and# (GHC.Prim.narrow32Word# (GHC.Prim.uncheckedShiftL# ww1_a2Fr 7)) __word 2636928640) } in let { ww3_X2Hp [Just L] :: GHC.Prim.Word# [Str: DmdType] ww3_X2Hp = GHC.Prim.xor# ww2_X2GX (GHC.Prim.and# (GHC.Prim.narrow32Word# (GHC.Prim.uncheckedShiftL# ww2_X2GX 15)) __word 4022730752) } in GHC.Word.W32# (GHC.Prim.xor# ww3_X2Hp (GHC.Prim.uncheckedShiftRL# ww3_X2Hp 18))), (GHC.Base.I# (GHC.Prim.+# ds_X2CS 1))) #) } }; 624 -> case Mersenne.generateNumbers32 w_s2YJ w1_s2YO of wild_a2DL { (# new_s_a2DN, a87_a2DO #) -> case Mersenne.$wnext32 w_s2YJ 0 new_s_a2DN of wild1_X2F2 { (# new_s1_X2F5, a871_X2F7 #) -> case a871_X2F7 of wild2_X80 { (w2_aSH, iN_aSI) -> (# new_s1_X2F5, wild2_X80 #) } } } } end Rec } Mersenne.next32 :: Data.Array.IO.Internals.IOUArray GHC.Base.Int GHC.Word.Word32 -> GHC.Base.Int -> GHC.IOBase.IO (GHC.Word.Word32, GHC.Base.Int) [GlobalId] [Arity 3 Worker Mersenne.$wnext32 NoCafRefs Str: DmdType LU(L)L] Mersenne.next32 = __inline_me (\ (w_s2YJ :: Data.Array.IO.Internals.IOUArray GHC.Base.Int GHC.Word.Word32) (w1_s2YK :: GHC.Base.Int) (w2_s2YO :: GHC.Prim.State# GHC.Prim.RealWorld) -> case w1_s2YK of w3_X2ZO { GHC.Base.I# ww_s2YM -> Mersenne.$wnext32 w_s2YJ ww_s2YM w2_s2YO }) -------------- next part -------------- A non-text attachment was scrubbed... Name: Mersenne.hs Type: text/x-haskell Size: 4696 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061105/a7f9291f/Mersenne-0001.bin -------------- next part -------------- A non-text attachment was scrubbed... Name: testMT.hs Type: text/x-haskell Size: 993 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061105/a7f9291f/testMT-0001.bin From stefan at cs.uu.nl Sun Nov 5 15:51:24 2006 From: stefan at cs.uu.nl (Stefan Holdermans) Date: Sun Nov 5 15:51:18 2006 Subject: [Haskell-cafe] Module visibility of data type constructors In-Reply-To: <171dfd0a0611041139r732cee51w1a1b88cc43700be5@mail.gmail.com> References: <171dfd0a0611041139r732cee51w1a1b88cc43700be5@mail.gmail.com> Message-ID: <17C8D3BD-2643-48CD-B937-C6CCCC23BD91@cs.uu.nl> Slavomir, > module Foo (Bar) where > data Bar = Bar > > In ghc this allows me to use Bar, the type constructor, in another > module, although it shouldn't be visible outside Foo. On the other > hand, if I change Bar's definition as: > > data Bar = Baz > > Baz isn't visible outside Foo. On terminology: in data T = D T is called a type constructor and is called a *data* constructor. Cheers, Stefan From stefan at cs.uu.nl Sun Nov 5 15:55:23 2006 From: stefan at cs.uu.nl (Stefan Holdermans) Date: Sun Nov 5 15:55:01 2006 Subject: [Haskell-cafe] Module visibility of data type constructors In-Reply-To: <17C8D3BD-2643-48CD-B937-C6CCCC23BD91@cs.uu.nl> References: <171dfd0a0611041139r732cee51w1a1b88cc43700be5@mail.gmail.com> <17C8D3BD-2643-48CD-B937-C6CCCC23BD91@cs.uu.nl> Message-ID: <29CB2600-C904-4615-9077-ED6AB3E8040E@cs.uu.nl> > data T = D I wrote: > T is called a type constructor and is called a *data* constructor. and obviously meant: ... and D is called a *data* constructor. From alfonso.acosta at gmail.com Sun Nov 5 15:56:02 2006 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Sun Nov 5 15:55:42 2006 Subject: [Haskell-cafe] RFC and Announcement: HLADSPA, LADSPA for Haskell Message-ID: <6a7c66fc0611051256x58efdd90qf1151cfbb64a179f@mail.gmail.com> Hi all, Let me introduce myself. I'm a computer science engineering student, writing his masters thesis about a VHDL translator for ForSyDe (http://www.imit.kth.se/info/FOFU/ForSyDe/ , a Hardware Description Language embedded in Haskell) In order to show a practical application of ForSyDe I decided to try with its audio processing design capabilities. For that purpouse I decided to port LADSPA (http://www.ladspa.org/ ) to Haskell. The result so far is HLADSPA 0.1, which can be downloaded from http://www.student.nada.kth.se/~alfonsoa/HLADSPA-0.1.tgz and contains a testing plugin (Null.hs). It requires GHC>=6.6 due to the use of template haskell and existentially quantified records (read on for more on this). Even for people not interested in LADSPA itself, the project can be regarded as an example of how to create plugins and shared libraries in Haskell without making use hs-plugins. I'll be happy to read any comments and/or questions regarding the project. Here are the design questions on my side: The most important part for creating the HLADSPA, was modelling the LADSPA header file (http://www.ladspa.org/ladspa_sdk/ladspa.h.txt ) in Haskell (http://www.student.nada.kth.se/~alfonsoa/HLADSPA-0.1/HLADSPA.hs ) The essential code snippet is, ===================== -- Existentially quantified records allow the plugin developer -- to chose hd and id types at will and, allowing to declare "heterogeneous" -- Descriptor lists. Drawback: it only works in ghc 6.6 and -- makes the design tricky. The problem comes from modelling (void*) in Haskell -- id is the implementation data data Descriptor = forall id. Descriptor {uniqueID :: LadspaIndex, label :: String, properties :: LadspaProperties, name, maker, copyright :: String, portCount :: LadspaIndex, portDescriptors :: [PortDescriptor], portNames :: [String], portRangeHints :: [PortRangeHint], _implementationData :: id, _instantiate :: Descriptor -> LadspaIndex -> Maybe Instance} -- hd is the handle data Instance = forall hd. Instance { _this :: hd, -- initial handle -- In this case we are using lists to represent the port I/O buffers, so the -- port connections (buffer pointers of ports) is handled by the marshaller -- connectPort :: (hd -> LadspaIndex -> Ptr LadspaData -> IO hd) _activate :: Maybe(hd -> IO ()), -- (LadspaIndex,PortData) indicates the portnumber and its data _run :: hd -> LadspaIndex -> [(LadspaIndex,PortData)] -> ([(LadspaIndex,PortData)], hd), -- Not yet implemented (is not mandatory for a plugin to provide them) -- _runAdding :: -- _setAddingGain :: _deactivate :: Maybe (hd -> IO ()), _cleanup :: hd -> IO () } ===================== This is the best solution I could come up with and I'm not still happy with it. The trickiest part, was modelling (void*) in Haskell. I know that using lists for I/O buffers is inefficient but I coded it having ForSyDe in mind. If people show interest I can code a faster StorableArray-version. Here are my questions. * I'm using GHC's existentially quantified records extension to hide the hd and id parameters because the plugin programmer has to be able to provide a collection of Descriptor (a Descriptor list in current release). I would love to find a solution in plain Haskell98. Any ideas? * This approach requires splitting the original C LADSPA_Descriptor struct in the Descriptor and Instance Haskell types, which leads to a design error: there are functions (e.g. _run, _activate ... ) in Instance which really belong to Descriptor (those functions shouldn't change with the plugin instance). For example, with this approach, it is not possible to tell the plugin host if activate() or deactivate() will be used because this is "asked" any instances is created. * Real Time support in HLADSPA. From LADSPA's documentation: "Property LADSPA_PROPERTY_HARD_RT_CAPABLE indicates that the plugin is capable of running not only in a conventional host but also in a `hard real-time' environment. To qualify for this the plugin must satisfy all of the following: (1) The plugin must not use malloc(), free() or other heap memory management within its run() or run_adding() functions. All new memory used in run() must be managed via the stack. These restrictions only apply to the run() function." Should I forget about HARD_RT_CAPABLE with Haskell? Is there a way to control the use of the heap by a function? * I'm not so sure about the types of _activate, _deactivate and _cleanup. I don't even know if I should include them because they only seem to be required by a language with side effects. Furthermore, _activate() and _deactivate() don't seem to have sense with current implementation cause they are "separated from instantiate() to aid real-time support" and using lists as I/O buffers discards RT support (see above) Thanks in advance for your comments/answers, Alfonso Acosta PS1: Big thanks and claps for the people at #haskell@Freenode . They helped a lot to make this initial release possible. PS2: I would like to get the project hosted at the darcs repository at haskell.org. Do you consider it interesting enough for it? From alfonso.acosta at gmail.com Sun Nov 5 16:04:58 2006 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Sun Nov 5 16:04:37 2006 Subject: [Haskell-cafe] Re: RFC and Announcement: HLADSPA, LADSPA for Haskell In-Reply-To: <6a7c66fc0611051256x58efdd90qf1151cfbb64a179f@mail.gmail.com> References: <6a7c66fc0611051256x58efdd90qf1151cfbb64a179f@mail.gmail.com> Message-ID: <6a7c66fc0611051304x2eed0cabmd3a879500bb5970e@mail.gmail.com> On 11/5/06, Alfonso Acosta wrote: > * This approach requires splitting the original C LADSPA_Descriptor > struct in the Descriptor and Instance Haskell types, which leads to a > design error: there are functions (e.g. _run, _activate ... ) in > Instance which really belong to Descriptor (those functions shouldn't > change with the plugin instance). For example, with this approach, it > is not possible to tell the plugin host if activate() or deactivate() > will be used because this is "asked" any instances is created. I meant "because this is 'asked' _before_ any instances are created", sorry From slavomir.kaslev at gmail.com Sun Nov 5 16:35:09 2006 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Sun Nov 5 16:34:47 2006 Subject: [Haskell-cafe] Module visibility of data type constructors In-Reply-To: <29CB2600-C904-4615-9077-ED6AB3E8040E@cs.uu.nl> References: <171dfd0a0611041139r732cee51w1a1b88cc43700be5@mail.gmail.com> <17C8D3BD-2643-48CD-B937-C6CCCC23BD91@cs.uu.nl> <29CB2600-C904-4615-9077-ED6AB3E8040E@cs.uu.nl> Message-ID: <171dfd0a0611051335r1de9e6al5132cb47914c07c1@mail.gmail.com> On 11/5/06, Stefan Holdermans wrote: > > data T = D > > I wrote: > > > T is called a type constructor and is called a *data* constructor. > > and obviously meant: > > ... and D is called a *data* constructor. > Yes, you are right. I am newcomer to Haskell, coming from the C++ world, and I certainly lack proper Haskell-ish terminology. I apologize for that. -- Slavomir Kaslev From alfonso.acosta at gmail.com Sun Nov 5 16:50:34 2006 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Sun Nov 5 16:50:14 2006 Subject: [Haskell-cafe] Translating Haskell to VHDL. What approach to follow? Message-ID: <6a7c66fc0611051350x2033367dt456f2b5aef1f5ce2@mail.gmail.com> Hi all, As I wrote in the previous HLADPSA announcement, during the following moths I'm going to write a translator from Haskell to VHDL in order to accomplish my masters thesis goal. The main requirement is managing to translate from a ForSyDe (http://www.imit.kth.se/info/FOFU/ForSyDe/ ) specification which is Haskell after all, to VHDL. In order to get part of the work for free I decided to design the translator as a compiler backend. The best option so far seems to be Yhc's Core API (http://haskell.org/haskellwiki/Yhc/API/Core ), which unfortunately lacks type information. I discarded GHC due to the current "bit-rotted" state of External Core (http://www.haskell.org/pipermail/haskell-cafe/2006-October/018786.html ) and higher complexity of its core representation (SystemFC). I might have overlooked other approaches and/or intermediate representations such as GHC's C-- and STG (is it still used?). I'd be pleased to hear any suggestions. Thanks in advance, Alfonso Acosta From ndmitchell at gmail.com Sun Nov 5 21:16:30 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Sun Nov 5 21:16:08 2006 Subject: [Haskell-cafe] Translating Haskell to VHDL. What approach to follow? In-Reply-To: <6a7c66fc0611051350x2033367dt456f2b5aef1f5ce2@mail.gmail.com> References: <6a7c66fc0611051350x2033367dt456f2b5aef1f5ce2@mail.gmail.com> Message-ID: <404396ef0611051816p2781e116te3332ad8c82d4bdc@mail.gmail.com> Hi > In order to get part of the work for free I decided to design the > translator as a compiler backend. The best option so far seems to be > Yhc's Core API (http://haskell.org/haskellwiki/Yhc/API/Core ), which > unfortunately lacks type information. Can you mention what you need type information for? If it is to detect higher order functions (as you have mentioned in IRC conversations with me) then in about a week I am going to announce a Yhc.Core first order transformation, which will remove that issue for you. In general the lack of types in Yhc.Core has not proved a major issue for anyone - if there is anyone who does absolutely require type information in their intermediate language and therefore cannot use Yhc.Core, I'd be very interested to hear from them. > I discarded GHC due to the current "bit-rotted" state of External Core > (http://www.haskell.org/pipermail/haskell-cafe/2006-October/018786.html > ) and higher complexity of its core representation (SystemFC). Igloo submitted a few patches in the last week to get GHC.Core working again. It doesn't have the same infrastructure support as Yhc.Core, but it does have the advantage of having the GHC team behind it. > I'd be pleased to hear any suggestions. I (obviously...) would like you to use Yhc.Core, if you could expand on why that isn't appropriate for you then perhaps you'll either get improvements into Yhc.Core or some hints from the GHC team :) Thanks Neil (ndm) From alfonso.acosta at gmail.com Sun Nov 5 23:18:45 2006 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Sun Nov 5 23:18:23 2006 Subject: [Haskell-cafe] Translating Haskell to VHDL. What approach to follow? In-Reply-To: <404396ef0611051816p2781e116te3332ad8c82d4bdc@mail.gmail.com> References: <6a7c66fc0611051350x2033367dt456f2b5aef1f5ce2@mail.gmail.com> <404396ef0611051816p2781e116te3332ad8c82d4bdc@mail.gmail.com> Message-ID: <6a7c66fc0611052018h31759ecfp6d302c0189cbc660@mail.gmail.com> On 11/6/06, Neil Mitchell wrote: > Can you mention what you need type information for? If it is to detect > higher order functions (as you have mentioned in IRC conversations > with me) then in about a week I am going to announce a Yhc.Core first > order transformation, which will remove that issue for you. In general > the lack of types in Yhc.Core has not proved a major issue for anyone > - if there is anyone who does absolutely require type information in > their intermediate language and therefore cannot use Yhc.Core, I'd be > very interested to hear from them. As you said, detecting the use of high order is one of the reasons as it's not supported by VHDL. I haven't yet planned how to achieve the translation but VHDL, unlike Haskell, doesn't have type inference mechanisms. That means I need to declare the interface of whatever I will translate each Yhc.Core function to (i.e. VHDL Entities, Architectures, Functions ... ) >> I discarded GHC due to the current "bit-rotted" state of External Core > Igloo submitted a few patches in the last week to get GHC.Core working > again. It doesn't have the same infrastructure support as Yhc.Core, > but it does have the advantage of having the GHC team behind it. Does that change involve ExternalCore as well? Either the way, those are great news. I'll have a look at it again.I don't know much about SystemFC itself but I'm familiar with SystemF and doesn't seem as friendly and easy to work with as Yhc.Core . I'll give it a try anyway. Thanks for the answer, Alfonso Acosta (fons) From simonpj at microsoft.com Mon Nov 6 03:37:01 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Mon Nov 6 03:36:49 2006 Subject: [Haskell-cafe] Translating Haskell to VHDL. What approach to follow? In-Reply-To: <6a7c66fc0611051350x2033367dt456f2b5aef1f5ce2@mail.gmail.com> References: <6a7c66fc0611051350x2033367dt456f2b5aef1f5ce2@mail.gmail.com> Message-ID: <036EAC76E7F5EC4996A3B3C3657D4116071C9998@EUR-MSG-21.europe.corp.microsoft.com> | In order to get part of the work for free I decided to design the | translator as a compiler backend. The best option so far seems to be | Yhc's Core API (http://haskell.org/haskellwiki/Yhc/API/Core ), which | unfortunately lacks type information. | | I discarded GHC due to the current "bit-rotted" state of External Core | (http://www.haskell.org/pipermail/haskell-cafe/2006-October/018786.html | ) and higher complexity of its core representation (SystemFC). Yhc is a great, so don't let me stop you using it... but I can't resist explaining why FC is the way it is. There is a real tension here between simplicity and types. The reason that GHC uses FC as its intermediate language is precisely because FC is the simplest *typed* language we know that can serve as a target for Haskell. If you drop the types, you certainly can use a simpler language! However, you only pay for what you use; for example, if you don't use newtypes, GADT's, associated types, you won't see any coercions. It's true that the ExtCore rep is somewhat bit-rotted, but the only thing missing to get Core *output* is someone to beef up the pretty printer. I'd do it myself, except that there is a *design* task to do, namely to fix the concrete syntax for some of FC's constructs. One could choose anything, but it'd be good to choose a syntax that is easy to parse. Once the syntax is designed, it'd take an hour or two to make GHC emit it. (There's a separate job to make GHC parse and typecheck ExtCore as its source program, but you don't need that.) Aaron Tomb has offered to become the maintainer for External Core; I'm sure he'd be interested in having a "customer". Simon From magnus at therning.org Mon Nov 6 05:08:44 2006 From: magnus at therning.org (Magnus Therning) Date: Mon Nov 6 05:13:37 2006 Subject: [Haskell-cafe] Re: Haskell-Cafe Digest, Vol 39, Issue 6 In-Reply-To: References: <20061102043317.75C9C3244F3@www.haskell.org> Message-ID: <20061106100844.GA427@die.therning.org> On Sat, Nov 04, 2006 at 17:22:31 +0100, Lemmih wrote: [..] >pseq is just as bad. The problem is excessive use of strictness >annotations in the hope of a magical performance improvement. >Strictness annotations should be used with care and only placed where >they're needed. Premature annotations for strictness is the root of all evil? :-) How do one find "good" places to use strictness annotations? (Is using a profiler the answer, just like it's the answer for manual optimisation in non-lazy languages?) Oh, just in case you didn't guess it already, I'm a Haskell n00b who has yet to achieve enlightenment... /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus Software is not manufactured, it is something you write and publish. Keep Europe free from software patents, we do not want censorship by patent law on written works. "And wow! Hey! What's this thing coming towards me very fast? Very very fast. So big and flat and round, it needs a big wide sounding word like... ow... ound... round... ground! That's it! That's a good name - ground! I wonder if it will be friends with me?" -- For the sperm whale, it wasn't. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061106/c35f8901/attachment.bin From lemming at henning-thielemann.de Mon Nov 6 05:27:54 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Mon Nov 6 05:29:14 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: <706781845.20061104095938@gmail.com> References: <002001c6efa4$c8372510$1cf52950@osmet> <22523.213.84.177.94.1161000771.squirrel@webmail.xs4all.nl> <5ce89fb50610160731ja2de0d8l23903e914dcfe8da@mail.gmail.com> <984680831.20061016195414@gmail.com> <454BF5D3.60705@imageworks.com> <706781845.20061104095938@gmail.com> Message-ID: On Sat, 4 Nov 2006, Bulat Ziganshin wrote: > Hello Dan, > > Saturday, November 4, 2006, 5:07:15 AM, you wrote: > > > Here's an idea that (I think) is useful and backwards compatible: > > fractional and negative fixity. > > yes, i think the same. for example, once i've tried to define postfix > 'when' operator like those in perl/ruby > > print msg `on` mode==debug > > but failed because my code frequently contains '$' and there is no way > to define operation with a lower precedence This could be solved by the solutions proposed in this thread: http://www.haskell.org/pipermail/haskell-cafe/2006-October/018923.html From ndmitchell at gmail.com Mon Nov 6 05:48:00 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Mon Nov 6 05:47:37 2006 Subject: [Haskell-cafe] Translating Haskell to VHDL. What approach to follow? In-Reply-To: <036EAC76E7F5EC4996A3B3C3657D4116071C9998@EUR-MSG-21.europe.corp.microsoft.com> References: <6a7c66fc0611051350x2033367dt456f2b5aef1f5ce2@mail.gmail.com> <036EAC76E7F5EC4996A3B3C3657D4116071C9998@EUR-MSG-21.europe.corp.microsoft.com> Message-ID: <404396ef0611060248n1b88a620o41c9ca77ad385ff9@mail.gmail.com> Hi > I haven't yet planned how to achieve the translation but VHDL, unlike > Haskell, doesn't have type inference mechanisms. That means I need to > declare the interface of whatever I will translate each Yhc.Core > function to (i.e. VHDL Entities, Architectures, Functions ... ) Can you explain more about the "declare the interface" remark? I suspect this can be acheived with Yhc using the signatures from the .hi files, or embeding the information with our "typerep" Haskell extension. > It's true that the ExtCore rep is somewhat bit-rotted, but the only > thing missing to get Core *output* is someone to beef up the pretty > printer. I'd do it myself, except that there is a *design* task to do, > namely to fix the concrete syntax for some of FC's constructs. One > could choose anything, but it'd be good to choose a syntax that is easy > to parse. Once the syntax is designed, it'd take an hour or two to make > GHC emit it. (There's a separate job to make GHC parse and typecheck > ExtCore as its source program, but you don't need that.) For a reference point, I debated what the Yhc Core language should look like for a while. Then I gave up, grabbed a copy of DrIFT, adding "deriving Binary" annotations and was done. There is a concrete binary data type that represents Yhc.Core, but I have no idea what it is, and I certainly don't support access to it. There is a Haskell library which can load a Yhc.Core file, manipulate it, write it out etc - removing the need for a concrete syntax. We have a pretty printer, but since thats a one way mapping its much easier, we just made it look as much like Haskell as possible (no Z encoding etc). Thanks Neil From lemming at henning-thielemann.de Mon Nov 6 06:35:55 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Mon Nov 6 06:36:22 2006 Subject: [Haskell-cafe] RFC and Announcement: HLADSPA, LADSPA for Haskell In-Reply-To: <6a7c66fc0611051256x58efdd90qf1151cfbb64a179f@mail.gmail.com> References: <6a7c66fc0611051256x58efdd90qf1151cfbb64a179f@mail.gmail.com> Message-ID: On Sun, 5 Nov 2006, Alfonso Acosta wrote: > PS1: Big thanks and claps for the people at #haskell@Freenode . They > helped a lot to make this initial release possible. > PS2: I would like to get the project hosted at the darcs repository at > haskell.org. Do you consider it interesting enough for it? Yes, definitely. Could you also please add some note to http://www.haskell.org/haskellwiki/Libraries_and_tools/Music_and_sound From dons at cse.unsw.edu.au Mon Nov 6 06:43:05 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Mon Nov 6 06:42:52 2006 Subject: [Haskell-cafe] RFC and Announcement: HLADSPA, LADSPA for Haskell In-Reply-To: References: <6a7c66fc0611051256x58efdd90qf1151cfbb64a179f@mail.gmail.com> Message-ID: <20061106114305.GG20953@cse.unsw.EDU.AU> lemming: > > On Sun, 5 Nov 2006, Alfonso Acosta wrote: > > > PS1: Big thanks and claps for the people at #haskell@Freenode . They > > helped a lot to make this initial release possible. > > PS2: I would like to get the project hosted at the darcs repository at > > haskell.org. Do you consider it interesting enough for it? > > Yes, definitely. Could you also please add some note to > http://www.haskell.org/haskellwiki/Libraries_and_tools/Music_and_sound I agree, and would remark for anyone reading: Please add your projects, whether they are applications, libraries, tools, darcs repos, to : http://haskell.org/haskellwiki/Libraries_and_tools *All* Haskell code that's available, and fit to compile should be findable from that page. -- Don From alfonso.acosta at gmail.com Mon Nov 6 08:37:18 2006 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Mon Nov 6 08:36:56 2006 Subject: [Haskell-cafe] RFC and Announcement: HLADSPA, LADSPA for Haskell In-Reply-To: References: <6a7c66fc0611051256x58efdd90qf1151cfbb64a179f@mail.gmail.com> Message-ID: <6a7c66fc0611060537w437bcac7vf43de59112c1be62@mail.gmail.com> > > PS2: I would like to get the project hosted at the darcs repository at > > haskell.org. Do you consider it interesting enough for it? > > Yes, definitely. Could you also please add some note to > http://www.haskell.org/haskellwiki/Libraries_and_tools/Music_and_sound That's something I had in mind from the very beginning, but I didn't want to add anything to the Libraries section before deciding upon where I was going to host it. As suggested at http://haskell.org/haskellwiki/How_to_write_a_Haskell_program#Hosting I'll contact Simon Marlow to ask for it. Can anyone confirm if wrting to simonmar _at_ microsoft _dot_ com is the right way to reach him for his purpose? (I couldn't find any haskell.org-specific address) From alfonso.acosta at gmail.com Mon Nov 6 09:17:56 2006 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Mon Nov 6 09:18:23 2006 Subject: [Haskell-cafe] Translating Haskell to VHDL. What approach to follow? In-Reply-To: <404396ef0611060248n1b88a620o41c9ca77ad385ff9@mail.gmail.com> References: <6a7c66fc0611051350x2033367dt456f2b5aef1f5ce2@mail.gmail.com> <036EAC76E7F5EC4996A3B3C3657D4116071C9998@EUR-MSG-21.europe.corp.microsoft.com> <404396ef0611060248n1b88a620o41c9ca77ad385ff9@mail.gmail.com> Message-ID: <6a7c66fc0611060617u1da5254bt52d8202382a46639@mail.gmail.com> On 11/6/06, Neil Mitchell wrote: > Can you explain more about the "declare the interface" remark? I > suspect this can be acheived with Yhc using the signatures from the > .hi files, or embeding the information with our "typerep" Haskell > extension. I think you're correctly suspecting it. What I meant is that, like with every structured programming language (that I know about at least) all VHDL functions and procedure declarations (Entities & Architectures as well) include a mandatory interface declaration which includes the type of its parameters and possible return value. That implies I need a way to infere or directly obtain the types of the functions used in the core representation. That as you said, can probably be done by means of the .hi files or the typerep extension you mentioned. I'll try to have a look at both options. Any good documentation pointers? I think that should be all the type information required for the translation. > Yhc is a great, so don't let me stop you using it... but I can't resist > explaining why FC is the way it is. There is a real tension here > between simplicity and types. The reason that GHC uses FC as its > intermediate language is precisely because FC is the simplest *typed* > language we know that can serve as a target for Haskell. If you drop > the types, you certainly can use a simpler language! I'm sure SystemFC wasn't arbitrarily chosen, and works well for its main purpose (being GHC's intermediate language). On the other hand it can be a bit complicated if it is used as the input of backend whose goal is translating to a another another high abstraction language. For my planned backend, it _seems_ to be enough to use a desugarized version of the initial source file as input and being able to obtain/infer the type its the functions. That doesn't mean I have already discarded GHC, I recorsidered it again after reading that there is some work being done to update it. Does http://www.haskell.org/ghc/docs/papers/core.ps.gz still apply? From dons at cse.unsw.edu.au Mon Nov 6 09:22:48 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Mon Nov 6 09:22:27 2006 Subject: [Haskell-cafe] Livecoding music in Haskell Message-ID: <20061106142248.GA25716@cse.unsw.EDU.AU> Alex McLean has kindly put up a screencast of him creating *music via live coding in Haskell* ! http://doc.gold.ac.uk/~ma503am/alex/haskellmusic And a .avi version of the screencast, playable in mplayer (for those not flash inclined). http://yaxu.org/20/hs.avi The code is running in hs-plugins, and being reloaded on the fly as he edits the source, changing the rhythms that are produced. More on this on Alex's blog: http://doc.gold.ac.uk/~ma503am/alex/ Cool stuff! -- Don From alfonso.acosta at gmail.com Mon Nov 6 09:38:54 2006 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Mon Nov 6 09:38:31 2006 Subject: [Haskell-cafe] Livecoding music in Haskell In-Reply-To: <20061106142248.GA25716@cse.unsw.EDU.AU> References: <20061106142248.GA25716@cse.unsw.EDU.AU> Message-ID: <6a7c66fc0611060638p11eddc68l26a24638314cdce@mail.gmail.com> Absolutely cool I knew about hs-plugins but I didn't know that the plugin code could be reloaded on the fly. Impressive. On 11/6/06, Donald Bruce Stewart wrote: > Alex McLean has kindly put up a screencast of him creating > *music via live coding in Haskell* ! > > http://doc.gold.ac.uk/~ma503am/alex/haskellmusic > > And a .avi version of the screencast, playable in mplayer (for those not > flash inclined). > > http://yaxu.org/20/hs.avi > > The code is running in hs-plugins, and being reloaded on the fly as he > edits the source, changing the rhythms that are produced. More on this > on Alex's blog: > > http://doc.gold.ac.uk/~ma503am/alex/ > > Cool stuff! > > -- Don > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From dBuchmann at gmx.net Mon Nov 6 10:18:24 2006 From: dBuchmann at gmx.net (dBuchmann@gmx.net) Date: Mon Nov 6 10:18:02 2006 Subject: [Haskell-cafe] Vectors and Matrices Message-ID: <8F155BF6-D27C-42AB-9D5E-2D854A3F68FB@gmx.net> Is there a library implementing vectors and matrices in a possible elegant manner. Even perhaps with Tensor-/Kronecker-Product and Scalar-Product. greetings. _________________________________ dBuchmann@gmx.net; visit http://filzbits.de From lemming at henning-thielemann.de Mon Nov 6 10:22:55 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Mon Nov 6 10:23:17 2006 Subject: [Haskell-cafe] Vectors and Matrices In-Reply-To: <8F155BF6-D27C-42AB-9D5E-2D854A3F68FB@gmx.net> References: <8F155BF6-D27C-42AB-9D5E-2D854A3F68FB@gmx.net> Message-ID: On Mon, 6 Nov 2006 dBuchmann@gmx.net wrote: > Is there a library implementing vectors and matrices in a possible elegant > manner. Even perhaps with Tensor-/Kronecker-Product and Scalar-Product. > greetings. http://www.haskell.org/haskellwiki/Libraries_and_tools/Mathematics http://www.haskell.org/haskellwiki/Linear_algebra From bulat.ziganshin at gmail.com Mon Nov 6 07:40:14 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Mon Nov 6 11:53:04 2006 Subject: [Haskell-cafe] Re: Haskell-Cafe Digest, Vol 39, Issue 6 In-Reply-To: <20061106100844.GA427@die.therning.org> References: <20061102043317.75C9C3244F3@www.haskell.org> <20061106100844.GA427@die.therning.org> Message-ID: <17710137811.20061106154014@gmail.com> Hello Magnus, Monday, November 6, 2006, 1:08:44 PM, you wrote: > How do one find "good" places to use strictness annotations? (Is using > a profiler the answer, just like it's the answer for manual optimisation > in non-lazy languages?) the only way i know is to plug & pray :) btw, a few weeks ago Andrea Rosatto has memory leak problem and we (especially me :) tried to explain devil in details. look in archives, this may be very useful -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From lemming at henning-thielemann.de Mon Nov 6 12:34:07 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Mon Nov 6 12:36:16 2006 Subject: [Haskell-cafe] How to design default implementations of type class methods? Message-ID: I like to hear some opinions about how to implement class method defaults. Let's consider the following example: I want to classify types which allow for computation of the greatest common divisor. The greatest common divisor can be computed by Euclid's algorithm in some cases (integers, univariate polynomials) but not in all cases (integer matrices, multivariate polynomials). So maybe it's a good idea to set the Euclidean algorithm as default implementation for the GCD method. Say, I have already implemented both the normal Euclidean algorithm as "euclid", which only emits the GCD, and the extended Euclidean algorithm "extendedEuclid" which also determines a and b in "gcd(x,y) = a*x + b*y" for given x and y. Now I have two choices for implementing default methods: 1. Implement a method by calling other methods of the same class. class (Units a) => PID a where extendedGCD :: a -> a -> (a,a,a) extendedGCD = extendedEuclid divMod gcd :: a -> a -> a gcd x y = let (g,_,_) = extendedGCD x y in g Advantage: User must implement only few methods, here extendedGCD, the other ones work automatically. Disadvantage: User must know, how the default methods call each other, in order to not introduce cycles. 2. Implement a method by calling custom code, preferably a public function according to http://www.haskell.org/haskellwiki/Slim_instance_declaration class (Units a) => PID a where extendedGCD :: a -> a -> (a,a,a) extendedGCD = extendedEuclid divMod gcd :: a -> a -> a gcd = euclid mod Advantages/Disadvantages are negated with respect to the first item. :-) Ok, this example class is not well chosen, because in the case of multivariate polynomials, not only extended Euclidean algorithm fails, but it is in many cases not possible to represent the GCD of x and y as a linear combination of x and y. My question is not limited to this case: I want to know, what reasons exist pro and cons each alternative. Currently I prefer the first way, because it reduces the work of implementing instances to the things that are essential for the particular type. People who want specialized and more efficient methods, must implement all methods. From fis at wiwi.hu-berlin.de Mon Nov 6 13:33:35 2006 From: fis at wiwi.hu-berlin.de (Matthias Fischmann) Date: Mon Nov 6 13:37:50 2006 Subject: [Haskell-cafe] How to design default implementations of type class methods? In-Reply-To: References: Message-ID: <20061106183335.GU8171@localhost.localdomain> i haven't thought this through, but a variant of your first option may be to factor out extendedGCD into a class PIDEXT that is a parent of PID (occurs in the context of the declaration of PID). this way both methods will be available in PID. advantages: the dependencies are a little more explicit cycles are easier to avoid. drawbacks: more complicated interface less flexibility in implementation also i think there was an issue with superclass constraints not being inferrable from explicit subclass constraints, leading to bulky type signatures all over the code that is using your classes. but perhaps this gives somebody a better idea? m. On Mon, Nov 06, 2006 at 06:34:07PM +0100, Henning Thielemann wrote: > To: Haskell Cafe > From: Henning Thielemann > Date: Mon, 06 Nov 2006 18:34:07 +0100 (CET) > Subject: [Haskell-cafe] How to design default implementations of type class > methods? > > > I like to hear some opinions about how to implement class method defaults. > > Let's consider the following example: > I want to classify types which allow for computation of the greatest > common divisor. The greatest common divisor can be computed by Euclid's > algorithm in some cases (integers, univariate polynomials) but not in all > cases (integer matrices, multivariate polynomials). So maybe it's a good > idea to set the Euclidean algorithm as default implementation for the GCD > method. Say, I have already implemented both the normal Euclidean > algorithm as "euclid", which only emits the GCD, and the extended > Euclidean algorithm "extendedEuclid" which also determines a and b in > "gcd(x,y) = a*x + b*y" for given x and y. > > Now I have two choices for implementing default methods: > > 1. Implement a method by calling other methods of the same class. > > class (Units a) => PID a where > extendedGCD :: a -> a -> (a,a,a) > extendedGCD = extendedEuclid divMod > > gcd :: a -> a -> a > gcd x y = let (g,_,_) = extendedGCD x y in g > > Advantage: User must implement only few methods, > here extendedGCD, the other ones work automatically. > Disadvantage: User must know, how the default methods call each other, > in order to not introduce cycles. > > 2. Implement a method by calling custom code, > preferably a public function according to > http://www.haskell.org/haskellwiki/Slim_instance_declaration > > class (Units a) => PID a where > extendedGCD :: a -> a -> (a,a,a) > extendedGCD = extendedEuclid divMod > > gcd :: a -> a -> a > gcd = euclid mod > > Advantages/Disadvantages are negated with respect to the first item. :-) > > > Ok, this example class is not well chosen, because in the case of > multivariate polynomials, not only extended Euclidean algorithm fails, but > it is in many cases not possible to represent the GCD of x and y as a > linear combination of x and y. > > My question is not limited to this case: I want to know, what reasons > exist pro and cons each alternative. Currently I prefer the first way, > because it reduces the work of implementing instances to the things that > are essential for the particular type. People who want specialized and > more efficient methods, must implement all methods. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe -- Institute of Information Systems, Humboldt-Universitaet zu Berlin web: http://www.wiwi.hu-berlin.de/~fis/ e-mail: fis@wiwi.hu-berlin.de tel: +49 30 2093-5742 fax: +49 30 2093-5741 office: Spandauer Strasse 1, R.324, 10178 Berlin, Germany pgp: AD67 CF64 7BB4 3B9A 6F25 0996 4D73 F1FD 8D32 9BAA -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061106/60d1a95f/attachment.bin From cwitty at newtonlabs.com Mon Nov 6 14:15:14 2006 From: cwitty at newtonlabs.com (Carl Witty) Date: Mon Nov 6 14:15:22 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: <454BF5D3.60705@imageworks.com> References: <002001c6efa4$c8372510$1cf52950@osmet> <22523.213.84.177.94.1161000771.squirrel@webmail.xs4all.nl> <5ce89fb50610160731ja2de0d8l23903e914dcfe8da@mail.gmail.com> <984680831.20061016195414@gmail.com> <454BF5D3.60705@imageworks.com> Message-ID: <1162840514.9671.18.camel@meteor.newtonlabs.com> On Fri, 2006-11-03 at 18:07 -0800, Dan Weston wrote: > Here's an idea that (I think) is useful and backwards compatible: > fractional and negative fixity. > > There have been 3 separate times where I've wanted an operator just > above 0 ($) but less than 1 (>>= or >>>), or else just below 0 (like a > superlow $$) > > infix 0.5 ??? > infix -1 $$ > > The only change would be internal to compiler, wouldn't it? Since fixity > is just syntactic sugar, there should be no semantic difficulties. I like it! One caveat: the grammar from the Haskell Report specifies a fixed number of precedence levels; if anybody has a Haskell parser implemented by feeding this grammar into a parser generator, they would have to rewrite the parser to implement this. (But it's quite possible that nobody has such a parser; the alternate approach of using a first pass that ignores precedences and fixing them up with a second-pass hand-written operator precedence parser seems to be easier and more popular, and should be easy to adapt to new precedence levels.) Carl Witty From bortzmeyer at nic.fr Mon Nov 6 15:37:32 2006 From: bortzmeyer at nic.fr (Stephane Bortzmeyer) Date: Mon Nov 6 15:41:47 2006 Subject: [Haskell-cafe] [ghc 6.6] Where is FGL now? Message-ID: <20061106203732.GA1463@sources.org> In ghc 6.4, I used Data.Graph.Inductive (aka FGL): % ghc-pkg list /usr/lib/ghc-6.4/package.conf: ... fgl-5.2, ... In ghc 6.6, it seems it disappeared. ghc-pkg list does not show it, the compiler says "Could not find module `Data.Graph.Inductive'" but it is still documented in http://www.haskell.org/ghc/docs/latest/html/libraries/index.html and the ghc 6.6 changelog does not mention its removal. From bortzmeyer at nic.fr Mon Nov 6 15:56:03 2006 From: bortzmeyer at nic.fr (Stephane Bortzmeyer) Date: Mon Nov 6 15:56:42 2006 Subject: [Haskell-cafe] Re: [ghc 6.6] Where is FGL now? In-Reply-To: <20061106203732.GA1463@sources.org> References: <20061106203732.GA1463@sources.org> Message-ID: <20061106205603.GA3845@sources.org> On Mon, Nov 06, 2006 at 09:37:32PM +0100, Stephane Bortzmeyer wrote a message of 15 lines which said: > In ghc 6.6, it seems it disappeared. OK, sorry for the false alarm, I've found it: http://www.haskell.org/ghc/dist/6.6/ghc-6.6-src-extralibs.tar.bz2 For those who use the Debian packages, you'll need the package libghc6-fgl-dev (which is not yet in Debian "testing", while ghc 6.6 is; so, for Haskell programmers, you may have to choose between "stable" and "unstable" and avoid "testing" for the time being). From alex at slab.org Mon Nov 6 16:36:31 2006 From: alex at slab.org (alex) Date: Mon Nov 6 16:36:09 2006 Subject: [Haskell-cafe] Livecoding music in Haskell In-Reply-To: <20061106142248.GA25716@cse.unsw.EDU.AU> References: <20061106142248.GA25716@cse.unsw.EDU.AU> Message-ID: <1162848991.4908.19.camel@localhost> On Tue, 2006-11-07 at 01:22 +1100, Donald Bruce Stewart wrote: > Alex McLean has kindly put up a screencast of him creating > *music via live coding in Haskell* ! > http://doc.gold.ac.uk/~ma503am/alex/haskellmusic Thanks Don! I originally did this screencast a while ago for a 6 minute constrained talk which explains why it's so short. This was about my first Haskell program, I've progressed some since this experiment and will make a new screencast soon. I've been doing similar things with Perl for some years as part of a band called slub (http://slub.org/), a quick 20 second taster of my Perl here: http://yaxu.org/20/pl.avi the same thing as flash here: http://youtube.com/watch?v=fbefIdbSmD4 It's probably worth pointing out that while slub have had people dancing to their code on several occasions, these particular screencasts are really of tech demos rather than music. cheers, alex From bulat.ziganshin at gmail.com Mon Nov 6 12:07:17 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Mon Nov 6 16:44:05 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: References: <002001c6efa4$c8372510$1cf52950@osmet> <22523.213.84.177.94.1161000771.squirrel@webmail.xs4all.nl> <5ce89fb50610160731ja2de0d8l23903e914dcfe8da@mail.gmail.com> <984680831.20061016195414@gmail.com> <454BF5D3.60705@imageworks.com> <706781845.20061104095938@gmail.com> Message-ID: <1809061187.20061106200717@gmail.com> Hello Henning, Monday, November 6, 2006, 1:27:54 PM, you wrote: >> print msg `on` mode==debug >> >> but failed because my code frequently contains '$' and there is no way >> to define operation with a lower precedence > This could be solved by the solutions proposed in this thread: > > http://www.haskell.org/pipermail/haskell-cafe/2006-October/018923.html it's too complex for my purposes. -1 priority is enough -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From nicolas.frisby at gmail.com Mon Nov 6 17:09:35 2006 From: nicolas.frisby at gmail.com (Nicolas Frisby) Date: Mon Nov 6 17:09:10 2006 Subject: [Haskell-cafe] aggressiveness of functional dependencies Message-ID: <5ce89fb50611061409k18c7a446p559987bde70eaf10@mail.gmail.com> I have a question about functional dependencies, instance contexts, and type inference. A specific example and question is in the attached code. In brief the question is: to what degree does type inference use the functional dependencies of an instance's class and context? I believe I am wishing it were more aggressive than it is. Please note that I have not enabled overlapping instances. Any suggestions regarding how to get the inferred type of |rite_t1| to be the one I anticipated would be much appreciated. Of course, I would also appreciate explanations of why I shouldn't anticipate it! The rest of this message is a copy of the attached code. Thanks, Nick I'm using GHC 6.6, but I see the same inferred types with 6.4.1. > {-# OPTIONS -fglasgow-exts #-} > {-# OPTIONS -fallow-undecidable-instances #-} -- for the coverage condition > > module FunDepEx where A plain ole' isomorphism class. > class Iso a b | a -> b, b -> a where > rite :: a -> b > left :: b -> a Isomorphism lifts through the sum bifunctor. > bifmap_either f g = either (Left . f) (Right . g) > > instance ( Iso f f', Iso g g' > ) => Iso (Either f g) (Either f' g') where > rite = bifmap_either rite rite > left = bifmap_either left left Some types to play around with. > newtype MyChar = MyChar Char deriving (Show, Eq) > > instance Iso MyChar Char where > rite (MyChar c) = c > left c = MyChar c > instance Iso Char MyChar where > rite c = MyChar c > left (MyChar c) = c My type inference confusion follows; the unit arguments are just to suppress the monomorphism restriction. > t1 :: Either Char a > t1 = Left 'c' > > rite_t1 () = rite t1 The inferred type for rite_t1 is rite_t1 :: (Iso (Either Char a) (Either f' g')) => () -> Either f' g' Why isn't the inferred type of rite_t1 the same as the ascribed type of rite_t1'? > rite_t1' :: Iso b b' => () -> Either MyChar b' > rite_t1' () = rite t1 -------------- next part -------------- A non-text attachment was scrubbed... Name: FunDepEx.lhs Type: application/octet-stream Size: 1270 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061106/c062799d/FunDepEx.obj From haskell at henning-thielemann.de Tue Nov 7 06:00:37 2006 From: haskell at henning-thielemann.de (Henning Thielemann) Date: Tue Nov 7 06:01:25 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: <1809061187.20061106200717@gmail.com> References: <002001c6efa4$c8372510$1cf52950@osmet> <22523.213.84.177.94.1161000771.squirrel@webmail.xs4all.nl> <5ce89fb50610160731ja2de0d8l23903e914dcfe8da@mail.gmail.com> <984680831.20061016195414@gmail.com> <454BF5D3.60705@imageworks.com> <706781845.20061104095938@gmail.com> <1809061187.20061106200717@gmail.com> Message-ID: On Mon, 6 Nov 2006, Bulat Ziganshin wrote: > Hello Henning, > > Monday, November 6, 2006, 1:27:54 PM, you wrote: > > >> print msg `on` mode==debug > >> > >> but failed because my code frequently contains '$' and there is no way > >> to define operation with a lower precedence > > > This could be solved by the solutions proposed in this thread: > > > > http://www.haskell.org/pipermail/haskell-cafe/2006-October/018923.html > > it's too complex for my purposes. -1 priority is enough This reminds me on good old BASIC programming days, where we numbered lines in steps of 10, in order to be able insert lines later. Unfortunately, BASIC never supported negative nor fractional line numbers. :-) From dnavarro at gmail.com Tue Nov 7 07:27:51 2006 From: dnavarro at gmail.com (Diego Navarro) Date: Tue Nov 7 07:56:11 2006 Subject: [Haskell-cafe] Announcements list Message-ID: There should be a separate, moderated Haskell-announcements list. I filter out haskell-cafe into a folder and read it separately from my main inbox, but I'd like to have important announcements directly into my inbox, and haskell@haskell.org still has some chatty questions-and-answers sessions. -- Diego Navarro/syntaxfree From lennart at augustsson.net Tue Nov 7 07:59:49 2006 From: lennart at augustsson.net (Lennart Augustsson) Date: Tue Nov 7 07:59:36 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: References: <002001c6efa4$c8372510$1cf52950@osmet> <22523.213.84.177.94.1161000771.squirrel@webmail.xs4all.nl> <5ce89fb50610160731ja2de0d8l23903e914dcfe8da@mail.gmail.com> <984680831.20061016195414@gmail.com> <454BF5D3.60705@imageworks.com> <706781845.20061104095938@gmail.com> <1809061187.20061106200717@gmail.com> Message-ID: <17DF76C3-68BF-41D5-BD77-8C695D3F8E65@augustsson.net> But DEC's language FOCAL had fractional line numbers. :) On Nov 7, 2006, at 06:00 , Henning Thielemann wrote: > > On Mon, 6 Nov 2006, Bulat Ziganshin wrote: > >> Hello Henning, >> >> Monday, November 6, 2006, 1:27:54 PM, you wrote: >> >>>> print msg `on` mode==debug >>>> >>>> but failed because my code frequently contains '$' and there is >>>> no way >>>> to define operation with a lower precedence >> >>> This could be solved by the solutions proposed in this thread: >>> >>> http://www.haskell.org/pipermail/haskell-cafe/2006-October/ >>> 018923.html >> >> it's too complex for my purposes. -1 priority is enough > > This reminds me on good old BASIC programming days, where we numbered > lines in steps of 10, in order to be able insert lines later. > Unfortunately, BASIC never supported negative nor fractional line > numbers. > :-) > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From lemming at henning-thielemann.de Tue Nov 7 08:29:11 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Tue Nov 7 08:29:07 2006 Subject: [Haskell-cafe] Livecoding music in Haskell In-Reply-To: <1162848991.4908.19.camel@localhost> References: <20061106142248.GA25716@cse.unsw.EDU.AU> <1162848991.4908.19.camel@localhost> Message-ID: On Mon, 6 Nov 2006, alex wrote: > I originally did this screencast a while ago for a 6 minute constrained > talk which explains why it's so short. This was about my first Haskell > program, I've progressed some since this experiment and will make a new > screencast soon. I also tried to create some music with the SuperCollider wrapper by Rohan Drape and the Haskore music package. However I had problems with accurate timing. How do you do the timing? From daniel.is.fischer at web.de Tue Nov 7 08:34:28 2006 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Tue Nov 7 08:30:42 2006 Subject: [Haskell-cafe] Permutation with k levels In-Reply-To: References: Message-ID: <200611071434.28475.daniel.is.fischer@web.de> This message seems to have lingered in obscuriy for a while, I only just received it. What about permLev :: Int -> (a -> a -> a) -> [a] -> [a] permLev 0 _ _ = [] permLev 1 _ xs = xs permLev k f xs = do x <- xs y <- permLev (k-1) f xs return (f x y) l1 :: [(String,Double)] l1 = [("A",0.8),("B",0.2)] com :: Num b => ([a],b) -> ([a],b) -> ([a],b) com (xs,x) (ys,y) = (xs ++ ys, x*y) ? Does *PermGen> permLev 1 com l1 [("A",0.8),("B",0.2)] *PermGen> permLev 2 com l1 [("AA",0.6400000000000001),("AB",0.16000000000000003), ("BA",0.16000000000000003),("BB",4.000000000000001e-2)] *PermGen> permLev 3 com l1 [("AAA",0.5120000000000001),("AAB",0.12800000000000003), ("ABA",0.12800000000000003),("ABB",3.200000000000001e-2), ("BAA",0.12800000000000003),("BAB",3.200000000000001e-2), ("BBA",3.200000000000001e-2),("BBB",8.000000000000002e-3)] *PermGen> permLev 4 com l1 [("AAAA",0.40960000000000013),("AAAB",0.10240000000000003), ("AABA",0.10240000000000003),("AABB",2.5600000000000008e-2), ("ABAA",0.10240000000000003),("ABAB",2.5600000000000008e-2), ("ABBA",2.5600000000000008e-2),("ABBB",6.400000000000002e-3), ("BAAA",0.10240000000000003),("BAAB",2.5600000000000008e-2), ("BABA",2.5600000000000008e-2),("BABB",6.400000000000002e-3), ("BBAA",2.5600000000000008e-2),("BBAB",6.400000000000002e-3), ("BBBA",6.400000000000002e-3),("BBBB",1.6000000000000005e-3)] satisfy you? Cheers, Daniel Am Montag, 30. Oktober 2006 18:45 schrieb Nuno Pinto: > Hi all, > > I am coding a zip application (using huffman algorithm) for academic > reasons. In the process i needed a permute function that i coded but > disliked a lot.. > > I went to the internet looking for a good generic permute algorithm in > haskell the best one i found was not generic at all: > > import List perms [] = [[]] perms (x:xs) = [ p ++ [x] ++ s | xs' > <- perms xs , (p, s) <- zip (inits xs') > (tails xs') ] > > I also found information regarding this subject in: > http://www.haskell.org/hawiki/PermutationExample > > What am i coding in specific? I receive a list in the form: > > -- l1 is a pair of the identifier and the associated probability > l1 = [("A",0.6),("B",0.2)] > > I must return the permutation with k levels; for example: > > -- permute l k = ... > -- should return > permute l1 0 = [] > permute l1 1 = l1 > permute l2 2 = [("AA",0.64),("AB",0.16),("BA",0.16),("BB",0.04)] > permute l3 3 = [("AAA", Pa*Pa*Pa), > ("AAB",Pa*Pa*Pb),("ABA",...),("ABB",...),("BAA",...),("BAB",...),("BBA",... >),("BBB",...)] > > --where: > -- 0.64 = Pa*Pa > -- 0.16 = Pa*Pb > -- 0.04 = Pb*Pb > > All of my friend are developing this in c... Of course its easier but i > have enough of c and c# at work, so I'm doing this in haskell, the way i > like it :) For all interested in huffman coding: > http://en.wikipedia.org/wiki/Huffman_coding > > Thanks in advance for the help, and greetings to all! > Nuno > > P.s. Follows the code i developed until now.. Its open source :P Just hope > no-one submit the same work as i did :P > > > > -- -- Este modulo define uma ferramenta de compress?o usando > para o -- efeito o algoritmo de Huffman.---- HZip quer dizer isso > mesmo: HuffmanZip.-- module HZip where import List > > -- #region Notas-- . Ver parte de compress?o/rendimento pois pode ter > boas dicas para efici?ncia.-- #endregion > > -- #region Constantes para efeitos de teste.-- -- Listas usadas > para efeito de teste.-- l1 = > [("b",0.15),("d",0.08),("f",0.02),("g",0.01),("e",0.08),("c",0.15),("a",0.5 >),("h",0.01)] l2 = [("a",0.8),("b",0.2)]-- #endregion > > -- #region Fun??es Auxiliares-- -- Fun??o que testa a > converg?ncia de fun??es.-- Quando o valor da pr?xima itera??o ? igual > ao da anterior-- devolve o resultado respectivo.---- Da autoria de > jasdiuminhopt-- -- -- A > fun??o a aplicar recursivamente.-- -- -- > A solu??o actual do problema.-- -- -- O resultado > final da opera??o.-- -- limit :: (a -> a) -> a -> a limit f s | > s == next = s | otherwise = limit f next where next > = f s > > -- -- Calcula a metade das probabilidades.-- -- > -- A lista de probabilidades.-- -- > -- O total das probabilidades a dividir por 2.-- > metade l = (sum l) / 2 > > -- -- Devolve o primeiro elemento de um tuplo de 3.-- > -- -- O tuplo.-- -- -- > O primeiro elemento.-- fst3 (a,_,_) = a > > -- -- Devolve o segundo elemento de um tuplo de 3.-- > -- -- O tuplo.-- -- -- > O segundo elemento.-- snd3 (_,b,_) = b > > -- -- Devolve o terceiro elemento de um tuplo de 3.-- > -- -- O tuplo.-- -- -- > O terceiro elemento.-- trd3 (_,_,c) = c-- #endregion > > -- #region Fun??es: Teoria da informa??o-- -- Calcula a > quantidade de informa??o de uma determinada mensagem.-- -- > -- A probabilidade da mensagem.-- -- > -- A quantidade de informa??o da mensagem.-- -- i > :: Float -> Float i p = logBase 2 (1/p) > > -- -- Entropia, fun??o que calcula a informa??o m?dia por > mensagem.-- -- -- A lista de > probabilidades.-- -- -- A informa??o m?dia por > mensagem.-- -- h :: [Float] -> Float h l = sum $ map (\p -> if > p == 0 then 0 else p * i p) l > > -- -- Calcula o comprimento m?dio do c?digo (N).-- -- > -- Lista do tipo (c,p) em que:-- p -> > Probabilidade do acontecimento.-- c -> Comprimento da palavra > c?digo.-- -- -- O comprimento m?dio do c?digo.-- > -- n :: [(Float,Int)] -> Float n l = sum $ map (\(c,p) -> p * > c) l > > -- -- Desigualdade de Kraft.-- -- termo='l'>-- A lista de comprimento das palavras c?digo.-- > -- -- True, se o c?digo bin?rio for univocamente > decifravel-- False caso contr?rio.-- -- kr :: [Int] -> Bool > kr l = 1 >= sum ( map (\n -> 2^^(-n)) l ) > > -- -- Algoritmo dos c?digos de Huffman.-- -- termo='l'>-- Lista do tipo (c,p) em que:-- c -> Caracter > identificativo.-- p -> Probabilidade desse caracter acontecer.-- > -- -- Tuplo do tipo (t,n,b) em que:-- t -> > Tabela de Huffman resultante.-- n -> Comprimento m?dio do c?digo.-- > b -> Se o c?digo resultante ? un?vocamente decifravel.-- -- > huffman :: [(String,Float)] -> ([(String,Float,[Int])], Float, Float, Bool) > huffman l = (tabHuffman,n lProbTam,kr lTamanhos) where > lProbTam = map (\(c,p,b) -> (p,fromIntegral(length b))) tabHuffman > lTamanhos = map (\(c,p,b) -> (length b)) tabHuffman > tabHuffman = concat $ limit passo5 [map (\(c,p) -> (c,p,[])) > (passo1 l)] > > -- -- Ordena as mensagens por ordem decrescente de > probabilidade.-- -- -- Lista do tipo (c,p) > em que:-- c -> Caracter identificativo.-- p -> Probabilidade > desse caracter acontecer.-- -- -- A lista ordenada > por ordem decrescente de probabilidade.-- -- passo1 :: > [(String,Float)] -> [(String,Float)] passo1 l = sortBy (\(_,p1) (_,p2) -> > compare p2 p1) l -- -- Repete o calculo para cada um dos > subconjuntos.-- -- -- Lista do tipo > (c,p,b) em que:-- c -> Caracter identificativo.-- p -> > Probabilidade desse caracter acontecer.-- b -> Lista de inteiros com > o bin?rio correspondente.-- -- -- A lista ordenada > por ordem decrescente de probabilidade.-- -- passo5 :: > [(String,Float,[Int])] -> [(String,Float,[Int])] passo5 l@(h:[]) = > (passo234 0 (metade (map (\(_,p,_) -> p) h)) h (length h) [] []) passo5 > l@(h:t) = (passo234 0 (metade (map (\(_,p,_) -> p) h)) h (length h) [] []) > `union` (passo5 t) > > -- -- Divide os subconjuntos cada um com apr?ximadamente m?tade > da probabilidade-- mantendo a ordena??o. Em seguida atribui o c?digo > bin?rio e termina a codifica??o-- para o subconjunto se este tiver > apenas um elemento.-- -- -- O acumulador > de probabilidade.-- -- -- Sublista a > esquerda.-- -- -- Sublista a direita.-- > -- -- Define o comportamento de paragem > caso sublista tenha comprimento 1.-- -- -- > O calculo actual da tabela de huffman.-- -- -- Um > passo da tabela de huffman.-- -- passo234 :: Float -> Float -> > [(String,Float,[Int])] -> Int -> [(String,Float,[Int])]-- > -> [(String,Float,[Int])] -> [[(String,Float,[Int])]] passo234 _ _ [] _ e > [] = [e] passo234 _ _ [] _ e d = [e]++[d] > passo234 _ _ (h:t) 1 e d = passo234 0 0 [] 1 [h] d passo234 ac > met l@((c,p,b):t) n [] d = passo234 (ac+p) met t n [(c,p,b++[0])] d > passo234 ac met l@((c,p,b):t) _ e d | ac < met = passo234 (ac+p) met t 2 > (e++[(c,p,b++[0])]) d |otherwise = > passo234 (ac+p) met t 2 e (d++[(c,p,b++[1])]) > > -- -- Codifica por blocos conforme um factor.-- -- > -- Lista do tipo (c,p) em que:-- c -> > Caracter identificativo.-- p -> Probabilidade desse caracter > acontecer.-- -- -- k = 1, codifica??o = > 8 bits.-- k = 2, codifica?ao = 16 bits.-- k = 3, codifica??o = 32 > bits.-- k = n, cofifica??o = 2^(n+2) bits.-- -- -- > A tabela de huffman associada,-- H (fonte),-- N,-- Se o > codigo gerado ? un?vocamente decifravel.-- -- permute deve ser > subsituido por (permute l k) blocos l k = (fst3 tabHuffman, h (map snd l), > (snd3 tabHuffman)/k, trd3 tabHuffman) where tabHuffman = > huffman permute > > -- -- Cria as permuta??es da de simbolos e calcula a > probabilidade associada.-- -- -- Lista do > tipo (c,p) em que:-- c -> Caracter identificativo.-- p -> > Probabilidade desse caracter acontecer.-- -- termo='k'>-- N?mero de niveis.-- -- -- Uma > lista com os novos simbolos (codifica??o por blocos) e a respectiva-- > probabilidade.-- permute = > [("aa",0.64),("ab",0.16),("ba",0.16),("bb",0.04)] > > -- -- Calcula a compress?o num determinado passo.-- -- > -- Lista do tipo (c,p) em que:-- c -> > Caracter identificativo.-- p -> Probabilidade desse caracter > acontecer.-- -- -- N?mero do passo.-- > -- -- Percentagem de compress?o.-- > compressao l k = (nf - n_)/nf where nf = snd3 (huffman > l) n_ = trd4 (blocos l k) > trd4 (_,_,c,_) = c-- #endregion > _________________________________________________________________ > Windows Live Spaces is here! It?s easy to create your own personal Web > site. http://spaces.live.com/signup.aspx From bulat.ziganshin at gmail.com Tue Nov 7 08:50:29 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Nov 7 08:51:27 2006 Subject: [Haskell-cafe] Announcements list In-Reply-To: References: Message-ID: <256604688.20061107165029@gmail.com> Hello Diego, Tuesday, November 7, 2006, 3:27:51 PM, you wrote: > There should be a separate, moderated Haskell-announcements list. I you can also read Haskell Weekly News for this purpose -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Tue Nov 7 08:52:24 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Nov 7 10:19:45 2006 Subject: [Haskell-cafe] Announcement: new maintainers forr wxHaskell In-Reply-To: References: Message-ID: <1133622689.20061107165224@gmail.com> Hello Jeremy, Friday, October 27, 2006, 7:12:44 PM, you wrote: > I'd ask the community to send patches via this list. i suggest to use libraries@haskell.org for this purpose. at least other libs maintained there -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Tue Nov 7 09:00:15 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Nov 7 10:19:49 2006 Subject: [Haskell-cafe] Permutation with k levels In-Reply-To: References: Message-ID: <1284439888.20061107170015@gmail.com> Hello Nuno, Monday, October 30, 2006, 8:45:24 PM, you wrote: > What am i coding in specific? I receive a list in the form: > ? > ??? -- l1 is a pair of the identifier and the associated probability > ?????? l1 = [("A",0.6),("B",0.2)] > ? > I must return the permutation with k levels; for example: > ? > ??? -- permute l k = ... > ??? -- should return > ??? permute l1 0 = [] > ??? permute l1 1 = l1 > ??? permute l2 2 = [("AA",0.64),("AB",0.16),("BA",0.16),("BB",0.04)] > ??? permute l3 3 = [("AAA", Pa*Pa*Pa), > ("AAB",Pa*Pa*Pb),("ABA",...),("ABB",...),("BAA",...),("BAB",...),("BBA",...),("BBB",...)] this is just a sort of Cartesian Product. but why you need this? if this is for generation of huffman codes, there is standard algorithm that generates optimal encoding - and it is named Huffman algorithm this algorithm just repeats combining of two nodes with least probability into the node that has summed probability until only one node remains. this node got empty code, its sons got codes '0' and '1' and so on, recursively you can look into zip sources for this algorithm, although it's implementation there is not ideal -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From simonmar at microsoft.com Tue Nov 7 10:50:04 2006 From: simonmar at microsoft.com (Simon Marlow) Date: Tue Nov 7 10:49:53 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: <706781845.20061104095938@gmail.com> Message-ID: haskell-prime-bounces@haskell.org wrote: > Hello Dan, > > Saturday, November 4, 2006, 5:07:15 AM, you wrote: > >> Here's an idea that (I think) is useful and backwards compatible: >> fractional and negative fixity. > > yes, i think the same. for example, once i've tried to define postfix > 'when' operator like those in perl/ruby > > print msg `on` mode==debug > > but failed because my code frequently contains '$' and there is no way > to define operation with a lower precedence > > really, there is another alternative to solve my particular problem: > make `op` applications having fixed -1 precedence. such applications > look "heavyweight" and once i have a wonderful debugging story just > because for my eyes it was obvious that (a `div` b+1) means "do add > before div" I'd support fractional and negative fixity. It's a simple change to make, but we also have to adopt http://hackage.haskell.org/cgi-bin/haskell-prime/trac.cgi/wiki/FixityResolution I've added the proposal to the end of that page. In fact, the page already mentioned that we could generalise fixity levels, but it didn't mention fractional or negative values being allowed. Cheers, Simon From mark at ixod.org Tue Nov 7 10:50:46 2006 From: mark at ixod.org (Mark T.B. Carroll) Date: Tue Nov 7 10:50:20 2006 Subject: [Haskell-cafe] Announcements list In-Reply-To: (Diego Navarro's message of "Tue, 7 Nov 2006 10:27:51 -0200") References: Message-ID: <87lkmn1cix.fsf@ixod.org> "Diego Navarro" writes: > There should be a separate, moderated Haskell-announcements list. I > filter out haskell-cafe into a folder and read it separately from my > main inbox, but I'd like to have important announcements directly into > my inbox, and haskell@haskell.org still has some chatty > questions-and-answers sessions. Making haskell@haskell.org moderated might be the answer? -- Mark From haskell at henning-thielemann.de Tue Nov 7 11:15:12 2006 From: haskell at henning-thielemann.de (Henning Thielemann) Date: Tue Nov 7 11:16:02 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: References: Message-ID: On Tue, 7 Nov 2006, Simon Marlow wrote: > I'd support fractional and negative fixity. It's a simple change to > make, but we also have to adopt > > http://hackage.haskell.org/cgi-bin/haskell-prime/trac.cgi/wiki/FixityResolution > > I've added the proposal to the end of that page. In fact, the page > already mentioned that we could generalise fixity levels, but it didn't > mention fractional or negative values being allowed. Maybe that page could also mention earlier proposals and the solutions without precedence numbers. I prefer the non-numeric approach with rules like "(<) binds more tightly than (&&)", because it says what is intended and it allows to make things unrelated that are unrelated, e.g. infix operators from different libraries. Consequently a precedence relation to general infix operators like ($) and (.) had be defined in each library. From simonmar at microsoft.com Tue Nov 7 11:43:26 2006 From: simonmar at microsoft.com (Simon Marlow) Date: Tue Nov 7 11:43:20 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: Message-ID: Henning Thielemann wrote: > On Tue, 7 Nov 2006, Simon Marlow wrote: > >> I'd support fractional and negative fixity. It's a simple change to >> make, but we also have to adopt >> >> > http://hackage.haskell.org/cgi-bin/haskell-prime/trac.cgi/wiki > /FixityResolution >> >> I've added the proposal to the end of that page. In fact, the page >> already mentioned that we could generalise fixity levels, but it >> didn't mention fractional or negative values being allowed. > > Maybe that page could also mention earlier proposals and the solutions > without precedence numbers. I prefer the non-numeric approach > with rules > like "(<) binds more tightly than (&&)", because it says what > is intended > and it allows to make things unrelated that are unrelated, e.g. infix > operators from different libraries. This is a much more heavyweight change, and its not a clear win. Yes I agree that in some ways it's strange to enforce a total order between unrelated things, but on the other hand it's very convenient, and easy to understand. Currently the default fixity is infixl 9. That is, if you don't declare a fixity, you automatically get a fixity that can be used relative to every other operator. This is quite useful - I bet if we made it mandatory to declare all the relative fixities then we'd need to add fixity declarations to lots of code. I forsee this being quite tiresome. If you'd like to make a concrete proposal, then feel free to do so and I'll make sure it gets onto the wiki. Cheers, Simon From polyomino at f2s.com Tue Nov 7 11:41:12 2006 From: polyomino at f2s.com (DavidA) Date: Tue Nov 7 11:45:29 2006 Subject: [Haskell-cafe] Re: Permutation with k levels References: Message-ID: What you're trying to do is called permutations with repetition, whereas permutations (unqualified) usually refers to permutations without repetition (and that's what the Haskell code you found is doing). See http://en.wikipedia.org/wiki/Permutations_and_combinations To get the result you want, take the list of (letter, probability) pairs, and generate the Cartesian product of k copies of itself. cartProd 0 xs = [[]] cartProd k xs = [x:ys | x <- xs, ys <- cartProd (k-1) xs] The result is all sequences of k (letter,probability) pairs, allowing repetitions. Then you just need to unzip and multiply: (\lps -> let (ls,ps) = unzip lps in (concat ls, product ps)) From haskell at henning-thielemann.de Tue Nov 7 12:30:09 2006 From: haskell at henning-thielemann.de (Henning Thielemann) Date: Tue Nov 7 12:30:39 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: References: Message-ID: On Tue, 7 Nov 2006, Simon Marlow wrote: > This is a much more heavyweight change, and its not a clear win. Haskell 2 ? :-) > If you'd like to make a concrete proposal, then feel free to do so and > I'll make sure it gets onto the wiki. What about the one of J?n Fairbairn ? http://www.haskell.org/pipermail/haskell-cafe/2006-October/018925.html From jon.fairbairn at cl.cam.ac.uk Tue Nov 7 13:10:30 2006 From: jon.fairbairn at cl.cam.ac.uk (Jon Fairbairn) Date: Tue Nov 7 13:10:07 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: Your message of "Tue, 07 Nov 2006 18:30:09 +0100." Message-ID: <23077.1162923030@calligramme.charmers> On 2006-11-07 at 18:30+0100 Henning Thielemann wrote: > On Tue, 7 Nov 2006, Simon Marlow wrote: > > > This is a much more heavyweight change, and its not a clear win. > > Haskell 2 ? :-) > > > If you'd like to make a concrete proposal, then feel free to do so and > > I'll make sure it gets onto the wiki. > > What about the one of J?n Fairbairn ? > http://www.haskell.org/pipermail/haskell-cafe/2006-October/018925.html The proposal to which that message refers was made before Haskell really existed: we didn't know the concrete syntax of the language, so I used arbitrary keywords. Even if we look at Phil Wadler's subsequent tidying up of it, I'm not at all sure how it fits with the language as it stands now. So while it might make a reasonable starting point, I don't think it yet counts as a concrete proposal! I must say though, that I don't like the reasoning that we can put in fractional fixities because it's a small change. The way to hell is through a series of small steps. If using integers to express fixities is a bit of a hack, switching to rational numbers is a hack on top of a hack. J?n -- J?n Fairbairn Jon.Fairbairn at cl.cam.ac.uk From chad.scherrer at gmail.com Tue Nov 7 13:15:12 2006 From: chad.scherrer at gmail.com (Chad Scherrer) Date: Tue Nov 7 13:14:46 2006 Subject: [Haskell-cafe] Efficiency of bang patterns Message-ID: I'm curious about the implementation of bang patterns, and the implications for performance. Previously on this list, Lemmih has pointed out that throwing in an extra `seq` here and there to force strictness is a bad idea, unless you do it very carefully. He points out that the strictness analyzer will catch a lot of cases without a need for seq. But the approach of compiling without any `seq`s, looking for leaks, and then adding them in one at a time seems tedious. There should be a more predictable, more uniform way of achieving strictness. Is it reasonable to promote a programming style where strictness is achieved using strictness annotations and bang patterns? I find it very appealing that the "!" syntax translates so nicely from type declarations to patterns. I had originally thought that every bang pattern was translated into a seq call, as a sort of preprocessing step, but from this page... http://hackage.haskell.org/trac/haskell-prime/wiki/BangPatterns ... is is clear that in many cases a bang pattern can be rewritten as a case statement, which seems to me an opportunity to avoid some code ugliness. In cases semantically distinct from a case statement, maybe something like the following could be done, or maybe is already... 1. Pass the expression to the strictness analyzer, without the bang pattern. 2. If it's already strict, great! We're done. 3. If not, add an extra seq call. Now, I'm no compiler expert (obviously, I suspect), and maybe I've misunderstood the role of the strictness analysis step. But being able to easily make things really strict seems pretty important, and there seem to be a lot of subtleties to using seq that make it difficult to tune for performance. -- Chad Scherrer "Time flies like an arrow; fruit flies like a banana" -- Groucho Marx From nicolas.frisby at gmail.com Tue Nov 7 13:39:02 2006 From: nicolas.frisby at gmail.com (Nicolas Frisby) Date: Tue Nov 7 13:38:35 2006 Subject: [Haskell-cafe] Re: aggressiveness of functional dependencies In-Reply-To: <5ce89fb50611061409k18c7a446p559987bde70eaf10@mail.gmail.com> References: <5ce89fb50611061409k18c7a446p559987bde70eaf10@mail.gmail.com> Message-ID: <5ce89fb50611071039q621d67aam42888e810fb100b1@mail.gmail.com> Having thought longer about it, it seems to be an issue with functional dependencies and overlapping instances. Perhaps, because an overlapping instance may be defined in some other module which would trump the Iso instance for Either, the type inference mechanism cannot commit to the instance presented in my code. It's being conservative. My confusion stems from the notion of functional dependency. Given the functional dependencies of Iso, there is exactly one type b for any type a such that Iso a b (and also vice versa). Thus it would seem that c for Iso (Either a b) c is always uniquely determined because of the instance from my code. However, because a more specific overlapping instance could always be added, this isn't the case. That more specific instances could specify something like Iso (Either Char Char) (Either Int Int). The functional dependency check does not recognize that this violates the dependencies introduced by the more general instance's context. I think this is because said dependencies (the inductives: Iso f f' and Iso g g') are introduced iff the more general instance fires. Is the type inference conservative because the possibility of a new overlapping instance always looms? If so, is this a good thing or a bad thing? Is this the "murky water" that Strongly Typed Heterogeneous Collections mentions? Sorry to double post. Thanks again, Nick On 11/6/06, Nicolas Frisby wrote: > I have a question about functional dependencies, instance contexts, > and type inference. A specific example and question is in the attached > code. > > In brief the question is: to what degree does type inference use the > functional dependencies of an instance's class and context? I believe > I am wishing it were more aggressive than it is. Please note that I > have not enabled overlapping instances. > > Any suggestions regarding how to get the inferred type of |rite_t1| to > be the one I anticipated would be much appreciated. Of course, I would > also appreciate explanations of why I shouldn't anticipate it! > > The rest of this message is a copy of the attached code. > > Thanks, > Nick > > > > I'm using GHC 6.6, but I see the same inferred types with 6.4.1. > > > {-# OPTIONS -fglasgow-exts #-} > > {-# OPTIONS -fallow-undecidable-instances #-} -- for the coverage condition > > > > module FunDepEx where > > > A plain ole' isomorphism class. > > > class Iso a b | a -> b, b -> a where > > rite :: a -> b > > left :: b -> a > > > Isomorphism lifts through the sum bifunctor. > > > bifmap_either f g = either (Left . f) (Right . g) > > > > instance ( Iso f f', Iso g g' > > ) => Iso (Either f g) (Either f' g') where > > rite = bifmap_either rite rite > > left = bifmap_either left left > > > Some types to play around with. > > > newtype MyChar = MyChar Char deriving (Show, Eq) > > > > instance Iso MyChar Char where > > rite (MyChar c) = c > > left c = MyChar c > > instance Iso Char MyChar where > > rite c = MyChar c > > left (MyChar c) = c > > > My type inference confusion follows; the unit arguments are just to > suppress the monomorphism restriction. > > > t1 :: Either Char a > > t1 = Left 'c' > > > > rite_t1 () = rite t1 > > The inferred type for rite_t1 is > rite_t1 :: (Iso (Either Char a) (Either f' g')) => () -> Either f' g' > > Why isn't the inferred type of rite_t1 the same as the ascribed type > of rite_t1'? > > > rite_t1' :: Iso b b' => () -> Either MyChar b' > > rite_t1' () = rite t1 > > > From dm.maillists at gmail.com Tue Nov 7 14:23:51 2006 From: dm.maillists at gmail.com (Daniel McAllansmith) Date: Tue Nov 7 14:23:08 2006 Subject: [Haskell-cafe] Re: Permutation with k levels In-Reply-To: References: Message-ID: <200611080823.51926.dm.maillists@gmail.com> On Wednesday 08 November 2006 05:41, DavidA wrote: > To get the result you want, take the list of (letter, probability) pairs, > and generate the Cartesian product of k copies of itself. > > cartProd 0 xs = [[]] > cartProd k xs = [x:ys | x <- xs, ys <- cartProd (k-1) xs] > > The result is all sequences of k (letter,probability) pairs, allowing > repetitions. > > Then you just need to unzip and multiply: > > (\lps -> let (ls,ps) = unzip lps in (concat ls, product ps)) > It does the basically the same thing but, you might also want to check out the Probabilistic Functional Programming library by Martin Erwig at http://web.engr.oregonstate.edu/~erwig/pfp/ It's got all sorts of other probability goodies in it. By importing the Probability module you can define your distribution and a permute as so probDist = mkD [("A", 0.8), ("B", 0.2)] permute 0 d = mkD [] permute 1 d = d permute k d = mapD (uncurry (++)) (prod d (permute (k - 1) d)) From dm.maillists at gmail.com Tue Nov 7 14:33:32 2006 From: dm.maillists at gmail.com (Daniel McAllansmith) Date: Tue Nov 7 14:32:49 2006 Subject: [Haskell-cafe] Re: Permutation with k levels In-Reply-To: <200611080823.51926.dm.maillists@gmail.com> References: <200611080823.51926.dm.maillists@gmail.com> Message-ID: <200611080833.33009.dm.maillists@gmail.com> On Wednesday 08 November 2006 08:23, Daniel McAllansmith wrote: Ahhh, whoops. It seems that lack of compilation errors is not a universal sign that a haskell program is correct. > permute 0 d = mkD [] mkD doesn't allow distributions with 0 sum probabilities, so you'd need to restrict the range of k From dmhouse at gmail.com Tue Nov 7 15:10:57 2006 From: dmhouse at gmail.com (David House) Date: Tue Nov 7 15:10:32 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: <23077.1162923030@calligramme.charmers> References: <23077.1162923030@calligramme.charmers> Message-ID: On 07/11/06, Jon Fairbairn wrote: > I must say though, that I don't like the reasoning that we > can put in fractional fixities because it's a small > change. The way to hell is through a series of small > steps. If using integers to express fixities is a bit of a > hack, switching to rational numbers is a hack on top of a > hack. Well, It's a _conceptually_ simple idea, one that doesn't make understanding the language much harder. Also, it provides an infinite space for fixities. I think the problem 'binds tighter than X but not as tight as Y', where X and Y are only fixity integer apart is somewhat common, and this would fix it. It would allow for extensibility into the future, where the operator space will only become more dense, and maintaining a complete order with only 10 integers to play will become more and more difficult. Allowing an infinite amount of operators to come between any two operators sounds like a solid design decision to me. -- -David House, dmhouse@gmail.com From alex at slab.org Tue Nov 7 16:32:11 2006 From: alex at slab.org (alex) Date: Tue Nov 7 16:31:44 2006 Subject: [Haskell-cafe] Livecoding music in Haskell In-Reply-To: References: <20061106142248.GA25716@cse.unsw.EDU.AU> <1162848991.4908.19.camel@localhost> Message-ID: <1162935131.4900.19.camel@localhost> On Tue, 2006-11-07 at 14:29 +0100, Henning Thielemann wrote: > I also tried to create some music with the SuperCollider wrapper by Rohan > Drape and the Haskore music package. That's great, I have used the OSC part of the wrapper but not the rest, and haven't looked at Haskore yet but have some time tonight and tomorrow for that... I would like to hear more about how you got them to work together though. > However I had problems with accurate timing. How do you do the timing? The way I see it there are two big issues - the first is drift and the second is latency. A drift error would be something like running at 120.2 bpm instead of 120 bpm. This isn't a problem until you try playing with other people. To fix it you have to avoid accumulating errors. I take a note of the time at the start of the program (or the last bpm change), then perform calculations based on what time it *should* be as an offset from that. The first time measurement you take is the only one you should keep. Latency I deal with by calculating everything a second or so ahead of time, and timestamping my OSC packets with times in the future. Then on the other side I have some scheduling stuff to trigger sounds at the right moment, for example in SuperCollider's sclang: response = { arg time, responder, message; if (message[1] == 'on', { SystemClock.sched(time - Date.getDate.rawSeconds, {Synth("noisebox", [\lgain, message[2] / 100, \rgain, message[3] / 100, \ts, message[4] / 100, \browndel, message[5] / 100, \filter, message[6], \envtype, message[7] ] ); nil; }; ); }); }; o = OSCresponder(nil, '/noise', response); o.add; However, as is quite obvious from that screencast, I haven't quite got around to timestamping Haskell OSC packets yet, I wanted to hear the latency. To timestamp a packet you just have to put it in a timestamped bundle though. I hope that's useful, if not let me know more about your timing problems, maybe I can still help. alex From nicolas.frisby at gmail.com Tue Nov 7 17:25:23 2006 From: nicolas.frisby at gmail.com (Nicolas Frisby) Date: Tue Nov 7 17:24:56 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: <1809061187.20061106200717@gmail.com> References: <002001c6efa4$c8372510$1cf52950@osmet> <22523.213.84.177.94.1161000771.squirrel@webmail.xs4all.nl> <5ce89fb50610160731ja2de0d8l23903e914dcfe8da@mail.gmail.com> <984680831.20061016195414@gmail.com> <454BF5D3.60705@imageworks.com> <706781845.20061104095938@gmail.com> <1809061187.20061106200717@gmail.com> Message-ID: <5ce89fb50611071425x29a913e2pd400e42a8a86454a@mail.gmail.com> I don't see how it's too complex. Isn't infixl ?? prec ?? < $ (??) = whenOperator exactly what you want to say? Sure you can solve the problem with negative fixities, but that's less expressive than the above (the total order is actually an over-specification). You want ?? to bind more tightly than does $; that's exactly what this approach would let you specify. When conjuring a number less than 0, what makes -1 a more appropriate choice than -2? There's really no answer to that question. Fractional fixities make it even worse. Nick On 11/6/06, Bulat Ziganshin wrote: > Hello Henning, > > Monday, November 6, 2006, 1:27:54 PM, you wrote: > > >> print msg `on` mode==debug > >> > >> but failed because my code frequently contains '$' and there is no way > >> to define operation with a lower precedence > > > This could be solved by the solutions proposed in this thread: > > > > http://www.haskell.org/pipermail/haskell-cafe/2006-October/018923.html > > it's too complex for my purposes. -1 priority is enough > > > -- > Best regards, > Bulat mailto:Bulat.Ziganshin@gmail.com > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From nicolas.frisby at gmail.com Tue Nov 7 17:25:40 2006 From: nicolas.frisby at gmail.com (Nicolas Frisby) Date: Tue Nov 7 17:25:12 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: References: <23077.1162923030@calligramme.charmers> Message-ID: <5ce89fb50611071425i4568d3d7y7167fe1ec7ca9f23@mail.gmail.com> Let's remember that if something is broke, it's only _right_ to _fix_ it. I patiently waited for someone else to make that pun. Understanding the language won't be much harder, but understanding fixity declarations will become a task. Consider: infixl -1.7521 -- what and why? As the operator space becomes more dense, negative and fractional fixities are going to become more obfuscated. The negative and fractional fixities will satisfy a number purposes well, but they will also be abused and lead to confusion. This smells like a wart growing on a wart to me. Nick On 11/7/06, David House wrote: > On 07/11/06, Jon Fairbairn wrote: > > I must say though, that I don't like the reasoning that we > > can put in fractional fixities because it's a small > > change. The way to hell is through a series of small > > steps. If using integers to express fixities is a bit of a > > hack, switching to rational numbers is a hack on top of a > > hack. > > Well, It's a _conceptually_ simple idea, one that doesn't make > understanding the language much harder. > > Also, it provides an infinite space for fixities. I think the problem > 'binds tighter than X but not as tight as Y', where X and Y are only > fixity integer apart is somewhat common, and this would fix it. It > would allow for extensibility into the future, where the operator > space will only become more dense, and maintaining a complete order > with only 10 integers to play will become more and more difficult. > Allowing an infinite amount of operators to come between any two > operators sounds like a solid design decision to me. > > -- > -David House, dmhouse@gmail.com > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From hjgtuyl at chello.nl Tue Nov 7 17:26:40 2006 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Tue Nov 7 17:26:13 2006 Subject: [Haskell-cafe] Announcement: new maintainers forr wxHaskell In-Reply-To: <1133622689.20061107165224@gmail.com> References: <1133622689.20061107165224@gmail.com> Message-ID: Hello all, I suggest gui@haskell.org, the GUI task force mailing list; nothing is going on there at the moment, but it seems the most appropriate list. On Tue, 07 Nov 2006 14:52:24 +0100, Bulat Ziganshin wrote: > Hello Jeremy, > > Friday, October 27, 2006, 7:12:44 PM, you wrote: > >> I'd ask the community to send patches via this list. > > i suggest to use libraries@haskell.org for this purpose. at least > other libs maintained there > -- Met vriendelijke groet, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ -- Using Opera's revolutionary e-mail client: https://secure.bmtmicro.com/opera/buy-opera.html?AID=789433 From lennart at augustsson.net Tue Nov 7 17:32:39 2006 From: lennart at augustsson.net (Lennart Augustsson) Date: Tue Nov 7 17:32:24 2006 Subject: [Haskell-cafe] Re: Fractional/negative fixity? In-Reply-To: References: Message-ID: <7C54402C-E9EF-4B68-BA09-71AF9134D992@augustsson.net> On Nov 7, 2006, at 11:47 , apfelmus@quantentunnel.de wrote: > Henning Thielemann wrote: >> On Tue, 7 Nov 2006, Simon Marlow wrote: >> >>> I'd support fractional and negative fixity. It's a simple change to >>> make, but we also have to adopt >>> >>> http://hackage.haskell.org/cgi-bin/haskell-prime/trac.cgi/wiki/ >>> FixityResolution >>> >>> I've added the proposal to the end of that page. In fact, the page >>> already mentioned that we could generalise fixity levels, but it >>> didn't >>> mention fractional or negative values being allowed. >> >> Maybe that page could also mention earlier proposals and the >> solutions >> without precedence numbers. I prefer the non-numeric approach with >> rules >> like "(<) binds more tightly than (&&)", because it says what is >> intended >> and it allows to make things unrelated that are unrelated, e.g. infix >> operators from different libraries. Consequently a precedence >> relation to >> general infix operators like ($) and (.) had be defined in each >> library. > > I think that computable real fixity levels are useful, too. A further > step to complex numbers is not advised because those cannot be > ordered. But ordering of the computable reals is not computable. So it could cause the compiler to loop during parsing. :) -- Lennart From westondan at imageworks.com Tue Nov 7 19:20:52 2006 From: westondan at imageworks.com (Dan Weston) Date: Tue Nov 7 19:20:29 2006 Subject: [Haskell-cafe] Re: Fractional/negative fixity? In-Reply-To: <454BF5D3.60705@imageworks.com> References: <002001c6efa4$c8372510$1cf52950@osmet> <22523.213.84.177.94.1161000771.squirrel@webmail.xs4all.nl> <5ce89fb50610160731ja2de0d8l23903e914dcfe8da@mail.gmail.com> <984680831.20061016195414@gmail.com> <454BF5D3.60705@imageworks.com> Message-ID: <455122E4.5010503@imageworks.com> I started this e-mail thread on HaskellCafe instead of HaskellPrime because it was minimal, backwards-compatible, valid Haskell 98 (or very nearly so) and could go (now) into GHC if someone saw fit to put it in. > If you think C++ is not overly complicated, just what is a protected > abstract virtual base pure virtual private destructor, and when was > the last time you needed one? > -- Tom Cargil, C++ Journal The above was not a proposal for Haskell'. > Proposers of new [C++] features should be required to donate a kidney. > That would - Jim [Waldo] pointed out - make people think hard before > proposing, and even people without any sense would propose at most two > extensions. > -- Bjarne Stroustrup, creator of C++ But at the risk of losing a kidney... Here's where I think Haskell 98 got it wrong: "A fixity declaration may appear anywhere that a type signature appears and, like a type signature, declares a property of a particular operator." Like a type signature? A type signature has semantic value, fixity does not. In principle, neither does the name that a lambda abstraction is bound to in top-level definitions, but we are stuck with linkers that know about names. They don't know about fixity. Operator precedence is a purely syntactic device for people (like me) who hate parentheses. Its "scope" is essentially local to the attention span of a human being (i.e. a single module). A preprocessor can parethesize code to eliminate the need for fixity. I hate chasing other modules looking up operator fixity and would rather just specify it myself: What if we could remap fixity on import: -- (MyModule.???) fixity is 4, exported as its default... import MyModule((???)) -- But in this module I prefer 5... -- This fixity is *not* exported! infix 5 ??? Modules that import this module get the default fixity from the source. Summary: fixity at definition is exported, fixity on import is locally remapped but not reexported. > Better is the enemy of the good > -- Voltaire Simple, powerful, minimal. Any takers? Dan Dan Weston wrote: > Here's an idea that (I think) is useful and backwards compatible: > fractional and negative fixity. > > There have been 3 separate times where I've wanted an operator just > above 0 ($) but less than 1 (>>= or >>>), or else just below 0 (like a > superlow $$) > > infix 0.5 ??? > infix -1 $$ > > The only change would be internal to compiler, wouldn't it? Since fixity > is just syntactic sugar, there should be no semantic difficulties. > > Dan > From ariep at xs4all.nl Tue Nov 7 19:48:37 2006 From: ariep at xs4all.nl (Arie Peterson) Date: Tue Nov 7 19:48:09 2006 Subject: [Haskell-cafe] Re: Fractional/negative fixity? In-Reply-To: References: <23077.1162923030@calligramme.charmers> Message-ID: <5110.213.84.177.94.1162946917.squirrel@webmail.xs4all.nl> David House wrote: > Also, it provides an infinite space for fixities. I think the problem > 'binds tighter than X but not as tight as Y', where X and Y are only > fixity integer apart is somewhat common, and this would fix it. It > would allow for extensibility into the future, where the operator > space will only become more dense, and maintaining a complete order > with only 10 integers to play will become more and more difficult. > Allowing an infinite amount of operators to come between any two > operators sounds like a solid design decision to me. For me, the most important objection to specifying precedence by an embedding into some total order -- be it the integers or the rationals -- is that it forces you to make a global decision, and that threatens modularity. Consider the following scenario: - Two unrelated pieces of code each define an operator (`A` resp. `B`). The writers choose their precedences with due regard to relations to basic operators and maybe other relevant ones, but *not considering their mutual relation*. The last writer may not know about the code of the first one, or did not bother to consider the possibility of mixing it with his code (it is unreasonable to expect a writer to consider the relation to every other existing operator). - At some point, `A` and `B` meet; maybe they are part of two unrelated libraries and a programmer uses them both, or maybe `A` was defined by a programmer who just found out that there exists this wonderful library exporting `B`. - Now, if she is lucky, the relative precedence of `A` and `B` just happens to be nice and logical. If she is unlucky and the relative precedence is really annoying, the precedence of at least one of `A` and `B` will have to change to fix this. However, if you change the precedence of `B`, say, (which currently is "written in stone forever", as Nicolas Frisby put it,) and `B` is an operator of any significance, then you have to send out an announcement to everyone who uses `B`, telling them that its precedence has changed, so they should check if that breaks any of their code. If it does, they may have to change the precedence of other operators, propagating a horrible cascade of realignment. That's a whole yotta words for a small bikeshed, but I think this scenario is actually not far-fetched at all. Specifying precedence 'lazily', by a partial order, does not suffer from this problem, because it only requires you to make local decisions. Kind regards, Arie -- Mr. Pelican Shit may be Willy. ^ /e\ --- From claus.reinke at talk21.com Tue Nov 7 21:09:59 2006 From: claus.reinke at talk21.com (Claus Reinke) Date: Tue Nov 7 21:09:36 2006 Subject: [Haskell-cafe] Re: Fractional/negative fixity? References: <7C54402C-E9EF-4B68-BA09-71AF9134D992@augustsson.net> Message-ID: <018601c702da$ff533e00$2d5e8351@cr3lt> by all means, lets have warm fuzzy precedence declarations infix(nearly right) (exp (2*i*pi) + 1) :-) infix(mostly left) (((\x->cos x + i*(sin x)) (2*pi)) + 1) (-: who says that all the fun has to start in the type system?-) we would probably need to refer to hyperreals, in order to introduce infinitesimal differences between real precedence levels? oh, and let us not forget the early Basic's contribution to language design: renum (who could ever to without it!-) ah well, to justify the use of bandwith (and because you should never let your design decisions be influenced by someone making fun of any of the suggestions): - absolute numbers for operator precedence are a hack that reminds me strongly of my Basic times: I used steps of 100 starting with 1000 for line numbers, I used renum to make space for additions or to clean up (was that refactoring?-), but I was still happy to leave all that nonsense behind! - googling for "operator precedence relative" suggests that some parser generators already use something other that absolute preferences - prolog has more precedence levels, as well as simple declarations for pre- and postfix operators (fx, xf) sorry, I just couldn't resist any more;-) claus -- unsagePerformIO: some things are just not wise to do From bulat.ziganshin at gmail.com Wed Nov 8 03:02:37 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Wed Nov 8 03:04:34 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: <5ce89fb50611071425x29a913e2pd400e42a8a86454a@mail.gmail.com> References: <002001c6efa4$c8372510$1cf52950@osmet> <22523.213.84.177.94.1161000771.squirrel@webmail.xs4all.nl> <5ce89fb50610160731ja2de0d8l23903e914dcfe8da@mail.gmail.com> <984680831.20061016195414@gmail.com> <454BF5D3.60705@imageworks.com> <706781845.20061104095938@gmail.com> <1809061187.20061106200717@gmail.com> <5ce89fb50611071425x29a913e2pd400e42a8a86454a@mail.gmail.com> Message-ID: <306908383.20061108110237@gmail.com> Hello Nicolas, Wednesday, November 8, 2006, 1:25:23 AM, you wrote: > prec ?? < $ > over-specification). You want ?? to bind more tightly than does $; > that's exactly what this approach would let you specify. and how then compiler will guess that is relational priority of this operator comparing to '$!' ? :) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From jo at durchholz.org Tue Nov 7 18:08:00 2006 From: jo at durchholz.org (Joachim Durchholz) Date: Wed Nov 8 03:24:37 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: References: <23077.1162923030@calligramme.charmers> Message-ID: David House schrieb: > Also, it provides an infinite space for fixities. I think the problem > 'binds tighter than X but not as tight as Y', where X and Y are only > fixity integer apart is somewhat common, and this would fix it. It > would allow for extensibility into the future, where the operator > space will only become more dense, and maintaining a complete order > with only 10 integers to play will become more and more difficult. > Allowing an infinite amount of operators to come between any two > operators sounds like a solid design decision to me. Yes, but allowing simply to specify some ordering relationship to existing operators is an even more solid one. Fractional fixities are overspecification, and this can hurt in scenarios like this one: Developer A creates an operator with this fixity declaration: infixl 6.25 +* Developer B has this: infixl 6.75 *+ (They don't use 6.5 because each has another operator at 6.5 already.) Now when some developer mixes +* and *+ in the same expression, the compiler will automatically assign a relative priority for the two operators, even though it's not at all clear whether the two operators have any relative precedence - it would be far preferable if the compiler simply declared nonpriority and emitted an error, forcing the programmer to clearly state what priorities he had in mind when writing down the expression. I know the above example is a bit far-fetched. And it's not a really important issue anyway. Regards, Jo From simonmar at microsoft.com Wed Nov 8 04:55:39 2006 From: simonmar at microsoft.com (Simon Marlow) Date: Wed Nov 8 04:55:21 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: <5ce89fb50611071425i4568d3d7y7167fe1ec7ca9f23@mail.gmail.com> Message-ID: Nicolas Frisby wrote: > Let's remember that if something is broke, it's only _right_ to _fix_ > it. I patiently waited for someone else to make that pun. > > Understanding the language won't be much harder, but understanding > fixity declarations will become a task. Consider: > > infixl -1.7521 -- what and why? > > As the operator space becomes more dense, negative and fractional > fixities are going to become more obfuscated. The negative and > fractional fixities will satisfy a number purposes well, but they will > also be abused and lead to confusion. > > This smells like a wart growing on a wart to me. All these are valid points. However, given that we can't completely redesign, implement and test a new fixity system in time for Haskell', it makes sense to make a simple change that unambiguously improves the current system, and is no more difficult to implement (in fact, I bet it adds zero lines of code to the compiler). Cheers, Simon > Nick > > On 11/7/06, David House wrote: >> On 07/11/06, Jon Fairbairn wrote: >>> I must say though, that I don't like the reasoning that we >>> can put in fractional fixities because it's a small >>> change. The way to hell is through a series of small >>> steps. If using integers to express fixities is a bit of a >>> hack, switching to rational numbers is a hack on top of a >>> hack. >> >> Well, It's a _conceptually_ simple idea, one that doesn't make >> understanding the language much harder. >> >> Also, it provides an infinite space for fixities. I think the problem >> 'binds tighter than X but not as tight as Y', where X and Y are only >> fixity integer apart is somewhat common, and this would fix it. It >> would allow for extensibility into the future, where the operator >> space will only become more dense, and maintaining a complete order >> with only 10 integers to play will become more and more difficult. >> Allowing an infinite amount of operators to come between any two >> operators sounds like a solid design decision to me. >> >> -- >> -David House, dmhouse@gmail.com >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe From pnsteiner at gmail.com Wed Nov 8 05:48:24 2006 From: pnsteiner at gmail.com (Peter Steiner) Date: Wed Nov 8 05:47:55 2006 Subject: [Haskell-cafe] StateT and modify Message-ID: <879b20e90611080248t25a89419k1d73a0f92fc9248b@mail.gmail.com> hi haskellers, i have a basic question regarding StateT encapsulating IO and the modify function. my scenario is similar to the following simple code snippet: > import Control.Monad.State > > type MyState = StateT Int IO > > test = evalStateT foo 0 > > foo = do > modify $ (+) 1 > get i would like to be able to debug what's happening inside the modifier function. that's why i want to be able to use a modifier that's in the IO monad, like in the following, obviously defunct snippet: > test = evalStateT bar 0 > > bar = do > modify $ myAdd 1 > get > > myAdd :: Int -> Int -> IO Int > myAdd x y = do > putStr "in myAdd\n" > return $ x + y this fails because (myAdd :: Int -> Int -> IO Int) does not match the required modify argument type (Int -> Int -> Int) for MyState. Couldn't match expected type `Int' against inferred type `IO Int' In the second argument of `($)', namely `myAdd 1' In the expression: modify $ (myAdd 1) In a 'do' expression: modify $ (myAdd 1) is it possible to 'lift' StateT modify into the inner monad (IO in my case)? regards, peter. From cgibbard at gmail.com Wed Nov 8 06:01:09 2006 From: cgibbard at gmail.com (Cale Gibbard) Date: Wed Nov 8 06:00:41 2006 Subject: [Haskell-cafe] StateT and modify In-Reply-To: <879b20e90611080248t25a89419k1d73a0f92fc9248b@mail.gmail.com> References: <879b20e90611080248t25a89419k1d73a0f92fc9248b@mail.gmail.com> Message-ID: <89ca3d1f0611080301t770eff14u92b353e45360cc87@mail.gmail.com> bar = do x <- get y <- lift $ myAdd 1 x put y return y If you want, you can write something which captures this idiom: liftModify c = do x <- get y <- lift (c x) put y and then use that like: bar = do liftModify (myAdd 1) get On 08/11/06, Peter Steiner wrote: > hi haskellers, > > i have a basic question regarding StateT encapsulating IO and the > modify function. > > my scenario is similar to the following simple code snippet: > > > import Control.Monad.State > > > > type MyState = StateT Int IO > > > > test = evalStateT foo 0 > > > > foo = do > > modify $ (+) 1 > > get > > i would like to be able to debug what's happening inside the modifier > function. that's why i want to be able to use a modifier that's in the > IO monad, like in the following, obviously defunct snippet: > > > test = evalStateT bar 0 > > > > bar = do > > modify $ myAdd 1 > > get > > > > myAdd :: Int -> Int -> IO Int > > myAdd x y = do > > putStr "in myAdd\n" > > return $ x + y > > this fails because (myAdd :: Int -> Int -> IO Int) does not match the > required modify argument type (Int -> Int -> Int) for MyState. > > Couldn't match expected type `Int' against inferred type `IO Int' > In the second argument of `($)', namely `myAdd 1' > In the expression: modify $ (myAdd 1) > In a 'do' expression: modify $ (myAdd 1) > > is it possible to 'lift' StateT modify into the inner monad (IO in my case)? > > regards, > peter. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From rd at slavepianos.org Wed Nov 8 06:17:53 2006 From: rd at slavepianos.org (Rohan Drape) Date: Wed Nov 8 06:17:24 2006 Subject: [Haskell-cafe] Re: Livecoding music in Haskell Message-ID: On Tue Nov 7 16:32:11 EST 2006, alex wrote: > The way I see it there are two big issues - the first is drift and the > second is latency. As hinted at when Alex's work was discussed last November: "OSC messages can be timestamped, and SuperCollider has a sample accurate scheduling queue, so language timing jitter can easily be worked around." http://www.haskell.org/pipermail/haskell-cafe/2005-November/012483.html Currently Sound.SC3 has a procedure 'at' that can be used for scheduling. This procedure doesn't really belong in Sound.SC3, and ought probably be taken out. Still, with the current darcs repository the following makes a ping every second, on the second, sample accurately, for half a minute. If you run the binary twice the pings will be twice the amplitude, no phase errors - fingers crossed. import Sound.SC3 import Control.Concurrent (forkIO) ping f a = out 0 (sinOsc AR f 0 * e) where c = EnvNum (-4.0) e = envGen KR 1 a 0 1 removeSynth (envPerc 0.1 0.6 1 [c,c]) latency = 0.01 bundle t m = OscB (t + latency) m pinger = do now <- utc at (fromIntegral (ceiling now)) f where f t = do fd <- sc send' fd (bundle t [s_new "ping" (-1) AddToTail 1]) putStrLn "Sending ping" return 1.0 main = do fd <- sc putStrLn "Sending Ping Instrument" sync' fd (d_recv' "ping" (ping 440 0.1)) putStrLn "Resetting scsynth" reset fd putStrLn "Starting schedule thread" forkIO pinger putStrLn "Delaying main thread" pause 30 putStrLn "End of delay, exiting" The above assumes that scsynth is running on the local host at the standard port, 57110, and that the GHC runtime scheduler jitter plus localhost network latency for this task is below 0.01 seconds, which is true on my otherwise idle X31 at 600MHz - this is not at all bad, I am impressed in any case - setting latency to zero gives reports from scsynth of: > late 0.008414722 > late 0.006882722 > late 0.005348722 > late 0.003815721 > late 0.002282721 > late 0.000748721 Tacked on below, for interested readers, are some notes on a related scheme scheduler, the notes were written in response to a related query about scheme & scsynth some time ago. The relation to the haskell above is pretty straightforward, the haskell 'at' discards the notion of a mutable schedule - with cheap concurrency such a thing is of arguable use - and the haskell 'at' ought to allow the event generator to return Nothing to stop scheduling. Regards, Rohan ++ Simple sample accurate scheduling from runtimes with moderate scheduling jitter is straightforward using SuperCollider. One simple model is: (at Q TIME (lambda (t f) (EVENT t) (f DELTA))) at = the scheduler interface Q = a value TIME = a UTC timestamp t = the scheduled UTC time (ie. TIME or subsequent delta), regardless of when the procedure actually runs f = a rescheduling function that in effect does (at Q (+ t DELTA) *SELF*) EVENT = the action, usually constructs an osc bundle and sends it to scsynth DELTA = the delta time to reschedule to, to not re-schedule just don't call f The EVENT sends a bundle to scsynth and adds latency as required so that the scheduled bundle arrives ahead of the timestamp, the actual sample-accurate scheduling is handled by a queue at scsynth. The example below will schedule a ping at each whole second, and the scheduling will be sample accurate so long as the scheme runtime jitter is less than 0.1 seconds minus the network latency to get a UDP packet to the scsynth address. Here (utc) gets the current time, (-> s p) sends an OSC packet p to the server s, (/s_new ...) makes a /s_new OSC message, & (bundle t m) makes an OSC packet converting the UTC timestamp to NTP. (define s (open-udp* "127.0.0.1" 57110)) (define Q (make-schedule*)) (define L 0.1) (define (ship t m) (-> s (bundle (+ t L) m))) (at Q (ceiling (utc)) (lambda (t f) (ship t (/s_new "ping" -1 1 1)) (f 1.0))) Obviously to schedule just one ping in five seconds time: (at Q (+ (utc) 5) (lambda (t _) (ship t (/s_new "ping" -1 1 1)))) From bulat.ziganshin at gmail.com Wed Nov 8 06:17:42 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Wed Nov 8 06:18:51 2006 Subject: [Haskell-cafe] StateT and modify In-Reply-To: <879b20e90611080248t25a89419k1d73a0f92fc9248b@mail.gmail.com> References: <879b20e90611080248t25a89419k1d73a0f92fc9248b@mail.gmail.com> Message-ID: <1234639588.20061108141742@gmail.com> Hello Peter, Wednesday, November 8, 2006, 1:48:24 PM, you wrote: > i would like to be able to debug what's happening inside the modifier > function. that's why i want to be able to use a modifier that's in the > IO monad for debugging there is 'trace' function which don't needs IO monad -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From lemming at henning-thielemann.de Wed Nov 8 06:19:59 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Wed Nov 8 06:22:16 2006 Subject: [Haskell-cafe] Fun with Num instances of functions Message-ID: Some people have argued, that Num instances of (->) would be nice in order to add functions nicely, say for f, g :: Num a => b -> a you would define (f+g) x = f x + g x With an according definition of fromInteger fromInteger = const numeric literals would also denote constant functions. This allows f+2 == \x -> f x + 2 . Even nicer, the mathematically established notation of omitting the multiplication dot 2(x+y) :: Integer will now be parsed by a Haskell compiler to the most obvious meaning 2 :: Integer ! :-) From rd at slavepianos.org Wed Nov 8 06:35:45 2006 From: rd at slavepianos.org (Rohan Drape) Date: Wed Nov 8 06:35:18 2006 Subject: [Haskell-cafe] Re: Livecoding music in Haskell Message-ID: On Tue Nov 7 16:32:11 EST 2006, alex wrote: > Latency I deal with by calculating everything a second or so ahead of > time, and timestamping my OSC packets with times in the future. Then on > the other side I have some scheduling stuff to trigger sounds at the > right moment, for example in SuperCollider's sclang: A second seems excessive? Working directly with ghc <-> scsynth latencies of ~ 0.075 do not seem to be and issue with even relatively heavy scheduling loads. > response = { > arg time, responder, message; > if (message[1] == 'on', > { > SystemClock.sched(time - Date.getDate.rawSeconds, > {Synth("noisebox", > [\lgain, message[2] / 100, > \rgain, message[3] / 100, > \ts, message[4] / 100, > \browndel, message[5] / 100, > \filter, message[6], > \envtype, message[7] > ] > ); nil; > }; > ); > }); > }; > o = OSCresponder(nil, '/noise', response); > o.add; Even sclang, remarkable as it is, will need to be sending time-stamped bundles for reliable sample-accurate timing? Even to avoid perceptible jitter under high load? Regards, Rohan From simonmarhaskell at gmail.com Wed Nov 8 07:36:02 2006 From: simonmarhaskell at gmail.com (Simon Marlow) Date: Wed Nov 8 07:35:40 2006 Subject: [Haskell-cafe] Re: ANN: System.FilePath 0.10 In-Reply-To: <404396ef0611080403m403dd175w1fd420d4c3cb06bd@mail.gmail.com> References: <404396ef0611080403m403dd175w1fd420d4c3cb06bd@mail.gmail.com> Message-ID: <4551CF32.6040103@microsoft.com> Neil Mitchell wrote: > ANNOUNCEMENT: > > I am hereby announcing System.FilePath 0.10, which hopefully is pretty > close to final now. This library manipulates FilePath's correctly on > both Posix and Windows. > > http://www-users.cs.york.ac.uk/~ndm/projects/libraries.php#filepath > > (Includes a darcs repo, a .tar.gz, haddock documentation etc) > > In this version I have made reasonably large changes: > > * Lots of functions gone (temporary file handling, canonicalization, > drive manipulation, directory creation, directory enumeration) - > pretty much down to only pure (non-IO methods) left. > > * 3 new methods (asFile, isFile, asDirectory - look up the docs for > their meanings, but they are pretty small) > > * Renamed functions to follow the scheme replace/take/drop instead of > set/get/drop - as suggested by Simon Marlow (since set/get implies > state operations in Haskell) Looks good! I have a few small further suggestions: - remove addFileName: it does the same thing as combine, or rather the difference is subtle and not mentioned in the docs. It's subsumed by combine, anyway. - remove isDirectory. I think its presence is confusing, e.g forall x. isDirectory (takeDirectory x) == False! Also it's not really correct; "/bin/" means something subtly different to "/bin" on Unix systems. Similarly isFile, asFile, asDirectory could be removed, I think. - Use the terminology "search path" consistently for anything to do with $PATH. i.e. fileSeparator => searchPathSeparator, isFileSeparator => isSearchPathSeparator, splitFiles => splitSearchPath also, move fileSeparator, isFileSeparator into the $PATH section in the docs (or change "basic functions" to "separator predicates"). - remove splitPath: splitDirectories is enough. I'd rename it to splitPathComponents, though. - shortPath => relativeToCurrentDirectory shortPathWith => makeRelativePath Cheers, Simon From bertram.felgenhauer at googlemail.com Wed Nov 8 07:39:06 2006 From: bertram.felgenhauer at googlemail.com (Bertram Felgenhauer) Date: Wed Nov 8 07:38:39 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: References: <706781845.20061104095938@gmail.com> Message-ID: <20061108123906.GA3953@zombie.inf.tu-dresden.de> Simon Marlow wrote: > http://hackage.haskell.org/cgi-bin/haskell-prime/trac.cgi/wiki/FixityResolution What's the fate of unary minus under that proposal? In the Haskell report its syntax is part of the lexp^6 production. This production makes it possible to write (-1+) instead of (subtract 1), although that's not really advisable because Hugs fails to parse (-1+). Interestingly, hugs allows (+ -1) instead, but I believe that's wrong. Bertram From alex at slab.org Wed Nov 8 07:57:36 2006 From: alex at slab.org (alex) Date: Wed Nov 8 07:57:07 2006 Subject: [Haskell-cafe] Re: Livecoding music in Haskell In-Reply-To: References: Message-ID: <1162990657.5350.21.camel@localhost> On Wed, 2006-11-08 at 22:35 +1100, Rohan Drape wrote: > A second seems excessive? Working directly with ghc <-> scsynth > latencies of ~ 0.075 do not seem to be and issue with even relatively > heavy scheduling loads. Yes you're right, although with my current timescales of livecoding, an extra second of latency doesn't make much difference. I'm not dealing with individual notes, but longer term structures. > Even sclang, remarkable as it is, will need to be sending time-stamped > bundles for reliable sample-accurate timing? Even to avoid > perceptible jitter under high load? Ah, good point - so I am falsely conflating sclang with scsynth? I am (still) a beginner sclang programmer as well as a beginner haskell programmer. In any case I intend to move to your hsc library soon, so thanks for the scheduling details in your other mail. Thanks also to those pointing me at Haskore on #haskell, so far it looks a lot like my existing representation of music, only much better. alex From alex at slab.org Wed Nov 8 08:07:52 2006 From: alex at slab.org (alex) Date: Wed Nov 8 08:07:21 2006 Subject: [Haskell-cafe] Re: Livecoding music in Haskell In-Reply-To: <1162990657.5350.21.camel@localhost> References: <1162990657.5350.21.camel@localhost> Message-ID: <1162991272.5350.32.camel@localhost> I meant to add that of course once you have sample-accurate timing, the next job is to mess things up again with some model of expression in performance (unless you're making german techno). For example I intend to apply some of these rules within Haskore as part of my project: http://www.speech.kth.se/music/performance/performance_rules.html The alternative to this is to stick with a flawed system and decide that it's expressive :) Relatedly, one thing I dislike about supercollider (or at least the way I'm using it right now) is that its failure mode is to crash rather than produce inaccurate output. To me part of the enjoyment of an instrument is what happens when you go beyond its normal limits. alex From pnsteiner at gmail.com Wed Nov 8 08:23:39 2006 From: pnsteiner at gmail.com (Peter Steiner) Date: Wed Nov 8 08:23:09 2006 Subject: [Haskell-cafe] StateT and modify In-Reply-To: <1234639588.20061108141742@gmail.com> References: <879b20e90611080248t25a89419k1d73a0f92fc9248b@mail.gmail.com> <1234639588.20061108141742@gmail.com> Message-ID: <879b20e90611080523p16ae861djaaad479005b83eb5@mail.gmail.com> On 11/8/06, Bulat Ziganshin wrote: > Hello Peter, > > Wednesday, November 8, 2006, 1:48:24 PM, you wrote: > > > i would like to be able to debug what's happening inside the modifier > > function. that's why i want to be able to use a modifier that's in the > > IO monad > > for debugging there is 'trace' function which don't needs IO monad thanks. i am aware of trace, but the potentially messed up execution order makes it very hard for me to get useful information out of the resulting trace. besides, IO will scale to more elaborate logging mechanisms later on... -- peter From haskell at henning-thielemann.de Wed Nov 8 08:36:22 2006 From: haskell at henning-thielemann.de (Henning Thielemann) Date: Wed Nov 8 08:36:25 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: <306908383.20061108110237@gmail.com> References: <002001c6efa4$c8372510$1cf52950@osmet> <22523.213.84.177.94.1161000771.squirrel@webmail.xs4all.nl> <5ce89fb50610160731ja2de0d8l23903e914dcfe8da@mail.gmail.com> <984680831.20061016195414@gmail.com> <454BF5D3.60705@imageworks.com> <706781845.20061104095938@gmail.com> <1809061187.20061106200717@gmail.com> <5ce89fb50611071425x29a913e2pd400e42a8a86454a@mail.gmail.com> <306908383.20061108110237@gmail.com> Message-ID: On Wed, 8 Nov 2006, Bulat Ziganshin wrote: > Hello Nicolas, > > Wednesday, November 8, 2006, 1:25:23 AM, you wrote: > > > prec ?? < $ > > over-specification). You want ?? to bind more tightly than does $; > > that's exactly what this approach would let you specify. > > and how then compiler will guess that is relational priority of this > operator comparing to '$!' ? :) (What might the smiley mean?) It could not guess it, and this is good! However, if in the Prelude it is defined, that ($) and ($!) have the same precedence, then the compiler could derive automatically that prec ?? < $!. From haskell at henning-thielemann.de Wed Nov 8 08:37:10 2006 From: haskell at henning-thielemann.de (Henning Thielemann) Date: Wed Nov 8 08:38:08 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: References: <23077.1162923030@calligramme.charmers> Message-ID: On Tue, 7 Nov 2006, David House wrote: > On 07/11/06, Jon Fairbairn wrote: > > I must say though, that I don't like the reasoning that we > > can put in fractional fixities because it's a small > > change. The way to hell is through a series of small > > steps. If using integers to express fixities is a bit of a > > hack, switching to rational numbers is a hack on top of a > > hack. > > Well, It's a _conceptually_ simple idea, one that doesn't make > understanding the language much harder. > > Also, it provides an infinite space for fixities. I think the problem > 'binds tighter than X but not as tight as Y', where X and Y are only > fixity integer apart is somewhat common, and this would fix it. In school we learnt "dot operations (multiplication, division) bind more tightly than dash operations (addition, subtraction)". I imagine we would have learnt "dot operations have precedence 7, dash operations have precedence 6". :-) From ndmitchell at gmail.com Wed Nov 8 09:08:32 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Nov 8 09:08:03 2006 Subject: [Haskell-cafe] Re: ANN: System.FilePath 0.10 In-Reply-To: <4551CF32.6040103@microsoft.com> References: <404396ef0611080403m403dd175w1fd420d4c3cb06bd@mail.gmail.com> <4551CF32.6040103@microsoft.com> Message-ID: <404396ef0611080608n2102deffr813f99900bdd01c8@mail.gmail.com> Hi Simon, > - remove addFileName: it does the same thing as combine, or rather > the difference is subtle and not mentioned in the docs. It's > subsumed by combine, anyway. The difference is subtle: System.FilePath> addFileName "test" "c:\\" "test\\c:\\" System.FilePath> combine "test" "c:\\" "c:\\" I'm coming around to the idea that addFileName is subtly different and entirely wrong, so yes, removing it seems fine. > - remove isDirectory. I think its presence is confusing, e.g > forall x. isDirectory (takeDirectory x) == False! > Also it's not really correct; "/bin/" means something subtly different to > "/bin" on Unix systems. Similarly isFile, asFile, asDirectory could > be removed, I think. The reason I have them is because there are some circumstances where they are required in some programs. For example the behaviour of "cp" is different depending on whether the item is given as a file or a directory - hence these methods abstract away testing for that difference. I will think about this. > - Use the terminology "search path" consistently for anything to > do with $PATH. i.e. > fileSeparator => searchPathSeparator, > isFileSeparator => isSearchPathSeparator, > splitFiles => splitSearchPath Ok, makes sense - I viewed it as a "collection of files", of which one instance is a search path. I guess in reality this will be the only "collection of files" so the name should reflect this. > also, move fileSeparator, isFileSeparator into the $PATH section > in the docs (or change "basic functions" to "separator predicates"). Renaming basic functions to separator predicates is easy enough. I'd rather leave these predicates in a separate section so people are less inclined to use them - they are the building blocks that the higher level functionality is based on. > - remove splitPath: splitDirectories is enough. I'd rename it > to splitPathComponents, though. splitPath has the nice property that you can join it back together again with the right file separators: (\\ == \ since its escaped in a string) System.FilePath> joinPath $ splitPath "test/file\\more" "test/file\\more" System.FilePath> joinPath $ splitDirectories "test/file\\more" "test\\file\\more" This allows the developer to keep the FilePath more as the user specified. Maybe its not worth it though. > - shortPath => relativeToCurrentDirectory > shortPathWith => makeRelativePath I like them having the same prefix, it makes them more related in some way. makeRelative and makeRelativeToCurrentDirectory seem more natural to me. However, I'm not overly fussed. I've updated the way the versions of the FilePath library are organised, so once everyone's finished discussing this I'll try and get a 0.11 out in the next week that addresses these issues. Thanks Neil From robdockins at fastmail.fm Wed Nov 8 09:38:12 2006 From: robdockins at fastmail.fm (Robert Dockins) Date: Wed Nov 8 09:34:39 2006 Subject: [Haskell-cafe] Re: Fractional/negative fixity? In-Reply-To: References: <7C54402C-E9EF-4B68-BA09-71AF9134D992@augustsson.net> Message-ID: <83B31B10-6718-4ED1-879D-227ED9C1C625@fastmail.fm> On Nov 8, 2006, at 3:58 AM, apfelmus@quantentunnel.de wrote: > Lennart Augustsson wrote: >> >> On Nov 7, 2006, at 11:47 , >> apfelmus@quantentunnel.de wrote: >> >>> Henning Thielemann wrote: >>>> On Tue, 7 Nov 2006, Simon Marlow wrote: >>>> >>>>> I'd support fractional and negative fixity. It's a simple >>>>> change to >>>>> make, but we also have to adopt >> [...] >>> >>> I think that computable real fixity levels are useful, too. A >>> further >>> step to complex numbers is not advised because those cannot be >>> ordered. >> >> But ordering of the computable reals is not computable. So it could >> cause the compiler to loop during parsing. :) > > Actually, that's one of the use cases ;) A turing-complete type-checker isn't enough! Our work is not complete until the parser is a universal machine as well! > Regards, > apfelmus Rob Dockins Speak softly and drive a Sherman tank. Laugh hard; it's a long way to the bank. -- TMBG From nad at cs.chalmers.se Wed Nov 8 09:45:48 2006 From: nad at cs.chalmers.se (Nils Anders Danielsson) Date: Wed Nov 8 09:45:19 2006 Subject: [Haskell-cafe] Re: Fractional/negative fixity? In-Reply-To: <5110.213.84.177.94.1162946917.squirrel@webmail.xs4all.nl> (Arie Peterson's message of "Wed, 8 Nov 2006 01:48:37 +0100 (CET)") References: <23077.1162923030@calligramme.charmers> <5110.213.84.177.94.1162946917.squirrel@webmail.xs4all.nl> Message-ID: On Wed, 08 Nov 2006, "Arie Peterson" wrote: > Specifying precedence 'lazily', by a partial order, does not suffer from > this problem, because it only requires you to make local decisions. Assuming we only want to be able to make local decisions. Let's say that we want == to bind less tightly than +, as it is now. Let's also say that Eq and Num are defined in two different _unrelated_ modules (this of course implies that Eq is not a superclass of Num). Where and how would we specify the relation between these two operators? -- /NAD From dokondr at gmail.com Wed Nov 8 09:52:22 2006 From: dokondr at gmail.com (Dmitri O.Kondratiev) Date: Wed Nov 8 09:51:52 2006 Subject: [Haskell-cafe] Newbie Q: composeMaybe :: (a -> Maybe b) -> (b -> Maybe c) -> (a -> Maybe c) Message-ID: <53396d9e0611080652o144c1f64k9de381a16e2c455f@mail.gmail.com> I am trying to solve a problem from "The Craft of Functional Programming" book: 14.38 ... define the function: data Maybe a = Nothing | Just a composeMaybe :: (a -> Maybe b) -> (b -> Maybe c) -> (a -> Maybe c) using functions: squashMaybe :: Maybe (Maybe a) -> Maybe a squashMaybe (Just (Just x)) = Just x squashMaybe _ = Nothing mapMaybe :: (a -> b) -> Maybe a -> Maybe b mapMaybe f Nothing = Nothing mapMaybe f (Just x) = Just (f x) As a first step to the solution I defined auxilary function: f1 f g x = mapMaybe f (g x) GHCi gives the following type for this function: f1 :: (a -> b) -> (t -> Maybe a) -> t -> Maybe b ^^^ Q: I don't quite understand this signature. I would expect this instead (by mapMaybe definition): f1 :: (a -> b) -> (t -> Maybe a) -> Maybe b >From where does the second 't' come from? What are the arguments and what f1 returns in this case? From lemming at henning-thielemann.de Wed Nov 8 10:04:05 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Wed Nov 8 10:04:40 2006 Subject: [Haskell-cafe] Re: Fractional/negative fixity? In-Reply-To: References: <23077.1162923030@calligramme.charmers> <5110.213.84.177.94.1162946917.squirrel@webmail.xs4all.nl> Message-ID: On Wed, 8 Nov 2006, Nils Anders Danielsson wrote: > On Wed, 08 Nov 2006, "Arie Peterson" wrote: > > > Specifying precedence 'lazily', by a partial order, does not suffer from > > this problem, because it only requires you to make local decisions. > > Assuming we only want to be able to make local decisions. > > Let's say that we want == to bind less tightly than +, as it is now. > Let's also say that Eq and Num are defined in two different > _unrelated_ modules (this of course implies that Eq is not a > superclass of Num). Where and how would we specify the relation > between these two operators? Depends on what we consider being more special. * Does addition require comparison? Not in Haskell. However, the recursive implementation of addition for Peano numbers need equality check. * Provide all additive types comparison? No. * Does comparison require addition? No. So, these concepts seem to be unrelated at first. If the Prelude would be splitted into modules, where (==) and (+) are separated, and no module imports the other one, then we need a third module, which states the relation between (==) and (+). If I have missed something, and say (+)'s module imports (==)'s one, then (+)'s module should define the relation. From nicolas.frisby at gmail.com Wed Nov 8 10:38:43 2006 From: nicolas.frisby at gmail.com (Nicolas Frisby) Date: Wed Nov 8 10:38:13 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: <306908383.20061108110237@gmail.com> References: <002001c6efa4$c8372510$1cf52950@osmet> <22523.213.84.177.94.1161000771.squirrel@webmail.xs4all.nl> <5ce89fb50610160731ja2de0d8l23903e914dcfe8da@mail.gmail.com> <984680831.20061016195414@gmail.com> <454BF5D3.60705@imageworks.com> <706781845.20061104095938@gmail.com> <1809061187.20061106200717@gmail.com> <5ce89fb50611071425x29a913e2pd400e42a8a86454a@mail.gmail.com> <306908383.20061108110237@gmail.com> Message-ID: <5ce89fb50611080738v742dc6ax8a890786c76c582d@mail.gmail.com> Well let's see. First I'll assume that prec $! = $ is how $! was specified. Thus we know both ?? < $ and $! = $. Let's derive the relation between ?? and $! ?? < $ => ?? < $! {$ = $!} So I think that is pretty straight-forward. ":)" is a parse error... ;) This does bring up the interesting case where we want an operator between $ and $! (or some less offensive pair of operators with equal precedence). This, like Danielsson's later post, is a case that deserves some thought. If we handle such cases in a consistent way, I think we might have something quite useful. On the positive side, when I want $! to behave like $ (or perhaps more appropriately =*= to behave like ==) then I don't have to lookup the numeric precedence of $ (or ==). I can just say prec $! = $ and be done with it. There's no arbitrary middle man. Nick On 11/8/06, Bulat Ziganshin wrote: > Hello Nicolas, > > Wednesday, November 8, 2006, 1:25:23 AM, you wrote: > > > prec ?? < $ > > over-specification). You want ?? to bind more tightly than does $; > > that's exactly what this approach would let you specify. > > and how then compiler will guess that is relational priority of this > operator comparing to '$!' ? :) > > > -- > Best regards, > Bulat mailto:Bulat.Ziganshin@gmail.com > > From jon.fairbairn at cl.cam.ac.uk Wed Nov 8 11:11:02 2006 From: jon.fairbairn at cl.cam.ac.uk (=?utf-8?b?SsOzbiBGYWlyYmFpcm4=?=) Date: Wed Nov 8 11:11:38 2006 Subject: [Haskell-cafe] Re: Fractional/negative fixity? References: <5ce89fb50611071425i4568d3d7y7167fe1ec7ca9f23@mail.gmail.com> Message-ID: Simon Marlow writes: > Nicolas Frisby wrote: > > Let's remember that if something is broke, it's only _right_ to _fix_ > > it. I patiently waited for someone else to make that pun. > > > > Understanding the language won't be much harder, but understanding > > fixity declarations will become a task. Consider: > > > > infixl -1.7521 -- what and why? > > > > As the operator space becomes more dense, negative and fractional > > fixities are going to become more obfuscated. The negative and > > fractional fixities will satisfy a number purposes well, but they will > > also be abused and lead to confusion. > > > > This smells like a wart growing on a wart to me. > > All these are valid points. However, given that we can't > completely redesign, implement and test a new fixity > system in time for Haskell', ...the correct thing to do is to leave it alone, rather than make a change that addresses only one of the problems. > it makes sense to make a simple change that unambiguously > improves the current system, I dispute that. It does make it possible to introduce a new operator between two others, but on its own, that strikes me as as likely to be a new problem as an improvement because of the difficulty of remembering numeric precedences. It's bad enough with the present number, let alone a countable infinity of them. The biggest flaw in the present system (and something I wanted to address in my original proposal way back when) is that there is no way to state that there is /no/ precedence relationship between two operators. It would be far better to have the compiler give an error message saying that an expression needs some parentheses than have it choose the wrong parse. The next smaller flaw is that numeric precedences are a poor match for the way we think. I can easily remember that (*) binds more tightly than (+), or that (+) beats (:) (though the latter is slightly less obviously correct), but I don't remember the numbers so when I want to define something new that has a similar precedence to (*) (some new kind of multiplication), I have to look it up, which is tedious. Wanting to insert an operator between two others comes lower in importance even than that, because in many cases giving it the same precedence as something and appropriate associativity gets you most of the way there. It bites because you can't say you want an error if you use it next to something else without parentheses. Let me throw out a couple of possibilities differing only in syntax (one of my fears is that if we get fractional fixities the other problems will be forgotten, so a real improvement will never be discussed). I don't expect either of them to go into Haskell', but putting them forward might encourage further discussion and discourage introduction of something "temporary" that will stay with us forever. Syntax 1, based on Phil Wadler's improvement of my old proposal. The precedence relation is a preorder. infix {ops_1; ops_2; ...; ops_n} (where each ops is a collection of operators optionally annotated with L or R) would mean that each operator in ops_i binds more tightly than all the operators in ops_j for j>i. (and we require ops_i `intersect` ops_j = empty_set for i/=j) Layout rule applies for {;...}. An op can be a varsym or a backquoted varid. It says nothing about the relationship between the those operators and operators not mentioned, except by virtue of transitivity. So infix R ^ L * / L + - would replicate the current relationships between those arithmetic operators. An additional declaration infix + R : says that (+) binds more tightly than (:) and by transitivity, so do (^ * and /). The associativity label obviously has to be the same for all occurrences of an operator in scope, so omitting it just says that it's specified elsewhere. infix * R @+ @- + says that (@+) and (@-) fall between (*) and (-), and that (a @+ b @- c) parses as (a @+ (b@-c)) but infix * R @@ says that (a * b @@ c @@ d) parses as ((a*b) @@ (c@@d)) but leaves (a + b @@ c) undefined (a compile time error) unless another declaration specifies it elsewhere. And infix R @@ @@@ says nothing about the relationship between @@ or @@@ and other operators, but indicates that they associate to the right individually and together. The alternative syntax is exemplified thus: infix L + - (L * / (R ^)) The precedence increases the more deeply you go into the parentheses. Arguably this is more suggestive and avoids the possibility of reading precedences as increasing down the page (danger of endianism argument cropping up there!), but may be harder to read. With both syntaxes there's no reason to reserve L and R, since the context disambiguates. For exports (imports) you pass the graph of the relation with the unexported (unimported) operators omitted. > and is no more difficult to implement (in fact, I bet it > adds zero lines of code to the compiler). If ease of implementation had been a criterion, we'd never have had Haskell at all! I don't think the above suggestion would be hard to implement -- for someone who knows the internals of a compiler, anyway. J?n From max.vasin at gmail.com Wed Nov 8 11:39:57 2006 From: max.vasin at gmail.com (Max Vasin) Date: Wed Nov 8 11:44:19 2006 Subject: [Haskell-cafe] Re: StateT and modify References: <879b20e90611080248t25a89419k1d73a0f92fc9248b@mail.gmail.com> <1234639588.20061108141742@gmail.com> <879b20e90611080523p16ae861djaaad479005b83eb5@mail.gmail.com> Message-ID: <87hcx93naa.fsf@smtp.gmail.com> >>>>> "Peter" == Peter Steiner writes: Peter> On 11/8/06, Bulat Ziganshin wrote: >> Hello Peter, >> >> Wednesday, November 8, 2006, 1:48:24 PM, you wrote: >> >> > i would like to be able to debug what's happening inside the >> modifier > function. that's why i want to be able to use a >> modifier that's in the > IO monad >> >> for debugging there is 'trace' function which don't needs IO >> monad Peter> thanks. i am aware of trace, but the potentially messed up Peter> execution order makes it very hard for me to get useful Peter> information out of the resulting trace. besides, IO will Peter> scale to more elaborate logging mechanisms later on... If all you want from IO is logging why not just use MonadWriter? -- WBR, Max Vasin. From nad at cs.chalmers.se Wed Nov 8 11:56:13 2006 From: nad at cs.chalmers.se (Nils Anders Danielsson) Date: Wed Nov 8 11:55:44 2006 Subject: [Haskell-cafe] Re: Fractional/negative fixity? In-Reply-To: (Henning Thielemann's message of "Wed, 08 Nov 2006 16:04:05 +0100 (CET)") References: <23077.1162923030@calligramme.charmers> <5110.213.84.177.94.1162946917.squirrel@webmail.xs4all.nl> Message-ID: On Wed, 08 Nov 2006, Henning Thielemann wrote: > If the Prelude would be splitted into modules, where (==) and (+) > are separated, and no module imports the other one, then we need a > third module, which states the relation between (==) and (+). Yes, presumably. However, currently a fixity declaration for an operator can only be given in the module where the operator is defined. In this hypothetical new system, how would one import/export fixity declarations? Should they be named, or should they be treated like instance declarations are treated today? I've thought about this before, since I like the idea of not totally ordering operator precedences, but I haven't found an elegant and light-weight solution to this problem. -- /NAD From nicolas.frisby at gmail.com Wed Nov 8 12:11:09 2006 From: nicolas.frisby at gmail.com (Nicolas Frisby) Date: Wed Nov 8 12:10:42 2006 Subject: [Haskell-cafe] Re: StateT and modify In-Reply-To: <87hcx93naa.fsf@smtp.gmail.com> References: <879b20e90611080248t25a89419k1d73a0f92fc9248b@mail.gmail.com> <1234639588.20061108141742@gmail.com> <879b20e90611080523p16ae861djaaad479005b83eb5@mail.gmail.com> <87hcx93naa.fsf@smtp.gmail.com> Message-ID: <5ce89fb50611080911m6b1ca2b2sc9c71434b65afe5e@mail.gmail.com> Regardless of what monad is transformed by StateT, I think the OP's issue remains. modify below is straight from Gill's source at http://darcs.haskell.org/packages/ modify :: (MonadState s m) => (s -> s) -> m () modify f = do s <- get put (f s) we could add modifyM :: (MonadState s m) => (s -> m s) -> m () modifyM f = do s <- get s' <- f s put s' which I think you could use... modifyM is just a bit more flexible than Cale's liftModify, I think. On 11/8/06, Max Vasin wrote: > >>>>> "Peter" == Peter Steiner writes: > > Peter> On 11/8/06, Bulat Ziganshin wrote: > >> Hello Peter, > >> > >> Wednesday, November 8, 2006, 1:48:24 PM, you wrote: > >> > >> > i would like to be able to debug what's happening inside the > >> modifier > function. that's why i want to be able to use a > >> modifier that's in the > IO monad > >> > >> for debugging there is 'trace' function which don't needs IO > >> monad > > Peter> thanks. i am aware of trace, but the potentially messed up > Peter> execution order makes it very hard for me to get useful > Peter> information out of the resulting trace. besides, IO will > Peter> scale to more elaborate logging mechanisms later on... > > If all you want from IO is logging why not just use MonadWriter? > > -- > WBR, > Max Vasin. > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From deejay at g615.co.uk Wed Nov 8 12:17:35 2006 From: deejay at g615.co.uk (DeeJay-G615) Date: Wed Nov 8 12:17:07 2006 Subject: [Haskell-cafe] Newbie Q: composeMaybe :: (a -> Maybe b) -> (b -> Maybe c) -> (a -> Maybe c) In-Reply-To: <53396d9e0611080652o144c1f64k9de381a16e2c455f@mail.gmail.com> References: <53396d9e0611080652o144c1f64k9de381a16e2c455f@mail.gmail.com> Message-ID: <4552112F.9020801@g615.co.uk> Hi Dmitri, your f1 function has 3 arguments, f, g and x. you pass f as the first argument to mapMaybe, so it naturally must have type (a -> b). you pass the result of (g x) to the second argument of mapMaybe, so (g x) must have type Maybe a. This means g must have the type (t -> Maybe a) where t is the type of x. This gives f1 :: (a -> b) -> (t -> Maybe a) -> t -> Maybe b you are going to be passing in something with type (c -> Maybe d) as the first argument to f1. (I used different type variables to reduce confusion) This constraint gives f1 the following type f1 :: (c -> Maybe d) -> (t -> Maybe c) -> t -> Maybe (Maybe d) substituting different type variable names gives f1 :: (b -> Maybe c) -> (a -> Maybe b) -> a -> Maybe (Maybe c) So you are very close to finishing... :) Hope this helps. DeeJay Dmitri O.Kondratiev wrote: > I am trying to solve a problem from "The Craft of Functional > Programming" book: > > 14.38 ... define the function: > data Maybe a = Nothing | Just a > composeMaybe :: (a -> Maybe b) -> (b -> Maybe c) -> (a -> Maybe c) > > using functions: > > squashMaybe :: Maybe (Maybe a) -> Maybe a > squashMaybe (Just (Just x)) = Just x > squashMaybe _ = Nothing > > mapMaybe :: (a -> b) -> Maybe a -> Maybe b > mapMaybe f Nothing = Nothing > mapMaybe f (Just x) = Just (f x) > > As a first step to the solution I defined auxilary function: > f1 f g x = mapMaybe f (g x) > > GHCi gives the following type for this function: > > f1 :: (a -> b) -> (t -> Maybe a) -> t -> Maybe b > ^^^ > Q: I don't quite understand this signature. I would expect this > instead (by mapMaybe definition): > f1 :: (a -> b) -> (t -> Maybe a) -> Maybe b > >> From where does the second 't' come from? What are the arguments and > > what f1 returns in this case? > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > From pnsteiner at gmail.com Wed Nov 8 15:05:04 2006 From: pnsteiner at gmail.com (Peter Steiner) Date: Wed Nov 8 15:04:41 2006 Subject: [Haskell-cafe] Re: StateT and modify In-Reply-To: <5ce89fb50611080911m6b1ca2b2sc9c71434b65afe5e@mail.gmail.com> References: <879b20e90611080248t25a89419k1d73a0f92fc9248b@mail.gmail.com> <1234639588.20061108141742@gmail.com> <879b20e90611080523p16ae861djaaad479005b83eb5@mail.gmail.com> <87hcx93naa.fsf@smtp.gmail.com> <5ce89fb50611080911m6b1ca2b2sc9c71434b65afe5e@mail.gmail.com> Message-ID: <879b20e90611081205i77d59c7eqafb7eb1aa44df994@mail.gmail.com> cale's solution worked fine for me (i forgot to cc this list in my response). i have troubles getting your modifyM to compile, and i do not really understand how it might without somehow lifting the function into the inner monad. > import Control.Monad.State > > type MyState = StateT Int IO > > test = evalStateT bar 0 > > modifyM :: (MonadState s m) => (s -> m s) -> m () > modifyM f = do > s <- get > s' <- f s > put s' > > bar :: MyState Int > bar = do > modifyM $ myAdd 1 > get > > myAdd :: Int -> Int -> IO Int > myAdd x y = do > putStr "in myAdd\n" > return $ x + y fails with: Couldn't match `StateT Int IO' against `IO' Expected type: StateT Int IO Inferred type: IO In a 'do' expression: modifyM $ (myAdd 1) In the definition of `bar': bar = do modifyM $ (myAdd 1) get and applying lift is not possible outside of modifyM. what am i doing wrong? regards, peter. On 11/8/06, Nicolas Frisby wrote: > Regardless of what monad is transformed by StateT, I think the OP's > issue remains. > > modify below is straight from Gill's source at > http://darcs.haskell.org/packages/ > > modify :: (MonadState s m) => (s -> s) -> m () > modify f = do > s <- get > put (f s) > > we could add > > modifyM :: (MonadState s m) => (s -> m s) -> m () > modifyM f = do > s <- get > s' <- f s > put s' > > which I think you could use... > > modifyM is just a bit more flexible than Cale's liftModify, I think. > > On 11/8/06, Max Vasin wrote: > > >>>>> "Peter" == Peter Steiner writes: > > > > Peter> On 11/8/06, Bulat Ziganshin wrote: > > >> Hello Peter, > > >> > > >> Wednesday, November 8, 2006, 1:48:24 PM, you wrote: > > >> > > >> > i would like to be able to debug what's happening inside the > > >> modifier > function. that's why i want to be able to use a > > >> modifier that's in the > IO monad > > >> > > >> for debugging there is 'trace' function which don't needs IO > > >> monad > > > > Peter> thanks. i am aware of trace, but the potentially messed up > > Peter> execution order makes it very hard for me to get useful > > Peter> information out of the resulting trace. besides, IO will > > Peter> scale to more elaborate logging mechanisms later on... > > > > If all you want from IO is logging why not just use MonadWriter? > > > > -- > > WBR, > > Max Vasin. > > > > _______________________________________________ > > 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 > From pnsteiner at gmail.com Wed Nov 8 15:30:49 2006 From: pnsteiner at gmail.com (Peter Steiner) Date: Wed Nov 8 15:30:20 2006 Subject: [Haskell-cafe] Re: StateT and modify In-Reply-To: <87hcx93naa.fsf@smtp.gmail.com> References: <879b20e90611080248t25a89419k1d73a0f92fc9248b@mail.gmail.com> <1234639588.20061108141742@gmail.com> <879b20e90611080523p16ae861djaaad479005b83eb5@mail.gmail.com> <87hcx93naa.fsf@smtp.gmail.com> Message-ID: <879b20e90611081230o3245a16rb2c93ca301c7b3d4@mail.gmail.com> On 11/8/06, Max Vasin wrote: > Peter> thanks. i am aware of trace, but the potentially messed up > Peter> execution order makes it very hard for me to get useful > Peter> information out of the resulting trace. besides, IO will > Peter> scale to more elaborate logging mechanisms later on... > > If all you want from IO is logging why not just use MonadWriter? good question. my initial idea, being lazy, was that IO provides IORefs which might prove useful later on, but then i guess that a cleanly composed monad will behave better in the long term anyways. i have to add that this is my first large haskell project and i do many design decisions on a trial'n'error basis - naturally with a strong tendency to the error side. ;-) -- peter From ashley at semantic.org Wed Nov 8 15:31:04 2006 From: ashley at semantic.org (Ashley Yakeley) Date: Wed Nov 8 15:31:05 2006 Subject: [Haskell-cafe] Re: ANN: System.FilePath 0.10 In-Reply-To: <404396ef0611080403m403dd175w1fd420d4c3cb06bd@mail.gmail.com> References: <404396ef0611080403m403dd175w1fd420d4c3cb06bd@mail.gmail.com> Message-ID: Neil Mitchell wrote: > I am hereby announcing System.FilePath 0.10, which hopefully is pretty > close to final now. This library manipulates FilePath's correctly on > both Posix and Windows. How do I manipulate a Windows file path on a POSIX machine (something relating to Samba, for instance)? -- Ashley Yakeley From ndmitchell at gmail.com Wed Nov 8 16:48:14 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Nov 8 16:47:44 2006 Subject: [Haskell-cafe] Re: ANN: System.FilePath 0.10 In-Reply-To: References: <404396ef0611080403m403dd175w1fd420d4c3cb06bd@mail.gmail.com> Message-ID: <404396ef0611081348l26170528kfc2a03efe17b6a28@mail.gmail.com> Hi Ashley, > How do I manipulate a Windows file path on a POSIX machine (something > relating to Samba, for instance)? import System.FilePath.Windows This will give you windows FilePath handling regardless of your operating system. (in the same way System.FilePath.Posix will give you Linux style filepaths, and System.FilePath will give you the appropriate type based on your OS) Thanks Neil From nicolas.frisby at gmail.com Wed Nov 8 17:46:33 2006 From: nicolas.frisby at gmail.com (Nicolas Frisby) Date: Wed Nov 8 17:46:01 2006 Subject: [Haskell-cafe] Re: StateT and modify In-Reply-To: <879b20e90611081205i77d59c7eqafb7eb1aa44df994@mail.gmail.com> References: <879b20e90611080248t25a89419k1d73a0f92fc9248b@mail.gmail.com> <1234639588.20061108141742@gmail.com> <879b20e90611080523p16ae861djaaad479005b83eb5@mail.gmail.com> <87hcx93naa.fsf@smtp.gmail.com> <5ce89fb50611080911m6b1ca2b2sc9c71434b65afe5e@mail.gmail.com> <879b20e90611081205i77d59c7eqafb7eb1aa44df994@mail.gmail.com> Message-ID: <5ce89fb50611081446s4d2ad5fbsc8609856e34806a@mail.gmail.com> Applying lift outside of modifyM is not a problem. It can seem a bit tricky with the function types around. Try > modifyM $ lift . myAdd 1 instead of > modifyM $ myAdd 1 Cale's should certainly work fine and lead to more concise code for what you're after. Just thought I'd mention this in case your needs change. Good luck, Nick On 11/8/06, Peter Steiner wrote: > cale's solution worked fine for me (i forgot to cc this list in my response). > > i have troubles getting your modifyM to compile, and i do not really > understand how it might without somehow lifting the function into the > inner monad. > > > import Control.Monad.State > > > > type MyState = StateT Int IO > > > > test = evalStateT bar 0 > > > > modifyM :: (MonadState s m) => (s -> m s) -> m () > > modifyM f = do > > s <- get > > s' <- f s > > put s' > > > > bar :: MyState Int > > bar = do > > modifyM $ myAdd 1 > > get > > > > myAdd :: Int -> Int -> IO Int > > myAdd x y = do > > putStr "in myAdd\n" > > return $ x + y > > fails with: > > Couldn't match `StateT Int IO' against `IO' > Expected type: StateT Int IO > Inferred type: IO > In a 'do' expression: modifyM $ (myAdd 1) > In the definition of `bar': > bar = do > modifyM $ (myAdd 1) > get > > and applying lift is not possible outside of modifyM. > what am i doing wrong? > > regards, > peter. > > On 11/8/06, Nicolas Frisby wrote: > > Regardless of what monad is transformed by StateT, I think the OP's > > issue remains. > > > > modify below is straight from Gill's source at > > http://darcs.haskell.org/packages/ > > > > modify :: (MonadState s m) => (s -> s) -> m () > > modify f = do > > s <- get > > put (f s) > > > > we could add > > > > modifyM :: (MonadState s m) => (s -> m s) -> m () > > modifyM f = do > > s <- get > > s' <- f s > > put s' > > > > which I think you could use... > > > > modifyM is just a bit more flexible than Cale's liftModify, I think. > > > > On 11/8/06, Max Vasin wrote: > > > >>>>> "Peter" == Peter Steiner writes: > > > > > > Peter> On 11/8/06, Bulat Ziganshin wrote: > > > >> Hello Peter, > > > >> > > > >> Wednesday, November 8, 2006, 1:48:24 PM, you wrote: > > > >> > > > >> > i would like to be able to debug what's happening inside the > > > >> modifier > function. that's why i want to be able to use a > > > >> modifier that's in the > IO monad > > > >> > > > >> for debugging there is 'trace' function which don't needs IO > > > >> monad > > > > > > Peter> thanks. i am aware of trace, but the potentially messed up > > > Peter> execution order makes it very hard for me to get useful > > > Peter> information out of the resulting trace. besides, IO will > > > Peter> scale to more elaborate logging mechanisms later on... > > > > > > If all you want from IO is logging why not just use MonadWriter? > > > > > > -- > > > WBR, > > > Max Vasin. > > > > > > _______________________________________________ > > > 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 mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From nicolas.frisby at gmail.com Wed Nov 8 18:51:32 2006 From: nicolas.frisby at gmail.com (Nicolas Frisby) Date: Wed Nov 8 18:50:59 2006 Subject: [Haskell-cafe] Re: Re: aggressiveness of functional dependencies In-Reply-To: <5ce89fb50611071039q621d67aam42888e810fb100b1@mail.gmail.com> References: <5ce89fb50611061409k18c7a446p559987bde70eaf10@mail.gmail.com> <5ce89fb50611071039q621d67aam42888e810fb100b1@mail.gmail.com> Message-ID: <5ce89fb50611081551k4849f945h2a61c8bde2e13c99@mail.gmail.com> Last post until a response I promise! Another demonstration: bar () = runIdentity . flip runStateT 0 $ return 'c' Inferred signature: bar :: (Monad (StateT s Identity), Num s) => () -> (Char, s) Why not? bar :: Num s => () -> (Char, s) I am not coming up with an s that could prevent (StateT s Identity) from being a monad. Is there one? Nick On 11/7/06, Nicolas Frisby wrote: > Having thought longer about it, it seems to be an issue with > functional dependencies and overlapping instances. > > Perhaps, because an overlapping instance may be defined in some other > module which would trump the Iso instance for Either, the type > inference mechanism cannot commit to the instance presented in my > code. It's being conservative. > > My confusion stems from the notion of functional dependency. Given the > functional dependencies of Iso, there is exactly one type b for any > type a such that Iso a b (and also vice versa). Thus it would seem > that c for Iso (Either a b) c is always uniquely determined because of > the instance from my code. > > However, because a more specific overlapping instance could always be > added, this isn't the case. That more specific instances could specify > something like Iso (Either Char Char) (Either Int Int). The functional > dependency check does not recognize that this violates the > dependencies introduced by the more general instance's context. I > think this is because said dependencies (the inductives: Iso f f' and > Iso g g') are introduced iff the more general instance fires. > > Is the type inference conservative because the possibility of a new > overlapping instance always looms? If so, is this a good thing or a > bad thing? Is this the "murky water" that Strongly Typed Heterogeneous > Collections mentions? > > Sorry to double post. Thanks again, > Nick > > > > On 11/6/06, Nicolas Frisby wrote: > > I have a question about functional dependencies, instance contexts, > > and type inference. A specific example and question is in the attached > > code. > > > > In brief the question is: to what degree does type inference use the > > functional dependencies of an instance's class and context? I believe > > I am wishing it were more aggressive than it is. Please note that I > > have not enabled overlapping instances. > > > > Any suggestions regarding how to get the inferred type of |rite_t1| to > > be the one I anticipated would be much appreciated. Of course, I would > > also appreciate explanations of why I shouldn't anticipate it! > > > > The rest of this message is a copy of the attached code. > > > > Thanks, > > Nick > > > > > > > > I'm using GHC 6.6, but I see the same inferred types with 6.4.1. > > > > > {-# OPTIONS -fglasgow-exts #-} > > > {-# OPTIONS -fallow-undecidable-instances #-} -- for the coverage condition > > > > > > module FunDepEx where > > > > > > A plain ole' isomorphism class. > > > > > class Iso a b | a -> b, b -> a where > > > rite :: a -> b > > > left :: b -> a > > > > > > Isomorphism lifts through the sum bifunctor. > > > > > bifmap_either f g = either (Left . f) (Right . g) > > > > > > instance ( Iso f f', Iso g g' > > > ) => Iso (Either f g) (Either f' g') where > > > rite = bifmap_either rite rite > > > left = bifmap_either left left > > > > > > Some types to play around with. > > > > > newtype MyChar = MyChar Char deriving (Show, Eq) > > > > > > instance Iso MyChar Char where > > > rite (MyChar c) = c > > > left c = MyChar c > > > instance Iso Char MyChar where > > > rite c = MyChar c > > > left (MyChar c) = c > > > > > > My type inference confusion follows; the unit arguments are just to > > suppress the monomorphism restriction. > > > > > t1 :: Either Char a > > > t1 = Left 'c' > > > > > > rite_t1 () = rite t1 > > > > The inferred type for rite_t1 is > > rite_t1 :: (Iso (Either Char a) (Either f' g')) => () -> Either f' g' > > > > Why isn't the inferred type of rite_t1 the same as the ascribed type > > of rite_t1'? > > > > > rite_t1' :: Iso b b' => () -> Either MyChar b' > > > rite_t1' () = rite t1 > > > > > > > From ajb at spamcop.net Wed Nov 8 21:01:54 2006 From: ajb at spamcop.net (ajb@spamcop.net) Date: Wed Nov 8 21:01:23 2006 Subject: [Haskell-cafe] How to design default implementations of type class methods? In-Reply-To: References: Message-ID: <20061108210154.kjm0e80o4ss0wosc@webmail.spamcop.net> G'day all. Quoting Henning Thielemann : > I like to hear some opinions about how to implement class method defaults. In this case, don't. Use instance defaults instead. class (Eq a) => Ring a where (*),(+),(-) :: a -> Integer zero, one :: a negate :: a -> a negate = (zero -) isZero :: a -> Bool isZero = (==zero) class (Ring a) => RingWithNorm a where nu :: a -> Integer class (RingWithNorm a) => EuclideanDomain a where divMod :: a -> a -> (a,a) class (RingWithNorm a) => GCD a where gcd :: a -> a -> a instance (EuclideanDomain a) => GCD a where gcd = {- Euclidean GCD algorithm; detail omitted -} Then if you have some other domain where GCD applies, you can create other instances as needed: class (RingWithNorm a) => SteinDomain a where smallestPrime :: a steinDecompose :: a -> Maybe (a,a) -- scale p q = p/q -- where nu q < nu smallestPrime scale :: a -> a -> a instance (SteinDomain a) => GCD a where gcd a b | nu a < nu b = gcd b a | a == b = a | otherwise = case (steinDecompose a, steinDecompose b) of (Nothing,_) -> b (_,Nothing) -> a (Just (pa,ca), Just (pb,cb)) | isZero ca && isZero cb -> smallestPrime * gcd pa pb | isZero cb -> gcd a pb | otherwise -> gcd (pa - scale (ca*pb) cb) b Cheers, Andrew Bromage From dons at cse.unsw.edu.au Wed Nov 8 22:47:51 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Wed Nov 8 22:47:21 2006 Subject: [Haskell-cafe] don't: a 'do' for comonads? Message-ID: <20061109034751.GD27808@cse.unsw.EDU.AU> As seen on #haskell, from an idea by Malcolm, 14:42 ?let top'n'tail = ("
"++) . (++"
") 14:42 lambdabot> Defined. 14:43 dons> > L.top'n'tail "foo me now" 14:43 lambdabot> "
foo me now
" 14:43 mauke> that reminds me, haskell needs don't 14:43 dons> yes! 14:44 pkhuong-> mm. the opposite of do, eh? do for comonads? :) So now a prize to the person who comes up with the best use for the identifier: don't :: ? -- Don From sebasgj at gmail.com Wed Nov 8 22:52:50 2006 From: sebasgj at gmail.com (Sebastian Gaviria) Date: Wed Nov 8 22:52:19 2006 Subject: [Haskell-cafe] Sistema de Ecuaciones NO lineales Message-ID: hola como estan!!!! Quiero preguntar quien puede resolver el sistemas de ecuaciones NO lineales de Newton y el codigo de Jacobi en Haskell me ayudarian mucho al poder implementar ese codigo por Favor es con urgencia tener estos codigos!! muchas gracias !!! -- "La sociedad debe juzgarse por su capacidad para hacer que la gente sea feliz."" SEBASTIAN GAVIRIA J. INGENIERIA SISTEMAS UNIVERSIDAD EAFIT -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061108/b84d25fa/attachment.htm From pnsteiner at gmail.com Thu Nov 9 04:34:56 2006 From: pnsteiner at gmail.com (Peter Steiner) Date: Thu Nov 9 04:34:25 2006 Subject: [Haskell-cafe] Re: StateT and modify In-Reply-To: <5ce89fb50611081446s4d2ad5fbsc8609856e34806a@mail.gmail.com> References: <879b20e90611080248t25a89419k1d73a0f92fc9248b@mail.gmail.com> <1234639588.20061108141742@gmail.com> <879b20e90611080523p16ae861djaaad479005b83eb5@mail.gmail.com> <87hcx93naa.fsf@smtp.gmail.com> <5ce89fb50611080911m6b1ca2b2sc9c71434b65afe5e@mail.gmail.com> <879b20e90611081205i77d59c7eqafb7eb1aa44df994@mail.gmail.com> <5ce89fb50611081446s4d2ad5fbsc8609856e34806a@mail.gmail.com> Message-ID: <879b20e90611090134n530cf37ydeff3d1f4ee70c57@mail.gmail.com> stupid me, that works and is more flexible than cale's solution. thanks! On 11/8/06, Nicolas Frisby wrote: > Applying lift outside of modifyM is not a problem. It can seem a bit > tricky with the function types around. Try > > > modifyM $ lift . myAdd 1 > > instead of > > > modifyM $ myAdd 1 > > Cale's should certainly work fine and lead to more concise code for > what you're after. Just thought I'd mention this in case your needs > change. > > Good luck, > Nick > > On 11/8/06, Peter Steiner wrote: > > cale's solution worked fine for me (i forgot to cc this list in my response). > > > > i have troubles getting your modifyM to compile, and i do not really > > understand how it might without somehow lifting the function into the > > inner monad. > > > > > import Control.Monad.State > > > > > > type MyState = StateT Int IO > > > > > > test = evalStateT bar 0 > > > > > > modifyM :: (MonadState s m) => (s -> m s) -> m () > > > modifyM f = do > > > s <- get > > > s' <- f s > > > put s' > > > > > > bar :: MyState Int > > > bar = do > > > modifyM $ myAdd 1 > > > get > > > > > > myAdd :: Int -> Int -> IO Int > > > myAdd x y = do > > > putStr "in myAdd\n" > > > return $ x + y > > > > fails with: > > > > Couldn't match `StateT Int IO' against `IO' > > Expected type: StateT Int IO > > Inferred type: IO > > In a 'do' expression: modifyM $ (myAdd 1) > > In the definition of `bar': > > bar = do > > modifyM $ (myAdd 1) > > get > > > > and applying lift is not possible outside of modifyM. > > what am i doing wrong? > > > > regards, > > peter. > > > > On 11/8/06, Nicolas Frisby wrote: > > > Regardless of what monad is transformed by StateT, I think the OP's > > > issue remains. > > > > > > modify below is straight from Gill's source at > > > http://darcs.haskell.org/packages/ > > > > > > modify :: (MonadState s m) => (s -> s) -> m () > > > modify f = do > > > s <- get > > > put (f s) > > > > > > we could add > > > > > > modifyM :: (MonadState s m) => (s -> m s) -> m () > > > modifyM f = do > > > s <- get > > > s' <- f s > > > put s' > > > > > > which I think you could use... > > > > > > modifyM is just a bit more flexible than Cale's liftModify, I think. > > > > > > On 11/8/06, Max Vasin wrote: > > > > >>>>> "Peter" == Peter Steiner writes: > > > > > > > > Peter> On 11/8/06, Bulat Ziganshin wrote: > > > > >> Hello Peter, > > > > >> > > > > >> Wednesday, November 8, 2006, 1:48:24 PM, you wrote: > > > > >> > > > > >> > i would like to be able to debug what's happening inside the > > > > >> modifier > function. that's why i want to be able to use a > > > > >> modifier that's in the > IO monad > > > > >> > > > > >> for debugging there is 'trace' function which don't needs IO > > > > >> monad > > > > > > > > Peter> thanks. i am aware of trace, but the potentially messed up > > > > Peter> execution order makes it very hard for me to get useful > > > > Peter> information out of the resulting trace. besides, IO will > > > > Peter> scale to more elaborate logging mechanisms later on... > > > > > > > > If all you want from IO is logging why not just use MonadWriter? > > > > > > > > -- > > > > WBR, > > > > Max Vasin. > > > > > > > > _______________________________________________ > > > > 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 mailing list > > Haskell-Cafe@haskell.org > > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > From dokondr at gmail.com Thu Nov 9 05:16:47 2006 From: dokondr at gmail.com (Dmitri O.Kondratiev) Date: Thu Nov 9 05:16:18 2006 Subject: [Haskell-cafe] Newbie Q: composeMaybe :: (a -> Maybe b) -> (b -> Maybe c) -> (a -> Maybe c) In-Reply-To: <4552112F.9020801@g615.co.uk> References: <53396d9e0611080652o144c1f64k9de381a16e2c455f@mail.gmail.com> <4552112F.9020801@g615.co.uk> Message-ID: <53396d9e0611090216q332cb05dv551a5c2b1628d1d4@mail.gmail.com> Hey DeeJay, Thanks for detailed answer, it really helps as it shows the way I need to follow! It also helped me to realize that my question why f1 f g x = mapMaybe f (g x) has this type: f1 :: (a -> b) -> (t -> Maybe a) -> t -> Maybe b and not that (type which I expected): f1 :: (a -> b) -> (t -> Maybe a) -> Maybe b was actually very stupid of me, as I just blindly missed that f1 *also has* a third parameter 'x' of type 't' !!! (Perhaps that happened to me because I was too much absorbed by the grave nature of the problem of composing functions returning 'Maybe' :) Thanks again! Dima On 11/8/06, DeeJay-G615 wrote: > Hi Dmitri, > > your f1 function has 3 arguments, f, g and x. > > you pass f as the first argument to mapMaybe, so it naturally must have type (a > -> b). > you pass the result of (g x) to the second argument of mapMaybe, so (g x) must > have type Maybe a. This means g must have the type (t -> Maybe a) where t is the > type of x. > > This gives f1 :: (a -> b) -> (t -> Maybe a) -> t -> Maybe b > > you are going to be passing in something with type (c -> Maybe d) as the first > argument to f1. (I used different type variables to reduce confusion) > > This constraint gives f1 the following type > > f1 :: (c -> Maybe d) -> (t -> Maybe c) -> t -> Maybe (Maybe d) > > substituting different type variable names gives > > f1 :: (b -> Maybe c) -> (a -> Maybe b) -> a -> Maybe (Maybe c) > > So you are very close to finishing... :) > Hope this helps. > > DeeJay > > Dmitri O.Kondratiev wrote: > > I am trying to solve a problem from "The Craft of Functional > > Programming" book: > > > > 14.38 ... define the function: > > data Maybe a = Nothing | Just a > > composeMaybe :: (a -> Maybe b) -> (b -> Maybe c) -> (a -> Maybe c) > > > > using functions: > > > > squashMaybe :: Maybe (Maybe a) -> Maybe a > > squashMaybe (Just (Just x)) = Just x > > squashMaybe _ = Nothing > > > > mapMaybe :: (a -> b) -> Maybe a -> Maybe b > > mapMaybe f Nothing = Nothing > > mapMaybe f (Just x) = Just (f x) > > > > As a first step to the solution I defined auxilary function: > > f1 f g x = mapMaybe f (g x) > > > > GHCi gives the following type for this function: > > > > f1 :: (a -> b) -> (t -> Maybe a) -> t -> Maybe b > > ^^^ > > Q: I don't quite understand this signature. I would expect this > > instead (by mapMaybe definition): > > f1 :: (a -> b) -> (t -> Maybe a) -> Maybe b > > > >> From where does the second 't' come from? What are the arguments and > > > > what f1 returns in this case? > > _______________________________________________ > > Haskell-Cafe mailing list > > Haskell-Cafe@haskell.org > > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > > > > > > -- Dmitri O Kondratiev, dokondr@gmail.com http://www.geocities.com/dkondr/ From mnislaih at gmail.com Thu Nov 9 05:45:37 2006 From: mnislaih at gmail.com (Pepe Iborra) Date: Thu Nov 9 05:45:15 2006 Subject: [Haskell-cafe] Sistema de Ecuaciones NO lineales In-Reply-To: References: Message-ID: hi Sebastian I think that it would be more appropriate to use english when you post to this particular list. On non linear equations or jacobi, I'm sorry but I cannot help you. But hopefully someone else in this list may be able to. Saludos. Cheers. pepe. On 09/11/2006, at 4:52, Sebastian Gaviria wrote: > hola como estan!!!! > > Quiero preguntar quien puede resolver el sistemas de ecuaciones NO > lineales de Newton y el codigo de Jacobi en Haskell > > me ayudarian mucho al poder implementar ese codigo > > por Favor es con urgencia tener estos codigos!! > > > muchas gracias !!! > > -- > > "La sociedad debe juzgarse por su capacidad para hacer que la gente > sea feliz."" > > SEBASTIAN GAVIRIA J. > INGENIERIA SISTEMAS > UNIVERSIDAD EAFIT > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From bonobo at bigpond.net.au Thu Nov 9 07:07:55 2006 From: bonobo at bigpond.net.au (Alexis) Date: Thu Nov 9 07:07:37 2006 Subject: [Haskell-cafe] Sistema de Ecuaciones NO lineales In-Reply-To: References: Message-ID: <200611092307.57891.bonobo@bigpond.net.au> On Thu, 9 Nov 2006 02:52 pm, Sebastian Gaviria wrote: > hola como estan!!!! > > Quiero preguntar quien puede resolver el sistemas de ecuaciones NO lineales > de Newton y el codigo de Jacobi en Haskell > > me ayudarian mucho al poder implementar ese codigo > > por Favor es con urgencia tener estos codigos!! > > > muchas gracias !!! Hola Sebastian, Lo siento por mi espa?ol mal. Si esa es una pregunta sobre tarea, por favor lee http://www.haskell.org/haskellwiki/Homework_help Y escribo Haskell como escribo espa?ol :-), as? lo siento, no puedo ayudar. :-( Alexis. From apfelmus at quantentunnel.de Thu Nov 9 08:27:48 2006 From: apfelmus at quantentunnel.de (apfelmus@quantentunnel.de) Date: Thu Nov 9 08:30:57 2006 Subject: [Haskell-cafe] Re: don't: a 'do' for comonads? In-Reply-To: <20061109034751.GD27808@cse.unsw.EDU.AU> References: <20061109034751.GD27808@cse.unsw.EDU.AU> Message-ID: Donald Bruce Stewart wrote: > As seen on #haskell, from an idea by Malcolm, > > 14:42 ?let top'n'tail = ("
"++) . (++"
") > 14:42 lambdabot> Defined. > 14:43 dons> > L.top'n'tail "foo me now" > 14:43 lambdabot> "
foo me now
" > 14:43 mauke> that reminds me, haskell needs don't > 14:43 dons> yes! > 14:44 pkhuong-> mm. the opposite of do, eh? do for comonads? :) > > So now a prize to the person who comes up with the best use for the > identifier: > > don't :: ? > > -- Don don't :: IO a -> a example :: () example = don't (do erase "/dev/hda") Regards, apfelmus From apfelmus at quantentunnel.de Thu Nov 9 08:44:41 2006 From: apfelmus at quantentunnel.de (apfelmus@quantentunnel.de) Date: Thu Nov 9 08:47:49 2006 Subject: [Haskell-cafe] Re: aggressiveness of functional dependencies In-Reply-To: <5ce89fb50611081551k4849f945h2a61c8bde2e13c99@mail.gmail.com> References: <5ce89fb50611061409k18c7a446p559987bde70eaf10@mail.gmail.com> <5ce89fb50611071039q621d67aam42888e810fb100b1@mail.gmail.com> <5ce89fb50611081551k4849f945h2a61c8bde2e13c99@mail.gmail.com> Message-ID: Nicolas Frisby wrote: >> > The inferred type for rite_t1 is >> > rite_t1 :: (Iso (Either Char a) (Either f' g')) => () -> Either f' g' >> > >> > Why isn't the inferred type of rite_t1 the same as the ascribed type >> > of rite_t1'? >> > >> > > rite_t1' :: Iso b b' => () -> Either MyChar b' >> > > rite_t1' () = rite t1 I think GHC does not know whether the given instance declaration instance ... => Iso (Either a b) (Either a' b') even applies to the special case of (a = Char) because it mostly ignores the preconditions on the left side of (=>). Hugs is much different. Maybe throwing away undecidable instances will drastically change things. > Last post until a response I promise! Another demonstration: > > bar () = runIdentity . flip runStateT 0 $ return 'c' > > Inferred signature: > bar :: (Monad (StateT s Identity), Num s) => () -> (Char, s) > > Why not? > bar :: Num s => () -> (Char, s) > > I am not coming up with an s that could prevent (StateT s Identity) > from being a monad. Is there one? The same might go on for this case. By not looking at the preconditions in the instance declaration instance Monad m => Monad (StateT s m) GHC concludes that (Monad (StateT s Identity)) might or might not hold depending on s. Regards, apfelmus From coeus at gmx.de Thu Nov 9 09:09:26 2006 From: coeus at gmx.de (Marc A. Ziegert) Date: Thu Nov 9 09:08:58 2006 Subject: [Haskell-cafe] don't: a 'do' for comonads? In-Reply-To: <20061109034751.GD27808@cse.unsw.EDU.AU> References: <20061109034751.GD27808@cse.unsw.EDU.AU> Message-ID: <200611091509.26531.coeus@gmx.de> don't :: a don't = error "D'oh!" - marc Am Donnerstag, 9. November 2006 04:47 schrieb Donald Bruce Stewart: > As seen on #haskell, from an idea by Malcolm, > > 14:42 ?let top'n'tail = ("
"++) . (++"
") > 14:42 lambdabot> Defined. > 14:43 dons> > L.top'n'tail "foo me now" > 14:43 lambdabot> "
foo me now
" > 14:43 mauke> that reminds me, haskell needs don't > 14:43 dons> yes! > 14:44 pkhuong-> mm. the opposite of do, eh? do for comonads? :) > > So now a prize to the person who comes up with the best use for the > identifier: > > don't :: ? > > -- Don > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > From ithika at gmail.com Thu Nov 9 10:37:57 2006 From: ithika at gmail.com (Dougal Stanton) Date: Thu Nov 9 10:36:49 2006 Subject: [Haskell-cafe] Lazy data from pipe using MissingH module Message-ID: <20061109153757.GB18621@glowfish> Newbie here working on a little program for fetching podcasts. I've been using the MissingH.Cmd module in concert with curl to download the RSS feeds like this: > fetchFeed :: Subscription -> IO (Either Error [Episode]) > fetchFeed sub = do > (pid, feed) <- pipeFrom "curl" (curlOpts ++ > ["--url", (slocation sub)]) > let eps = parseEpisodes (stitle sub) feed > forceSuccess pid > return eps According to the API docs I have to forceSuccess pid *after* I use the data. Will this construct do that, or does the compiler have free reign to move the line beginning 'let ...' wherever it feels? It seems to work occasionally for me but then just hangs, so I thought this might be the problem. Cheers, D. -- Dougal Stanton Word attachments considered harmful. From magnus at therning.org Thu Nov 9 10:38:09 2006 From: magnus at therning.org (Magnus Therning) Date: Thu Nov 9 10:47:12 2006 Subject: [Haskell-cafe] string to date? Message-ID: <20061109153809.GB4371@die.therning.org> I've been staring my eyes out trying to find a function that converts a string into a ClockTime or CalendarTime. Basically something like C's strptime(3). I can't seem to find anything like it in System.Time, there are function that convert _to_ a string, but nothing that converts _from_ a string it seems. Where should I look? /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus Software is not manufactured, it is something you write and publish. Keep Europe free from software patents, we do not want censorship by patent law on written works. Finagle's Sixth Law: Don't believe in miracles -- rely on them. From ithika at gmail.com Thu Nov 9 10:58:08 2006 From: ithika at gmail.com (Dougal Stanton) Date: Thu Nov 9 10:56:50 2006 Subject: [Haskell-cafe] string to date? In-Reply-To: <20061109153809.GB4371@die.therning.org> References: <20061109153809.GB4371@die.therning.org> Message-ID: <20061109155808.GC18621@glowfish> Quoth Magnus Therning, nevermore, > I've been staring my eyes out trying to find a function that converts a > string into a ClockTime or CalendarTime. Basically something like C's > strptime(3). I can't seem to find anything like it in System.Time, > there are function that convert _to_ a string, but nothing that converts > _from_ a string it seems. Where should I look? The MissingH.Time.ParseDate [1] module might be what you want. There's also one from Bjorn Bringert [2]. I haven't used either though, so I can't recommend anything between them. Cheers, D. [1]: [2]: From lemming at henning-thielemann.de Thu Nov 9 11:31:47 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Thu Nov 9 11:33:08 2006 Subject: [Haskell-cafe] Fractional/negative fixity? In-Reply-To: References: <23077.1162923030@calligramme.charmers> <5110.213.84.177.94.1162946917.squirrel@webmail.xs4all.nl> Message-ID: On Wed, 8 Nov 2006, Nils Anders Danielsson wrote: > On Wed, 08 Nov 2006, Henning Thielemann wrote: > > > If the Prelude would be splitted into modules, where (==) and (+) > > are separated, and no module imports the other one, then we need a > > third module, which states the relation between (==) and (+). > > Yes, presumably. However, currently a fixity declaration for an > operator can only be given in the module where the operator is > defined. In this hypothetical new system, how would one import/export > fixity declarations? Should they be named, or should they be treated > like instance declarations are treated today? Good question. Today fixity can only be declared per symbol. Thus it is natural to allow it only in the scope, where the symbol is defined. If fixity definitions consists of relations, then there are multiple symbols involved per relation. Is it sensible to restrict the definition to a module where one of the involved symbols is defined? Will people define non-exported dummy symbols in order to define fixities somewhere else? Maybe making fixity declarations like type class instance declarations is good. Is it good that instance declarations are anonymous, at all? There can be instance clashes, say if several people feel that Prelude misses Num instances for Strings, Boolean instances for Int and so on. I can't hide them, if I find them more dangerous than helpful. Similar problems apply to fixities. Maybe explicit fixity import or redeclaration, as proposed recently http://www.haskell.org/pipermail/haskell-cafe/2006-November/019364.html is a good idea. From Malcolm.Wallace at cs.york.ac.uk Thu Nov 9 11:57:20 2006 From: Malcolm.Wallace at cs.york.ac.uk (Malcolm Wallace) Date: Thu Nov 9 11:59:40 2006 Subject: [Haskell-cafe] string to date? In-Reply-To: <20061109153809.GB4371@die.therning.org> References: <20061109153809.GB4371@die.therning.org> Message-ID: <20061109165720.3083602e.Malcolm.Wallace@cs.york.ac.uk> Magnus Therning wrote: > I've been staring my eyes out trying to find a function that converts > a string into a ClockTime or CalendarTime. Basically something like > C's strptime(3). I can't seem to find anything like it in > System.Time, there are function that convert _to_ a string, but > nothing that converts _from_ a string it seems. Where should I look? Not quite what you want, but: "read"? (opposite of "show") Regards, Malcolm From benjamin.franksen at bessy.de Thu Nov 9 13:12:49 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Thu Nov 9 13:12:58 2006 Subject: [Haskell-cafe] Re: Re[2]: Fractional/negative fixity? References: <002001c6efa4$c8372510$1cf52950@osmet> <22523.213.84.177.94.1161000771.squirrel@webmail.xs4all.nl> <5ce89fb50610160731ja2de0d8l23903e914dcfe8da@mail.gmail.com> <984680831.20061016195414@gmail.com> <454BF5D3.60705@imageworks.com> <706781845.20061104095938@gmail.com> <1809061187.20061106200717@gmail.com> <5ce89fb50611071425x29a913e2pd400e42a8a86454a@mail.gmail.com> Message-ID: Nicolas Frisby wrote: > I don't see how it's too complex. Isn't > > infixl ?? > prec ?? < $ > (??) = whenOperator > > exactly what you want to say? Yes. I'd add that the system should (of course) take the transitive closure over all explicitly stated precedence relations. That really cuts down the number of cases one needs to specify. For instance, we'll want the Prelude operators to retain their relative precedences, so Prelude will contain (using a slightly changed syntax): prec ($ $! seq) < (>> >>= =<<) < (||) < (&&) < (== /= < <= >= >) < (:) prec (:) < (+ -) < (* / quot rem div mod) < (^ ^^ **) < (.) (Syntax summary: * ops with equal precedence are grouped by parentheses which are mandatory even if they contain only a single operator * precedence relations may use '<' or '>' between equality groups * no commas between operators are necessary if they are seperated by whitespace * backticks for operators with function names can be left out) Fixity would have to be declared separately as (using 'infixl' or 'infixr'; or whatever). Whenever we would currently declare an operator as having precedence N, we'd now declare it to have precedence equal to one or more operators from the corresponding precedence group, e.g. prec (<+> +) or, if you like prec (<+> + -) However prec (<+> + *) would be an error because (*) and (+) have previously been declared to have different precedence. Compilers can support a special command line switch "--dump-precedences") (and interpreters an interactive command) to display the precedences of all operators in scope in some module. (The latter would be quite a useful addition even with the current numerical precedence system). The more I think about it the more I like the idea. Cheers, Ben From benjamin.franksen at bessy.de Thu Nov 9 13:25:36 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Thu Nov 9 13:25:43 2006 Subject: [Haskell-cafe] Re: Fractional/negative fixity? References: <5ce89fb50611071425i4568d3d7y7167fe1ec7ca9f23@mail.gmail.com> Message-ID: J?n Fairbairn wrote: > Syntax 1, based on Phil Wadler's improvement of my old > proposal. The precedence relation is a preorder.[...] > > infix {ops_1; ops_2; ...; ops_n} > > The alternative syntax is exemplified thus: > > infix L + - (L * / (R ^)) > > [...] I think both ways (I like the second one more) are a lot better than precedence numbers, whether they be fractional or integral. Let us add compiler/interpreter support for querying known precedence/fixity relations and it's (almost) perfect. Cheers Ben From jgbailey at gmail.com Thu Nov 9 14:12:51 2006 From: jgbailey at gmail.com (Justin Bailey) Date: Thu Nov 9 14:12:18 2006 Subject: [Haskell-cafe] Haskell Quiz Solution - Haskell Newbie Requesting Review Message-ID: As part of the Ruby Quiz in Haskell solutions appearing on the wiki recently, I just a solution to Ruby Quiz #100 - create a bytecode interpreter for a simple expression language. Like I said, the code below parses simple integer arithmetic expressions and generates byte codes for a hypothetical stack-based intepreter that would evaluate the expressions. To run it, save it as a literate haskell file and run "interpret_tests". That just shows correctness, though. Other output can be obtained by running "compile_tests" (shows bytes for all tests), "generate_tests" (symbolic bytecodes for all tests), and "eval_tests" (evaluate ASTs for all tests). To see the AST generated for a example expression, try something like 'parse "2-2-2"'. I'm just learning Haskell (about a month in) and if anyone has time and desire to critique the code below, I'd love to hear it. I come from an OOP (primarily C# & Ruby) background, so I'm really interested in getting a handle on the functional/Haskell "way" of coding. Thanks for any feedback! Justin p.s. This code is also available on the wiki: http://www.haskell.org/haskellwiki/Haskell_Quiz/Bytecode_Compiler/Solution_Justin_Bailey p.p.s. The original ruby quiz is available at: http://www.rubyquiz.com/quiz100.html \begin{code} import Text.ParserCombinators.Parsec hiding (parse) import qualified Text.ParserCombinators.Parsec as P (parse) import Text.ParserCombinators.Parsec.Expr import Data.Bits import Data.Int -- Represents various operations that can be applied -- to expressions. data Op = Plus | Minus | Mult | Div | Pow | Mod | Neg deriving (Show, Eq) -- Represents expression we can build - either numbers or expressions -- connected by operators. This structure is the basis of the AST built -- when parsing data Expression = Statement Op Expression Expression | Val Integer | Empty deriving (Show) -- Define the byte codes that can be generated. data Bytecode = NOOP | CONST Integer | LCONST Integer | ADD | SUB | MUL | POW | DIV | MOD | SWAP deriving (Show) -- Using imported Parsec.Expr library, build a parser for expressions. expr :: Parser Expression expr = buildExpressionParser table factor "expression" where -- Recognizes a factor in an expression factor = do{ char '(' ; x <- expr ; char ')' ; return x } <|> number "simple expression" -- Recognizes a number number :: Parser Expression number = do{ ds <- many1 digit ; return (Val (read ds)) } "number" -- Specifies operator, associativity, precendence, and constructor to execute -- and built AST with. table = [[prefix "-" (Statement Mult (Val (-1)))], [binary "^" (Statement Pow) AssocRight], [binary "*" (Statement Mult) AssocLeft, binary "/" (Statement Div) AssocLeft, binary "%" (Statement Mod) AssocLeft], [binary "+" (Statement Plus) AssocLeft, binary "-" (Statement Minus) AssocLeft] ] where binary s f assoc = Infix (do{ string s; return f}) assoc prefix s f = Prefix (do{ string s; return f}) -- Parses a string into an AST, using the parser defined above parse s = case P.parse expr "" s of Right ast -> ast Left e -> error $ show e -- Take AST and evaluate (mostly for testing) eval (Val n) = n eval (Statement op left right) | op == Mult = eval left * eval right | op == Minus = eval left - eval right | op == Plus = eval left + eval right | op == Div = eval left `div` eval right | op == Pow = eval left ^ eval right | op == Mod = eval left `mod` eval right -- Takes an AST and turns it into a byte code list generate stmt = generate' stmt [] where generate' (Statement op left right) instr = let li = generate' left instr ri = generate' right instr lri = li ++ ri in case op of Plus -> lri ++ [ADD] Minus -> lri ++ [SUB] Mult -> lri ++ [MUL] Div -> lri ++ [DIV] Mod -> lri ++ [MOD] Pow -> lri ++ [POW] generate' (Val n) instr = if abs(n) > 32768 then LCONST n : instr else CONST n : instr -- Takes a statement and converts it into a list of actual bytes to -- be interpreted compile s = toBytes (generate $ parse s) -- Convert a list of byte codes to a list of integer codes. If LCONST or CONST -- instruction are seen, correct byte representantion is produced toBytes ((NOOP):xs) = 0 : toBytes xs toBytes ((CONST n):xs) = 1 : (toConstBytes (fromInteger n)) ++ toBytes xs toBytes ((LCONST n):xs) = 2 : (toLConstBytes (fromInteger n)) ++ toBytes xs toBytes ((ADD):xs) = 0x0a : toBytes xs toBytes ((SUB):xs) = 0x0b : toBytes xs toBytes ((MUL):xs) = 0x0c : toBytes xs toBytes ((POW):xs) = 0x0d : toBytes xs toBytes ((DIV):xs) = 0x0e : toBytes xs toBytes ((MOD):xs) = 0x0f : toBytes xs toBytes ((SWAP):xs) = 0x0a : toBytes xs toBytes [] = [] -- Convert number to CONST representation (2 element list) toConstBytes n = toByteList 2 n toLConstBytes n = toByteList 4 n -- Convert a number into a list of 8-bit bytes (big-endian/network byte order). -- Make sure final list is size elements long toByteList :: Bits Int => Int -> Int -> [Int] toByteList size n = reverse $ take size (toByteList' n) where toByteList' a = (a .&. 255) : toByteList' (a `shiftR` 8) -- All tests defined by the quiz, with the associated values they should evaluate to. test1 = [(2+2, "2+2"), (2-2, "2-2"), (2*2, "2*2"), (2^2, "2^2"), (2 `div` 2, "2/2"), (2 `mod` 2, "2%2"), (3 `mod` 2, "3%2")] test2 = [(2+2+2, "2+2+2"), (2-2-2, "2-2-2"), (2*2*2, "2*2*2"), (2^2^2, "2^2^2"), (4 `div` 2 `div` 2, "4/2/2"), (7`mod`2`mod`1, "7%2%1")] test3 = [(2+2-2, "2+2-2"), (2-2+2, "2-2+2"), (2*2+2, "2*2+2"), (2^2+2, "2^2+2"), (4 `div` 2+2, "4/2+2"), (7`mod`2+1, "7%2+1")] test4 = [(2+(2-2), "2+(2-2)"), (2-(2+2), "2-(2+2)"), (2+(2*2), "2+(2*2)"), (2*(2+2), "2*(2+2)"), (2^(2+2), "2^(2+2)"), (4 `div` (2+2), "4/(2+2)"), (7`mod`(2+1), "7%(2+1)")] test5 = [(-2+(2-2), "-2+(2-2)"), (2-(-2+2), "2-(-2+2)"), (2+(2 * -2), "2+(2*-2)")] test6 = [((3 `div` 3)+(8-2), "(3/3)+(8-2)"), ((1+3) `div` (2 `div` 2)*(10-8), "(1+3)/(2/2)*(10-8)"), ((1*3)*4*(5*6), "(1*3)*4*(5*6)"), ((10`mod`3)*(2+2), "(10%3)*(2+2)"), (2^(2+(3 `div` 2)^2), "2^(2+(3/2)^2)"), ((10 `div` (2+3)*4), "(10/(2+3)*4)"), (5+((5*4)`mod`(2+1)), "5+((5*4)%(2+1))")] -- Evaluates the tests and makes sure the expressions match the expected values eval_tests = concat $ map eval_tests [test1, test2, test3, test4, test5, test6] where eval_tests ((val, stmt):ts) = let eval_val = eval $ parse stmt in if val == eval_val then ("Passed: " ++ stmt) : eval_tests ts else ("Failed: " ++ stmt ++ "(" ++ show eval_val ++ ")") : eval_tests ts eval_tests [] = [] -- Takes all the tests and displays symbolic bytes codes for each generate_tests = concat $ map generate_all [test1,test2,test3,test4,test5,test6] where generate_all ((val, stmt):ts) = (stmt, generate (parse stmt)) : generate_all ts generate_all [] = [] -- Takes all tests and generates a list of bytes representing them compile_tests = concat $ map compile_all [test1,test2,test3,test4,test5,test6] where compile_all ((val, stmt):ts) = (stmt, compile stmt) : compile_all ts compile_all [] = [] interpret_tests = concat $ map f' [test1, test2, test3, test4, test5, test6] where f' tests = map f'' tests f'' (expected, stmt) = let value = fromIntegral $ interpret [] $ compile stmt in if value == expected then "Passed: " ++ stmt else "Failed: " ++ stmt ++ "(" ++ (show value) ++ ")" fromBytes n xs = let int16 = (fromIntegral ((fromIntegral int32) :: Int16)) :: Int int32 = byte xs byte xs = foldl (\accum byte -> (accum `shiftL` 8) .|. (byte)) (head xs) (take (n - 1) (tail xs)) in if n == 2 then int16 else int32 interpret [] [] = error "no result produced" interpret (s1:s) [] = s1 interpret s (o:xs) | o < 10 = interpret ((fromBytes (o*2) xs):s) (drop (o*2) xs) interpret (s1:s2:s) (o:xs) | o == 16 = interpret (s2:s1:s) xs | otherwise = interpret (((case o of 10 -> (+); 11 -> (-); 12 -> (*); 13 -> (^); 14 -> div; 15 -> mod) s2 s1):s) xs \end{code} From brandonm at yahoo-inc.com Thu Nov 9 14:22:30 2006 From: brandonm at yahoo-inc.com (Brandon Moore) Date: Thu Nov 9 14:23:24 2006 Subject: [Haskell-cafe] Haskell Quiz Solution - Haskell Newbie Requesting Review In-Reply-To: References: Message-ID: <45537FF6.8090307@yahoo-inc.com> Justin Bailey wrote: > As part of the Ruby Quiz in Haskell solutions appearing on the wiki > recently, I just a solution to Ruby Quiz #100 - create a bytecode > interpreter for a simple expression language. > > Like I said, the code below parses simple integer arithmetic > expressions and generates byte codes for a hypothetical stack-based > intepreter that would evaluate the expressions. To run it, save it as > a literate haskell file and run "interpret_tests". That just shows > correctness, though. Other output can be obtained by running > "compile_tests" (shows bytes for all tests), "generate_tests" > (symbolic bytecodes for all tests), and "eval_tests" (evaluate ASTs > for all tests). > > To see the AST generated for a example expression, try something like > 'parse "2-2-2"'. > > I'm just learning Haskell (about a month in) and if anyone has time > and desire to critique the code below, I'd love to hear it. I come > from an OOP (primarily C# & Ruby) background, so I'm really interested > in getting a handle on the functional/Haskell "way" of coding. Thanks > for any feedback! > I haven't had time to look over your code, but this reminds me of a fun paper, "A type-correct, stack-safe, provably correct expression compiler in Epigram" The code consists of an expression interpreter, a stack machine emulator, a compiler, and a proof that forall expr, evaluate exper == execute (compile expr). (proofs are functions - go Curry-Howard) You can find the paper at http://www.cs.nott.ac.uk/~jjw/ Brandon From bringert at cs.chalmers.se Thu Nov 9 14:43:36 2006 From: bringert at cs.chalmers.se (=?ISO-8859-1?Q?Bj=F6rn_Bringert?=) Date: Thu Nov 9 14:39:12 2006 Subject: [Haskell-cafe] string to date? In-Reply-To: <20061109155808.GC18621@glowfish> References: <20061109153809.GB4371@die.therning.org> <20061109155808.GC18621@glowfish> Message-ID: <455384E8.8040507@cs.chalmers.se> Dougal Stanton wrote: > Quoth Magnus Therning, nevermore, >> I've been staring my eyes out trying to find a function that converts a >> string into a ClockTime or CalendarTime. Basically something like C's >> strptime(3). I can't seem to find anything like it in System.Time, >> there are function that convert _to_ a string, but nothing that converts >> _from_ a string it seems. Where should I look? > > The MissingH.Time.ParseDate [1] module might be what you want. There's > also one from Bjorn Bringert [2]. I haven't used either though, so I > can't recommend anything between them. > > Cheers, > > D. > > [1]: > [2]: Those two are the same code. I have a preliminary new version which can also parse most of the types from the time package (Data.Time.*) available at: http://www.cs.chalmers.se/~bringert/darcs/parsedate-2/ /Bj?rn From benjamin.franksen at bessy.de Thu Nov 9 16:20:38 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Thu Nov 9 16:20:49 2006 Subject: [Haskell-cafe] non-total operator precedence order (was:Fractional/negative fixity?) References: <23077.1162923030@calligramme.charmers> <5110.213.84.177.94.1162946917.squirrel@webmail.xs4all.nl> Message-ID: Henning Thielemann wrote: > Maybe making fixity declarations like type class instance declarations is > good. I thought so too at first but, having thought about it for a while, I now see this will cause /major/ problems. The precedence relations as declared explicitly by the programmer must form a DAG, with the vertices being the operator classes with equal precedence. There are two ways you can break the DAG: by introducing a 'smaller' or 'larger' relation when another module has already declared them to have equal precedence (resp. the other way around); or by introducing a cycle. Both can be caused simply by importing yet another module. I think it would be unacceptable not to provide some way for the programmer to resolve such conflicts. One way to do so would be to give an explicit order of 'precedence declaration priority' (PDP) for conflicting modules. Any rule introduced by a module with a lower PDP would be dropped (in the order of appearance) if it causes the DAG to break. Simple to use but the resulting precedence order would be quite hard to predict! Another way would be to hide precedence relation(s) in the import declaration. However, this is practical only if precedence declarations have a name we can refer to. The cleanest variant would probably be to tear holes in the graph by removing all relations to a particular operator from the graph, making it an isolated vertice, and then re-introducing new precedence relations for this operator. You might have to do this with several operators and it would be quite difficult to find the minimal set of operators that together will do the trick (i.e. restore the DAG). Even if you manage to find out, it could well be that by removing an operator from the graph you will accidentally remove many other operators, too, for instance if all these other operators have been declared to have the same precedence than the one you removed. I am not a graph specialist; maybe there exist semi-automatic solutions for such problems in the literature, anyway I know of none, and it would would in any case be quite a 'heavy' extension. All in all, in must agree with Nils and say that I can't see a light-weight and elegant way to make this work. Too bad, really. Ben From ndmitchell at gmail.com Thu Nov 9 16:54:02 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Thu Nov 9 16:53:31 2006 Subject: [Haskell-cafe] Translating Haskell to VHDL. What approach to follow? In-Reply-To: <6a7c66fc0611060617u1da5254bt52d8202382a46639@mail.gmail.com> References: <6a7c66fc0611051350x2033367dt456f2b5aef1f5ce2@mail.gmail.com> <036EAC76E7F5EC4996A3B3C3657D4116071C9998@EUR-MSG-21.europe.corp.microsoft.com> <404396ef0611060248n1b88a620o41c9ca77ad385ff9@mail.gmail.com> <6a7c66fc0611060617u1da5254bt52d8202382a46639@mail.gmail.com> Message-ID: <404396ef0611091354v2e3673d4t16f2dd7a52e21a04@mail.gmail.com> Hi > That implies I need a way to infere or directly obtain the types of > the functions used in the core representation. That as you said, can > probably be done by means of the .hi files or the typerep extension > you mentioned. I'll try to have a look at both options. Any good > documentation pointers? For .hi files just compile it with Yhc and take a look at the .hi file it creates, they are plain text. If they are top level functions (which they certainly are, I guess) this should be all you need. Another approach is to get the type information out of Hugs with the :t command line prod. I've done this before in another project. Thanks Neil From cwitty at newtonlabs.com Thu Nov 9 17:26:44 2006 From: cwitty at newtonlabs.com (Carl Witty) Date: Thu Nov 9 17:27:13 2006 Subject: [Haskell-cafe] non-total operator precedence order (was:Fractional/negative fixity?) In-Reply-To: References: <23077.1162923030@calligramme.charmers> <5110.213.84.177.94.1162946917.squirrel@webmail.xs4all.nl> Message-ID: <1163111205.11834.30.camel@meteor.newtonlabs.com> On Thu, 2006-11-09 at 22:20 +0100, Benjamin Franksen wrote: > Henning Thielemann wrote: > > Maybe making fixity declarations like type class instance declarations is > > good. > > I thought so too at first but, having thought about it for a while, I now > see this will cause /major/ problems. The precedence relations as declared > explicitly by the programmer must form a DAG, with the vertices being the > operator classes with equal precedence. There are two ways you can break > the DAG: by introducing a 'smaller' or 'larger' relation when another > module has already declared them to have equal precedence (resp. the other > way around); or by introducing a cycle. Both can be caused simply by > importing yet another module. I think it would be unacceptable not to > provide some way for the programmer to resolve such conflicts. [ ... possibilities for resolving conflicts omitted ... ] Another possibility is: If you have operators op1 and op2, where the compiler sees conflicting requirements for the precedence of op1 and op2, then they are treated as non-associative relative to each other: the expression a op1 b op2 c is illegal, and the programmer must instead write (a op1 b) op2 c or a op1 (b op2 c) Carl Witty From magnus at therning.org Thu Nov 9 18:29:47 2006 From: magnus at therning.org (Magnus Therning) Date: Thu Nov 9 18:29:24 2006 Subject: [Haskell-cafe] string to date? In-Reply-To: <455384E8.8040507@cs.chalmers.se> References: <20061109153809.GB4371@die.therning.org> <20061109155808.GC18621@glowfish> <455384E8.8040507@cs.chalmers.se> Message-ID: <20061109232947.GD3861@die.therning.org> On Thu, Nov 09, 2006 at 20:43:36 +0100, Bj?rn Bringert wrote: >Dougal Stanton wrote: >>Quoth Magnus Therning, nevermore, >>>I've been staring my eyes out trying to find a function that converts a >>>string into a ClockTime or CalendarTime. Basically something like C's >>>strptime(3). I can't seem to find anything like it in System.Time, >>>there are function that convert _to_ a string, but nothing that converts >>>_from_ a string it seems. Where should I look? >>The MissingH.Time.ParseDate [1] module might be what you want. There's >>also one from Bjorn Bringert [2]. I haven't used either though, so I >>can't recommend anything between them. >>Cheers, >>D. >>[1]: >>[2]: > >Those two are the same code. I have a preliminary new version which can also >parse most of the types from the time package (Data.Time.*) available at: > >http://www.cs.chalmers.se/~bringert/darcs/parsedate-2/ I noticed one thing when playing around with ParseDate.parseCalendarTime in ghci: > parseCalendarTime System.Locale.defaultTimeLocale "%Y" "2006" Just (CalendarTime {ctYear = 2006, ctMonth = January, ctDay = 1, ctHour = 0, ctMin = 0, ctSec = 0, ctPicosec = 0, ctWDay = Thursday, ctYDay = 1, ctTZName = "UTC", ctTZ = 0, ctIsDST = False}) > parseCalendarTime System.Locale.defaultTimeLocale "%Y%m%d" "20061109" Nothing > parseCalendarTime System.Locale.defaultTimeLocale "%C%y%m%d" "20061109" Just (CalendarTime {ctYear = 2006, ctMonth = November, ctDay = 9, ctHour = 0, ctMin = 0, ctSec = 0, ctPicosec = 0, ctWDay = Thursday, ctYDay = 1, ctTZName = "UTC", ctTZ = 0, ctIsDST = False}) I'm on a Debian Sid system: % dpkg -l \*missingh\* Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad) ||/ Name Version Description +++-=========================-==============-============================================== ii libghc6-hdbc-missingh-dev 1.0.1.1 Integration of HDBC with MissingH, GHC version ii libghc6-missingh-dev 0.16.2 Library of utility functions for Haskell, GHC6 un missingh-doc (no description available) /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus Software is not manufactured, it is something you write and publish. Keep Europe free from software patents, we do not want censorship by patent law on written works. It's important for a corporate leader to know the difference between what is actually illegal, and what people assume should be illegal. -- Bill Gates, in interview for The Register, 19th June 2006 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061109/e90e105d/attachment.bin From dons at cse.unsw.edu.au Thu Nov 9 18:34:37 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Thu Nov 9 18:34:03 2006 Subject: [Haskell-cafe] Sistema de Ecuaciones NO lineales In-Reply-To: <200611092307.57891.bonobo@bigpond.net.au> References: <200611092307.57891.bonobo@bigpond.net.au> Message-ID: <20061109233437.GA27874@cse.unsw.EDU.AU> bonobo: > On Thu, 9 Nov 2006 02:52 pm, Sebastian Gaviria wrote: > > hola como estan!!!! > > > > Quiero preguntar quien puede resolver el sistemas de ecuaciones NO lineales > > de Newton y el codigo de Jacobi en Haskell > > > > me ayudarian mucho al poder implementar ese codigo > > > > por Favor es con urgencia tener estos codigos!! > > > > > > muchas gracias !!! > > Hola Sebastian, > > Lo siento por mi espa?ol mal. > > Si esa es una pregunta sobre tarea, por favor lee > http://www.haskell.org/haskellwiki/Homework_help > > Y escribo Haskell como escribo espa?ol :-), as? lo siento, no puedo > ayudar. :-( > You might try: #haskell.es irc channel http://www.haskell.org/haskellwiki/IRC_channel -- Don From benjamin.franksen at bessy.de Thu Nov 9 19:16:23 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Thu Nov 9 19:16:13 2006 Subject: [Haskell-cafe] Re: non-total operator precedence order (was:Fractional/negative fixity?) References: <23077.1162923030@calligramme.charmers> <5110.213.84.177.94.1162946917.squirrel@webmail.xs4all.nl> <1163111205.11834.30.camel@meteor.newtonlabs.com> Message-ID: Carl Witty wrote: > On Thu, 2006-11-09 at 22:20 +0100, Benjamin Franksen wrote: >> Henning Thielemann wrote: >> > Maybe making fixity declarations like type class instance declarations >> > is >> > good. >> >> I thought so too at first but, having thought about it for a while, I now >> see this will cause /major/ problems. The precedence relations as >> declared explicitly by the programmer must form a DAG, with the vertices >> being the operator classes with equal precedence. There are two ways you >> can break the DAG: by introducing a 'smaller' or 'larger' relation when >> another module has already declared them to have equal precedence (resp. >> the other way around); or by introducing a cycle. Both can be caused >> simply by importing yet another module. I think it would be unacceptable >> not to provide some way for the programmer to resolve such conflicts. > > [ ... possibilities for resolving conflicts omitted ... ] > > Another possibility is: > > If you have operators op1 and op2, where the compiler sees conflicting > requirements for the precedence of op1 and op2, then they are treated as > non-associative relative to each other: the expression > a op1 b op2 c > is illegal, and the programmer must instead write > (a op1 b) op2 c > or > a op1 (b op2 c) It's a possibility. However, I fear that such conflicting precedences might not come in nice little isolated pairs. For instance, each operator that is in the same precedence class as op1 (i.e. has been declared as having equal precedence) will now be 'incompatible' with any that is in the same class as op2, right? It gets worse if the conflict creates a cycle in a chain of large operator classes. Thus one single bad declaration can tear a gaping hole into an otherwise perfectly nice and consistent DAG of precedence order relations, possibly invalidating a whole lot of code. Although one could view this as a bug in the offending module it makes me somewhat uneasy that one additional import can have such a drastic effect on the code in a module /even if you don't use anything from that module/. Ben From bringert at cs.chalmers.se Thu Nov 9 19:27:32 2006 From: bringert at cs.chalmers.se (Bjorn Bringert) Date: Thu Nov 9 19:27:09 2006 Subject: [Haskell-cafe] string to date? In-Reply-To: <20061109232947.GD3861@die.therning.org> References: <20061109153809.GB4371@die.therning.org> <20061109155808.GC18621@glowfish> <455384E8.8040507@cs.chalmers.se> <20061109232947.GD3861@die.therning.org> Message-ID: <864F25C6-7E9B-4D2A-A42A-03CCDACFC668@cs.chalmers.se> On 10 nov 2006, at 00.29, Magnus Therning wrote: > On Thu, Nov 09, 2006 at 20:43:36 +0100, Bj?rn Bringert wrote: >> Dougal Stanton wrote: >>> Quoth Magnus Therning, nevermore, >>>> I've been staring my eyes out trying to find a function that >>>> converts a >>>> string into a ClockTime or CalendarTime. Basically something >>>> like C's >>>> strptime(3). I can't seem to find anything like it in System.Time, >>>> there are function that convert _to_ a string, but nothing that >>>> converts >>>> _from_ a string it seems. Where should I look? >>> The MissingH.Time.ParseDate [1] module might be what you want. >>> There's >>> also one from Bjorn Bringert [2]. I haven't used either though, so I >>> can't recommend anything between them. >>> Cheers, >>> D. >>> [1]: >> ParseDate.html> >>> [2]: >> >> Those two are the same code. I have a preliminary new version >> which can also >> parse most of the types from the time package (Data.Time.*) >> available at: >> >> http://www.cs.chalmers.se/~bringert/darcs/parsedate-2/ > > I noticed one thing when playing around with > ParseDate.parseCalendarTime > in ghci: > >> parseCalendarTime System.Locale.defaultTimeLocale "%Y" "2006" > Just (CalendarTime {ctYear = 2006, ctMonth = January, ctDay = 1, > ctHour = 0, ctMin = 0, ctSec = 0, ctPicosec = 0, ctWDay = Thursday, > ctYDay = 1, ctTZName = "UTC", ctTZ = 0, ctIsDST = False}) >> parseCalendarTime System.Locale.defaultTimeLocale "%Y%m%d" "20061109" > Nothing >> parseCalendarTime System.Locale.defaultTimeLocale "%C%y%m%d" >> "20061109" > Just (CalendarTime {ctYear = 2006, ctMonth = November, ctDay = 9, > ctHour = 0, ctMin = 0, ctSec = 0, ctPicosec = 0, ctWDay = Thursday, > ctYDay = 1, ctTZName = "UTC", ctTZ = 0, ctIsDST = False}) Hi Magnus, thanks for the bug report. I have fixed this now in the version of the library available from http://www.cs.chalmers.se/~bringert/darcs/parsedate/ I intend to retire that version, and instead switch to the new implementation available at http://www.cs.chalmers.se/~bringert/darcs/parsedate-2/ This supports both CalendarTime and the new much nicer Data.Time types. However, the implementation is still incomplete (about as complete as the old version I think). It is missing support for week date formats and the like, and there is no test suite or QuickCheck properties (and thus there are surely lots of bugs). By the way, if you want to be sure that I see your bug reports about any of the libraries I maintain, please to cc the reports to me, or send them to me directly. /Bj?rn From dons at cse.unsw.edu.au Thu Nov 9 19:44:15 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Thu Nov 9 19:43:41 2006 Subject: [Haskell-cafe] Great language shootout: reloaded Message-ID: <20061110004415.GA28727@cse.unsw.EDU.AU> So back in January we had lots of fun tuning up Haskell code for the Great Language Shootout[1]. We did quite well at the time, at one point ranking overall first[2]. After doing all we could with ghc 6.4.2, the Haskell entries have been left for the last 10 months, while we worked on new libraries (bytestring, regex-*). 1. http://shootout.alioth.debian.org/ 2. http://www.cse.unsw.edu.au/~dons/data/haskell_1.html Now the time has come to reload the shootout for another round! GHC 6.6 is on the 'sandbox' debian machine, and will soon be on the other shootout boxes[3], which means we can use: * Data.ByteString * regex-* libraries 3. http://shootout.alioth.debian.org/sandbox/benchmark.php?test=all&lang=ghc&lang2=javaxint#about And thus greatly improve: fannkuch fasta k-nucleotide regex-dna reverse-complement sum-file While we're here we should fix: chameneos And anything else you want to take a look at. A community page has been set up to which you can submit improved entries: http://www.haskell.org/haskellwiki/Great_language_shootout So, install GHC 6.6, read up on Data.ByteString and the new regex libs, and submit faster code to the wiki! Our shootout-interface officer, musasabi, can then commit them to shootout cvs, once consensus is reached on the best code to submit. Let's take back first place! :) -- Don From dons at cse.unsw.edu.au Thu Nov 9 22:46:52 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Thu Nov 9 22:46:33 2006 Subject: [Haskell-cafe] Re: don't: a 'do' for comonads? In-Reply-To: References: <20061109034751.GD27808@cse.unsw.EDU.AU> Message-ID: <20061110034651.GA4911@cse.unsw.EDU.AU> apfelmus: > Donald Bruce Stewart wrote: > > As seen on #haskell, from an idea by Malcolm, > > > > 14:42 ?let top'n'tail = ("
"++) . (++"
") > > 14:42 lambdabot> Defined. > > 14:43 dons> > L.top'n'tail "foo me now" > > 14:43 lambdabot> "
foo me now
" > > 14:43 mauke> that reminds me, haskell needs don't > > 14:43 dons> yes! > > 14:44 pkhuong-> mm. the opposite of do, eh? do for comonads? :) > > > > So now a prize to the person who comes up with the best use for the > > identifier: > > > > don't :: ? > > > > -- Don > > don't :: IO a -> a > > example :: () > example = don't (do erase "/dev/hda") I like it! -- Don From dons at cse.unsw.edu.au Thu Nov 9 22:47:32 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Thu Nov 9 22:47:02 2006 Subject: [Haskell-cafe] don't: a 'do' for comonads? In-Reply-To: References: <20061109034751.GD27808@cse.unsw.EDU.AU> Message-ID: <20061110034732.GB4911@cse.unsw.EDU.AU> hjgtuyl: > > don't :: whatever -> > > (whatever goes in, nothing comes out) So its: don't :: a -> Void ? -- Don From brandonm at yahoo-inc.com Fri Nov 10 00:06:50 2006 From: brandonm at yahoo-inc.com (Brandon Moore) Date: Fri Nov 10 00:08:34 2006 Subject: [Haskell-cafe] Haskell Quiz Solution - Haskell Newbie Requesting Review In-Reply-To: References: Message-ID: <455408EA.5070703@yahoo-inc.com> Justin Bailey wrote: > As part of the Ruby Quiz in Haskell solutions appearing on the wiki > recently, I just a solution to Ruby Quiz #100 - create a bytecode > interpreter for a simple expression language. > > Like I said, the code below parses simple integer arithmetic > expressions and generates byte codes for a hypothetical stack-based > intepreter that would evaluate the expressions. To run it, save it as > a literate haskell file and run "interpret_tests". That just shows > correctness, though. Other output can be obtained by running > "compile_tests" (shows bytes for all tests), "generate_tests" > (symbolic bytecodes for all tests), and "eval_tests" (evaluate ASTs > for all tests). > > To see the AST generated for a example expression, try something like > 'parse "2-2-2"'. > > I'm just learning Haskell (about a month in) and if anyone has time > and desire to critique the code below, I'd love to hear it. I come > from an OOP (primarily C# & Ruby) background, so I'm really interested > in getting a handle on the functional/Haskell "way" of coding. Thanks > for any feedback! Looks nice, especially if you're just getting started. The overall structure looks good, I've just made a bunch of little changes to the details. Mostly I found repeated patterns to replace with library functions or extract as helper functions. In particular, you often wrote fun (x:xs) = : fun xs fun [] = [] instead of fun xs = map xs Getting a little fancier, defining the fold over your expression type captures the recursion pattern in eval and generate. It's fairly handy for defining constant folding too, if you want that. Haskell is very easy to refactor. You pull out some functions, the code shrinks, you see more subtle patterns, you pull out more functions. Eventually you start noticing and reifying patterns between those functions, like a star off the main sequence burning the products of the last round of fusion, until finally the "degeneracy pressure" or fixed boilerplate of introducing and calling a new abstraction stops the collapse. And Haskell has very little syntactic overhead, no classes, keywords on function definitions, or even block delimiters - it's like neutronium instead of that bloated electron-degenerate matter :) I wonder, what's the programming equivalent of a black hole? Happy Hacking Brandon \begin{code} import Text.ParserCombinators.Parsec hiding (parse) import qualified Text.ParserCombinators.Parsec as P (parse) import Text.ParserCombinators.Parsec.Expr import Data.Bits import Data.Int -- Represents various operations that can be applied -- to expressions. data Op = Plus | Minus | Mult | Div | Pow | Mod | Neg deriving (Show, Eq) -- Represents expression we can build - either numbers or expressions -- connected by operators. This structure is the basis of the AST built -- when parsing data Expression = Val Integer | Statement Op Expression Expression deriving (Show) foldExpression val stmt = f where f (Val n) = val n f (Statement op l r) = stmt op (f l) (f r) -- Define the byte codes that can be generated. data Bytecode = NOOP | CONST Integer | LCONST Integer | ADD | SUB | MUL | POW | DIV | MOD | SWAP deriving (Show) -- Using imported Parsec.Expr library, build a parser for expressions. expr :: Parser Expression expr = buildExpressionParser table factor "expression" where -- Recognizes a factor in an expression factor = between (char '(') (char ')') expr <|> number "simple expression" -- Recognizes a number number = fmap (Val . read) (many1 digit) "number" -- Specifies operator, associativity, precendence, and constructor to execute -- and built AST with. table = [[prefix "-" (Statement Mult (Val (-1)))], [binary "^" Pow AssocRight], [binary "*" Mult AssocLeft, binary "/" Div AssocLeft, binary "%" Mod AssocLeft], [binary "+" Plus AssocLeft, binary "-" Minus AssocLeft]] where binary s op assoc = Infix (do{ string s; return (Statement op)}) assoc prefix s f = Prefix (do{ string s; return f}) -- Parses a string into an AST, using the parser defined above parse s = case P.parse expr "" s of Right ast -> ast Left e -> error $ show e -- Take AST and evaluate (mostly for testing) eval = foldExpression id evalOp evalOp op = case op of Mult -> (*) Minus -> (-) Plus -> (+) Div -> div Pow -> (^) Mod -> mod -- Takes an AST and turns it into a byte code list generate = foldExpression generateVal (\op l r -> l ++ r ++ generateOp op) where generateVal n = if abs n > 2^(2*8)-1 then [CONST n] else [LCONST n] generateOp op = case op of Plus -> [ADD] Minus -> [SUB] Mult -> [MUL] Div -> [DIV] Mod -> [MOD] Pow -> [POW] -- Takes a statement and converts it into a list of actual bytes to -- be interpreted compile s = toBytes (generate $ parse s) -- Convert a list of byte codes to a list of integer codes. If LCONST or CONST -- instruction are seen, correct byte representantion is produced toBytes xs = concatMap instToBytes xs instToBytes instr = case instr of NOOP -> [0] (CONST n) -> 1 : toByteList 2 (fromInteger n) (LCONST n) -> 2 : toByteList 4 (fromInteger n) ADD -> [0x0a] SUB -> [0x0b] MUL -> [0x0c] POW -> [0x0d] DIV -> [0x0e] MOD -> [0x0f] SWAP -> [0x0a] -- Convert a number into a list of 8-bit bytes (big-endian/network byte order). -- Make sure final list is size elements long toByteList :: Int -> Int -> [Int] toByteList size n = reverse $ take size (toByteList' n) where toByteList' a = (a .&. 255) : toByteList' (a `shiftR` 8) fromBytes xs = foldl (\accum byte -> (accum `shiftL` 8) .|. byte) 0 xs -- The stack machine for binary bytecodes interpret [] [] = error "no result produced" interpret (s1:s) [] = s1 interpret s (o:xs) | o < 10 = interpret (fromBytes (take (o*2) xs):s) (drop (o*2) xs) interpret (s1:s2:s) (o:xs) | o == 16 = interpret (s2:s1:s) xs | otherwise = interpret (evalOpCode o s2 s1:s) xs evalOpCode o = case o of 10 -> (+) 11 -> (-) 12 -> (*) 13 -> (^) 14 -> div 15 -> mod -- All tests defined by the quiz, with the associated values they should evaluate to. test1 = [(2+2, "2+2"), (2-2, "2-2"), (2*2, "2*2"), (22, "22"), (2 `div` 2, "2/2"), (2 `mod` 2, "2%2"), (3 `mod` 2, "3%2")] test2 = [(2+2+2, "2+2+2"), (2-2-2, "2-2-2"), (2*2*2, "2*2*2"), (22^2, "22^2"), (4 `div` 2 `div` 2, "4/2/2"), (7`mod`2`mod`1, "7%2%1")] test3 = [(2+2-2, "2+2-2"), (2-2+2, "2-2+2"), (2*2+2, "2*2+2"), (22+2, "22+2"), (4 `div` 2+2, "4/2+2"), (7`mod`2+1, "7%2+1")] test4 = [(2+(2-2), "2+(2-2)"), (2-(2+2), "2-(2+2)"), (2+(2*2), "2+(2*2)"), (2*(2+2), "2*(2+2)"), (2^(2+2), "2^(2+2)"), (4 `div` (2+2), "4/(2+2)"), (7`mod`(2+1), "7%(2+1)")] test5 = [(-2+(2-2), "-2+(2-2)"), (2-(-2+2), "2-(-2+2)"), (2+(2*(-2)), "2+(2*-2)")] test6 = [((3 `div` 3)+(8-2), "(3/3)+(8-2)"), ((1+3) `div` (2 `div` 2)*(10-8), "(1+3)/(2/2)*(10-8)"), ((1*3)*4*(5*6), "(1*3)*4*(5*6)"), ((10`mod`3)*(2+2), "(10%3)*(2+2)"), -- (2^(2+(3 `div` 2)2), "2^(2+(3/2)2)"), -- maybe *2 at the end? ((10 `div` (2+3)*4), "(10/(2+3)*4)"), (5+((5*4)`mod`(2+1)), "5+((5*4)%(2+1))")] suite = [test1, test2, test3, test4, test5, test6] suiteResults doCase = [doCase val stmt | batch <- suite, (val, stmt) <- batch] checkResult fun expected arg | result == expected = "Passed: " ++ show arg | otherwise = "Failed: " ++ show arg ++ "(" ++ show result ++ ")" where result = fun arg showResult fun _ arg = (arg, fun arg) -- Evaluates the tests and makes sure the expressions match the expected values eval_tests = suiteResults (checkResult (eval . parse)) -- Takes all the tests and displays symbolic bytes codes for each generate_tests = suiteResults (showResult (generate . parse)) -- Takes all tests and generates a list of bytes representing them compile_tests = suiteResults (showResult compile) -- Execute the binary bytecode for each test, and make sure the results are expected interpret_tests = suiteResults (checkResult (fromIntegral . interpret [] . compile)) \end{code} From szefirov at ot.ru Fri Nov 10 08:26:52 2006 From: szefirov at ot.ru (szefirov@ot.ru) Date: Fri Nov 10 08:26:28 2006 Subject: [Haskell-cafe] Template Haskell. Message-ID: <45547E1C.6020205@ot.ru> Why doesn't reify return function body? reify (mkName "somefunction") for a function defined in the same module returns constructor VarI (of data type Info) that does not contain function declaration in (Maybe Dec) part. What actions should I perform to get a function body with patterns, expressions and all that? From lemming at henning-thielemann.de Fri Nov 10 10:08:29 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Fri Nov 10 10:08:35 2006 Subject: [Haskell-cafe] Re: non-total operator precedence order (was:Fractional/negative fixity?) In-Reply-To: References: <23077.1162923030@calligramme.charmers> <5110.213.84.177.94.1162946917.squirrel@webmail.xs4all.nl> <1163111205.11834.30.camel@meteor.newtonlabs.com> Message-ID: On Fri, 10 Nov 2006, Benjamin Franksen wrote: > Although one could view this as a bug in the offending module it makes > me somewhat uneasy that one additional import can have such a drastic > effect on the code in a module /even if you don't use anything from that > module/. It's the same as with instance declarations, isn't it? I don't want to defend the problems arising with todays anonymous instance declarations, but I think a simple error report is better than trying to solve the problem automatically and thus hide it from the programmer. From Benjamin.Rudiak-Gould at cl.cam.ac.uk Fri Nov 10 12:13:11 2006 From: Benjamin.Rudiak-Gould at cl.cam.ac.uk (Ben Rudiak-Gould) Date: Fri Nov 10 12:14:36 2006 Subject: [Haskell-cafe] Re: Fractional/negative fixity? In-Reply-To: <706781845.20061104095938@gmail.com> References: <002001c6efa4$c8372510$1cf52950@osmet> <22523.213.84.177.94.1161000771.squirrel@webmail.xs4all.nl> <5ce89fb50610160731ja2de0d8l23903e914dcfe8da@mail.gmail.com> <984680831.20061016195414@gmail.com> <454BF5D3.60705@imageworks.com> <706781845.20061104095938@gmail.com> Message-ID: I'm surprised that no one has mentioned showsPrec and readsPrec. Anything more complicated than negative fixities would require their interfaces to be changed. -- Ben From jgbailey at gmail.com Fri Nov 10 12:43:23 2006 From: jgbailey at gmail.com (Justin Bailey) Date: Fri Nov 10 12:42:47 2006 Subject: [Haskell-cafe] Haskell Quiz Solution - Haskell Newbie Requesting Review In-Reply-To: <455408EA.5070703@yahoo-inc.com> References: <455408EA.5070703@yahoo-inc.com> Message-ID: On 11/9/06, Brandon Moore wrote: > Looks nice, especially if you're just getting started. > > The overall structure looks good, I've just made a bunch of > little changes to the details. Mostly I found repeated patterns > to replace with library functions or extract as helper functions. Thanks very much! I really appreciate you taking the time to look through this code and perform the refactoring you did. Now, I hope you don't mind me asking a lot of questions about it :) > > Getting a little fancier, defining the fold over your expression type > captures the recursion pattern in eval and generate. It's fairly > handy for defining constant folding too, if you want that. Do you have any tips for recognizing these patterns? Its still hard for me to see them. Is there a general way to think of them? Comparing the two code pieces, I can see how the structure of the recursion was similar, but not the same. Is there a "pattern" for which pieces are common and which are unique? For example, I can think of foldl as "folding" a function over a list, with a given base case. Is there something similar for thinking about recursion? > I wonder, what's the programming equivalent of a black hole? To stretch the analogy to the breaking point, what about virtual particles and Hawking radiation? And what does the event horizon look like? LOL. > foldExpression val stmt = f > where f (Val n) = val n > f (Statement op l r) = stmt op (f l) (f r) This is great. It took me a while to realize that 'val' is a function for translating values, and 'stmt' is for translating statements. Really cool! > number = fmap (Val . read) (many1 digit) "number" How is this working? I read it as 'map (Val (read)) (string)' ('map', because its applied the List version of fmap). Is that correct? How does 'read' get the string argument? I would assume read is evaluated, and then its result and the string would be passed as arguments to Val. Clearly that's not right - can you correct me? > > -- Takes an AST and turns it into a byte code list > generate = foldExpression generateVal (\op l r -> l ++ r ++ generateOp op) > where generateVal n = if abs n > 2^(2*8)-1 > then [CONST n] > else [LCONST n] > generateOp op = case op of > Plus -> [ADD] > Minus -> [SUB] > Mult -> [MUL] > Div -> [DIV] > Mod -> [MOD] > Pow -> [POW] This is what clued me into how foldExpression was working. I especially like how the lambda works to generate the correct bytecode for the operator, and how "l" and "r" are already recursively evaluated by the "f" function returned from foldExpression. I just wonder how I'll ever spot similar patterns ;) > eval_tests = suiteResults (checkResult (eval . parse)) > > generate_tests = suiteResults (showResult (generate . parse)) > > interpret_tests = suiteResults (checkResult (fromIntegral . interpret [] > . compile)) Above are all more examples of partial functions and function composition. I understand the first concept, but function composition escapes me somehow. What are the rules for partial functions getting arguments when they are eventually supplied? For example, in 'interpret_tests' I can see that the function (fromIntegral . interpret . compile) gets applied to the statement via 'checkResult', but it seems to me that fromIntegral should get teh argument (i.e. because I read it is '(fromIntegral (interpret (compile)))'). Clearly, I'm wrong. Do arguments get consumed by partially applied functions regardless of their "depth"? Thanks again for your time looking at this code and maybe even answering these questions. I've already learned a ton just seeing the refactor. Justin From benjamin.franksen at bessy.de Fri Nov 10 12:51:44 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Fri Nov 10 12:51:46 2006 Subject: [Haskell-cafe] Re: Re: non-total operator precedence order (was:Fractional/negative fixity?) References: <23077.1162923030@calligramme.charmers> <5110.213.84.177.94.1162946917.squirrel@webmail.xs4all.nl> <1163111205.11834.30.camel@meteor.newtonlabs.com> Message-ID: Henning Thielemann wrote: > On Fri, 10 Nov 2006, Benjamin Franksen wrote: >> Although one could view this as a bug in the offending module it makes >> me somewhat uneasy that one additional import can have such a drastic >> effect on the code in a module /even if you don't use anything from that >> module/. > > It's the same as with instance declarations, isn't it? I don't want to > defend the problems arising with todays anonymous instance declarations, Right. However, with instances I can imagine solutions that avoid naming them, that is, I could imagine to write something like select instance C T1 T2 ... Tn from module M or import M hiding (instance C T1 T2 ... Tn, ....) Such a feature could prove extremely useful in practice. Disclaimer: I am almost sure that there is something I have overlooked that makes such a simple solution impossible, otherwise it would have been proposed and implemented long ago... > but I think a simple error report is better than trying to solve the > problem automatically and thus hide it from the programmer. I agree 100% that error is better than silently change ("fix") semantics. However the fact that there is currently no way to manually resolve instance clashes coming from imported (library) modules is really problematic, IMHO. I think the only reason this hasn't yet produced major upheaval is that Haskell community is still quite small so library writers can still have most of the field in their eyeview, so to speak. If Haskell libraries were written and used in multitudes such as seen e.g. on CPAN, then the probability of conflicting instances would be a lot greater, in turn causing many libraries to be incompatible with each other. IMHO, this must be fixed before Haskell reaches even a fraction of that level of popularity. Non-total precedence order will give us more potential incompatibilities that the programmer has no way of resolving satisfactorily, so I'd rather stick with the current system, however limited. (And yes, I /have/ changed my mind on this. I'd /love/ to be convinced that this is not really going to be a problem but I am not and I hate it.) Cheers Ben From haskell at henning-thielemann.de Fri Nov 10 12:59:37 2006 From: haskell at henning-thielemann.de (Henning Thielemann) Date: Fri Nov 10 12:59:29 2006 Subject: [Haskell-cafe] Re: Fractional/negative fixity? In-Reply-To: References: <002001c6efa4$c8372510$1cf52950@osmet> <22523.213.84.177.94.1161000771.squirrel@webmail.xs4all.nl> <5ce89fb50610160731ja2de0d8l23903e914dcfe8da@mail.gmail.com> <984680831.20061016195414@gmail.com> <454BF5D3.60705@imageworks.com> <706781845.20061104095938@gmail.com> Message-ID: On Fri, 10 Nov 2006, Ben Rudiak-Gould wrote: > I'm surprised that no one has mentioned showsPrec and readsPrec. Anything more > complicated than negative fixities would require their interfaces to be > changed. Very true. Does it mean, that the Functional Graph Library has to become part of the Prelude? From ithika at gmail.com Fri Nov 10 13:31:15 2006 From: ithika at gmail.com (Dougal Stanton) Date: Fri Nov 10 13:29:43 2006 Subject: [Haskell-cafe] Haskell Quiz Solution - Haskell Newbie Requesting Review In-Reply-To: References: <455408EA.5070703@yahoo-inc.com> Message-ID: <20061110183115.GD19186@glowfish> Quoth Justin Bailey, nevermore, > Above are all more examples of partial functions and function > composition. I understand the first concept, but function composition > escapes me somehow. What are the rules for partial functions getting > arguments when they are eventually supplied? For example, in > 'interpret_tests' I can see that the function (fromIntegral . > interpret . compile) gets applied to the statement via 'checkResult', > but it seems to me that fromIntegral should get teh argument (i.e. > because I read it is '(fromIntegral (interpret (compile)))'). Clearly, > I'm wrong. Do arguments get consumed by partially applied functions > regardless of their "depth"? The operators (.) and ($) are used to join functions together, but in slightly different ways. Taking your example above, we would use ($) to obtain nested functions: > fromIntegral $ interpret $ compile == > fromIntegral (interpret (compile)) As you noted that doesn't seem right --- how does compile capture its input? Well, the (.) operator is slightly different. It captures variables and passes them into the 'innermost' function, a bit like this: > f . g = \x -> f (g x) In this respect you can treat 'f . g' as a single functional entity which takes the same number and type of functions as 'g' and return whatever type 'f' returns. As in the type signature: > (.) :: (b -> c) -> (a -> b) -> a -> c If it helps, think of something like > map (f . g . h) xs as identical to the following (although obviously much more succinct and orders of magnitude clearer) > map (f') xs > where f' = \x -> f (g (h x)) Cheers, D. -- Dougal Stanton Word attachments considered harmful. From jgbailey at gmail.com Fri Nov 10 13:39:47 2006 From: jgbailey at gmail.com (Justin Bailey) Date: Fri Nov 10 13:39:11 2006 Subject: [Haskell-cafe] Haskell Quiz Solution - Haskell Newbie Requesting Review In-Reply-To: <20061110183115.GD19186@glowfish> References: <455408EA.5070703@yahoo-inc.com> <20061110183115.GD19186@glowfish> Message-ID: On 11/10/06, Dougal Stanton wrote: > As you noted that doesn't seem right --- how does compile capture its > input? Well, the (.) operator is slightly different. It captures > variables and passes them into the 'innermost' function, a bit like > this: That is a great explanation. I've got a much better understanding of the operator now - thanks very much! Justin From jmaessen at alum.mit.edu Fri Nov 10 14:05:10 2006 From: jmaessen at alum.mit.edu (Jan-Willem Maessen) Date: Fri Nov 10 14:04:44 2006 Subject: [Haskell-cafe] Re: non-total operator precedence order (was:Fractional/negative fixity?) In-Reply-To: References: <23077.1162923030@calligramme.charmers> <5110.213.84.177.94.1162946917.squirrel@webmail.xs4all.nl> <1163111205.11834.30.camel@meteor.newtonlabs.com> Message-ID: <9402DFAB-514F-4D93-8F38-8E4DE3D9CD18@alum.mit.edu> On Nov 9, 2006, at 7:16 PM, Benjamin Franksen wrote: > Carl Witty wrote: > >> On Thu, 2006-11-09 at 22:20 +0100, Benjamin Franksen wrote: >>> Henning Thielemann wrote: >>>> Maybe making fixity declarations like type class instance >>>> declarations >>>> is >>>> good. >>> >>> I thought so too at first but, having thought about it for a >>> while, I now >>> see this will cause /major/ problems. The precedence relations as >>> declared explicitly by the programmer must form a DAG, with the >>> vertices >>> being the operator classes with equal precedence. There are two >>> ways you >>> can break the DAG: by introducing a 'smaller' or 'larger' >>> relation when >>> another module has already declared them to have equal precedence >>> (resp. >>> the other way around); or by introducing a cycle. Both can be caused >>> simply by importing yet another module. I think it would be >>> unacceptable >>> not to provide some way for the programmer to resolve such >>> conflicts. >> >> [ ... possibilities for resolving conflicts omitted ... ] >> >> Another possibility is: >> >> If you have operators op1 and op2, where the compiler sees >> conflicting >> requirements for the precedence of op1 and op2, then they are >> treated as >> non-associative relative to each other: the expression >> a op1 b op2 c >> is illegal, and the programmer must instead write >> (a op1 b) op2 c >> or >> a op1 (b op2 c) > > It's a possibility. However, I fear that such conflicting > precedences might > not come in nice little isolated pairs. For instance, each operator > that is > in the same precedence class as op1 (i.e. has been declared as > having equal > precedence) will now be 'incompatible' with any that is in the same > class > as op2, right? Well, look at it from the perspective of the reader. Does the reader of your code know beyond a shadow of a doubt what the intended precedence will be in these cases? If not, there should be parentheses there---quite apart from what the parser may or may not permit you to do. If the parser can't figure it out, you can bet your readers will have trouble as well. > It gets worse if the conflict creates a cycle in a chain of > large operator classes. Thus one single bad declaration can tear a > gaping > hole into an otherwise perfectly nice and consistent DAG of precedence > order relations, possibly invalidating a whole lot of code. Requiring parenthesization solves these problems in a stroke. -Jan-Willem Maessen who can't reliably parenthesize the C expression a==b << 3&&4 | 17 (yes, the horrific whitespace is deliberate!) > Although one > could view this as a bug in the offending module it makes me somewhat > uneasy that one additional import can have such a drastic effect on > the > code in a module /even if you don't use anything from that module/. > > Ben > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2425 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061110/8649ea2a/smime.bin From dagit at codersbase.com Fri Nov 10 14:27:36 2006 From: dagit at codersbase.com (Jason Dagit) Date: Fri Nov 10 14:26:58 2006 Subject: [Haskell-cafe] Template Haskell. In-Reply-To: <45547E1C.6020205@ot.ru> References: <45547E1C.6020205@ot.ru> Message-ID: On 11/10/06, szefirov@ot.ru wrote: > Why doesn't reify return function body? > > reify (mkName "somefunction") for a function defined in the same module > returns constructor VarI (of data type Info) that does not contain > function declaration in (Maybe Dec) part. > > What actions should I perform to get a function body with patterns, > expressions and all that? I'm not sure, but when faced a similar problem I used the Haskell98 parser to get at the AST of the functions. In my case the functions were defined in a different module so TH definitely couldn't get at the internals. The details of what I did are here: http://blog.codersbase.com/2006/09/01/simple-unit-testing-in-haskell/ HTH, Jason From benjamin.franksen at bessy.de Fri Nov 10 14:35:28 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Fri Nov 10 14:35:09 2006 Subject: [Haskell-cafe] Re: Re: non-total operator precedence order (was:Fractional/negative fixity?) References: <23077.1162923030@calligramme.charmers> <5110.213.84.177.94.1162946917.squirrel@webmail.xs4all.nl> <1163111205.11834.30.camel@meteor.newtonlabs.com> <9402DFAB-514F-4D93-8F38-8E4DE3D9CD18@alum.mit.edu> Message-ID: Jan-Willem Maessen wrote: > On Nov 9, 2006, at 7:16 PM, Benjamin Franksen wrote: >> Carl Witty wrote: >>> If you have operators op1 and op2, where the compiler sees >>> conflicting >>> requirements for the precedence of op1 and op2, then they are >>> treated as >>> non-associative relative to each other: the expression >>> a op1 b op2 c >>> is illegal, and the programmer must instead write >>> (a op1 b) op2 c >>> or >>> a op1 (b op2 c) >> >> It's a possibility. However, I fear that such conflicting >> precedences might >> not come in nice little isolated pairs. For instance, each operator >> that is >> in the same precedence class as op1 (i.e. has been declared as >> having equal >> precedence) will now be 'incompatible' with any that is in the same >> class >> as op2, right? > > Well, look at it from the perspective of the reader. Does the reader > of your code know beyond a shadow of a doubt what the intended > precedence will be in these cases? If not, there should be > parentheses there---quite apart from what the parser may or may not > permit you to do. If the parser can't figure it out, you can bet > your readers will have trouble as well. Imagine op1=(+), op2=(*). Would you think that it is acceptable if any wild module can come along and destroy the relative precedence order everyone espects to hold between those two? For this to happen it would be enough if M1 says prec (<+>) = prec (+) prec (<*>) = prec (*) while M2 says prec (<>) = prec (<*>) and M3 prec (<>) = prec (<+>) All modules M1, M2, and M3, when viewed independently, and even when viewed in pairwise combination, don't do anything bad. It is only the combination of all three that cause the expression 3 + 4 * 3 to become a syntax error! Ben From lemming at henning-thielemann.de Fri Nov 10 17:26:11 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Fri Nov 10 17:26:46 2006 Subject: [Haskell-cafe] Re: Livecoding music in Haskell In-Reply-To: References: Message-ID: On Wed, 8 Nov 2006, Rohan Drape wrote: > import Sound.SC3 > import Control.Concurrent (forkIO) > > ping f a = out 0 (sinOsc AR f 0 * e) > where c = EnvNum (-4.0) > e = envGen KR 1 a 0 1 removeSynth (envPerc 0.1 0.6 1 [c,c]) > > latency = 0.01 > > bundle t m = OscB (t + latency) m > > pinger = do now <- utc > at (fromIntegral (ceiling now)) f > where f t = do fd <- sc > send' fd (bundle t [s_new "ping" (-1) AddToTail 1]) > putStrLn "Sending ping" > return 1.0 > > main = do fd <- sc > putStrLn "Sending Ping Instrument" > sync' fd (d_recv' "ping" (ping 440 0.1)) > putStrLn "Resetting scsynth" > reset fd > putStrLn "Starting schedule thread" > forkIO pinger > putStrLn "Delaying main thread" > pause 30 > putStrLn "End of delay, exiting" When I run this, then SuperCollider emits the error FAILURE ew Command not found Do you use some new feature? (I could even not tell you my SuperCollider version, 'scsynth --version', 'scsynth -v' and the like, don't tell me. :-( From hjgtuyl at chello.nl Fri Nov 10 18:59:21 2006 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Fri Nov 10 18:58:45 2006 Subject: [Haskell-cafe] Great language shootout: reloaded In-Reply-To: <20061110004415.GA28727@cse.unsw.EDU.AU> References: <20061110004415.GA28727@cse.unsw.EDU.AU> Message-ID: On Fri, 10 Nov 2006 01:44:15 +0100, Donald Bruce Stewart wrote: > So back in January we had lots of fun tuning up Haskell code for the > Great Language Shootout[1]. We did quite well at the time, at one point > ranking overall first[2]. [...] Haskell suddenly dropped several places in the overall socre, when the size measurement changed from line-count to number-of-bytes after gzipping. Maybe it's worth it, to study why this is; Haskell programs are often much more compact then programs in other languages, but after gzipping, other languages do much better. One reason I can think of, is that for very short programs, the import statements weigh heavily. -- Met vriendelijke groet, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ -- Using Opera's revolutionary e-mail client: https://secure.bmtmicro.com/opera/buy-opera.html?AID=789433 From sylvan at student.chalmers.se Fri Nov 10 19:51:09 2006 From: sylvan at student.chalmers.se (Sebastian Sylvan) Date: Fri Nov 10 19:50:46 2006 Subject: [Haskell-cafe] Great language shootout: reloaded In-Reply-To: References: <20061110004415.GA28727@cse.unsw.EDU.AU> Message-ID: <3d96ac180611101651x7f2f696cn1f5b49c0792a7409@mail.gmail.com> On 11/10/06, Henk-Jan van Tuyl wrote: > > On Fri, 10 Nov 2006 01:44:15 +0100, Donald Bruce Stewart > wrote: > > > So back in January we had lots of fun tuning up Haskell code for the > > Great Language Shootout[1]. We did quite well at the time, at one point > > ranking overall first[2]. [...] > > Haskell suddenly dropped several places in the overall socre, when the > size measurement changed from line-count to number-of-bytes after > gzipping. Maybe it's worth it, to study why this is; Haskell programs are > often much more compact then programs in other languages, but after > gzipping, other languages do much better. One reason I can think of, is > that for very short programs, the import statements weigh heavily. I think the main factor is that languages with large syntactic redundancy get that compressed away. I.e if you write: MyVeryLongAndConvlutedClassName MyVeryLargeAndConvulutedObject new MyVeryLongAndConvolutedClassName( somOtherLongVariableName ); Or something like that, that makes the code clumpsy and difficult to read, but it won't affect the gzipped byte count very much. Their current way of meassuring is pretty much pointless, since the main thing the gzipping does is remove the impact of clunky syntax. Meassuring lines of code is certainly not perfect, but IMO it's a lot more useful as a metric then gzipped bytes. -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862 From tmorris at tmorris.net Fri Nov 10 20:14:12 2006 From: tmorris at tmorris.net (Tony Morris) Date: Fri Nov 10 20:13:36 2006 Subject: [Haskell-cafe] Great language shootout: reloaded In-Reply-To: <3d96ac180611101651x7f2f696cn1f5b49c0792a7409@mail.gmail.com> References: <20061110004415.GA28727@cse.unsw.EDU.AU> <3d96ac180611101651x7f2f696cn1f5b49c0792a7409@mail.gmail.com> Message-ID: <455523E4.9050003@tmorris.net> Sebastian Sylvan wrote: > On 11/10/06, Henk-Jan van Tuyl wrote: >> >> On Fri, 10 Nov 2006 01:44:15 +0100, Donald Bruce Stewart >> wrote: >> >> > So back in January we had lots of fun tuning up Haskell code for the >> > Great Language Shootout[1]. We did quite well at the time, at one >> point >> > ranking overall first[2]. [...] >> >> Haskell suddenly dropped several places in the overall socre, when the >> size measurement changed from line-count to number-of-bytes after >> gzipping. Maybe it's worth it, to study why this is; Haskell programs >> are >> often much more compact then programs in other languages, but after >> gzipping, other languages do much better. One reason I can think of, is >> that for very short programs, the import statements weigh heavily. > > I think the main factor is that languages with large syntactic > redundancy get that compressed away. I.e if you write: > > MyVeryLongAndConvlutedClassName MyVeryLargeAndConvulutedObject new > MyVeryLongAndConvolutedClassName( somOtherLongVariableName ); > > Or something like that, that makes the code clumpsy and difficult to > read, but it won't affect the gzipped byte count very much. > Their current way of meassuring is pretty much pointless, since the > main thing the gzipping does is remove the impact of clunky syntax. > Meassuring lines of code is certainly not perfect, but IMO it's a lot > more useful as a metric then gzipped bytes. > It may not be useful on its own, but it is not entirely meaningless. By using a lossless compression algorithm, you might infer some meaning about the code. Where it fails though is that if the algorithm was ideal (preferring low space at the expense of time), then the resulting bytes should be exactly the same. If it is not, then the samples did not do the exact same thing in the first place and so are not comparable! So, assuming gzip is ideal, then it is considered a win by having a higher compressed output! It is not that the method is pointless, it is the extrapolation and interpretation of the results. You could argue that the gzipped output is just the same thing written in a new programming language - of course, it is not very readable (at least not to me since I do not have gunzip installed in my brain, but I do have a Haskell interpreter of some sort). Achieving minimum expressiveness at the source code level is entirely subjective and is based on an interpretation by the observer. Using gzip attempts to minimise this subjectivity - whether or not it is successful is not entirely decidable, but it is at least better. Unfortunately, the results have been misinterpreted. Just smile and nod, I do :) From igouy2 at yahoo.com Fri Nov 10 21:56:57 2006 From: igouy2 at yahoo.com (Isaac Gouy) Date: Fri Nov 10 21:56:19 2006 Subject: [Haskell-cafe] Great language shootout: reloaded Message-ID: <20061111025657.3051.qmail@web60522.mail.yahoo.com> > On 11/10/06, Henk-Jan van Tuyl wrote: >> >> Haskell suddenly dropped several places in the overall socre, when the >> size measurement changed from line-count to number-of-bytes after >> gzipping. Maybe it's worth it, to study why this is; Haskell programs >> are >> often much more compact then programs in other languages, but after >> gzipping, other languages do much better. One reason I can think of, is >> that for very short programs, the import statements weigh heavily. Before this gets out-of-hand, my memory is certainly fallible but as I recall Haskell /did not/ drop several places because size measurement changed from line-count to gzip byte-count. 1) Check the webpage that Don Stewart cached and note the values for the memory use and code-lines multipliers, and note the values for the benchmark weights http://www.cse.unsw.edu.au/~dons/data/haskell_1.html Now go to the computer language shootout website and note the multipliers and benchmark weights. 2) Some Haskell programs were pushed into 'interesting alternative implementations' because they'd strayed so far from the spirit of the benchmark. (It takes a while for people to notice and complain, but eventually they do.) ____________________________________________________________________________________ Do you Yahoo!? Everyone is raving about the all-new Yahoo! Mail beta. http://new.mail.yahoo.com From dons at cse.unsw.edu.au Fri Nov 10 23:00:16 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Fri Nov 10 22:59:42 2006 Subject: [Haskell-cafe] Great language shootout: reloaded In-Reply-To: <20061111025657.3051.qmail@web60522.mail.yahoo.com> References: <20061111025657.3051.qmail@web60522.mail.yahoo.com> Message-ID: <20061111040016.GA31927@cse.unsw.EDU.AU> igouy2: > > On 11/10/06, Henk-Jan van Tuyl wrote: > >> > >> Haskell suddenly dropped several places in the overall socre, when > the > >> size measurement changed from line-count to number-of-bytes after > >> gzipping. Maybe it's worth it, to study why this is; Haskell > programs > >> are > >> often much more compact then programs in other languages, but after > >> gzipping, other languages do much better. One reason I can think of, > is > >> that for very short programs, the import statements weigh heavily. > > > Before this gets out-of-hand, my memory is certainly fallible but as I > recall Haskell /did not/ drop several places because size measurement > changed from line-count to gzip byte-count. > > > 1) Check the webpage that Don Stewart cached and note the values for > the memory use and code-lines multipliers, and note the values for the > benchmark weights > http://www.cse.unsw.edu.au/~dons/data/haskell_1.html > > Now go to the computer language shootout website and note the > multipliers and benchmark weights. > > > 2) Some Haskell programs were pushed into 'interesting alternative > implementations' because they'd strayed so far from the spirit of the > benchmark. (It takes a while for people to notice and complain, but > eventually they do.) I agree. Breaking the rules was mainly the reason for the drop. Entries like chameneos and fasta. Also, the other language teams kept improving things. Other language (perl, iirc) were affected far worse by the gzipping. gzip is an interesting measurement, and it doesn't hurt Haskell too much either way -- short Haskell programs stay short when compressed. As a result, rewriting verbose entries to ByteString will probably be much more useful :) Btw, Isaac, are we going to have any new parallelism benchmarks? I'd love to try out the SMP runtime ;) -- Don From rd at slavepianos.org Fri Nov 10 23:14:20 2006 From: rd at slavepianos.org (Rohan Drape) Date: Fri Nov 10 23:13:39 2006 Subject: [Haskell-cafe] Re: Livecoding music in Haskell In-Reply-To: References: Message-ID: > When I run this, then SuperCollider emits the error > FAILURE ew Command not found > Do you use some new feature? No, however you may need to run darcs update, there was an error in the OSC bundle encoder that I located writing that example: > Wed Nov 8 21:29:28 EST 2006 Rohan Drape > * Fix error in OSC bundle encoder hence the sly reference to current repository in the post! Regards, Rohan From nicolas.frisby at gmail.com Fri Nov 10 23:35:21 2006 From: nicolas.frisby at gmail.com (Nicolas Frisby) Date: Fri Nov 10 23:34:43 2006 Subject: [Haskell-cafe] Re: aggressiveness of functional dependencies In-Reply-To: References: <5ce89fb50611061409k18c7a446p559987bde70eaf10@mail.gmail.com> <5ce89fb50611071039q621d67aam42888e810fb100b1@mail.gmail.com> <5ce89fb50611081551k4849f945h2a61c8bde2e13c99@mail.gmail.com> Message-ID: <5ce89fb50611102035l7388888bld5784de1a65a79fe@mail.gmail.com> First off, thanks for the reply. I am accustomed to GHC ignoring instance contexts as you mentioned. It's the "mostly" part that I'm curious about: mostly implies there's some phases that don't ignore context. Is that only the checking the type of the method definitions and absolutely nothing else? So it seems... My project is rather committed to GHC, but could you elaborate on your reference to Hugs being different? Thanks again, Nick On 11/9/06, apfelmus@quantentunnel.de wrote: > Nicolas Frisby wrote: > > >> > The inferred type for rite_t1 is > >> > rite_t1 :: (Iso (Either Char a) (Either f' g')) => () -> Either f' g' > >> > > >> > Why isn't the inferred type of rite_t1 the same as the ascribed type > >> > of rite_t1'? > >> > > >> > > rite_t1' :: Iso b b' => () -> Either MyChar b' > >> > > rite_t1' () = rite t1 > > I think GHC does not know whether the given instance declaration > > instance ... => Iso (Either a b) (Either a' b') > > even applies to the special case of (a = Char) because it mostly ignores > the preconditions on the left side of (=>). Hugs is much different. > Maybe throwing away undecidable instances will drastically change things. > > > Last post until a response I promise! Another demonstration: > > > > bar () = runIdentity . flip runStateT 0 $ return 'c' > > > > Inferred signature: > > bar :: (Monad (StateT s Identity), Num s) => () -> (Char, s) > > > > Why not? > > bar :: Num s => () -> (Char, s) > > > > I am not coming up with an s that could prevent (StateT s Identity) > > from being a monad. Is there one? > > The same might go on for this case. By not looking at the preconditions > in the instance declaration > > instance Monad m => Monad (StateT s m) > > GHC concludes that (Monad (StateT s Identity)) might or might not hold > depending on s. > > Regards, > apfelmus > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From bulat.ziganshin at gmail.com Sat Nov 11 03:52:25 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sat Nov 11 04:23:36 2006 Subject: [Haskell-cafe] Great language shootout: reloaded In-Reply-To: <3d96ac180611101651x7f2f696cn1f5b49c0792a7409@mail.gmail.com> References: <20061110004415.GA28727@cse.unsw.EDU.AU> <3d96ac180611101651x7f2f696cn1f5b49c0792a7409@mail.gmail.com> Message-ID: <32380172.20061111115225@gmail.com> Hello Sebastian, Saturday, November 11, 2006, 3:51:09 AM, you wrote: > Meassuring lines of code is certainly not perfect, but IMO it's a lot > more useful as a metric then gzipped bytes. why they don't use word count?? -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Sat Nov 11 04:00:49 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sat Nov 11 04:23:39 2006 Subject: [Haskell-cafe] Great language shootout: reloaded In-Reply-To: <20061111025657.3051.qmail@web60522.mail.yahoo.com> References: <20061111025657.3051.qmail@web60522.mail.yahoo.com> Message-ID: <72771180.20061111120049@gmail.com> Hello Isaac, Saturday, November 11, 2006, 5:56:57 AM, you wrote: > 2) Some Haskell programs were pushed into 'interesting alternative > implementations' because they'd strayed so far from the spirit of the > benchmark. (It takes a while for people to notice and complain, but > eventually they do.) it's very real :) while ghc allows to write rather fast programs, such programs are much harder to write and manage than even equivalent C ones! just for comparison: -- compact, but very slow s = sum arr // not so compact, but very fast double sum=0; for(int i=0; i<10; i++) sum+=arr[i]; // nor fast, nor compact, nor in Haskell spirit anyway :)) sum' <- newIORef 0 for 0 10 $ \i -> do x <- unsafeRead arr i sum <- readIORef sum' writeIORef sum' (sum+x) for :: Int -> Int -> (Int -> IO a) -> IO () -- Faster equivalent of "mapM_ action [from..to-1]" for from to action = go from where go i | i>=to = return () | otherwise = do action i go $! (i+1) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From sylvan at student.chalmers.se Sat Nov 11 07:08:41 2006 From: sylvan at student.chalmers.se (Sebastian Sylvan) Date: Sat Nov 11 07:08:11 2006 Subject: [Haskell-cafe] Great language shootout: reloaded In-Reply-To: <32380172.20061111115225@gmail.com> References: <20061110004415.GA28727@cse.unsw.EDU.AU> <3d96ac180611101651x7f2f696cn1f5b49c0792a7409@mail.gmail.com> <32380172.20061111115225@gmail.com> Message-ID: <3d96ac180611110408x39afd858te908a0d7119e2b41@mail.gmail.com> On 11/11/06, Bulat Ziganshin wrote: > Hello Sebastian, > > Saturday, November 11, 2006, 3:51:09 AM, you wrote: > > > Meassuring lines of code is certainly not perfect, but IMO it's a lot > > more useful as a metric then gzipped bytes. > > why they don't use word count?? I don't know. I suppose it's quite difficult to define a useful meaning of "word". I mean: foo=\xs->[y*2|y<-xs] Would count as one word, I suppose, though the number of tokens is far greater. Though I do think a word count as well, would hold more intuitive meaning than gzipped bytes. /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862 From apfelmus at quantentunnel.de Sat Nov 11 07:08:59 2006 From: apfelmus at quantentunnel.de (apfelmus@quantentunnel.de) Date: Sat Nov 11 07:11:48 2006 Subject: [Haskell-cafe] Re: aggressiveness of functional dependencies In-Reply-To: <5ce89fb50611102035l7388888bld5784de1a65a79fe@mail.gmail.com> References: <5ce89fb50611061409k18c7a446p559987bde70eaf10@mail.gmail.com> <5ce89fb50611071039q621d67aam42888e810fb100b1@mail.gmail.com> <5ce89fb50611081551k4849f945h2a61c8bde2e13c99@mail.gmail.com> <5ce89fb50611102035l7388888bld5784de1a65a79fe@mail.gmail.com> Message-ID: Nicolas Frisby wrote: > First off, thanks for the reply. > > I am accustomed to GHC ignoring instance contexts as you mentioned. > It's the "mostly" part that I'm curious about: mostly implies there's > some phases that don't ignore context. Is that only the checking the > type of the method definitions and absolutely nothing else? So it > seems... I just said "mostly" because I don't know exactly... Though I strongly suspect, like you, that the preconditions are only used in type inference/checking and not for overlapping instances and similar questions related to uniqueness of instance declarations. > > My project is rather committed to GHC, but could you elaborate on your > reference to Hugs being different? By tradition from Gofer, Hugs implements type classes more flexible than GHC does. I once experimented with the following code using overlapping instances: > data Lift a = Lift a > type Test = Char > > class Message m o where > send :: m -> o -> Test > > instance Message (o -> Test) o where > send m o = m o > > instance Message m o => Message m (Lift o) where > send m (Lift o) = send m o > > msg :: Test -> Test > msg = id > > r1 = send msg 'a' > r2 = send msg (Lift 'b') It implements some kind of subtyping. GHC won't typecheck this but "hugs -98 +m" will. If I remember correctly, the problem was with instance Message (Lift a -> Test) (Lift a) Does this follow from the first or from the second instance declaration? GHC ignores the precondition in the second declaration, thus believes it follows from both and consequently rejects it. But Hugs has no problems with that: it follows the precondition and sees that the second declaration does not apply to the culprit because there is no (instance (Lift a -> Test) a). Note that if you add this instance later on (perhaps in a different module), things will break. The flexibility comes at a price: Gofer's type class system was unsound and I don't know how much Hugs comes close to this. Regards, apfelmus From eric.kow at gmail.com Sat Nov 11 07:48:11 2006 From: eric.kow at gmail.com (Eric Y. Kow) Date: Sat Nov 11 07:47:52 2006 Subject: [wxhaskell-users] [Haskell-cafe] Announcement: new maintainers forr wxHaskell In-Reply-To: References: <1133622689.20061107165224@gmail.com> Message-ID: <20061111124811.GI24726@dewdrop.local> On Tue, Nov 07, 2006 at 23:26:40 +0100, Henk-Jan van Tuyl wrote: > I suggest gui@haskell.org, the GUI task force mailing list; nothing is > going on there at the moment, but it seems the most appropriate list. Hmm... I guess I'm happy just using the wxhaskell-users list for now, but if we do switch to something, this is a likely candidate. Although in the future, if it does get more active, and more than one project decide to use the list, it might get confusing. Maybe that list would better be for cross toolkit discussions. -- Eric Kow http://www.loria.fr/~kow PGP Key ID: 08AC04F9 Merci de corriger mon fran?ais. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 186 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061111/9bd103dc/attachment.bin From brianh at metamilk.com Sat Nov 11 11:19:59 2006 From: brianh at metamilk.com (Brian Hulley) Date: Sat Nov 11 11:19:02 2006 Subject: [Haskell-cafe] Why instances can't be hidden (was: non-total operator precedence order) References: <23077.1162923030@calligramme.charmers><5110.213.84.177.94.1162946917.squirrel@webmail.xs4all.nl><1163111205.11834.30.camel@meteor.newtonlabs.com> Message-ID: <002401c705ad$3c6e2140$71c22950@osmet> Benjamin Franksen wrote: > Henning Thielemann wrote: >> On Fri, 10 Nov 2006, Benjamin Franksen wrote: >>> Although one could view this as a bug in the offending module it >>> makes me somewhat uneasy that one additional import can have such a >>> drastic effect on the code in a module /even if you don't use >>> anything from that module/. >> >> It's the same as with instance declarations, isn't it? I don't want >> to defend the problems arising with todays anonymous instance >> declarations, > > Right. However, with instances I can imagine solutions that avoid > naming them, that is, I could imagine to write something like > > select instance C T1 T2 ... Tn from module M > > or > > import M hiding (instance C T1 T2 ... Tn, ....) > > Such a feature could prove extremely useful in practice. > > Disclaimer: I am almost sure that there is something I have > overlooked that makes such a simple solution impossible, otherwise it > would have been proposed and implemented long ago... I think the reason you can't do this kind of thing is that within any set of modules that is compiled at the same time, anywhere in any of these modules, if you have a type T that's an instance of class C, then all occurrences of C T must refer to the exact same instance declaration or else things would get totally messed up when/if the compiler did whole program optimization. In other words, the instances are actually properties of the type(s) themselves so allowing different modules to "see" different implementations of the instances would break the conceptual merging of modules (modulo renaming) that occurs at compile time. Regards, Brian. -- Logic empowers us and Love gives us purpose. Yet still phantoms restless for eras long past, congealed in the present in unthought forms, strive mightily unseen to destroy us. http://www.metamilk.com From haskell at sleepingsquirrel.org Sat Nov 11 13:45:24 2006 From: haskell at sleepingsquirrel.org (Greg Buchholz) Date: Sat Nov 11 13:40:21 2006 Subject: [Haskell-cafe] (twice head) && (twice tail) Message-ID: <20061111184524.GA2158@sleepingsquirrel.org> Over on comp.lang.functional ( http://xrl.us/s6kv ), Toby Kelsey is wondering about writing a function "twice" that applies a function to an argument two times... > twice' :: (a -> a) -> a -> a > twice' f x = f (f x) ...that works for things like "twice succ 0" and "twice tail [1,2,3]", but the type signature means you can't try something like "twice head [[1]]". You can get the "twice head" case to work with a function like... > twice'' :: (forall a. (m a) -> a) -> (m (m b)) -> b > twice'' f x = f (f x) ...and if you want something like "twice (flip (:) [])", you'd use... > twice''' :: (forall a. a -> (m a)) -> b -> (m (m b)) > twice''' f x = f (f x) ...it seems like those type signatures have at least a passing resemblance, so I was wondering if you could use type classes to combine these functions. I tried something like... > class Twice a b c | a b -> c where > twice :: a -> b -> c > > instance Twice (a->a) a a where > twice f x = f (f x) > > instance Twice (forall a. (m a) -> a) (m (m b)) b where > twice f x = f (f x) ...but with ghc-6.6 it chokes with... Illegal polymorphic or qualified type: forall a. m a -> a In the instance declaration for `Twice (forall a. (m a) -> a) (m (m b)) b' ...I can't say I'm surprised, but I was wondering if anyone else has thoughts on how this limitation might be worked around. Curious, Greg Buchholz From igouy2 at yahoo.com Sat Nov 11 14:36:07 2006 From: igouy2 at yahoo.com (Isaac Gouy) Date: Sat Nov 11 14:35:34 2006 Subject: [Haskell-cafe] Great language shootout: reloaded Message-ID: <20061111193607.27520.qmail@web60513.mail.yahoo.com> Donald Bruce Stewart wrote: -snip- > I agree. Breaking the rules was mainly the reason for the drop. Entries > like chameneos and fasta. Also, the other language teams kept improving > things. Yes, I missed that opportunity for listing things in threes ;-) Over the year improved programs were contributed for other languages. In contrast to the last focussed effort by the Haskell community, many of the other programs are contributed by individuals working alone, over many weeks. > > Other language (perl, iirc) were affected far worse by the gzipping. > gzip is an interesting measurement, and it doesn't hurt Haskell too much > either way -- short Haskell programs stay short when compressed. > > As a result, rewriting verbose entries to ByteString will probably be > much more useful :) > > Btw, Isaac, are we going to have any new parallelism benchmarks? I'd > love to try out the SMP runtime ;) If we were to have a 'which is the silliest comparison on the computer language shootout' competition, I think chameneos and cheap-concurrency would be joint first - there are so many really really different approaches. Ideas for unicode text processing would be more welcome. ____________________________________________________________________________________ Cheap talk? Check out Yahoo! Messenger's low PC-to-Phone call rates. http://voice.yahoo.com From aditya_siram at hotmail.com Sat Nov 11 14:51:23 2006 From: aditya_siram at hotmail.com (Aditya Siram) Date: Sat Nov 11 14:50:47 2006 Subject: [Haskell-cafe] Section Syntax Errors Message-ID: Hi all, I am learning about sections and currying from SOE. There are three functions below. The first is from SOE and the other two are my own practice functions. Why does the third function fail? --Test for negative numbers (from SOE pg 109). This works posInts :: [Integer] -> [Bool] posInts = map (> 0) --Add 1 to a list of numbers. This works. addOne :: [Integer] -> [Integer] addOne = map (+ 1) --Subtract 1 from a list of numbers. This does NOT work. --Fails in Hugs with: -- Instance of Num (Integer -> Integer) required for definition of testSections -- I tried : subOne :: Num a => [a] -> [a] -- and : subOne :: [Float] -> [Float] --in case the problem is with negative numbers. They both fail. --Without any type signature I get: -- Unresolved top level overloading subOne :: [Integer] -> [Integer] subOne = map (- 1) Thanks... Deech _________________________________________________________________ Add a Yahoo! contact to Windows Live Messenger for a chance to win a free trip! http://www.imagine-windowslive.com/minisites/yahoo/default.aspx?locale=en-us&hmtagline From ndmitchell at gmail.com Sat Nov 11 14:57:13 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Sat Nov 11 14:56:35 2006 Subject: [Haskell-cafe] Section Syntax Errors In-Reply-To: References: Message-ID: <404396ef0611111157h38a23a28mcafa0a1ec3b33b9c@mail.gmail.com> Hi Deech, Trying some things in Hugs: Hugs> :t (+1) flip (+) 1 :: Num a => a -> a Hugs> :t (<0) flip (<) 0 :: (Num a, Ord a) => a -> Bool Hugs> :t (-1) -1 :: Num a => a If you see, Haskell interprets the first two as sections, but the last one is treated as a unary minus, inside brackets - i.e. as though you typed the numeric literal -1. Haskell's treatment of negative literals is sometimes confusing... Thanks Neil On 11/11/06, Aditya Siram wrote: > Hi all, > I am learning about sections and currying from SOE. There are three > functions below. The first is from SOE and the other two are my own practice > functions. Why does the third function fail? > > --Test for negative numbers (from SOE pg 109). This works > posInts :: [Integer] -> [Bool] > posInts = map (> 0) > > --Add 1 to a list of numbers. This works. > addOne :: [Integer] -> [Integer] > addOne = map (+ 1) > > --Subtract 1 from a list of numbers. This does NOT work. > --Fails in Hugs with: > -- Instance of Num (Integer -> Integer) required for definition of > testSections > -- I tried : subOne :: Num a => [a] -> [a] > -- and : subOne :: [Float] -> [Float] > --in case the problem is with negative numbers. They both fail. > --Without any type signature I get: > -- Unresolved top level overloading > subOne :: [Integer] -> [Integer] > subOne = map (- 1) > > Thanks... > Deech > > _________________________________________________________________ > Add a Yahoo! contact to Windows Live Messenger for a chance to win a free > trip! > http://www.imagine-windowslive.com/minisites/yahoo/default.aspx?locale=en-us&hmtagline > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From dmhouse at gmail.com Sat Nov 11 14:57:32 2006 From: dmhouse at gmail.com (David House) Date: Sat Nov 11 14:56:51 2006 Subject: [Haskell-cafe] Section Syntax Errors In-Reply-To: References: Message-ID: On 11/11/06, Aditya Siram wrote: > subOne :: [Integer] -> [Integer] > subOne = map (- 1) The short answer is that this is interpreted as negative unity, rather than a section of binary minus. There are two common workarounds: subOne = map (subtract 1) subOne = map (+ (-1)) There's a whole minefield of opinions on whether this is the right syntax or not. I'm sure you could google through the archives to research this a bit more. -- -David House, dmhouse@gmail.com From lemming at henning-thielemann.de Sat Nov 11 16:04:08 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Sat Nov 11 16:04:31 2006 Subject: [Haskell-cafe] Re: Livecoding music in Haskell In-Reply-To: References: Message-ID: On Sat, 11 Nov 2006, Rohan Drape wrote: > > When I run this, then SuperCollider emits the error > > FAILURE ew Command not found > > Do you use some new feature? > > No, however you may need to run darcs update, there was an error in > the OSC bundle encoder that I located writing that example: > > > Wed Nov 8 21:29:28 EST 2006 Rohan Drape > > * Fix error in OSC bundle encoder > > hence the sly reference to current repository in the post! Indeed, that was the problem. Thanks! Now the scheduling is really accurate. I'll use that in future. From lennart at augustsson.net Sun Nov 12 10:32:35 2006 From: lennart at augustsson.net (Lennart Augustsson) Date: Sun Nov 12 10:32:14 2006 Subject: [Haskell-cafe] Simple implementations of the lambda calculus Message-ID: <18BD8C77-9937-4449-A8F2-198503974F27@augustsson.net> Some time ago I made a little experiment and implemented an interpreter for the lambda-calculus in Haskell. The only reason was that I wanted to try different ways of doing it. So I did it using simple substitution (i.e., as the textbooks describe it), unique identifiers, deBruijn indicies, and higher order abstract syntax. You can get the code from http://darcs.augustsson.net/Darcs/Lambda/ or just check out small paper at http://darcs.augustsson.net/Darcs/ Lambda/top.pdf -- Lennart From alfonso.acosta at gmail.com Sun Nov 12 10:44:34 2006 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Sun Nov 12 10:43:50 2006 Subject: [Haskell-cafe] Translating Haskell to VHDL. What approach to follow? In-Reply-To: <404396ef0611091354v2e3673d4t16f2dd7a52e21a04@mail.gmail.com> References: <6a7c66fc0611051350x2033367dt456f2b5aef1f5ce2@mail.gmail.com> <036EAC76E7F5EC4996A3B3C3657D4116071C9998@EUR-MSG-21.europe.corp.microsoft.com> <404396ef0611060248n1b88a620o41c9ca77ad385ff9@mail.gmail.com> <6a7c66fc0611060617u1da5254bt52d8202382a46639@mail.gmail.com> <404396ef0611091354v2e3673d4t16f2dd7a52e21a04@mail.gmail.com> Message-ID: <6a7c66fc0611120744g1eec886cu38fef4248f422bdf@mail.gmail.com> > For .hi files just compile it with Yhc and take a look at the .hi file > it creates, they are plain text. If they are top level functions > (which they certainly are, I guess) this should be all you need. > Another approach is to get the type information out of Hugs with the > :t command line prod. I've done this before in another project. Sorry for the delay answering. I didn't (and still won't) have access to the Internet for a few days but Ill try it and tell you if it worked once I'm back to normality. Thanks, Alfonso Acosta From donn at drizzle.com Sun Nov 12 13:49:28 2006 From: donn at drizzle.com (Donn Cave) Date: Sun Nov 12 13:48:46 2006 Subject: [Haskell-cafe] ByteString FFI Message-ID: <200611121849.kACInSn8019579@cascadia.drizzle.com> How do people like to set up their foreign I/O functions to return ByteStrings? I was a little stumped over this yesterday evening, while trying to write ` recv :: Socket -> Int -> Int -> ByteString ' Doc says `Byte vectors are encoded as strict Word8 arrays of bytes, held in a ForeignPtr, and can be passed between C and Haskell with little effort.' Which sounds perfect - I'm always up for `little effort'! CString doesn't seem like the right thing for socket results, because the data shouldn't be NUL-terminated, and I might want to realloc when the returned data doesn't fill the buffer. I don't see any other Ptr-related function or constructor in the documentation - am I missing something there? Thanks, Donn Cave, donn@drizzle.com From duncan.coutts at worc.ox.ac.uk Sun Nov 12 14:44:49 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun Nov 12 14:38:34 2006 Subject: [Haskell-cafe] ByteString FFI In-Reply-To: <200611121849.kACInSn8019579@cascadia.drizzle.com> References: <200611121849.kACInSn8019579@cascadia.drizzle.com> Message-ID: <1163360689.7179.264.camel@localhost> On Sun, 2006-11-12 at 10:49 -0800, Donn Cave wrote: > How do people like to set up their foreign I/O functions to return > ByteStrings? I was a little stumped over this yesterday evening, > while trying to write ` recv :: Socket -> Int -> Int -> ByteString ' > > Doc says `Byte vectors are encoded as strict Word8 arrays of bytes, > held in a ForeignPtr, and can be passed between C and Haskell with > little effort.' Which sounds perfect - I'm always up for `little effort'! > > CString doesn't seem like the right thing for socket results, because > the data shouldn't be NUL-terminated, and I might want to realloc when > the returned data doesn't fill the buffer. I don't see any other > Ptr-related function or constructor in the documentation - am I missing > something there? packCStringLen :: CStringLen -> ByteString (type CStringLen = (Ptr CChar, Int)) http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-ByteString.html#v%3ApackCStringLen So if you know the length and the pointer to the beginning of the buffer then it's just packCStringLen (ptr, len) Of course you're not allowed to change the buffer after this, if you are using a mutable buffer then you'll have to make a copy: copyCStringLen :: CStringLen -> IO ByteString Duncan From dm.maillists at gmail.com Sun Nov 12 18:02:19 2006 From: dm.maillists at gmail.com (Daniel McAllansmith) Date: Sun Nov 12 18:01:16 2006 Subject: [Haskell-cafe] GHCi 6.6 tab-completion of source file paths not working. Message-ID: <200611131202.19382.dm.maillists@gmail.com> Hi. I've just installed GHC 6.6 on an amd64 running a gentoo linux distribution. With GHCi from 6.4.2 I could run "ghci" then do Prelude> :l Foo/Bar.hs by hitting tab after Foo to complete the path to Bar.hs This no longer works, hitting tab only shows what's in the pwd. If I run "ghci Foo/Bar.hs" then I can :r fine and I can do a :l Foo.Bar using tab-completion to complete the module name. Tab completion of in-scope functions looks to be working fine. Has anybody else experienced this problem? Thanks Daniel From claus.reinke at talk21.com Sun Nov 12 18:14:58 2006 From: claus.reinke at talk21.com (Claus Reinke) Date: Sun Nov 12 18:15:10 2006 Subject: [Haskell-cafe] (twice head) && (twice tail) References: <20061111184524.GA2158@sleepingsquirrel.org> Message-ID: <024101c706b0$8080bd80$98857ad5@cr3lt> not a solution to your problem, but covers all your tests, as well as one more that would inevitably have followed:-) cheers, claus -------------- next part -------------- A non-text attachment was scrubbed... Name: Twice.hs Type: application/octet-stream Size: 1125 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061112/b9853b4e/Twice.obj From bulat.ziganshin at gmail.com Sun Nov 12 18:36:45 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sun Nov 12 18:50:52 2006 Subject: [Haskell-cafe] best Linux for GHC? Message-ID: <524915860.20061113023645@gmail.com> Hello haskell-cafe, Now i'm consider installation of some Linux version at my box. My friend offered me 3 variants: SuSe, Fedora Core 5, free variant of RedHat (i can't remember its name, may be Ubuntu?) what may be best for GHC-based development? in particular, i want to compile Haskell itself i suspect that it is a really dumb question, and GHC will work great just with any linux i can find :) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Sun Nov 12 18:50:03 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sun Nov 12 18:50:59 2006 Subject: [Haskell-cafe] what GUI library should i select? Message-ID: <1344369241.20061113025003@gmail.com> Hello haskell-cafe, afaik, there are just two good enough libs - wxHaskell and GtkHs. can anyone point (or write) detailed comparison of their features? i plan to write large GUI program in Haskell and want to select best one. the requirements that i can imagine at this moment is the following: * my main target is Windows but ability to compile the same code both for Windows and Linux would be a plus * the program developed is a sort of advanced file manager, so i need treeview, table view and tabbed view controls * user likes beauty, so various bells-and-whistles are welcomed. in particular, it would be great to have skinnable interface * use of resource file for all texts to make internalization easier -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From dons at cse.unsw.edu.au Sun Nov 12 19:11:20 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Sun Nov 12 19:10:37 2006 Subject: [Haskell-cafe] best Linux for GHC? In-Reply-To: <524915860.20061113023645@gmail.com> References: <524915860.20061113023645@gmail.com> Message-ID: <20061113001120.GA32512@cse.unsw.EDU.AU> bulat.ziganshin: > Hello haskell-cafe, > > Now i'm consider installation of some Linux version at my box. My > friend offered me 3 variants: SuSe, Fedora Core 5, free variant of > RedHat (i can't remember its name, may be Ubuntu?) > > what may be best for GHC-based development? in particular, i want to > compile Haskell itself > > i suspect that it is a really dumb question, and GHC will work great > just with any linux i can find :) > > -- Gentoo or Debian, I suspect, since then you get the #haskell-gentoo team, and Igloo, keeping things up to date :) -- Don From duncan.coutts at worc.ox.ac.uk Sun Nov 12 19:36:32 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun Nov 12 19:30:15 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <1344369241.20061113025003@gmail.com> References: <1344369241.20061113025003@gmail.com> Message-ID: <1163378192.7179.289.camel@localhost> On Mon, 2006-11-13 at 02:50 +0300, Bulat Ziganshin wrote: > Hello haskell-cafe, > > afaik, there are just two good enough libs - wxHaskell and GtkHs. can > anyone point (or write) detailed comparison of their features? i plan > to write large GUI program in Haskell and want to select best one. > the requirements that i can imagine at this moment is the following: I maintain Gtk2Hs, so I can tell you about that. Much of the difference comes down to the difference between Gtk+ and wxWidgets. You can read detailed comparisons between them elsewhere. The main touted advantage of wxWidgets is that it is a wrapper over different 'native' widget sets on each platform. This is also it's main disadvantage as it means the semantics of the API are not always 100% portable, it adds an extra indirection layer and it can't provide all the features of the native widget set as it has to provide a lowest common denominator API. On the other hand Gtk+ is a portable implementation that uses themes to provide a 'native' look (on windows it uses the native WinXP themeing dll). This means the look is not always perfect (though it has improved dramatically recently) but the semantics are much better preserved between platforms. As for the bindings, there's a great deal of similarity. One difference is in memory management. Gtk+ was designed while keeping in mind the goal of having bindings in garbage-collected languages where as wxWidgets uses ordinary C++ object lifetime management. Basically this means that with Gtk2Hs, if you get a segfault then it was my fault and a bug in Gtk2Hs. With wxHaskell you can get into situations where you can get a segfault and there's nothing wxHaskell can do about it. Axel wrote more about that here: http://haskell.org/gtk2hs/archives/2005/07/15/automatic-memory-management/ > * my main target is Windows but ability to compile the same code both > for Windows and Linux would be a plus Gtk2Hs works on both. > * the program developed is a sort of advanced file manager, so i need > treeview, table view and tabbed view controls Gtk+ has quite a flexible tree/list widget. With the upcoming release there is a new Haskell api to this to make it much easier to use and more Haskell-like. The tree/list widget follows the model/view and the view is very flexible in how it displays data from the model. You can set arbitrary Haskell functions to map data from the model to attributes of the cell renderers in the columns. There are also several different cell renderers, eg simple text, check buttons, icons, combo boxes etc. > * user likes beauty, so various bells-and-whistles are welcomed. in > particular, it would be great to have skinnable interface Gtk+ uses themes. Of course on windows the default theme is the same as the native global theme. Similarly, on Linux it follows the global Gtk/GNOME theme. > * use of resource file for all texts to make internalization easier If you use glade for the UI (which the recommended style) then it's possible to internationalise it. This is how most of the Gtk/GNOME programs do internationalisation of their UIs. Duncan From duncan.coutts at worc.ox.ac.uk Sun Nov 12 19:38:53 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun Nov 12 19:32:35 2006 Subject: [Haskell-cafe] GHCi 6.6 tab-completion of source file paths not working. In-Reply-To: <200611131202.19382.dm.maillists@gmail.com> References: <200611131202.19382.dm.maillists@gmail.com> Message-ID: <1163378333.7179.292.camel@localhost> On Mon, 2006-11-13 at 12:02 +1300, Daniel McAllansmith wrote: > Hi. > > I've just installed GHC 6.6 on an amd64 running a gentoo linux distribution. > > With GHCi from 6.4.2 I could run "ghci" then do > > Prelude> :l Foo/Bar.hs > > by hitting tab after Foo to complete the path to Bar.hs > > This no longer works, hitting tab only shows what's in the pwd. > > > If I run "ghci Foo/Bar.hs" then I can :r fine and I can do a :l Foo.Bar using > tab-completion to complete the module name. > Tab completion of in-scope functions looks to be working fine. > > Has anybody else experienced this problem? The tab completion was changed in GHC 6.6 so that it can tab-complete Haskell identifiers. It's quite possible that in the change-over that tab completion for files got broken. I suggest you file a bug report and describe exactly the behaviour that you would expect. Duncan From grady.lemoine at gmail.com Sun Nov 12 19:45:04 2006 From: grady.lemoine at gmail.com (Grady Lemoine) Date: Sun Nov 12 19:44:21 2006 Subject: [Haskell-cafe] best Linux for GHC? In-Reply-To: <524915860.20061113023645@gmail.com> References: <524915860.20061113023645@gmail.com> Message-ID: <5bbe25930611121645r52ec16f9w552cbbe71b4984a1@mail.gmail.com> I use Ubuntu, which is a flavor of Debian. It was pretty easy to install, and it's intended to be friendly to new Linux users, while not getting in the way of people who want to do more advanced things. My only complaint Haskell-wise is that GHC 6.6 hasn't made it into the package system yet; the latest available from the package system is 6.4.1, but you could always download 6.6 and compile it yourself if necessary. --Grady Lemoine On 11/12/06, Bulat Ziganshin wrote: > Hello haskell-cafe, > > Now i'm consider installation of some Linux version at my box. My > friend offered me 3 variants: SuSe, Fedora Core 5, free variant of > RedHat (i can't remember its name, may be Ubuntu?) > > what may be best for GHC-based development? in particular, i want to > compile Haskell itself > > i suspect that it is a really dumb question, and GHC will work great > just with any linux i can find :) > > -- > Best regards, > Bulat mailto:Bulat.Ziganshin@gmail.com > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From ndmitchell at gmail.com Sun Nov 12 20:10:52 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Sun Nov 12 20:10:07 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <1344369241.20061113025003@gmail.com> References: <1344369241.20061113025003@gmail.com> Message-ID: <404396ef0611121710g2b1c0b4dp1d06fa906ae05ec1@mail.gmail.com> Hi Bulat, > afaik, there are just two good enough libs - wxHaskell and GtkHs. can > anyone point (or write) detailed comparison of their features? i plan > to write large GUI program in Haskell and want to select best one. > the requirements that i can imagine at this moment is the following: I used to use wxHaskell. I wanted to write a GUI program using GHC 6.4.2 and was (disturbingly) shocked to find out that _neither_ of the GUI toolkits had prebuilt packages that worked on Windows with GHC 6.4.2. I complained and within a day Duncan had done one for Gtk2Hs, and to my knowledge wxHaskell still doesn't have such a packaged version. For this reason, I would recommend Gtk2Hs - the level of support and maintainership is far better than wxHaskell at the moment. I appreciate wxHaskell has new maintainers, but when picking a GUI toolkit where you can't easily switch later, currently maintained is a big bullet point for me! Thanks Neil From ccshan at post.harvard.edu Sun Nov 12 18:38:05 2006 From: ccshan at post.harvard.edu (Chung-chieh Shan) Date: Sun Nov 12 20:13:55 2006 Subject: [Haskell-cafe] Re: A type class puzzle References: <2608b8a80610310102i1e54092bhb04da958a3978def@mail.gmail.com> Message-ID: Yitzchak Gale wrote in article <2608b8a80610310102i1e54092bhb04da958a3978def@mail.gmail.com> in gmane.comp.lang.haskell.cafe: > replace0 :: a -> a -> a > replace1 :: Int -> a -> [a] -> [a] > replace2 :: Int -> Int -> a -> [[a]] -> [[a]] This message is joint work with Oleg Kiselyov. All errors are mine. Part of what makes this type-class puzzle difficult can be explained by trying to write Prolog code to identify those types that the general "replace" function can take. We use an auxiliary predicate repl(X0,X,Y0,Y), which means that X0 is "int ->" applied the same number of times to X as Y0 is "[]" applied to Y. repl(X, X, Y, Y). repl((int -> X0), X, [Y0], Y) :- repl(X0, X, Y0, Y). We can now write a unary predicate replace1(X0) to test if any given type X0 is a valid type for the "replace" function. replace1(X0) :- repl(X0, (Y -> Y0 -> Y0), Y0, Y). Positive and negative tests: ?- replace1(bool -> bool -> bool). ?- replace1(int -> bool -> [bool] -> [bool]). ?- replace1(int -> int -> bool -> [[bool]] -> [[bool]]). ?- replace1(int -> int -> int -> [[int]] -> [[int]]). ?- \+ replace1(bool -> [bool] -> [bool]). The optimist would expect to be able to turn these Prolog clauses into Haskell type-class instances directly. Unfortunately, at least one difference between Prolog and Haskell stands in the way: Haskell overloading resolution does not backtrack, and the order of type-class instances should not matter. Suppose that we switch the two repl clauses and add a cut, as follows: repl((int -> X0), X, [Y0], Y) :- !, repl(X0, X, Y0, Y). repl(X, X, Y, Y). Now the second-to-last test above ?- replace1(int -> int -> int -> [[int]] -> [[int]]). fails, because repl needs to "look ahead" beyond the current argument type to know that the third "int" in the type is not an index but a list element. This kind of ambiguity is analogous to a shift-reduce conflict in parsing. We could roll our own backtracking if we really wanted to, but let's switch to the saner type family > replace0 :: a -> a -> a > replace1 :: Int -> [a] -> a -> [a] > replace2 :: Int -> Int -> [[a]] -> a -> [[a]] where the old list comes before the new element. The corresponding Prolog predicate and tests now succeed, even with the switched and cut repl clauses above. replace2(X0) :- repl(X0, (Y0 -> Y -> Y0), Y0, Y). ?- replace2(bool -> bool -> bool). ?- replace2(int -> [bool] -> bool -> [bool]). ?- replace2(int -> int -> [[bool]] -> bool -> [[bool]]). ?- replace2(int -> int -> [[int]] -> int -> [[int]]). ?- \+ replace2([bool] -> bool -> [bool]). Regardless of this change, note that a numeric literal such as "2" in Haskell can denote not just an Int but also a list, given a suitable Num instance. Therefore, the open-world assumption of Haskell type classes forces us to annotate our indices with "::Int" in Haskell. Below, then, are the tests that we strive to satisfy. > x1 = "abc" > x2 = ["ab", "cde", "fghi", "uvwxyz"] > x3 = [[[i1 + i2 + i3 | i3 <- [10..13]] | i2<- [4..5]] | i1 <- [(1::Int)..3]] > test1:: String > test1 = replace (1::Int) x1 'X' > {- expected error reported > test2:: [String] > test2 = replace (1::Int) x2 'X' > -} > test3:: [String] > test3 = replace (1::Int) x2 "X" > test4:: [String] > test4 = replace (2::Int) (1::Int) x2 'X' > test5:: [[[Int]]] > test5 = replace (2::Int) (0::Int) (1::Int) x3 (100::Int) The remainder of this message shows two ways to pass these tests. Both ways require allowing undecidable instances in GHC 6.6. > {-# OPTIONS -fglasgow-exts #-} > {-# OPTIONS -fallow-undecidable-instances #-} In the first way, the Replace type-class parses the desired type for "replace" into a tuple of indices, in other words, a type-level list of indices. An auxiliary type-class Replace' then reverses this list. Finally, another auxiliary type-class Replace'' performs the actual replacement. > class Replace'' n old new where > repl'' :: n -> old -> new -> old > instance Replace'' () a a where > repl'' () old new = new > instance Replace'' n old new => Replace'' (n,Int) [old] new where > repl'' (i,i0) old new = > case splitAt i0 old of (h,[] ) -> h > (h,th:tt) -> h ++ repl'' i th new : tt > class Replace' n n' old new where > repl' :: n -> n' -> old -> new -> old > instance Replace'' n old new => Replace' n () old new where > repl' n () = repl'' n > instance Replace' (n1,n2) n3 old new => Replace' n1 (n2,n3) old new where > repl' n1 (n2,n3) = repl' (n1,n2) n3 > class Replace n a b c where > repl :: n -> a -> b -> c > instance Replace' () n [old] new => Replace n [old] new [old] where > repl = repl' () > instance Replace (i,n) a b c => Replace n i a (b->c) where > repl i0 i = repl (i,i0) > replace n = repl () n The second way, shown below, eliminates the intermediate tuple of indices used above. This code doesn't require allowing undecidable instances in Hugs, but it does use functional dependencies to coax Haskell into applying the last Replace instance. > class Replace old new old' new' w1 w2 w3 > | w1 w2 w3 -> old new old' new' where > repl :: ((old -> new -> old) -> (old' -> new' -> old')) > -> w1 -> w2 -> w3 > instance Replace a a b a b a b where > repl k = k (\old new -> new) > instance Replace old new old' new' w1 w2 w3 > => Replace [old] new old' new' Int w1 (w2 -> w3) where > repl k i = repl (\r -> k (\old new -> case splitAt i old of > (h, [] ) -> h > (h, th:tt) -> h ++ r th new : tt)) > replace :: Replace old new old new w1 w2 w3 => w1 -> w2 -> w3 > replace = repl id Both ways pass all tests above. -- Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig The fact that SM [Standard Model] cannot suggest any reason for our continued existence seems to be pretty serious to me. Discussion on Ars Technica about barion counts, mesons and SM From dons at cse.unsw.edu.au Sun Nov 12 20:47:31 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Sun Nov 12 20:46:48 2006 Subject: [Haskell-cafe] ByteString FFI In-Reply-To: <200611121849.kACInSn8019579@cascadia.drizzle.com> References: <200611121849.kACInSn8019579@cascadia.drizzle.com> Message-ID: <20061113014731.GD32512@cse.unsw.EDU.AU> donn: > How do people like to set up their foreign I/O functions to return > ByteStrings? I was a little stumped over this yesterday evening, > while trying to write ` recv :: Socket -> Int -> Int -> ByteString ' > > Doc says `Byte vectors are encoded as strict Word8 arrays of bytes, > held in a ForeignPtr, and can be passed between C and Haskell with > little effort.' Which sounds perfect - I'm always up for `little effort'! > > CString doesn't seem like the right thing for socket results, because > the data shouldn't be NUL-terminated, and I might want to realloc when > the returned data doesn't fill the buffer. I don't see any other > Ptr-related function or constructor in the documentation - am I missing > something there? And for custom data (not just C strings), if the withCString* functions don't quite fit, you can always pack the foreign Ptr into a ByteString by stepping inside the ByteString constructor: http://www.haskell.org/haskellwiki/Wc#Going_via_C -- Don From ivanperezdominguez at gmail.com Sun Nov 12 22:18:02 2006 From: ivanperezdominguez at gmail.com (=?ISO-8859-1?Q?Iv=E1n_P=E9rez_Dom=EDnguez?=) Date: Sun Nov 12 22:17:31 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <404396ef0611121710g2b1c0b4dp1d06fa906ae05ec1@mail.gmail.com> References: <1344369241.20061113025003@gmail.com> <404396ef0611121710g2b1c0b4dp1d06fa906ae05ec1@mail.gmail.com> Message-ID: <4557E3EA.8080303@babel.ls.fi.upm.es> Neil Mitchell wrote: > Hi Bulat, > >> afaik, there are just two good enough libs - wxHaskell and GtkHs. can >> anyone point (or write) detailed comparison of their features? i plan >> to write large GUI program in Haskell and want to select best one. >> the requirements that i can imagine at this moment is the following: > > I used to use wxHaskell. So did I. I tried gtk2hs as well. In my experience, gtk2hs is more complicated. On the other hand, gtk2hs supports glade, I think. wxHaskell seems to be easier to understand and to use. In my case, I took a reversi game from haskell.org and did a sudoku game in a few weeks (with no prior knowledge on wxHaskell). I wanted to write a GUI program using GHC > 6.4.2 and was (disturbingly) shocked to find out that _neither_ of the > GUI toolkits had prebuilt packages that worked on Windows with GHC > 6.4.2. I complained and within a day Duncan had done one for Gtk2Hs, > and to my knowledge wxHaskell still doesn't have such a packaged > version. > I'm using Gentoo Linux. We obviously don't use prebuilt packaged versions, but installing it is just doing "emerge wxhaskell" and 'playing the... waiting game'. Gtk2hs support under Gentoo is mostly missing (the package is included, but doesn't work at all). > For this reason, I would recommend Gtk2Hs - the level of support and > maintainership is far better than wxHaskell at the moment. I > appreciate wxHaskell has new maintainers, but when picking a GUI > toolkit where you can't easily switch later, currently maintained is a > big bullet point for me! From duncan.coutts at worc.ox.ac.uk Sun Nov 12 22:41:46 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun Nov 12 22:35:31 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <4557E3EA.8080303@babel.ls.fi.upm.es> References: <1344369241.20061113025003@gmail.com> <404396ef0611121710g2b1c0b4dp1d06fa906ae05ec1@mail.gmail.com> <4557E3EA.8080303@babel.ls.fi.upm.es> Message-ID: <1163389307.7179.308.camel@localhost> On Mon, 2006-11-13 at 04:18 +0100, Iv?n P?rez Dom?nguez wrote: > I'm using Gentoo Linux. We obviously don't use prebuilt packaged > versions, but installing it is just doing "emerge wxhaskell" and > 'playing the... waiting game'. Gtk2hs support under Gentoo is mostly > missing (the package is included, but doesn't work at all). Heh, that's odd. For me it's usually the other way around and I maintain both of those Gentoo packages! :-) Are you thinking of this bug or is it something else? http://bugs.gentoo.org/show_bug.cgi?id=144028 If it's something else then please report it. Duncan From ivanperezdominguez at gmail.com Sun Nov 12 23:43:04 2006 From: ivanperezdominguez at gmail.com (=?ISO-8859-1?Q?Iv=E1n_P=E9rez_Dom=EDnguez?=) Date: Sun Nov 12 23:42:31 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <1344369241.20061113025003@gmail.com> References: <1344369241.20061113025003@gmail.com> Message-ID: <4557F7D8.6010104@babel.ls.fi.upm.es> Bulat Ziganshin wrote: > Hello haskell-cafe, > > afaik, there are just two good enough libs - wxHaskell and GtkHs. can > anyone point (or write) detailed comparison of their features? i plan > to write large GUI program in Haskell and want to select best one. > the requirements that i can imagine at this moment is the following: > > * my main target is Windows but ability to compile the same code both > for Windows and Linux would be a plus with wxhaskell, you've got this one for sure. > * the program developed is a sort of advanced file manager, so i need > treeview, table view and tabbed view controls this one too, I guess. > * user likes beauty, so various bells-and-whistles are welcomed. in > particular, it would be great to have skinnable interface I did this in a sudoku game. I used the same schema as in the reversi game (available at haskell.org). > * use of resource file for all texts to make internalization easier Last one I don't know. From donn at drizzle.com Mon Nov 13 01:45:27 2006 From: donn at drizzle.com (Donn Cave) Date: Mon Nov 13 01:44:48 2006 Subject: [Haskell-cafe] ByteString FFI In-Reply-To: <20061113014731.GD32512@cse.unsw.EDU.AU> Message-ID: On Mon, 13 Nov 2006, Donald Bruce Stewart wrote: > And for custom data (not just C strings), if the withCString* functions > don't quite fit, you can always pack the foreign Ptr into a ByteString > by stepping inside the ByteString constructor: > > http://www.haskell.org/haskellwiki/Wc#Going_via_C That's actually what I tried first, but in this particular situation (ghc-6.4.1 / fps-0.7), PS apparently isn't exported? The CStringLen approach works, except that the allocated data doesn't get garbage-collected. Just for the sake of experiment I tried a regular CString with packMallocCString, and that didn't leak nearly as much memory - but still some, in a simple loop where "pack" doesn't leak anything. Thanks, Donn Cave, donn@drizzle.com From dons at cse.unsw.edu.au Mon Nov 13 01:46:48 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Mon Nov 13 01:46:05 2006 Subject: [Haskell-cafe] ByteString FFI In-Reply-To: References: <20061113014731.GD32512@cse.unsw.EDU.AU> Message-ID: <20061113064648.GC1826@cse.unsw.EDU.AU> donn: > On Mon, 13 Nov 2006, Donald Bruce Stewart wrote: > > > And for custom data (not just C strings), if the withCString* functions > > don't quite fit, you can always pack the foreign Ptr into a ByteString > > by stepping inside the ByteString constructor: > > > > http://www.haskell.org/haskellwiki/Wc#Going_via_C > > That's actually what I tried first, but in this particular situation > (ghc-6.4.1 / fps-0.7), PS apparently isn't exported? Right, you'll want to grab the soon-to-be-tagged fps 0.8, which matches that provided with ghc 6.6. It's in the darcs repo. > The CStringLen approach works, except that the allocated data doesn't > get garbage-collected. Just for the sake of experiment I tried a regular > CString with packMallocCString, and that didn't leak nearly as much memory - > but still some, in a simple loop where "pack" doesn't leak anything. -- Don From Ketil.Malde at bccs.uib.no Mon Nov 13 02:45:59 2006 From: Ketil.Malde at bccs.uib.no (Ketil Malde) Date: Mon Nov 13 02:45:18 2006 Subject: [Haskell-cafe] best Linux for GHC? In-Reply-To: <5bbe25930611121645r52ec16f9w552cbbe71b4984a1@mail.gmail.com> References: <524915860.20061113023645@gmail.com> <5bbe25930611121645r52ec16f9w552cbbe71b4984a1@mail.gmail.com> Message-ID: <455822B7.6070803@ii.uib.no> Grady Lemoine wrote: > I use Ubuntu, Me too, and I'm fairly happy with it. > > My only complaint Haskell-wise is that GHC 6.6 hasn't made it into the > package system yet; the latest available from the package system is > 6.4.1, 6.4.2 is in the latest version (Edgy). I've tried to pester them into shipping 6.6, but they're a bit conservative on that point. > but you could always download 6.6 and compile it yourself if > necessary. > I just download the binary snapshots, that usually "just works". >> >> Now i'm consider installation of some Linux version at my box. Welcome aboard! >> My friend offered me 3 variants: SuSe, Fedora Core 5, free variant of >> RedHat (i can't remember its name, may be Ubuntu?) CentOS, perhaps? It is usually good advice to choose whatever your friends are using, that way, it's easier to get help. If you really want to learn how Linux ticks, I'd recommend Gentoo - it's a bit more work, but the recipes are easy to follow, and you'll know a lot more about how your system works afterwards. We use CentOS at work, and I'm not too happy about it - too many outdated versions of too much software. Gentoo is fun and flexible, but everything takes time (it compiles everything on installation), and when I python upgrade broke my box, I decided enough was enough. Most of my business-oriented friends seem to like SuSE, but Fedora was too unstable last time I looked (which admittedly is some time ago). >> >> i suspect that it is a really dumb question, and GHC will work great >> just with any linux i can find :) True. There may be some dependency issues between ghc binary snapshots and libraries (libreadline 4 vs 5?), but it'll mostly all work. -k From newhoggy at gmail.com Mon Nov 13 05:24:52 2006 From: newhoggy at gmail.com (John Ky) Date: Mon Nov 13 05:24:07 2006 Subject: [Haskell-cafe] Testing non-exported functions using ghci Message-ID: Hello, I have modules that don't export some functions. Is there a way I can access them from ghci without exporting them? Thanks -John -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061113/33d09d75/attachment.htm From bulat.ziganshin at gmail.com Mon Nov 13 05:36:13 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Mon Nov 13 05:35:56 2006 Subject: [Haskell-cafe] best Linux for GHC? In-Reply-To: <455822B7.6070803@ii.uib.no> References: <524915860.20061113023645@gmail.com> <5bbe25930611121645r52ec16f9w552cbbe71b4984a1@mail.gmail.com> <455822B7.6070803@ii.uib.no> Message-ID: <1596152630.20061113133613@gmail.com> Hello Ketil, Monday, November 13, 2006, 10:45:59 AM, you wrote: >>> My friend offered me 3 variants: SuSe, Fedora Core 5, free variant of >>> RedHat (i can't remember its name, may be Ubuntu?) > CentOS, perhaps? It is usually good advice to choose whatever your > friends are using, thanks to everyone who answered my question! as you say, FC and CentOS are not ideal for me. Gentoo is too good for me, it is for unix geeks while i just don't have resources to play one more Game. i think that i will install it on my next box of remaining, Ubuntu has widest support here while SuSe is favourite of my friend. one thing that i like in suse is that it uses the same RPMs as RedHat and RPMs is widely used for packaging software available via internet. Is Ubuntu supports RPMs too? -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From tpledger at ihug.co.nz Mon Nov 13 06:13:09 2006 From: tpledger at ihug.co.nz (tpledger@ihug.co.nz) Date: Mon Nov 13 06:12:27 2006 Subject: [Haskell-cafe] Great language shootout: reloaded Message-ID: <45585345.3cb.4ad.1069118136@ihug.co.nz> Donald Bruce Stewart wrote: [...] > While we're here we should fix: > chameneos > And anything else you want to take a > look at. > > A community page has been set up to > which you can submit improved entries: > http://www.haskell.org/haskellwiki/Great_language_shootout [...] Well, then! I've put a new chameneos solution up on the wiki, and will wait the recommended couple of days for Community Feedback. - Tom From dons at cse.unsw.edu.au Mon Nov 13 06:17:24 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Mon Nov 13 06:16:53 2006 Subject: [Haskell-cafe] Great language shootout: reloaded In-Reply-To: <45585345.3cb.4ad.1069118136@ihug.co.nz> References: <45585345.3cb.4ad.1069118136@ihug.co.nz> Message-ID: <20061113111724.GC3301@cse.unsw.EDU.AU> tpledger: > Donald Bruce Stewart wrote: > [...] > > While we're here we should fix: > > chameneos > > And anything else you want to take a > > look at. > > > > A community page has been set up to > > which you can submit improved entries: > > > http://www.haskell.org/haskellwiki/Great_language_shootout > [...] > > > Well, then! > > I've put a new chameneos solution up on the wiki, and will > wait the recommended couple of days for Community Feedback. Great! One issue is that the pragma is unnecessary (all the good flags are set in the Makefile, so that saves a few gzipped bytes ;) -- Don From bulat.ziganshin at gmail.com Mon Nov 13 07:41:30 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Mon Nov 13 07:43:16 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <1163378192.7179.289.camel@localhost> References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> Message-ID: <655793883.20061113154130@gmail.com> Hello Duncan, Monday, November 13, 2006, 3:36:32 AM, you wrote: >> afaik, there are just two good enough libs - wxHaskell and GtkHs. can in brief, i see the following main differences: - wxHaskell is easier to understand and to use, Ght2Hs allows to use Glade to develop "look&feel" - Gtk2Hs had better support, but now wxHaskell has more maintainers and situation may change to opposite in a next few months - wxHaskell provides more native look&feel, while Gtk2Hs simplifies porting of GUI application from Windows to Linux. Also Gtk2Hs needs Gtk DLL to be installed, but this can be made a part of application installation procedure, afaik? - Gtk2Hs has better memory management - differences between Gtk and wxWidgets that i will go to study i also have more questions: first, how about tabbed pages control? such controls are widely used to represent plenty of information in limited screen space second: ability and easiness to develop my own controls, and to combine several customized controls together to make one "supercontrol" (although i guess that last feature is important only for RAD environments) third: are there any "appetizers" demonstrating features of each library and with source code available for studying? except for memory.pdf which don't mention where full source can be downloaded it will be interesting to see sources of more "business-like" applications developed with both libs. if there are no ones, may be i will develop basic file manager utility as such appetizer -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From mail at joachim-breitner.de Mon Nov 13 07:44:47 2006 From: mail at joachim-breitner.de (Joachim Breitner) Date: Mon Nov 13 07:44:20 2006 Subject: [Haskell-cafe] Testing non-exported functions using ghci In-Reply-To: References: Message-ID: <1163421887.3953.0.camel@otto.ehbuehl.net> Hi, Am Montag, den 13.11.2006, 21:24 +1100 schrieb John Ky: > I have modules that don't export some functions. Is there a way I can > access them from ghci without exporting them? It seems that if there are .hi files around, ghci can?t reach the non-exported functions, but if you delete this file, it works. Greetings, Joachim -- Joachim Breitner e-Mail: mail@joachim-breitner.de Homepage: http://www.joachim-breitner.de ICQ#: 74513189 From duncan.coutts at worc.ox.ac.uk Mon Nov 13 08:10:03 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Mon Nov 13 08:03:47 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <655793883.20061113154130@gmail.com> References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> Message-ID: <1163423403.7179.354.camel@localhost> On Mon, 2006-11-13 at 15:41 +0300, Bulat Ziganshin wrote: > Hello Duncan, > > Monday, November 13, 2006, 3:36:32 AM, you wrote: > > >> afaik, there are just two good enough libs - wxHaskell and GtkHs. can > > in brief, i see the following main differences: > > - wxHaskell is easier to understand and to use, Ght2Hs allows to use > Glade to develop "look&feel" Easier to understand is rather a matter of personal taste. Certainly Gtk is a big library, providing lots of features. I should also note that one of the main improvements in the upcoming Gtk2Hs release will be to try to simplify the api and improve the reference documentation by making greater use of atribute and signal abstractions rather than lots of getter/setter functions. > - Gtk2Hs had better support, but now wxHaskell has more maintainers and > situation may change to opposite in a next few months It'll be good to have more competition :-) hopefully both systems will improve more rapidly. > - wxHaskell provides more native look&feel, while Gtk2Hs simplifies > porting of GUI application from Windows to Linux. Also Gtk2Hs needs Gtk > DLL to be installed, but this can be made a part of application > installation procedure, afaik? Both Gtk2Hs and wxHaskell need DLLs to be installed and in both cases it can be made part of the install procedure. You just need to bung the right set of dlls in the same directory as the .exe that you distribute. It's exactly the same as with any other windows app that needs extra dlls. > - Gtk2Hs has better memory management > > - differences between Gtk and wxWidgets that i will go to study > > > i also have more questions: first, how about tabbed pages control? > such controls are widely used to represent plenty of information in > limited screen space Both have tab controls. > second: ability and easiness to develop my own controls, and to > combine several customized controls together to make one > "supercontrol" (although i guess that last feature is important only > for RAD environments) > > third: are there any "appetizers" demonstrating features of each > library and with source code available for studying? except for > memory.pdf which don't mention where full source can be downloaded There are a bunch of demos included in the Gtk2Hs sources and there are various apps written by other people available on the web. For example: http://www.cs.kent.ac.uk/projects/pivotal/downloads.html http://haskell.galois.com/~paolo/nymphaea/ Apart from the memory pdf intro there a general intro presentation and a glade tutorial: http://haskell.org/gtk2hs/archives/2006/03/06/introductory-presentation/ http://eddy.writelinux.com/gtk2hs/GladeGtk2Hs.html > it will be interesting to see sources of more "business-like" > applications developed with both libs. if there are no ones, may be i > will develop basic file manager utility as such appetizer That would be great. Duncan From ndmitchell at gmail.com Mon Nov 13 08:43:59 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Mon Nov 13 08:43:13 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <655793883.20061113154130@gmail.com> References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> Message-ID: <404396ef0611130543j488e6054u74bd45cf68202419@mail.gmail.com> Hi > - Gtk2Hs had better support, but now wxHaskell has more maintainers and > situation may change to opposite in a next few months As long as Duncan is around, there will always be enough Gtk2Hs support! Currently Gtk2Hs _has_ better support, the situation may change or may not. Remember that Duncan is not the only Gtk2Hs person, merely the most active :) > - wxHaskell provides more native look&feel Definately true. For GuiHaskell (http://www-users.cs.york.ac.uk/~ndm/projects/guihaskell.php) I was able to get it quite Windows looking with a bit of help from Duncan. As a result of the attempt to make it more Windows like a few Gtk bugs were filed, and it does appear that better Windows GUI styles are something that is already in a Gtk release. > third: are there any "appetizers" demonstrating features of each > library and with source code available for studying? except for > memory.pdf which don't mention where full source can be downloaded The full source code of GuiHaskell is available. The one thing you should be aware of is that Windows + Threading + Gtk2Hs + Gtk + GHC = Pain. I suspect the same equation holds for wxHaskell as well. Ask Duncan for more information if this looks like being a problem. Thanks Neil From bringert at cs.chalmers.se Mon Nov 13 08:47:20 2006 From: bringert at cs.chalmers.se (=?ISO-8859-1?Q?Bj=F6rn_Bringert?=) Date: Mon Nov 13 08:43:25 2006 Subject: [Haskell-cafe] deepSeq vs rnf In-Reply-To: <89ca3d1f0610222019i11d948f1p5f151eee56c05188@mail.gmail.com> References: <89ca3d1f0610222019i11d948f1p5f151eee56c05188@mail.gmail.com> Message-ID: <45587768.4040204@cs.chalmers.se> Cale Gibbard wrote: > On 22/10/06, Chad Scherrer wrote: >> Hi, >> >> I had posted this question a while back, but I think it was in the >> middle of another discussion, and I never did get a reply. Do we >> really need both Control.Parallel.Strategies.rnf and deepSeq? Should >> we not always have >> >> x `deepSeq` y == rnf x `seq` y >> ? >> >> Maybe there's a distinction I'm missing, but it seems to me they're >> basically the same. > > I agree, they are the same. The Strategies library also gives much > more general operations for working with strictness and > parallelisation. That library seems to need more love, I think it's a > great idea, but it doesn't really get noticed all that much. The > Hierarchical libraries documentation for it is a little lacking -- it > doesn't even provide a reference or link to the paper, and many of the > combinators, as well as the general idea of how to use it are > undocumented from there. It also spuriously contains an Assoc > datatype, which if I recall correctly, was an example from the paper, > but doesn't really belong in the library as far as I can tell. It > would also be really nice to see the list of instances for the NFData > class expanded to include other datatypes in the libraries, possibly > also with compiler support for deriving, since it's mostly > boilerplate. I wanted to use the Strategies library and didn't understand much of it, so I sat down and documented it. The darcs version, http://darcs.haskell.org/packages/base/Control/Parallel/Strategies.hs has my changes. If noone objects, I could do some more clean-up, including: - Add NFData instances for common data types, such as - Maybe - Either - Data.Map.Map - Data.Set.Set - Data.Tree.Tree - All Data.Int and Data.Word types - Deprecate sSeq and sPar, as the code comments say that you should use demanding and sparking instead. - Deprecate these defintions, which seem to be examples or Lolita-specific: - Assoc - fstPairFstList - force - sforce If anyone has objections or further suggestions, let me know. /Bj?rn From bulat.ziganshin at gmail.com Mon Nov 13 08:48:14 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Mon Nov 13 08:55:12 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <1163423403.7179.354.camel@localhost> References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> <1163423403.7179.354.camel@localhost> Message-ID: <974586385.20061113164814@gmail.com> Hello Duncan, Monday, November 13, 2006, 4:10:03 PM, you wrote: on the download page only GHC 6.4.1 support mentioned. is 6.4.2 and 6.6 supported on windows? on linux? where i can read about forthcoming gtk2hs version and when it will be released? -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Mon Nov 13 08:59:34 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Mon Nov 13 08:59:07 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <404396ef0611130543j488e6054u74bd45cf68202419@mail.gmail.com> References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> <404396ef0611130543j488e6054u74bd45cf68202419@mail.gmail.com> Message-ID: <1224838352.20061113165934@gmail.com> Hello Neil, Monday, November 13, 2006, 4:43:59 PM, you wrote: > The full source code of GuiHaskell is available. i will at it too > The one thing you should be aware of is that Windows + Threading + > Gtk2Hs + Gtk + GHC = Pain. why? are you tried to call Gtk2Hs from only one thread? -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From lemming at henning-thielemann.de Mon Nov 13 08:59:54 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Mon Nov 13 09:02:46 2006 Subject: [Haskell-cafe] Section Syntax Errors In-Reply-To: References: Message-ID: On Sat, 11 Nov 2006, David House wrote: > On 11/11/06, Aditya Siram wrote: > > subOne :: [Integer] -> [Integer] > > subOne = map (- 1) > > The short answer is that this is interpreted as negative unity, rather > than a section of binary minus. There are two common workarounds: > > subOne = map (subtract 1) > subOne = map (+ (-1)) > > There's a whole minefield of opinions on whether this is the right > syntax or not. I'm sure you could google through the archives to > research this a bit more. E.g. this thread http://www.haskell.org/pipermail/haskell-cafe/2006-August/017403.html continued here: http://www.haskell.org/pipermail/haskell-cafe/2006-September/017941.html From ndmitchell at gmail.com Mon Nov 13 09:06:02 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Mon Nov 13 09:05:16 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <1224838352.20061113165934@gmail.com> References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> <404396ef0611130543j488e6054u74bd45cf68202419@mail.gmail.com> <1224838352.20061113165934@gmail.com> Message-ID: <404396ef0611130606t5b06b24eu534b13c1e5eade94@mail.gmail.com> Hi Bulat, http://haskell.org/~duncan/gtk2hs/gtk2hs-0.9.10.exe That's the most recent Gtk2Hs for 6.4.2. > > The one thing you should be aware of is that Windows + Threading + > > Gtk2Hs + Gtk + GHC = Pain. > > why? are you tried to call Gtk2Hs from only one thread? I think so, yes. Or there are bizare -threaded restrictions. Only Duncan (and perhaps Simon Marlow) understand this. I merely got bit by it... Thanks Neil From bulat.ziganshin at gmail.com Mon Nov 13 09:10:34 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Mon Nov 13 09:10:08 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <404396ef0611130606t5b06b24eu534b13c1e5eade94@mail.gmail.com> References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> <404396ef0611130543j488e6054u74bd45cf68202419@mail.gmail.com> <1224838352.20061113165934@gmail.com> <404396ef0611130606t5b06b24eu534b13c1e5eade94@mail.gmail.com> Message-ID: <844844545.20061113171034@gmail.com> Hello Neil, Monday, November 13, 2006, 5:06:02 PM, you wrote: > http://haskell.org/~duncan/gtk2hs/gtk2hs-0.9.10.exe > That's the most recent Gtk2Hs for 6.4.2. the http://haskell.org/gtk2hs/download/ page says that gtk2hs is available only for 6.4.1 >> > The one thing you should be aware of is that Windows + Threading + >> > Gtk2Hs + Gtk + GHC = Pain. >> >> why? are you tried to call Gtk2Hs from only one thread? > I think so, yes. Or there are bizare -threaded restrictions. Only > Duncan (and perhaps Simon Marlow) understand this. I merely got bit by > it... it will be great to see comments about this. it's impossible to write my program without using threaded RTS -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From wferi at niif.hu Mon Nov 13 09:19:55 2006 From: wferi at niif.hu (Ferenc Wagner) Date: Mon Nov 13 09:19:09 2006 Subject: [Haskell-cafe] Re: best Linux for GHC? In-Reply-To: <1596152630.20061113133613@gmail.com> (Bulat Ziganshin's message of "Mon, 13 Nov 2006 13:36:13 +0300") References: <524915860.20061113023645@gmail.com> <5bbe25930611121645r52ec16f9w552cbbe71b4984a1@mail.gmail.com> <455822B7.6070803@ii.uib.no> <1596152630.20061113133613@gmail.com> Message-ID: <87y7qfv378.fsf@tac.ki.iif.hu> Bulat Ziganshin writes: > of remaining, Ubuntu has widest support here while SuSe is favourite > of my friend. one thing that i like in suse is that it uses the same > RPMs as RedHat and RPMs is widely used for packaging software > available via internet. Is Ubuntu supports RPMs too? Hi Bulat, forget RPM's, real men use DEB's. Ubuntu -- being a Debian derivative -- does so, too. Btw Debian unstable has got GHC 6.6, and isn't unstable nowadays, except for the name. Better call it Sid; the freezing process has already begun. If you are interested in a stable system with GHC 6.6, go with Debian Sid until it transforms into Etch (the next stable version). Then you can forget hacking Linux for a couple of years. On the other hand, it will probably take some months until release, which brings some risk in the game. -- Regards, Feri. From max.vasin at gmail.com Mon Nov 13 09:42:08 2006 From: max.vasin at gmail.com (Max Vasin) Date: Mon Nov 13 09:46:02 2006 Subject: [Haskell-cafe] Re: best Linux for GHC? References: <524915860.20061113023645@gmail.com> <5bbe25930611121645r52ec16f9w552cbbe71b4984a1@mail.gmail.com> <455822B7.6070803@ii.uib.no> <1596152630.20061113133613@gmail.com> Message-ID: <87d57rl873.fsf@smtp.gmail.com> Yes, but I wouldn't recommend installing rpms in debian-based system (although, it can work perfectly). GHC 6.6 is in Debian unstable (and should be in Ubuntu 6.10 or development branch). Ubuntu universe repositiry is automatically updated from Debian repos thus being one of the largest repos for Linux. PS: I'm using Debian testing/unstable. -- WBR, Max Vasin From max.vasin at gmail.com Mon Nov 13 09:51:47 2006 From: max.vasin at gmail.com (Max Vasin) Date: Mon Nov 13 09:55:59 2006 Subject: [Haskell-cafe] Re: what GUI library should i select? References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> <1163423403.7179.354.camel@localhost> <974586385.20061113164814@gmail.com> Message-ID: <878xifl7r0.fsf@smtp.gmail.com> On linux you should use your package manager (whenever possible), not binaries from the site (or compile it yourself). -- WBR, Max Vasin. From max.vasin at gmail.com Mon Nov 13 09:56:03 2006 From: max.vasin at gmail.com (Max Vasin) Date: Mon Nov 13 10:04:44 2006 Subject: [Haskell-cafe] Re: best Linux for GHC? References: <524915860.20061113023645@gmail.com> <5bbe25930611121645r52ec16f9w552cbbe71b4984a1@mail.gmail.com> <455822B7.6070803@ii.uib.no> <1596152630.20061113133613@gmail.com> <87y7qfv378.fsf@tac.ki.iif.hu> Message-ID: <87veljjszg.fsf@smtp.gmail.com> I think Haskell packages from sid can be installed on etch with no harm (or problem). All you need is to configure apt to use both testing and unstable. -- WBR, Max Vasin. From valentin.gjorgjioski at ijs.si Mon Nov 13 10:32:34 2006 From: valentin.gjorgjioski at ijs.si (Valentin Gjorgjioski) Date: Mon Nov 13 10:31:59 2006 Subject: [Haskell-cafe] Haskell Debugging Message-ID: <45589012.9060708@ijs.si> I'm pretty new in Haskell, few days since I started learning it. I want to debu my programs. I'm currently using WinHugs, and I prefer debugger for this. I tried googling and I found Hugs.Observer. I like it how it works, but still I have one BIG problem with it. It doesn't work well with floats. Following example import Hugs.Observe ex8 :: [Float] ex8 = (observe "after reverse" ) reverse [10.0,7.0,3.0,0.0,4.0] gives me >ex8 [4.0,0.0,3.0,7.0,10.0] >>>>>>> Observations <<<<<< after reverse { \ ($-990871 : $-990888 : $-990905 : $-990922 : $-990939 : []) -> $-990939 : $-990922 : $-990905 : $-990888 : $-990871 : [] } Which is not useful. After that I try to install http://www.haskell.org/hat/ but for installing that I need hmake, and when I try to install hmake, I typed first configure -prefix, and then, make. cd src/hmake; make HC=ghc BUILDCOMP=ghc all config make[1]: Entering directory `/cygdrive/E/Haskell/hmake/src/hmake' Makefile:59: *** target pattern contains no `%'. Stop. make[1]: Leaving directory `/cygdrive/E/Haskell/hmake/src/hmake' make: *** [targets/ix86-CYGWIN_NT-5.1/hmake-ghc] Error 2 as you can see I'm using cygwin. I'm really stacked here, and I will kindly ask for help. Thanks, Valentin -- Valentin Gjorgjioski Bachelor of Computer Science Department of Knowledge Technologies, Jozef Stefan Institute Jamova 39, SI-1000 Ljubljana, Slovenia Phone: +386 1 477 3343 Fax: +386 1 477 3315 Web: http://kt.ijs.si/ValentinGjorgjioski/ Email: Valentin.Gjorgjioski@ijs.si From mnislaih at gmail.com Mon Nov 13 10:48:07 2006 From: mnislaih at gmail.com (Pepe Iborra) Date: Mon Nov 13 10:47:26 2006 Subject: [Haskell-cafe] Haskell Debugging In-Reply-To: <45589012.9060708@ijs.si> References: <45589012.9060708@ijs.si> Message-ID: Hi Valentin Please, take a look at the Haskell Wiki page for debugging. http://haskell.org/haskellwiki/Debugging You will find that thanks to Neil Mitchell there is a Windows version of Hat available. Perhaps you can add your experiences with it if it works for you. pepe On 13/11/2006, at 16:32, Valentin Gjorgjioski wrote: > I'm pretty new in Haskell, few days since I started learning it. I > want to debu my programs. I'm currently using WinHugs, and I prefer > debugger for this. > > I tried googling and I found Hugs.Observer. > > I like it how it works, but still I have one BIG problem with it. > It doesn't work well with floats. > > Following example > > import Hugs.Observe > > ex8 :: [Float] > ex8 = (observe "after reverse" ) reverse [10.0,7.0,3.0,0.0,4.0] > > gives me > > >ex8 > [4.0,0.0,3.0,7.0,10.0] > > >>>>>>> Observations <<<<<< > > after reverse > { \ ($-990871 : $-990888 : $-990905 : $-990922 : $-990939 : []) - > > $-990939 : $-990922 : $-990905 : $-990888 : $-990871 : [] > } > > Which is not useful. After that I try to install > > http://www.haskell.org/hat/ > > but for installing that I need hmake, and when I try to install > hmake, I typed first configure -prefix, and then, make. > > cd src/hmake; make HC=ghc BUILDCOMP=ghc all config > make[1]: Entering directory `/cygdrive/E/Haskell/hmake/src/hmake' > Makefile:59: *** target pattern contains no `%'. Stop. > make[1]: Leaving directory `/cygdrive/E/Haskell/hmake/src/hmake' > make: *** [targets/ix86-CYGWIN_NT-5.1/hmake-ghc] Error 2 > > as you can see I'm using cygwin. > > I'm really stacked here, and I will kindly ask for help. > > > Thanks, > Valentin > > > -- > Valentin Gjorgjioski > Bachelor of Computer Science > Department of Knowledge Technologies, Jozef Stefan Institute > Jamova 39, SI-1000 Ljubljana, Slovenia > Phone: +386 1 477 3343 > Fax: +386 1 477 3315 > Web: http://kt.ijs.si/ValentinGjorgjioski/ > Email: Valentin.Gjorgjioski@ijs.si > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From Mark.Carroll at Aetion.com Mon Nov 13 10:48:51 2006 From: Mark.Carroll at Aetion.com (Mark T.B. Carroll) Date: Mon Nov 13 10:48:04 2006 Subject: [Haskell-cafe] Re: best Linux for GHC? In-Reply-To: <87d57rl873.fsf@smtp.gmail.com> (Max Vasin's message of "Mon, 13 Nov 2006 17:42:08 +0300") References: <524915860.20061113023645@gmail.com> <5bbe25930611121645r52ec16f9w552cbbe71b4984a1@mail.gmail.com> <455822B7.6070803@ii.uib.no> <1596152630.20061113133613@gmail.com> <87d57rl873.fsf@smtp.gmail.com> Message-ID: <87mz6vqrdo.fsf@ixod.org> Max Vasin writes: > Yes, but I wouldn't recommend installing rpms in debian-based system > (although, it can work perfectly). GHC 6.6 is in Debian unstable > (and should be in Ubuntu 6.10 or development branch). Ubuntu universe > repositiry is automatically updated from Debian repos thus being > one of the largest repos for Linux. > > PS: I'm using Debian testing/unstable. How up to date will Debian unstable's GHC be kept, though? It seems pretty good at the moment, but there have been times when we've had to install from source instead of via Debian earlier this year so that we had GHC features and bugfixes in place - the Debian version has got rather out of date at times with respect to stuff we needed. -- Mark From asandroq at gmail.com Mon Nov 13 10:50:57 2006 From: asandroq at gmail.com (Alex Queiroz) Date: Mon Nov 13 10:50:12 2006 Subject: [Haskell-cafe] Re: best Linux for GHC? In-Reply-To: <87mz6vqrdo.fsf@ixod.org> References: <524915860.20061113023645@gmail.com> <5bbe25930611121645r52ec16f9w552cbbe71b4984a1@mail.gmail.com> <455822B7.6070803@ii.uib.no> <1596152630.20061113133613@gmail.com> <87d57rl873.fsf@smtp.gmail.com> <87mz6vqrdo.fsf@ixod.org> Message-ID: <54e12800611130750y599f1a18seb51427c0aeaed37@mail.gmail.com> Hallo, On 11/13/06, Mark T.B. Carroll wrote: > > How up to date will Debian unstable's GHC be kept, though? It seems > pretty good at the moment, but there have been times when we've had to > install from source instead of via Debian earlier this year so that we > had GHC features and bugfixes in place - the Debian version has got > rather out of date at times with respect to stuff we needed. > No OpenGL neither Gtk2hs in Debian Sid yet. :-( -- -alex http://www.ventonegro.org/ From valentin.gjorgjioski at ijs.si Mon Nov 13 10:54:16 2006 From: valentin.gjorgjioski at ijs.si (Valentin Gjorgjioski) Date: Mon Nov 13 10:53:39 2006 Subject: [Haskell-cafe] Haskell Debugging In-Reply-To: References: <45589012.9060708@ijs.si> Message-ID: <45589528.2030302@ijs.si> On 13.11.2006 16:48 Pepe Iborra wrote: > Hi Valentin > > Please, take a look at the Haskell Wiki page for debugging. > > http://haskell.org/haskellwiki/Debugging > > You will find that thanks to Neil Mitchell there is a Windows version > of Hat available. Perhaps you can add your experiences with it if it > works for you. > Oh silly me, I was looking that page, but I didn't notice this. Thanks a lot, pepe. I'll try, and I'll post feedback here. Valentin From valentin.gjorgjioski at ijs.si Mon Nov 13 11:29:39 2006 From: valentin.gjorgjioski at ijs.si (Valentin Gjorgjioski) Date: Mon Nov 13 11:29:03 2006 Subject: [Haskell-cafe] Haskell Debugging In-Reply-To: <45589528.2030302@ijs.si> References: <45589012.9060708@ijs.si> <45589528.2030302@ijs.si> Message-ID: <45589D73.5010507@ijs.si> On 13.11.2006 16:54 Valentin Gjorgjioski wrote: > On 13.11.2006 16:48 Pepe Iborra wrote: >> Hi Valentin >> >> Please, take a look at the Haskell Wiki page for debugging. >> >> http://haskell.org/haskellwiki/Debugging >> >> You will find that thanks to Neil Mitchell there is a Windows version >> of Hat available. Perhaps you can add your experiences with it if it >> works for you. >> > Oh silly me, I was looking that page, but I didn't notice this. Thanks > a lot, pepe. > I'll try, and I'll post feedback here. > I install it, I tried it, and it doesn't work for me. ./Hat/DML.hs:535:66: Ambiguous type variable `a' in the constraint: `Integral a' arising from use of `*^' at ./Hat/DML.hs:535:66-69 Probable fix: add a type signature that fixes these type variable(s) And this is line 535.... T.uapp2 p125v94v125v148 p125v147v125v147 p (+^) (*^) After that, I have in my code used operator ^, and I deleted that operator. Program finally compiled, but now, hat-observe reports me an error... this program has encountered a problem.... So, I will be really happy with something simple as Hugs.Observe if it works with floats. Some recommendation please? Valentin From sylvan at student.chalmers.se Mon Nov 13 11:35:03 2006 From: sylvan at student.chalmers.se (Sebastian Sylvan) Date: Mon Nov 13 11:34:26 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <844844545.20061113171034@gmail.com> References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> <404396ef0611130543j488e6054u74bd45cf68202419@mail.gmail.com> <1224838352.20061113165934@gmail.com> <404396ef0611130606t5b06b24eu534b13c1e5eade94@mail.gmail.com> <844844545.20061113171034@gmail.com> Message-ID: <3d96ac180611130835p52a9d22fn7190a86dd4e73d81@mail.gmail.com> On 11/13/06, Bulat Ziganshin wrote: > Hello Neil, > > Monday, November 13, 2006, 5:06:02 PM, you wrote: > > > http://haskell.org/~duncan/gtk2hs/gtk2hs-0.9.10.exe > > > That's the most recent Gtk2Hs for 6.4.2. > > the http://haskell.org/gtk2hs/download/ page says that gtk2hs is > available only for 6.4.1 > > > >> > The one thing you should be aware of is that Windows + Threading + > >> > Gtk2Hs + Gtk + GHC = Pain. > >> > >> why? are you tried to call Gtk2Hs from only one thread? > > > I think so, yes. Or there are bizare -threaded restrictions. Only > > Duncan (and perhaps Simon Marlow) understand this. I merely got bit by > > it... > > it will be great to see comments about this. it's impossible to write > my program without using threaded RTS I'm not an expert, but I think the only solutions available depend on some sort of polling. E.g. you could start the GUI in a single bound thread, and then pass in all GUI calls to a channel. Then you would attach an event handler to idle event (or a timer) which checks to see if there are any items in the channel, and if so runs them in the GUI thread. The problem is that you can't actually run GUI actions from other threads, you can only schedule them to be run by the GUI thread, and you can't actually "insert" your "block on the UI actions queue as well as message queue" in the GTK event loop. So you have to every now and then do this yourself. This could end up in a situation where you very often check this channel and it's empty, which uses unnecessary resources, or it could end up in a situation where you don't check it often enough and any UI actions caused by other threads get delayed. I suspect that a more sophistated scheduler could be written which helps with most of this (i.e. use a timer with some default value, if there are many items in the channel then decrease the timout value, if there are no items in the channel increase the timout value up to some maximum). /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862 From mnislaih at gmail.com Mon Nov 13 12:08:33 2006 From: mnislaih at gmail.com (Pepe Iborra) Date: Mon Nov 13 12:07:53 2006 Subject: [Haskell-cafe] Haskell Debugging In-Reply-To: <45589D73.5010507@ijs.si> References: <45589012.9060708@ijs.si> <45589528.2030302@ijs.si> <45589D73.5010507@ijs.si> Message-ID: <6F871804-DC77-45A0-B5DD-DC98462FCBB3@gmail.com> Can you manage to compile GHC under Windows? Compiling GHC under Windows is known to be a bit tricky and time consuming, certainly not for the novice user, although the steps are well detailed in the GHC developer documentation. If so, I'd encourage you to play with the Ghci Debugger project. But beware, it is still in an experimental phase and there are some pending issues. If you want to try it I have set up the repository to point to the "last good known" version I have around. Just follow the instructions on how to get the patches in the wiki page. Otherwise, I'd advise you to stick to Debug.Trace and friends. Cheers pepe On 13/11/2006, at 17:29, Valentin Gjorgjioski wrote: > On 13.11.2006 16:54 Valentin Gjorgjioski wrote: >> On 13.11.2006 16:48 Pepe Iborra wrote: >>> Hi Valentin >>> >>> Please, take a look at the Haskell Wiki page for debugging. >>> >>> http://haskell.org/haskellwiki/Debugging >>> >>> You will find that thanks to Neil Mitchell there is a Windows >>> version of Hat available. Perhaps you can add your experiences >>> with it if it works for you. >>> >> Oh silly me, I was looking that page, but I didn't notice this. >> Thanks a lot, pepe. >> I'll try, and I'll post feedback here. >> > I install it, I tried it, and it doesn't work for me. > > ./Hat/DML.hs:535:66: > Ambiguous type variable `a' in the constraint: > `Integral a' arising from use of `*^' at ./Hat/DML.hs:535:66-69 > Probable fix: add a type signature that fixes these type variable(s) > > And this is line 535.... > T.uapp2 p125v94v125v148 p125v147v125v147 p (+^) (*^) > > After that, I have in my code used operator ^, and I deleted that > operator. Program finally compiled, but now, hat-observe reports me > an error... this program has encountered a problem.... > > So, I will be really happy with something simple as Hugs.Observe if > it works with floats. Some recommendation please? > Valentin > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From luis at arjox.org Mon Nov 13 12:21:57 2006 From: luis at arjox.org (Luis F. Araujo) Date: Mon Nov 13 12:22:18 2006 Subject: [Haskell-cafe] Re: best Linux for GHC? In-Reply-To: <455899A6.7070401@arjox.org> References: <524915860.20061113023645@gmail.com> <5bbe25930611121645r52ec16f9w552cbbe71b4984a1@mail.gmail.com> <455822B7.6070803@ii.uib.no> <1596152630.20061113133613@gmail.com> <87d57rl873.fsf@smtp.gmail.com> <87mz6vqrdo.fsf@ixod.org> <54e12800611130750y599f1a18seb51427c0aeaed37@mail.gmail.com> <455899A6.7070401@arjox.org> Message-ID: <4558A9B5.7060607@arjox.org> Alex Queiroz wrote: >> Hallo, >> >> On 11/13/06, Mark T.B. Carroll wrote: >> >>> How up to date will Debian unstable's GHC be kept, though? It seems >>> pretty good at the moment, but there have been times when we've had to >>> install from source instead of via Debian earlier this year so that we >>> had GHC features and bugfixes in place - the Debian version has got >>> rather out of date at times with respect to stuff we needed. >>> >>> >> No OpenGL neither Gtk2hs in Debian Sid yet. :-( >> I'd recommend Gentoo for using these kind of packages. We even have darcs repository versions of Gtk2Hs in our gentoo haskell overlay. Regards, From lemming at henning-thielemann.de Mon Nov 13 12:29:19 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Mon Nov 13 12:30:30 2006 Subject: [Haskell-cafe] Testing non-exported functions using ghci In-Reply-To: <1163421887.3953.0.camel@otto.ehbuehl.net> References: <1163421887.3953.0.camel@otto.ehbuehl.net> Message-ID: On Mon, 13 Nov 2006, Joachim Breitner wrote: > Am Montag, den 13.11.2006, 21:24 +1100 schrieb John Ky: > > I have modules that don't export some functions. Is there a way I can > > access them from ghci without exporting them? > > It seems that if there are .hi files around, ghci can't reach the > non-exported functions, but if you delete this file, it works. or 'touch' the source module http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-compiled.html From twd_gg at dockerz.net Mon Nov 13 13:00:19 2006 From: twd_gg at dockerz.net (Tim Docker) Date: Mon Nov 13 12:59:39 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <1344369241.20061113025003@gmail.com> References: <1344369241.20061113025003@gmail.com> Message-ID: <24253.217.150.105.195.1163440819.squirrel@dockerz.net> > afaik, there are just two good enough libs - wxHaskell and GtkHs. can > anyone point (or write) detailed comparison of their features? One point in wxHaskell's favour is that it supports Mac OS X directly. At present, to the best of my knowledge, you can only run GtkHs applications on OS X using the X Windows server. Whilst this works, it's a _long_ way from native look and feel. If OS X support is significant to you, this may sway your decision. Tim From magnus at therning.org Mon Nov 13 08:38:27 2006 From: magnus at therning.org (Magnus Therning) Date: Mon Nov 13 13:11:15 2006 Subject: [Haskell-cafe] best Linux for GHC? In-Reply-To: <1596152630.20061113133613@gmail.com> References: <524915860.20061113023645@gmail.com> <5bbe25930611121645r52ec16f9w552cbbe71b4984a1@mail.gmail.com> <455822B7.6070803@ii.uib.no> <1596152630.20061113133613@gmail.com> Message-ID: <20061113133827.GC2063@die.therning.org> On Mon, Nov 13, 2006 at 13:36:13 +0300, Bulat Ziganshin wrote: >Hello Ketil, > >Monday, November 13, 2006, 10:45:59 AM, you wrote: > >>>> My friend offered me 3 variants: SuSe, Fedora Core 5, free variant of >>>> RedHat (i can't remember its name, may be Ubuntu?) >> CentOS, perhaps? It is usually good advice to choose whatever your >> friends are using, > >thanks to everyone who answered my question! > >as you say, FC and CentOS are not ideal for me. Gentoo is too good for >me, it is for unix geeks while i just don't have resources to play one >more Game. i think that i will install it on my next box > >of remaining, Ubuntu has widest support here while SuSe is favourite of >my friend. one thing that i like in suse is that it uses the same RPMs >as RedHat and RPMs is widely used for packaging software available via >internet. Is Ubuntu supports RPMs too? I think it's widely regarded as a Bad Idea to mix packages between distributions. I would suggest Ubuntu (or Debian Sid if you are interested in getting newer versions of GHC). I think you'd find it difficult to find software that wasn't already in Ubuntu's multiverse repository. /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus Software is not manufactured, it is something you write and publish. Keep Europe free from software patents, we do not want censorship by patent law on written works. `In those days spirits were brave, the stakes were high, men were REAL men, women were REAL women, and small furry creatures from Alpha Centauri were REAL small furry creatures from Aplha Centauri.' -- The Book getting all nostalgic. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061113/9d24927d/attachment.bin From luis at arjox.org Mon Nov 13 13:14:54 2006 From: luis at arjox.org (Luis F. Araujo) Date: Mon Nov 13 13:15:13 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <4557E3EA.8080303@babel.ls.fi.upm.es> References: <1344369241.20061113025003@gmail.com> <404396ef0611121710g2b1c0b4dp1d06fa906ae05ec1@mail.gmail.com> <4557E3EA.8080303@babel.ls.fi.upm.es> Message-ID: <4558B61E.3040009@arjox.org> Iv?n P?rez Dom?nguez wrote: > Neil Mitchell wrote: > >> Hi Bulat, >> >> >>> afaik, there are just two good enough libs - wxHaskell and GtkHs. can >>> anyone point (or write) detailed comparison of their features? i plan >>> to write large GUI program in Haskell and want to select best one. >>> the requirements that i can imagine at this moment is the following: >>> >> I used to use wxHaskell. >> > > So did I. I tried gtk2hs as well. In my experience, gtk2hs is more > complicated. On the other hand, gtk2hs supports glade, I think. > OK, i feel like i need to give my personal opinion about this. I have been using Gtk2Hs since a bit more of a year now, and though i don't consider myself a GUI guy, i gotta say it _has_ been very easy to use for me. Most of the operations while reasoning in terms of the gtk2hs API summarizes up on: - Creating windows - Creating and adding containers into these windows with a specific layout. - Creating and adding objects (widgets) inside these containers. - Link widget-specific events with Haskell functions implementing the desired functionality. Each of these general operations translate to very well defined functions, making it a very concise and easy-to-use API imho; plus you have the automatic garbage collection feature. Besides that, you have plenty of very good documentation on the gtk2hs web site; even with a hoogle interface to search on the API. I really don't see where it is the complicated part. > wxHaskell seems to be easier to understand and to use. In my case, I > took a reversi game from haskell.org and did a sudoku game in a few > weeks (with no prior knowledge on wxHaskell). > > I wanted to write a GUI program using GHC > >> 6.4.2 and was (disturbingly) shocked to find out that _neither_ of the >> GUI toolkits had prebuilt packages that worked on Windows with GHC >> 6.4.2. I complained and within a day Duncan had done one for Gtk2Hs, >> and to my knowledge wxHaskell still doesn't have such a packaged >> version. >> >> > > I'm using Gentoo Linux. We obviously don't use prebuilt packaged > versions, but installing it is just doing "emerge wxhaskell" and > 'playing the... waiting game'. Gtk2hs support under Gentoo is mostly > missing (the package is included, but doesn't work at all). > > We even have a gtk2hs darcs repository (optional to the stable package) version available on Gentoo through the Haskell overlay. Though we appreciate if you give us more detail about the 'missing' support. >> For this reason, I would recommend Gtk2Hs - the level of support and >> maintainership is far better than wxHaskell at the moment. I >> appreciate wxHaskell has new maintainers, but when picking a GUI >> toolkit where you can't easily switch later, currently maintained is a >> big bullet point for me! >> I agree. Regards, From luis at arjox.org Mon Nov 13 13:24:05 2006 From: luis at arjox.org (Luis F. Araujo) Date: Mon Nov 13 13:24:24 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <655793883.20061113154130@gmail.com> References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> Message-ID: <4558B845.3000205@arjox.org> Bulat Ziganshin wrote: > third: are there any "appetizers" demonstrating features of each > library and with source code available for studying? except for > memory.pdf which don't mention where full source can be downloaded > > it will be interesting to see sources of more "business-like" > applications developed with both libs. if there are no ones, may be i > will develop basic file manager utility as such appetizer > There are plenty of nice gtk2hs examples out there. You can take a look at [1]himerge, one of the applications i've been developing with gtk2hs as an example, which uses several features and common functionalities for most GUI. Regards, [1] http://www.arjox.org/himerge.html From duncan.coutts at worc.ox.ac.uk Mon Nov 13 13:51:10 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Mon Nov 13 13:44:52 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <974586385.20061113164814@gmail.com> References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> <1163423403.7179.354.camel@localhost> <974586385.20061113164814@gmail.com> Message-ID: <1163443870.7179.366.camel@localhost> On Mon, 2006-11-13 at 16:48 +0300, Bulat Ziganshin wrote: > Hello Duncan, > > Monday, November 13, 2006, 4:10:03 PM, you wrote: > > on the download page only GHC 6.4.1 support mentioned. is 6.4.2 and > 6.6 supported on windows? The last official release for Windows supports GHC 6.2.2 and 6.4.1. I made another build for 6.4.2 here: http://haskell.org/~duncan/gtk2hs/gtk2hs-0.9.10.exe > on linux? It builds from source fine on linux. There are also packages for some distros, like Gentoo, Debian, Fedora etc. As for 6.6, the current development version works fine with 6.6 and so of course the forthcoming release will do to. There will be new binary builds for windows too. > where i can read about forthcoming gtk2hs version and when it will be > released? You can subscribe to the gtk2hs-users list to get advance notice of the release and help with testing for your favourite platform. We're aiming for a 0.9.11 release before Christmas. This release will change the API slightly so we want to make sure we get it right. We don't want to have to change the api often as it's annoying. So I hope you understand why it will not be released immediately. Of course you are welcome to use the development version in the meantime. This release cycle has been rather longer than we would have liked, I expect the next one will be much shorter. Details are on the Gtk2Hs website of how to subscribe to the mailing list and how to get the development version with darcs: http://haskell.org/gtk2hs/development/ Duncan From duncan.coutts at worc.ox.ac.uk Mon Nov 13 14:03:23 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Mon Nov 13 13:57:05 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <24253.217.150.105.195.1163440819.squirrel@dockerz.net> References: <1344369241.20061113025003@gmail.com> <24253.217.150.105.195.1163440819.squirrel@dockerz.net> Message-ID: <1163444603.7179.371.camel@localhost> On Mon, 2006-11-13 at 18:00 +0000, Tim Docker wrote: > > afaik, there are just two good enough libs - wxHaskell and GtkHs. can > > anyone point (or write) detailed comparison of their features? > > One point in wxHaskell's favour is that it supports Mac OS X directly. At > present, to the best of my knowledge, you can only run GtkHs applications > on OS X using the X Windows server. Whilst this works, it's a _long_ way > from native look and feel. This is quite true. Fortunately the Gtk+ folk are well underway with a project to make it all more native looking. The latest released version of Gtk+ 2.10.x has 'experimental' support for running on OSX without using X11. The next step (apart from general bug fixing) is to use the right native theme. So yes, at the moment it doesn't look native on OSX but hopefully in the future it will. You can read more about that here: http://developer.imendio.com/projects/gtk-macosx Duncan From duncan.coutts at worc.ox.ac.uk Mon Nov 13 14:19:16 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Mon Nov 13 14:12:56 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <844844545.20061113171034@gmail.com> References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> <404396ef0611130543j488e6054u74bd45cf68202419@mail.gmail.com> <1224838352.20061113165934@gmail.com> <404396ef0611130606t5b06b24eu534b13c1e5eade94@mail.gmail.com> <844844545.20061113171034@gmail.com> Message-ID: <1163445556.7179.386.camel@localhost> On Mon, 2006-11-13 at 17:10 +0300, Bulat Ziganshin wrote: > >> > The one thing you should be aware of is that Windows + Threading + > >> > Gtk2Hs + Gtk + GHC = Pain. > >> > >> why? are you tried to call Gtk2Hs from only one thread? > > > I think so, yes. Or there are bizare -threaded restrictions. Only > > Duncan (and perhaps Simon Marlow) understand this. I merely got bit by > > it... > > it will be great to see comments about this. it's impossible to write > my program without using threaded RTS This is a problem for all GUI libs, it's not something that's different between Gtk2Hs and wxHaskell. I think the problem is better understood in Gtk2Hs because we have tried to tackle it. I've written some multi-threaded GUI apps when using the single-threaded RTS. I have no idea if you can use threads with wxHaskell, you'd have to ask someone who knows more about it. As for the threaded RTS, currently that's only ok if you never make GUI calls from more than one Haskell thread. The reason for the restriction is that GUI libs like wxWiddgets and Gtk+ are really designed to be used in a single threaded manner[1]. I know Gtk+ does have some support for using multiple threads but it requires a lot of explicit locking so it's not easy to use from Haskell where we expect to be able to use light weight threads with ease. The problem at the moment with GUIs and GHC's threaded RTS is that there is now way to specify that all the Haskell threads that want to do GUI stuff must run on a single OS thread. It's not impossible to solve but it requires either more support from the RTS or it needs a totally different approach, perhaps using a Haskell-level threading GUI monad rather than the IO monad. Duncan [1] in fact on windows it's even worse, not only must there be no concurrent modification of GUI objects but the windows GDI enforces that *only* the thread that created an object may access/modify that object. That's a pretty severe restriction which is why we would normally say that the GUI is just single threaded rather than going into the nasty details of how exactly you really do GUIs with multiple OS threads. It's so hard to do that it's effectively just single threaded. From donn at drizzle.com Mon Nov 13 15:11:43 2006 From: donn at drizzle.com (Donn Cave) Date: Mon Nov 13 15:11:03 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <4558B845.3000205@arjox.org> Message-ID: I notice that the Socket returned by ghc Network.Socket (socket) has been set non-blocking. (Noticed empirically, not from documentation.) The Network.Socket functions that use it, e.g., recv, are ready for that, of course, but as a general rule, external functions that expect a socket are very likely not. So I hacked up a crude fcntl call to undo the damage and restore my socket to normal default mode, but it makes me wonder what moved the ghc library authors to depart from common usage in this respect, and provide no obvious means for the programmer to restore the normal mode? Threads, maybe? Is blocking I/O seriously incompatible with the GHC threading model (or one of the models)? If I have external library functions that use socket I/O internally, e.g., an OpenLDAP interface, that's effectively the same as a blocking socket created in Haskell, so whatever problem with one is the same with the other, right? thanks, Donn Cave, donn@drizzle.com From bulat.ziganshin at gmail.com Mon Nov 13 14:31:12 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Mon Nov 13 15:27:12 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <1163445556.7179.386.camel@localhost> References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> <404396ef0611130543j488e6054u74bd45cf68202419@mail.gmail.com> <1224838352.20061113165934@gmail.com> <404396ef0611130606t5b06b24eu534b13c1e5eade94@mail.gmail.com> <844844545.20061113171034@gmail.com> <1163445556.7179.386.camel@localhost> Message-ID: <387065214.20061113223112@gmail.com> Hello Duncan, Monday, November 13, 2006, 10:19:16 PM, you wrote: >> >> why? are you tried to call Gtk2Hs from only one thread? >> it will be great to see comments about this. it's impossible to write >> my program without using threaded RTS > As for the threaded RTS, currently that's only ok if you never make GUI > calls from more than one Haskell thread. it is what i say about. threaded RTS + multipls threads that does computations + one thread that interfaces with Gtk2Hs. afaiu, the only problem is that i need to manage both Gtk events and periodically check queue of commands from other threads, but using timer + Chan should allow to implement this -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From donn at drizzle.com Mon Nov 13 15:44:05 2006 From: donn at drizzle.com (Donn Cave) Date: Mon Nov 13 15:43:25 2006 Subject: [Haskell-cafe] non-blocking Socket In-Reply-To: Message-ID: [reposted with improved subject] I notice that the Socket returned by ghc Network.Socket (socket) has been set non-blocking. (Noticed empirically, not from documentation.) The Network.Socket functions that use it, e.g., recv, are ready for that, of course, but as a general rule, external functions that expect a socket are very likely not. So I hacked up a crude fcntl call to undo the damage and restore my socket to normal default mode, but it makes me wonder what moved the ghc library authors to depart from common usage in this respect, and provide no obvious means for the programmer to restore the normal mode? Threads, maybe? Is blocking I/O seriously incompatible with the GHC threading model (or one of the models)? If I have external library functions that use socket I/O internally, e.g., an OpenLDAP interface, that's effectively the same as a blocking socket created in Haskell, so whatever problem with one is the same with the other, right? thanks, Donn Cave, donn@drizzle.com From ben_moseley at mac.com Mon Nov 13 15:49:10 2006 From: ben_moseley at mac.com (Ben Moseley) Date: Mon Nov 13 15:45:02 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <1163444603.7179.371.camel@localhost> References: <1344369241.20061113025003@gmail.com> <24253.217.150.105.195.1163440819.squirrel@dockerz.net> <1163444603.7179.371.camel@localhost> Message-ID: <396855AC-5E4D-4812-BC74-C49735BB52D4@mac.com> Has anyone succeeded in getting it running on OSX/intel at all? ...I had a brief go a few weeks back, managed to get the Cairo Clock running, but anything that used GTK seemed to blow up instantly. (OSX/ ppc was fine). --Ben On 13 Nov 2006, at 19:03, Duncan Coutts wrote: > On Mon, 2006-11-13 at 18:00 +0000, Tim Docker wrote: >>> afaik, there are just two good enough libs - wxHaskell and GtkHs. >>> can >>> anyone point (or write) detailed comparison of their features? >> >> One point in wxHaskell's favour is that it supports Mac OS X >> directly. At >> present, to the best of my knowledge, you can only run GtkHs >> applications >> on OS X using the X Windows server. Whilst this works, it's a >> _long_ way >> from native look and feel. > > This is quite true. Fortunately the Gtk+ folk are well underway with a > project to make it all more native looking. The latest released > version > of Gtk+ 2.10.x has 'experimental' support for running on OSX without > using X11. The next step (apart from general bug fixing) is to use the > right native theme. > > So yes, at the moment it doesn't look native on OSX but hopefully > in the > future it will. You can read more about that here: > > http://developer.imendio.com/projects/gtk-macosx > > Duncan > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From duncan.coutts at worc.ox.ac.uk Mon Nov 13 16:01:00 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Mon Nov 13 15:54:40 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <396855AC-5E4D-4812-BC74-C49735BB52D4@mac.com> References: <1344369241.20061113025003@gmail.com> <24253.217.150.105.195.1163440819.squirrel@dockerz.net> <1163444603.7179.371.camel@localhost> <396855AC-5E4D-4812-BC74-C49735BB52D4@mac.com> Message-ID: <1163451660.7179.398.camel@localhost> On Mon, 2006-11-13 at 20:49 +0000, Ben Moseley wrote: > Has anyone succeeded in getting it running on OSX/intel at all? I'm not sure actually. I seem to recall someone trying it but I can't remember who now. cc-ing to gtk2hs-users in case anyone knows: has anyone on OSX tried the new Gtk+ 2.10.x that doesn't use X11? > ...I had a brief go a few weeks back, managed to get the Cairo Clock > running, but anything that used GTK seemed to blow up instantly. (OSX/ > ppc was fine). Did you try any of the C examples, like gtk-demo? I'm afraid I don't have access to OSX. We're actually looking for someone to help with maintaining Gtk2Hs on OSX (and someone for windows too). So if you're interested or know anyone who is interested then do get in touch. Duncan > On 13 Nov 2006, at 19:03, Duncan Coutts wrote: > >> One point in wxHaskell's favour is that it supports Mac OS X > >> directly. At present, to the best of my knowledge, you can only run > >> GtkHs applications on OS X using the X Windows server. Whilst this > >> works, it's a _long_ way from native look and feel. > > > > This is quite true. Fortunately the Gtk+ folk are well underway with > > a project to make it all more native looking. The latest released > > version of Gtk+ 2.10.x has 'experimental' support for running on OSX > > without using X11. The next step (apart from general bug fixing) is > > to use the right native theme. > > > > So yes, at the moment it doesn't look native on OSX but hopefully > > in the future it will. You can read more about that here: > > > > http://developer.imendio.com/projects/gtk-macosx From ben_moseley at mac.com Mon Nov 13 16:38:36 2006 From: ben_moseley at mac.com (Ben Moseley) Date: Mon Nov 13 16:34:27 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <1163451660.7179.398.camel@localhost> References: <1344369241.20061113025003@gmail.com> <24253.217.150.105.195.1163440819.squirrel@dockerz.net> <1163444603.7179.371.camel@localhost> <396855AC-5E4D-4812-BC74-C49735BB52D4@mac.com> <1163451660.7179.398.camel@localhost> Message-ID: <2D647FD8-10AB-4F6C-8C86-37944E2586F3@mac.com> gtk-demo seemed to run fine. --Ben On 13 Nov 2006, at 21:01, Duncan Coutts wrote: > On Mon, 2006-11-13 at 20:49 +0000, Ben Moseley wrote: >> Has anyone succeeded in getting it running on OSX/intel at all? > > I'm not sure actually. I seem to recall someone trying it but I can't > remember who now. > > cc-ing to gtk2hs-users in case anyone knows: has anyone on OSX > tried the > new Gtk+ 2.10.x that doesn't use X11? > >> ...I had a brief go a few weeks back, managed to get the Cairo Clock >> running, but anything that used GTK seemed to blow up instantly. >> (OSX/ >> ppc was fine). > > Did you try any of the C examples, like gtk-demo? I'm afraid I don't > have access to OSX. > > We're actually looking for someone to help with maintaining Gtk2Hs on > OSX (and someone for windows too). So if you're interested or know > anyone who is interested then do get in touch. > > Duncan > >> On 13 Nov 2006, at 19:03, Duncan Coutts wrote: > >>>> One point in wxHaskell's favour is that it supports Mac OS X >>>> directly. At present, to the best of my knowledge, you can only run >>>> GtkHs applications on OS X using the X Windows server. Whilst this >>>> works, it's a _long_ way from native look and feel. >>> >>> This is quite true. Fortunately the Gtk+ folk are well underway with >>> a project to make it all more native looking. The latest released >>> version of Gtk+ 2.10.x has 'experimental' support for running on OSX >>> without using X11. The next step (apart from general bug fixing) is >>> to use the right native theme. >>> >>> So yes, at the moment it doesn't look native on OSX but hopefully >>> in the future it will. You can read more about that here: >>> >>> http://developer.imendio.com/projects/gtk-macosx > > From mgross21 at verizon.net Mon Nov 13 21:57:54 2006 From: mgross21 at verizon.net (Murray Gross) Date: Mon Nov 13 21:56:43 2006 Subject: [Haskell-cafe] best Linux for GHC? In-Reply-To: <20061113133827.GC2063@die.therning.org> References: <524915860.20061113023645@gmail.com> <5bbe25930611121645r52ec16f9w552cbbe71b4984a1@mail.gmail.com> <455822B7.6070803@ii.uib.no> <1596152630.20061113133613@gmail.com> <20061113133827.GC2063@die.therning.org> Message-ID: >> as RedHat and RPMs is widely used for packaging software available via >> internet. Is Ubuntu supports RPMs too? > > I think it's widely regarded as a Bad Idea to mix packages between > distributions. > > I would suggest Ubuntu (or Debian Sid if you are interested in getting > newer versions of GHC). I think you'd find it difficult to find > software that wasn't already in Ubuntu's multiverse repository. > Please note: Debian does support RPM, either as RPM's, or by conversion (through the "alien" utility) to DEB's. My experience with such mixing is that it usually goes fine without any problems, although now and again, a bit of tinkering is necessary. Murray Gross From clawsie at fastmail.fm Tue Nov 14 00:57:42 2006 From: clawsie at fastmail.fm (brad clawsie) Date: Tue Nov 14 00:56:50 2006 Subject: [Haskell-cafe] pleac, examples, etc Message-ID: <1163483862.12553.275756050@webmail.messagingengine.com> it would be great if some of the more informed posters here took a stab at filling in http://pleac.sourceforge.net/pleac_haskell/index.html a neat site for cookbook-style problem solving from looking over haskell documentation for a few months now, i would say what is missing is one central cookbook-style document (want to query a database? want to parse xml? etc etc) thanks From sjanssen at cse.unl.edu Tue Nov 14 01:36:07 2006 From: sjanssen at cse.unl.edu (Spencer Janssen) Date: Tue Nov 14 01:36:38 2006 Subject: [Haskell-cafe] pleac, examples, etc In-Reply-To: <1163483862.12553.275756050@webmail.messagingengine.com> References: <1163483862.12553.275756050@webmail.messagingengine.com> Message-ID: <18614262-C37C-4B38-B7A2-83C8B579C205@cse.unl.edu> Please do not use the PLEAC Haskell cookbook for learning Haskell. The author redefined many of the standard operators to produce code that isn't standard Haskell. Here are some choice snippets from the first chapter: Now, we all know that the (.) operator is function composition, right? Not in this example! The author has silently defined "(.) = flip ($)" -- a sort of reverse function application. > cut2fmt xs = xs.foldl aux (1,[]).snd.(GrabAll:).reverse Ah yes, (^) is surely exponent here? Nope, it's some kind of unholy combination of show and (++). > s9 = "I have "^10+1^" guanacos." More of the same: > piece = s!![-8 .. -5] Complaining aside, I do agree with you: we need more example-style documentation. Rewriting the PLEAC cookbook might be a good start. Cheers, Spencer Janssen On Nov 13, 2006, at 11:57 PM, brad clawsie wrote: > it would be great if some of the more informed posters here took a > stab > at filling in > > http://pleac.sourceforge.net/pleac_haskell/index.html > > a neat site for cookbook-style problem solving > > from looking over haskell documentation for a few months now, i would > say what is missing is one central cookbook-style document (want to > query a database? want to parse xml? etc etc) > > thanks > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From bjpop at csse.unimelb.edu.au Tue Nov 14 02:16:53 2006 From: bjpop at csse.unimelb.edu.au (Bernie Pope) Date: Tue Nov 14 02:38:48 2006 Subject: [Haskell-cafe] Haskell Debugging In-Reply-To: <45589D73.5010507@ijs.si> References: <45589012.9060708@ijs.si> <45589528.2030302@ijs.si> <45589D73.5010507@ijs.si> Message-ID: On 14/11/2006, at 3:29 AM, Valentin Gjorgjioski wrote: > On 13.11.2006 16:54 Valentin Gjorgjioski wrote: >> On 13.11.2006 16:48 Pepe Iborra wrote: >>> Hi Valentin >>> >>> Please, take a look at the Haskell Wiki page for debugging. >>> >>> http://haskell.org/haskellwiki/Debugging >>> >>> You will find that thanks to Neil Mitchell there is a Windows >>> version of Hat available. Perhaps you can add your experiences >>> with it if it works for you. >>> >> Oh silly me, I was looking that page, but I didn't notice this. >> Thanks a lot, pepe. >> I'll try, and I'll post feedback here. >> > I install it, I tried it, and it doesn't work for me. > > ./Hat/DML.hs:535:66: > Ambiguous type variable `a' in the constraint: > `Integral a' arising from use of `*^' at ./Hat/DML.hs:535:66-69 > Probable fix: add a type signature that fixes these type variable(s) > > And this is line 535.... > T.uapp2 p125v94v125v148 p125v147v125v147 p (+^) (*^) Okay, the type error you are getting is most likely caused by numeric defaulting, or lack of it in Hat. In Haskell, some instances of ambiguous overloading are resolved by the defaulting rules. See: http://haskell.org/onlinereport/decls.html#sect4.3.4 Hat is based on program transformation, and to cut a long story short, the defaulting rules do not work on the transformed program. So you must do the defaulting yourself by adding in explicit type annotations to the offending expression, then transform the program again. In your case it probably amounts to adding something like " :: Integer", or " :: Int" after the expression which uses (^). There is a note about this in the hat faq: http://www.cs.york.ac.uk/fp/hat/faq.html BTW the same problem happens in buddha, which is also based on program transformation. Cheers, Bernie. From akamaus at gmail.com Tue Nov 14 05:26:36 2006 From: akamaus at gmail.com (Dmitry V'yal) Date: Tue Nov 14 05:26:05 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <387065214.20061113223112@gmail.com> References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> <404396ef0611130543j488e6054u74bd45cf68202419@mail.gmail.com> <1224838352.20061113165934@gmail.com> <404396ef0611130606t5b06b24eu534b13c1e5eade94@mail.gmail.com> <844844545.20061113171034@gmail.com> <1163445556.7179.386.camel@localhost> <387065214.20061113223112@gmail.com> Message-ID: <455999DC.7030400@gmail.com> Bulat Ziganshin wrote: > it is what i say about. threaded RTS + multipls threads that does > computations + one thread that interfaces with Gtk2Hs. afaiu, the only > problem is that i need to manage both Gtk events and periodically > check queue of commands from other threads, but using timer + Chan > should allow to implement this > I wrote multi threaded gui application in Haskell last spring as a educational project. That was a tool for analyzing and extracting contents of FAT volumes. Then i started my project, i was completely unaware of these threading issues and freely called gtk2hs routines from several threads. All worked fine at first, but when i added some disk I/O to my threads, my program became unstable. While on linux it just crashed from time to time, on windows i saw more curious behavior. At random spots threads lost ability to call WinAPI functions. Basically they got an error code meaning something weird like "insufficient memory to complete call" in return. That was not easily reproducible and depended on exact version of Windows. At some point my app was fully functional on WinXP and didn't even start on Win2000. I spent a lot of time trying to debug these issues and finally refactored my program to make use of approach you describe. Worked fine after that. All you have to do is to choose appropriate timer interval, otherwise your app becomes too jerky or CPU hungry. From simonpj at microsoft.com Tue Nov 14 05:40:40 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Tue Nov 14 05:39:53 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <455999DC.7030400@gmail.com> References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> <404396ef0611130543j488e6054u74bd45cf68202419@mail.gmail.com> <1224838352.20061113165934@gmail.com> <404396ef0611130606t5b06b24eu534b13c1e5eade94@mail.gmail.com> <844844545.20061113171034@gmail.com> <1163445556.7179.386.camel@localhost> <387065214.20061113223112@gmail.com> <455999DC.7030400@gmail.com> Message-ID: I wonder whether it'd be possible to make the gtk2hs stuff emit warnings if you make calls from two different threads? Then an application would complain constructively rather than "becoming unstable". Simon | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of | Dmitry V'yal | Sent: 14 November 2006 10:27 | To: haskell-cafe@haskell.org | Subject: Re: [Haskell-cafe] what GUI library should i select? | | Bulat Ziganshin wrote: | | > it is what i say about. threaded RTS + multipls threads that does | > computations + one thread that interfaces with Gtk2Hs. afaiu, the only | > problem is that i need to manage both Gtk events and periodically | > check queue of commands from other threads, but using timer + Chan | > should allow to implement this | > | I wrote multi threaded gui application in Haskell last spring as a educational | project. That was a tool for analyzing and extracting contents of FAT volumes. | Then i started my project, i was completely unaware of these threading issues | and freely called gtk2hs routines from several threads. All worked fine at | first, but when i added some disk I/O to my threads, my program became unstable. | While on linux it just crashed from time to time, on windows i saw more curious | behavior. At random spots threads lost ability to call WinAPI functions. | Basically they got an error code meaning something weird like "insufficient | memory to complete call" in return. That was not easily reproducible and | depended on exact version of Windows. At some point my app was fully functional | on WinXP and didn't even start on Win2000. | I spent a lot of time trying to debug these issues and finally refactored my | program to make use of approach you describe. Worked fine after that. All you | have to do is to choose appropriate timer interval, otherwise your app becomes | too jerky or CPU hungry. | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe From akamaus at gmail.com Tue Nov 14 05:52:27 2006 From: akamaus at gmail.com (Dmitry V'yal) Date: Tue Nov 14 05:51:42 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <1163445556.7179.386.camel@localhost> References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> <404396ef0611130543j488e6054u74bd45cf68202419@mail.gmail.com> <1224838352.20061113165934@gmail.com> <404396ef0611130606t5b06b24eu534b13c1e5eade94@mail.gmail.com> <844844545.20061113171034@gmail.com> <1163445556.7179.386.camel@localhost> Message-ID: <45599FEB.8010502@gmail.com> Duncan Coutts wrote: > The problem at the moment with GUIs and GHC's threaded RTS is that there > is now way to specify that all the Haskell threads that want to do GUI > stuff must run on a single OS thread. It's not impossible to solve but > it requires either more support from the RTS or it needs a totally > different approach, perhaps using a Haskell-level threading GUI monad > rather than the IO monad. Looks interesting for me. It's not too haskellish imo, when one ends with 2/3 of code being in the IO monad. Although situation probably gets better then more complex algorithms for processing data involved. Are there any attempts to fine grain allowed side effects using several monads? From simonmarhaskell at gmail.com Tue Nov 14 05:53:46 2006 From: simonmarhaskell at gmail.com (Simon Marlow) Date: Tue Nov 14 05:53:01 2006 Subject: [Haskell-cafe] deepSeq vs rnf In-Reply-To: <45587768.4040204@cs.chalmers.se> References: <89ca3d1f0610222019i11d948f1p5f151eee56c05188@mail.gmail.com> <45587768.4040204@cs.chalmers.se> Message-ID: <4559A03A.4010603@microsoft.com> Bj?rn Bringert wrote: > Cale Gibbard wrote: > >> On 22/10/06, Chad Scherrer wrote: >> >>> Hi, >>> >>> I had posted this question a while back, but I think it was in the >>> middle of another discussion, and I never did get a reply. Do we >>> really need both Control.Parallel.Strategies.rnf and deepSeq? Should >>> we not always have >>> >>> x `deepSeq` y == rnf x `seq` y >>> ? >>> >>> Maybe there's a distinction I'm missing, but it seems to me they're >>> basically the same. >> >> >> I agree, they are the same. The Strategies library also gives much >> more general operations for working with strictness and >> parallelisation. That library seems to need more love, I think it's a >> great idea, but it doesn't really get noticed all that much. The >> Hierarchical libraries documentation for it is a little lacking -- it >> doesn't even provide a reference or link to the paper, and many of the >> combinators, as well as the general idea of how to use it are >> undocumented from there. It also spuriously contains an Assoc >> datatype, which if I recall correctly, was an example from the paper, >> but doesn't really belong in the library as far as I can tell. It >> would also be really nice to see the list of instances for the NFData >> class expanded to include other datatypes in the libraries, possibly >> also with compiler support for deriving, since it's mostly >> boilerplate. > > > I wanted to use the Strategies library and didn't understand much of it, > so I sat down and documented it. The darcs version, > http://darcs.haskell.org/packages/base/Control/Parallel/Strategies.hs > has my changes. > > If noone objects, I could do some more clean-up, including: > > - Add NFData instances for common data types, such as > - Maybe > - Either > - Data.Map.Map > - Data.Set.Set > - Data.Tree.Tree > - All Data.Int and Data.Word types > > - Deprecate sSeq and sPar, as the code comments say that you should use > demanding and sparking instead. > > - Deprecate these defintions, which seem to be examples or > Lolita-specific: > - Assoc > - fstPairFstList > - force > - sforce > > If anyone has objections or further suggestions, let me know. Looks good to me. I didn't really look closely at this code before enabling it, except to check that it compiled and appeared to work with a couple of the old Parallel Haskell benchmarks in nofib/par. Cheers, Simon From akamaus at gmail.com Tue Nov 14 06:03:27 2006 From: akamaus at gmail.com (Dmitry V'yal) Date: Tue Nov 14 06:02:42 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <4557E3EA.8080303@babel.ls.fi.upm.es> References: <1344369241.20061113025003@gmail.com> <404396ef0611121710g2b1c0b4dp1d06fa906ae05ec1@mail.gmail.com> <4557E3EA.8080303@babel.ls.fi.upm.es> Message-ID: <4559A27F.50709@gmail.com> Iv?n P?rez Dom?nguez wrote: > I'm using Gentoo Linux. We obviously don't use prebuilt packaged > versions, but installing it is just doing "emerge wxhaskell" and > 'playing the... waiting game'. Gtk2hs support under Gentoo is mostly > missing (the package is included, but doesn't work at all). Hmm, that strange. I emerged both gtk2hs-0.9.10 and ghc-6.4.2 just fine. Probably you should update your portage tree. I don't remember exactly, but I used portage snapshot from late spring of 2006. Now I'm waiting for ghc-6.6 being added to official portage tree. From sylvan at student.chalmers.se Tue Nov 14 06:11:12 2006 From: sylvan at student.chalmers.se (Sebastian Sylvan) Date: Tue Nov 14 06:10:24 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <455999DC.7030400@gmail.com> References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> <404396ef0611130543j488e6054u74bd45cf68202419@mail.gmail.com> <1224838352.20061113165934@gmail.com> <404396ef0611130606t5b06b24eu534b13c1e5eade94@mail.gmail.com> <844844545.20061113171034@gmail.com> <1163445556.7179.386.camel@localhost> <387065214.20061113223112@gmail.com> <455999DC.7030400@gmail.com> Message-ID: <3d96ac180611140311r2aec93bejfda04cb197758645@mail.gmail.com> On 11/14/06, Dmitry V'yal wrote: > Bulat Ziganshin wrote: > > > it is what i say about. threaded RTS + multipls threads that does > > computations + one thread that interfaces with Gtk2Hs. afaiu, the only > > problem is that i need to manage both Gtk events and periodically > > check queue of commands from other threads, but using timer + Chan > > should allow to implement this > > > I wrote multi threaded gui application in Haskell last spring as a educational > project. That was a tool for analyzing and extracting contents of FAT volumes. > Then i started my project, i was completely unaware of these threading issues > and freely called gtk2hs routines from several threads. All worked fine at > first, but when i added some disk I/O to my threads, my program became unstable. > While on linux it just crashed from time to time, on windows i saw more curious > behavior. At random spots threads lost ability to call WinAPI functions. > Basically they got an error code meaning something weird like "insufficient > memory to complete call" in return. That was not easily reproducible and > depended on exact version of Windows. At some point my app was fully functional > on WinXP and didn't even start on Win2000. > I spent a lot of time trying to debug these issues and finally refactored my > program to make use of approach you describe. Worked fine after that. All you > have to do is to choose appropriate timer interval, otherwise your app becomes > too jerky or CPU hungry. [I sent a message earlier to this effect but accidentally hit "reply" rather than "reply all" so only duncan got it] I'm looking through the GTK docs and it appears to me that you don't actually have to choose an interval at all. All that's needed is that you somehow "trigger" the GTK event loop to call an event handler in its thread which empties the channel and executes any GUI actions therein. It seems that GTK supports adding custom sources to the event loop (if I understand the docs correctly, this is thread safe, and signalling one of these sources should be too). So either we add a new custom source, or find some other way of "signalling" a particular event. I would guess one way of doing this would be to add a timeout event handler with delay 0, this event handler would be a function called, say, dispatchPendingGUIActions, which empties the channel of GUI actions, and also returns False so that it will only get called once (per "signal" - the next "signal" it will get added again). In other words, there is no need for polling. Just add the function to the channel and signal the main loop (first checking if we are already in the main GUI thread in which case we just call the action directly without going through the channel, and also checking if a "signal" has already been raised but not yet "handled" in which case we don't do it again) . Something like (untested): -- contains the action, and the response mvar data GUIWorkItem = forall a . GUIWorkItem !(IO a) !(MVar a) newGUIChan :: IO (Chan GUIWorkItem) newGUIChan = newChan -- this adds an action to the main channel, unless we're already -- in the main GUI thread, in which case we just run the action directly dispatchGUIAction act do isMain <- isMainGUIThread if isMain then act else do res <- newEmptyMVar writeChan theGlobalGUIChan (GUIWorkItem act res) triggerMainGUIThread unsafeInterleaveIO (takeMVar res) -- this is the action we want to call from the main GUI thread -- every time a new action has been added to the queue, e.g. -- by adding it as an event handler to a timer event dispatchPendingGUIActions do empty <- isEmptyChan if empty then setGTKThreadNoLongerTriggered >> return False else do GUIWorkItem act resVar <- readChan theGlobalGUIChan res <- act putMVar resVar res dispatchPendingGUIActions -- an example GUI action, this is how we "wrap" all our actions gtkAction' x y z = dispatchGUIAction (gtkAction x y z) -- this is how we signal GTK so that it will call the code which -- handles all the actions in theGlobalGUIChan triggerMainGUIThread = do isTriggered <- isGTKThreadTriggered -- not necessarily needed... if isTriggered then return () else timeoutAddFull dispatchPendingGUIActions priorityHigh 0 (note: The unsafeInterleaveIO is there so that dispatchPendingGUIActions won't have to block until the main GUI thread gets around to handling the event, after all for quite a few GTK actions you don't really care about the result so you should return immediately). There are some minor gaps here, but that's the general idea. We avoid the polling by explicitly signalling GTK whenever we add a GUI event to the channel. I've done it here by adding the "dispatch" function as an event handler to a timeout event (this event handler returns False so the timeout event is removed after being called). This depends on wether or not adding event handlers is thread safe. If it isn't, it may be enough to wrap the triggerMainGUIThead action in a global lock (someone who knows more obout this?). If that still isn't safe, then we could add our own custom source to the GTK event loop and signal the event loop using that (though that might be a bit more messy?). /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862 From bulat.ziganshin at gmail.com Tue Nov 14 05:51:25 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Nov 14 07:09:46 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <455999DC.7030400@gmail.com> References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> <404396ef0611130543j488e6054u74bd45cf68202419@mail.gmail.com> <1224838352.20061113165934@gmail.com> <404396ef0611130606t5b06b24eu534b13c1e5eade94@mail.gmail.com> <844844545.20061113171034@gmail.com> <1163445556.7179.386.camel@localhost> <387065214.20061113223112@gmail.com> <455999DC.7030400@gmail.com> Message-ID: <537186874.20061114135125@gmail.com> Hello Dmitry, Tuesday, November 14, 2006, 1:26:36 PM, you wrote: >> it is what i say about. threaded RTS + multipls threads that does >> computations + one thread that interfaces with Gtk2Hs. afaiu, the only >> problem is that i need to manage both Gtk events and periodically >> check queue of commands from other threads, but using timer + Chan >> should allow to implement this > I spent a lot of time trying to debug these issues and finally refactored my > program to make use of approach you describe. to be exact, i describe the approach you used. you've written me about this, if you remember :) also, i've fixed memory-mapped files so they can now work with files > 4gb and performs aligned i/o, so if you are interested, you can use streams 0.2 with a maximum comfort :) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From simonmarhaskell at gmail.com Tue Nov 14 08:31:27 2006 From: simonmarhaskell at gmail.com (Simon Marlow) Date: Tue Nov 14 08:30:41 2006 Subject: [Haskell-cafe] Re: Great language shootout: reloaded In-Reply-To: <3d96ac180611101651x7f2f696cn1f5b49c0792a7409@mail.gmail.com> References: <20061110004415.GA28727@cse.unsw.EDU.AU> <3d96ac180611101651x7f2f696cn1f5b49c0792a7409@mail.gmail.com> Message-ID: <4559C52F.9090301@microsoft.com> Sebastian Sylvan wrote: > On 11/10/06, Henk-Jan van Tuyl wrote: > >> >> On Fri, 10 Nov 2006 01:44:15 +0100, Donald Bruce Stewart >> wrote: >> >> > So back in January we had lots of fun tuning up Haskell code for the >> > Great Language Shootout[1]. We did quite well at the time, at one point >> > ranking overall first[2]. [...] >> >> Haskell suddenly dropped several places in the overall socre, when the >> size measurement changed from line-count to number-of-bytes after >> gzipping. Maybe it's worth it, to study why this is; Haskell programs are >> often much more compact then programs in other languages, but after >> gzipping, other languages do much better. One reason I can think of, is >> that for very short programs, the import statements weigh heavily. > > > I think the main factor is that languages with large syntactic > redundancy get that compressed away. I.e if you write: > > MyVeryLongAndConvlutedClassName MyVeryLargeAndConvulutedObject new > MyVeryLongAndConvolutedClassName( somOtherLongVariableName ); > > Or something like that, that makes the code clumpsy and difficult to > read, but it won't affect the gzipped byte count very much. > Their current way of meassuring is pretty much pointless, since the > main thing the gzipping does is remove the impact of clunky syntax. > Meassuring lines of code is certainly not perfect, but IMO it's a lot > more useful as a metric then gzipped bytes. Sure, since gzip is the metric, then we can optimise for that. For example, instead of writing a higher-order function, just copy it out N times instantiating the higher-order argument differently each time. There should be no gzipped-code-size penalty for doing that, and it'll be faster :-) Cheers, Simon From ccshan at post.harvard.edu Tue Nov 14 09:24:44 2006 From: ccshan at post.harvard.edu (Chung-chieh Shan) Date: Tue Nov 14 10:33:26 2006 Subject: [Haskell-cafe] Re: what GUI library should i select? References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> <404396ef0611130543j488e6054u74bd45cf68202419@mail.gmail.com> <1224838352.20061113165934@gmail.com> <404396ef0611130606t5b06b24eu534b13c1e5eade94@mail.gmail.com> <844844545.20061113171034@gmail.com> <1163445556.7179.386.camel@localhost> <387065214.20061113223112@gmail.com> <455999DC.7030400@gmail.com> Message-ID: Simon Peyton-Jones wrote in article in gmane.comp.lang.haskell.cafe: > I wonder whether it'd be possible to make the gtk2hs stuff emit > warnings if you make calls from two different threads? Then an > application would complain constructively rather than "becoming > unstable". ... or whether it's possible to represent the gtk2hs thread by a phantom type, to enforce the restriction statically? -- Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig Batman don't...but Kathmandu! From bulat.ziganshin at gmail.com Tue Nov 14 10:42:22 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Nov 14 10:43:20 2006 Subject: [Haskell-cafe] Re: Great language shootout: reloaded In-Reply-To: <4559C52F.9090301@microsoft.com> References: <20061110004415.GA28727@cse.unsw.EDU.AU> <3d96ac180611101651x7f2f696cn1f5b49c0792a7409@mail.gmail.com> <4559C52F.9090301@microsoft.com> Message-ID: <944731633.20061114184222@gmail.com> Hello Simon, Tuesday, November 14, 2006, 4:31:27 PM, you wrote: > Sure, since gzip is the metric, then we can optimise for that. For example, > instead of writing a higher-order function, just copy it out N times > instantiating the higher-order argument differently each time. There should be > no gzipped-code-size penalty for doing that, and it'll be faster :-) i hope that ghc 6.8 will include -Ogzip! switch which transforms program so it becomes more compressible by gzip. also jhc's recent haskell-to-ghc translation mode may be optimized in this way, so jhc will finally outperform ghc as a best shootout platform :) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From sethg at ropine.com Tue Nov 14 16:06:31 2006 From: sethg at ropine.com (Seth Gordon) Date: Tue Nov 14 16:05:44 2006 Subject: [Haskell-cafe] the case of the 100-fold program speedup Message-ID: <455A2FD7.1040909@ropine.com> One of Alan Perlis's "Epigrams in Programming" is "A language that doesn't affect the way you think about programming, is not worth knowing". I recently had an experience that demonstrated this principle. I had to write some code that took a polygon (encoded in WKT, a standard format for geographic information exchange), computed its intersection with several rectangles, and then compute the centroid of each one of these intersections. No problem, I thought. People who know more than me about this geometry stuff have written an open-source library, OGR, which has functions for parsing WKT, computing intersections, computing centroids, and computing all sorts of other things. And there are Python bindings for OGR so I don't have to wrestle with C++ to solve my problem. So I wrote a Python program that used OGR to crunch the numbers, ran it through the data set we needed to process, and...it took over sixteen hours to run. Since we want to have this program process this data set with every build of our software, adding sixteen hours to our build time was not a pleasant thought. Then I thought about some of the things I'd read about optimization of functional programming languages, and said, "Hey! The algorithm for clipping the polygon to the rectangle is producing a sequence of vertices, and the algorithm for computing the centroid is consuming a sequence of vertices. I can do some deforestation here!" It took me a week to figure out the right algorithm for combining these two procedures and write some almost-working code that implemented it. It took a co-worker of mine another few days to find the bugs that had eluded me. But after the program worked for my test cases, I ran it again on the full data set...and it took ten minutes. In other words, I sped up the code by two orders of magnitude. And I didn't even have to drop into C++ to do the number-crunching; I used OGR to parse the WKT strings and to look up the coordinates of each vertex of the polygon, but the algorithm itself was implemented in Python. w00t! From pixel at mandriva.com Tue Nov 14 17:10:59 2006 From: pixel at mandriva.com (Pixel) Date: Tue Nov 14 17:10:02 2006 Subject: [Haskell-cafe] pleac, examples, etc In-Reply-To: <18614262-C37C-4B38-B7A2-83C8B579C205@cse.unl.edu> (Spencer Janssen's message of "Tue, 14 Nov 2006 00:36:07 -0600") References: <1163483862.12553.275756050@webmail.messagingengine.com> <18614262-C37C-4B38-B7A2-83C8B579C205@cse.unl.edu> Message-ID: Spencer Janssen writes: > Please do not use the PLEAC Haskell cookbook for learning Haskell. The > author redefined many of the standard operators to produce code that isn't > standard Haskell. > > Here are some choice snippets from the first chapter: > > Now, we all know that the (.) operator is function composition, right? Not > in this example! The author has silently defined "(.) = flip ($)" -- a sort > of reverse function application. >> cut2fmt xs = xs.foldl aux (1,[]).snd.(GrabAll:).reverse > > Ah yes, (^) is surely exponent here? Nope, it's some kind of unholy > combination of show and (++). >> s9 = "I have "^10+1^" guanacos." > > More of the same: >> piece = s!![-8 .. -5] > > > Complaining aside, I do agree with you: we need more example-style > documentation. Rewriting the PLEAC cookbook might be a good start. i agree. A friend of mine did this haskell PLEAC version, and i would really like to have a /standard/ haskell one. (alas i've no more time to do it myself...) From cgibbard at gmail.com Tue Nov 14 17:17:17 2006 From: cgibbard at gmail.com (Cale Gibbard) Date: Tue Nov 14 17:16:25 2006 Subject: [Haskell-cafe] Haskell Debugging In-Reply-To: <45589012.9060708@ijs.si> References: <45589012.9060708@ijs.si> Message-ID: <89ca3d1f0611141417u5ed956b8h7a769bb0c25ca619@mail.gmail.com> On 13/11/06, Valentin Gjorgjioski wrote: > I'm pretty new in Haskell, few days since I started learning it. I want > to debu my programs. I'm currently using WinHugs, and I prefer debugger > for this. > > I tried googling and I found Hugs.Observer. > > I like it how it works, but still I have one BIG problem with it. It > doesn't work well with floats. > > Following example > > import Hugs.Observe > > ex8 :: [Float] > ex8 = (observe "after reverse" ) reverse [10.0,7.0,3.0,0.0,4.0] > > gives me > > >ex8 > [4.0,0.0,3.0,7.0,10.0] > > >>>>>>> Observations <<<<<< > > after reverse > { \ ($-990871 : $-990888 : $-990905 : $-990922 : $-990939 : []) -> > $-990939 : $-990922 : $-990905 : $-990888 : $-990871 : [] > } > First of all, I don't get this behaviour in Hugs 20050308 on Ubuntu. Main> ex8 [4.0,0.0,3.0,7.0,10.0] >>>>>>> Observations <<<<<< after reverse { \ (10.0 : 7.0 : 3.0 : 0.0 : 4.0 : []) -> 4.0 : 0.0 : 3.0 : 7.0 : 10.0 : [] } and: Main> ex8 `seq` () () >>>>>>> Observations <<<<<< after reverse { \ (_ : _ : _ : _ : _ : []) -> _ : _ } So it might just be the version which you have. I think that the $ values are perhaps representations of unevaluated thunks. Try it with a string, or something like ex = (observe "after replicate") (replicate 3) (5+5) and see what you get (should be a list with 3 elements that are all the same thunk). Also try: ex8 = foldr seq () xs `seq` (observe "after reverse" ) reverse xs where xs = [10.0,7.0,3.0,0.0,4.0] to see if forcing the values in the list first causes any change in the output. - Cale From evilantleredthing at yahoo.ca Tue Nov 14 19:00:16 2006 From: evilantleredthing at yahoo.ca (chris moline) Date: Tue Nov 14 18:59:23 2006 Subject: [Haskell-cafe] pleac, examples, etc In-Reply-To: <1163483862.12553.275756050@webmail.messagingengine.com> Message-ID: <20061115000016.67313.qmail@web57207.mail.re3.yahoo.com> --- brad clawsie wrote: > it would be great if some of the more informed > posters here took a stab > at filling in > > http://pleac.sourceforge.net/pleac_haskell/index.html > > a neat site for cookbook-style problem solving What I've always found funny about pleac is that none of the examples are actually Haskell, but some weird Haskell-with-oo-features. Does anyone know what language it is? Here are some examples: password = [1..8].mapM (\_ -> rand (0, chars.length -1) >>> (chars!)) -- in haskell, regexp are first class, then can be appended, sometimes easier to read m0' s = .... (s ==~ dec_number) .... __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From duncan.coutts at worc.ox.ac.uk Tue Nov 14 20:20:49 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Tue Nov 14 20:14:26 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: References: <1344369241.20061113025003@gmail.com> <1163378192.7179.289.camel@localhost> <655793883.20061113154130@gmail.com> <404396ef0611130543j488e6054u74bd45cf68202419@mail.gmail.com> <1224838352.20061113165934@gmail.com> <404396ef0611130606t5b06b24eu534b13c1e5eade94@mail.gmail.com> <844844545.20061113171034@gmail.com> <1163445556.7179.386.camel@localhost> <387065214.20061113223112@gmail.com> <455999DC.7030400@gmail.com> Message-ID: <1163553649.7179.490.camel@localhost> On Tue, 2006-11-14 at 10:40 +0000, Simon Peyton-Jones wrote: > I wonder whether it'd be possible to make the gtk2hs stuff emit > warnings if you make calls from two different threads? Then an > application would complain constructively rather than "becoming > unstable". I have three plans: Plan 1: prevent gtk2hs initialising when using the threaded RTS. This is what the dev version does at the moment to prevent people shooting themselves in the foot. Obviously this is not satisfactory as long term the threaded rts is going to be the only option available. The funny thing is that we can actually use Haskell threads with Gtk2Hs perfectly well with the single threaded rts (we currently use a polling scheme to to cooperative scheduling between gtk+ and ghc rts but there are some non-polling possibilities that could be implemented.) Indeed, we used to be able to have GUI stuff work fine in GHCi, but now that GHCi uses the threaded rts we're in trouble. Plan 2: Make the threaded rts do what we want. This is hard and involves begging Simon M to do lots of work. The constraints we have are that only the OS thread that initialised the GUI can make calls to the GUI lib. So any Haskell threads doing GUI stuff have to be running on that OS thread. Note that this really means one OS thread, not one capability which can run on a pool of threads (with X11, the pool might be ok as only one would be doing GUI stuff at once but on Win32 the restrictions are even tighter). I really don't want to make the Haskell coders have to deal with passing actions between threads to get it right, because people will get it wrong too easily. So any thread cunning needs to be hidden in the library so that people cn just use threads willy nilly without there being dangerous unchecked conditions. So one idea is to start the UI in a bound OS thread, but then we also want to make sure that any Haskell thread that makes a GUI call only do it in that same OS thread. Currently we cannot bind several Haskell threads to a single OS thread. From discussions with Simon M it is clear that making this possible is non-trivial. Then even once we have that, to make it transparent we'd need to be able to migrate a Haskell thread to the right OS thread if it makes a GUI call. The GUI wrapper lib would need to arrange this and arrange for cooperative scheduling on the one OS thread. Lots of work. The reason we can't just post actions to the right thread all the time is that GUI calls are typically very short lived. Many are just reading fields out of C struts. If every one of those needed an OS thread switch then it'd be pretty bad. So thats why we'd need to migrate the thread since that's a one off and after that GUI calls would be quick. Plan 3: perhaps the IO monad isn't the right monad It's really quite convenient to have complete access to the IO monad when doing GUI stuff and that seems to be the design that most recent libs have chosen. So suppose we had a GUI monad and the boundaries between the IO and GUI monad would take care of making sure we were using the right OS thread. So we would initialise the GUI and then work inside the GUI monad. It'd fork a bound thread to run the GUI lib's event loop. It'd also have to arrange for cooperative scheduling in that OS thread. Then the GUI monad could have a forkGUI that uses Haskell level scheduling to schedule several GUI 'threads' in the single bound Haskell thread. Then to do IO, we could provide an escape hatch to do IO, for blocking stuff we could forkIO and let it run in an unbound thread. Similarly for long running pure computations we could provide something (or just par?) to let those run outside the GUI thread so that it doesn't block the UI. So you'd be able to lift IO stuff into the GUI monad. As for the other way around, I guess that could arrange for the GUI action to be added to the GUI scheduler run queue. Tricky bits: callbacks get run in their own unbound Haskell thread which would therefore not run in the bound OS GUI thread. That'd be annoying as it'd involve 2 pointless context switches per callback event. Is there any way we could be a bit less strict. All we need is that the GUI Haskell thread runs in the GUI OS thread, we don't mind if other Haskell threads run in that OS thread too. So a could a callback that comes in on that OS thread spark a Haskell thread in that same OS thread? Then we could add the callback action to the Haskell GUI thread's runqueue and yield to that thread. So we might still need some RTS changes to make it work nicely. Sigh. I'd welcome other suggestions. If we can make it work nicely it should be great. Using light weight threads is a nice approach to GUIs compared to the contortions that people have to do in other languages to do everything in an event driven style to share a single thread while avoiding ever blocking. Duncan From valentin.gjorgjioski at ijs.si Tue Nov 14 20:15:55 2006 From: valentin.gjorgjioski at ijs.si (Valentin Gjorgjioski) Date: Tue Nov 14 20:15:14 2006 Subject: [Haskell-cafe] Haskell Debugging In-Reply-To: <89ca3d1f0611141417u5ed956b8h7a769bb0c25ca619@mail.gmail.com> References: <45589012.9060708@ijs.si> <89ca3d1f0611141417u5ed956b8h7a769bb0c25ca619@mail.gmail.com> Message-ID: <455A6A4B.3070007@ijs.si> On 14.11.2006 23:17 Cale Gibbard wrote: > On 13/11/06, Valentin Gjorgjioski wrote: >> >> Following example >> >> import Hugs.Observe >> >> ex8 :: [Float] >> ex8 = (observe "after reverse" ) reverse [10.0,7.0,3.0,0.0,4.0] >> >> gives me >> >> >ex8 >> [4.0,0.0,3.0,7.0,10.0] >> >> >>>>>>> Observations <<<<<< >> >> after reverse >> { \ ($-990871 : $-990888 : $-990905 : $-990922 : $-990939 : []) -> >> $-990939 : $-990922 : $-990905 : $-990888 : $-990871 : [] >> } >> > > First of all, I don't get this behaviour in Hugs 20050308 on Ubuntu. > > Main> ex8 > [4.0,0.0,3.0,7.0,10.0] > >>>>>>>> Observations <<<<<< > > after reverse > { \ (10.0 : 7.0 : 3.0 : 0.0 : 4.0 : []) -> 4.0 : 0.0 : 3.0 : 7.0 : > 10.0 : [] > } Just one more thing If I write ex9 :: [Float] ex9 = (observe "after reverse" ) reverse [10.0,7.0,3.0,0.0,4.0] it doesn't work. If I delete ex9 :: [Float] then it works fine. any suggestions? From ndmitchell at gmail.com Tue Nov 14 20:29:44 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Tue Nov 14 20:28:54 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <1163553649.7179.490.camel@localhost> References: <1344369241.20061113025003@gmail.com> <404396ef0611130543j488e6054u74bd45cf68202419@mail.gmail.com> <1224838352.20061113165934@gmail.com> <404396ef0611130606t5b06b24eu534b13c1e5eade94@mail.gmail.com> <844844545.20061113171034@gmail.com> <1163445556.7179.386.camel@localhost> <387065214.20061113223112@gmail.com> <455999DC.7030400@gmail.com> <1163553649.7179.490.camel@localhost> Message-ID: <404396ef0611141729j2b7adefbv9056847a3f897375@mail.gmail.com> Hi > Plan 1: prevent gtk2hs initialising when using the threaded RTS. > > This is what the dev version does at the moment to prevent people > shooting themselves in the foot. > > The funny thing is that we can actually use Haskell threads with Gtk2Hs > perfectly well with the single threaded rts (we currently use a polling > scheme to to cooperative scheduling between gtk+ and ghc rts but there > are some non-polling possibilities that could be implemented.) Do these work for my particular application? (running a process in the background, and sending its stdout to a Gtk Window). The polling I implemented didn't work very well at all. > Plan 2: Make the threaded rts do what we want. > > This is hard and involves begging Simon M to do lots of work. How many people are required to beg? I volunteer :) > Plan 3: perhaps the IO monad isn't the right monad > > It's really quite convenient to have complete access to the IO monad > when doing GUI stuff and that seems to be the design that most recent > libs have chosen. Can I read a file in a GUI thread? Can I spawn a process and read an external handle? I suspect that more and more things would be added to the GUI monad until GUI == IO. Thanks Neil From duncan.coutts at worc.ox.ac.uk Tue Nov 14 20:58:18 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Tue Nov 14 20:51:54 2006 Subject: [Haskell-cafe] what GUI library should i select? In-Reply-To: <404396ef0611141729j2b7adefbv9056847a3f897375@mail.gmail.com> References: <1344369241.20061113025003@gmail.com> <404396ef0611130543j488e6054u74bd45cf68202419@mail.gmail.com> <1224838352.20061113165934@gmail.com> <404396ef0611130606t5b06b24eu534b13c1e5eade94@mail.gmail.com> <844844545.20061113171034@gmail.com> <1163445556.7179.386.camel@localhost> <387065214.20061113223112@gmail.com> <455999DC.7030400@gmail.com> <1163553649.7179.490.camel@localhost> <404396ef0611141729j2b7adefbv9056847a3f897375@mail.gmail.com> Message-ID: <1163555898.7179.496.camel@localhost> On Wed, 2006-11-15 at 01:29 +0000, Neil Mitchell wrote: > > The funny thing is that we can actually use Haskell threads with Gtk2Hs > > perfectly well with the single threaded rts (we currently use a polling > > scheme to to cooperative scheduling between gtk+ and ghc rts but there > > are some non-polling possibilities that could be implemented.) > > Do these work for my particular application? (running a process in the > background, and sending its stdout to a Gtk Window). The polling I > implemented didn't work very well at all. Yeah, we did have that weird problem on windows with the single threaded rts that we never tracked down. However I get the feeling that we shouldn't be putting too much effort into fixing the single threaded rts on windows as it will not be around for ever. > > Plan 2: Make the threaded rts do what we want. > > > > This is hard and involves begging Simon M to do lots of work. > > How many people are required to beg? I volunteer :) Heh :-) Well it's got to be clear that it's worth the effort. We don't want to steal too much of his paper-writing time. > > Plan 3: perhaps the IO monad isn't the right monad > > > > It's really quite convenient to have complete access to the IO monad > > when doing GUI stuff and that seems to be the design that most recent > > libs have chosen. > > Can I read a file in a GUI thread? Can I spawn a process and read an > external handle? I suspect that more and more things would be added to > the GUI monad until GUI == IO. Aye, there would be methods to get between them. So you could do IO in the GUI monad using liftIO, and perhaps another liftIO variant for IO actions that would block. So we wouldn't need to keep adding things to the GUI monad. The crucial ones would be for liftIO, forkGUI and MVar-style synchronisation. Duncan From cgibbard at gmail.com Tue Nov 14 21:48:48 2006 From: cgibbard at gmail.com (Cale Gibbard) Date: Tue Nov 14 21:47:58 2006 Subject: [Haskell-cafe] Haskell Debugging In-Reply-To: <455A6A4B.3070007@ijs.si> References: <45589012.9060708@ijs.si> <89ca3d1f0611141417u5ed956b8h7a769bb0c25ca619@mail.gmail.com> <455A6A4B.3070007@ijs.si> Message-ID: <89ca3d1f0611141848v2c0506f4q8124ad8093128fa6@mail.gmail.com> On 14/11/06, Valentin Gjorgjioski wrote: > Just one more thing > > If I write > > ex9 :: [Float] > ex9 = (observe "after reverse" ) reverse [10.0,7.0,3.0,0.0,4.0] > > it doesn't work. If I delete ex9 :: [Float] then it works fine. any > suggestions? > This doesn't happen for me. The only thing I can think of trying is to check the type of ex9 by deleting the type signature, loading the file, and typing: :t ex9 on the hugs prompt. If it prints anything other than ex9 :: [Float] then you'll have your answer. - Cale From cgibbard at gmail.com Tue Nov 14 21:59:43 2006 From: cgibbard at gmail.com (Cale Gibbard) Date: Tue Nov 14 21:58:54 2006 Subject: [Haskell-cafe] Haskell Debugging In-Reply-To: <89ca3d1f0611141848v2c0506f4q8124ad8093128fa6@mail.gmail.com> References: <45589012.9060708@ijs.si> <89ca3d1f0611141417u5ed956b8h7a769bb0c25ca619@mail.gmail.com> <455A6A4B.3070007@ijs.si> <89ca3d1f0611141848v2c0506f4q8124ad8093128fa6@mail.gmail.com> Message-ID: <89ca3d1f0611141859k4267ebcds5dcb40c3824c2809@mail.gmail.com> On 14/11/06, Cale Gibbard wrote: > On 14/11/06, Valentin Gjorgjioski wrote: > > Just one more thing > > > > If I write > > > > ex9 :: [Float] > > ex9 = (observe "after reverse" ) reverse [10.0,7.0,3.0,0.0,4.0] > > > > it doesn't work. If I delete ex9 :: [Float] then it works fine. any > > suggestions? > > > This doesn't happen for me. The only thing I can think of trying is to > check the type of ex9 by deleting the type signature, loading the > file, and typing: > :t ex9 > on the hugs prompt. If it prints anything other than > ex9 :: [Float] > then you'll have your answer. > > - Cale > Sorry, I just realised what you meant, and I do get the behaviour you initially described without the typesignature there. Actually, without the typesignature, it's inferring the type [Double], due to defaulting. However, adding the typesignature ex9 :: [Double] will again cause it to print the values in the list rather than raw thunks. So perhaps it's because you haven't given a typesignature explicitly, so the list is initially polymorphic, which means that the values in it are actually function calls initially (that is, things like (fromRational 10.0)), and they only end up getting a specialised type later, when hugs finishes compiling the module and applies the monomorphism restriction and defaulting, but hugs isn't going back and optimising the function with the additional knowledge? I don't really know, that's my best guess at it. Maybe someone who knows hugs better would know with more certainty? - Cale From cgibbard at gmail.com Tue Nov 14 22:07:29 2006 From: cgibbard at gmail.com (Cale Gibbard) Date: Tue Nov 14 22:06:36 2006 Subject: [Haskell-cafe] pleac, examples, etc In-Reply-To: <20061115000016.67313.qmail@web57207.mail.re3.yahoo.com> References: <1163483862.12553.275756050@webmail.messagingengine.com> <20061115000016.67313.qmail@web57207.mail.re3.yahoo.com> Message-ID: <89ca3d1f0611141907j5520e781i17f5a9ff1d0b4f02@mail.gmail.com> On 14/11/06, chris moline wrote: > --- brad clawsie wrote: > > it would be great if some of the more informed > > posters here took a stab > > at filling in > > > > > http://pleac.sourceforge.net/pleac_haskell/index.html > > > > a neat site for cookbook-style problem solving > > What I've always found funny about pleac is that none > of the examples are actually Haskell, but some weird > Haskell-with-oo-features. Does anyone know what > language it is? > > Here are some examples: > > password = [1..8].mapM (\_ -> rand (0, chars.length > -1) >>> (chars!)) > > -- in haskell, regexp are first class, then can be > appended, sometimes easier to read > m0' s = .... (s ==~ dec_number) .... They are actually Haskell, but notice the appendix: http://pleac.sourceforge.net/pleac_haskell/a1102.html It's Haskell with a completely bizarre prelude. No real new features were added to the language itself. Replacing composition with reverse function application is a waste of operator symbols. Personally, if I was going to change (.), it would be to define it as fmap, which (as a number of people, myself included, have pointed out) together with the instance of Functor for ((->) e) would generalise ordinary composition, map, liftM, etc. - Cale From dons at cse.unsw.edu.au Tue Nov 14 23:54:31 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Tue Nov 14 23:53:41 2006 Subject: [Haskell-cafe] Debugging partial functions by the rules Message-ID: <20061115045431.GE3715@cse.unsw.EDU.AU> So all this talk of locating head [] and fromJust failures got me thinking: Couldn't we just use rewrite rules to rewrite *transparently* all uses of fromJust to safeFromJust, tagging the call site with a location? To work this requires a few things to go right: * a rewrite rule * assertions * and rewrite rules firing before assertions are expanded Let's try this. Consider the program: 1 import qualified Data.Map as M 2 import Data.Maybe 3 4 main = print f 5 6 f = let m = M.fromList 7 [(1,"1") 8 ,(2,"2") 9 ,(3,"3")] 10 s = M.lookup 4 m 11 in fromJust s When we run it we get the not so useful error: $ ./A A: Maybe.fromJust: Nothing Ok, so we have a few tricks for locating this, using LocH (http://www.cse.unsw.edu.au/~dons/loch.html), we can catch an assertion failure, but we have to insert the assertion by hand: 1 import Debug.Trace.Location 2 import qualified Data.Map as M 3 import Data.Maybe 4 5 main = do print f 6 7 f = let m = M.fromList 8 [(1,"1") 9 ,(2,"2") 10 ,(3,"3")] 11 s = M.lookup 4 m 12 in safeFromJust assert s 13 14 safeFromJust a = check a . fromJust Which correctly identifies the call site: $ ./A A: A.hs:12:20-25: Maybe.fromJust: Nothing Now, this approach is a little fragile. 'assert' is only respected by GHC if -O is *not* on, so if we happened to try this trick with -O, we'd get: $ ./A A: Debug.Trace.Location.failure So lesson one: you have to do the bug hunting with -Onot. Currently there's -fignore-asserts for turning off assertions, but no flag for turning them on with -O, Simon, could this be fixed? Could we get a -frespect-asserts that works even with -O ? Ok, assuming this assert trick is used, can we get the compiler to insert the asserts for us? If so, this would be a great advantage, you'd just be able to switch on a flag, or import a debugging module, and your fromJusts would be transparently rewritten. With rewrite rules we do just this! So, to our initial unsafe use of fromJust, we add a rewrite rule: -- -- rewrite fromJust to a located version, and hope that GHC expands -- 'assert' after the rule fires.. -- {-# RULES "located fromJust" fromJust = check assert . myFromJust #-} This just tells the compiler to replace every occurence of fromJust with a assertion-throwing fromJust, should it fail. We have to use myFromJust here, to avoid rule recursion. -- -- Inlined to avoid recursion in the rule: -- myFromJust :: Maybe a -> a myFromJust Nothing = error "Maybe.fromJust: Nothing" -- yuck myFromJust (Just x) = x Ok, so can we get ghc to rewrite fromJust to the safe fromJust magicaly? $ ghc --make -Onot A.hs -fglasgow-exts -ddump-simpl-stats [1 of 1] Compiling Main ( A.hs, A.o ) 1 RuleFired 1 located fromJust Linking A ... Yes, the rule fired! GHC *did* rewrite our fromJust to a more useful fromJust. Running it: $ ./A A: A.hs:19:36-41: Maybe.fromJust: Nothing Looks good! But that is deceiving: the assert was expanded before the rule fired, and refers to the rewrite rule source line (line 19), not the fromJust call site (line 12). Now if we could just have the 'assert' token inserted into the AST before it was expanded, we'd be home and dry. Could this be done with TH? Or could we arrange for asserts in rewrite rules not to be expanded till later? Note that this is still a useful technique, we can rewrite head/fromJust/... to some other possibly more useful message. And if we can constrain the rule to fire in only particular modules, we may be able to narrow down the bug, just by turning on a rule. For example, adding: {-# RULES "located fromJust" fromJust = safeFromJust #-} safeFromJust s = case s of Nothing -> "safeFromJust: failed with Nothing. Ouch" Just x -> x will produce: $ ./A "safeFromJust: failed with Nothing. Ouch" So rewrite rules can be used to transparently alter uses of partial functions like head and fromJust. So, further work: * have 'assert' respected when -O is on * think up a technique for splicing in 'assert' via rewrite rules (or TH ...) such that the src locations are expanded after the rewrite, and correctly reflect the location of the splice point. Any ideas? -- Don From dagit at eecs.oregonstate.edu Wed Nov 15 00:21:59 2006 From: dagit at eecs.oregonstate.edu (Jason Dagit) Date: Wed Nov 15 00:21:06 2006 Subject: [Haskell-cafe] Debugging partial functions by the rules In-Reply-To: <20061115045431.GE3715@cse.unsw.EDU.AU> References: <20061115045431.GE3715@cse.unsw.EDU.AU> Message-ID: On 11/14/06, Donald Bruce Stewart wrote: > So, further work: > > * have 'assert' respected when -O is on > > * think up a technique for splicing in 'assert' via rewrite rules (or TH > ...) such that the src locations are expanded after the rewrite, and > correctly reflect the location of the splice point. > > Any ideas? Overall I like what you've said. But when I read it, I wondered, "Why do I have to fix every function which calls error? Why can't we just fix error?" We discussed this a bit in #haskell and it was pointed out that, that would only give us the line number of where error is defined. Someone mentoined stack traces aren't so great in haskell, but Cale sugested we try to get a "cost-center trace" plus line numbers? Even though __FILE__ and __LINE__ are a bit simplistic in C they are quite handy for things like this. $0.02, Jason From dons at cse.unsw.edu.au Wed Nov 15 01:14:28 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Wed Nov 15 01:13:36 2006 Subject: [Haskell-cafe] Debugging partial functions by rewriting ... In-Reply-To: <20061115045431.GE3715@cse.unsw.EDU.AU> References: <20061115045431.GE3715@cse.unsw.EDU.AU> Message-ID: <20061115061428.GF3715@cse.unsw.EDU.AU> Ok, so I took the rule rewriting idea and added a preprocessor instead, that inserts 'assert's for you, currently just for head,tail and fromJust. This program, for example: module Main where import qualified Data.Map as M import Data.Maybe main = do print f f = let m = M.fromList [(1,"1") ,(2,"2") ,(3,"3")] s = M.lookup 4 m :: Maybe String in head ([] :: [()]) Fails with: $ ghc A.hs --make [1 of 1] Compiling Main ( A.hs, A.o ) Linking A ... $ ./A A: Maybe.fromJust: Nothing Add one import statement: import Debug.Trace.Location And recompile with the preprocessor: $ ghc A.hs --make -pgmF loch -F -no-recomp [1 of 1] Compiling Main ( A.hs, A.o ) Linking A ... And our fromJust is rewritten to a located fromJust: $ ./A A: A.hs:14:14-19: Maybe.fromJust: Nothing Currently this only works for fromJust, head and tail. Adding user-specified located functions should be trivial. The 'loch' preprocessor is in the darcs repo, now. http://www.cse.unsw.edu.au/~dons/code/loch/ Comments, suggestions? -- Don From fis at wiwi.hu-berlin.de Wed Nov 15 01:57:59 2006 From: fis at wiwi.hu-berlin.de (Matthias Fischmann) Date: Wed Nov 15 01:58:04 2006 Subject: [Haskell-cafe] Debugging partial functions by the rules In-Reply-To: <20061115045431.GE3715@cse.unsw.EDU.AU> References: <20061115045431.GE3715@cse.unsw.EDU.AU> Message-ID: <20061115065759.GT14168@localhost.localdomain> On Wed, Nov 15, 2006 at 03:54:31PM +1100, Donald Bruce Stewart wrote: > To: glasgow-haskell-users@haskell.org > Cc: haskell-cafe@haskell.org > From: Donald Bruce Stewart > Date: Wed, 15 Nov 2006 15:54:31 +1100 > Subject: [Haskell-cafe] Debugging partial functions by the rules > > So all this talk of locating head [] and fromJust failures got me > thinking: > > Couldn't we just use rewrite rules to rewrite *transparently* > all uses of fromJust to safeFromJust, tagging the call site > with a location? The problem with tagging the call site is that there has to be an explicit location somewhere in the code that is maximally meaningful for the user. I don't think that's the whole story. I have always been wondering why error shouldn't always return a call stack from the occurrance of fromJust up to the function I typed into ghci (or up to main, for that matter). I guess this is because the call tree is rewritten extensively before being evaluated, and the output wouldn't be so easy to match to the source code? But shouldn't the mapping of source tree to executable tree be bijective, at least in theory? How hard would it be to hack call stack output into ghc? -matthias -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061115/d8996b6c/attachment.bin From oleg at pobox.com Wed Nov 15 03:21:00 2006 From: oleg at pobox.com (oleg@pobox.com) Date: Wed Nov 15 03:20:39 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules Message-ID: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> Donald Bruce Stewart wrote: > So all this talk of locating head [] and fromJust failures got me > thinking: > > Couldn't we just use rewrite rules to rewrite *transparently* > all uses of fromJust to safeFromJust, tagging the call site > with a location? I'm sorry for shifting the topic: I'm wondering if, rather than trying to make an error message more informative, we ought to make sure that no error will ever arise? The fromJust and `head of empty list' errors are totally equivalent to the dereferencing of zero pointer in C++ or NullPointerException in Java. It pains me to see that exactly the same problem arises in Haskell -- keeping in mind that already in C++ and Java one may exterminate these errors given right encapsulations. Languages like Cyclone or Cw use the type system to eliminate such errors. Surely Haskell can do something about this? This topic has been discussed at length on this list. It seems that the discussion came to the conclusion that eliminating head of the empty list error is possible and quite easy in Haskell. http://www.haskell.org/pipermail/haskell-cafe/2006-September/017915.html http://www.haskell.org/pipermail/haskell-cafe/2006-September/017937.html As to fromJust: would the world come to an end if this function is just not available? Oftentimes when we get the value of the type |Maybe a|, the algorithm prescribes the actions for the case if this value is Nothing. Thus the function `maybe', the deconstructor, seems to be called for. And if we are dead sure that the |Maybe a| value is definitely |Just smth| and we need to extract this |smth|, we can always write maybe (assert False undefined) id value I like how this phrase stands out in the code, to remind me to double-check my certainty about the value (and perhaps, to re-factor the code). Similarly for empty lists: it is often algorithmically significant as it is the base case for our recursion/induction. Thus, we have to make the null check according to the algorithm anyway. The type system can carry the result of such a test, so we don't have to repeat it. The functions head and tail should operate on the newtype NonemptyList -- in which case they are total. Other list functions may remain as they are, because we can always `forget' the NonemptyList tag. The run-time overhead is zero, the notational overhead is not much: writing a few extra `fromNonemptyList'. Compare with writing `fromIntegral', especially in the FFI-related code. The Haskell type system can do far more complex things, for example, solve the pervasive SQL injections and cross-site scripting problems: http://blog.moertel.com/articles/2006/10/18/a-type-based-solution-to-the-strings-problem (This URL appeared on one of the recent Haskell Weekly News, btw). Surely we can do something about a far simpler problem of head [] and fromJust? We may have to adjust our coding styles a little. The adjustment doesn't appear extensive; besides, isn't the whole point of programming in Haskell is to think differently? From dons at cse.unsw.edu.au Wed Nov 15 03:44:25 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Wed Nov 15 03:45:17 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> References: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> Message-ID: <20061115084425.GG3715@cse.unsw.EDU.AU> oleg: > > Donald Bruce Stewart wrote: > > So all this talk of locating head [] and fromJust failures got me > > thinking: > > > > Couldn't we just use rewrite rules to rewrite *transparently* > > all uses of fromJust to safeFromJust, tagging the call site > > with a location? > > I'm sorry for shifting the topic: I'm wondering if, rather than trying > to make an error message more informative, we ought to make sure that > no error will ever arise? > > The fromJust and `head of empty list' errors are totally equivalent to > the dereferencing of zero pointer in C++ or NullPointerException in > Java. It pains me to see that exactly the same problem arises in > Haskell -- keeping in mind that already in C++ and Java one may > exterminate these errors given right encapsulations. Languages like > Cyclone or Cw use the type system to eliminate such errors. Surely > Haskell can do something about this? Yes, these techniques are fairly well known now, and hopefully some of the more experienced Haskellers are using them (I certainly use the non-empty list tricks). Any anyone with more than 6 months Haskell knows to avoid fromJust. The problem I see is that head/fromJust errors are usually caused by *beginner* Haskellers, who don't know the techniques for statically avoiding them. One solution would be to deprecate fromJust (we recently decided not to add fromLeft/Right for the same reasons). Having a compiler warning is a good way to encourage good behaviour :) But it seems hardly likely that head will be deprecated any time soon, and we have no support for checked non-empty lists in the base libraries. So how do we help out the beginners, other than warning about fromJust, and providing a useful error message as we can, for when they just go ahead and use head anyway? -- Don From simonpj at microsoft.com Wed Nov 15 04:04:01 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Wed Nov 15 04:03:15 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: <20061115084425.GG3715@cse.unsw.EDU.AU> References: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> <20061115084425.GG3715@cse.unsw.EDU.AU> Message-ID: | > The fromJust and `head of empty list' errors are totally equivalent to | > the dereferencing of zero pointer in C++ or NullPointerException in | > Java. It pains me to see that exactly the same problem arises in | > Haskell -- keeping in mind that already in C++ and Java one may | > exterminate these errors given right encapsulations. Languages like | > Cyclone or Cw use the type system to eliminate such errors. Surely | > Haskell can do something about this? | | Yes, these techniques are fairly well known now, and hopefully some of | the more experienced Haskellers are using them (I certainly use the | non-empty list tricks). Any anyone with more than 6 months Haskell knows | to avoid fromJust. | | The problem I see is that head/fromJust errors are usually caused by | *beginner* Haskellers, who don't know the techniques for statically | avoiding them. I don't agree. My programs have invariants that I can't always express in a way that the type system can understand. E.g. I know that a variable is in scope, so searching for it in an environment can't fail: head [ v | (n,v) <- env, n==target ] (Maybe if I had an Oleg implant I could express all this in the type system -- but I don't.) But yes, we should have more sophisticated techniques to express and check these invariants. With Dana Xu I'm working on this very thing (see her Haskell Workshop paper http://www.cl.cam.ac.uk/~nx200/research/escH-hw.ps); and Neil Mitchell is doing complementary work at York. So I think there is reason to be hopeful. Simon From ndmitchell at gmail.com Wed Nov 15 05:00:38 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Nov 15 04:59:46 2006 Subject: [Haskell-cafe] Debugging partial functions by the rules In-Reply-To: <20061115065759.GT14168@localhost.localdomain> References: <20061115045431.GE3715@cse.unsw.EDU.AU> <20061115065759.GT14168@localhost.localdomain> Message-ID: <404396ef0611150200y7a6beegc250727f9db5ca30@mail.gmail.com> Hi > I have always been wondering why error shouldn't always return a call > stack from the occurrance of fromJust up to the function I typed into > ghci (or up to main, for that matter). yhi-stack (as yet unreleased) does exactly this, without requiring you to recompile your code even. hat-stack also does this. Thanks Neil From ndmitchell at gmail.com Wed Nov 15 05:07:10 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Nov 15 05:06:18 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: <20061115084425.GG3715@cse.unsw.EDU.AU> References: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> <20061115084425.GG3715@cse.unsw.EDU.AU> Message-ID: <404396ef0611150207i4c293f70v8d58343b457c3042@mail.gmail.com> Hi > Yes, these techniques are fairly well known now, and hopefully some of > the more experienced Haskellers are using them (I certainly use the > non-empty list tricks). Any anyone with more than 6 months Haskell knows > to avoid fromJust. I'm not, I use fromJust all the time. Ditto for head, init, maximum, foldr1... > One solution would be to deprecate fromJust (we recently decided not to > add fromLeft/Right for the same reasons). Having a compiler warning is a > good way to encourage good behaviour :) We didn't decide not to add fromLeft/fromRight, Russell decided to defer it to a later patch. I am still very interested in them being put in! There seem to be two sides forming to this issue - use partial functions or don't. I don't see why we should restrict the functions available to the partial people, when the unpartial people can choose not to use them. Thanks Neil From simonpj at microsoft.com Wed Nov 15 05:56:59 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Wed Nov 15 05:56:12 2006 Subject: [Haskell-cafe] Debugging partial functions by the rules In-Reply-To: <20061115065759.GT14168@localhost.localdomain> References: <20061115045431.GE3715@cse.unsw.EDU.AU> <20061115065759.GT14168@localhost.localdomain> Message-ID: | I have always been wondering why error shouldn't always return a call | stack from the occurrance of fromJust up to the function I typed into | ghci (or up to main, for that matter). | | I guess this is because the call tree is rewritten extensively before | being evaluated, and the output wouldn't be so easy to match to the | source code? But shouldn't the mapping of source tree to executable | tree be bijective, at least in theory? Simon and I have been brainstorming on just such a thing. I've jotted down our current notes (well some of them) here http://hackage.haskell.org/trac/ghc/wiki/ExplicitCallStack Simon From claus.reinke at talk21.com Wed Nov 15 05:58:16 2006 From: claus.reinke at talk21.com (Claus Reinke) Date: Wed Nov 15 05:57:30 2006 Subject: [Haskell-cafe] Debugging partial functions by the rules References: <20061115045431.GE3715@cse.unsw.EDU.AU> Message-ID: <009201c708a4$f5368c40$96437ad5@cr3lt> > Couldn't we just use rewrite rules to rewrite *transparently* > all uses of fromJust to safeFromJust, tagging the call site > with a location? .. > Looks good! But that is deceiving: the assert was expanded before the rule > fired, and refers to the rewrite rule source line (line 19), not the fromJust > call site (line 12). Now if we could just have the 'assert' token inserted > into the AST before it was expanded, we'd be home and dry. Could this be done > with TH? Or could we arrange for asserts in rewrite rules not to be expanded > till later? .. > Any ideas? http://www.haskell.org/pipermail/glasgow-haskell-users/2006-November/011545.html claus From lennart at augustsson.net Wed Nov 15 07:37:34 2006 From: lennart at augustsson.net (Lennart Augustsson) Date: Wed Nov 15 07:37:22 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: <404396ef0611150207i4c293f70v8d58343b457c3042@mail.gmail.com> References: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> <20061115084425.GG3715@cse.unsw.EDU.AU> <404396ef0611150207i4c293f70v8d58343b457c3042@mail.gmail.com> Message-ID: Should Haskell also provide unrestricted side effects, setjmp/ longjmp, missile launching functions, etc? After all, people who don't want to use them can just avoid them. :) On Nov 15, 2006, at 05:07 , Neil Mitchell wrote: > Hi > >> Yes, these techniques are fairly well known now, and hopefully >> some of >> the more experienced Haskellers are using them (I certainly use the >> non-empty list tricks). Any anyone with more than 6 months Haskell >> knows >> to avoid fromJust. > > I'm not, I use fromJust all the time. Ditto for head, init, > maximum, foldr1... > >> One solution would be to deprecate fromJust (we recently decided >> not to >> add fromLeft/Right for the same reasons). Having a compiler >> warning is a >> good way to encourage good behaviour :) > > We didn't decide not to add fromLeft/fromRight, Russell decided to > defer it to a later patch. I am still very interested in them being > put in! > > There seem to be two sides forming to this issue - use partial > functions or don't. I don't see why we should restrict the functions > available to the partial people, when the unpartial people can choose > not to use them. > > Thanks > > Neil > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From ross at soi.city.ac.uk Wed Nov 15 07:58:49 2006 From: ross at soi.city.ac.uk (Ross Paterson) Date: Wed Nov 15 07:57:57 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: References: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> <20061115084425.GG3715@cse.unsw.EDU.AU> Message-ID: <20061115125848.GA10355@soi.city.ac.uk> On Wed, Nov 15, 2006 at 09:04:01AM +0000, Simon Peyton-Jones wrote: > I don't agree. My programs have invariants that I can't always express > in a way that the type system can understand. E.g. I know that a > variable is in scope, so searching for it in an environment can't fail: > head [ v | (n,v) <- env, n==target ] > (Maybe if I had an Oleg implant I could express all this in the type > system -- but I don't.) Yes, that is sometimes true (though many of the uses of fromJust I see could be easily avoided). The problem is an imbalance of costs. It's so easy to write these things, to the point of discouraging alternatives, but the costs come in debugging and reading. Every time I read code containing these functions, I have to perform a non-local analysis to verify the invariant, or even to determine the invariant. I don't think it's unreasonable to ask the programmer to give some justification, in something like (using Neil's library): headNote "The variable is in scope" [...] That would be extra tagging for the static analysis techniques too. Of course there'd be nothing to stop someone defining head = headNote "I'm all right, Jack" From simonpj at microsoft.com Wed Nov 15 08:03:29 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Wed Nov 15 08:02:39 2006 Subject: [Haskell-cafe] RE: Debugging partial functions by the rules In-Reply-To: <20061115045431.GE3715@cse.unsw.EDU.AU> References: <20061115045431.GE3715@cse.unsw.EDU.AU> Message-ID: | Looks good! But that is deceiving: the assert was expanded before the rule | fired, and refers to the rewrite rule source line (line 19), not the fromJust | call site (line 12). Now if we could just have the 'assert' token inserted | into the AST before it was expanded, we'd be home and dry. Could this be done | with TH? Or could we arrange for asserts in rewrite rules not to be expanded | till later? That's difficult. Trouble is, the assert expansion happens right at the front, before any desugaring or program transformation. But rewrite rules fire much, much later, in the simplifier. It is, however, possible (or could be made possible) to answer the question "When this rule fires, what module am I compiling", and make that available in the RHS of the rule, by some magic incantation. Harder would be "when this rule fires, what top-level function's RHS is being simplified?". But even that is tricky, because it might be "lvl_4532", a function created by the simplifier itself. The only solid way to connect to programmer-comprehensible stuff is by transforming the original, unadulterated source code, as Hat does, and as Jhc does, and as Simon and I are musing about doing. Your idea is to do something cheap and cheerful, which is always a good plan. But I don't see how to make it fly. (The -O thing, and/or providing $currentLocation rather than just 'assert', seem easier.) Simon From ndmitchell at gmail.com Wed Nov 15 08:07:13 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Nov 15 08:06:21 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: References: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> <20061115084425.GG3715@cse.unsw.EDU.AU> <404396ef0611150207i4c293f70v8d58343b457c3042@mail.gmail.com> Message-ID: <404396ef0611150507j2a7a26bu4f05029bc71b4575@mail.gmail.com> Hi > Should Haskell also provide unrestricted side effects, setjmp/ > longjmp, missile launching functions, etc? After all, people who > don't want to use them can just avoid them. :) Fair point. But if you eliminate incomplete cases, and the error function, you'd probably need to increase the power of the type checker by introducing dependant types. It's a good research avenue, and an interesting approach, but its not what Haskell is to me (but it might be to others). > Every time I read code containing these functions, I have to > perform a non-local analysis to verify the invariant, or even to determine > the invariant. If you use the Programmatica annotations, the ESC/Haskell annotations or Catch then you can have these assertions checked for you, and in the case of Catch even infered for you. Admitedly ESC/Haskell and Catch aren't ready for use yet, but they will be soon! Thanks Neil From bulat.ziganshin at gmail.com Wed Nov 15 06:57:38 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Wed Nov 15 08:11:55 2006 Subject: [Haskell-cafe] Re: [Haskell] I18N, external strings In-Reply-To: <455AC36A.9020202@imn.htwk-leipzig.de> References: <455AC36A.9020202@imn.htwk-leipzig.de> Message-ID: <449526149.20061115145738@gmail.com> Hello Johannes, Wednesday, November 15, 2006, 10:36:10 AM, you wrote: > What methods and tools are there for i18n of Haskell programs? > In Haskell, I see at least two problems: > a) reading the file is in IO if you need utf8 and other encodings support, you can use Streams lib: h <- openFile "test" ReadMode >>= withEncoding utf8 http://haskell.org/haskellwiki/Library/Streams > b) there are no "global variables". implicit parameters perhaps? there is a sort of global vars: ref_command = unsafePerformIO$ newIORef$ error "undefined ref_command" uiStartCommand command = do writeIORef ref_command command .. uiStartProcessing filelist = do command <- readIORef ref_command .. but implicit parameters, of course, are more intelligent approach -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From u.stenzel at web.de Wed Nov 15 07:57:48 2006 From: u.stenzel at web.de (Udo Stenzel) Date: Wed Nov 15 08:30:14 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: <20061115084425.GG3715@cse.unsw.EDU.AU> References: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> <20061115084425.GG3715@cse.unsw.EDU.AU> Message-ID: <20061115125747.GA2012@web.de> Donald Bruce Stewart wrote: > So how do we help out the beginners, other than warning about fromJust, > and providing a useful error message as we can, for when they just go > ahead and use head anyway? Kill head and tail right now and provide a safe equivalent? Either uncons :: [a] -> Maybe (a,[a]) which is to be used in conjunction with 'maybe' (or with fmap/first/second/unfoldr) or list :: r -> (a -> [a] -> r) -> [a] -> r in analogy with 'maybe' and 'either'. Or combine it with 'foldr' to form the paramorphism (if I got the terminology right). Or even better, don't mention the existence of uncons and encourage people to write list consumers in terms of 'destroy'. -Udo -- Sturgeon's Law: Ninety percent of everything is crud. (Sturgeon was an optimist.) -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061115/6ed247ff/attachment.bin From bulat.ziganshin at gmail.com Wed Nov 15 08:32:52 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Wed Nov 15 09:03:20 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: References: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> <20061115084425.GG3715@cse.unsw.EDU.AU> <404396ef0611150207i4c293f70v8d58343b457c3042@mail.gmail.com> Message-ID: <1326145825.20061115163252@gmail.com> Hello Lennart, Wednesday, November 15, 2006, 3:37:34 PM, you wrote: > Should Haskell also provide unrestricted side effects, setjmp/ > longjmp, missile launching functions, etc? After all, people who > don't want to use them can just avoid them. :) these are documented in "tackling the awkward squad, or that remains from our beauty Haskell after uncheckedMissileLauch" :) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From agocorona at gmail.com Wed Nov 15 09:22:49 2006 From: agocorona at gmail.com (Alberto G. Corona ) Date: Wed Nov 15 09:21:59 2006 Subject: [Haskell-cafe] Re: Haskell custom search engine Message-ID: By the way, I have developped the core of a search engine completely in Haskell. It can index arbitrary objects (including files, of course) has definitions for filters, with predefined filters for plain text, HTML/XML and a general filter for Haskell data types It has basic search capabilities: it returns a list of identifiers (URIs) of the objects that contains all the entered keywords. But it is fairly easy to accept arbitrary AND OR and NOT conditions. Just query parsing is necessary. More info: http://haskell-web.blogspot.com/2006/11/search-engine-written-in-haskell.html The source of Search.hs can be found here -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061115/296d4e3d/attachment.htm From lemming at henning-thielemann.de Wed Nov 15 09:22:17 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Wed Nov 15 09:23:29 2006 Subject: [Haskell-cafe] the case of the 100-fold program speedup In-Reply-To: <455A2FD7.1040909@ropine.com> References: <455A2FD7.1040909@ropine.com> Message-ID: On Tue, 14 Nov 2006, Seth Gordon wrote: > It took me a week to figure out the right algorithm for combining these > two procedures and write some almost-working code that implemented it. > It took a co-worker of mine another few days to find the bugs that had > eluded me. Were these bugs of the kind that would have been found by a static type checker, say the one of Haskell? From sethg at ropine.com Wed Nov 15 09:49:20 2006 From: sethg at ropine.com (Seth Gordon) Date: Wed Nov 15 09:48:32 2006 Subject: [Haskell-cafe] the case of the 100-fold program speedup In-Reply-To: References: <455A2FD7.1040909@ropine.com> Message-ID: <455B28F0.8050008@ropine.com> Henning Thielemann wrote: > On Tue, 14 Nov 2006, Seth Gordon wrote: > > >>It took me a week to figure out the right algorithm for combining these >>two procedures and write some almost-working code that implemented it. >>It took a co-worker of mine another few days to find the bugs that had >>eluded me. > > > Were these bugs of the kind that would have been found by a static type > checker, say the one of Haskell? The most significant bug that my co-worker caught was in the math, not the implementation--when translating the centroid formula from big-sigma notation to a recurrence, I accidentally wrote (x_i x_{i+1}) when I should have written (x_i + x_{i+1}). My stupidity surpasses the stupidity-catching power of the type checker. There were less significant bugs that probably would have been caught by static type checking, but in this case I think the unit tests caught them just as quickly. The "producer" part of the clip-and-centroid algorithm generates 0, 1, or 2 vertices for every vertex of the original polygon, which are then fed into the "consumer" part to compute the centroid. It did cross my mind as I was writing the Python code that this sort of thing could be handled much more concisely with the List monad, but doing the whole thing in Haskell would have required (a) writing Haskell glue code to either interface with the OGR library or parse WKT strings, and (b) convincing my co-workers that Haskell was *so* incredibly useful that it was worth adding another language as a build-time dependency. (I'm laying the groundwork for (b) in my Copious Free Time....) > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From jon.fairbairn at cl.cam.ac.uk Wed Nov 15 09:48:27 2006 From: jon.fairbairn at cl.cam.ac.uk (=?utf-8?b?SsOzbiBGYWlyYmFpcm4=?=) Date: Wed Nov 15 09:48:43 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules References: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> <20061115084425.GG3715@cse.unsw.EDU.AU> Message-ID: Simon Peyton-Jones writes: > | The problem I see is that head/fromJust errors are usually > |caused by *beginner* Haskellers, who don't know the > |techniques for statically avoiding them. > > I don't agree. My programs have invariants that I can't > always express in a way that the type system can > understand. E.g. I know that a variable is in scope, so > searching for it in an environment can't fail: > head [ v | (n,v) <- env, n==target ] (Maybe if I had > an Oleg implant I could express all this in the type system > -- but I don't.) But instead of ?blah (head [ v | (n,v) <- env, n==target ]) blah?, you could write blah the_v_in_scope blah where (the_v_in_scope:_) = [ v | (n,v) <- env, n==target ] and get a source-code located error message, couldn't you? It's not very high tech, but it's what you would write if head didn't exist, and it doesn't seem /that/ great an imposition. -- J?n Fairbairn Jon.Fairbairn@cl.cam.ac.uk From ndmitchell at gmail.com Wed Nov 15 09:55:47 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Nov 15 09:54:55 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: References: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> <20061115084425.GG3715@cse.unsw.EDU.AU> Message-ID: <404396ef0611150655x4b6124f2m28a9365919ae8646@mail.gmail.com> Hi Haskell is great for equational reasoning. > blah the_v_in_scope blah > where (the_v_in_scope:_) = [ v | (n,v) <- env, n==target ] This piece of code isn't. If you used head then you could trivially inline the_v_in_scope, this way is a lot harder. You might spot a pointfree pattern and lift it up. You might move code around more freely. Lots of patterns like this breaks the equational reasoning in the style that most people are used to. > and it doesn't seem /that/ great an > imposition. I disagree, this is a massive imposition, and requires lots of refactoring, and is just a little bit ugly. What to go in a where should be the programmers decision, not the decision based on which hoops one has to hop through to write a debuggable Haskell program. Thanks Neil From ketil+haskell at ii.uib.no Wed Nov 15 10:03:50 2006 From: ketil+haskell at ii.uib.no (Ketil Malde) Date: Wed Nov 15 10:03:01 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: (Lennart Augustsson's message of "Wed, 15 Nov 2006 07:37:34 -0500") References: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> <20061115084425.GG3715@cse.unsw.EDU.AU> <404396ef0611150207i4c293f70v8d58343b457c3042@mail.gmail.com> Message-ID: Lennart Augustsson writes: > Should Haskell also provide unrestricted side effects, setjmp/ > longjmp, missile launching functions, etc? After all, people who > don't want to use them can just avoid them. :) Yes. It is indeed a common problem that programs have unintended behavior, and partial functions are only the tip of the iceberg. We can keep patching things up. For instance, 'head' can be made to never fail simply by requiring all lists to be infinite. Similarly, fromJust can be fixed by having 'data Maybe a = Just a', and doing away with 'Nothing', which is hardly useful for anything anyway. But this is only superficial patchwork that glosses over the deeper problem. I therefore propose that all functions should either be of type '() -> ()', or non-terminating. That should avoid most error messages, I think, and make it very easy to avoid any unintended consequences - and the programmer is relieved of the burden of actively avoiding dangerous stuff. Is it possible to implement this for Haskell'? -k -- If I haven't seen further, it is by standing in the footprints of giants From robdockins at fastmail.fm Wed Nov 15 10:41:54 2006 From: robdockins at fastmail.fm (Robert Dockins) Date: Wed Nov 15 10:37:45 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: References: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> <20061115084425.GG3715@cse.unsw.EDU.AU> Message-ID: On Nov 15, 2006, at 9:48 AM, J?n Fairbairn wrote: > Simon Peyton-Jones writes: > >> | The problem I see is that head/fromJust errors are usually >> |caused by *beginner* Haskellers, who don't know the >> |techniques for statically avoiding them. >> >> I don't agree. My programs have invariants that I can't >> always express in a way that the type system can >> understand. E.g. I know that a variable is in scope, so >> searching for it in an environment can't fail: >> head [ v | (n,v) <- env, n==target ] (Maybe if I had >> an Oleg implant I could express all this in the type system >> -- but I don't.) > > But instead of ?blah (head [ v | (n,v) <- env, n==target ]) > blah?, you could write > > blah the_v_in_scope blah > where (the_v_in_scope:_) = [ v | (n,v) <- env, n==target ] > > and get a source-code located error message, couldn't you? > It's not very high tech, but it's what you would write if > head didn't exist, and it doesn't seem /that/ great an > imposition. Or how about.... ?? lookupVarible target env = case [ v | (n,v) <- env, n==target ] of (x:_) -> x _ -> assert False $ "BUG: Unexpected variable out of scope "++ (show target)++" in environment "++(show env) ... lookupVariable target env .... It seems to me that every possible use of a partial function has some (possibly imagined) program invariant that prevents it from failing. Otherwise it is downright wrong. 'head', 'fromJust' and friends don't do anything to put that invariant in the program text. Custom functions like the above 1) give you a great opportunity to add a meaningful assertion AND document the program invariant 2) attach some semantic meaning to the operation by naming it 3) make you think about what you're doing and help you avoid writing bugs in the first place 4) give you nice hooks for replacing your data- structure with a better one later, should it be necessary 5) encourage you to break down larger functions into smaller ones. Big win if you ask me. The frequent use of partial functions from the Prelude counters all of these advantages, and I avoid them as much as possible. > -- > J?n Fairbairn > Jon.Fairbairn@cl.cam.ac.uk Rob Dockins Speak softly and drive a Sherman tank. Laugh hard; it's a long way to the bank. -- TMBG From jon.fairbairn at cl.cam.ac.uk Wed Nov 15 10:39:53 2006 From: jon.fairbairn at cl.cam.ac.uk (=?utf-8?b?SsOzbiBGYWlyYmFpcm4=?=) Date: Wed Nov 15 10:39:13 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules References: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> <20061115084425.GG3715@cse.unsw.EDU.AU> <404396ef0611150655x4b6124f2m28a9365919ae8646@mail.gmail.com> Message-ID: "Neil Mitchell" writes: > Hi > > Haskell is great for equational reasoning. > > > blah the_v_in_scope blah > > where (the_v_in_scope:_) = [ v | (n,v) <- env, n==target ] > > This piece of code isn't. Strange. It's semantically the same, isn't it? Indeed, the definition of head gets you to it. > If you used head then you could trivially inline > the_v_in_scope, this way is a lot harder. I don't follow that at all. I don't do inlining, the compiler does. Or are you talking about the inlining that was originally there and my version explicitly removed? > You might spot a pointfree pattern and lift it up. You > might move code around more freely. Lots of patterns like > this breaks the equational reasoning in the style that > most people are used to. To convince me of that, you'd have to convince me that (head []) doesn't break the equational reasoning. > > and it doesn't seem /that/ great an imposition. > > I disagree, this is a massive imposition, and requires > lots of refactoring, "lots" is in the eye of the beholder. You only have to do this where you would have used head -- and if you can already /prove/ that head won't fail, there's no reason to replace it. So it's only necessary in cases where the proof is absent. > and is just a little bit ugly. Sure, I don't dispute that. I was merely suggesting that one can already do this for the uncertain cases, rather than have to invoke a whole other set of new machinery just to get a line number in the error message. Your headNote is a good approach, but it strikes me that it's a bit redundant. Instead of ?headNote "foo"? just use ?headDef (error "foo")?. It's a wee bit longer, but having the ?error? out there in the open seems more honest somehow, and there would be fewer function names to remember. -- J?n Fairbairn Jon.Fairbairn@cl.cam.ac.uk From jgbailey at gmail.com Wed Nov 15 11:31:12 2006 From: jgbailey at gmail.com (Justin Bailey) Date: Wed Nov 15 11:30:23 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: <20061115084425.GG3715@cse.unsw.EDU.AU> References: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> <20061115084425.GG3715@cse.unsw.EDU.AU> Message-ID: On 11/15/06, Donald Bruce Stewart wrote: > > Yes, these techniques are fairly well known now, and hopefully some of > the more experienced Haskellers are using them (I certainly use the > non-empty list tricks). Any anyone with more than 6 months Haskell knows > to avoid fromJust. > > The problem I see is that head/fromJust errors are usually caused by > *beginner* Haskellers, who don't know the techniques for statically > avoiding them. I'm one of those "beginning" Haskellers (about one month in) and I'd like to know these techniques. Are they written up anywhere? Justin p.s. apologies for the double-email Donald - forget to CC the list on the first one. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061115/3eef84fe/attachment.htm From ross at soi.city.ac.uk Wed Nov 15 11:38:19 2006 From: ross at soi.city.ac.uk (Ross Paterson) Date: Wed Nov 15 11:37:32 2006 Subject: [Haskell-cafe] Haskell Debugging In-Reply-To: <45589012.9060708@ijs.si> References: <45589012.9060708@ijs.si> Message-ID: <20061115163819.GB10355@soi.city.ac.uk> On Mon, Nov 13, 2006 at 04:32:34PM +0100, Valentin Gjorgjioski wrote: > import Hugs.Observe > > ex8 :: [Float] > ex8 = (observe "after reverse" ) reverse [10.0,7.0,3.0,0.0,4.0] > > gives me > > >ex8 > [4.0,0.0,3.0,7.0,10.0] > > >>>>>>> Observations <<<<<< > > after reverse > { \ ($-990871 : $-990888 : $-990905 : $-990922 : $-990939 : []) -> > $-990939 : $-990922 : $-990905 : $-990888 : $-990871 : [] > } It's a Hugs bug (Float only, Double is fine). Now fixed in CVS. From jon.fairbairn at cl.cam.ac.uk Wed Nov 15 12:02:16 2006 From: jon.fairbairn at cl.cam.ac.uk (=?utf-8?b?SsOzbiBGYWlyYmFpcm4=?=) Date: Wed Nov 15 12:01:45 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules References: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> <20061115084425.GG3715@cse.unsw.EDU.AU> Message-ID: Robert Dockins writes: > On Nov 15, 2006, at 9:48 AM, J?n Fairbairn wrote: > > But instead of ?blah (head [ v | (n,v) <- env, n==target ]) > > blah?, you could write > > > > blah the_v_in_scope blah > > where (the_v_in_scope:_) = [ v | (n,v) <- env, n==target ] > > Or how about.... ?? > > lookupVarible target env = > case [ v | (n,v) <- env, n==target ] of > (x:_) -> x > _ -> assert False $ "BUG: Unexpected variable out of > scope "++ (show target)++" in environment "++(show env) > > > ... lookupVariable target env .... > > > It seems to me that every possible use of a partial function > has some (possibly imagined) program invariant that > prevents it from failing. Otherwise it is downright wrong. > 'head', 'fromJust' and friends don't do anything to put > that invariant in the program text. Hear hear. -- J?n Fairbairn Jon.Fairbairn@cl.cam.ac.uk From valentin.gjorgjioski at ijs.si Wed Nov 15 13:03:54 2006 From: valentin.gjorgjioski at ijs.si (Valentin Gjorgjioski) Date: Wed Nov 15 13:03:12 2006 Subject: [Haskell-cafe] Haskell Debugging In-Reply-To: <20061115163819.GB10355@soi.city.ac.uk> References: <45589012.9060708@ijs.si> <20061115163819.GB10355@soi.city.ac.uk> Message-ID: <455B568A.5040706@ijs.si> On 15.11.2006 17:38 Ross Paterson wrote: > On Mon, Nov 13, 2006 at 04:32:34PM +0100, Valentin Gjorgjioski wrote: > >> import Hugs.Observe >> >> ex8 :: [Float] >> ex8 = (observe "after reverse" ) reverse [10.0,7.0,3.0,0.0,4.0] >> >> gives me >> >> >>> ex8 >>> >> [4.0,0.0,3.0,7.0,10.0] >> >> >>>>>>>>> Observations <<<<<< >>>>>>>>> >> after reverse >> { \ ($-990871 : $-990888 : $-990905 : $-990922 : $-990939 : []) -> >> $-990939 : $-990922 : $-990905 : $-990888 : $-990871 : [] >> } >> > > It's a Hugs bug (Float only, Double is fine). Now fixed in CVS. > Oh, thanks a lot. Nice to hear good news. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Valentin Gjorgjioski Bachelor of Computer Science Department of Knowledge Technologies, Jozef Stefan Institute Jamova 39, SI-1000 Ljubljana, Slovenia Phone: +386 1 477 3343 Fax: +386 1 477 3315 Web: http://kt.ijs.si/ValentinGjorgjioski/ Email: Valentin.Gjorgjioski@ijs.si From carette at mcmaster.ca Wed Nov 15 13:08:55 2006 From: carette at mcmaster.ca (Jacques Carette) Date: Wed Nov 15 13:08:51 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: References: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> <20061115084425.GG3715@cse.unsw.EDU.AU> Message-ID: <455B57B7.8070000@mcmaster.ca> Robert Dockins wrote: > Or how about.... ?? > > lookupVarible target env = > case [ v | (n,v) <- env, n==target ] of > (x:_) -> x > _ -> assert False $ "BUG: Unexpected variable out of scope > "++(show target)++" in environment "++(show env) > Other have pointed out that, in the CURRENT Haskell semantics, the above is quite difficult to reason about. Note that the whole point of Wolfram Kahl's Pattern Matching Calculus is to restore equational reasoning to pattern-matches. http://www.cas.mcmaster.ca/~kahl/PMC/ Jacques From sethg at ropine.com Wed Nov 15 15:49:16 2006 From: sethg at ropine.com (Seth Gordon) Date: Wed Nov 15 15:48:25 2006 Subject: [Haskell-cafe] the case of the 100-fold program speedup In-Reply-To: <455A2FD7.1040909@ropine.com> References: <455A2FD7.1040909@ropine.com> Message-ID: <455B7D4C.3040604@ropine.com> As Lily Tomlin would say, neVERmind. Simon P-J asked me, in email, whether the deforestation was the thing that actually made the program faster or whether it was just the thing that made me think about how to solve the problem. I realized that my fast program had *another* difference from the earlier, slower program: it was based on an algorithm that was specifically designed to clip polygons to rectangles, whereas OGR just had a function to compute the intersection between two arbitrary polygons. So I threw together a version that accumulated all the vertices of the clipped polygon in a list and then iterated through the list to compute the centroid--i.e., preserving everything from my fast program except the deforestation--and it ran at almost exactly the same speed as the deforested program. (Actually, it ran 2% faster, but that could be just random variation from things like the load on the database server.) "The tragedy of science: a beautiful theory slain by an ugly fact." "T. H. Huxley said it first." From rjmh at cs.chalmers.se Wed Nov 15 15:53:03 2006 From: rjmh at cs.chalmers.se (John Hughes) Date: Wed Nov 15 16:00:23 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules References: <20061115180322.91DD3324510@www.haskell.org> Message-ID: <010901c708f8$0b668c10$6401a8c0@DESKTOPPC> > From: Robert Dockins > It seems to me that every possible use of a partial function has some > (possibly imagined) program invariant that prevents it from failing. > Otherwise it is downright wrong. 'head', 'fromJust' and friends > don't do anything to put that invariant in the program text. Well, not really. For example, I often write programs with command line arguments, that contain code of the form do ... [a,b] <- getArgs ... Of course the pattern match is partial, but if it fails, then the standard error message is good enough. This applies to "throw away" code, of course, and if I decide to keep the code then I sooner or later extend it to fix the partiality and give a more sensible error message. But it's still an advantage to be ABLE to write the more concise, but cruder version initially. This isn't a trivial point. We know that error handling code is a major part of software cost--it can even dominate the cost of the "correct case" code (by a large factor). Erlang's "program for the correct case" strategy, coupled with good fault tolerance mechanisms, is one reason for its commercial success--the cost of including error handling code *everywhere* is avoided. But this means accepting that code *may* very well fail--the failure is just going to be handled somewhere else. Haskell (or at least GHC) has good exception handling mechanisms too. We should be prepared to use them, and "let it fail" when things go wrong. The savings of doing so are too large to ignore. John -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061115/627224b9/attachment.htm From isto.aho at dnainternet.net Wed Nov 15 16:04:52 2006 From: isto.aho at dnainternet.net (isto) Date: Wed Nov 15 16:03:33 2006 Subject: [Haskell-cafe] type keeping rounding, typeable (and a difficulty) Message-ID: <1163624692.23061.15.camel@localhost.localdomain> Hi, I've been trying to compile the following function (rounding to a desired degree): roundDec :: (Num a, Typeable a) => Int -> a -> a roundDec d a = let t = show (typeOf a) in case t of "Double" -> roundDDec d a "Complex Double" -> roundCDec d a otherwise -> a -- or something The two other functions are roundCDec :: (RealFloat a) => Int -> Complex a -> Complex a roundCDec d (c :+ b) = (roundDDec d c :+ roundDDec d b) and roundDDec :: (RealFloat a) => Int -> a -> a roundDDec d a = a -- or somegthing Compiler gives the following error message: Couldn't match expected type `Complex a' against inferred type `a1' (a rigid variable) `a1' is bound by the type signature for `roundDec' at FFT.hs:57:17 In the second argument of `roundCDec', namely `a' In the expression: roundCDec d a In a case alternative: "Complex Double" -> roundCDec d a If in the roundDDec a's are replaced with Double, there will be similar error message from the "Double"-line. The functionality can be written differently, but I wanted to try write rounding having in a signature at least "(Num a) => Int -> a -> a". Again, any help would be appreciated a lot! Thanks in advance! br, Isto From haskell at sleepingsquirrel.org Wed Nov 15 16:31:30 2006 From: haskell at sleepingsquirrel.org (Greg Buchholz) Date: Wed Nov 15 16:26:02 2006 Subject: [Haskell-cafe] type keeping rounding, typeable (and a difficulty) In-Reply-To: <1163624692.23061.15.camel@localhost.localdomain> References: <1163624692.23061.15.camel@localhost.localdomain> Message-ID: <20061115213130.GA1730@sleepingsquirrel.org> isto wrote: ] I've been trying to compile the following function ] (rounding to a desired degree): ] ] roundDec :: (Num a, Typeable a) => Int -> a -> a ] roundDec d a = ] let t = show (typeOf a) ] in case t of ] "Double" -> roundDDec d a ] "Complex Double" -> roundCDec d a ] otherwise -> a -- or something ] ] The two other functions are ] ] roundCDec :: (RealFloat a) => Int -> Complex a -> Complex a ] roundCDec d (c :+ b) = (roundDDec d c :+ roundDDec d b) ] and ] roundDDec :: (RealFloat a) => Int -> a -> a ] roundDDec d a = a -- or somegthing Maybe you want type classes instead? > import Complex > > class Round a where > roundD :: Int -> a -> a > > instance Round Double where > roundD d a = a > > instance (Round a, RealFloat a) => Round (Complex a) where > roundD d (c :+ b) = (roundD d c :+ roundD d b) From benjamin.franksen at bessy.de Wed Nov 15 16:42:26 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Wed Nov 15 16:42:24 2006 Subject: [Haskell-cafe] Re: Re: Debugging partial functions by the rules References: <20061115180322.91DD3324510@www.haskell.org> <010901c708f8$0b668c10$6401a8c0@DESKTOPPC> Message-ID: John Hughes wrote: >> From: Robert Dockins > >> It seems to me that every possible use of a partial function has some >> (possibly imagined) program invariant that prevents it from failing. >> Otherwise it is downright wrong. 'head', 'fromJust' and friends >> don't do anything to put that invariant in the program text. > > Well, not really. For example, I often write programs with command line > arguments, that contain code of the form > > do ... > [a,b] <- getArgs > ... > > Of course the pattern match is partial, but if it fails, then the standard > error message is good enough. > > This applies to "throw away" code, of course, and if I decide to keep the > code then I sooner or later extend it to fix the partiality and give a > more sensible error message. But it's still an advantage to be ABLE to > write the more concise, but cruder version initially. > > This isn't a trivial point. We know that error handling code is a major > part of software cost--it can even dominate the cost of the "correct case" > code (by a large factor). Erlang's "program for the correct case" > strategy, coupled with good fault tolerance mechanisms, is one reason for > its commercial success--the cost of including error handling code > *everywhere* is avoided. But this means accepting that code *may* very > well fail--the failure is just going to be handled somewhere else. > > Haskell (or at least GHC) has good exception handling mechanisms too. We > should be prepared to use them, and "let it fail" when things go wrong. > The savings of doing so are too large to ignore. But note that Erlang will give you a stack trace for unhandled exceptions which Haskell (currently?) doesn't/can't. Also, I remember an Erlang expert (Ulf Wiger?) stating recently that 'catching and re-throwing expections in most cases tends to hide program errors rather than avoid them' (quoted non-verbatim from memory, I can't recall the name of the paper). Lastly, Erlang's "program for the correct case" is not meant for things like input of data from sources outside the program's control, but only applies to not-checking for program internal invariants. I would be very surprised if there were Erlang experts encouraging "throwaway" code such as your example above. Cheers, Ben From robdockins at fastmail.fm Wed Nov 15 16:50:32 2006 From: robdockins at fastmail.fm (Robert Dockins) Date: Wed Nov 15 16:50:08 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: <010901c708f8$0b668c10$6401a8c0@DESKTOPPC> References: <20061115180322.91DD3324510@www.haskell.org> <010901c708f8$0b668c10$6401a8c0@DESKTOPPC> Message-ID: <200611151650.32592.robdockins@fastmail.fm> On Wednesday 15 November 2006 15:53, John Hughes wrote: > > From: Robert Dockins > > > > It seems to me that every possible use of a partial function has some > > (possibly imagined) program invariant that prevents it from failing. > > Otherwise it is downright wrong. 'head', 'fromJust' and friends > > don't do anything to put that invariant in the program text. > > Well, not really. For example, I often write programs with command line > arguments, that contain code of the form > > do ... > [a,b] <- getArgs > ... > > Of course the pattern match is partial, but if it fails, then the standard > error message is good enough. I'd actually put this in a different category than 'partial function' (in what might be regarded as an abuse of termonology). This is failure in a monad, and is something I personally use a lot. Failure in IO just usually happens to have behavior very similar to calling 'error'. I'll often write code in an arbitrary monad just to model partiality via the 'fail' function. Sometimes, as here, I use partial pattern matches to do this implicitly. Why is this better than 'error'? Because it allows the code consumer decide how to deal with problems. You can use runIdentity to convert 'fail' to 'error'. You can run with runErrorT and recover the error message. You can run it in a custom moand that has some other fancy error handling. etc, etc. > This applies to "throw away" code, of course, and if I decide to keep the > code then I sooner or later extend it to fix the partiality and give a more > sensible error message. But it's still an advantage to be ABLE to write the > more concise, but cruder version initially. I'm not against partial pattern matching. I think it's way better than using partial projection functions. > This isn't a trivial point. We know that error handling code is a major > part of software cost--it can even dominate the cost of the "correct case" > code (by a large factor). Erlang's "program for the correct case" strategy, > coupled with good fault tolerance mechanisms, is one reason for its > commercial success--the cost of including error handling code *everywhere* > is avoided. But this means accepting that code *may* very well fail--the > failure is just going to be handled somewhere else. > > Haskell (or at least GHC) has good exception handling mechanisms too. We > should be prepared to use them, and "let it fail" when things go wrong. The > savings of doing so are too large to ignore. > > John -- Rob Dockins Talk softly and drive a Sherman tank. Laugh hard, it's a long way to the bank. -- TMBG From eric.kow at gmail.com Wed Nov 15 17:10:44 2006 From: eric.kow at gmail.com (Eric Y. Kow) Date: Wed Nov 15 17:10:22 2006 Subject: [Haskell-cafe] submenu doesn't seem to work properly in wxhaskell In-Reply-To: <4522208C.4070301@snowlion.nl> References: <4522208C.4070301@snowlion.nl> Message-ID: <20061115221044.GR26664@dewdrop.local> Hi, Let's transfer this to wxhaskell-users. I've attached your example as a small .lhs file and makefile. For Debian Linux, uncomment the -lwx_gtk2u_gl-2.6 line or otherwise, modify to taste. > The following code doesn't seem to work properly. Either the main entry > (m1/mp1) or it's sub menu entry (ms1/mps1) do not seem to propagate the > event when pressed. It is possible to make it working by uncomments the > lines where the menu commands are registered in the frame. It seems to work fine on my Mac at least, unless I'm misunderstanding something. Selecting the menubar items m1 and ms1 both putStr their respective strings, as do mp1 and mps1 (right click on the main frame). On the other hand, under Linux, m1 does not putStr, whereas the others do. Is this the problem you are experiencing? -- Eric Kow http://www.loria.fr/~kow PGP Key ID: 08AC04F9 Merci de corriger mon fran?ais. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 186 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061115/4bca1c74/attachment-0001.bin From jmaessen at alum.mit.edu Wed Nov 15 17:11:36 2006 From: jmaessen at alum.mit.edu (Jan-Willem Maessen) Date: Wed Nov 15 17:10:44 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> References: <20061115082100.7AC94AC04@Adric.metnet.fnmoc.navy.mil> Message-ID: <68DB2CB1-5C8C-47D7-A941-0CF5AAE17AA9@alum.mit.edu> On Nov 15, 2006, at 3:21 AM, oleg@pobox.com wrote: > > Donald Bruce Stewart wrote: >> So all this talk of locating head [] and fromJust failures got me >> thinking: >> >> Couldn't we just use rewrite rules to rewrite *transparently* >> all uses of fromJust to safeFromJust, tagging the call site >> with a location? > > I'm sorry for shifting the topic: I'm wondering if, rather than trying > to make an error message more informative, we ought to make sure that > no error will ever arise? > ... > This topic has been discussed at length on this list. It seems that > the discussion came to the conclusion that eliminating head of > the empty list error is possible and quite easy in Haskell. > > http://www.haskell.org/pipermail/haskell-cafe/2006-September/ > 017915.html But this code contains a function with_non_empty_list (or perhaps with_nonempty_list or withNonemptyList or...) which has the same confusing failure mode as the examples under discussion. Fundamentally, if we try to package up "check for failure" in a function, whether the function does something useful as well (head, tail, fromJust) or not (withNonemptyList), we miss out on useful contextual information when our program fails. In addition, we have this rather nice assembly of functions which work on ordinary lists. Sadly, rewriting them all to also work on NonEmptyList or MySpecialInvariantList is a nontrivial task. Which isn't to say that I disapprove of this style: check your invariants early, maintain them as you go. I'm quite enjoying the escH paper, but I get through about a column per day between compiles. :-) -Jan-Willem Maessen -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2425 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061115/f714a7f5/smime.bin From eric.kow at gmail.com Wed Nov 15 17:12:31 2006 From: eric.kow at gmail.com (Eric Y. Kow) Date: Wed Nov 15 17:12:06 2006 Subject: [Haskell-cafe] submenu doesn't seem to work properly in wxhaskell In-Reply-To: <20061115221044.GR26664@dewdrop.local> References: <4522208C.4070301@snowlion.nl> <20061115221044.GR26664@dewdrop.local> Message-ID: <20061115221231.GL2058@dewdrop.local> Skipped content of type multipart/mixed-------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 186 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061115/3aa0bd14/attachment.bin From rturk at science.uva.nl Wed Nov 15 17:59:20 2006 From: rturk at science.uva.nl (Remi Turk) Date: Wed Nov 15 17:57:18 2006 Subject: [Haskell-cafe] forall and a parse error In-Reply-To: <036EAC76E7F5EC4996A3B3C3657D411605E4A5F9@EUR-MSG-21.europe.corp.microsoft.com> References: <404396ef0607031144g6ea0ac05y6fc8d8fe13255613@mail.gmail.com> <036EAC76E7F5EC4996A3B3C3657D411605E4A5F9@EUR-MSG-21.europe.corp.microsoft.com> Message-ID: <20061115225920.GB7533@krikkit.lan> Probably unrelated, but this thread is what triggered it for me. There is a minor bug in showing impredicative types without -fglasgow-exts: *hope I got that right* Prelude> let x = [] :: [forall a. a] :1:23: Warning: Accepting non-standard infix type constructor `.' Use -fglasgow-exts to avoid this warning Prelude> :t x x :: [. (forall a) a] ^^^^^^^^^^^^^^^^ When -fglasgow-exts is set it shows what it should: Prelude> :t x x :: [forall a. a] Groetjes, Remi On Tue, Jul 04, 2006 at 04:55:49PM +0100, Simon Peyton-Jones wrote: > It's a parsing infelicity. (Inside square brackets the parser knows not > to expect a forall, whereas inside round parens it might.) Perhaps it > should be more accepting in square brackets, and reject later. > > Which the current HEAD does -- actually [forall a. a->a] is ok in the > HEAD, see our ICFP06 paper. > > Simon > > | -----Original Message----- > | From: haskell-cafe-bounces@haskell.org > [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Neil > | Mitchell > | Sent: 03 July 2006 19:44 > | To: Haskell Cafe > | Subject: [Haskell-cafe] forall and a parse error > | > | Hi, > | > | I was experimenting with forall and higher rank types briefly, in > particular: > | > | x :: [forall a . a] > | > | This is illegal because of: > | > http://www.haskell.org/ghc/docs/latest/html/users_guide/type-extensions. > html#universal-quantification > | > | Which is fine, however its surprising to compare the error messages: > | > | [forall a . a] > | parse error on input `forall' > | > | [(forall a . a)] > | Illegal polymorphic or qualified type: forall a. a > | In the type signature: lst :: [(forall a. a)] > | > | In normal Haskell, I tend to view [x] as equivalent to [(x)] (provided > | that x is not a tuple) but in this case it has a different meaning - > | albeit both are erronous meanings. > | > | When running the example with Hugs, they both come out as syntax > | errors - the first on the forall, the second on the closing square > | bracket. > | > | Thanks > | > | Neil > | _______________________________________________ > | 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 > From claus.reinke at talk21.com Wed Nov 15 18:19:09 2006 From: claus.reinke at talk21.com (Claus Reinke) Date: Wed Nov 15 18:18:19 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules References: <20061115180322.91DD3324510@www.haskell.org> <010901c708f8$0b668c10$6401a8c0@DESKTOPPC> Message-ID: <028a01c7090c$750ad450$96437ad5@cr3lt> >This isn't a trivial point. We know that error handling code is a major part of software cost--it >can even >dominate the cost of the "correct case" code (by a large factor). Erlang's "program for >the correct case" >strategy, coupled with good fault tolerance mechanisms, is one reason for its >commercial success--the cost of >including error handling code *everywhere* is avoided. But this >means accepting that code *may* very well >fail--the failure is just going to be handled somewhere >else. I've been waiting for someone to put in a quick word for Erlang's approach;-) if I recall correctly, the opposite to "programming for the correct case" was to "program defensively" - try to predict and handle all errors where they occur, and the arguments against that style were that: 1 it spreads error handling all over the place, obscuring the correct case, instead of factoring out the handling code into a coherent framework 2 it tries to handle errors where there is nothing to be done about them, leading to potentially dangerous "default values", or catch/rethrow, or even sweaping helpful diagnostics under the carpet. As I've been trying to argue, the Haskell language report forces implementations to handle functions with non-exhaustive left-hand sides defensively: - the left-hand sides are translated into a case on the right-hand side - the case is completed by a default branch calling error since this behaviour is implicit, there is little that the programmer can do about it, and unlike inlined partial matches (such as your getArgs example), this forces the error to be raised where the offending context is no longer available. it is perhaps a small thing, and mostly concerns everyone just once (because once bitten, we try to "untrain" ourselves and our co-workers from using those "easy" functions like head or tail, fromJust, etc.), but perhaps Haskell' should fix this? Instead of forcing implementations to let non-exhaustive functions accept responsibility for arguments they are not equipped to handle, such arguments should be rejected at the call site, with more useful error context. >Haskell (or at least GHC) has good exception handling mechanisms too. We >should be prepared to use them, and "let it fail" when things go wrong. The >savings of doing so are too large to ignore. indeed, though lazyness makes these things a little more cumbersome. "let it fail" really means "don't worry about it here", but "have a safety net separate from the main act" - lazyness might keep our failing trapeze artists in mid flight until someone chooses to observe them, possible forcing them to complete their crash after the safety net has been removed.. Claus -- Data.Ransom: API documentation withheld pending initial payment From loeh at iai.uni-bonn.de Wed Nov 15 18:42:40 2006 From: loeh at iai.uni-bonn.de (Andres Loeh) Date: Wed Nov 15 18:36:57 2006 Subject: [Haskell-cafe] forall and a parse error In-Reply-To: <20061115225920.GB7533@krikkit.lan> References: <404396ef0607031144g6ea0ac05y6fc8d8fe13255613@mail.gmail.com> <036EAC76E7F5EC4996A3B3C3657D411605E4A5F9@EUR-MSG-21.europe.corp.microsoft.com> <20061115225920.GB7533@krikkit.lan> Message-ID: <20061115234240.GK4732@iai.uni-bonn.de> > Probably unrelated, but this thread is what triggered it for me. > There is a minor bug in showing impredicative types without > -fglasgow-exts: *hope I got that right* > > Prelude> let x = [] :: [forall a. a] > > :1:23: > Warning: Accepting non-standard infix type constructor `.' > Use -fglasgow-exts to avoid this warning > Prelude> :t x > x :: [. (forall a) a] > > ^^^^^^^^^^^^^^^^ This is a minor bug, but not the one I think you mean. Look at the message. GHC says it's accepting the non-standard infix type constructor called `.' ... So it's really interpreting `.' as an infix type variable. It is also interpreting `forall' as a type variable, because without -fglasgow-exts, `forall' is not a keyword, so it's a valid variable name. So, renaming the `.' to `x' and `forall' to `f', your expression is equivalent to Prelude> let x = [] :: [x (f a) a] and that is type-correct. This is also very close to what GHC prints as the type, namely [. (forall a) a] So GHC decides to put `.' in prefix position, which is ok also for infix type operators, but you have to put them in parentheses for GHC to re-accept the type, so the bug is that GHC should really print [(.) (forall a) a] as type of `x'. Cheers, Andres From semanticphilosopher at googlemail.com Wed Nov 15 18:40:12 2006 From: semanticphilosopher at googlemail.com (Neil Davies) Date: Wed Nov 15 18:39:18 2006 Subject: [Haskell-cafe] help with threadDelay Message-ID: <37c497340611151540u121adcdbu381d15ea10068c93@mail.gmail.com> Hi, I'm using GHC 6.6 (debian/etch) - and having some fun with threadDelay. When compiled without the -threaded compiler argument it "behaves" as documented - waits at least the interval - for example: Tgt/Actual = 0.000000/0.036174s, diff = 0.036174s Tgt/Actual = 0.000001/0.049385s, diff = 0.049384s Tgt/Actual = 0.000005/0.049492s, diff = 0.049487s Tgt/Actual = 0.000025/0.049596s, diff = 0.049571s Tgt/Actual = 0.000125/0.049655s, diff = 0.04953s Tgt/Actual = 0.000625/0.04969s, diff = 0.049065s Tgt/Actual = 0.003125/0.049684s, diff = 0.046559s Tgt/Actual = 0.015625/0.04962s, diff = 0.033995s Tgt/Actual = 0.078125/0.099668s, diff = 0.021543s Tgt/Actual = 0.390625/0.399637s, diff = 0.009012s Tgt/Actual = 1.953125/1.999515s, diff = 0.04639s Tgt/Actual = 9.765625/9.799505s, diff = 0.03388s however when -threaded is used you get some interesting effects, including returning too early: Tgt/Actual = 0.000000/0.000093s, diff = 0.000093s Tgt/Actual = 0.000001/0.000031s, diff = 0.00003s Tgt/Actual = 0.000005/0.000029s, diff = 0.000024s Tgt/Actual = 0.000025/0.000028s, diff = 0.000003s Tgt/Actual = 0.000125/0.000034s, diff = -0.000091s Tgt/Actual = 0.000625/0.000035s, diff = -0.00059s Tgt/Actual = 0.003125/0.000029s, diff = -0.003096s Tgt/Actual = 0.015625/0.000028s, diff = -0.015597s Tgt/Actual = 0.078125/0.058525s, diff = -0.0196s Tgt/Actual = 0.390625/0.389669s, diff = -0.000956s Tgt/Actual = 1.953125/1.939513s, diff = -0.013612s Tgt/Actual = 9.765625/9.749573s, diff = -0.016052s The program I used to generate this is :- import Control.Concurrent import Data.Time import Text.Printf main = mapM_ delay (0 : take 11 (iterate (*5) 1)) delay n = do tS <- getCurrentTime threadDelay n tE <- getCurrentTime let n' = toRational n / 10^6 n'' = fromRational (n') :: Double obs = diffUTCTime tE tS printf "Tgt/Actual = %0.6f/%s, diff = %s\n" n'' (show obs) (show $ obs - fromRational n') return () Any suggestions? Neil From oleg at pobox.com Wed Nov 15 20:23:51 2006 From: oleg at pobox.com (oleg@pobox.com) Date: Wed Nov 15 20:23:07 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: <20061115125747.GA2012@web.de> Message-ID: <20061116012351.A8E8EAB40@Adric.metnet.fnmoc.navy.mil> It must be stressed that the advocated technique for avoiding partial function errors requires *NO* research advances, *NO* dependent types, *NO* annotations, and *NO* tools. Everything is possible in Haskell as it is -- actually, even in Haskell98. As a matter of fact, exactly the same approach applies to OCaml (and even to any language with a half-decent type system, including Java and C++). The only required advancement is in our thinking and programming style. First, regarding fromJust: to quote Nancy Reagan, let's `Just say NO'. Let us assume that `fromJust' just does not exist. That does not reduce any expressiveness, as `maybe' always suffices. The latter function causes us to think of the boundary case, when the value is Nothing. And if we are absolutely positive that the value is (Just x), we can always write maybe (assert False undefined) id v This is *exactly* equivalent to `fromJust v', only with a better error message. So, no `safeFromJust' is ever necessary! The expression above takes longer to type than `fromJust v' -- and I consider that a feature. Whenever I am telling the compiler that I know better, I'd rather had to type it in more words -- so I could think meanwhile if I indeed know better. Also, such phrases should stand out in the code. I'd be quite happy seeing fromJust removed from the standard libraries, or at least tagged `deprecated' or with the stigma attached that is rightfully accorded to unsafePerformIO. Regarding head and tail. Here's the 0th approximation of the advocated approach: > {-# Haskell98! #-} > -- Safe list functions > > module NList (FullList, > fromFL, > indeedFL, > decon, > head, > tail, > Listable (..) > ) where > > import Prelude hiding (head, tail) > > newtype FullList a = FullList [a] -- data constructor is not exported! > > fromFL (FullList x) = x -- Injection into general lists > > -- The following is an analogue of `maybe' > indeedFL :: [a] -> w -> (FullList a -> w) -> w > indeedFL x on_empty on_full > | null x = on_empty > | otherwise = on_full $ FullList x > > -- A possible alternative, with an extra Maybe tagging > -- indeedFL :: [a] -> Maybe (FullList a) > > -- A more direct analogue of `maybe', for lists > decon :: [a] -> w -> (a -> [a] -> w) -> w > decon [] on_empty on_full = on_empty > decon (h:t) on_empty on_full = on_full h t > > > -- The following are _total_ functions > -- They are guaranteed to be safe, and so we could have used > -- unsafeHead# and unsafeTail# if GHC provides though... > > head :: FullList a -> a > head (FullList (x:_)) = x > > tail :: FullList a -> [a] > tail (FullList (_:x)) = x > > -- Mapping over a non-empty list gives a non-empty list > instance Functor FullList where > fmap f (FullList x) = FullList $ map f x > > -- Adding something to a general list surely gives a non-empty list > infixr 5 !: > > class Listable l where > (!:) :: a -> l a -> FullList a > > instance Listable [] where > (!:) h t = FullList (h:t) > > instance Listable FullList where > (!:) h (FullList t) = FullList (h:t) Now we can write > import NList > import Prelude hiding (head, tail) > safe_reverse l = loop l [] > where > loop l accum = indeedFL l accum $ > (\l -> loop (tail l) (head l : accum)) > > test1 = safe_reverse [1,2,3] As we can see, the null test is algorithmic. After we've done it, head and tail no longer need to check for null list. Those head and tail functions are total. Thus we achieve both safety and performance. We can also write > -- Again, we are statically assured of no head [] error! > test2 = head $ 1 !: 2 !: 3 !: [] This would look better had `[1,2,3]' been a rebindable syntax similar to `do'. I should point to http://pobox.com/~oleg/ftp/Computation/lightweight-dependent-typing.html for further, more complex examples. We can also use the approach to ensure various control properties, e.g., the yield property: a thread may not invoke `yield' while holding a lock. We can assure this property both for recursive and non-recursive locks. If there is a surprise in this, it is in the triviality of approach. One can't help but wonder why don't we program in this style. Simon Peyton-Jones wrote: > My programs have invariants that I can't always express in > a way that the type system can understand. E.g. I know that a variable is in > scope, so searching for it in an environment can't fail: > head [ v | (n,v) <- env, n==target ] In the 0th approximation, the above line will read as indeedFL [ v | (n,v) <- env, n==target ] (assert False undefined) head Alternatively, one may write case [ v | (n,v) <- env, n==target ] of (h:_) -> h with the compiler issuing a warning over the incomplete match and prompting us to consider the empty list case (writing assert False undefined if we are sure it can't happen). I have a hunch we can do better and really express our knowledge that [ v | (n,v) <- env, n==target ] can't be empty. We don't ask the type system to decide this for us; we only ask the type system to carry along our decisions (and complain if we seem to be contradicting ourselves). To test if we indeed can do better, I'd like to see the above line in a larger context (with more code). Incidentally, this is an open invitation. If someone has a (complex) example with head/tail/readArray etc. partial functions and is interested in possibly improving static assurances of that code, Chung-chieh Shan and I would be quite interested in looking into it. The code can be either posted here or mailed to us privately. From aditya_siram at hotmail.com Wed Nov 15 21:00:32 2006 From: aditya_siram at hotmail.com (Aditya Siram) Date: Wed Nov 15 20:59:40 2006 Subject: [Haskell-cafe] Newbie; Can't Install Hat From Source Message-ID: Hi all, I have been trying to install Hat for the last couple of days but GHC does not recognize it as a package. I compiled 2.05 from source, but at the 'make install' step I see this error message: **Begin Output** ./configure --install Configuring for hat... [ 2.05 ] Starting with earlier config in targets/ix86-Linux/config.cache [ config: ix86-Linux/ by deech@ubuntu on 15 Nov 2006 ] (but cmdline options have precedence) -------- Looking for already-installed Haskell compilers: Looking for ghc... found 6.6 Looking for nhc98... (not found) Looking for hmake... found 3.13 You said you want to use ghc to build hat. Done. -------- Configuration report for hat. You are going to build hat with: ghc Executables need .exe suffix? no (detected) Testing for the glib library: no (using slower replacement) Installation directories are now created/checked. Install directory root is: /usr/local Hat interface files (.hx) go into: /usr/local/include/hat-2.05 (exists) Array.hx ...... Debug/Trace.hx Installing hat as a ghc package: Installing hat package for ghc under /usr/local/lib/hat-2.05/ix86-Linux/ghc-606 ghc-pkg: cannot find package hat <-----ERROR MESSAGE!!!!! Reading package info from stdin ... done. ghc-pkg: package hat-2.4 is already installed Scripts go into: /usr/local/bin (exists) hat-graph hat-trans hat-tools: hat-stack hat-check hat-observe hat-detect hat-delta hat-view hat-trail hat-anim hat-explore hat-cover black-hat hat-nonterm pretty-hat Executables go into: /usr/local/lib/hat-2.05/ix86-Linux (exists) config hat-anim hat-check hat-cover hat-delta hat-detect hat-explore hat-nonterm hat-observe hat-stack hat-trail hat-trans hat-view black-hat pretty-hat Man pages go into: /usr/local/man/man1 (exists) hat-anim.1 hat-delta.1 hat-detect.1 hat-observe.1 hat-stack.1 hat-trail.1 hat-trans.1 pretty-hat.1 Not (re-)installing html documents Saving current configuration in targets/ix86-Linux/config.cache Done. Please ensure /usr/local/bin is in your PATH variable. **End Of Output** The output of 'ghc-pkg list' is: /usr/local/lib/ghc-6.6/package.conf: Cabal-1.1.6, HUnit-1.1, QuickCheck-1.0, base-2.0, cgi-2006.9.6, fgl-5.2, (ghc-6.6), haskell-src-1.0, haskell98-1.0, html-1.0, mtl-1.0, network-2.0, parsec-2.0, readline-1.0, regex-base-0.71, regex-compat-0.71, regex-posix-0.71, rts-1.0, stm-2.0, template-haskell-2.0, time-1.0, unix-1.0, xhtml-2006.9.13 /home/deech/.ghc/i386-linux-6.6/package.conf: (hat-2.4) <----ERROR!!! For some reason it thinks that hat-2.4 is installed. I tried to run a test program saved in HatTest.hs: import Prelude main = do { print "Hello"; } When I compile it with 'hmake -hat HatTest' I get the following error: hat-trans HatTest.hs Wrote Hat/HatTest.hs ghc-6.6 -c -package hat -o Hat/HatTest.o Hat/HatTest.hs Hat/HatTest.hs:3:0: Bad interface file: /usr/local/imports/hat-2.05/ghc-606/Hat/PreludeBasic.hi Something is amiss; requested module hat-2.4:Hat.PreludeBasic differs from name found in the interface file hat:Hat.PreludeBasic I'm not really sure how to proceed. Any help is appreciated. BTW I get the ghc-package: cannot find package hat when I 'apt-get install' it too. Thanks.. Deech _________________________________________________________________ View Athlete’s Collections with Live Search http://sportmaps.live.com/index.html?source=hmemailtaglinenov06&FORM=MGAC01 From oleg at pobox.com Wed Nov 15 23:01:03 2006 From: oleg at pobox.com (oleg@pobox.com) Date: Wed Nov 15 23:00:13 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: <68DB2CB1-5C8C-47D7-A941-0CF5AAE17AA9@alum.mit.edu> Message-ID: <20061116040103.110B8AB40@Adric.metnet.fnmoc.navy.mil> Jan-Willem Maessen wrote: > In addition, we have this rather nice assembly of functions which > work on ordinary lists. Sadly, rewriting them all to also work on > NonEmptyList or MySpecialInvariantList is a nontrivial task. That's an excellent question. Indeed, let us assume we have a function foo:: [a] -> [a] (whose code, if available, we'd rather not change) and we want to write something like \l -> [head l, head (foo l)] To use the safe `head' from NList.hs , we should write \l -> indeedFL l onempty (\l -> [head l, head (foo l)]) But that doesn't type: first of all, foo applies to [a] rather than FullList a, and second, the result of foo is not FullList a, required by our |head|. The first problem is easy to solve: we can always inject FullList a into the general list: fromFL. We insist on writing the latter function explicitly, which keeps the typesystem simple, free of subtyping and implicit coercions. One may regard fromFL as an analogue of fromIntegral -- which, too, we have to write explicitly, in any code with more than one sort of integral numbers (e.g., Int and Integer, or Int and CInt). If we are not sure if our function foo maps non-empty lists to non-empty lists, we really should handle the empty list case: \l -> indeedFL l onempty $ \l -> [head l, indeedFL (foo $ fromFL l) onempty' head] If we have a hunch that foo maps non-empty lists to non-empty lists, but we are too busy to verify it, we can write \l -> indeedFL l onempty $ \l -> [head l, indeedFL (foo $ fromFL l) (assert (const False msg) undefined) head] where msg = "I'm quite sure foo maps non-empty lists to " ++ "non-empty lists. I'll be darned if it doesn't." That would get the code running. Possibly at some future date (during the code review?) I'll be called to justify my hunch, to whatever degree of formality (informal argument, formal proof) required by the policies in effect. If I fail at this justification, I'd better think what to do if the result of foo is really the empty list. If I succeed, I'd be given permission to update the module NList with the following definition nfoo (FullList x) = FullList $ foo x after which I could write \l -> indeedFL l onempty (\l -> [head l, head (nfoo l)]) with no extra empty list checks. It goes without saying that it would save a lot of typing if List were a typeclass (like Num) rather than a datatype... From simonpj at microsoft.com Thu Nov 16 03:07:35 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Thu Nov 16 03:06:41 2006 Subject: [Haskell-cafe] the case of the 100-fold program speedup In-Reply-To: <455B7D4C.3040604@ropine.com> References: <455A2FD7.1040909@ropine.com> <455B7D4C.3040604@ropine.com> Message-ID: Don't knock it! Using a functional language helped you to think about the problem in a new way, and throw together a prototype that worked in a short enough time that you actually did it. A merit of fp is, I think, that you can explore the algorithm design space much more quickly -- and algorithms are the dominant factor in the performance equation. Simon | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Seth | Gordon | Sent: 15 November 2006 20:49 | To: haskell-cafe@haskell.org | Subject: Re: [Haskell-cafe] the case of the 100-fold program speedup | | As Lily Tomlin would say, neVERmind. | | Simon P-J asked me, in email, whether the deforestation was the thing | that actually made the program faster or whether it was just the thing | that made me think about how to solve the problem. I realized that my | fast program had *another* difference from the earlier, slower program: | it was based on an algorithm that was specifically designed to clip | polygons to rectangles, whereas OGR just had a function to compute the | intersection between two arbitrary polygons. | | So I threw together a version that accumulated all the vertices of the | clipped polygon in a list and then iterated through the list to compute | the centroid--i.e., preserving everything from my fast program except | the deforestation--and it ran at almost exactly the same speed as the | deforested program. (Actually, it ran 2% faster, but that could be just | random variation from things like the load on the database server.) | | "The tragedy of science: a beautiful theory slain by an ugly fact." | | "T. H. Huxley said it first." | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe From Malcolm.Wallace at cs.york.ac.uk Thu Nov 16 05:42:10 2006 From: Malcolm.Wallace at cs.york.ac.uk (Malcolm Wallace) Date: Thu Nov 16 05:43:32 2006 Subject: [Haskell-cafe] Newbie; Can't Install Hat From Source In-Reply-To: References: Message-ID: <20061116104210.215ef3d2.Malcolm.Wallace@cs.york.ac.uk> "Aditya Siram" wrote: > I have been trying to install Hat for the last couple of days but GHC > does not recognize it as a package. I compiled 2.05 from source, but > at the 'make install' step I see this error message: > > Installing hat package for ghc under > /usr/local/lib/hat-2.05/ix86-Linux/ghc-606 > ghc-pkg: cannot find package hat <-----ERROR MESSAGE!!!!! This error message can be safely ignored - it comes from a requirement to support several different versions of ghc, each of which has a different interface to the package manager ghc-pkg. > ghc-pkg: package hat-2.4 is already installed > > /usr/local/lib/ghc-6.6/package.conf: > ... > /home/deech/.ghc/i386-linux-6.6/package.conf: > (hat-2.4) <----ERROR!!! > > For some reason it thinks that hat-2.4 is installed. This is one of a couple of bugs in the 2.05 package. The .cabal file simply had the wrong version number in it. > Bad interface file: > /usr/local/imports/hat-2.05/ghc-606/Hat/PreludeBasic.hi > Something is amiss; requested module hat-2.4:Hat.PreludeBasic > differs from name found in the interface file hat:Hat.PreludeBasic And this is the other bug: the Hat library package was built using "-package-name hat" instead of "-package-name hat-2.05" (as now required by ghc-6.6 and above). I have re-rolled the Hat-2.05 distribution package with these two very minor bugfixes. Please try downloading it again, and re-building. Regards, Malcolm From dagit at eecs.oregonstate.edu Thu Nov 16 05:46:32 2006 From: dagit at eecs.oregonstate.edu (Jason Dagit) Date: Thu Nov 16 05:45:35 2006 Subject: [Haskell-cafe] Generalizing zip Message-ID: In #haskell on freenode we had a discussion about isPrefixOf, which is probably implemented roughly as so: isPrefixOf [] _ = True isPrefixOf _ [] = False isPrefixOf (x:xs) (y:ys) = x == y && isPrefixOf xs ys Well, this is basically just a zip with a special base case. But you can't just write it with zipWith because zipWith stops when it exausts either list. How about we define zipWith'' like this: zipWith'' _ [] _ l _ = [l] zipWith'' _ _ [] _ r = [r] zipWith'' f (x:xs) (y:ys) l r = f x y : zipWith'' f xs ys l r Then we can write: isPrefixOf xs ys = and (zipWith'' (==) xs ys True False) A point free reduction might look like the following and probably isn't worth it: isPrefixOf = (and .) . flip flip False . flip flip True . zipWith'' (==) Are there lots of other places where this zipWith'' would come in handy? It seems like I've found lots of times when I needed to manually code the recursion because of the way zip behaves when it exhausts one of its parameter lists. Jason From maiabhmg at gmail.com Thu Nov 16 08:55:58 2006 From: maiabhmg at gmail.com (Leandro Maia) Date: Thu Nov 16 08:55:00 2006 Subject: [Haskell-cafe] ghc 6.2 and wxhaskell Message-ID: <17717efd0611160555k39d44e08j3e9ff6c54924464a@mail.gmail.com> Hi Maybe this is not the best place to post this question, but here a lot of people will see and can direct me to the right place. I'm using Linux Slackware 10.2 and 11.0, GHC 6.2 and wxWidgets 2.6.X, 2.7.x I have already tried all kind of combinations but never worked. I tried: GHC 6.2 , 6.2.2, 6.4, 6.4.1, 6.6 wxWidgets 2.6.x, 2.7.x My best result was GHC 6.2 and wxwidgets 2.6.x. But all programs and samples using wxhaskell results in "segmentation fault" I would like to know how to solve this problem. I have to do my exercise but ... Thanks a lot. -- Leandro Maia -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061116/2f789054/attachment.htm From bringert at cs.chalmers.se Thu Nov 16 09:06:13 2006 From: bringert at cs.chalmers.se (Bjorn Bringert) Date: Thu Nov 16 09:05:19 2006 Subject: [Haskell-cafe] Generalizing zip In-Reply-To: References: Message-ID: On 16 nov 2006, at 11.46, Jason Dagit wrote: > In #haskell on freenode we had a discussion about isPrefixOf, which is > probably implemented roughly as so: > > isPrefixOf [] _ = True > isPrefixOf _ [] = False > isPrefixOf (x:xs) (y:ys) = x == y && isPrefixOf xs ys > > Well, this is basically just a zip with a special base case. But you > can't just write it with zipWith because zipWith stops when it exausts > either list. > > How about we define zipWith'' like this: > zipWith'' _ [] _ l _ = [l] > zipWith'' _ _ [] _ r = [r] > zipWith'' f (x:xs) (y:ys) l r = f x y : zipWith'' f xs ys l r > > Then we can write: > isPrefixOf xs ys = and (zipWith'' (==) xs ys True False) > > A point free reduction might look like the following and probably > isn't worth it: > isPrefixOf = (and .) . flip flip False . flip flip True . > zipWith'' (==) > > Are there lots of other places where this zipWith'' would come in > handy? It seems like I've found lots of times when I needed to > manually code the recursion because of the way zip behaves when it > exhausts one of its parameter lists. I needed something like this just the other day. I think that it could be made more general: > zipWith'' :: (a -> b -> c) -> [a] -> [b] -> ([b] -> [c]) -> ([a] - > [c]) -> [c] > zipWith'' _ [] ys l _ = l ys > zipWith'' _ xs [] _ r = r xs > zipWith'' f (x:xs) (y:ys) l r = f x y : zipWith'' f xs ys l r Now zipWith is a special case of zipWith'': > zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] > zipWith f xs ys = zipWith'' f xs ys (const []) (const []) Though isPrefixOf becomes a bit more complex: > isPrefixOf :: Eq a => [a] -> [a] -> Bool > isPrefixOf xs ys = and (zipWith'' (==) xs ys (const [True]) (const [False])) /Bj?rn From ewilligers at gmail.com Thu Nov 16 09:18:21 2006 From: ewilligers at gmail.com (Eric Willigers) Date: Thu Nov 16 09:24:32 2006 Subject: [Haskell-cafe] Re: what GUI library should i select? References: <1344369241.20061113025003@gmail.com> Message-ID: Bulat Ziganshin gmail.com> writes: > > Hello haskell-cafe, > > afaik, there are just two good enough libs - wxHaskell and GtkHs. can > anyone point (or write) detailed comparison of their features? i plan > to write large GUI program in Haskell and want to select best one. Putting aside issues of completeness and the availability of particular components **, how have people found the Functional Reactive approach used by Fruit or FranTk? The example code for each looks very appealing. ** Suppose FranTk had been written or generated with Gtk2Hs or wxHaskell as the underlying library instead of Tk. Eric Willigers. From grzegorz.chrupala at computing.dcu.ie Thu Nov 16 11:09:42 2006 From: grzegorz.chrupala at computing.dcu.ie (=?UTF-8?Q?Grzegorz_Chrupa=C5=82a?=) Date: Thu Nov 16 11:08:49 2006 Subject: [Haskell-cafe] Implicit params and typeclasses Message-ID: <73f919100611160809l26936595rd6533b2166e5cf98@mail.gmail.com> Hi all, When I try to compile the following in GHC (v 6.6) (with -fno-monomorphism-restriction -fimplicit-params) class Configuration a where thestring:: a -> String foo c = let { ?c = c } in bar bar = thestring ?c I get: Ambiguous type variable `a' in the constraint: `Configuration a' arising from use of `thestring' at /home/grzegorz/Foo.hs:9:6-17 Possible cause: the monomorphism restriction applied to the following: bar :: (?c::a) => String (bound at /home/grzegorz/Foo.hs:9:0) foo :: a -> String (bound at /home/grzegorz/Foo.hs:8:0) Probable fix: give these definition(s) an explicit type signature or use -fno-monomorphism-restriction Adding the type signature bar :: (Configuration a,?c :: a) => String the compiler says: Ambiguous constraint `Configuration a' At least one of the forall'd type variables mentioned by the constraint must be reachable from the type after the '=>' In the type signature for `bar': bar :: (Configuration a, ?c :: a) => String Similar code without use of implicit params compiles fine: class Configuration a where thestring:: a -> String foo c = thestring c Why do implicit params cause this error and is there a way to make it work? Thanks, -- Grzegorz From lemming at henning-thielemann.de Thu Nov 16 11:46:22 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Thu Nov 16 11:46:38 2006 Subject: [Haskell-cafe] discouraging unsafePerformIO (Was: Debugging partial functions by the rules) In-Reply-To: <20061116012351.A8E8EAB40@Adric.metnet.fnmoc.navy.mil> References: <20061116012351.A8E8EAB40@Adric.metnet.fnmoc.navy.mil> Message-ID: On Wed, 15 Nov 2006 oleg@pobox.com wrote: > ... > I'd be quite happy seeing fromJust removed from the standard > libraries, or at least tagged `deprecated' or with the stigma > attached that is rightfully accorded to unsafePerformIO. However, unsafe* functions are still recommended by Haskell users to newbies, as if these functions belong to the normal usage. Maybe one should add a string parameter to these functions, which must be bound to "I confirm that I know that this function should be used only if really necessary and that I checked properly that safe alternatives do not exist.". The unsafe* function must be undefined, if the confirmation argument does not match. :-) From dmhouse at gmail.com Thu Nov 16 12:29:20 2006 From: dmhouse at gmail.com (David House) Date: Thu Nov 16 12:28:23 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: <20061116012351.A8E8EAB40@Adric.metnet.fnmoc.navy.mil> References: <20061115125747.GA2012@web.de> <20061116012351.A8E8EAB40@Adric.metnet.fnmoc.navy.mil> Message-ID: On 16/11/06, oleg@pobox.com wrote: > And if we are absolutely positive that the value is (Just x), > we can always write > maybe (assert False undefined) id v It should be pointed out that Data.Maybe does export a less well-known function, fromMaybe: fromMaybe z = maybe z id This can be used to make the 'maybe X id' case a bit tidier (although technically it's not a save on characters). -- -David House, dmhouse@gmail.com From jon.fairbairn at cl.cam.ac.uk Thu Nov 16 13:44:43 2006 From: jon.fairbairn at cl.cam.ac.uk (=?utf-8?b?SsOzbiBGYWlyYmFpcm4=?=) Date: Thu Nov 16 13:44:40 2006 Subject: [Haskell-cafe] Re: Generalizing zip References: Message-ID: "Jason Dagit" writes: > Well, this is basically just a zip with a special base case. But you > can't just write it with zipWith because zipWith stops when it exausts > either list. > > How about we define zipWith'' like this: > zipWith'' _ [] _ l _ = [l] > zipWith'' _ _ [] _ r = [r] > zipWith'' f (x:xs) (y:ys) l r = f x y : zipWith'' f xs ys l r > > Then we can write: > isPrefixOf xs ys = and (zipWith'' (==) xs ys True False) I wonder if there is mileage to be had from persuing something like this, rather different (off top of head, very provisional, E&OE &c) approach: extend_infinitely l = map Just l ++ repeat Nothing promote1 rel (Just a) b = rel a b promote1 rel Nothing b = False is_pfx_of l1 l2 = and (zipWith (promote1 (==)) (extend_infinitely l2) l1) ? For at least the few minutes I've thought about it, it seems like promote and extend_infinitely might be more generally userful. I've probably missed something better, too. > A point free reduction might look like the following and probably > isn't worth it: > isPrefixOf = (and .) . flip flip False . flip flip True . zipWith'' (==) "probably"? -- J?n Fairbairn Jon.Fairbairn@cl.cam.ac.uk From isto.aho at dnainternet.net Thu Nov 16 15:44:59 2006 From: isto.aho at dnainternet.net (isto) Date: Thu Nov 16 15:43:33 2006 Subject: [Haskell-cafe] type keeping rounding, typeable (and a difficulty) In-Reply-To: <20061115213130.GA1730@sleepingsquirrel.org> References: <1163624692.23061.15.camel@localhost.localdomain> <20061115213130.GA1730@sleepingsquirrel.org> Message-ID: <1163709899.22561.14.camel@localhost.localdomain> ke, 2006-11-15 kello 13:31 -0800, Greg Buchholz kirjoitti: > isto wrote: > ] let t = show (typeOf a) > ] in case t of > ] "Double" -> roundDDec d a > ] "Complex Double" -> roundCDec d a > Maybe you want type classes instead? aaaa yes, I was blind... Thanks! I'll guess the reason it didn't compile was different types at case branches (am I wrong?) Anyhow, do you know that is it possible to choose the return type somehow in the spirit above? br, Isto From haskell at sleepingsquirrel.org Thu Nov 16 17:02:51 2006 From: haskell at sleepingsquirrel.org (Greg Buchholz) Date: Thu Nov 16 16:57:18 2006 Subject: [Haskell-cafe] type keeping rounding, typeable (and a difficulty) In-Reply-To: <1163709899.22561.14.camel@localhost.localdomain> References: <1163624692.23061.15.camel@localhost.localdomain> <20061115213130.GA1730@sleepingsquirrel.org> <1163709899.22561.14.camel@localhost.localdomain> Message-ID: <20061116220251.GC1739@sleepingsquirrel.org> isto wrote: ] > isto wrote: ] > ] let t = show (typeOf a) ] > ] in case t of ] > ] "Double" -> roundDDec d a ] > ] "Complex Double" -> roundCDec d a ] ] I'll guess the reason it didn't compile was different ] types at case branches (am I wrong?) Correct. ] Anyhow, do you know that is it possible to choose the return type ] somehow in the spirit above? Maybe you want something like... > roundDec d (Left a) = Left (roundDDec d a) > roundDec d (Right a) = Right (roundCDec d a) > > roundCDec :: (RealFloat a) => Int -> Complex a -> Complex a > roundCDec d (c :+ b) = (roundDDec d c :+ roundDDec d b) > > roundDDec :: (RealFloat a) => Int -> a -> a > roundDDec d a = a -- or somegthing Greg Buchholz From sylvan at student.chalmers.se Thu Nov 16 17:15:58 2006 From: sylvan at student.chalmers.se (Sebastian Sylvan) Date: Thu Nov 16 17:15:02 2006 Subject: [Haskell-cafe] Re: what GUI library should i select? In-Reply-To: References: <1344369241.20061113025003@gmail.com> Message-ID: <3d96ac180611161415w2b549b3vef16c99d7efe6472@mail.gmail.com> On 11/16/06, Eric Willigers wrote: > Bulat Ziganshin gmail.com> writes: > > > > > Hello haskell-cafe, > > > > afaik, there are just two good enough libs - wxHaskell and GtkHs. can > > anyone point (or write) detailed comparison of their features? i plan > > to write large GUI program in Haskell and want to select best one. > > > Putting aside issues of completeness and the availability of particular > components **, how have people found the Functional Reactive approach used by > Fruit or FranTk? The example code for each looks very appealing. > > ** Suppose FranTk had been written or generated with Gtk2Hs or wxHaskell as the > underlying library instead of Tk. > Personally I find all of that stuff really cool in a geeky sort of way, but for unclear reasons it just doesn't "feel" all that useful for real-world stuff. It just seems a bit too "heavy" to use, to the point where I prefer a much more low level but straightforward approach (using a thin wrapper on top of imperative libraries). I'm sorry I can't explain better, but I do think it's a promising area for research. /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862 From nicolas.frisby at gmail.com Thu Nov 16 17:17:30 2006 From: nicolas.frisby at gmail.com (Nicolas Frisby) Date: Thu Nov 16 17:16:31 2006 Subject: [Haskell-cafe] 'type' for isomorphism [was poorly named: aggressiveness of functional dependencies] Message-ID: <5ce89fb50611161417t4dde39b9u1bfded413b929498@mail.gmail.com> If anyone is interested, the solution to my problem was to use a type synonym instead of an isomorphism class. Pros: - Not susceptible to the functional dependencies/overlapping instances/open-world issue - Very simple (in fact that simplicity migrated into the rest of the system) Cons: - Obviously less flexible So it works, but it wasn't quite what I had hoped for. Has there been any work/proposals for specifying a "finalized" type class? I.E. Those not subject to overlap and thus "closed" to the world? Thanks, Nick On 11/11/06, apfelmus@quantentunnel.de wrote: > Nicolas Frisby wrote: > > First off, thanks for the reply. > > > > I am accustomed to GHC ignoring instance contexts as you mentioned. > > It's the "mostly" part that I'm curious about: mostly implies there's > > some phases that don't ignore context. Is that only the checking the > > type of the method definitions and absolutely nothing else? So it > > seems... > > I just said "mostly" because I don't know exactly... Though I strongly > suspect, like you, that the preconditions are only used in type > inference/checking and not for overlapping instances and similar > questions related to uniqueness of instance declarations. > > > > > My project is rather committed to GHC, but could you elaborate on your > > reference to Hugs being different? > > By tradition from Gofer, Hugs implements type classes more flexible than > GHC does. I once experimented with the following code using overlapping > instances: > > > data Lift a = Lift a > > type Test = Char > > > > class Message m o where > > send :: m -> o -> Test > > > > instance Message (o -> Test) o where > > send m o = m o > > > > instance Message m o => Message m (Lift o) where > > send m (Lift o) = send m o > > > > msg :: Test -> Test > > msg = id > > > > r1 = send msg 'a' > > r2 = send msg (Lift 'b') > > It implements some kind of subtyping. GHC won't typecheck this but "hugs > -98 +m" will. If I remember correctly, the problem was with > > instance Message (Lift a -> Test) (Lift a) > > Does this follow from the first or from the second instance declaration? > GHC ignores the precondition in the second declaration, thus believes it > follows from both and consequently rejects it. But Hugs has no problems > with that: it follows the precondition and sees that the second > declaration does not apply to the culprit because there is no (instance > (Lift a -> Test) a). Note that if you add this instance later on > (perhaps in a different module), things will break. > > The flexibility comes at a price: Gofer's type class system was unsound > and I don't know how much Hugs comes close to this. > > Regards, > apfelmus > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From nicolas.frisby at gmail.com Thu Nov 16 18:59:05 2006 From: nicolas.frisby at gmail.com (Nicolas Frisby) Date: Thu Nov 16 18:58:07 2006 Subject: [Haskell-cafe] topEq for types Message-ID: <5ce89fb50611161559w2675dbd1o21fdec7412ec35d3@mail.gmail.com> I'm sharing what I think is a novel extension of TypeEq. Please 1) cope with my introduction of the motivating problem 2) inform me if something similar has already been presented 3) criticize the solution This presentation is quite a simplification of my actual problem/code, but I'm trying to just show the essence of the technique. Feel free to request the real story or for me to actually code this up. Disclaimer: the following is an untested presentation of correctly functioning code. Thanks for your time. Motivation: In the HList paper, a subtle example involved polymorphism and the singleton list. Because the list was a singleton, TypeCast can be used to resolve the polymorphism. Otherwise, the polymorphism (i.e. free type variables) would prevent crucial typeclass instances from firing. This has inspired a solution to a recent problem of mine. I essentially had an HList of functor values that share the same carrier type. Envision the type of such a list as [F0 Char, F1 Char, ..., Fn Char] where Fi is a functor. I occasionally wanted to "update" one of these values: fn :: F0 Char -> F0 Char fn (F0_CtorOfInterest c) = ...new value... fn f0_c = f0_c newList = specialHMap fn oldList This works fine; the specialHMap method/class is pretty easy to write using TypeEq. The problem arises when I introduce more interesting functors; consider [F Char, G Char, (BF Int) Char] where BF is a bifunctor. Targeting such an functor with an update operation will fail if the update does not specify t. fn2 :: (BF t) Char -> (BF t) Char fn2 (C0 _) = C1 'c' fn2 x = x When the typeclass instances traverse the HList and check each element for a type match, the polymorphism of t in fn2 precludes a successful match of any TypeEq instance. This was frustrating, because it prohibited me from writing modular code! Solution: My solution to the problem was to indicate to the typechecker that certain functors were unique in my HList. So if BF showed up in the HList with a first argument of t', then it would be safe to unify the free t from fn2 with t' (via TypeCast), because no other BF will show up in my list. This quickly generalized to types of various kind with various parameters free. The key to the solution is this class: > class TypeTopEq' () teq x y bn => TypeTopEq teq x y bn > | teq x y -> bn > class TypeTopEq' q teq x y bn > | q teq x y -> bn > class TypeTopEq'' q teq x y bn > | q teq x y -> bn > > instance TypeTopEq' () teq x y bn => TypeTopEq teq x y bn > > > instance TypeCast bn HTrue => TypeTopEq' () TEQ_ hd hd bn > > instance TypeCast bn HTrue => TypeTopEq' () TEQ_0 (hd a) (hd z) bn > instance TypeCast bn HTrue => TypeTopEq' () TEQ_1 (hd a) (hd a) bn > > instance TypeCast bn HTrue => TypeTopEq' () TEQ_00 (hd a b) (hd z y) bn > instance TypeCast bn HTrue => TypeTopEq' () TEQ_01 (hd a b) (hd z b) bn > instance TypeCast bn HTrue => TypeTopEq' () TEQ_10 (hd a b) (hd a y) bn > instance TypeCast bn HTrue => TypeTopEq' () TEQ_11 (hd a b) (hd a b) bn > > -- more instances and TEQ_* for higher kinds of hd TEQ stands for "top equality qualifier". Each 0 specifies that the corresponding argument to the functor is "soft" and not required to match while each 1 specifies that the type is "hard" and is required to match. For example, these instances result in TypeTopEq TEQ_ Int Char HFalse TypeTopEq TEQ_ Int Int HTrue TypeTopEq TEQ_0 (F Int) (F Int) HTrue TypeTopEq TEQ_0 (F Int) (F Char) HTrue TypeTopEq TEQ_0 (F Int) (F Char) HTrue TypeTopEq TEQ_1 (F Int) (F Char) HFalse TypeTopEq TEQ_0 (F Int) (G Int) HFalse TypeTopEq TEQ_1 (F Int) (G Int) HFalse TypeTopEq TEQ_00 (F2 Int Int) (F2 Char Char) HTrue TypeTopEq TEQ_01 (F2 Int Int) (F2 Char Char) HFalse TypeTopEq TEQ_10 (F2 Int Int) (F2 Char Char) HFalse TypeTopEq TEQ_11 (F2 Int Int) (F2 Char Char) HFalse TypeTopEq TEQ_01 (BF t x) (BF Int x) HTrue --- solves the problem above TypeTopEq TEQ_00 (F2 Int Char) (F2 Char Char) HTrue TypeTopEq TEQ_01 (F2 Int Char) (F2 Char Char) HTrue TypeTopEq TEQ_10 (F2 Int Char) (F2 Char Char) HFalse TypeTopEq TEQ_11 (F2 Int Char) (F2 Char Char) HFalse And so on. This class enables typecases based on the "top equality" of two type variables instead of requiring total equality. For example > class SpecialHMap a b l l' | a b l -> l' where specialHMap :: (a -> b) -> l -> l' > -- HNil case elided > instance ( TypeTopEq teq a head bn, HMap_Case bn a b (HCons teq head tail) l' > ) => SpecialHMap a b (HCons teq head tail) l' where > specialHMap = hmap_case (undefined :: bn) > > class HMap_Case a b l l' | a b l -> l' where hmap_case :: bn -> (a -> b) -> l -> l' > instance ( SpecialHMap a b tail tail' > , TypeCast head a > ) => HMap_Case HTrue a b (HCons teq head tail) (HCons teq b tail) where > hmap_case _ fn (HCons hd tl) = HCons (fn . typeCast $ hd) (specialHMap fn tail) > > -- HFalse/recursive instance elided Note that the HTrue instance uses TypeCast instead of multiple occurences of the same variable in the instance parameters. Unfortunately TypeTopEq wanders into the territory of varying kinds and gets a bit out of hand. It has, however, solved my problem. I used a variant of HCons that also has, as a phantom argument, the TEQ to be used for that element. When the typeclass instances traverse the HList, they use the TEQ for each element to decide how to check for a type match with the domain of the update function. Alternatively, I could try to write an overloaded uHCons function that will calculate the proper TEQ value for an element as it adds it to a list; but that was overkill at the moment. I hope that was interesting! I think this could be quickly expanded to other sorts of type-level pattern matching. Please share any thoughts. Thanks again, Nick From robin_bb at acm.org Fri Nov 17 00:29:43 2006 From: robin_bb at acm.org (Robin Bate Boerop) Date: Fri Nov 17 00:29:01 2006 Subject: [Haskell-cafe] Squash ladder software in Haskell Message-ID: <8A1B9139-B02D-43CB-8117-78670603D3C5@acm.org> I've recently been looking for some open source software that will enable me to run a squash/tennis/badminton ladder on the Web. I haven't found any. So, it's time to write my own. Haskell is my language of choice. Before I start this project, is there anyone out there who has written some code that might be of use to me? Want to share? -- Robin Bate Boerop From tmorris at tmorris.net Fri Nov 17 00:43:22 2006 From: tmorris at tmorris.net (Tony Morris) Date: Fri Nov 17 00:42:29 2006 Subject: [Haskell-cafe] Squash ladder software in Haskell In-Reply-To: <8A1B9139-B02D-43CB-8117-78670603D3C5@acm.org> References: <8A1B9139-B02D-43CB-8117-78670603D3C5@acm.org> Message-ID: <455D4BFA.3010106@tmorris.net> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello fellow squashy, Sorry I cannot provide any software references for you, but I have had similar thoughts to yourself. In particular, I keep a track of my win rate for one of the competitions I play in - but I do this manually. Each time I do, I think, "gee, I should just fire up ghci and blah blah...", but of course, I get home from squash at "ridiculous o'clock" and so ghci is a bit contradictory to my immediate objective - to sleep. I'm not sure if you're aware of the "usual" method of scoring local competitions, but it is a match of best of 5 (as usual) games and a win percentage is calculated by number of games won/total number of games played. For example, suppose I play 3 matches and win 3/0 3/2 and lose 1/3, my win percentage is number of games won (3+3+1)/total number of games played (3+3+1+0+2+3) == 7/12 == 58.3% Many sporting bodies use this number for grading, etc. so it would be good have a cumulative number, with graphs, etc. and for comparison to others (i.e. for grading). A bit early for feature requests I know :) I'll put my hand up as a potential volunteer if you decide to pursue it further. Where do you play? Tony Morris http://tmorris.net/ Robin Bate Boerop wrote: > I've recently been looking for some open source software that will > enable me to run a squash/tennis/badminton ladder on the Web. I haven't > found any. So, it's time to write my own. Haskell is my language of > choice. Before I start this project, is there anyone out there who has > written some code that might be of use to me? Want to share? > > --Robin Bate Boerop > > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFXUv6mnpgrYe6r60RArRYAKCiPMGa6m+lQkW7wjq5vm6ZLZEiYwCgsskd ++NdG6UFRwkMOrEIkOoTvNw= =HdeY -----END PGP SIGNATURE----- From dons at cse.unsw.edu.au Fri Nov 17 01:59:52 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Fri Nov 17 01:59:11 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: References: <20061115125747.GA2012@web.de> <20061116012351.A8E8EAB40@Adric.metnet.fnmoc.navy.mil> Message-ID: <20061117065952.GA11077@cse.unsw.EDU.AU> dmhouse: > On 16/11/06, oleg@pobox.com wrote: > >And if we are absolutely positive that the value is (Just x), > >we can always write > > maybe (assert False undefined) id v > > It should be pointed out that Data.Maybe does export a less well-known > function, fromMaybe: > > fromMaybe z = maybe z id > > This can be used to make the 'maybe X id' case a bit tidier (although > technically it's not a save on characters). How controversial would a proposal to {-# DEPRECATE fromJust #-} be, in favour of: Just _ = x -- which will give you the precise line number maybe (assert False) maybe id fromMaybe It seems to me this is one cause of mysterious newbie errors we could easily discourage, with little harm. -- Don From dons at cse.unsw.edu.au Fri Nov 17 02:13:24 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Fri Nov 17 02:12:28 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: <20061117065952.GA11077@cse.unsw.EDU.AU> References: <20061115125747.GA2012@web.de> <20061116012351.A8E8EAB40@Adric.metnet.fnmoc.navy.mil> <20061117065952.GA11077@cse.unsw.EDU.AU> Message-ID: <20061117071324.GA11255@cse.unsw.EDU.AU> dons: > dmhouse: > > On 16/11/06, oleg@pobox.com wrote: > > >And if we are absolutely positive that the value is (Just x), > > >we can always write > > > maybe (assert False undefined) id v > > > > It should be pointed out that Data.Maybe does export a less well-known > > function, fromMaybe: > > > > fromMaybe z = maybe z id > > > > This can be used to make the 'maybe X id' case a bit tidier (although > > technically it's not a save on characters). > > How controversial would a proposal to {-# DEPRECATE fromJust #-} be, in > favour of: > > Just _ = x -- which will give you the precise line number > > maybe (assert False) > > maybe id > > fromMaybe > > It seems to me this is one cause of mysterious newbie errors we > could easily discourage, with little harm. Btw, I'm not seriously suggesting removing it ;) It could be discouraged ever so slightly in the haddocks though. I'd encourage those worried about fromJust not to use it though, and perhaps try: import Debug.Trace.Location fromMaybe (failure assert "my just was nothing") (Nothing :: Maybe ()) $ ./a.out *** Exception: A.hs:5:34-39: my just was nothing instead of: fromJust (Nothing :: Maybe ()) $ ./a.out *** Exception: Maybe.fromJust: Nothing While Dana and Neil work on more tools for spotting these for us. -- Don From alex at alexjacobson.com Fri Nov 17 02:17:37 2006 From: alex at alexjacobson.com (S. Alexander Jacobson) Date: Fri Nov 17 02:15:55 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: <20061117071324.GA11255@cse.unsw.EDU.AU> References: <20061115125747.GA2012@web.de> <20061116012351.A8E8EAB40@Adric.metnet.fnmoc.navy.mil> <20061117065952.GA11077@cse.unsw.EDU.AU> <20061117071324.GA11255@cse.unsw.EDU.AU> Message-ID: As long as we are doing this, perhaps we should also discourage the use of (head list)? -Alex- ______________________________________________________________ S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com On Fri, 17 Nov 2006, Donald Bruce Stewart wrote: > dons: >> dmhouse: >>> On 16/11/06, oleg@pobox.com wrote: >>>> And if we are absolutely positive that the value is (Just x), >>>> we can always write >>>> maybe (assert False undefined) id v >>> >>> It should be pointed out that Data.Maybe does export a less well-known >>> function, fromMaybe: >>> >>> fromMaybe z = maybe z id >>> >>> This can be used to make the 'maybe X id' case a bit tidier (although >>> technically it's not a save on characters). >> >> How controversial would a proposal to {-# DEPRECATE fromJust #-} be, in >> favour of: >> >> Just _ = x -- which will give you the precise line number >> >> maybe (assert False) >> >> maybe id >> >> fromMaybe >> >> It seems to me this is one cause of mysterious newbie errors we >> could easily discourage, with little harm. > > Btw, I'm not seriously suggesting removing it ;) > It could be discouraged ever so slightly in the haddocks though. > > I'd encourage those worried about fromJust not to use it though, and > perhaps try: > > import Debug.Trace.Location > fromMaybe (failure assert "my just was nothing") > (Nothing :: Maybe ()) > > $ ./a.out > *** Exception: A.hs:5:34-39: my just was nothing > > instead of: > > fromJust (Nothing :: Maybe ()) > > $ ./a.out > *** Exception: Maybe.fromJust: Nothing > > While Dana and Neil work on more tools for spotting these for us. > > -- Don > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From jon.fairbairn at cl.cam.ac.uk Fri Nov 17 05:02:24 2006 From: jon.fairbairn at cl.cam.ac.uk (=?utf-8?b?SsOzbiBGYWlyYmFpcm4=?=) Date: Fri Nov 17 05:01:32 2006 Subject: [Haskell-cafe] Re: Generalizing zip References: Message-ID: J?n Fairbairn writes: > "Jason Dagit" writes: > > > Well, this is basically just a zip with a special base case. But you > > [...] > I wonder if there is mileage to be had from persuing > something like this, rather different (off top of head, very > provisional, E&OE &c) approach: > > extend_infinitely l = map Just l ++ repeat Nothing > promote1 rel (Just a) b = rel a b > promote1 rel Nothing b = False > is_pfx_of l1 l2 = and (zipWith (promote1 (==)) (extend_infinitely l2) l1) or, possibly better extend_infinitely l = map Just l ++ repeat Nothing is_pfx_of l1 l2 = and (zipWith (==) (extend_infinitely l2) (map Just l1)) -- J?n Fairbairn Jon.Fairbairn@cl.cam.ac.uk From bulat.ziganshin at gmail.com Thu Nov 16 17:46:22 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Nov 17 05:08:05 2006 Subject: [Haskell-cafe] 'type' for isomorphism [was poorly named: aggressiveness of functional dependencies] In-Reply-To: <5ce89fb50611161417t4dde39b9u1bfded413b929498@mail.gmail.com> References: <5ce89fb50611161417t4dde39b9u1bfded413b929498@mail.gmail.com> Message-ID: <749433127.20061117014622@gmail.com> Hello Nicolas, Friday, November 17, 2006, 1:17:30 AM, you wrote: > So it works, but it wasn't quite what I had hoped for. Has there been > any work/proposals for specifying a "finalized" type class? I.E. Those > not subject to overlap and thus "closed" to the world? it is a common idea, at least i had it and seen John Meacham's proposal reasons mainly falls into two categories: 1) optimization: this allows compiler to make final decisions and inline appropriate code instead of be ready for some new instances that will change the whole game 2) with closed class, compiler may be smarter about overlapping, type deriving and other type checking/inferring procedures -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From lemming at henning-thielemann.de Fri Nov 17 05:44:58 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Fri Nov 17 06:28:14 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: References: <20061115125747.GA2012@web.de> <20061116012351.A8E8EAB40@Adric.metnet.fnmoc.navy.mil> <20061117065952.GA11077@cse.unsw.EDU.AU> <20061117071324.GA11255@cse.unsw.EDU.AU> Message-ID: On Fri, 17 Nov 2006, S. Alexander Jacobson wrote: > As long as we are doing this, perhaps we should also discourage the use of > (head list)? Is 'cycle' also bad style, because it fails on empty lists? From ndmitchell at gmail.com Fri Nov 17 06:37:12 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Fri Nov 17 06:36:13 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: <20061117071324.GA11255@cse.unsw.EDU.AU> References: <20061115125747.GA2012@web.de> <20061116012351.A8E8EAB40@Adric.metnet.fnmoc.navy.mil> <20061117065952.GA11077@cse.unsw.EDU.AU> <20061117071324.GA11255@cse.unsw.EDU.AU> Message-ID: <404396ef0611170337w1511821ej5543b45f984dce8a@mail.gmail.com> Hi > > How controversial would a proposal to {-# DEPRECATE fromJust #-} be, in > > favour of: > > > > Just _ = x -- which will give you the precise line number > > It seems to me this is one cause of mysterious newbie errors we > > could easily discourage, with little harm. > > Btw, I'm not seriously suggesting removing it ;) > It could be discouraged ever so slightly in the haddocks though. I strongly disagree. If we are removing things that confuse newbies why not start with higher rank types, MPTC's and GADT's ;) fromJust is simple, useful and clear. What you mean is that implementations aren't very good at debugging this. It seems unfair to blame partial functions for the lack of a debugger. If a call stack was automatically output every time a fromJust failed would this even be something people complained about? Thanks Neil From lemming at henning-thielemann.de Fri Nov 17 07:30:29 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Fri Nov 17 07:30:25 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: <404396ef0611170337w1511821ej5543b45f984dce8a@mail.gmail.com> References: <20061115125747.GA2012@web.de> <20061116012351.A8E8EAB40@Adric.metnet.fnmoc.navy.mil> <20061117065952.GA11077@cse.unsw.EDU.AU> <20061117071324.GA11255@cse.unsw.EDU.AU> <404396ef0611170337w1511821ej5543b45f984dce8a@mail.gmail.com> Message-ID: On Fri, 17 Nov 2006, Neil Mitchell wrote: > Hi > > > > How controversial would a proposal to {-# DEPRECATE fromJust #-} be, in > > > favour of: > > > > > > Just _ = x -- which will give you the precise line number > > > > It seems to me this is one cause of mysterious newbie errors we > > > could easily discourage, with little harm. > > > > Btw, I'm not seriously suggesting removing it ;) > > It could be discouraged ever so slightly in the haddocks though. > > I strongly disagree. If we are removing things that confuse newbies > why not start with higher rank types, MPTC's and GADT's ;) > > fromJust is simple, useful and clear. What you mean is that > implementations aren't very good at debugging this. It seems unfair to > blame partial functions for the lack of a debugger. If a call stack > was automatically output every time a fromJust failed would this even > be something people complained about? It seems to me like the discussion about static typesafety vs. no or weak typesafety. (Which still exists with respect to several Haskell libraries.) Of course, all type errors can be catched also by a debugger. So was the decision of making Haskell statically type-safe only made in order to be freed of writing a debugger? Certainly not, because type checks can catch errors early and precisely, that is, better than any debugger. That's also true for DEPRECATE fromJust. Give the user a hint early, that his decision of using fromJust is shortsighted and is possibly due to unfortunate program design. From lennart at augustsson.net Fri Nov 17 08:21:05 2006 From: lennart at augustsson.net (Lennart Augustsson) Date: Fri Nov 17 08:20:31 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: References: <20061115125747.GA2012@web.de> <20061116012351.A8E8EAB40@Adric.metnet.fnmoc.navy.mil> <20061117065952.GA11077@cse.unsw.EDU.AU> <20061117071324.GA11255@cse.unsw.EDU.AU> <404396ef0611170337w1511821ej5543b45f984dce8a@mail.gmail.com> Message-ID: <76727302-ECDA-4E5A-AEF9-690B9F94E5A9@augustsson.net> Exactly! On Nov 17, 2006, at 07:30 , Henning Thielemann wrote: > > > It seems to me like the discussion about static typesafety vs. no > or weak > typesafety. (Which still exists with respect to several Haskell > libraries.) Of course, all type errors can be catched also by a > debugger. > So was the decision of making Haskell statically type-safe only > made in > order to be freed of writing a debugger? Certainly not, because type > checks can catch errors early and precisely, that is, better than any > debugger. That's also true for DEPRECATE fromJust. Give the user a > hint > early, that his decision of using fromJust is shortsighted and is > possibly > due to unfortunate program design. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From jon.fairbairn at cl.cam.ac.uk Fri Nov 17 10:31:48 2006 From: jon.fairbairn at cl.cam.ac.uk (=?utf-8?b?SsOzbiBGYWlyYmFpcm4=?=) Date: Fri Nov 17 10:31:45 2006 Subject: [Haskell-cafe] Friday Afternoon Play: The Burrows Wheeler Transformation Message-ID: So, it's Friday afternoon (well, here anyway), and presumably everyone is thinking of leaving for the weekend. Is anyone interested in playing a little game? I'm going to make the first move, and then just wait and see if anyone makes the next. I'm certainly not promising to make any further moves myself, but I'm not promising I won't, either. Below you'll see a na?ve implementation of the Burrows Wheeler transformation and its inverse. That's my move. (And don't complain too much about style and such -- I'm half asleep.) Further moves are made by transforming the programme so that it becomes more efficient. The first target is not raw speed, but to adjust it until the computational complexity gets to be what it should be. I'm hoping for elegant moves here. After that, folk might start replacing the lists with more efficient datastructures and so on, but still /elegantly/. The object of the game isn't ultimate speed -- I've no particular wish to see a Haskell version that's as fast as a good C version, especially not if it ends up /looking/ like a C version. Really the objective is to think about Haskell programming -- and probably come up with some observations such as "there really ought to be a class of indexable structures, so that we don't have to change (!!) to (!) all over the place". And to have fun, anyhow... * * * Demonstration of the principle of the Burrows Wheeler transform. The implementations are simplistic (and have worse complexity than is possible). > module Burrows_Wheeler_Transform where > import List This is surely the wrong module to have to find (><) from: > import Data.Graph.Inductive.Query.Monad((><)) The forward transformation. Input a list, output the transformed list and possibly an int (Nothing if there were no elements in the input -- perhaps the result type should be Maybe (NonEmptyList t,Int)) > slow_bwt:: Ord t => [t] -> ([t], Maybe Int) This version works by computing a list of all the rotations of the input and sorting it. The transformation is then the last element of each line of the sorted rotations. Tag the data with an index so that it's possible to find where the original form of the unput ends up after sorting. This is essentially the specification of the transform coded up directly. > slow_bwt l > = (map fst tagged_bwt, index_of_original) > where tagged_bwt = map (last> $ sort > $ rotations l`zip`[0..] > index_of_original = findIndex ((==0).snd) tagged_bwt that looks like worst case n??log n to me (where n is the length of the string): if every element is the same, the n?log n comparisons the sort does will each look at every element, and that's really more than is necessary. The inverse transform. We should have that @ slow_inv_bwt . slow_bwt == id @ Observe that sorting the input gives the first column of the sorted rotations (and the input is the last). So after one sort we have X ... c Y ... b Z ... a . . . . . . . . . Since they are rotations, rotating each row of this gives pairs that belong to the original list: cX ... by ... aZ ... . . . . . . sorting these gives us the first two columns of the sorted rotations, and again we already know the last column, which can be rotated into the first and so on. > slow_inv_bwt ([],_) = [] > slow_inv_bwt (l,Just index_of_original) > = iterate catsort (replicate len []) After (length input) iterations we have the original sorted rotations, > !! len and we have the index of where the untransformed string is, so we can just pick it back out. > !! index_of_original > where catsort s = sort $ map (uncurry (:)) $ l `zip`s > len = length l This version does rather fewer sorts: > mark2_inv_bwt ([],_) = [] > mark2_inv_bwt (l,Just n) > = (transpose $ take (length l) $ iterate (permuteWith perm) l)!!(perm!!n) > where perm = map snd $ sort $ l `zip` [0..] Should I simply have left it out and hoped that it would turn up after a few moves? I'm not going to explain it, anyway. > rotations l = init $ zipWith (++) (tails l) (inits l) > permuteWith ns l = map (l!!) ns -- J?n Fairbairn Jon.Fairbairn@cl.cam.ac.uk From bulat.ziganshin at gmail.com Fri Nov 17 06:58:31 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Nov 17 10:52:06 2006 Subject: [Haskell-cafe] Re[2]: [Haskell] I18N, external strings In-Reply-To: <95235646408efacc4a9a283dc2f0b479@kent.ac.uk> References: <455AC36A.9020202@imn.htwk-leipzig.de> <207060770611150135t1afe7815qe2d60f195295f0e9@mail.gmail.com> <95235646408efacc4a9a283dc2f0b479@kent.ac.uk> Message-ID: <1097469246.20061117145831@gmail.com> Hello Axel, Friday, November 17, 2006, 11:27:00 AM, you wrote: > (l_ "Translate this") > is compiled into a C string constant, that GHC then turns lazily into a > list of characters, which l_ then turns into an array in C land to pass > to the gettext function, which, in turn, returns a new C string array > that has to be turned into a Haskell string again. So I'm glad Lennart > proposed to turn String into a class which would then make it possible > to pass a pointer to a contant C string to gettext. i'm not sure that you are right. GHC can perform compile-time computation of constant expressions. Don Bruce should know better, once he pointed out how a String constant can be turned into ByteString one at compile time -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From jgbailey at gmail.com Fri Nov 17 12:03:11 2006 From: jgbailey at gmail.com (Justin Bailey) Date: Fri Nov 17 12:02:11 2006 Subject: [Haskell-cafe] Updated School of Expression Sources? Message-ID: I downloaded the SOE sources from http://www.haskell.org/soe and found they were not compatible with the my version of WinHugs (Sep 2006). I have two questions: 1) Is an updated version of those sources available? 2) If not, would someone like to host mine? I updated all the source files so they at least load without error. Mostly it involved changing a few import statements. I also had to make some updates to the included Haskore files. Also, I found the some of the programs included crash Hugs without warning. For example, evaluating "test cball5" in the file "Fal.lhs" will crash Hugs after running for a few seconds, or if the mouse is moved over the window. Does anyone know why that may occur? Justin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061117/f614564a/attachment.htm From valentin.gjorgjioski at ijs.si Fri Nov 17 12:36:30 2006 From: valentin.gjorgjioski at ijs.si (Valentin Gjorgjioski) Date: Fri Nov 17 12:35:42 2006 Subject: [Haskell-cafe] Collection of objects? Message-ID: <455DF31E.5000606@ijs.si> Is some kind of collection of object with different types in Haskell exist? Except the tuples, which have fixed length. I find this * Tuples heterogeneous, lists homogeneous. * Tuples have a fixed length, or at least their length is encoded in their type. That is, two tuples with different lengths will have different types. * Tuples always finite. But I need something which is heterogeneous and non-fixed length. I'm used do Java, and this switch to functional languages is very strange to me. So, to be clear, I need something like LinkedList in java. Can you please help me or suggest me, what can I use in this case? Valentin From kelanslists at gmail.com Fri Nov 17 12:55:43 2006 From: kelanslists at gmail.com (Kurt Hutchinson) Date: Fri Nov 17 12:54:43 2006 Subject: [Haskell-cafe] Collection of objects? In-Reply-To: <455DF31E.5000606@ijs.si> References: <455DF31E.5000606@ijs.si> Message-ID: On 11/17/06, Valentin Gjorgjioski wrote: > But I need something which is heterogeneous and non-fixed length. You're looking for HList: http://homepages.cwi.nl/~ralf/HList/ Kurt From fis at wiwi.hu-berlin.de Fri Nov 17 13:02:30 2006 From: fis at wiwi.hu-berlin.de (Matthias Fischmann) Date: Fri Nov 17 13:03:44 2006 Subject: [Haskell-cafe] Collection of objects? In-Reply-To: <455DF31E.5000606@ijs.si> References: <455DF31E.5000606@ijs.si> Message-ID: <20061117180230.GC14168@localhost.localdomain> this is not exactly what you are looking for, but it contains a link to HList: http://www.haskell.org/haskellwiki/Extensible_record and then there is the follow-up work to HList, an OO library written in Haskell: http://homepages.cwi.nl/~ralf/OOHaskell/ it's quite a challenging read if you just want to go ahead and use hetero-collections, but it should give you a lot of ideas and pointers. i think there are also less type-safe alternatives in at least ghc. is Data.Typeable an interesting thing to look at? hth, matthias On Fri, Nov 17, 2006 at 06:36:30PM +0100, Valentin Gjorgjioski wrote: > To: haskell-cafe@haskell.org > From: Valentin Gjorgjioski > Date: Fri, 17 Nov 2006 18:36:30 +0100 > Subject: [Haskell-cafe] Collection of objects? > > Is some kind of collection of object with different types in Haskell > exist? Except the tuples, which have fixed length. > I find this > > * Tuples heterogeneous, lists homogeneous. > * Tuples have a fixed length, or at least their length is encoded in > their type. That is, two tuples with different lengths will have > different types. > * Tuples always finite. > > But I need something which is heterogeneous and non-fixed length. I'm > used do Java, and this switch to functional languages is very strange to > me. So, to be clear, I need something like LinkedList in java. > > Can you please help me or suggest me, what can I use in this case? > > Valentin > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe -- Institute of Information Systems, Humboldt-Universitaet zu Berlin web: http://www.wiwi.hu-berlin.de/~fis/ e-mail: fis@wiwi.hu-berlin.de tel: +49 30 2093-5742 fax: +49 30 2093-5741 office: Spandauer Strasse 1, R.324, 10178 Berlin, Germany pgp: AD67 CF64 7BB4 3B9A 6F25 0996 4D73 F1FD 8D32 9BAA From donn at drizzle.com Fri Nov 17 13:08:35 2006 From: donn at drizzle.com (Donn Cave) Date: Fri Nov 17 13:07:38 2006 Subject: [Haskell-cafe] Collection of objects? In-Reply-To: <455DF31E.5000606@ijs.si> Message-ID: On Fri, 17 Nov 2006, Valentin Gjorgjioski wrote: ... > But I need something which is heterogeneous and non-fixed length. I'm > used do Java, and this switch to functional languages is very strange to > me. So, to be clear, I need something like LinkedList in java. I looked in a couple of on-line tutorials, thinking I would quickly find something about this, but -- maybe in my haste I missed something. Objective CAML documentation gets right to it, I wonder if we're assuming prior exposure to strongly typed functional languages? Anyway, you need to define a type that accounts for the types you want to support - data Object = IntObject Int | StringObject String objectString :: Object -> String objectString (IntObject v) = show v objectString (StringObject v) = v main = mapM (putStrLn . objectString) [(IntObject 7), (StringObject "eight")] Donn Cave, donn@drizzle.com From lemming at henning-thielemann.de Fri Nov 17 13:07:35 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Fri Nov 17 13:07:47 2006 Subject: [Haskell-cafe] Collection of objects? In-Reply-To: <455DF31E.5000606@ijs.si> References: <455DF31E.5000606@ijs.si> Message-ID: On Fri, 17 Nov 2006, Valentin Gjorgjioski wrote: > Is some kind of collection of object with different types in Haskell exist? > Except the tuples, which have fixed length. > I find this > > * Tuples heterogeneous, lists homogeneous. > * Tuples have a fixed length, or at least their length is encoded in > their type. That is, two tuples with different lengths will have > different types. > * Tuples always finite. > > But I need something which is heterogeneous and non-fixed length. I'm used do > Java, and this switch to functional languages is very strange to me. So, to be > clear, I need something like LinkedList in java. > > Can you please help me or suggest me, what can I use in this case? If the number of types to cover is fixed, then I suggest a data type like data T = ConsInt Int | ConsString String | ConsChar Char Since this is a very FAQ I wonder why I don't find the answer in any of the Haskell wikis. From robdockins at fastmail.fm Fri Nov 17 13:26:27 2006 From: robdockins at fastmail.fm (Robert Dockins) Date: Fri Nov 17 13:21:58 2006 Subject: [Haskell-cafe] Collection of objects? In-Reply-To: <455DF31E.5000606@ijs.si> References: <455DF31E.5000606@ijs.si> Message-ID: <36CBE334-FE91-4198-BA3B-1247E163FE39@fastmail.fm> On Nov 17, 2006, at 12:36 PM, Valentin Gjorgjioski wrote: > Is some kind of collection of object with different types in > Haskell exist? Except the tuples, which have fixed length. > I find this > > * Tuples heterogeneous, lists homogeneous. > * Tuples have a fixed length, or at least their length is > encoded in > their type. That is, two tuples with different lengths will have > different types. > * Tuples always finite. > > But I need something which is heterogeneous and non-fixed length. > I'm used do Java, and this switch to functional languages is very > strange to me. So, to be clear, I need something like > LinkedList in java. > The thing you're looking for doesn't really exist. (OK, yes, I'm lying a bit. You can use existential types, but you probably don't actually need them, and they can get complicated quickly; they're better left until later). Can you give us more details about what you're trying to do? Readjusting your thinking patterns can be difficult, but the people on this list are usually happy to help. > Can you please help me or suggest me, what can I use in this case? > > Valentin Rob Dockins Speak softly and drive a Sherman tank. Laugh hard; it's a long way to the bank. -- TMBG From nicolas.frisby at gmail.com Fri Nov 17 13:23:07 2006 From: nicolas.frisby at gmail.com (Nicolas Frisby) Date: Fri Nov 17 13:22:08 2006 Subject: [Haskell-cafe] Collection of objects? In-Reply-To: References: <455DF31E.5000606@ijs.si> Message-ID: <5ce89fb50611171023g743bcba4m3eb33374f45e28ce@mail.gmail.com> Depending on your needs and your comfort level with fancier types, the existential approach to ADTs might solve your problem. The following code is a demonstration you can cut-and-paste-and-run. This is example akin to upcasting in Java to an interface that lets you print things. That way you know how to print every object (or do whatever else it is you need to do) in the list. Beware: there is no safe downcasting (that's what Typeable would be for); that would likely be more than you need. There are other ways to do this with existentials (e.g. bounded existentials), but this is what came out of my head when I read your post. Existentials seems to be the "Haskellish" way to reduce a hetergenous list to a collection of objects with common operations. HList would be the Haskellish way for more static and flexible assurances. {-# OPTIONS -fglasgow-exts #-} module Test where data PrintPackage = forall a . PrintPackage a (a -> String) instance Show PrintPackage where show (PrintPackage val showMethod) = showMethod val list = [ PrintPackage 3 show , PrintPackage "string" show , PrintPackage 3.4 show ] main = print list Hope that helps more than it confuses, Nick On 11/17/06, Henning Thielemann wrote: > > On Fri, 17 Nov 2006, Valentin Gjorgjioski wrote: > > > Is some kind of collection of object with different types in Haskell exist? > > Except the tuples, which have fixed length. > > I find this > > > > * Tuples heterogeneous, lists homogeneous. > > * Tuples have a fixed length, or at least their length is encoded in > > their type. That is, two tuples with different lengths will have > > different types. > > * Tuples always finite. > > > > But I need something which is heterogeneous and non-fixed length. I'm used do > > Java, and this switch to functional languages is very strange to me. So, to be > > clear, I need something like LinkedList in java. > > > > Can you please help me or suggest me, what can I use in this case? > > If the number of types to cover is fixed, then I suggest a data type like > > data T = > ConsInt Int > | ConsString String > | ConsChar Char > > > Since this is a very FAQ I wonder why I don't find the answer in any of > the Haskell wikis. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From zacara at gmail.com Fri Nov 17 13:29:25 2006 From: zacara at gmail.com (Clara Zamolo) Date: Fri Nov 17 13:28:24 2006 Subject: [Haskell-cafe] working with lists of couples Message-ID: Hello, i'd like to write a function that given a list like [1,2,3,4...] returns a list of couple where the first element is the corresponding element of the string, and the second is the sum of the previous elements. An example: input: [1,2,3,4] output: [(1,0)(2,1)(3,3)(4,6)] The problem could seem trivial, and here's a first solution: buildCouples = snd . foldl op (0,[]) where op (v,xs) x = (v+x,xs++[(x,v)]) The problem is that this solution is quadratic, and I want a solution that take time n (2n is not good either). Any suggestion? Thanks, Clare. From lemming at henning-thielemann.de Fri Nov 17 13:39:44 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Fri Nov 17 13:39:13 2006 Subject: [Haskell-cafe] working with lists of couples In-Reply-To: References: Message-ID: On Fri, 17 Nov 2006, Clara Zamolo wrote: > Hello, > i'd like to write a function that given a list like [1,2,3,4...] > returns a list of couple where the first element is the corresponding > element of the string, and the second is the sum of the previous > elements. > An example: > input: [1,2,3,4] > output: [(1,0)(2,1)(3,3)(4,6)] > > The problem could seem trivial, and here's a first solution: > > buildCouples = snd . foldl op (0,[]) > where > op (v,xs) x = (v+x,xs++[(x,v)]) > > The problem is that this solution is quadratic, and I want a solution > that take time n (2n is not good either). > > Any suggestion? I suggest using 'scanl' and then 'zip' the result together with the original list. From valentin.gjorgjioski at ijs.si Fri Nov 17 13:51:26 2006 From: valentin.gjorgjioski at ijs.si (Valentin Gjorgjioski) Date: Fri Nov 17 13:50:40 2006 Subject: [Haskell-cafe] working with lists of couples In-Reply-To: References: Message-ID: <455E04AE.7040209@ijs.si> On 17.11.2006 19:29 Clara Zamolo wrote: > Hello, > i'd like to write a function that given a list like [1,2,3,4...] > returns a list of couple where the first element is the corresponding > element of the string, and the second is the sum of the previous > elements. > An example: > input: [1,2,3,4] > output: [(1,0)(2,1)(3,3)(4,6)] > > The problem could seem trivial, and here's a first solution: > > buildCouples = snd . foldl op (0,[]) > where > op (v,xs) x = (v+x,xs++[(x,v)]) > > The problem is that this solution is quadratic, and I want a solution > that take time n (2n is not good either). time n = time 2*n because of O(n)=O(2*n) So, this algorithm should work fine for you buildCouples :: [Int]->Int->[(Int,Int)] buildCouples (x:[]) s = [(x,s)] buildCouples (x:xs) s = [(x,s)] ++ (buildCouples xs (x+s)). buildCouples [1,2,3,4,5,6] 0 [(1,0),(2,1),(3,3),(4,6),(5,10),(6,15)] Valentin From valentin.gjorgjioski at ijs.si Fri Nov 17 13:54:02 2006 From: valentin.gjorgjioski at ijs.si (Valentin Gjorgjioski) Date: Fri Nov 17 13:53:14 2006 Subject: [Haskell-cafe] working with lists of couples In-Reply-To: <455E04AE.7040209@ijs.si> References: <455E04AE.7040209@ijs.si> Message-ID: <455E054A.40407@ijs.si> On 17.11.2006 19:51 Valentin Gjorgjioski wrote: > So, this algorithm should work fine for you > > buildCouples :: [Int]->Int->[(Int,Int)] > buildCouples (x:[]) s = [(x,s)] > buildCouples (x:xs) s = [(x,s)] ++ (buildCouples xs (x+s)). Please ignore the . at the end, it is a typo :( Sorry again... From fis at wiwi.hu-berlin.de Fri Nov 17 13:53:43 2006 From: fis at wiwi.hu-berlin.de (Matthias Fischmann) Date: Fri Nov 17 13:54:22 2006 Subject: [Haskell-cafe] Collection of objects? In-Reply-To: <36CBE334-FE91-4198-BA3B-1247E163FE39@fastmail.fm> References: <455DF31E.5000606@ijs.si> <36CBE334-FE91-4198-BA3B-1247E163FE39@fastmail.fm> Message-ID: <20061117185343.GF14168@localhost.localdomain> i have cut-and-pasted the last few postings into the wiki: http://haskell.org/haskellwiki/Heterogenous_collections it'is very ad hoc, but i hope it helps those who bump into it a little. and it's easier to edit and improve than a mailing list thread. (-: matthias -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061117/873b4008/attachment.bin From valentin.gjorgjioski at ijs.si Fri Nov 17 13:55:26 2006 From: valentin.gjorgjioski at ijs.si (Valentin Gjorgjioski) Date: Fri Nov 17 13:54:30 2006 Subject: [Haskell-cafe] Collection of objects? In-Reply-To: References: Message-ID: <455E059E.5000000@ijs.si> On 17.11.2006 19:08 Donn Cave wrote: > On Fri, 17 Nov 2006, Valentin Gjorgjioski wrote: > ... > >> But I need something which is heterogeneous and non-fixed length. I'm >> used do Java, and this switch to functional languages is very strange to >> me. So, to be clear, I need something like LinkedList in java. >> > > I looked in a couple of on-line tutorials, thinking I would quickly > find something about this, but -- maybe in my haste I missed something. > Objective CAML documentation gets right to it, I wonder if we're assuming > prior exposure to strongly typed functional languages? > > Anyway, you need to define a type that accounts for the types you > want to support - > > data Object = IntObject Int | StringObject String > > objectString :: Object -> String > objectString (IntObject v) = show v > objectString (StringObject v) = v > > main = mapM (putStrLn . objectString) [(IntObject 7), (StringObject "eight")] > > Donn Cave, donn@drizzle.com > > Thanks to all try to help me. I like the solution from Donn and Henning. I obviously not read enough. The solution is also in Yet Another Haskell Tutorial. Ok, not this much explicit, but its there. It says We have seen an example of the data type with one constructor: Pair. It is also possible (and extremely useful) to have multiple constructors(I'm shame that I even didn't know this). It's interesting that it's said EXTREMELY useful. And yes, it is! So, I think that Henning idea is good and this should go on some haskell wiki - s. Once again thanks to all for quick and nice solution. From steve at fenestra.com Fri Nov 17 14:04:22 2006 From: steve at fenestra.com (Steve Schafer) Date: Fri Nov 17 14:03:21 2006 Subject: [Haskell-cafe] Collection of objects? In-Reply-To: <455DF31E.5000606@ijs.si> References: <455DF31E.5000606@ijs.si> Message-ID: <2v0sl25358lo1e6tpvmffkqci3fpclv4c3@4ax.com> On Fri, 17 Nov 2006 18:36:30 +0100, you wrote: >But I need something which is heterogeneous and non-fixed length. I'm >used do Java, and this switch to functional languages is very strange to >me. So, to be clear, I need something like LinkedList in java. In an attempt to leverage your existing Java knowledge... In Java, while the "things" in your list are heterogeneous at some level, they are homogeneous at another: They are all instances of Object (or a subclass thereof). You can't, for example, put an int in your list. And in fact, that's a primary reason for the existence of the Integer class--it makes your int look like an Object, so that you can treat it like one. (And similarly for Character, Float, Double, etc.) So you do the analogous thing in Haskell: First, you ask yourself, "What kinds of things do I want to put in my list?" Once you have the answer to that, you ask, "Are these things homogeneous at some level?" If they are, then you make your list a list of those homogenous things (actually, the compiler generally does it for you). If they aren't, then you wrap them up in a homogeneous wrapper in exactly the same way as you wrap your int in an Integer, your double in a Double, etc., in Java. Some of the other replies have shown you how to declare this; it's trivially simple: data MyHomogeneousWrapper = Integer Int | Character Char | Float Float deriving Show Finally, constructing new instances of this homogenous wrapper in Haskesll is just like it is in Java: myList = [(Integer 42), (Character 'a'), (Float 3.14159)] vs. myList = new LinkedList(); myList.add(new Integer(42)); myList.add(new Character('a')); myList.add(new Float(3.14159)); Steve Schafer Fenestra Technologies Corp. http://www.fenestra.com/ From aditya_siram at hotmail.com Fri Nov 17 15:03:38 2006 From: aditya_siram at hotmail.com (Aditya Siram) Date: Fri Nov 17 15:02:42 2006 Subject: [Haskell-cafe] Updated School of Expression Sources? In-Reply-To: Message-ID: My understanding is that the SOE sources only work with an old version of Hugs. It is available at : http://www.haskell.org/soe/software.htm Regards, Deech >From: "Justin Bailey" >To: haskell-cafe@haskell.org >Subject: [Haskell-cafe] Updated School of Expression Sources? >Date: Fri, 17 Nov 2006 09:03:11 -0800 > >I downloaded the SOE sources from http://www.haskell.org/soe and found they >were not compatible with the my version of WinHugs (Sep 2006). I have two >questions: > >1) Is an updated version of those sources available? >2) If not, would someone like to host mine? I updated all the source files >so they at least load without error. Mostly it involved changing a few >import statements. I also had to make some updates to the included Haskore >files. > >Also, I found the some of the programs included crash Hugs without warning. >For example, evaluating "test cball5" in the file "Fal.lhs" will crash Hugs >after running for a few seconds, or if the mouse is moved over the window. >Does anyone know why that may occur? > >Justin >_______________________________________________ >Haskell-Cafe mailing list >Haskell-Cafe@haskell.org >http://www.haskell.org/mailman/listinfo/haskell-cafe _________________________________________________________________ Share your latest news with your friends with the Windows Live Spaces friends module. http://clk.atdmt.com/MSN/go/msnnkwsp0070000001msn/direct/01/?href=http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mk From aditya_siram at hotmail.com Fri Nov 17 15:13:19 2006 From: aditya_siram at hotmail.com (Aditya Siram) Date: Fri Nov 17 15:12:22 2006 Subject: [Haskell-cafe] Newbie; Can't Install Hat From Source In-Reply-To: <20061116104210.215ef3d2.Malcolm.Wallace@cs.york.ac.uk> Message-ID: Thanks to Malcolm Wallace I got Hat installed and working from darcs using: 'darcs get http://darcs.haskell.org/hat' cd'ing in to the 'hat' directory and doing an 'sh start'. This last step makes all scripts executable. Appreciate the support... Deech >From: Malcolm Wallace >To: haskell-cafe@haskell.org >CC: hat@haskell.org >Subject: Re: [Haskell-cafe] Newbie; Can't Install Hat From Source >Date: Thu, 16 Nov 2006 10:42:10 +0000 > >"Aditya Siram" wrote: > > > I have been trying to install Hat for the last couple of days but GHC > > does not recognize it as a package. I compiled 2.05 from source, but > > at the 'make install' step I see this error message: > > > > Installing hat package for ghc under > > /usr/local/lib/hat-2.05/ix86-Linux/ghc-606 > > ghc-pkg: cannot find package hat <-----ERROR MESSAGE!!!!! > >This error message can be safely ignored - it comes from a requirement >to support several different versions of ghc, each of which has a >different interface to the package manager ghc-pkg. > > > ghc-pkg: package hat-2.4 is already installed > > > > /usr/local/lib/ghc-6.6/package.conf: > > ... > > /home/deech/.ghc/i386-linux-6.6/package.conf: > > (hat-2.4) <----ERROR!!! > > > > For some reason it thinks that hat-2.4 is installed. > >This is one of a couple of bugs in the 2.05 package. The .cabal file >simply had the wrong version number in it. > > > Bad interface file: > > /usr/local/imports/hat-2.05/ghc-606/Hat/PreludeBasic.hi > > Something is amiss; requested module hat-2.4:Hat.PreludeBasic > > differs from name found in the interface file hat:Hat.PreludeBasic > >And this is the other bug: the Hat library package was built using >"-package-name hat" instead of "-package-name hat-2.05" (as now required >by ghc-6.6 and above). > >I have re-rolled the Hat-2.05 distribution package with these two very >minor bugfixes. Please try downloading it again, and re-building. > >Regards, > Malcolm >_______________________________________________ >Haskell-Cafe mailing list >Haskell-Cafe@haskell.org >http://www.haskell.org/mailman/listinfo/haskell-cafe _________________________________________________________________ View Athlete’s Collections with Live Search http://sportmaps.live.com/index.html?source=hmemailtaglinenov06&FORM=MGAC01 From hjgtuyl at chello.nl Fri Nov 17 17:19:55 2006 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Fri Nov 17 17:18:56 2006 Subject: [Haskell-cafe] Collection of objects? In-Reply-To: <2v0sl25358lo1e6tpvmffkqci3fpclv4c3@4ax.com> References: <455DF31E.5000606@ijs.si> <2v0sl25358lo1e6tpvmffkqci3fpclv4c3@4ax.com> Message-ID: On Fri, 17 Nov 2006 20:04:22 +0100, Steve Schafer wrote: > myList = [(Integer 42), (Character 'a'), (Float 3.14159)] You can leave out the parentheses, making even simpler: myList = [Integer 42, Character 'a', Float 3.14159] -- Met vriendelijke groet, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ -- Using Opera's revolutionary e-mail client: https://secure.bmtmicro.com/opera/buy-opera.html?AID=789433 From shae at ScannedInAvian.com Fri Nov 17 18:08:10 2006 From: shae at ScannedInAvian.com (Shae Matijs Erisson) Date: Fri Nov 17 18:07:33 2006 Subject: [Haskell-cafe] Try Graphics.SOE.Gtk ? was Re: Updated School of Expression Sources? References: Message-ID: <87wt5t4qp1.fsf@thunderbird.scannedinavian.com> "Justin Bailey" writes: > I downloaded the SOE sources from http://www.haskell.org/soe and found they > were not compatible with the my version of WinHugs (Sep 2006). I have two > questions: > > 1) Is an updated version of those sources available? > 2) If not, would someone like to host mine? I updated all the source files > so they at least load without error. Mostly it involved changing a few > import statements. I also had to make some updates to the included Haskore > files. Another option is Duncan Coutts' reimplementation of Graphics.SOE in GTK2: http://haskell.org/~duncan/soegtk/ -- I've tried to teach people autodidactism, | ScannedInAvian.com but it seems they always have to learn it for themselves.| Shae Matijs Erisson -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061117/fc4beb56/attachment.bin From john at repetae.net Fri Nov 17 19:21:38 2006 From: john at repetae.net (John Meacham) Date: Fri Nov 17 19:20:13 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: <404396ef0611170337w1511821ej5543b45f984dce8a@mail.gmail.com> References: <20061115125747.GA2012@web.de> <20061116012351.A8E8EAB40@Adric.metnet.fnmoc.navy.mil> <20061117065952.GA11077@cse.unsw.EDU.AU> <20061117071324.GA11255@cse.unsw.EDU.AU> <404396ef0611170337w1511821ej5543b45f984dce8a@mail.gmail.com> Message-ID: <20061118002138.GK25206@momenergy.repetae.net> On Fri, Nov 17, 2006 at 11:37:12AM +0000, Neil Mitchell wrote: > fromJust is simple, useful and clear. What you mean is that > implementations aren't very good at debugging this. It seems unfair to > blame partial functions for the lack of a debugger. If a call stack > was automatically output every time a fromJust failed would this even > be something people complained about? indeed. jhc debugs this quite fine. when you use it the wrong way you get Main.hs:23:33:fromJust Nothing as your error message. or you should at least. likewise for head, tail, undefined, etc.. actually any function including ones you write yourself for which you give the SRCLOC_ANNOTATE pragma. boy I want to have the time to port that to ghc... a six pack of beer for whoever does :) John -- John Meacham - ?repetae.net?john? From dm.maillists at gmail.com Fri Nov 17 19:37:30 2006 From: dm.maillists at gmail.com (Daniel McAllansmith) Date: Fri Nov 17 19:35:35 2006 Subject: [Haskell-cafe] Re: Debugging partial functions by the rules In-Reply-To: <404396ef0611170337w1511821ej5543b45f984dce8a@mail.gmail.com> References: <20061115125747.GA2012@web.de> <20061117071324.GA11255@cse.unsw.EDU.AU> <404396ef0611170337w1511821ej5543b45f984dce8a@mail.gmail.com> Message-ID: <200611181337.30466.dm.maillists@gmail.com> On Saturday 18 November 2006 00:37, Neil Mitchell wrote: > Hi > > > > How controversial would a proposal to {-# DEPRECATE fromJust #-} be, in > > > favour of: > > > > > > Just _ = x -- which will give you the precise line number > > > > > > It seems to me this is one cause of mysterious newbie errors we > > > could easily discourage, with little harm. > > > > Btw, I'm not seriously suggesting removing it ;) > > It could be discouraged ever so slightly in the haddocks though. > > I strongly disagree. If we are removing things that confuse newbies > why not start with higher rank types, MPTC's and GADT's ;) > > fromJust is simple, useful and clear. What you mean is that > implementations aren't very good at debugging this. It seems unfair to > blame partial functions for the lack of a debugger. If a call stack > was automatically output every time a fromJust failed would this even > be something people complained about? Well, I strongly disagree. :) I suspect I would be classified as a newbie relative to most posters on this list but here's my thoughts anyway... I chose to learn haskell largely because I thought the static type safety would help eliminate bugs, I've never once been happy when I've needed to fire up a debugger or add trace statements and I hoped they would become things of the past. One of my initial responses to haskell was disappointment upon seeing head, fromJust and the like. 'Those look nasty', I sez to meself. From day one I've tried to avoid using them. Very occasionally I do use them in the heat of the moment, but it makes me feel unclean and I end up having to take my keyboard into the bathroom for a good scrubbing with the sandsoap. The disappointment has pretty much changed to frustration since reading Oleg, and others, type-hackery work. I realise the problems are just poor/limited usage of haskell, not inherent in the language. Unfortunately I can understand the 'right' solutions but still have trouble formulating them myself. I'm hoping that if I hang out in the type-hackery 'hot zone' long enough I'll start emitting enough picoOlegs myself to solve simple problems. ;) My view is that if I can reason about my program and know a static property I want to be able to stamp this into the types and have my reasoning validated during compilation. But existing library code with weak typesafety is a large inertial mass, when trying to do something 'right' the interfacing is a daunting prospect. In general I'd rather have effort go into promoting 'right' solutions, and making those solutions easier to express, than going into debuggers for 'wrong' solutions. Daniel From dons at cse.unsw.edu.au Fri Nov 17 20:32:20 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Fri Nov 17 20:31:21 2006 Subject: [Haskell-cafe] Re[2]: [Haskell] I18N, external strings In-Reply-To: <1097469246.20061117145831@gmail.com> References: <455AC36A.9020202@imn.htwk-leipzig.de> <207060770611150135t1afe7815qe2d60f195295f0e9@mail.gmail.com> <95235646408efacc4a9a283dc2f0b479@kent.ac.uk> <1097469246.20061117145831@gmail.com> Message-ID: <20061118013220.GC10581@cse.unsw.EDU.AU> bulat.ziganshin: > Hello Axel, > > Friday, November 17, 2006, 11:27:00 AM, you wrote: > > > (l_ "Translate this") > > > is compiled into a C string constant, that GHC then turns lazily into a > > list of characters, which l_ then turns into an array in C land to pass > > to the gettext function, which, in turn, returns a new C string array > > that has to be turned into a Haskell string again. So I'm glad Lennart > > proposed to turn String into a class which would then make it possible > > to pass a pointer to a contant C string to gettext. > > i'm not sure that you are right. GHC can perform compile-time computation > of constant expressions. Don Bruce should know better, once he pointed > out how a String constant can be turned into ByteString one at compile > time Quite so, using (what else?) rewrite rules! Supposing I want to use a ByteString literal (and lennart hasn't yet committed overloaded strings into GHC..) I can write: import qualified Data.ByteString.Char8 as C main = C.putStrLn mystring mystring = C.pack "rewrite rules are fun!" and it is compiled by GHC to: mystring_rDR = Data.ByteString.Char8.pack (GHC.Base.unpackCString# "rewrite rules are fun!"#) Main.main :: GHC.IOBase.IO () Main.main = Data.ByteString.putStrLn mystring_rDR :Main.main :: GHC.IOBase.IO () :Main.main = GHC.TopHandler.runMainIO @ () Main.main Now, the string literals has been packed by GHC for us into a Addr#, pointing to a proper C string. Now, we'd like to remove that intermediate unpackCString#, and just pack the string literal straight into a ByteString, avoiding an intermediate list. So we add a rewrite rule: {-# RULES "pack/packAddress" forall s . pack (unpackCString# s) = B.packAddress s #-} Now, when compiled with -O -fglasgow-exts, we get: 1 RuleFired 1 FPS pack/packAddress and the code is transformed as follows: mystring = Data.ByteString.Base.packAddress "rewrite rules are fun!" to mystring = Data.ByteString.Char8.pack (GHC.Base.unpackCString# "rewrite rules are fun!"#) and then the rewrite rule kicks in, and we construct a new ByteString directly from the Addr#, via a call to strlen to get the length: mystring = let addr#_a146 :: GHC.Prim.Addr# addr#_a146 = "rewrite rules are fun!"# in case Data.ByteString.Base.$wccall addr#_a146 s2#_a1Q8 of (# ds3_a1Re, ds4_a1Rf #) -> Data.ByteString.Base.PS addr#_a146 (GHC.ForeignPtr.PlainForeignPtr var#_a1Q9) 0 (GHC.Prim.word2Int# ds4_a1Rf) *exactly* what we'd like. So at runtime, this string will require only a call to strlen to build. If the compiler was able to pack string literals to CStringLen, tagging them with their length, we could avoid the O(n) strlen call, and directy build ByteStrings in O(1), using unsafePackAddress#, which takes a length field. I.e. something like: mystring = let addr#_a146 :: GHC.Prim.Addr# addr#_a146 = "rewrite rules are fun!"# len :: GHC.Prim.Int# len = 22 in Data.ByteString.Base.PS addr#_a146 (GHC.ForeignPtr.PlainForeignPtr var#_a1Q9) 0 len# -- Don From chak at cse.unsw.edu.au Fri Nov 17 21:23:36 2006 From: chak at cse.unsw.edu.au (Manuel M T Chakravarty) Date: Fri Nov 17 21:22:40 2006 Subject: [Haskell-cafe] Are associated types synonyms like type classes? In-Reply-To: References: <63944068.20060901212621@gmail.com> Message-ID: <1163816616.23772.183.camel@trinity.localdomain> Brian Smith: > When using AT then we have to decide what part of the abstraction is > the class and what part is the associated type. Sometimes this seams > arbitrary. If we have: > > class A a where > type B b > f :: a -> B b > instance A Int where > type B = Bool > f = (==0) > > Can't we also rewrite it as: > > class B b where > type A a > f :: A a -> b > instance B Bool where > type A = Int > f = (==0) If it is arbitrary, you should use a two parameter class. The bias in an associated type is on purpose; ie, an associated type should be used if one type depends on the other. Bulat wrote: > > Also, has anybody written a paper on the differences between > > typeclasses + associated types and ML's module system + > overloading? > > "ML Modules and Haskell Type Classes: A Constructive Comparison" > http://www.informatik.uni-freiburg.de/~wehr/diplom/Wehr_ML_modules_and_Haskell_type_classes.pdf In addition to this comparison, there is now also a proposal for type classes with associated types as a mode of use of ML modules. See our forthcoming POPL paper: http://www.cse.unsw.edu.au/~chak/papers/DHC07.html Ie, this gives you ML modules + overloading. Manuel From dagit at eecs.oregonstate.edu Fri Nov 17 21:42:57 2006 From: dagit at eecs.oregonstate.edu (Jason Dagit) Date: Fri Nov 17 21:41:55 2006 Subject: [Haskell-cafe] Debugging partial functions by the rules In-Reply-To: <20061115045431.GE3715@cse.unsw.EDU.AU> References: <20061115045431.GE3715@cse.unsw.EDU.AU> Message-ID: This good long thread prompted Don and I to take a look at the darcs source (this is current darcs-unstable). You can get the darcs source at: darcs get http://abridgegame.org/repos/darcs-unstable Here are some data points (without interpretation): In impossible.h we have the definitions: import Bug ( bug ) #define impossible (bug $ "Impossible case at "++__FILE__++":"++show (__LINE__ :: Int)++" compiled "++__TIME__++" "++__DATE__) #define fromJust (\m_fromJust_funny_name -> case m_fromJust_funny_name of {Nothing -> bug ("fromJust error at "++__FILE__++":"++show (__LINE__ :: Int)++" compiled "++__TIME__++" "++__DATE__); Just x -> x}) The second definition gives bug reports like the following: fromJust error at Push.lhs:136 compiled 11:51:58 Jun 16 2006 Please report this to bugs@darcs.net, If possible include the output of 'darcs --exact-version'. To see at a glance the various bug reports about fromJust you can search the bug database: http://bugs.darcs.net/issue?@columns=id%2Cactivity%2Ctitle%2Ccreator%2Cassignedto%2Cstatus&@sort=activity&@group=priority&@search_text=fromJust I count 7 bugs. Some other datapoints: $ grep fromJust *.lhs *.hs | wc -l 101 $ grep fromMaybe *.lhs *.hs | wc -l 7 $ grep maybe *.lhs *.hs | wc -l 120 I would be interested to see the results of static analysis tools (Catch?) or applying Oleg's strategy. Any volunteers? thanks! Jason From dons at cse.unsw.edu.au Sat Nov 18 00:27:34 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Sat Nov 18 00:26:36 2006 Subject: [Haskell-cafe] Wiki page for rewrite rules tips, types and tricks Message-ID: <20061118052734.GE10581@cse.unsw.EDU.AU> After suggesting solutions based on rewrite rules to three different questions this week, I though maybe we better have a wiki page on using rewrite rules for non-traditional ad-hoc tricks. http://haskell.org/haskellwiki/Playing_by_the_rules If you've used rewrite rules for something fun (other than implementing a major deforestation system), please add it to the page. -- Don From ndmitchell at gmail.com Sat Nov 18 01:34:43 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Sat Nov 18 01:33:44 2006 Subject: [Haskell-cafe] Debugging partial functions by the rules In-Reply-To: References: <20061115045431.GE3715@cse.unsw.EDU.AU> Message-ID: <404396ef0611172234o733fb251q637f297e195fab4a@mail.gmail.com> Hi > To see at a glance the various bug reports about fromJust you can > search the bug database: > http://bugs.darcs.net/issue?@columns=id%2Cactivity%2Ctitle%2Ccreator%2Cassignedto%2Cstatus&@sort=activity&@group=priority&@search_text=fromJust > > I count 7 bugs. > I would be interested to see the results of static analysis tools > (Catch?) or applying Oleg's strategy. Any volunteers? Unfortunately darcs is too big, and too unhaskell-98 to go through Catch as it currently stands. In reality the best strategy would probably be to use Catch on darcs, then where Catch is unable to automatically verify the program use Oleg's techniques and other rewritings until Catch can verify everything. Just taking a random example (the first fromJust I stumbled upon): http://abridgegame.org/repos/darcs-unstable/Population.lhs, cleanPop The requirement here is that the modifiedHowI field of the 2nd field of the Pop at the top must be not a removal. Figuring out in an existing code-base whether that is a general invariant for Pop, true in this specific case, or any other random combination is quite a hard problem! Thanks Neil From trevion at gmail.com Sat Nov 18 03:44:41 2006 From: trevion at gmail.com (J. Garrett Morris) Date: Sat Nov 18 03:43:40 2006 Subject: [Haskell-cafe] working with lists of couples In-Reply-To: References: Message-ID: <6cf91caa0611180044s7d0e873eka7bc7b53c5190987@mail.gmail.com> On 11/17/06, Henning Thielemann wrote: > On Fri, 17 Nov 2006, Clara Zamolo wrote: > > buildCouples = snd . foldl op (0,[]) > > where > > op (v,xs) x = (v+x,xs++[(x,v)]) > > You could make something like this that doesn't have quadratic-type appends by accumulating functions instead of lists: Prelude> snd (foldl (\(s,f) x -> (x+s,f . ((x,s):))) (0,id) [1..6]) [] [(1,0),(2,1),(3,3),(4,6),(5,10),(6,15)] but this is better: > I suggest using 'scanl' and then 'zip' the result together with the > original list. Or, equivalently, use mapAccumL from the Data.List library: Prelude Data.List> snd $ mapAccumL (\s x -> (s + x,(x,s))) 0 [1..6] [(1,0),(2,1),(3,3),(4,6),(5,10),(6,15)] /g From hjgtuyl at chello.nl Sat Nov 18 04:15:28 2006 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Sat Nov 18 04:14:32 2006 Subject: [Haskell-cafe] Wiki page for rewrite rules tips, types and tricks In-Reply-To: <20061118052734.GE10581@cse.unsw.EDU.AU> References: <20061118052734.GE10581@cse.unsw.EDU.AU> Message-ID: Great page, I especially like the phrase: [...] changing a non-terminating program [...] into a much faster one [...] On Sat, 18 Nov 2006 06:27:34 +0100, Donald Bruce Stewart wrote: > After suggesting solutions based on rewrite rules to three different > questions this week, I though maybe we better have a wiki page on using > rewrite rules for non-traditional ad-hoc tricks. > > http://haskell.org/haskellwiki/Playing_by_the_rules > > If you've used rewrite rules for something fun (other than implementing > a major deforestation system), please add it to the page. > > -- Don -- Met vriendelijke groet, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ -- Using Opera's revolutionary e-mail client: https://secure.bmtmicro.com/opera/buy-opera.html?AID=789433 From benjamin.franksen at bessy.de Sat Nov 18 08:29:42 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Sat Nov 18 08:28:49 2006 Subject: [Haskell-cafe] Re: Re: Debugging partial functions by the rules References: <20061115125747.GA2012@web.de> <20061117071324.GA11255@cse.unsw.EDU.AU> <404396ef0611170337w1511821ej5543b45f984dce8a@mail.gmail.com> <200611181337.30466.dm.maillists@gmail.com> Message-ID: Daniel, you wrote: > I suspect I would be classified as a newbie relative to most posters on > this list but here's my thoughts anyway... > [...] > One of my initial responses to haskell was disappointment upon seeing > head, > fromJust and the like. 'Those look nasty', I sez to meself. > From day one I've tried to avoid using them. Very occasionally I do use > them in the heat of the moment, but it makes me feel unclean and I end up > having to take my keyboard into the bathroom for a good scrubbing with the > sandsoap. I completely agree and couldn't have said it in any better way (including the relative newbie part). Ben From dons at cse.unsw.edu.au Sat Nov 18 08:44:30 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Sat Nov 18 08:43:31 2006 Subject: [Haskell-cafe] Debugging partial functions by the rules In-Reply-To: <404396ef0611172234o733fb251q637f297e195fab4a@mail.gmail.com> References: <20061115045431.GE3715@cse.unsw.EDU.AU> <404396ef0611172234o733fb251q637f297e195fab4a@mail.gmail.com> Message-ID: <20061118134430.GA14267@cse.unsw.EDU.AU> ndmitchell: > Hi > > >To see at a glance the various bug reports about fromJust you can > >search the bug database: > >http://bugs.darcs.net/issue?@columns=id%2Cactivity%2Ctitle%2Ccreator%2Cassignedto%2Cstatus&@sort=activity&@group=priority&@search_text=fromJust > > > >I count 7 bugs. > > >I would be interested to see the results of static analysis tools > >(Catch?) or applying Oleg's strategy. Any volunteers? > > Unfortunately darcs is too big, and too unhaskell-98 to go through > Catch as it currently stands. In reality the best strategy would > probably be to use Catch on darcs, then where Catch is unable to > automatically verify the program use Oleg's techniques and other > rewritings until Catch can verify everything. > > Just taking a random example (the first fromJust I stumbled upon): > > http://abridgegame.org/repos/darcs-unstable/Population.lhs, cleanPop > > The requirement here is that the modifiedHowI field of the 2nd field > of the Pop at the top must be not a removal. Figuring out in an > existing code-base whether that is a general invariant for Pop, true > in this specific case, or any other random combination is quite a hard > problem! This would be an argument for deprecating fromJust then, to discourage its use. The darcs case illustrates how the fromJust style encourages the (unintentional) embedding of uncheckable isJust invariants into Haskell code. The relatively high bug report rate in darcs due to uncaught fromJusts only emphasises the problems associated with this style. -- Don From alfonso.acosta at gmail.com Sat Nov 18 12:45:35 2006 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Sat Nov 18 12:44:37 2006 Subject: [Haskell-cafe] Type signatures in FFI exported functions Message-ID: <6a7c66fc0611180945u74010cf2o387cc19db39ea682@mail.gmail.com> Hi, The FFI doesn't allow using type signatures in exported functions. Imagine this simplified example class Foo a where action1 :: a -> IO() action2 :: a -> IO() exportable :: Foo a => StablePtr a -> IO() exportable ptr = do deref <- deRefStablePtr ptr action1 deref Currently the FFI doesn't allow to export exportable due to the type signature. But I don't really understand why isn't it feisable. In my code I solved the problem by quantifying existentially data CFoo = forall a.Foo a => CFoo a instance Foo CFoo where action1 (CFoo a) = action1 a action2 (CFoo a) = action2 a exportable' :: StablePtr CFoo -> IO() exportable' ptr = do deref <- deRefStablePtr ptr action1 a Another way to fix it would be, unlike standard Haskell98, allowing dictionaries to be packaged in data constructors data CFoo' a = Foo a => CFoo' a instance Foo (CFoo' a) where action1 (CFoo' x) = action1 x action2 (CFoo' x) = action2 x exportable'' :: StablePtr (CFoo' a) -> IO() exportable'' ptr = do deref <- deRefStablePtr ptr action1 deref As far as I know, the later option has only been recently made available for GADTs in GHC, does anyone know away of doing it with normal ADT? Does anyone know a better workaround? Thanks in advance, Alfonso Acosta From magnus at therning.org Sat Nov 18 13:48:44 2006 From: magnus at therning.org (Magnus Therning) Date: Sat Nov 18 13:47:48 2006 Subject: [Haskell-cafe] importing Distribution.Compat.FilePath fails Message-ID: <20061118184844.GA2683@die.therning.org> Putting import Distribution.Compat.FilePath in my source results in Could not find module `Distribution.Compat.FilePath': it is hidden (in package Cabal-1.1.6) I want to use 'joinFileName'. I found this thread from the cabal-devel list http://www.mail-archive.com/cabal-devel@haskell.org/msg00162.html and I was hoping that my cabal version would have an unhidden FilePath module... apparently not. Can I unhide it somehow? /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus Software is not manufactured, it is something you write and publish. Keep Europe free from software patents, we do not want censorship by patent law on written works. It's important for a corporate leader to know the difference between what is actually illegal, and what people assume should be illegal. -- Bill Gates, in interview for The Register, 19th June 2006 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061118/f781231b/attachment.bin From lemmih at gmail.com Sat Nov 18 14:18:12 2006 From: lemmih at gmail.com (Lemmih) Date: Sat Nov 18 14:17:07 2006 Subject: [Haskell-cafe] importing Distribution.Compat.FilePath fails In-Reply-To: <20061118184844.GA2683@die.therning.org> References: <20061118184844.GA2683@die.therning.org> Message-ID: On 11/18/06, Magnus Therning wrote: > Putting > > import Distribution.Compat.FilePath > > in my source results in > > Could not find module `Distribution.Compat.FilePath': > it is hidden (in package Cabal-1.1.6) > > I want to use 'joinFileName'. > > I found this thread from the cabal-devel list > > http://www.mail-archive.com/cabal-devel@haskell.org/msg00162.html > > and I was hoping that my cabal version would have an unhidden FilePath > module... apparently not. Can I unhide it somehow? How about using this instead: http://www-users.cs.york.ac.uk/~ndm/projects/libraries.php#filepath -- Cheers, Lemmih From coffeemug at gmail.com Sat Nov 18 15:33:42 2006 From: coffeemug at gmail.com (Vyacheslav Akhmechet) Date: Sat Nov 18 15:32:39 2006 Subject: [Haskell-cafe] Cabal ^M bug Message-ID: Cabal appears to have an end-of-line bug. If the .cabal file is created on Windows and the project is installed on a Unix system, the resulting executable ends up having ^M at the end because Cabal doesn't properly handle Windows line termination. If the .cabal file is converted to Unix style, everything installs as expected. I tried to submit a ticket to Cabal via the wiki but couldn't authenticate (guest/haskell, as says on the web page, doesn't seem to work). Also HackageDB link seems to be down. I'm not sure who's maintaining the project, so I'm emaling here. Thanks, - Slava. From magnus at therning.org Sat Nov 18 16:31:09 2006 From: magnus at therning.org (Magnus Therning) Date: Sat Nov 18 16:30:12 2006 Subject: [Haskell-cafe] importing Distribution.Compat.FilePath fails In-Reply-To: References: <20061118184844.GA2683@die.therning.org> Message-ID: <20061118213109.GB2683@die.therning.org> On Sat, Nov 18, 2006 at 20:18:12 +0100, Lemmih wrote: >On 11/18/06, Magnus Therning wrote: >>Putting >> >> import Distribution.Compat.FilePath >> >>in my source results in >> >> Could not find module `Distribution.Compat.FilePath': >> it is hidden (in package Cabal-1.1.6) >> >>I want to use 'joinFileName'. >> >>I found this thread from the cabal-devel list >> >> http://www.mail-archive.com/cabal-devel@haskell.org/msg00162.html >> >>and I was hoping that my cabal version would have an unhidden FilePath >>module... apparently not. Can I unhide it somehow? > >How about using this instead: >http://www-users.cs.york.ac.uk/~ndm/projects/libraries.php#filepath The only reason would be that it isn't in my GHC install by default (I'm on Debian Sid). However, I suppose I can look at this as an excellent first experiment with Cabal and packaging Haskell libs for Debian :-) Thanks for pointing it out. Looks like a perfect fit for me! /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus Software is not manufactured, it is something you write and publish. Keep Europe free from software patents, we do not want censorship by patent law on written works. Programs should be written for people to read, and only incidentally for machines to execute. -- Quote from Structure and Interpretation of Computer Programs -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061118/5380c753/attachment-0001.bin From ndmitchell at gmail.com Sat Nov 18 16:33:43 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Sat Nov 18 16:32:39 2006 Subject: [Haskell-cafe] Wiki page for rewrite rules tips, types and tricks In-Reply-To: References: <20061118052734.GE10581@cse.unsw.EDU.AU> Message-ID: <404396ef0611181333i44e9ecd2mf3b67891c3bddb5c@mail.gmail.com> Hi > Great page, I especially like the phrase: > [...] changing a non-terminating program [...] into a much faster one [...] And one important point: In general its a bad idea for rules to change the semantics (meaning) of your code in such a way. Consider someone using reverse . reverse to demand strictness of an IO action (I've seen this in conjunction with interact), this code would no longer work with the above rule. Thanks Neil From ndmitchell at gmail.com Sat Nov 18 16:34:55 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Sat Nov 18 16:33:51 2006 Subject: [Haskell-cafe] importing Distribution.Compat.FilePath fails In-Reply-To: <20061118213109.GB2683@die.therning.org> References: <20061118184844.GA2683@die.therning.org> <20061118213109.GB2683@die.therning.org> Message-ID: <404396ef0611181334g605e0727i2722cd5fd0dc6627@mail.gmail.com> Hi > >How about using this instead: > >http://www-users.cs.york.ac.uk/~ndm/projects/libraries.php#filepath > > The only reason would be that it isn't in my GHC install by default (I'm > on Debian Sid). However, I suppose I can look at this as an excellent > first experiment with Cabal and packaging Haskell libs for Debian :-) > > Thanks for pointing it out. Looks like a perfect fit for me! I think someone is packaging this for Debian already, you might want to email the debian haskell list to check and avoid duplicated work. Thanks Neil From dons at cse.unsw.edu.au Sat Nov 18 23:41:29 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Sat Nov 18 23:40:31 2006 Subject: [Haskell-cafe] Starting your own Haskell project: part 2 Message-ID: <20061119044129.GA12107@cse.unsw.EDU.AU> We've expanded the wiki page on 'How to write a Haskell project', to include a complete walkthrough creating: * Darcs * Cabal * QuickCheck infrastructure. http://haskell.org/haskellwiki/How_to_write_a_Haskell_program Feedback welcome! -- Don P.S. It might even be useful to have a tool, haskell-project, which sets up all these files automatically. From ithika at gmail.com Sun Nov 19 06:10:09 2006 From: ithika at gmail.com (Dougal Stanton) Date: Sun Nov 19 06:07:12 2006 Subject: [Haskell-cafe] Starting your own Haskell project: part 2 In-Reply-To: <20061119044129.GA12107@cse.unsw.EDU.AU> References: <20061119044129.GA12107@cse.unsw.EDU.AU> Message-ID: <20061119111009.GH22797@glowfish> Quoth Donald Bruce Stewart, nevermore, > P.S. It might even be useful to have a tool, haskell-project, which > sets up all these files automatically. I was wondering about that just the other day. Is there such an application to interrogate the user about particulars and then create a fully compliant *.cabal file? D. -- Dougal Stanton Word attachments considered harmful. From dagit at codersbase.com Sun Nov 19 07:08:53 2006 From: dagit at codersbase.com (Jason Dagit) Date: Sun Nov 19 07:07:48 2006 Subject: [Haskell-cafe] Starting your own Haskell project: part 2 In-Reply-To: <20061119111009.GH22797@glowfish> References: <20061119044129.GA12107@cse.unsw.EDU.AU> <20061119111009.GH22797@glowfish> Message-ID: On 11/19/06, Dougal Stanton wrote: > Quoth Donald Bruce Stewart, nevermore, > > P.S. It might even be useful to have a tool, haskell-project, which > > sets up all these files automatically. > > I was wondering about that just the other day. Is there such an > application to interrogate the user about particulars and then create a > fully compliant *.cabal file? I'm unaware of such a tool, but as far as UIs go, it should be fairly straight forward. It would be nice to have both a text mode and a GUI version. This would make an excellent project for someone just starting in Haskell who wants to make life easier for everyone (a great way to get some fame in the community). I'm imagining the tool looks at your darcs repository, asks you a few questions and then generates a .cabal file. Considering that the basic cabal file is about 10 lines or less, not counting the list of source modules, it's almost not worth writing. On the other hand, even as simple as the .cabal files are I always have to copy an existing one or check the manual because I never can remember the exact syntax. Which is how I see this tool helping. Do we have any enthusiastic people to take this on? I bet you could have something usable in less than a days worth of hacking. Jason From ithika at gmail.com Sun Nov 19 07:34:35 2006 From: ithika at gmail.com (Dougal Stanton) Date: Sun Nov 19 07:31:35 2006 Subject: [Haskell-cafe] Starting your own Haskell project: part 2 In-Reply-To: References: <20061119044129.GA12107@cse.unsw.EDU.AU> <20061119111009.GH22797@glowfish> Message-ID: <20061119123435.GI22797@glowfish> Quoth Jason Dagit, nevermore, > Do we have any enthusiastic people to take this on? I bet you could > have something usable in less than a days worth of hacking. I'll give it a try. Of course I take this opportunity to solicit suggestions for a name for this application. Which is to say, what colour should my bike shed be? ;-) D. -- Dougal Stanton Word attachments considered harmful. From haskell at list.mightyreason.com Sun Nov 19 07:38:05 2006 From: haskell at list.mightyreason.com (Chris Kuklewicz) Date: Sun Nov 19 07:36:52 2006 Subject: [Haskell-cafe] Starting your own Haskell project: part 2 In-Reply-To: <20061119123435.GI22797@glowfish> References: <20061119044129.GA12107@cse.unsw.EDU.AU> <20061119111009.GH22797@glowfish> <20061119123435.GI22797@glowfish> Message-ID: <4560502D.5040601@list.mightyreason.com> Dougal Stanton wrote: > Quoth Jason Dagit, nevermore, >> Do we have any enthusiastic people to take this on? I bet you could >> have something usable in less than a days worth of hacking. > > I'll give it a try. Of course I take this opportunity to solicit > suggestions for a name for this application. Which is to say, what > colour should my bike shed be? ;-) > > D. JoinCabal From dons at cse.unsw.edu.au Sun Nov 19 07:54:03 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Sun Nov 19 07:52:59 2006 Subject: [Haskell-cafe] Starting your own Haskell project: part 2 In-Reply-To: References: <20061119044129.GA12107@cse.unsw.EDU.AU> <20061119111009.GH22797@glowfish> Message-ID: <20061119125403.GA14949@cse.unsw.EDU.AU> dagit: > On 11/19/06, Dougal Stanton wrote: > >Quoth Donald Bruce Stewart, nevermore, > >> P.S. It might even be useful to have a tool, haskell-project, which > >> sets up all these files automatically. > > > >I was wondering about that just the other day. Is there such an > >application to interrogate the user about particulars and then create a > >fully compliant *.cabal file? > > I'm unaware of such a tool, but as far as UIs go, it should be fairly Ok, done! darcs get http://www.cse.unsw.edu.au/~dons/code/mkcabal mkcabal creates a new project directory for an executable, populates with cabal files, setup.hs and a stub .hs file, based on the project name. A transcript: $ mkcabal Project name: haq Created new project directory: haq $ cd haq $ ls Haq.hs Setup.hs haq.cabal $ cat Haq.hs main :: IO () main = putStrLn "Hello, world!" $ cat Setup.hs #!/usr/bin/env runhaskell import Distribution.Simple $ cat haq.cabal Name: haq Version: 0.0 Description: Project description License: BSD3 License-file: LICENSE Author: Author Name Maintainer: user@email.address Build-Depends: base Executable: haq Main-is: Haq.hs $ c Configuring haq-0.0... ... $ b Preprocessing executables for haq-0.0... Building haq-0.0... [1 of 1] Compiling Main ( Haq.hs, /usr/obj/cabal/haq/haq-tmp/Main.o ) Linking /usr/obj/cabal/haq/haq ... And we're in business. We could be smarter and figure out more defaults, and generate some stub quickcheck and haddock details. We could also init and create the project in a darcs directory. Comments, suggestions *and patches* welcome! -- Don From dagit at codersbase.com Sun Nov 19 07:55:05 2006 From: dagit at codersbase.com (Jason Dagit) Date: Sun Nov 19 07:53:58 2006 Subject: [Haskell-cafe] Starting your own Haskell project: part 2 In-Reply-To: <20061119123435.GI22797@glowfish> References: <20061119044129.GA12107@cse.unsw.EDU.AU> <20061119111009.GH22797@glowfish> <20061119123435.GI22797@glowfish> Message-ID: On 11/19/06, Dougal Stanton wrote: > Quoth Jason Dagit, nevermore, > > Do we have any enthusiastic people to take this on? I bet you could > > have something usable in less than a days worth of hacking. > > I'll give it a try. Of course I take this opportunity to solicit > suggestions for a name for this application. Which is to say, what > colour should my bike shed be? ;-) Here is a list to draw ideas from: The Haskell Project Wizard (bit long but descriptive) Cabal Wizard darcs2cabal autoproj cabalize (the cabalizer?) The project butler repo nanny? bikeshedgen I'd say have fun with it :) And as Chris points out in a different email, team up with the cabal folks or at least plan to join them by the time you reach your first release. Jason From dons at cse.unsw.edu.au Sun Nov 19 08:32:10 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Sun Nov 19 08:31:07 2006 Subject: [Haskell-cafe] Starting your own Haskell project: part 2 In-Reply-To: <20061119125403.GA14949@cse.unsw.EDU.AU> References: <20061119044129.GA12107@cse.unsw.EDU.AU> <20061119111009.GH22797@glowfish> <20061119125403.GA14949@cse.unsw.EDU.AU> Message-ID: <20061119133210.GB14949@cse.unsw.EDU.AU> dons: > dagit: > > On 11/19/06, Dougal Stanton wrote: > > >Quoth Donald Bruce Stewart, nevermore, > > >> P.S. It might even be useful to have a tool, haskell-project, which > > >> sets up all these files automatically. > > > > > >I was wondering about that just the other day. Is there such an > > >application to interrogate the user about particulars and then create a > > >fully compliant *.cabal file? > > > > I'm unaware of such a tool, but as far as UIs go, it should be fairly > > Ok, done! > > darcs get http://www.cse.unsw.edu.au/~dons/code/mkcabal > > mkcabal creates a new project directory for an executable, populates > with cabal files, setup.hs and a stub .hs file, based on the project > name. Jason suggested that it should create just: Setup.hs foo.cabal by default. This is now what mkcabal does. So you can use it to generate stub .cabal files for existing projects. $ runhaskell mkcabal.hs Project name: x Created Setup.hs and x.cabal For entirely new projects, mkcabal --init-project creates an entire new project tree. $ runhaskell mkcabal.hs --init-project Project name: ruby-on-rails-killer Created new project directory: ruby-on-rails-killer $ ls ruby-on-rails-killer LICENSE Ruby-on-rails-killer.hs ruby-on-rails-killer.cabal README Setup.hs Further wishlists would be for the default to scan for src files to populate the .cabal file with, and to distinguish libraries from executables. Feedback welcome -- Don From ross at soi.city.ac.uk Sun Nov 19 09:20:37 2006 From: ross at soi.city.ac.uk (Ross Paterson) Date: Sun Nov 19 09:19:40 2006 Subject: [Haskell-cafe] Starting your own Haskell project: part 2 In-Reply-To: <20061119044129.GA12107@cse.unsw.EDU.AU> References: <20061119044129.GA12107@cse.unsw.EDU.AU> Message-ID: <20061119142037.GA7583@soi.city.ac.uk> On Sun, Nov 19, 2006 at 03:41:29PM +1100, Donald Bruce Stewart wrote: > http://haskell.org/haskellwiki/How_to_write_a_Haskell_program > > Feedback welcome! There is inconsistent advice regarding Setup.hs/Setup.lhs. (#! in .hs files seems to be a feature of GHC Haskell.) For releases, another possibility is Cabal's sdist feature. This will do a bit more checking, and ensure that the tarball has the structure expected by HackageDB. In the example project, you'd want to add extra-source-files: Tests.hs to make this work. Regarding hosting, I don't think that darcs.haskell.org is the preferred solution (unfortunately nor is anything else). Regarding publicity, another possibility is HackageDB, even if it's not fully working yet (http://hackage.haskell.org/trac/hackage). From mail at joachim-breitner.de Sun Nov 19 09:50:25 2006 From: mail at joachim-breitner.de (Joachim Breitner) Date: Sun Nov 19 09:49:37 2006 Subject: [Haskell-cafe] Starting your own Haskell project: part 2 In-Reply-To: <20061119133210.GB14949@cse.unsw.EDU.AU> References: <20061119044129.GA12107@cse.unsw.EDU.AU> <20061119111009.GH22797@glowfish> <20061119125403.GA14949@cse.unsw.EDU.AU> <20061119133210.GB14949@cse.unsw.EDU.AU> Message-ID: <1163947825.4163.8.camel@otto.ehbuehl.net> Hi, Am Montag, den 20.11.2006, 00:32 +1100 schrieb Donald Bruce Stewart: > For entirely new projects, mkcabal --init-project > creates an entire new project tree. > > $ runhaskell mkcabal.hs --init-project > Project name: ruby-on-rails-killer > Created new project directory: ruby-on-rails-killer > > $ ls ruby-on-rails-killer > LICENSE Ruby-on-rails-killer.hs > ruby-on-rails-killer.cabal > README Setup.hs Where can I find ruby-on-rails-killer? Joachim (SCNR) -- Joachim Breitner e-Mail: mail@joachim-breitner.de Homepage: http://www.joachim-breitner.de ICQ#: 74513189 From ithika at gmail.com Sun Nov 19 12:16:32 2006 From: ithika at gmail.com (Dougal Stanton) Date: Sun Nov 19 12:13:40 2006 Subject: [Haskell-cafe] Starting your own Haskell project: part 2 In-Reply-To: <20061119125403.GA14949@cse.unsw.EDU.AU> References: <20061119044129.GA12107@cse.unsw.EDU.AU> <20061119111009.GH22797@glowfish> <20061119125403.GA14949@cse.unsw.EDU.AU> Message-ID: <20061119171632.GJ22797@glowfish> Quoth Donald Bruce Stewart, nevermore, > Ok, done! Hehe, you can't leave this community alone for a second... Oh well, that'll teach me to volunteer for something and then take a few hours away from the computer! ;-) D. From szefirov at ot.ru Sun Nov 19 14:14:33 2006 From: szefirov at ot.ru (szefirov@ot.ru) Date: Sun Nov 19 14:13:39 2006 Subject: [Haskell-cafe] jhc, whole program optimizing compiler. Message-ID: <4560AD19.9030306@ot.ru> Do anyone had any experience with JHC? I tried to install it second time and again get an error during library build. It's a pity, we need a speed in our very lazy code. ;) From benjamin.franksen at bessy.de Sun Nov 19 14:35:48 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Sun Nov 19 14:35:03 2006 Subject: [Haskell-cafe] Re: jhc, whole program optimizing compiler. References: <4560AD19.9030306@ot.ru> Message-ID: szefirov@ot.ru wrote: > Do anyone had any experience with JHC? > > I tried to install it second time and again get an error during library > build. > > It's a pity, we need a speed in our very lazy code. ;) I had the same problem and asked John. He explained why and told me how to proceed: > that is most likely because the format of the 'ho' and 'hl' files > changed recently. you will need to delete all old versions with 'make > clean-ho' and rm *.hl to get rid of them. I think the pre-compiled > libraries on the site are up to date if you want to get those. HTH Ben From bulat.ziganshin at gmail.com Sun Nov 19 12:27:25 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sun Nov 19 15:24:28 2006 Subject: [Haskell-cafe] Starting your own Haskell project: part 2 In-Reply-To: <20061119111009.GH22797@glowfish> References: <20061119044129.GA12107@cse.unsw.EDU.AU> <20061119111009.GH22797@glowfish> Message-ID: <1715170430.20061119202725@gmail.com> Hello Dougal, Sunday, November 19, 2006, 2:10:09 PM, you wrote: >> P.S. It might even be useful to have a tool, haskell-project, which >> sets up all these files automatically. > I was wondering about that just the other day. Is there such an > application to interrogate the user about particulars and then create a > fully compliant *.cabal file? Haskell killer app implementing point-and-shoot programming paradigm :) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Sun Nov 19 12:29:36 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sun Nov 19 15:24:34 2006 Subject: [Haskell-cafe] Starting your own Haskell project: part 2 In-Reply-To: References: <20061119044129.GA12107@cse.unsw.EDU.AU> <20061119111009.GH22797@glowfish> Message-ID: <07224757.20061119202936@gmail.com> Hello Jason, Sunday, November 19, 2006, 3:08:53 PM, you wrote: > great way to get some fame in the community). I'm imagining the tool > looks at your darcs repository, asks you a few questions and then > generates a .cabal file. and another one which looks at the cabal file and generates darcs repository. and both should lazily consume its input data to allow true beginners create both files in mutual recursive way :) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Sun Nov 19 12:46:39 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sun Nov 19 15:24:41 2006 Subject: [Haskell-cafe] Starting your own Haskell project: part 2 In-Reply-To: <20061119133210.GB14949@cse.unsw.EDU.AU> References: <20061119044129.GA12107@cse.unsw.EDU.AU> <20061119111009.GH22797@glowfish> <20061119125403.GA14949@cse.unsw.EDU.AU> <20061119133210.GB14949@cse.unsw.EDU.AU> Message-ID: <443548870.20061119204639@gmail.com> Hello Donald, Sunday, November 19, 2006, 4:32:10 PM, you wrote: > For entirely new projects, mkcabal --init-project > creates an entire new project tree. > $ runhaskell mkcabal.hs --init-project i think it should be asked instead of using option. and in general it will be better to split this program into the worker/driver parts. we will have many drivers which asks users (using stdio, curses, GUI) and then cmdline-driven worker will be invoked to do the real work. worker can also be used by other automation tools -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Sun Nov 19 12:51:22 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sun Nov 19 15:24:48 2006 Subject: [Haskell-cafe] Starting your own Haskell project: part 2 In-Reply-To: References: <20061119044129.GA12107@cse.unsw.EDU.AU> <20061119111009.GH22797@glowfish> <20061119123435.GI22797@glowfish> Message-ID: <1425700849.20061119205122@gmail.com> Hello Jason, Sunday, November 19, 2006, 3:55:05 PM, you wrote: >> I'll give it a try. Of course I take this opportunity to solicit >> suggestions for a name for this application. Which is to say, what >> colour should my bike shed be? ;-) > I'd say have fun with it :) me, me too! :) HelloHaskell HsInit AAAAA MenuFileNew CabalSecretary NewToHaskell? HaskellNewbie ProjectGenerator -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From newsham at lava.net Sun Nov 19 15:53:57 2006 From: newsham at lava.net (Tim Newsham) Date: Sun Nov 19 15:52:50 2006 Subject: [Haskell-cafe] Arrows tutorial Message-ID: Small arrows tutorial (sorta, I'm learning myself and trying to doc as I go): http://www.thenewsh.com/~newsham/x/arrow.txt comments welcome. I ran into a type issue I couldnt resolve. I'd love any comments on that (documented near the bottom, liftA2'). Also, I'd like to put some info about ghci -farrows syntax when I figure that stuff out. If anyone feels like translating some examples into do-notation or coming up with new examples that showcase do-notation, please post em or send them to me. Tim Newsham http://www.thenewsh.com/~newsham/ From alistair at abayley.org Sun Nov 19 16:24:53 2006 From: alistair at abayley.org (Alistair Bayley) Date: Sun Nov 19 16:23:43 2006 Subject: [Haskell-cafe] importing Distribution.Compat.FilePath fails In-Reply-To: <20061118184844.GA2683@die.therning.org> References: <20061118184844.GA2683@die.therning.org> Message-ID: <79d7c4980611191324sfcfd2c3u38daaac17f08cfc3@mail.gmail.com> On 18/11/06, Magnus Therning wrote: > Could not find module `Distribution.Compat.FilePath': > it is hidden (in package Cabal-1.1.6) > > I want to use 'joinFileName'. Try upgrading to 1.1.6.1. This explains why: http://www.haskell.org/pipermail/libraries/2006-October/005996.html Alistair From ndmitchell at gmail.com Sun Nov 19 17:03:27 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Sun Nov 19 17:02:23 2006 Subject: [Haskell-cafe] Arrows tutorial In-Reply-To: References: Message-ID: <404396ef0611191403g793c92e0y871c73cfb503c7c4@mail.gmail.com> Hi > Small arrows tutorial (sorta, I'm learning myself and trying to doc > as I go): > > http://www.thenewsh.com/~newsham/x/arrow.txt Why not shove it on the wiki? Then everyone can find it, improve it, and treasure it forever more. Thanks Neil From newsham at lava.net Sun Nov 19 18:52:36 2006 From: newsham at lava.net (Tim Newsham) Date: Sun Nov 19 18:51:30 2006 Subject: [Haskell-cafe] Arrows tutorial In-Reply-To: <404396ef0611191403g793c92e0y871c73cfb503c7c4@mail.gmail.com> References: <404396ef0611191403g793c92e0y871c73cfb503c7c4@mail.gmail.com> Message-ID: >> http://www.thenewsh.com/~newsham/x/arrow.txt > Why not shove it on the wiki? Then everyone can find it, improve it, > and treasure it forever more. Its now fair game. Thanks for the help, Neil. http://www.haskell.org/haskellwiki/Arrow_tutorial > Neil Tim Newsham http://www.thenewsh.com/~newsham/ From jim at sdf-eu.org Sun Nov 19 19:13:30 2006 From: jim at sdf-eu.org (jim burton) Date: Sun Nov 19 19:12:24 2006 Subject: [Haskell-cafe] ghci stack overflow Message-ID: <7435185.post@talk.nabble.com> This code produces a stack overflow in ghci when I call `makeSpiral' with large values, e.g. big enough to produce a 1001x1001 spiral. (makeSpiral produces a list of lists which form a clockwise 'spiral', it's a puzzle from mathschallenge.net.) I'm sure there is a way to increase the stack space in ghc which I will look into, but is there a way I could avoid the problem in the first place by attacking the problem differently? Does stack space run out because the list is an argument being passed around (1001x1001 versions of it)? If so would the state monad help me? data Dir = R | D | L | U deriving (Show, Eq, Enum) type Spiral = ([[Int]], Int, Dir) -- (rows, current row, next direction) rows :: Spiral -> [[Int]] rows (rs, i, d) = rs currentrow :: Spiral -> Int currentrow (rs, i, d) = i nextdir :: Spiral -> Dir nextdir (rs, i, d) = d getrow :: Int -> [[Int]] -> Maybe [Int] getrow i sp = if i < 0 || i >= length sp then Nothing else Just (sp!!i) ndir :: Dir -> Dir ndir d = if d == U then R else succ d newsp :: Spiral newsp = ([[1]], 0, R) makeSpiral :: Int -> Spiral makeSpiral i = makeSpiral' 2 newsp where makeSpiral' j sp = if j > i then sp else makeSpiral' (j+1) (update j sp) update :: Int -> Spiral -> Spiral update i (sp, cr, d) = (sp', cr', d') where oldrow = if (d == U && cr' == cr && cr == 0) || (d == D && cr' == length sp) then [] else fromJust $ getrow cr' sp cr' | d == L || d == R = cr | d == U = if cr == 0 then 0 else cr-1 | otherwise = cr+1 cr'' = if d == U && cr == 0 then -1 else cr' sp' = insertrow cr'' newrow sp newrow = case d of R -> oldrow++[i] D -> oldrow++[i] L -> i:oldrow U -> i:oldrow d' | d == R || d == L = if length oldrow == maximum (map length sp) then ndir d else d | d == U = if cr'' == -1 then ndir d else d | otherwise = if cr' == length sp then ndir d else d insertrow :: Int -> [Int] -> [[Int]] -> [[Int]] insertrow i r rs = if i == -1 then r:rs else front++[r]++back where (front, rest) = splitAt i rs back = if null rest then [] else tail rest printSpiral :: Spiral -> IO () printSpiral (sp, i, d) = putStrLn (concat $ intersperse "\n" (map show sp)) sumdiags :: Spiral -> Int sumdiags (sp, i, d) = (sumdiags' 0 0 (+1)) + (sumdiags' 0 end (subtract 1)) - centre where row1 = sp!!0 end = length row1 - 1 halfx = (length row1 `div` 2) halfy = (length sp `div` 2) centre = (sp!!halfy)!!halfx sumdiags' row col f = if row == length sp then 0 else (sp!!row)!!col + sumdiags' (row+1) (f col) f -- View this message in context: http://www.nabble.com/ghci-stack-overflow-tf2666036.html#a7435185 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From ttmrichter at gmail.com Mon Nov 20 02:27:31 2006 From: ttmrichter at gmail.com (Michael T. Richter) Date: Mon Nov 20 02:26:39 2006 Subject: [Haskell-cafe] LLVM back end Message-ID: <1164007651.6196.14.camel@localhost.localdomain> Skipped content of type multipart/alternative-------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 191 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061120/b4614df4/attachment.bin From evilantleredthing at yahoo.ca Mon Nov 20 02:44:56 2006 From: evilantleredthing at yahoo.ca (chris moline) Date: Mon Nov 20 02:43:47 2006 Subject: [Haskell-cafe] Yet more type confusion Message-ID: <472825.97906.qm@web57205.mail.re3.yahoo.com> Hey all, I'm thoroughly confused by the type error produced by the following: applies a fun returning a tuple of lists to a list of values and then repeatedly applies it to the snd of the result, returning a list of the fst's of successive applications > iterT :: ([a] -> ([a], [a])) -> [a] -> [[a]] > iterT f a = let (b, c) = f a in b : iterT f c like break, but drops the separator > breakDrop :: (a -> Bool) -> [a] -> ([a], [a]) > breakDrop p l = (takeWhile (not . p) l, drop 1 $ dropWhile (not . p) l) like break, but returns a list of lists of values separated by the separator > sep :: (a -> Bool) -> [a] -> [[a]] > sep p = takeWhile (/= "") . iterT (breakDrop p) > main = print $ sep (== 1) "" compling with ghc --make returns this: test.hs:14:45: Couldn't match the rigid variable `a' against `Char' `a' is bound by the type signature for `sep' Expected type: Char -> Bool Inferred type: a -> Bool In the first argument of `breakDrop', namely `p' In the first argument of `iterT', namely `(breakDrop p)' Setting the type signature of sep to (Char -> Bool) -> [Char] -> [[Char]] fixes the problem but I don't get why the signature isn't as general as I think it should be. Something to do with defaulting perhaps? __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From dan.doel at gmail.com Mon Nov 20 03:05:01 2006 From: dan.doel at gmail.com (Dan Doel) Date: Mon Nov 20 03:03:56 2006 Subject: [Haskell-cafe] Yet more type confusion In-Reply-To: <472825.97906.qm@web57205.mail.re3.yahoo.com> References: <472825.97906.qm@web57205.mail.re3.yahoo.com> Message-ID: <200611200305.01619.dan.doel@gmail.com> On Monday 20 November 2006 02:44, chris moline wrote: > > sep :: (a -> Bool) -> [a] -> [[a]] > > sep p = takeWhile (/= "") . iterT (breakDrop p) > Setting the type signature of sep to (Char -> Bool) -> > [Char] -> [[Char]] fixes the problem but I don't get > why the signature isn't as general as I think it > should be. Something to do with defaulting perhaps? The problem is (I believe) 'takeWhile (/= "")'. That's a string, which causes everything to be specialized to Char. You want 'takeWhile (not . null)'. -- Dan From dm.maillists at gmail.com Mon Nov 20 03:14:49 2006 From: dm.maillists at gmail.com (Daniel McAllansmith) Date: Mon Nov 20 03:12:41 2006 Subject: [Haskell-cafe] Yet more type confusion In-Reply-To: <472825.97906.qm@web57205.mail.re3.yahoo.com> References: <472825.97906.qm@web57205.mail.re3.yahoo.com> Message-ID: <200611202114.49558.dm.maillists@gmail.com> On Monday 20 November 2006 20:44, chris moline wrote: > Hey all, I'm thoroughly confused by the type error > produced by the following: > > sep :: (a -> Bool) -> [a] -> [[a]] > > sep p = takeWhile (/= "") . iterT (breakDrop p) It'll be the "" in (/= ""). Maybe you want to be using (/= []) ? That will work for any type a in the Eq class. Daniel From kenneth.hoste at ugent.be Mon Nov 20 03:29:16 2006 From: kenneth.hoste at ugent.be (Kenneth Hoste) Date: Mon Nov 20 03:28:28 2006 Subject: [Haskell-cafe] LLVM back end In-Reply-To: <1164007651.6196.14.camel@localhost.localdomain> References: <1164007651.6196.14.camel@localhost.localdomain> Message-ID: <4EF4EC8D-019C-41EA-9B5B-4A6AE8707545@elis.ugent.be> On 20 Nov 2006, at 08:27, Michael T. Richter wrote: > I've been eyeing LLVM[1] as interesting technology -- brief > executive summary: a virtual machine suited as the back end of > compiler output with optimised native code then coming from it as > either JIT-based execution of the LLVM bytecode or as a further > compilation step -- and couldn't help but immediately think of the > possibility of one of the Haskell compiler projects providing an > LLVM code generator. I think this would help in several areas: > it could make porting the compiler to other architectures -- > including oddball ones that would be too small to otherwise support > -- easier; > it could help remove the nigh-ubiquitous reliance upon GCC as a > back-end (while I think that GCC is a pretty good piece of > software, I'm not sure it's really suited to its current role as > the "do-everything" back end); > it could leverage some of the really interesting work that's going > on in optimisation technology by letting one VM's optimiser do the > work for any number of languages; > it could improve interaction between source code written in > multiple languages. > > Is this me opening up a Pandora's Box of ignorance here? Or is > LLVM potentially interesting? (And were someone motivated into > perhaps trying to make an LLVM back-end, where would one start to > poke around in, say, the GHC codebase to even begin to implement > this? And how insane would they be driven by the process?) I've been looking at LLVM for a while too now, for research purposes. And one of the big downsides (at least for me), is the lack of a real simulator which mimicks the virtual machine. They do have a JIT compiler which allows you to execute LLVM bytecode on a number of platforms, but I'm interested in analyzing the dynamic behaviour of the LLVM bytecode, and JIT'ing doesn''t allow that. They also have an interpreter, which is probably quite similar to a simulator, but that's just horrible slow because of the SSA (hence, no registers) system used. To get to the point: I think Haskell might be a great candidate for building an LLVM bytecode simulator. I have been thinking about it, but because of my lack of coding experience (and understanding of Monads), I haven't started a project yet. If some people would be interested in such a thing though, we might join to make this a succes. I'm not LLVM expert, and surely no Haskell expert either, but I think such a project can be pretty interesting. greetings, Kenneth -- Statistics are like a bikini. What they reveal is suggestive, but what they conceal is vital (Aaron Levenstein) Kenneth Hoste ELIS - Ghent University kenneth.hoste@elis.ugent.be http://www.elis.ugent.be/~kehoste From magnus at therning.org Mon Nov 20 03:42:09 2006 From: magnus at therning.org (Magnus Therning) Date: Mon Nov 20 03:41:08 2006 Subject: [Haskell-cafe] importing Distribution.Compat.FilePath fails In-Reply-To: <79d7c4980611191324sfcfd2c3u38daaac17f08cfc3@mail.gmail.com> References: <20061118184844.GA2683@die.therning.org> <79d7c4980611191324sfcfd2c3u38daaac17f08cfc3@mail.gmail.com> Message-ID: <20061120084209.GB2392@die.therning.org> On Sun, Nov 19, 2006 at 21:24:53 +0000, Alistair Bayley wrote: >On 18/11/06, Magnus Therning wrote: >> Could not find module `Distribution.Compat.FilePath': >> it is hidden (in package Cabal-1.1.6) >> >>I want to use 'joinFileName'. > >Try upgrading to 1.1.6.1. This explains why: >http://www.haskell.org/pipermail/libraries/2006-October/005996.html The official FilePath they mention, is that Neil Mitchell's module (mentioned earlier in this thread)? I'm not looking to use it in a Setup.hs :-) /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus Software is not manufactured, it is something you write and publish. Keep Europe free from software patents, we do not want censorship by patent law on written works. If our ideas of intellectual property are wrong, we must change them, improve them and return them to their original purpose. When intellectual property rules diminish the supply of new ideas, they steal from all of us. -- Andrew Brown, November 19, 2005, The Guardian -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061120/1fe27bc2/attachment.bin From simonpj at microsoft.com Mon Nov 20 03:50:40 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Mon Nov 20 03:49:40 2006 Subject: [Haskell-cafe] Wiki page for rewrite rules tips, types and tricks In-Reply-To: <20061118052734.GE10581@cse.unsw.EDU.AU> References: <20061118052734.GE10581@cse.unsw.EDU.AU> Message-ID: Don | After suggesting solutions based on rewrite rules to three different | questions this week, I though maybe we better have a wiki page on using | rewrite rules for non-traditional ad-hoc tricks. | | http://haskell.org/haskellwiki/Playing_by_the_rules Great stuff. Would it be possible to combine it with http://haskell.org/haskellwiki/GHC/Using_Rules which is linked from http://haskell.org/haskellwiki/GHC It seems a pity to have two pages with the same purpose! (Mind you, obviously the former is not easily findable. Perhaps we could improve that?) Simon | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of | Donald Bruce Stewart | Sent: 18 November 2006 05:28 | To: haskell-cafe@haskell.org | Subject: [Haskell-cafe] Wiki page for rewrite rules tips, types and tricks | | After suggesting solutions based on rewrite rules to three different | questions this week, I though maybe we better have a wiki page on using | rewrite rules for non-traditional ad-hoc tricks. | | http://haskell.org/haskellwiki/Playing_by_the_rules | | If you've used rewrite rules for something fun (other than implementing | a major deforestation system), please add it to the page. | | -- Don | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe From cgibbard at gmail.com Mon Nov 20 05:51:02 2006 From: cgibbard at gmail.com (Cale Gibbard) Date: Mon Nov 20 05:49:53 2006 Subject: [Haskell-cafe] Yet more type confusion In-Reply-To: <200611202114.49558.dm.maillists@gmail.com> References: <472825.97906.qm@web57205.mail.re3.yahoo.com> <200611202114.49558.dm.maillists@gmail.com> Message-ID: <89ca3d1f0611200251q28038b77wf66ed39c873d9c47@mail.gmail.com> Never use (/= "") or (/= []), use (not . null), which doesn't have the Eq constraint. On 20/11/06, Daniel McAllansmith wrote: > On Monday 20 November 2006 20:44, chris moline wrote: > > Hey all, I'm thoroughly confused by the type error > > produced by the following: > > > sep :: (a -> Bool) -> [a] -> [[a]] > > > sep p = takeWhile (/= "") . iterT (breakDrop p) > > It'll be the "" in (/= ""). > > Maybe you want to be using (/= []) ? > That will work for any type a in the Eq class. > > Daniel > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From lemming at henning-thielemann.de Mon Nov 20 08:13:30 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Mon Nov 20 08:16:47 2006 Subject: [Haskell-cafe] Collection of objects? In-Reply-To: <20061117185343.GF14168@localhost.localdomain> References: <455DF31E.5000606@ijs.si> <36CBE334-FE91-4198-BA3B-1247E163FE39@fastmail.fm> <20061117185343.GF14168@localhost.localdomain> Message-ID: On Fri, 17 Nov 2006, Matthias Fischmann wrote: > i have cut-and-pasted the last few postings into the wiki: > > http://haskell.org/haskellwiki/Heterogenous_collections > > it'is very ad hoc, but i hope it helps those who bump into it a > little. and it's easier to edit and improve than a mailing list > thread. (-: Thanks a lot for setting it up! Maybe there should be a FAQ category? This page would certainly belong to it. From ndmitchell at gmail.com Mon Nov 20 08:23:34 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Mon Nov 20 08:22:27 2006 Subject: [Haskell-cafe] importing Distribution.Compat.FilePath fails In-Reply-To: <20061120084209.GB2392@die.therning.org> References: <20061118184844.GA2683@die.therning.org> <79d7c4980611191324sfcfd2c3u38daaac17f08cfc3@mail.gmail.com> <20061120084209.GB2392@die.therning.org> Message-ID: <404396ef0611200523i145a0543y40ae9d837eca38b2@mail.gmail.com> Hi > The official FilePath they mention, is that Neil Mitchell's module > (mentioned earlier in this thread)? There is the Cabal FilePath library, by Lemmih, which is bundled with Cabal. Cabal is not really the place to put a FilePath library, so I took it out, merged it with a library I wrote for Yhc, took some ideas out of other places as well and put together a new FilePath library. It is my intention to try and get this FilePath library into the base, a process which I'll probably be starting next week. I would recommend you use my FilePath library, and have a nice easy upgrade to just importing FilePath directly sometime in the future. Thanks Neil From fis at wiwi.hu-berlin.de Mon Nov 20 08:32:17 2006 From: fis at wiwi.hu-berlin.de (Matthias Fischmann) Date: Mon Nov 20 08:32:05 2006 Subject: [Haskell-cafe] Collection of objects? In-Reply-To: References: <455DF31E.5000606@ijs.si> <36CBE334-FE91-4198-BA3B-1247E163FE39@fastmail.fm> <20061117185343.GF14168@localhost.localdomain> Message-ID: <20061120133217.GF14168@localhost.localdomain> On Mon, Nov 20, 2006 at 02:13:30PM +0100, Henning Thielemann wrote: > To: Matthias Fischmann > Cc: haskell-cafe@haskell.org > From: Henning Thielemann > Date: Mon, 20 Nov 2006 14:13:30 +0100 (CET) > Subject: Re: [Haskell-cafe] Collection of objects? > > > On Fri, 17 Nov 2006, Matthias Fischmann wrote: > > > i have cut-and-pasted the last few postings into the wiki: > > > > http://haskell.org/haskellwiki/Heterogenous_collections > > > > it'is very ad hoc, but i hope it helps those who bump into it a > > little. and it's easier to edit and improve than a mailing list > > thread. (-: > > Thanks a lot for setting it up! > > Maybe there should be a FAQ category? This page would certainly belong to > it. Sure, makes sense to me. (Not that it has to. ;) I just haven't done it because I don't know very much about wiki categories. I am also currently a little distracted. But hey, it's wiki! By all means do stuff to it. cheers, matthias -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061120/43b30009/attachment.bin From daniel.is.fischer at web.de Mon Nov 20 10:37:06 2006 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Mon Nov 20 10:52:49 2006 Subject: [Haskell-cafe] ghci stack overflow In-Reply-To: <7435185.post@talk.nabble.com> References: <7435185.post@talk.nabble.com> Message-ID: <200611201637.06961.daniel.is.fischer@web.de> Hi Jim, Am Montag, 20. November 2006 01:13 schrieb jim burton: > This code produces a stack overflow in ghci when I call `makeSpiral' with > large values, e.g. big enough to produce a 1001x1001 spiral. (makeSpiral > produces a list of lists which form a clockwise 'spiral', it's a puzzle > from mathschallenge.net.) Problem 28 of Project Euler, I believe? If you stick to that approach for problem 58, you'll have trouble again. > > I'm sure there is a way to increase the stack space in ghc which I will > look into, but is there a way I could avoid the problem in the first place > by attacking the problem differently? Definitely. Just take a pen and a piece of paper and figure out which numbers appear in the corners of a (2m+1)x(2m+1) spiral (write those numbers in terms of m), prove the correctness of your result via induction and you'll be done (it'll be certainly helpful to know the formulae for sum [n^k | n <- [1 .. bound]] for small exponents k). > Does stack space run out because the > list is an argument being passed around (1001x1001 versions of it)? If so > would the state monad help me? I think the stack overflow is due to creating a lot of thunks, possibly strictness could help, but you'd still use a fat lot of memory for keeping the whole spiral (1001 lists of length 1001 will need roughly 4MB just for the Ints, plus list-overhead..., probably you'd be better off if you used a mutable unboxed array, say spiral :: UArray (Int,Int) Int spiral = runSTUArray ( do sp <- newArray ((-500,-500),(500,500)) 0 fill your array here return sp) ) but even that would need a _huge_ memory for problem 58. HTH, Daniel > > data Dir = R | D | L | U deriving (Show, Eq, Enum) > type Spiral = ([[Int]], Int, Dir) -- (rows, current row, next direction) > > rows :: Spiral -> [[Int]] > rows (rs, i, d) = rs > currentrow :: Spiral -> Int > currentrow (rs, i, d) = i > nextdir :: Spiral -> Dir > nextdir (rs, i, d) = d > > getrow :: Int -> [[Int]] -> Maybe [Int] > getrow i sp = if i < 0 || i >= length sp then Nothing else Just (sp!!i) > > ndir :: Dir -> Dir > ndir d = if d == U then R else succ d > > newsp :: Spiral > newsp = ([[1]], 0, R) > > makeSpiral :: Int -> Spiral > makeSpiral i = makeSpiral' 2 newsp > where makeSpiral' j sp = if j > i > then sp > else makeSpiral' (j+1) (update j sp) > > update :: Int -> Spiral -> Spiral > update i (sp, cr, d) = (sp', cr', d') > where oldrow = if (d == U && cr' == cr && cr == 0) || > (d == D && cr' == length sp) > then [] > else fromJust $ getrow cr' sp > cr' | d == L || d == R = cr > > | d == U = if cr == 0 then 0 else cr-1 > | otherwise = cr+1 > > cr'' = if d == U && cr == 0 then -1 else cr' > sp' = insertrow cr'' newrow sp > newrow = case d of > R -> oldrow++[i] > D -> oldrow++[i] > L -> i:oldrow > U -> i:oldrow > d' | d == R || d == L = if length oldrow == maximum (map length > sp) > then ndir d > else d > > | d == U = if cr'' == -1 then ndir d else d > | otherwise = if cr' == length sp then ndir d else d > > insertrow :: Int -> [Int] -> [[Int]] -> [[Int]] > insertrow i r rs = if i == -1 then r:rs else front++[r]++back > where (front, rest) = splitAt i rs > back = if null rest then [] else tail rest > > printSpiral :: Spiral -> IO () > printSpiral (sp, i, d) = putStrLn (concat $ intersperse "\n" (map show sp)) > > sumdiags :: Spiral -> Int > sumdiags (sp, i, d) = (sumdiags' 0 0 (+1)) + (sumdiags' 0 end (subtract 1)) > - centre > where row1 = sp!!0 > end = length row1 - 1 > halfx = (length row1 `div` 2) > halfy = (length sp `div` 2) > centre = (sp!!halfy)!!halfx > sumdiags' row col f = if row == length sp > then 0 > else (sp!!row)!!col + sumdiags' (row+1) (f > col) f From mark at ixod.org Mon Nov 20 11:31:27 2006 From: mark at ixod.org (Mark T.B. Carroll) Date: Mon Nov 20 11:30:05 2006 Subject: [Haskell-cafe] Interoperating with Java Message-ID: <87ac2mulk0.fsf@ixod.org> I was wondering, what's the status of the various means of two-way interoperation with Java? Are things actively maintained? According to the WWW, HaskellDirect's (I have Lambada in mind) current version was released Jan 2004 and compiles with 'recent' versions of GHC, such as ghc-6.2, and the latest released JVM Bridge isn't much newer. We were looking at using the Standard Widget Toolkit (SWT) but don't want to rely on driving it from Haskell if the connectors are going to rot away. (We could still use FP, after all - e.g. Scheme's Kawa and Bigloo have good Java interoperation.) -- Mark From apfelmus at quantentunnel.de Mon Nov 20 11:34:24 2006 From: apfelmus at quantentunnel.de (apfelmus@quantentunnel.de) Date: Mon Nov 20 11:36:57 2006 Subject: [Haskell-cafe] Re: Friday Afternoon Play: The Burrows Wheeler Transformation In-Reply-To: References: Message-ID: Hello J?n, sadly, nobody wants to play with you. Most likely, it's because the next move is too hard: for a faster forward transform, you need (something as tricky as) suffix trees. See also Robert Giegerich, Stefan Kurtz: "A Comparison of Imperative and Purely Functional Suffix Tree Constructions" http://citeseer.ist.psu.edu/giegerich95comparison.html Regards, apfelmus J?n Fairbairn wrote: > So, it's Friday afternoon (well, here anyway), and > presumably everyone is thinking of leaving for the > weekend. Is anyone interested in playing a little game? I'm > going to make the first move, and then just wait and see if > anyone makes the next. I'm certainly not promising to make > any further moves myself, but I'm not promising I won't, > either. > > Below you'll see a na?ve implementation of the Burrows > Wheeler transformation and its inverse. That's my > move. (And don't complain too much about style and such -- > I'm half asleep.) Further moves are made by transforming > the programme so that it becomes more efficient. The first > target is not raw speed, but to adjust it until the > computational complexity gets to be what it should be. I'm > hoping for elegant moves here. After that, folk might start > replacing the lists with more efficient datastructures and > so on, but still /elegantly/. > > The object of the game isn't ultimate speed -- I've no > particular wish to see a Haskell version that's as fast as a > good C version, especially not if it ends up /looking/ like > a C version. Really the objective is to think about Haskell > programming -- and probably come up with some observations > such as "there really ought to be a class of indexable > structures, so that we don't have to change (!!) to (!) all > over the place". And to have fun, anyhow... > > * * * > > Demonstration of the principle of the Burrows Wheeler > transform. The implementations are simplistic (and have > worse complexity than is possible). > >> module Burrows_Wheeler_Transform where >> import List > > This is surely the wrong module to have to find (><) from: > >> import Data.Graph.Inductive.Query.Monad((><)) > > The forward transformation. Input a list, output the > transformed list and possibly an int (Nothing if there were > no elements in the input -- perhaps the result type should > be Maybe (NonEmptyList t,Int)) > >> slow_bwt:: Ord t => [t] -> ([t], Maybe Int) > > This version works by computing a list of all the rotations > of the input and sorting it. The transformation is then the > last element of each line of the sorted rotations. Tag the > data with an index so that it's possible to find where the > original form of the unput ends up after sorting. This is > essentially the specification of the transform coded up > directly. > >> slow_bwt l >> = (map fst tagged_bwt, index_of_original) >> where tagged_bwt = map (last>> $ sort >> $ rotations l`zip`[0..] >> index_of_original = findIndex ((==0).snd) tagged_bwt > > that looks like worst case n??log n to me (where n is the > length of the string): if every element is the same, the > n?log n comparisons the sort does will each look at every > element, and that's really more than is necessary. > > > > The inverse transform. We should have that > > @ > slow_inv_bwt . slow_bwt == id > @ > > Observe that sorting the input gives the first column of the > sorted rotations (and the input is the last). So after one > sort we have > > X ... c > Y ... b > Z ... a > .. . . > .. . . > .. . . > > > Since they are rotations, rotating each row of this gives > pairs that belong to the original list: > > cX ... > by ... > aZ ... > .. . > .. . > .. . > > sorting these gives us the first two columns of the sorted > rotations, and again we already know the last column, which > can be rotated into the first and so on. > >> slow_inv_bwt ([],_) = [] >> slow_inv_bwt (l,Just index_of_original) >> = iterate catsort (replicate len []) > > After (length input) iterations we have the original sorted > rotations, > >> !! len > > and we have the index of where the untransformed string is, > so we can just pick it back out. > >> !! index_of_original > >> where catsort s = sort $ map (uncurry (:)) $ l `zip`s >> len = length l > > > This version does rather fewer sorts: > >> mark2_inv_bwt ([],_) = [] >> mark2_inv_bwt (l,Just n) >> = (transpose $ take (length l) $ iterate (permuteWith perm) l)!!(perm!!n) >> where perm = map snd $ sort $ l `zip` [0..] > > Should I simply have left it out and hoped that it would > turn up after a few moves? I'm not going to explain it, > anyway. > >> rotations l = init $ zipWith (++) (tails l) (inits l) > >> permuteWith ns l = map (l!!) ns From lemming at henning-thielemann.de Mon Nov 20 11:52:22 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Mon Nov 20 11:52:06 2006 Subject: [Haskell-cafe] Interoperating with Java In-Reply-To: <87ac2mulk0.fsf@ixod.org> References: <87ac2mulk0.fsf@ixod.org> Message-ID: On Mon, 20 Nov 2006, Mark T.B. Carroll wrote: > I was wondering, what's the status of the various means of two-way > interoperation with Java? Are things actively maintained? According to > the WWW, HaskellDirect's (I have Lambada in mind) current version was > released Jan 2004 and compiles with 'recent' versions of GHC, such as > ghc-6.2, and the latest released JVM Bridge isn't much newer. We were > looking at using the Standard Widget Toolkit (SWT) but don't want to > rely on driving it from Haskell if the connectors are going to rot away. > (We could still use FP, after all - e.g. Scheme's Kawa and Bigloo have > good Java interoperation.) Maybe not quite what you are searching for, but something that has to do both with Haskell and Java: http://labs.businessobjects.com/cal/ From benjamin.franksen at bessy.de Mon Nov 20 12:45:23 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Mon Nov 20 12:44:52 2006 Subject: [Haskell-cafe] Re: Re[2]: Starting your own Haskell project: part 2 References: <20061119044129.GA12107@cse.unsw.EDU.AU> <20061119111009.GH22797@glowfish> <20061119125403.GA14949@cse.unsw.EDU.AU> <20061119133210.GB14949@cse.unsw.EDU.AU> <443548870.20061119204639@gmail.com> Message-ID: Bulat Ziganshin wrote: > Hello Donald, > Sunday, November 19, 2006, 4:32:10 PM, you wrote: > >> For entirely new projects, mkcabal --init-project >> creates an entire new project tree. > >> $ runhaskell mkcabal.hs --init-project > > i think it should be asked instead of using option. I like the way darcs handles this (mostly), i.e. ask the user if and only if there is no explicit command line option. Options (and thus no questions asked) are good e.g. for scripting. Ben From ndmitchell at gmail.com Mon Nov 20 13:08:38 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Mon Nov 20 13:07:31 2006 Subject: [Haskell-cafe] Interoperating with Java In-Reply-To: <87ac2mulk0.fsf@ixod.org> References: <87ac2mulk0.fsf@ixod.org> Message-ID: <404396ef0611201008t2b19a59fw6bb5fb5758adbede@mail.gmail.com> Hi There is a Yhc bytecode interpretter written in Java, if that does you any good. It would be easy to get Java to call Haskell using that, the reverse would probably not be so easy. Thanks Neil On 11/20/06, Mark T.B. Carroll wrote: > I was wondering, what's the status of the various means of two-way > interoperation with Java? Are things actively maintained? According to > the WWW, HaskellDirect's (I have Lambada in mind) current version was > released Jan 2004 and compiles with 'recent' versions of GHC, such as > ghc-6.2, and the latest released JVM Bridge isn't much newer. We were > looking at using the Standard Widget Toolkit (SWT) but don't want to > rely on driving it from Haskell if the connectors are going to rot away. > (We could still use FP, after all - e.g. Scheme's Kawa and Bigloo have > good Java interoperation.) > > -- Mark > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From bulat.ziganshin at gmail.com Mon Nov 20 13:41:39 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Mon Nov 20 13:42:06 2006 Subject: [Haskell-cafe] importing Distribution.Compat.FilePath fails In-Reply-To: <404396ef0611200523i145a0543y40ae9d837eca38b2@mail.gmail.com> References: <20061118184844.GA2683@die.therning.org> <79d7c4980611191324sfcfd2c3u38daaac17f08cfc3@mail.gmail.com> <20061120084209.GB2392@die.therning.org> <404396ef0611200523i145a0543y40ae9d837eca38b2@mail.gmail.com> Message-ID: <1482395629.20061120214139@gmail.com> Hello Neil, > It is my intention to try and get this FilePath library into the base, please no!!! why you don't understand that including in base means death of development for any library! are you really want that anyone who need new version of your lib should recompile GHC himself?! libs should be included in "base libs" set and i proposed a few months ago to radically extend it by including fundamental libs, including FilePath. but base library, which contains ghc-version specific code and can't be upgraded using cabal, should not evolve. see our discussion in libraries maillist -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From ndmitchell at gmail.com Mon Nov 20 13:53:45 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Mon Nov 20 13:52:36 2006 Subject: [Haskell-cafe] importing Distribution.Compat.FilePath fails In-Reply-To: <1482395629.20061120214139@gmail.com> References: <20061118184844.GA2683@die.therning.org> <79d7c4980611191324sfcfd2c3u38daaac17f08cfc3@mail.gmail.com> <20061120084209.GB2392@die.therning.org> <404396ef0611200523i145a0543y40ae9d837eca38b2@mail.gmail.com> <1482395629.20061120214139@gmail.com> Message-ID: <404396ef0611201053m216c94dcoe2fec0fbda4014ba@mail.gmail.com> Hi > > It is my intention to try and get this FilePath library into the base, > > please no!!! why you don't understand that including in base means > death of development for any library! are you really want that anyone > who need new version of your lib should recompile GHC himself?! I consider the FilePath library to be complete, and somewhat frozen already. I doubt that people need many other features - so I don't think thats the end of the world. I have split my FilePath library into System.FilePath (which I want included in base) and System.FilePath.Version_0_10 (which people should currently import) - that way there are no conflicts, and in a few years time everyone can use System.FilePath instead of the version specific one, and everyone will be happy. I don't propose to break any current users at any point. > libs should be included in "base libs" set and i proposed a few months > ago to radically extend it by including fundamental libs, including > FilePath. but base library, which contains ghc-version specific code > and can't be upgraded using cabal, should not evolve. see our > discussion in libraries maillist I think that FilePath should be in the current base library, as its standards go. Once your work to split base up into just the compiler dependant bits is done then I think it should be moved out, but I suspect that this work won't happen until 6.10 or later, so it deserves to go in the base library now. Anyway, I think we can have a big discussion on this when the time comes - so any discussion now would just be preempting things. Thanks Neil From slavomir.kaslev at gmail.com Mon Nov 20 17:16:44 2006 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Mon Nov 20 17:15:34 2006 Subject: [Haskell-cafe] Newbie Haskell optimization question Message-ID: <171dfd0a0611201416v1cfd786ub75115aeae8bb252@mail.gmail.com> Hello, I am new to Haskell and I am having fun with it writing L-system generator. I was very pleased with concise syntax. It's an order of magnitude better than any C++, Lisp, etc program I've ever written or read. Doing algorithmic optimizations on my generator I ended up with 4 different versions (you can see the other 3 in the file attached). The most optimal of them is: import qualified Data.Map type LSystemElement = (Char, [Int]) type LSystem = [LSystemElement] type LSystemRules = Data.Map.Map Char (LSystemElement -> LSystem) generate'' :: LSystemRules -> LSystem -> Int -> LSystem generate'' rules axiom steps = concatMap (iterate f axiom !!) (ind !! steps) where ind = [0] : [g x | x <- ind] where g [] = [] g [x] = [x, x + 1] g xs = xs ++ g (drop (length xs `div` 2) xs) f = concatMap $ \elem -> Data.Map.findWithDefault (\x -> [x]) (fst elem) rules elem -- Tests a (_, [x, y]) | y <= 2 = [('A', [x + 2, y + 2])] | otherwise = [('B', [2]), ('A', [x - 1, y - 1])] b (_, [x]) | x <= 2 = [('C', [])] | otherwise = [('B', [x - 1])] rules = Data.Map.fromList [('A', a), ('B', b)] axiom = [('A', [2, 2])] Now I am thinking of doing some language level optimizations. Can you give me any (random) directions? Any style recommendations are welcome as well. Cheers. -- Slavomir Kaslev -------------- next part -------------- A non-text attachment was scrubbed... Name: lsys.hs Type: application/octet-stream Size: 1999 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061121/22a27537/lsys.obj From alfonso.acosta at gmail.com Mon Nov 20 22:39:35 2006 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Mon Nov 20 22:38:33 2006 Subject: [Haskell-cafe] Re: RFC and Announcement: HLADSPA, LADSPA for Haskell In-Reply-To: <6a7c66fc0611051256x58efdd90qf1151cfbb64a179f@mail.gmail.com> References: <6a7c66fc0611051256x58efdd90qf1151cfbb64a179f@mail.gmail.com> Message-ID: <6a7c66fc0611201939m384de5d4s6c6b27c51542ff53@mail.gmail.com> Just in case anyone is interested. I finally overcame those difficulties and released HLADSPA 0.2 which can be found at http://www.student.nada.kth.se/~alfonsoa/HLADSPA/HLADSPA-0.2.tgz whose changelog is 2006-11-21 Version 0.2 * API refactored (now the plugins are coded in pure haskell98 + TH and it doesnt depend on the latest (6.6) version of ghc anymore) * Created proper Make system (http://hackage.haskell.org/trac/ghc/ticket/933 + the use of template records didn't allow it) * Fixed lots of major and minor bugs * Added Amp and (currently broken) ForSyDeEq plugins On 11/5/06, Alfonso Acosta wrote: > The essential code snippet is, > > ===================== > -- Existentially quantified records allow the plugin developer > -- to chose hd and id types at will and, allowing to declare "heterogeneous" > -- Descriptor lists. Drawback: it only works in ghc 6.6 and > -- makes the design tricky. The problem comes from modelling (void*) in Haskell > > -- id is the implementation data > data Descriptor = forall id. > Descriptor {uniqueID :: LadspaIndex, > label :: String, > properties :: LadspaProperties, > name, maker, copyright :: String, > portCount :: LadspaIndex, > portDescriptors :: [PortDescriptor], > portNames :: [String], > portRangeHints :: [PortRangeHint], > _implementationData :: id, > _instantiate :: Descriptor -> LadspaIndex -> > Maybe Instance} > > -- hd is the handle > data Instance = forall hd. > Instance { > _this :: hd, -- initial handle > -- In this case we are using lists to represent the port I/O buffers, so the > -- port connections (buffer pointers of ports) is handled by the marshaller > -- connectPort :: (hd -> LadspaIndex -> Ptr LadspaData -> IO hd) > _activate :: Maybe(hd -> IO ()), > -- (LadspaIndex,PortData) indicates the portnumber and its data > _run :: hd -> > LadspaIndex -> > [(LadspaIndex,PortData)] -> > ([(LadspaIndex,PortData)], hd), > -- Not yet implemented (is not mandatory for a plugin to provide them) > -- _runAdding :: > -- _setAddingGain :: > _deactivate :: Maybe (hd -> IO ()), > _cleanup :: hd -> IO () } > ===================== > > > This is the best solution I could come up with and I'm not still happy > with it. The trickiest part, was modelling (void*) in Haskell. > > I know that using lists for I/O buffers is inefficient but I coded it > having ForSyDe in mind. If people show interest I can code a faster > StorableArray-version. > > > Here are my questions. > > * I'm using GHC's existentially quantified records extension to hide > the hd and id parameters because the plugin programmer has to be able > to provide a collection of Descriptor (a Descriptor list in current > release). I would love to find a solution in plain Haskell98. Any > ideas? > > * This approach requires splitting the original C LADSPA_Descriptor > struct in the Descriptor and Instance Haskell types, which leads to a > design error: there are functions (e.g. _run, _activate ... ) in > Instance which really belong to Descriptor (those functions shouldn't > change with the plugin instance). For example, with this approach, it > is not possible to tell the plugin host if activate() or deactivate() > will be used because this is "asked" any instances is created. > > * Real Time support in HLADSPA. From LADSPA's documentation: > > "Property LADSPA_PROPERTY_HARD_RT_CAPABLE indicates that the plugin > is capable of running not only in a conventional host but also in a > `hard real-time' environment. To qualify for this the plugin must > satisfy all of the following: > (1) The plugin must not use malloc(), free() or other heap memory > management within its run() or run_adding() functions. All new > memory used in run() must be managed via the stack. These > restrictions only apply to the run() function." > > Should I forget about HARD_RT_CAPABLE with Haskell? Is there a way to > control the use of the heap by a function? > > > * I'm not so sure about the types of _activate, _deactivate and > _cleanup. I don't even know if I should include them because they only > seem to be required by a language with side effects. Furthermore, > _activate() and _deactivate() don't seem to have sense with current > implementation cause they are "separated from instantiate() to aid > real-time support" and using lists as I/O buffers discards RT support > (see above) > > > Thanks in advance for your comments/answers, > > Alfonso Acosta From sic at lerp.com Tue Nov 21 01:37:57 2006 From: sic at lerp.com (Scott Cruzen) Date: Tue Nov 21 01:35:30 2006 Subject: [Haskell-cafe] Squash ladder software in Haskell In-Reply-To: <455D4BFA.3010106@tmorris.net> References: <8A1B9139-B02D-43CB-8117-78670603D3C5@acm.org> <455D4BFA.3010106@tmorris.net> Message-ID: <20061121063757.GA30268@harlan.lerp.com> I'd previously written an implementation of the Glicko rating system in SML. Since I've been trying to learn Haskell, I decided to translate it. The results are here: http://harlan.lerp.com:9990/ http://harlan.lerp.com/~sic/ladder/ * Tony Morris [061116 21:45]: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hello fellow squashy, > Sorry I cannot provide any software references for you, but I have had > similar thoughts to yourself. In particular, I keep a track of my win > rate for one of the competitions I play in - but I do this manually. > Each time I do, I think, "gee, I should just fire up ghci and blah > blah...", but of course, I get home from squash at "ridiculous o'clock" > and so ghci is a bit contradictory to my immediate objective - to sleep. > > I'm not sure if you're aware of the "usual" method of scoring local > competitions, but it is a match of best of 5 (as usual) games and a win > percentage is calculated by number of games won/total number of games > played. > > For example, suppose I play 3 matches and win 3/0 3/2 and lose 1/3, my > win percentage is number of games won (3+3+1)/total number of games > played (3+3+1+0+2+3) == 7/12 == 58.3% > > Many sporting bodies use this number for grading, etc. so it would be > good have a cumulative number, with graphs, etc. and for comparison to > others (i.e. for grading). > > A bit early for feature requests I know :) I'll put my hand up as a > potential volunteer if you decide to pursue it further. > > Where do you play? > > Tony Morris > http://tmorris.net/ > > > > Robin Bate Boerop wrote: > > I've recently been looking for some open source software that will > > enable me to run a squash/tennis/badminton ladder on the Web. I haven't > > found any. So, it's time to write my own. Haskell is my language of > > choice. Before I start this project, is there anyone out there who has > > written some code that might be of use to me? Want to share? > > > > --Robin Bate Boerop > > > > > > > > _______________________________________________ > > Haskell-Cafe mailing list > > Haskell-Cafe@haskell.org > > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.3 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org > > iD8DBQFFXUv6mnpgrYe6r60RArRYAKCiPMGa6m+lQkW7wjq5vm6ZLZEiYwCgsskd > ++NdG6UFRwkMOrEIkOoTvNw= > =HdeY > -----END PGP SIGNATURE----- > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From oleg at pobox.com Tue Nov 21 02:42:02 2006 From: oleg at pobox.com (oleg@pobox.com) Date: Tue Nov 21 02:41:06 2006 Subject: [Haskell-cafe] Re: topEq for types Message-ID: <20061121074202.CA6A6AB40@Adric.metnet.fnmoc.navy.mil> Nicolas Frisby described the problem and the solution of the type equality comparison that takes into account the top-most type constructor only. Thus `Maybe Bool' should be considered equal to `Maybe Char' because both types have the same top constructor Maybe. The following complete code shows another solution. The code includes several tests, test1 through test6, along with the expected answers. {-# OPTIONS -fglasgow-exts #-} {-# OPTIONS -fallow-undecidable-instances #-} {-# OPTIONS -fallow-overlapping-instances #-} -- type equality for the top-level type constructor -- That is, decide two types to be equal if the top-most type constructor -- matches. Thus `Maybe Bool' should be considered equal to `Maybe Char' module TEQ where -- Our approach is simple. Given a type, we normalize it: -- replace all arguments of the type constructor with unit. -- After that, we use the regular HList's TypeEq. class Normalize t r | t -> r instance TypeCast (c ()) r => Normalize (c x) r instance TypeCast (c () ()) r => Normalize (c x y) r instance TypeCast (c () () ()) r => Normalize (c x y z) r -- add instances for type constructors of higher arities instance TypeCast y x => Normalize x y top_eq :: (Normalize a a', Normalize b b', TypeEq a' b' r) => a -> b -> r top_eq = undefined test1 = top_eq (undefined::Int) (undefined::Char) -- :t test1 -- test1 :: HFalse test2 = top_eq (undefined::Bool) (undefined::Bool) -- test2 :: HTrue test3 = top_eq (undefined::Maybe Bool) (undefined::Maybe Char) -- test3 :: HTrue test4 = top_eq (undefined::Maybe Bool) (undefined::[Char]) -- test4 :: HFalse test5 = top_eq (undefined::Either Int Char) (undefined::Either Char Int) -- test5 :: HTrue test6 = top_eq (undefined::Either Int Char) (undefined::[Char]) -- test6 :: HFalse -- The following is borrowed from HList and included here for completeness data HTrue data HFalse class TypeCast a b | a -> b, b->a where typeCast :: a -> b class TypeCast' t a b | t a -> b, t b -> a where typeCast' :: t->a->b class TypeCast'' t a b | t a -> b, t b -> a where typeCast'' :: t->a->b instance TypeCast' () a b => TypeCast a b where typeCast x = typeCast' () x instance TypeCast'' t a b => TypeCast' t a b where typeCast' = typeCast'' instance TypeCast'' () a a where typeCast'' _ x = x class TypeEq x y b | x y -> b instance TypeEq x x HTrue instance TypeCast HFalse b => TypeEq x y b From voigt at tcs.inf.tu-dresden.de Tue Nov 21 03:10:29 2006 From: voigt at tcs.inf.tu-dresden.de (Janis Voigtlaender) Date: Tue Nov 21 03:09:18 2006 Subject: [Haskell-cafe] Newbie Haskell optimization question In-Reply-To: <171dfd0a0611201416v1cfd786ub75115aeae8bb252@mail.gmail.com> References: <171dfd0a0611201416v1cfd786ub75115aeae8bb252@mail.gmail.com> Message-ID: <4562B475.2040507@tcs.inf.tu-dresden.de> Slavomir Kaslev wrote: > ... > g xs = xs ++ g (drop (length xs `div` 2) xs) > ... > > Now I am thinking of doing some language level optimizations. As a starter, the argument of g in the above right-hand side traverses xs twice, once to compute the length, then to drop an appropriate number of elements (so actually traverses xs once and a half times). The fullowing funny function could be used instead: h (_:_:xs) (_:ys) = h xs ys h _ ys = ys Then "h xs xs" is the same as "drop (length xs `div` 2) xs". It also kind of traverses xs once and a half times, but in one go. It might also be better in terms of space consumption behavior, because elements in the first half of xs can be reclaimed earlier than in the "drop (length xs `div` 2) xs" case, where the full list xs needs to be kept around until its length is computed and divided by two. A nice exercise: try to provide a function h' in a similar style as above, but in the same traversal computing also the "xs ++" part of the above right-hand side for g, i.e., "h' xs xs" gives "xs ++ g (drop (length xs `div` 2) xs)" without a third traversal of xs being necessary. Have fun, Janis. -- Dr. Janis Voigtlaender http://wwwtcs.inf.tu-dresden.de/~voigt/ mailto:voigt@tcs.inf.tu-dresden.de From Ketil.Malde at bccs.uib.no Tue Nov 21 03:53:09 2006 From: Ketil.Malde at bccs.uib.no (Ketil Malde) Date: Tue Nov 21 03:52:02 2006 Subject: [Haskell-cafe] Tuesday Morning Games (was: Friday Afternoon Play:) The Burrows Wheeler Transformation In-Reply-To: References: Message-ID: <4562BE75.7080204@ii.uib.no> apfelmus@quantentunnel.de wrote: > sadly, nobody wants to play with you. Okay, here's a small possible contribution. > Most likely, it's because the next > move is too hard: for a faster forward transform, you need (something as > tricky as) suffix trees. > To make it fast, I guess you'll need a suffix array. (And in a sense, that is what we're making when we sort the list of rotations, but of course the time complexity is way worse than the linear time SA algorithms.) >>> rotations l = init $ zipWith (++) (tails l) (inits l) >>> I haven't done the benchmarks, but I'm a bit disturbed by the number of list traversals. It seems to me that instead of sorting the rotations and taking the last element, it would be more efficient to sort the rotations by the tails, and taking the head? Especially if the string contains little redundancy, the sorting wouldn't need to traverse very deeply. Here's a (rather ugly) attempt, which seems to work: \begin{code} slow_bwt2:: Ord t => [t] -> ([t], Maybe Int) slow_bwt2 l = (map fst tagged_bwt, index_of_original) where tagged_bwt = map (head> References: <4562BE75.7080204@ii.uib.no> Message-ID: <20061121112625.GV14168@localhost.localdomain> On Tue, Nov 21, 2006 at 09:53:09AM +0100, Ketil Malde wrote: > sortBy ((. tail . fst) . compare . tail . fst) this would actually be a nice thing to have in the standard libraries: sortOn :: (Ord b) => (a -> b) -> [a] -> [a] sortOn f = sortBy $ (.f) . compare . f kibitzing (: matthias -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061121/f269fd0e/attachment.bin From Ketil.Malde at bccs.uib.no Tue Nov 21 07:36:40 2006 From: Ketil.Malde at bccs.uib.no (Ketil Malde) Date: Tue Nov 21 07:35:33 2006 Subject: [Haskell-cafe] Tuesday Morning Games In-Reply-To: <20061121112625.GV14168@localhost.localdomain> References: <4562BE75.7080204@ii.uib.no> <20061121112625.GV14168@localhost.localdomain> Message-ID: <4562F2D8.4090106@ii.uib.no> Matthias Fischmann wrote: >> sortBy ((. tail . fst) . compare . tail . fst) >> > > this would actually be a nice thing to have in the standard libraries: > > sortOn :: (Ord b) => (a -> b) -> [a] -> [a] > sortOn f = sortBy $ (.f) . compare . f I think the recommended way is to define on f g = \x y -> f (g x) (g y) That way, you can do sortBy (compare `on` snd) [(1,2),(2,1)] => [(2,1),(1,2)] -k From lemming at henning-thielemann.de Tue Nov 21 08:10:48 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Tue Nov 21 08:15:45 2006 Subject: [Haskell-cafe] Tuesday Morning Games (was: Friday Afternoon Play:) The Burrows Wheeler Transformation In-Reply-To: <20061121112625.GV14168@localhost.localdomain> References: <4562BE75.7080204@ii.uib.no> <20061121112625.GV14168@localhost.localdomain> Message-ID: On Tue, 21 Nov 2006, Matthias Fischmann wrote: > > On Tue, Nov 21, 2006 at 09:53:09AM +0100, Ketil Malde wrote: > > sortBy ((. tail . fst) . compare . tail . fst) > > this would actually be a nice thing to have in the standard libraries: > > sortOn :: (Ord b) => (a -> b) -> [a] -> [a] > sortOn f = sortBy $ (.f) . compare . f http://www.haskell.org/pipermail/libraries/2006-November/006169.html From apfelmus at quantentunnel.de Tue Nov 21 10:54:17 2006 From: apfelmus at quantentunnel.de (apfelmus@quantentunnel.de) Date: Tue Nov 21 10:57:12 2006 Subject: [Haskell-cafe] Re: Newbie Haskell optimization question In-Reply-To: <171dfd0a0611201416v1cfd786ub75115aeae8bb252@mail.gmail.com> References: <171dfd0a0611201416v1cfd786ub75115aeae8bb252@mail.gmail.com> Message-ID: > generate'' :: LSystemRules -> LSystem -> Int -> LSystem > generate'' rules axiom steps = > concatMap (iterate f axiom !!) (ind !! steps) > where > ind = [0] : [g x | x <- ind] > where > g [] = [] > g [x] = [x, x + 1] > g xs = xs ++ g (drop (length xs `div` 2) xs) > f = concatMap $ \elem -> Data.Map.findWithDefault (\x -> [x]) > (fst elem) rules elem I absolutely don't know what (ind) (hereby called the "index list") means, but it can be improved (slightly, see note at the end). Currently, you define ind = iterate g [0] (this is exactly the same as [0] : [g x | x <- ind]) and the first iterations of g yield [0] [0, 1] [0, 1, 1,2] [0, 1, 1,2, 1,2,2,3] [0, 1, 1,2, 1,2,2,3, 1,2,2,3,2,3,3,4] [0, 1, 1,2, 1,2,2,3, 1,2,2,3,2,3,3,4, 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5] ... Clearly, g xs = xs ++ map (+1) xs but your recursion scheme is more clever and exploits the fact that g is iterated and most of the additions (+1) already have been calculated. Yet it is unnecessary to generate all intermediate lists: by starting the iteration at [1], you can generate all "differences": iterate g [1] == [[1], [1,2], [1,2,2,3], [1,2,2,3,2,3,3,4], ... and get the equivalent to (ind !! steps): ind steps = 0 : (concat . take steps . iterate g $ [1]) Concerning (drop (length xs `div` 2)), you can carry (n = length xs) around so that you don't have to recalculate the length everytime. Alternatively, you can even make the recursion structure explicit and avoid the rescan involved with (drop) entirely data List a = Zero | One a | List a :++: List a g x@(One k) = x :++: One (k + 1) g xs@(_ :++: xs') = xs :++: g xs' flatten' Zero = id flatten' (One x) = (x :) flatten' (xs :++: ys) = (xs ++) . (ys ++) flatten = flip flatten' [] ind steps = 0 : (flatten . foldr1 (:++:) . take steps . iterate g $ One 1) Going even further, you can fuse the lindenmaier iteration into this (starting the iteration of g at 0 again): generate rules axiom steps = flatten . flip (!!) (steps + 1) . iterate g $ Zero where g Zero = One axiom g x@(One lsys) = x :++: One (f lsys) g xs@(_ :++: xs') = xs :++: g xs' f = ... Look, the Ints are gone! (k + 1) only meant (f k)! The data structures are lightweight and now perfectly fit the structure of the calculation. This is the best you can do, for all languages: In C, the most native data structure is (int) and pointer arithmetic is the way to win. In LISP, lists are favored above all else. And in Haskell, all algebraic data types are native and together with laziness, they pave the road to speed. As a last note, all these things are only able to improve a constant factor (measured relative to the exponential length of the outcoming index list) and only benchmarks can show which ones really improve things. Constant factors are quite sensitive on how the code looks like. Of course, "ghc -O2" is the best constant factor improver known :) Regards, apfelmus PS: You can even improve upon the logarithmic factor that comes from repeatedly using Data.Map by decorating each LSystemElement with its rule: data LSystemElement' = LSE LSystemElement LSystem' type LSystem' = [LSystemElement'] a l@[x,y] = LSE ('A',l) $ if y <= 2 then [a [x + 2, y + 2]] else [b [2], a [x - 1, y - 1]] b l@[x] = LSE ('B',l) $ if x <= 2 then [c []] else [b [x - 1]] c [] = LSE ('C',[]) [c] axiom = [a [2,2]] generate = ... where ... f = concatMap (\(LSE _ s) -> s) This decoration can be derived from LSystemRules if you want to keep your traditional rules. From magnus at therning.org Tue Nov 21 13:07:40 2006 From: magnus at therning.org (Magnus Therning) Date: Tue Nov 21 13:09:42 2006 Subject: [Haskell-cafe] Articles on programming with (IO) exceptions in Haskell? Message-ID: <20061121180740.GA8881@die.therning.org> I'm having problems finding a good introduction to exceptions. Yet Another Haskell Tutorial leaves it for chapter 10, which is empty. I'd prefer something that suits a noob. :-) /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus Software is not manufactured, it is something you write and publish. Keep Europe free from software patents, we do not want censorship by patent law on written works. `Time is an illusion. Lunchtime doubly so.' `Very deep,' said Arthur, `you should send that in to the "Reader's Digest". They've got a page for people like you.' -- Ford convincing Arthur to drink three pints in ten minutes at lunchtime. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061121/0a43ffad/attachment.bin From dagit at eecs.oregonstate.edu Tue Nov 21 13:27:51 2006 From: dagit at eecs.oregonstate.edu (Jason Dagit) Date: Tue Nov 21 13:26:39 2006 Subject: [Haskell-cafe] Tuesday Morning Games (was: Friday Afternoon Play:) The Burrows Wheeler Transformation In-Reply-To: References: <4562BE75.7080204@ii.uib.no> <20061121112625.GV14168@localhost.localdomain> Message-ID: Could we please only change the subject of threads when it's necessary? It confuses my mail reader which then confuses me. Of course it's not your fault I choose to use an easily confused mail reader, but at the same time I don't understand the point of changing the subject of the thread. And not just this thread; I see it happen fairly often but this thread seems to have done it a lot in a short period of time making it a good example. Jason On 11/21/06, Henning Thielemann wrote: > > On Tue, 21 Nov 2006, Matthias Fischmann wrote: > > > > > On Tue, Nov 21, 2006 at 09:53:09AM +0100, Ketil Malde wrote: > > > sortBy ((. tail . fst) . compare . tail . fst) > > > > this would actually be a nice thing to have in the standard libraries: > > > > sortOn :: (Ord b) => (a -> b) -> [a] -> [a] > > sortOn f = sortBy $ (.f) . compare . f > > http://www.haskell.org/pipermail/libraries/2006-November/006169.html > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > From alex at alexjacobson.com Tue Nov 21 14:18:50 2006 From: alex at alexjacobson.com (S. Alexander Jacobson) Date: Tue Nov 21 14:16:53 2006 Subject: [Haskell-cafe] why are implicit types different? Message-ID: Why do g and g' have different types? g x y = let ?f = \x-> x in ?f x ++ (show (?f y)) g' x y = let f = \x-> x in f x ++ (show (f y)) Is there a way I can use implicit types and let g be as general as g'? -Alex- ______________________________________________________________ S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com From newsham at lava.net Tue Nov 21 14:24:38 2006 From: newsham at lava.net (Tim Newsham) Date: Tue Nov 21 14:23:26 2006 Subject: [Haskell-cafe] Type Error. Why!? Message-ID: Can anyone tell me why I get a type error in the following code? I have to define liftA2 twice to avoid the type error. Both times its defined identically but with different type signature. If I use the original liftA2 in place of liftA2' I get: whyerror.lhs:36:25: Ambiguous type variable `a' in the constraint: `Arrow a' arising from use of `>>>' at whyerror.lhs:36:25-27 Possible cause: the monomorphism restriction applied to the following: liftA2' :: forall b a1 b1 c. (a1 -> b1 -> c) -> a b a1 -> a b b1 -> a b c (bound at whyerror.lhs:36:1) unsplit' :: forall a1 b c. (a1 -> b -> c) -> a (a1, b) c (bound at whyerror.lhs:34:1) split' :: forall b. a b (b, b) (bound at whyerror.lhs:33:1) Probable fix: give these definition(s) an explicit type signature or use -fno-monomorphism-restriction ----- whyerror.lhs ---- > {-# OPTIONS_GHC -farrows #-} > module WhyError where > import Control.Arrow > newtype SimpleFunc a b = SimpleFunc { runF :: (a -> b) } > instance Arrow SimpleFunc where > arr f = SimpleFunc f > first (SimpleFunc f) = SimpleFunc (mapFst f) > where mapFst g (a,b) = (g a, b) > (SimpleFunc f) >>> (SimpleFunc g) = SimpleFunc (g . f) > split :: (Arrow a) => a b (b, b) > split = arr (\x -> (x,x)) > unsplit :: (Arrow a) => (b -> c -> d) -> a (b, c) d > unsplit = arr . uncurry > -- arr (\op (x,y) -> x `op` y) > liftA2 :: (Arrow a) => (b -> c -> d) -> a e b -> a e c -> a e d > liftA2 op f g = split >>> first f >>> second g >>> unsplit op > -- f &&& g >>> unsplit op > f, g :: SimpleFunc Int Int > f = arr (`div` 2) > g = arr (\x -> x*3 + 1) > h = liftA2 (+) f g > hOutput = runF h 8 > -- XXX I am getting type problems with split, unsplit and liftA2! why? > split' = arr (\x -> (x,x)) > unsplit' = arr . uncurry > -- liftA2' :: (Arrow a) => (b -> c -> d) -> a e b -> a e c -> a e d > liftA2' op f g = split' >>> first f >>> second g >>> unsplit' op > plusminus, double, h2 :: Kleisli [] Int Int > plusminus = Kleisli (\x -> [x, -x]) > double = arr (* 2) > h2 = liftA2 (+) plusminus double > h2Output = runKleisli h2 8 > main = do > print hOutput > print h2Output Tim Newsham http://www.thenewsh.com/~newsham/ From alex at alexjacobson.com Tue Nov 21 14:28:07 2006 From: alex at alexjacobson.com (S. Alexander Jacobson) Date: Tue Nov 21 14:25:49 2006 Subject: [Haskell-cafe] why are implicit types different? (cleanup) Message-ID: Why do g and g' have different types? g x y = let ?f = \x-> x in ?f x ++ (show (?f y)) g :: [Char] -> [Char] -> [Char] g' :: (Show t) => [Char] -> t -> [Char] g' x y = let f = \x-> x in f x ++ (show (f y)) Is there a way I can use implicit types and let g be as general as g'? -Alex- ______________________________________________________________ S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com From robdockins at fastmail.fm Tue Nov 21 16:07:28 2006 From: robdockins at fastmail.fm (Robert Dockins) Date: Tue Nov 21 16:02:58 2006 Subject: [Haskell-cafe] Type Error. Why!? In-Reply-To: References: Message-ID: On Nov 21, 2006, at 2:24 PM, Tim Newsham wrote: > Can anyone tell me why I get a type error in the following code? > I have to define liftA2 twice to avoid the type error. Both > times its defined identically but with different type signature. > If I use the original liftA2 in place of liftA2' I get: > > whyerror.lhs:36:25: > Ambiguous type variable `a' in the constraint: > `Arrow a' arising from use of `>>>' at whyerror.lhs:36:25-27 > Possible cause: the monomorphism restriction applied to the > following: > liftA2' :: forall b a1 b1 c. (a1 -> b1 -> c) -> a b a1 -> a b > b1 -> a b c > (bound at whyerror.lhs:36:1) > unsplit' :: forall a1 b c. (a1 -> b -> c) -> a (a1, b) c > (bound at whyerror.lhs:34:1) > split' :: forall b. a b (b, b) (bound at whyerror.lhs:33:1) > Probable fix: give these definition(s) an explicit type signature > or use -fno-monomorphism-restriction I'm not sure I understand your problem. If I comment out split', unsplit' and liftA2', your program compiles and executes. Without signatures, MR kicks in and gives the error above (which recommends you give signatures ;-) ) However, you've got type signatures, and the foul MR beast is slain, so the problem appears solved... [snip code] > Tim Newsham > http://www.thenewsh.com/~newsham/ Rob Dockins Speak softly and drive a Sherman tank. Laugh hard; it's a long way to the bank. -- TMBG From dons at cse.unsw.edu.au Tue Nov 21 18:34:28 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Tue Nov 21 18:33:20 2006 Subject: [Haskell-cafe] Articles on programming with (IO) exceptions in Haskell? In-Reply-To: <20061121180740.GA8881@die.therning.org> References: <20061121180740.GA8881@die.therning.org> Message-ID: <20061121233428.GA30891@cse.unsw.EDU.AU> magnus: > I'm having problems finding a good introduction to exceptions. Yet > Another Haskell Tutorial leaves it for chapter 10, which is empty. I'd > prefer something that suits a noob. :-) Something from here: http://www.haskell.org/haskellwiki/Books_and_tutorials#Practical_Haskell Perhaps: http://research.microsoft.com/%7Esimonpj/Papers/marktoberdorf -- Don From dagit at eecs.oregonstate.edu Tue Nov 21 19:03:51 2006 From: dagit at eecs.oregonstate.edu (Jason Dagit) Date: Tue Nov 21 19:02:35 2006 Subject: [Haskell-cafe] Articles on programming with (IO) exceptions in Haskell? In-Reply-To: <20061121233428.GA30891@cse.unsw.EDU.AU> References: <20061121180740.GA8881@die.therning.org> <20061121233428.GA30891@cse.unsw.EDU.AU> Message-ID: On 11/21/06, Donald Bruce Stewart wrote: > magnus: > > I'm having problems finding a good introduction to exceptions. Yet > > Another Haskell Tutorial leaves it for chapter 10, which is empty. I'd > > prefer something that suits a noob. :-) > > Something from here: > http://www.haskell.org/haskellwiki/Books_and_tutorials#Practical_Haskell > > Perhaps: > http://research.microsoft.com/%7Esimonpj/Papers/marktoberdorf That second link, "Tackling the awkward squad..." should be required reading material for anyone planning to use haskell for "real-world" stuff. The reader doesn't even need to know that much Haskell to benefit from it. It and "All about monads" are both very nice because they are accessible to the beginner but still contain useful ideas, examples and idioms for the intermediate haskell programmer. I've also noticed that programmers coming from imperative backgrounds seem to digest "Tackling the awkward squad..." fairly well and it seems to answer their need to understand the IO monad. Jason From newsham at lava.net Tue Nov 21 19:48:21 2006 From: newsham at lava.net (Tim Newsham) Date: Tue Nov 21 19:47:07 2006 Subject: [Haskell-cafe] Type Error. Why!? In-Reply-To: References: Message-ID: > I'm not sure I understand your problem. If I comment out split', unsplit' > and liftA2', your program compiles and executes. Blah.. you're right! I tried so many different things I guess I didn't notice that along the way I fixed it with the type signatures.. > Without signatures, MR kicks in and gives the error above (which recommends > you give signatures ;-) ) However, you've got type signatures, and the foul > MR beast is slain, so the problem appears solved... MR = ? Thanks for injecting some sanity. > Rob Dockins Tim Newsham http://www.thenewsh.com/~newsham/ From ndmitchell at gmail.com Tue Nov 21 19:52:08 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Tue Nov 21 19:50:54 2006 Subject: [Haskell-cafe] Type Error. Why!? In-Reply-To: References: Message-ID: <404396ef0611211652o8affdcex55733c8b334265c1@mail.gmail.com> Hi > MR = ? Monomorphism Restriction http://www.haskell.org/hawiki/MonomorphismRestriction Is there really not a page on the new wiki that explains that MR? We should also have a nice big FAQ, as this is often asked about. Thanks Neil From igloo at earth.li Tue Nov 21 21:34:39 2006 From: igloo at earth.li (Ian Lynagh) Date: Tue Nov 21 21:33:28 2006 Subject: [Haskell-cafe] help with threadDelay In-Reply-To: <37c497340611151540u121adcdbu381d15ea10068c93@mail.gmail.com> References: <37c497340611151540u121adcdbu381d15ea10068c93@mail.gmail.com> Message-ID: <20061122023439.GA3165@matrix.chaos.earth.li> [moving to glasgow-haskell-bugs] On Wed, Nov 15, 2006 at 11:40:12PM +0000, Neil Davies wrote: > > however when -threaded is used you get some interesting effects, > including returning too early: > > Tgt/Actual = 0.000125/0.000034s, diff = -0.000091s Thanks for the report; I can reproduce it on Linux/amd64. OK, so the bug here is that threadDelay n might return after less than n microseconds. This looks like it's caused by truncation problems when converting times to ticks (where a tick is 1/50 of a second), e.g. while trying to sleep for 1.953125s one run started at 1164157960.773726s which is (Int) 1164157960 * 50 + 773726 * 50 / 1000000 = (Int) 58207898038.6863 = 58207898038 ticks and woke the thread up at 1164157962.708609s which is (Int) 1164157962 * 50 + 708609 * 50 / 1000000 = (Int) 58207898135.4305 = 58207898135 ticks The difference is 58207898135 - 58207898038 = 97 ticks. Meanwhile we're trying to sleep for (Int) 50 * 1.953125 = (Int) 97.65625 = 97 ticks However, 1164157962.708609s - 1164157960.773726s = 1.93488311767578s which is 0.0182418823242201s too short. The problem is that we have counted 0.6863 ticks before the start time, not counted 0.4305 ticks before the finish time and have been waiting 0.65625 ticks too short a time. Thus we have counted (0.6863-0.4305 + 0.65625) / 50 == 0.018241 too much time. I think the answer is that let target = now + usecs `quot` tick_usecs in GHC/Conc.lhs should be let target = 1 + now + (usecs + tick_usecs - 1) `quot` tick_usecs I'm also a bit dubious about the use of the constant "50" for the number of ticks per second, but the results with +RTS -V0.001 don't look any more wrong so perhaps I just need to get some sleep. You can get the same symptoms with the non-threaded RTS with +RTS -V0.001, although they are less frequent. I suspect we need a similar fix to target = (R1 / (TO_W_(RtsFlags_MiscFlags_tickInterval(RtsFlags))*1000)) + time; in delayzh_fast in PrimOps.cmm. Thanks Ian From polyomino at f2s.com Wed Nov 22 04:12:33 2006 From: polyomino at f2s.com (DavidA) Date: Wed Nov 22 04:12:04 2006 Subject: [Haskell-cafe] Why are new releases of libraries required for every GHC release? Message-ID: Some recent comments suggested that every time there is a new GHC release, there needs to be a new wxHaskell release (or insert name of other library here) to work with it. This seems to be true even for minor upgrades, like 6.4.1 -> 6.4.2. Why is this? Does GHC break binary compatibility at every release? Is this avoidable? This makes using Haskell unnecessarily hard compared to other platforms. From simonmarhaskell at gmail.com Wed Nov 22 04:26:46 2006 From: simonmarhaskell at gmail.com (Simon Marlow) Date: Wed Nov 22 04:25:36 2006 Subject: [Haskell-cafe] Re: help with threadDelay In-Reply-To: <20061122023439.GA3165@matrix.chaos.earth.li> References: <37c497340611151540u121adcdbu381d15ea10068c93@mail.gmail.com> <20061122023439.GA3165@matrix.chaos.earth.li> Message-ID: <456417D6.8030100@microsoft.com> Ian Lynagh wrote: > [moving to glasgow-haskell-bugs] > > On Wed, Nov 15, 2006 at 11:40:12PM +0000, Neil Davies wrote: > >>however when -threaded is used you get some interesting effects, >>including returning too early: >> >>Tgt/Actual = 0.000125/0.000034s, diff = -0.000091s > > > Thanks for the report; I can reproduce it on Linux/amd64. > > OK, so the bug here is that threadDelay n might return after less than n > microseconds. > > This looks like it's caused by truncation problems when converting times > to ticks (where a tick is 1/50 of a second), e.g. while trying to sleep > for 1.953125s one run started at 1164157960.773726s which is > (Int) 1164157960 * 50 + 773726 * 50 / 1000000 > = (Int) 58207898038.6863 > = 58207898038 ticks > and woke the thread up at 1164157962.708609s which is > (Int) 1164157962 * 50 + 708609 * 50 / 1000000 > = (Int) 58207898135.4305 > = 58207898135 ticks > > The difference is 58207898135 - 58207898038 = 97 ticks. > > Meanwhile we're trying to sleep for > (Int) 50 * 1.953125 > = (Int) 97.65625 > = 97 ticks > > However, 1164157962.708609s - 1164157960.773726s = 1.93488311767578s > which is 0.0182418823242201s too short. > > The problem is that we have counted 0.6863 ticks before the start time, > not counted 0.4305 ticks before the finish time and have been waiting > 0.65625 ticks too short a time. Thus we have counted > (0.6863-0.4305 + 0.65625) / 50 == 0.018241 too much time. > > I think the answer is that > > let target = now + usecs `quot` tick_usecs > > in GHC/Conc.lhs should be > > let target = 1 + now + (usecs + tick_usecs - 1) `quot` tick_usecs > > I'm also a bit dubious about the use of the constant "50" for the number > of ticks per second, but the results with +RTS -V0.001 don't look any > more wrong so perhaps I just need to get some sleep. The hardcoded 50 in GHC/Conc.lhs matches up with TICK_FREQ in libraries/base/includes/HsBase.h. It could probably be made larger without any ill effects. I agree that we should round up the target time to the nearest tick rather than rounding down, though. Cheers, Simon From ndmitchell at gmail.com Wed Nov 22 04:38:58 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Nov 22 04:37:43 2006 Subject: [Haskell-cafe] Why are new releases of libraries required for every GHC release? In-Reply-To: References: Message-ID: <404396ef0611220138q5eb6616ck8ae14d3617da7181@mail.gmail.com> Hi > Some recent comments suggested that every time there is a new GHC release, > there needs to be a new wxHaskell release (or insert name of other library > here) to work with it. This seems to be true even for minor upgrades, like > 6.4.1 -> 6.4.2. Yes, if you pick Gtk2Hs, wxHaskell. However lots of other libraries will work just fine between GHC releases > Why is this? Does GHC break binary compatibility at every release? Is this > avoidable? It breaks binary compatibility, not source compatibility. Only a relatively small number of libraries are effected. Thanks Neil From duncan.coutts at worc.ox.ac.uk Wed Nov 22 05:39:06 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Wed Nov 22 05:32:12 2006 Subject: [Haskell-cafe] Why are new releases of libraries required for every GHC release? In-Reply-To: References: Message-ID: <1164191946.2084.429.camel@localhost> On Wed, 2006-11-22 at 09:12 +0000, DavidA wrote: > Some recent comments suggested that every time there is a new GHC release, > there needs to be a new wxHaskell release (or insert name of other library > here) to work with it. This seems to be true even for minor upgrades, like > 6.4.1 -> 6.4.2. These GUI libs tend only to break on major releases like 6.2 -> 6.4 and 6.4 -> 6.6. In both cases this was due to changes in the way packages are managed. Since these GUI libs are both pretty large and made of several packages they were affected. Many simpler projects were fine with the transition. > Why is this? Does GHC break binary compatibility at every release? Is this > avoidable? Yes this is what you're thinking about with minor upgrades like 6.4.1 -> 6.4.2, so any binary packages, eg windows installers need to be rebuilt from source to work with the new ghc version. > This makes using Haskell unnecessarily hard compared to other platforms. Well, usually it's only a rebuild so as long as your build system is ok, it's not too hard. Duncan From magnus at therning.org Wed Nov 22 08:20:38 2006 From: magnus at therning.org (Magnus Therning) Date: Wed Nov 22 08:24:47 2006 Subject: [Haskell-cafe] Why are new releases of libraries required for every GHC release? In-Reply-To: <1164191946.2084.429.camel@localhost> References: <1164191946.2084.429.camel@localhost> Message-ID: <20061122132038.GC24054@die.therning.org> On Wed, Nov 22, 2006 at 10:39:06 +0000, Duncan Coutts wrote: >On Wed, 2006-11-22 at 09:12 +0000, DavidA wrote: >> Some recent comments suggested that every time there is a new GHC release, >> there needs to be a new wxHaskell release (or insert name of other library >> here) to work with it. This seems to be true even for minor upgrades, like >> 6.4.1 -> 6.4.2. > >These GUI libs tend only to break on major releases like 6.2 -> 6.4 and >6.4 -> 6.6. In both cases this was due to changes in the way packages >are managed. Since these GUI libs are both pretty large and made of >several packages they were affected. Many simpler projects were fine >with the transition. > >> Why is this? Does GHC break binary compatibility at every release? Is this >> avoidable? > >Yes this is what you're thinking about with minor upgrades like 6.4.1 -> >6.4.2, so any binary packages, eg windows installers need to be rebuilt >from source to work with the new ghc version. > >> This makes using Haskell unnecessarily hard compared to other platforms. > >Well, usually it's only a rebuild so as long as your build system is >ok, it's not too hard. Does this affect any apps at all? On Debian at least, ghc links in all haskell code statically which means that no re-compiles are necessary for binaries. How's this on other platforms? /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus Software is not manufactured, it is something you write and publish. Keep Europe free from software patents, we do not want censorship by patent law on written works. As far as the laws of mathematics refer to reality, they are not certain, and as far as they are certain, they do not refer to reality. -- Albert Einstein -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061122/f337d531/attachment.bin From lemming at henning-thielemann.de Wed Nov 22 09:28:28 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Wed Nov 22 09:29:37 2006 Subject: [Haskell-cafe] Type Error. Why!? In-Reply-To: <404396ef0611211652o8affdcex55733c8b334265c1@mail.gmail.com> References: <404396ef0611211652o8affdcex55733c8b334265c1@mail.gmail.com> Message-ID: On Wed, 22 Nov 2006, Neil Mitchell wrote: > http://www.haskell.org/hawiki/MonomorphismRestriction > > Is there really not a page on the new wiki that explains that MR? We > should also have a nice big FAQ, as this is often asked about. http://www.haskell.org/haskellwiki/Category:FAQ From ndmitchell at gmail.com Wed Nov 22 09:43:04 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Nov 22 09:41:49 2006 Subject: [Haskell-cafe] Type Error. Why!? In-Reply-To: References: <404396ef0611211652o8affdcex55733c8b334265c1@mail.gmail.com> Message-ID: <404396ef0611220643u15675ae5w71945120e4f79f60@mail.gmail.com> Hi > http://www.haskell.org/haskellwiki/Category:FAQ How is this an FAQ: http://www.haskell.org/haskellwiki/Why_Haskell_just_works It's a nice piece of marketing, but I can't imagine anyone has ever asked Why Haskell just works, unless they've already used it, in which case they've moved past an FAQ. It would be nice to flesh that out, make it more traditional FAQ style (with a bit of info on what each one means) and have a real FAQ Thanks Neil From bulat.ziganshin at gmail.com Wed Nov 22 09:59:58 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Wed Nov 22 10:00:14 2006 Subject: [Haskell-cafe] Articles on programming with (IO) exceptions in Haskell? In-Reply-To: <20061121180740.GA8881@die.therning.org> References: <20061121180740.GA8881@die.therning.org> Message-ID: <291788868.20061122175958@gmail.com> Hello Magnus, Tuesday, November 21, 2006, 9:07:40 PM, you wrote: > I'm having problems finding a good introduction to exceptions. Yet > Another Haskell Tutorial leaves it for chapter 10, which is empty. I'd > prefer something that suits a noob. :-) "Tackling the awkward squad: monadic input/output, concurrency, exceptions, and foreign-language calls in Haskell" http://research.microsoft.com/Users/simonpj/papers/marktoberdorf/marktoberdorf.ps.gz -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From semanticphilosopher at googlemail.com Wed Nov 22 10:37:05 2006 From: semanticphilosopher at googlemail.com (Neil Davies) Date: Wed Nov 22 10:35:49 2006 Subject: [Haskell-cafe] Re: help with threadDelay Message-ID: <37c497340611220737pde4003ald4966848f25a8242@mail.gmail.com> Ian/Simon(s) Thanks - looking forward to the fix. It will help with the real time enviroment that I've got. Follow on query: Is there a way of seeing the value of this interval from within the Haskell program? Helps in the calibration loop. Neil From clawsie at fastmail.fm Wed Nov 22 18:00:26 2006 From: clawsie at fastmail.fm (brad clawsie) Date: Wed Nov 22 17:59:13 2006 Subject: [Haskell-cafe] trivial ghc problem, help needed Message-ID: <1164236426.15564.277061667@webmail.messagingengine.com> i have a program tb.hs: --- module Main where import Network.URI (URI(..), URIAuth(..), parseURI) myFunc :: String -> Maybe URI myFunc u = parseURI u main = do { return () } --- when i attempt to build it with ghc, i get the following output: tb.o: In function `Main_myFunc_info': (.text+0x11): undefined reference to `networkzm2zi0_NetworkziURI_parseURI_closure' tb.o: In function `Main_myFunc_srt': (.rodata+0x0): undefined reference to `networkzm2zi0_NetworkziURI_parseURI_closure' collect2: ld returned 1 exit status any clue why? i would send this to the ghc list but i presume my issue is due to a trivial misunderstanding of the language thanks in advance From dons at cse.unsw.edu.au Wed Nov 22 18:03:19 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Wed Nov 22 18:02:04 2006 Subject: [Haskell-cafe] trivial ghc problem, help needed In-Reply-To: <1164236426.15564.277061667@webmail.messagingengine.com> References: <1164236426.15564.277061667@webmail.messagingengine.com> Message-ID: <20061122230319.GA806@cse.unsw.EDU.AU> clawsie: > i have a program tb.hs: > > --- > module Main where > import Network.URI (URI(..), URIAuth(..), parseURI) > > myFunc :: String -> Maybe URI > myFunc u = parseURI u > > main = do { return () } > --- > > when i attempt to build it with ghc, i get the following output: > > tb.o: In function `Main_myFunc_info': > (.text+0x11): undefined reference to > `networkzm2zi0_NetworkziURI_parseURI_closure' > tb.o: In function `Main_myFunc_srt': > (.rodata+0x0): undefined reference to > `networkzm2zi0_NetworkziURI_parseURI_closure' > collect2: ld returned 1 exit status > > any clue why? i would send this to the ghc list but i presume my issue > is due to a trivial misunderstanding of the language Assuming you have the Network package installed, you need to tell the compile to link in the extra network library. The above is a linker error. Adding --make or -package network to the command line should do the trick. -- Don From golubovsky at gmail.com Wed Nov 22 23:50:02 2006 From: golubovsky at gmail.com (Dimitry Golubovsky) Date: Wed Nov 22 23:48:47 2006 Subject: [Haskell-cafe] YCR2JS Programmers Guide Draft available Message-ID: Hi, I have finished typing in the draft of low-level programming guide for Yhc Core to Javascript converter. Everyone interested in future use of this tool is encouraged to read and review the Guide. Its purpose is to give some ideas about interaction of Haskell programs converted into Javascript with a web browser on the lowest possible level, without application frameworks and support libraries (just because these haven't been developed). Any feedback and ideas are appreciated. The document is located at: http://haskell.org/haskellwiki/Yhc/Javascript/Programmers_guide Thanks. -- Dimitry Golubovsky Anywhere on the Web From simonmarhaskell at gmail.com Thu Nov 23 04:30:17 2006 From: simonmarhaskell at gmail.com (Simon Marlow) Date: Thu Nov 23 04:29:21 2006 Subject: [Haskell-cafe] Re: help with happy/alex In-Reply-To: <7FC65C10-010F-1000-EB55-E9E57D45E32E-Webmail-10021@mac.com> References: <7FC65C10-010F-1000-EB55-E9E57D45E32E-Webmail-10021@mac.com> Message-ID: <45656A29.6080100@microsoft.com> robert bauer wrote: > Hi, > > I have a .y and .x file. The alex -g _.x gives me a .hs file and happy -g -a -c _.y gives me a .hs file. > I then use ghc -c alex.hs to get a a .o and a .hi file. This works great. > Unfortunately > ghc -c happy.y doesn't work -- it says that it the module name for the lexer doesn't match. I've attached the > .y and .x files. > > Also, I cannot figure out what I need to do in the parser to call the lexer and I don't know how to kick start the > parser -- I have no clue what to put in third, main.hs, module. > > Any help would be appreciated. You have a typo in the module name in TVScriptLexer.x. As for tying it together, I suggest taking a look at some of the examples, eg. http://darcs.haskell.org/alex/examples/tiny.y from the Alex distribution. Cheers, Simon From niko.korhonen at gmail.com Thu Nov 23 05:11:43 2006 From: niko.korhonen at gmail.com (Niko Korhonen) Date: Thu Nov 23 05:10:27 2006 Subject: [Haskell-cafe] Difficult memory leak in array processing Message-ID: Hi everyone, I have the following code whose purpose is to add dither (noise) to a given array. The code looks very straightforward but apparently it has a memory leak somewhere. Here I try to run the algorithm for an array of 10,000,000 integers. Ten million unboxed strict integers should equal to 40MB which should pose no problems to any modern system. However, the program fails with a stack overflow error. I'm using GHC 6.6 on Windows with 1 GB of RAM. I've tried applying seq and some other strictness tricks (such as x == x) pretty much everywhere on the code with no results. Could you please help me understand what is going on here? Have I misunderstood something critical in how Haskell works? Here is the relevant portion of the code: module Main where import Data.Array.IO import System.Random type Buffer = IOUArray Int Int -- | Triangular Probability Density Function, equivalent to a roll of two dice. -- The number sums have different probabilities of surfacing. tpdf :: (Int, Int) -> IO Int tpdf (low, high) = do first <- getStdRandom (randomR (low, high)) second <- getStdRandom (randomR (low, high)) return ((first + second) `div` 2) -- | Fills an array with dither generated by the specified function. genSeries :: Buffer -> ((Int, Int) -> IO Int) -> (Int, Int) -> IO () genSeries buf denfun lims = let worker low i | i >= low = do r <- denfun lims writeArray buf i r worker low (i - 1) | otherwise = return () in do (lo, hi) <- getBounds buf worker lo hi main = do -- This should allocate a 40 MB array buf <- newArray_ (0, 10000000) :: IO Buffer -- Fill the array with dither genSeries buf tpdf (2, 12) -- niko.korhonen@gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061123/6f2b20b7/attachment.htm From isto.aho at dnainternet.net Thu Nov 23 06:26:08 2006 From: isto.aho at dnainternet.net (isto) Date: Thu Nov 23 06:24:49 2006 Subject: [Haskell-cafe] Difficult memory leak in array processing In-Reply-To: References: Message-ID: <1164281168.4975.17.camel@localhost.localdomain> Hi Niko, to, 2006-11-23 kello 12:11 +0200, Niko Korhonen kirjoitti: > I've tried applying seq and some other strictness tricks (such as x == > x) pretty much everywhere on the code with no results. Could you > please help me understand what is going on here? Have I misunderstood > something critical in how Haskell works? Here is the relevant portion > of the code: > main = do > -- This should allocate a 40 MB array > buf <- newArray_ (0, 10000000) :: IO Buffer > -- Fill the array with dither > genSeries buf tpdf (2, 12) main = do -- This should allocate a 40 MB array buf <- newArray_ (0, 100000000) :: IO Buffer -- Fill the array with dither genSeries buf tpdf (2, 12) a <- readArray buf 100000000 putStrLn $ "a is " ++ (show a) By adding -O3 -optc-O3 -funfolding-use-threshold=16 compile flags the above code with 100'000'000 elements worked. And by still adding -ddump-simpl > core.txt flag and looking the generated core, the worker-loop seemed to use primitives. I cannot say, if this was the helping part here. Have you tried profiling: -prof -auto-all and running with +RTS -p -RTS? Or running with +RTS -sstderr gives 14,257,786,344 bytes allocated in the heap 4,282,040 bytes copied during GC (scavenged) 1,646,936 bytes copied during GC (not scavenged) 80,733,232 bytes maximum residency (2 sample(s)) 27045 collections in generation 0 ( 0.31s) 2 collections in generation 1 ( 0.00s) 78 Mb total memory in use INIT time 0.00s ( 0.00s elapsed) MUT time 22.61s ( 24.07s elapsed) GC time 0.31s ( 0.32s elapsed) EXIT time 0.00s ( 0.00s elapsed) Total time 22.92s ( 24.39s elapsed) %GC time 1.3% (1.3% elapsed) Alloc rate 630,612,876 bytes per MUT second Productivity 98.6% of total user, 92.7% of total elapsed It seems that garbage collector has not used very much time here. There is more information on haskell wiki: http://www.haskell.org/haskellwiki/Performance http://www.haskell.org/haskellwiki/Performance/GHC This GHC specific part does not mention -O3 -optc-O3 -funfolding-use-threshold=nn flags. They were hinted here on this list; I have found them very helpful a couple of weeks ago - thanks again :) btw, Could the GHC specific wiki page be updated to contain and explain these flags? Hopefully this helped you a bit! And hopefully someone who knows how these things go have time to give you a detailed answer! br, Isto From Alistair_Bayley at invescoperpetual.co.uk Thu Nov 23 07:56:00 2006 From: Alistair_Bayley at invescoperpetual.co.uk (Bayley, Alistair) Date: Thu Nov 23 07:54:43 2006 Subject: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video Message-ID: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> http://channel9.msdn.com/Showpost.aspx?postid=231495 The links to the video are a couple of yellow buttons at the bottom of the article: "Watch" or "Download". I haven't watched this yet (it's nearly an hour long, I think). Found via reddit (http://reddit.com). Haskeller's on TV (sort of...) woot woot! Alistair ***************************************************************** Confidentiality Note: The information contained in this message, and any attachments, may contain confidential and/or privileged material. It is intended solely for the person(s) or entity to which it is addressed. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient(s) is prohibited. If you received this in error, please contact the sender and delete the material from any computer. ***************************************************************** From u.stenzel at web.de Thu Nov 23 07:39:36 2006 From: u.stenzel at web.de (Udo Stenzel) Date: Thu Nov 23 08:29:49 2006 Subject: [Haskell-cafe] Difficult memory leak in array processing In-Reply-To: References: Message-ID: <20061123123936.GA1535@web.de> Niko Korhonen wrote: > I have the following code whose purpose is to add dither (noise) to a given > array. The code looks very straightforward but apparently it has a memory leak > somewhere. No, it doesn't. It can't, because it doesn't even compile. After correcting the obvious > (lo, hi) <- getBounds buf to let (lo,hi) = bounds buf it just works and needs 40MB plus epsilon. Your problem has to be somewhere else. -Udo. -- fork(2) New processes are created by other processes, just like new humans. New humans are created by other humans, of course, not by processes. -- Unix System Administration Handbook -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061123/af59f20b/attachment.bin From apfelmus at quantentunnel.de Thu Nov 23 09:14:17 2006 From: apfelmus at quantentunnel.de (apfelmus@quantentunnel.de) Date: Thu Nov 23 09:17:00 2006 Subject: [Haskell-cafe] Re: Difficult memory leak in array processing In-Reply-To: References: Message-ID: Ah, yet another UndeadArray necromancer exhausting his stack of bones. May the forces of light suggest to structure the incantation of darkness? modifyArray arr i f = readArray arr i >>= \y -> writeArray arr i (f y) accumM :: (MArray a e m, Ix i) => (e -> e' -> e) -> a i e -> [(i, e')] -> m () accumM f arr xs = mapM_ chg xs where chg (i,x) = modifyArray arr i (flip f x) twodice (x:x':xs) = (x+x') `div` 2 : twodice xs noise rng gen = twodice $ randomRs rng gen main = do let bnds = (0, 10000000) buf <- newArray_ bnds :: IO Buffer gen <- getStdGen accumM (curry snd) buf $ zip (range bnds) $ noise (2,12) gen I absolutely don't know why there is no (accumM) function in the standard libraries. And having the ByteString API (maybe even the fusion) for general arrays would be very nice. Maybe (modifyArray) is missing, too. Regards, apfelmus PS: did you try worker low (i `seq` i-1) ? PSS: The strictness analyzer is likely to insert that automatically if you compile with -O or -O2. Niko Korhonen wrote: > Hi everyone, > > I have the following code whose purpose is to add dither (noise) to a given > array. The code looks very straightforward but apparently it has a memory > leak somewhere. Here I try to run the algorithm for an array of 10,000,000 > integers. Ten million unboxed strict integers should equal to 40MB which > should pose no problems to any modern system. However, the program fails > with a stack overflow error. I'm using GHC 6.6 on Windows with 1 GB of RAM. > > I've tried applying seq and some other strictness tricks (such as x == x) > pretty much everywhere on the code with no results. Could you please > help me > understand what is going on here? Have I misunderstood something > critical in > how Haskell works? Here is the relevant portion of the code: > > module Main where > > import Data.Array.IO > import System.Random > > type Buffer = IOUArray Int Int > > -- | Triangular Probability Density Function, equivalent to a roll of two > dice. > -- The number sums have different probabilities of surfacing. > tpdf :: (Int, Int) -> IO Int > tpdf (low, high) = do > first <- getStdRandom (randomR (low, high)) > second <- getStdRandom (randomR (low, high)) > return ((first + second) `div` 2) > > -- | Fills an array with dither generated by the specified function. > genSeries :: Buffer -> ((Int, Int) -> IO Int) -> (Int, Int) -> IO () > genSeries buf denfun lims = > let worker low i > | i >= low = do > r <- denfun lims > writeArray buf i r > worker low (i - 1) > | otherwise = return () > in do > (lo, hi) <- getBounds buf > worker lo hi > > main = do > -- This should allocate a 40 MB array > buf <- newArray_ (0, 10000000) :: IO Buffer > -- Fill the array with dither > genSeries buf tpdf (2, 12) From apfelmus at quantentunnel.de Thu Nov 23 09:19:45 2006 From: apfelmus at quantentunnel.de (apfelmus@quantentunnel.de) Date: Thu Nov 23 09:22:03 2006 Subject: [Haskell-cafe] Re: Difficult memory leak in array processing In-Reply-To: <20061123123936.GA1535@web.de> References: <20061123123936.GA1535@web.de> Message-ID: Udo Stenzel wrote: > Niko Korhonen wrote: >> I have the following code whose purpose is to add dither (noise) to a given >> array. The code looks very straightforward but apparently it has a memory leak >> somewhere. > > No, it doesn't. It can't, because it doesn't even compile. After > correcting the obvious > >> (lo, hi) <- getBounds buf > > to > > let (lo,hi) = bounds buf The interface changed between GHC 6.4.2 and 6.6. But no honorable Haskell paladin would ever dare to use UndeadArrays. > it just works and needs 40MB plus epsilon. Your problem has to be > somewhere else. The strictness analyzer likes Udo more than Niko, does it? Regards, apfelmus From kenneth.hoste at ugent.be Thu Nov 23 09:57:55 2006 From: kenneth.hoste at ugent.be (Kenneth Hoste) Date: Thu Nov 23 09:56:43 2006 Subject: [Haskell-cafe] LLVM back end In-Reply-To: <4EF4EC8D-019C-41EA-9B5B-4A6AE8707545@elis.ugent.be> References: <1164007651.6196.14.camel@localhost.localdomain> <4EF4EC8D-019C-41EA-9B5B-4A6AE8707545@elis.ugent.be> Message-ID: <6519CA77-8992-431E-928D-D11EDE8204A6@elis.ugent.be> On 20 Nov 2006, at 08:27, Michael T. Richter wrote: > I've been eyeing LLVM[1] as interesting technology -- brief > executive summary: a virtual machine suited as the back end of > compiler output with optimised native code then coming from it as > either JIT-based execution of the LLVM bytecode or as a further > compilation step -- and couldn't help but immediately think of the > possibility of one of the Haskell compiler projects providing an > LLVM code generator. I think this would help in several areas: > it could make porting the compiler to other architectures -- > including oddball ones that would be too small to otherwise support > -- easier; > it could help remove the nigh-ubiquitous reliance upon GCC as a > back-end (while I think that GCC is a pretty good piece of > software, I'm not sure it's really suited to its current role as > the "do-everything" back end); > it could leverage some of the really interesting work that's going > on in optimisation technology by letting one VM's optimiser do the > work for any number of languages; > it could improve interaction between source code written in > multiple languages. > > Is this me opening up a Pandora's Box of ignorance here? Or is > LLVM potentially interesting? (And were someone motivated into > perhaps trying to make an LLVM back-end, where would one start to > poke around in, say, the GHC codebase to even begin to implement > this? And how insane would they be driven by the process?) I've been looking at LLVM for a while too now, for research purposes. And one of the big downsides (at least for me), is the lack of a real simulator which mimicks the virtual machine. They do have a JIT compiler which allows you to execute LLVM bytecode on a number of platforms, but I'm interested in analyzing the dynamic behaviour of the LLVM bytecode, and JIT'ing doesn''t allow that. They also have an interpreter, which is probably quite similar to a simulator, but that's just horrible slow because of the SSA (hence, no registers) system used. To get to the point: I think Haskell might be a great candidate for building an LLVM bytecode simulator. I have been thinking about it, but because of my lack of coding experience (and understanding of Monads), I haven't started a project yet. If some people would be interested in such a thing though, we might join to make this a succes. I'm not LLVM expert, and surely no Haskell expert either, but I think such a project can be pretty interesting. greetings, Kenneth -- Statistics are like a bikini. What they reveal is suggestive, but what they conceal is vital (Aaron Levenstein) Kenneth Hoste ELIS - Ghent University kenneth.hoste@elis.ugent.be http://www.elis.ugent.be/~kehoste From jo at durchholz.org Thu Nov 23 13:44:10 2006 From: jo at durchholz.org (Joachim Durchholz) Date: Thu Nov 23 13:42:37 2006 Subject: [Haskell-cafe] Re: Type Error. Why!? In-Reply-To: <404396ef0611220643u15675ae5w71945120e4f79f60@mail.gmail.com> References: <404396ef0611211652o8affdcex55733c8b334265c1@mail.gmail.com> <404396ef0611220643u15675ae5w71945120e4f79f60@mail.gmail.com> Message-ID: Neil Mitchell schrieb: > How is this an FAQ: > http://www.haskell.org/haskellwiki/Why_Haskell_just_works > > It's a nice piece of marketing, but I can't imagine anyone has ever > asked Why Haskell just works, unless they've already used it, in which > case they've moved past an FAQ. Oh, but that kind of question regularly crops up after Haskell programmers have claimed that Haskell "just works". So yes indeed that's a FAQ. Regards, Jo From dagit at eecs.oregonstate.edu Thu Nov 23 15:18:32 2006 From: dagit at eecs.oregonstate.edu (Jason Dagit) Date: Thu Nov 23 15:17:11 2006 Subject: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> Message-ID: A comment on that video said: ----- BEGIN QUOTE ----? It seems to me that STM creates new problems with composability. You create two classes of code: atomic methods and non atomic methods. Nonatomic methods can easily call atomic ones ? the compiler could even automatically inject the atomic block if the programmer forgot. Atomic methods and blocks cannot be allowed to call nonatomic code. The nonatomic code could do I/O or other irrevocable things that would be duplicated when the block had to retry. ---- END QUOTE ---- I imagine an example like this (some pseudo code for a side effect happy OO language): class Foo { protected int counter; // assume this gets initialized to 0 public doSomething() { atomic{ counter++; Console.Write("called doSomething execution# " + counter); // something which could cause the transaction to restart } } public doOtherThing() { atomic{ doSomething(); // something which could cause the transaction to restart } } } Now imagine doSomething gets restarted, then we see the console output once each time and counter gets incremented. So one solution would be to move the side effects (counter++ and the console write) to happen before the atomic block. This works for doSomething, but now what if we called doOtherThing instead? We're back to having the extra side-effects from the failed attempts at doSomething, right? We just lost composability of doSomething? I'm assuming counter is only meant to be incremented once per successful run of doSomething and we only want to see the output to the log file once per successful run, but it needs to come before the log output inside doSomething so that the log makes sense. I realize STM is not a silver bullet, but it does seem like side-effects do not play nicely with STM. What is the proposed solution to this? Am I just missing something simple? Is the solution to make it so that Console.Write can be rolled back too? Thanks, Jason On 11/23/06, Bayley, Alistair wrote: > http://channel9.msdn.com/Showpost.aspx?postid=231495 > > The links to the video are a couple of yellow buttons at the bottom of > the article: "Watch" or "Download". > > I haven't watched this yet (it's nearly an hour long, I think). Found > via reddit (http://reddit.com). > > Haskeller's on TV (sort of...) woot woot! > > Alistair > ***************************************************************** > Confidentiality Note: The information contained in this message, > and any attachments, may contain confidential and/or privileged > material. It is intended solely for the person(s) or entity to > which it is addressed. Any review, retransmission, dissemination, > or taking of any action in reliance upon this information by > persons or entities other than the intended recipient(s) is > prohibited. If you received this in error, please contact the > sender and delete the material from any computer. > ***************************************************************** > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > From cgibbard at gmail.com Thu Nov 23 15:44:07 2006 From: cgibbard at gmail.com (Cale Gibbard) Date: Thu Nov 23 15:42:47 2006 Subject: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> Message-ID: <89ca3d1f0611231244j3d6dcaa7i84356813324422be@mail.gmail.com> On 23/11/06, Jason Dagit wrote: > A comment on that video said: > > ----- BEGIN QUOTE ---- > It seems to me that STM creates new problems with composability. > You create two classes of code: atomic methods and non atomic methods. > > Nonatomic methods can easily call atomic ones ? the compiler could > even automatically inject the atomic block if the programmer forgot. > > Atomic methods and blocks cannot be allowed to call nonatomic code. > The nonatomic code could do I/O or other irrevocable things that would > be duplicated when the block had to retry. > ---- END QUOTE ---- > > I imagine an example like this (some pseudo code for a side effect > happy OO language): > > class Foo { > protected int counter; // assume this gets initialized to 0 > public doSomething() { > atomic{ > counter++; > Console.Write("called doSomething execution# " + counter); > // something which could cause the transaction to restart > } > } > public doOtherThing() { > atomic{ > doSomething(); > // something which could cause the transaction to restart > } > } > } > > Now imagine doSomething gets restarted, then we see the console output > once each time and counter gets incremented. So one solution would be > to move the side effects (counter++ and the console write) to happen > before the atomic block. This works for doSomething, but now what if > we called doOtherThing instead? We're back to having the extra > side-effects from the failed attempts at doSomething, right? We just > lost composability of doSomething? I'm assuming counter is only meant > to be incremented once per successful run of doSomething and we only > want to see the output to the log file once per successful run, but it > needs to come before the log output inside doSomething so that the log > makes sense. > > I realize STM is not a silver bullet, but it does seem like > side-effects do not play nicely with STM. What is the proposed > solution to this? Am I just missing something simple? Is the > solution to make it so that Console.Write can be rolled back too? > > Thanks, > Jason The solution is to simply not allow side effecting computations in transactions. They talk a little about it in the video, but perhaps that's not clear. The only side effects an atomic STM transaction may have are changes to shared memory. Another example in pseudocode: atomic x <- launchMissiles if (x < 5) then retry This is obviously catastrophic. If launchMissiles has the side effect of launching a salvo of missiles, and then the retry occurs, it's unlikely that rolling back the transaction is going to be able to put them back on the launchpad. Worse yet, if some variable read in launchMissiles changes, the transaction would retry, possibly causing a second salvo of missiles to be launched. So you simply disallow this. The content of a transaction may only include reads and writes to shared memory, along with pure computations. This is especially easy in Haskell, because one simply uses a new monad STM, with no way to lift IO actions into that monad, but atomically :: (STM a -> IO a) goes in the other direction, turning a transaction into IO. In other languages, you'd want to add some static typechecking to ensure that this constraint was enforced. - Cale From isto.aho at dnainternet.net Thu Nov 23 16:25:23 2006 From: isto.aho at dnainternet.net (isto) Date: Thu Nov 23 16:23:59 2006 Subject: [Haskell-cafe] list monad and controlling the backtracking Message-ID: <1164317123.19751.11.camel@localhost.localdomain> Hi all, Weekly news had a link to article "Local and global side effects with monad transformers" and the following is from there (minor modification done): import Control.Monad.List import Control.Monad.State import Control.Monad.Writer test5 :: StateT Integer (ListT (Writer [Char])) Integer test5 = do a <- lift $ mlist aList b <- lift $ mlist bList lift $ lift $ tell ("trying "++show a++" "++show b++"\n") modify (+1) guard $ a+b<5 return $ a+b go5 = runWriter $ runListT $ runStateT test5 0 If the aList = [1..5] as well as bList, then there will be 25 tryings. If aList and bList are [1..10000000], there will be a lot of tryings... However, guard is saying that we are interested in only values whose sum is less than 5. Is it possible to control easily in the above example that when we have tried out pairs (1,1), (1,2), (1,3), (1,4), that now we are ready to stop trying from the bList? And then similarly when we finally arrive to a pair (4,1), that now we are ready to finish also with aList? This would give a nice way to build branch & bounding algorithms, even though it does not take much more lines to do it in some other way. br, Isto From u.stenzel at web.de Thu Nov 23 16:13:25 2006 From: u.stenzel at web.de (Udo Stenzel) Date: Thu Nov 23 16:29:54 2006 Subject: [Haskell-cafe] Re: Difficult memory leak in array processing In-Reply-To: References: <20061123123936.GA1535@web.de> Message-ID: <20061123211325.GB1535@web.de> apfelmus@quantentunnel.de wrote: > >> (lo, hi) <- getBounds buf > > > > to > > > > let (lo,hi) = bounds buf > > The interface changed between GHC 6.4.2 and 6.6. > But no honorable Haskell paladin would ever dare to use UndeadArrays. Hm, and 'bounds' is simply gone? Hope that doesn't bite in an unexpected way. > The strictness analyzer likes Udo more than Niko, does it? So it seems. I just tried it with GHC 6.6 and there still is no leak and no stack overflow. And frankly, I can't even see where too much lazyness could creep into this code. Everything is sequenced by IO, the array is unboxed, there's hardly any room for an unexpected thunk to hide in. -Udo -- "Science is like sex - sometimes something useful comes out of it, but that's not what we are doing it for." -- Richard Feynman -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061123/2f051c42/attachment.bin From isto.aho at dnainternet.net Thu Nov 23 16:32:25 2006 From: isto.aho at dnainternet.net (isto) Date: Thu Nov 23 16:31:02 2006 Subject: [Haskell-cafe] type keeping rounding, typeable (and a difficulty) In-Reply-To: <20061116220251.GC1739@sleepingsquirrel.org> References: <1163624692.23061.15.camel@localhost.localdomain> <20061115213130.GA1730@sleepingsquirrel.org> <1163709899.22561.14.camel@localhost.localdomain> <20061116220251.GC1739@sleepingsquirrel.org> Message-ID: <1164317546.19751.15.camel@localhost.localdomain> Hi & thanks! to, 2006-11-16 kello 14:02 -0800, Greg Buchholz kirjoitti: > ] I'll guess the reason it didn't compile was different > ] types at case branches (am I wrong?) > > Correct. > > ] Anyhow, do you know that is it possible to choose the return type > ] somehow in the spirit above? > > Maybe you want something like... This time, however, I'm not sure after seeing oleg's email: http://www.haskell.org/pipermail/haskell/2006-November/018736.html I'll have yet to re-read it carefully to be sure... :) br, Isto From ithika at gmail.com Thu Nov 23 16:34:49 2006 From: ithika at gmail.com (Dougal Stanton) Date: Thu Nov 23 16:31:14 2006 Subject: [Haskell-cafe] Equivalent of if/then/else for IO Bool? Message-ID: <20061123213449.GS22797@glowfish> Is there some sort of equivalent of the if/then/else construct for use in the IO monad? For instance the following can get quite tedious: > do bool <- doesFileExist filename > if bool > then sth > else sth' Is there a more compact way of writing that? Something akin to: > condM (doesFileExist filename) (sth) (sth') Or maybe there's a more sensible way of doing the above that I've missed. I seem to use endless alternate conditions sometimes and there's bound to be a better way. From benjamin.franksen at bessy.de Thu Nov 23 16:45:55 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Thu Nov 23 16:48:48 2006 Subject: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> <89ca3d1f0611231244j3d6dcaa7i84356813324422be@mail.gmail.com> Message-ID: [sorry for quoting so much, kinda hard to decide here where to snip] Cale Gibbard wrote: > On 23/11/06, Jason Dagit wrote: >> A comment on that video said: >> >> ----- BEGIN QUOTE ---- >> It seems to me that STM creates new problems with composability. >> You create two classes of code: atomic methods and non atomic methods. >> >> Nonatomic methods can easily call atomic ones ? the compiler could >> even automatically inject the atomic block if the programmer forgot. >> >> Atomic methods and blocks cannot be allowed to call nonatomic code. >> The nonatomic code could do I/O or other irrevocable things that would >> be duplicated when the block had to retry. >> ---- END QUOTE ---- >> >> I imagine an example like this (some pseudo code for a side effect >> happy OO language): >> >> class Foo { >> protected int counter; // assume this gets initialized to 0 >> public doSomething() { >> atomic{ >> counter++; >> Console.Write("called doSomething execution# " + counter); >> // something which could cause the transaction to restart >> } >> } >> public doOtherThing() { >> atomic{ >> doSomething(); >> // something which could cause the transaction to restart >> } >> } >> } >> >> Now imagine doSomething gets restarted, then we see the console output >> once each time and counter gets incremented. So one solution would be >> to move the side effects (counter++ and the console write) to happen >> before the atomic block. This works for doSomething, but now what if >> we called doOtherThing instead? We're back to having the extra >> side-effects from the failed attempts at doSomething, right? We just >> lost composability of doSomething? I'm assuming counter is only meant >> to be incremented once per successful run of doSomething and we only >> want to see the output to the log file once per successful run, but it >> needs to come before the log output inside doSomething so that the log >> makes sense. >> >> I realize STM is not a silver bullet, but it does seem like >> side-effects do not play nicely with STM. What is the proposed >> solution to this? Am I just missing something simple? Is the >> solution to make it so that Console.Write can be rolled back too? > > The solution is to simply not allow side effecting computations in > transactions. They talk a little about it in the video, but perhaps > that's not clear. The only side effects an atomic STM transaction may > have are changes to shared memory. > > Another example in pseudocode: > > atomic > x <- launchMissiles > if (x < 5) then retry > > This is obviously catastrophic. If launchMissiles has the side effect > of launching a salvo of missiles, and then the retry occurs, it's > unlikely that rolling back the transaction is going to be able to put > them back on the launchpad. Worse yet, if some variable read in > launchMissiles changes, the transaction would retry, possibly causing > a second salvo of missiles to be launched. > > So you simply disallow this. The content of a transaction may only > include reads and writes to shared memory, along with pure > computations. This is especially easy in Haskell, because one simply > uses a new monad STM, with no way to lift IO actions into that monad, > but atomically :: (STM a -> IO a) goes in the other direction, turning > a transaction into IO. In other languages, you'd want to add some > static typechecking to ensure that this constraint was enforced. This is of course the technically correct answer. However, I suspect that it may not be completely satisfying to the practitioner. What if you want or even need your output to be atomically tied to a pure software transaction? One answer is in fact "to make it so that Console.Write can be rolled back too". To achieve this one can factor the actual output to another task and inside the transaction merely send the message to a transactional channel (TChan): atomic $ do increment counter counterval <- readvar counter sendMsg msgChan ("called doSomething execution# " ++ show counterval) -- something which could cause the transaction to restart Another task regularly takes messages from the channel and actually outputs them. Of course the output will be somewhat delayed, but the order of messages will be preserved between tasks sending to the same channel. And the message will only be sent if and only if the transaction commits. Unfortunately I can't see how to generalize this to input as well... Cheers Ben From benjamin.franksen at bessy.de Thu Nov 23 16:54:32 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Thu Nov 23 16:53:47 2006 Subject: [Haskell-cafe] Re: list monad and controlling the backtracking References: <1164317123.19751.11.camel@localhost.localdomain> Message-ID: isto wrote: > Hi all, > > Weekly news had a link to article > "Local and global side effects with monad transformers" > and the following is from there (minor modification done): > > import Control.Monad.List > import Control.Monad.State > import Control.Monad.Writer > > test5 :: StateT Integer (ListT (Writer [Char])) Integer > > test5 = do > a <- lift $ mlist aList > b <- lift $ mlist bList > lift $ lift $ tell ("trying "++show a++" "++show b++"\n") > modify (+1) > guard $ a+b<5 > return $ a+b > > go5 = runWriter $ runListT $ runStateT test5 0 > > > If the aList = [1..5] as well as bList, then there will be 25 tryings. > If aList and bList are [1..10000000], there will be a lot of tryings... > > However, guard is saying that we are interested in only values > whose sum is less than 5. > > Is it possible to control easily in the above example that when we > have tried out pairs (1,1), (1,2), (1,3), (1,4), that now we are > ready to stop trying from the bList? And then similarly when we > finally arrive to a pair (4,1), that now we are ready to finish > also with aList? If I understood you correctly you seem to want a monad that offers something akin to Prolog's cut. You might want to take a look at http://okmij.org/ftp/Computation/monads.html#LogicT Cheers Ben From dagit at eecs.oregonstate.edu Thu Nov 23 17:00:33 2006 From: dagit at eecs.oregonstate.edu (Jason Dagit) Date: Thu Nov 23 16:59:10 2006 Subject: [Haskell-cafe] Equivalent of if/then/else for IO Bool? In-Reply-To: <20061123213449.GS22797@glowfish> References: <20061123213449.GS22797@glowfish> Message-ID: On 11/23/06, Dougal Stanton wrote: > Is there some sort of equivalent of the if/then/else construct for use > in the IO monad? For instance the following can get quite tedious: > > > do bool <- doesFileExist filename > > if bool > > then sth > > else sth' > > Is there a more compact way of writing that? Something akin to: > > > condM (doesFileExist filename) (sth) (sth') Maybe there is one built in but don't know it or see anything in hoogle. I'd use something like the following (and then just make it a standard part of the libraries I use personally): import Control.Monad if' b t e = if b then t else e ifM = liftM3 if' which gives ifM :: (Monad m) => m Bool -> m t -> m t -> m t HTH, Jason From benjamin.franksen at bessy.de Thu Nov 23 17:00:34 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Thu Nov 23 16:59:35 2006 Subject: [Haskell-cafe] Re: Equivalent of if/then/else for IO Bool? References: <20061123213449.GS22797@glowfish> Message-ID: Dougal Stanton wrote: > Is there some sort of equivalent of the if/then/else construct for use > in the IO monad? For instance the following can get quite tedious: > >> do bool <- doesFileExist filename >> if bool >> then sth >> else sth' > > Is there a more compact way of writing that? Something akin to: > >> condM (doesFileExist filename) (sth) (sth') > > Or maybe there's a more sensible way of doing the above that I've > missed. I seem to use endless alternate conditions sometimes and there's > bound to be a better way. Roll your own control structures! Haskell has higher order functions for a reason. This should do the trick (untested): condM condAction thenBranch elseBranch = do bool <- condAction if bool then thenBranch else elseBranch (Hack it into ghci or hugs to find out the type, it's a bit more general than what you need.) Cheers Ben From john at repetae.net Thu Nov 23 17:11:25 2006 From: john at repetae.net (John Meacham) Date: Thu Nov 23 17:09:44 2006 Subject: [Haskell-cafe] Re: Difficult memory leak in array processing In-Reply-To: <20061123211325.GB1535@web.de> References: <20061123123936.GA1535@web.de> <20061123211325.GB1535@web.de> Message-ID: <20061123221125.GA17796@momenergy.repetae.net> On Thu, Nov 23, 2006 at 10:13:25PM +0100, Udo Stenzel wrote: > apfelmus@quantentunnel.de wrote: > > >> (lo, hi) <- getBounds buf > > > > > > to > > > > > > let (lo,hi) = bounds buf > > > > The interface changed between GHC 6.4.2 and 6.6. > > But no honorable Haskell paladin would ever dare to use UndeadArrays. > > Hm, and 'bounds' is simply gone? Hope that doesn't bite in an > unexpected way. bounds is only gone for mutable arrays. Since they might change size you need to use the monad to get at their bounds. 'bounds' still exists with the same interface for immutable arrays. -- John Meacham - ?repetae.net?john? From tharris at microsoft.com Thu Nov 23 17:17:49 2006 From: tharris at microsoft.com (Tim Harris (RESEARCH)) Date: Thu Nov 23 17:16:23 2006 Subject: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> <89ca3d1f0611231244j3d6dcaa7i84356813324422be@mail.gmail.com> Message-ID: <9BF202E6B745664F896FB822A141D3310BB3BB3B@EA-EXMSG-C303.europe.corp.microsoft.com> (Dropping Haskell@hakell.org) Hi, We've not yet looked at I/O in detail in Haskell, but there's a paper from a few years back where I experimented with ways of integrating I/O with an earlier implementation of atomic blocks in Java. http://research.microsoft.com/~tharris/papers/2005-scp.pdf The basic idea is to provide a way for a transaction to call into transaction-aware libraries. The libraries can register callbacks for if the transaction commits (to actually do any "O") and for if the transaction aborts (to re-buffer any "I" that the transaction has consumed). In addition, a library providing access to another transactional abstraction (e.g. a database supporting transactions) can perform a 2-phase commit that means that the memory transaction and database transaction either both commit or both abort. Of course, these solutions don't deal with the question of atomic blocks that want to perform output (e.g. to the console) and receive input in response to that. My view at the moment is _that does not make sense in an atomic block_ -- the output and input can't be performed atomically because the intervening state must be visible for the user to respond to. We also briefly experimented with extending the SXM system Maurice Herlihy worked on at MSR Cambridge to support transactions that include accesses to the file system and registry -- http://msdn2.microsoft.com/en-us/library/aa366295.aspx describes the TxF and TxR systems it was built over. Some other interesting work in this area is Elliot Moss' papers on "open nested" transactions -- these provide another building block at the same level as the Java system I mentioned: library writers can use them with care to extend the range of things that can be done inside an atomic block. Cheers, Tim -----Original Message----- From: haskell-bounces@haskell.org [mailto:haskell-bounces@haskell.org] On Behalf Of Benjamin Franksen Sent: 24 November 2006 03:16 To: haskell@haskell.org Cc: haskell-cafe@haskell.org Subject: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video [sorry for quoting so much, kinda hard to decide here where to snip] Cale Gibbard wrote: > On 23/11/06, Jason Dagit wrote: >> A comment on that video said: >> >> ----- BEGIN QUOTE ---- >> It seems to me that STM creates new problems with composability. >> You create two classes of code: atomic methods and non atomic methods. >> >> Nonatomic methods can easily call atomic ones ? the compiler could >> even automatically inject the atomic block if the programmer forgot. >> >> Atomic methods and blocks cannot be allowed to call nonatomic code. >> The nonatomic code could do I/O or other irrevocable things that would >> be duplicated when the block had to retry. >> ---- END QUOTE ---- >> >> I imagine an example like this (some pseudo code for a side effect >> happy OO language): >> >> class Foo { >> protected int counter; // assume this gets initialized to 0 >> public doSomething() { >> atomic{ >> counter++; >> Console.Write("called doSomething execution# " + counter); >> // something which could cause the transaction to restart >> } >> } >> public doOtherThing() { >> atomic{ >> doSomething(); >> // something which could cause the transaction to restart >> } >> } >> } >> >> Now imagine doSomething gets restarted, then we see the console output >> once each time and counter gets incremented. So one solution would be >> to move the side effects (counter++ and the console write) to happen >> before the atomic block. This works for doSomething, but now what if >> we called doOtherThing instead? We're back to having the extra >> side-effects from the failed attempts at doSomething, right? We just >> lost composability of doSomething? I'm assuming counter is only meant >> to be incremented once per successful run of doSomething and we only >> want to see the output to the log file once per successful run, but it >> needs to come before the log output inside doSomething so that the log >> makes sense. >> >> I realize STM is not a silver bullet, but it does seem like >> side-effects do not play nicely with STM. What is the proposed >> solution to this? Am I just missing something simple? Is the >> solution to make it so that Console.Write can be rolled back too? > > The solution is to simply not allow side effecting computations in > transactions. They talk a little about it in the video, but perhaps > that's not clear. The only side effects an atomic STM transaction may > have are changes to shared memory. > > Another example in pseudocode: > > atomic > x <- launchMissiles > if (x < 5) then retry > > This is obviously catastrophic. If launchMissiles has the side effect > of launching a salvo of missiles, and then the retry occurs, it's > unlikely that rolling back the transaction is going to be able to put > them back on the launchpad. Worse yet, if some variable read in > launchMissiles changes, the transaction would retry, possibly causing > a second salvo of missiles to be launched. > > So you simply disallow this. The content of a transaction may only > include reads and writes to shared memory, along with pure > computations. This is especially easy in Haskell, because one simply > uses a new monad STM, with no way to lift IO actions into that monad, > but atomically :: (STM a -> IO a) goes in the other direction, turning > a transaction into IO. In other languages, you'd want to add some > static typechecking to ensure that this constraint was enforced. This is of course the technically correct answer. However, I suspect that it may not be completely satisfying to the practitioner. What if you want or even need your output to be atomically tied to a pure software transaction? One answer is in fact "to make it so that Console.Write can be rolled back too". To achieve this one can factor the actual output to another task and inside the transaction merely send the message to a transactional channel (TChan): atomic $ do increment counter counterval <- readvar counter sendMsg msgChan ("called doSomething execution# " ++ show counterval) -- something which could cause the transaction to restart Another task regularly takes messages from the channel and actually outputs them. Of course the output will be somewhat delayed, but the order of messages will be preserved between tasks sending to the same channel. And the message will only be sent if and only if the transaction commits. Unfortunately I can't see how to generalize this to input as well... Cheers Ben _______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell From john at repetae.net Thu Nov 23 17:20:04 2006 From: john at repetae.net (John Meacham) Date: Thu Nov 23 17:18:20 2006 Subject: [Haskell-cafe] type keeping rounding, typeable (and a difficulty) In-Reply-To: <1163709899.22561.14.camel@localhost.localdomain> References: <1163624692.23061.15.camel@localhost.localdomain> <20061115213130.GA1730@sleepingsquirrel.org> <1163709899.22561.14.camel@localhost.localdomain> Message-ID: <20061123222004.GB17796@momenergy.repetae.net> On Thu, Nov 16, 2006 at 10:44:59PM +0200, isto wrote: > I'll guess the reason it didn't compile was different > types at case branches (am I wrong?) Anyhow, do you know that > is it possible to choose the return type somehow in the spirit > above? GADTs let you do this. And they even omit the run time type check. though, the type class solution is the correct way to do this sort of thing. data Value a where IntLike :: Int -> Value Int CharLike :: Char -> Value Char f :: Value a -> a f x = case x of IntLike x -> x + 1 CharLike x -> x:" plus one" there is also Data.Dynamic and existential types which are related to the task. John -- John Meacham - ?repetae.net?john? From hjgtuyl at chello.nl Thu Nov 23 17:22:36 2006 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Thu Nov 23 17:21:16 2006 Subject: [Haskell-cafe] Equivalent of if/then/else for IO Bool? In-Reply-To: <20061123213449.GS22797@glowfish> References: <20061123213449.GS22797@glowfish> Message-ID: You can use 'when' or 'unless' from the module Control.Monad, but they each have only one branch, see: http://members.chello.nl/hjgtuyl/tourdemonad.html#unless and http://members.chello.nl/hjgtuyl/tourdemonad.html#when You can create a monadic 'if' like this (in an interactive session): Control.Monad> let ifM p a b = do { p' <- p; if p' then return a else return b } in ifM (Just True) 1 2 Just 1 Met vriendelijke groet, Henk-Jan van Tuyl -- On Thu, 23 Nov 2006 22:34:49 +0100, Dougal Stanton wrote: > Is there some sort of equivalent of the if/then/else construct for use > in the IO monad? For instance the following can get quite tedious: > >> do bool <- doesFileExist filename >> if bool >> then sth >> else sth' > > Is there a more compact way of writing that? Something akin to: > >> condM (doesFileExist filename) (sth) (sth') > > Or maybe there's a more sensible way of doing the above that I've > missed. I seem to use endless alternate conditions sometimes and there's > bound to be a better way. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe -- http://Van.Tuyl.eu/ -- Using Opera's revolutionary e-mail client: https://secure.bmtmicro.com/opera/buy-opera.html?AID=789433 From haskell.org at liyang.hu Thu Nov 23 17:42:57 2006 From: haskell.org at liyang.hu (Liyang HU) Date: Thu Nov 23 17:41:37 2006 Subject: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> <89ca3d1f0611231244j3d6dcaa7i84356813324422be@mail.gmail.com> Message-ID: Hi, On 23/11/06, Benjamin Franksen wrote: > One answer is in fact "to make it so that Console.Write can be rolled back > too". To achieve this one can factor the actual output to another task and > inside the transaction merely send the message to a transactional channel > (TChan): So, you could simply return the console output as (part of) the result of the atomic action. Wrap it in a WriterT monad transformer, even. (one, console) <- atomic $ runWriterT $ do tell "hello world\n" return 1 putStr console (Not terribly efficient, but you get the idea.) You're just calculating what output to make inside the transaction; the actual outputting happens outside, once the transaction commits. > Another task regularly takes messages from the channel With STM, the outputter task won't see any messages from the channel until your main atomic block completes, after which you're living in IO-land, so you might as well do the output yourself. Pugs/Perl 6 takes the approach that any IO inside an atomic block raises an exception. > Unfortunately I can't see how to generalize this to input as well... The dual of how you described the output situation: read a block of input before the transaction starts, and consume this during the transaction. I guess you're not seeing how this generalises because potentially you won't know how much of the input you will need to read beforehand... (so read all available input?(!) You have the dual situation in the output case, in that you can't be sure how much output it may generate / you will need to buffer.) input <- hGetContent file atomic $ flip runReaderT input $ do input <- ask -- do something with input return 42 (This is actually a bad example, since hGetContents reads the file lazily with interleaved IO...) later, /Liyang From zacara at gmail.com Thu Nov 23 17:51:27 2006 From: zacara at gmail.com (Clare) Date: Thu Nov 23 17:50:07 2006 Subject: [Haskell-cafe] working with lists of couples In-Reply-To: <455E2F1C.1010609@ijs.si> References: <455E0465.2000209@ijs.si> <455E2F1C.1010609@ijs.si> Message-ID: Yes the code you are suggesting is certainly linear and it takes without doubt time n. But I was looking for a solution using foldl that of course takes time n. The problem of the following solution is that it gives a reversed result, and of course i can't just reverse the result. couples = snd . foldl f (0,[]) where f (s,[]) x = (s+x, [(x,0)]) f (s,xs) x = (s+x, (:) (x,s) xs) Clare 2006/11/17, Valentin Gjorgjioski : > > On 17.11.2006 21:04 Clare wrote: > > I'm not sure it takes time n couse of the operator ++ and the lazy > > stuffs in haskell. > Ok, you can use > buildCouples (x:xs) s = (x,s) : (buildCouples xs (x+s)) > instead of ++ > > this algorithm is linear, I don't know why(?) you think it is not. > > Valentin > > -- > Valentin Gjorgjioski > Bachelor of Computer Science > Department of Knowledge Technologies, Jozef Stefan Institute > Jamova 39, SI-1000 Ljubljana, Slovenia > Phone: +386 1 477 3343 > Fax: +386 1 477 3315 > Web: http://kt.ijs.si/ValentinGjorgjioski/ > Email: Valentin.Gjorgjioski@ijs.si > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061123/886bb26e/attachment.htm From ctm at cs.nott.ac.uk Thu Nov 23 18:01:01 2006 From: ctm at cs.nott.ac.uk (Conor McBride) Date: Thu Nov 23 17:59:42 2006 Subject: [Haskell-cafe] Equivalent of if/then/else for IO Bool? In-Reply-To: References: <20061123213449.GS22797@glowfish> Message-ID: <4566282D.9000300@cs.nott.ac.uk> Jason Dagit wrote: > On 11/23/06, Dougal Stanton wrote: >> Is there some sort of equivalent of the if/then/else construct for use >> in the IO monad? For instance the following can get quite tedious: >> >> > do bool <- doesFileExist filename >> > if bool >> > then sth >> > else sth' >> >> Is there a more compact way of writing that? Something akin to: >> >> > condM (doesFileExist filename) (sth) (sth') > > Maybe there is one built in but don't know it or see anything in > hoogle. I'd use something like the following (and then just make it a > standard part of the libraries I use personally): > > import Control.Monad > > if' b t e = if b then t else e > ifM = liftM3 if' > > which gives ifM :: (Monad m) => m Bool -> m t -> m t -> m t No! You can really screw up this way... Your function will perform the effects of the Bool and *both* branch computation in sequence, then use the returned Bool value to select between the returned 'then' value and the returned 'else' value. Do not use it to operate machinery! *Grr> ifM (Just True) (Just 3) Nothing Nothing More care required! Conor From benjamin.franksen at bessy.de Thu Nov 23 19:34:34 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Thu Nov 23 19:33:25 2006 Subject: [Haskell-cafe] Re: [Haskell] Re: SimonPJ and Tim Harris explain STM - video References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> <89ca3d1f0611231244j3d6dcaa7i84356813324422be@mail.gmail.com> Message-ID: Hi Liyang HU you wrote: > On 23/11/06, Benjamin Franksen wrote: >> One answer is in fact "to make it so that Console.Write can be rolled >> back too". To achieve this one can factor the actual output to another >> task and inside the transaction merely send the message to a >> transactional channel (TChan): > > So, you could simply return the console output as (part of) the result > of the atomic action. Wrap it in a WriterT monad transformer, even. But this would break atomicity, wouldn't it? Another call to doSomething from another task could interrupt before I get the chance to do the actual output. With a channel whatever writes will happen in the same order in which the STM actions commit (which coincides with the order in which the counters get incremented). >> Another task regularly takes messages from the channel > > With STM, the outputter task won't see any messages from the channel > until your main atomic block completes, after which you're living in > IO-land, so you might as well do the output yourself. Yeah, right. Separate task might still be preferable, otherwise you have to take care not to forget to actually do the IO after each transaction. I guess it even makes sense to hide the channel stuff behind some nice abstraction, so inside the transaction it looks similar to a plain IO action: output port msg The result is in fact mostly indistiguishable from a direct IO call due to the fact that IO is buffered in the OS anyway. > Pugs/Perl 6 takes the approach that any IO inside an atomic block > raises an exception. > >> Unfortunately I can't see how to generalize this to input as well... > > The dual of how you described the output situation: read a block of > input before the transaction starts, and consume this during the > transaction. I guess you're not seeing how this generalises because > potentially you won't know how much of the input you will need to read > beforehand... (so read all available input?(!) You have the dual > situation in the output case, in that you can't be sure how much > output it may generate / you will need to buffer.) You say it. I guess the main difference is that I have a pretty good idea how much data is going to be produced by my own code, and if it's a bit more than I calculated then the whole process merely uses up some more memory, which is usually not a big problem. However, with input things are different: in many cases the input length is not under my control and could be arbitrarily large. If I read until my buffer is full and I still haven't got enough data, my transaction will be stuck with no way to demand more input. (however, see below) > input <- hGetContent file > atomic $ flip runReaderT input $ do > input <- ask > -- do something with input > return 42 > > (This is actually a bad example, since hGetContents reads the file > lazily with interleaved IO...) In fact reading everything lazily seems to be the only way out, if you don't want to have arbitrary limits for chunks of input. OTOH, maybe limiting the input chunks to some maximum length is a good idea regardless of STM and whatnot. Some evil data source may want to crash my process by making it eat more and more memory... So, after all you are probably right and there is an obvious generalization to input. Cool. Cheers Ben From ithika at gmail.com Thu Nov 23 20:18:53 2006 From: ithika at gmail.com (Dougal Stanton) Date: Thu Nov 23 20:15:07 2006 Subject: [Haskell-cafe] Command line prompt templates Message-ID: <20061124011853.GU22797@glowfish> I was trying to write my own equivalent to Don Stewart's mkcabal but ended up getting sidetracked. I made some generalised prompts for use at the command line and wanted to get some feedback on them. The full code can be found at [1] but the basic summary is like this: > prompt :: String -> IO String Simple prompt - supply a question and receive the user's answer. > promptYesNo :: String -> Maybe String -> IO Bool A yes/no question, with an optional value to ask about. I suppose this could be simplified to just one string. > promptList :: String -> [String] -> Maybe Integer -> IO Integer Ask the user to choose from a list, where the result is the number chosen. The optional value is a default if the user doesn't pick a number. > promptListEdit :: String -> [String] -> Maybe Integer -> IO String As above, but the last option in the list is an invitation to provide your own answer. Again the optional value is the default choice if nothing else is chosen. The result here is necessarily the string rather than the integer cos I didn't want to complicate matters further with stuff like Either types. If you can see any flaws or have any suggestions please let me know! Cheers, D. [1]: From haskell.org at liyang.hu Thu Nov 23 20:21:03 2006 From: haskell.org at liyang.hu (Liyang HU) Date: Thu Nov 23 20:19:42 2006 Subject: [Haskell-cafe] Re: [Haskell] Re: SimonPJ and Tim Harris explain STM - video In-Reply-To: References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> <89ca3d1f0611231244j3d6dcaa7i84356813324422be@mail.gmail.com> Message-ID: Hallo, On 24/11/06, Benjamin Franksen wrote: > > So, you could simply return the console output as (part of) the result > > of the atomic action. Wrap it in a WriterT monad transformer, even. > But this would break atomicity, wouldn't it? In the sense as you just described, yes. You're right: there's no guarantee that something else might not jump in between the call to atomic and the following putStr, so the TVar changes in the atomic block no longer take place in step with the output actions. > I have a pretty good idea how much data is going to be produced by > my own code, and if it's a bit more than I calculated then the whole > process merely uses up some more memory, which is usually not a > big problem. However, with input things are different: Really? I'd have said that I have a pretty good idea how much data is going to be consumed by my own code, and if it's a bit more than I calculated then I'd merely read some more at the beginning (putting any unused bits back on the input queue afterwards of course), which is usually not a big problem. :) Yes, I do get your point. It's easier to allocate a larger buffer for your output as needed, than to anticipate how much input you might require. I'd still claim they're different instances of the same scheme though! > [If] I still haven't got enough data, my transaction will be stuck with no way to demand more input. Take your output channel idea, and use that for input too? (Separate thread to read the input and place it at the end of some queue.) You would basically retry and block (or rather, STM would do the latter for you) if you haven't enough data, until more came along. Cheers, /Liyang From dons at cse.unsw.edu.au Thu Nov 23 21:03:03 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Thu Nov 23 21:01:44 2006 Subject: [Haskell-cafe] Command line prompt templates In-Reply-To: <20061124011853.GU22797@glowfish> References: <20061124011853.GU22797@glowfish> Message-ID: <20061124020303.GB2428@cse.unsw.EDU.AU> ithika: > I was trying to write my own equivalent to Don Stewart's mkcabal but > ended up getting sidetracked. I made some generalised prompts for use at > the command line and wanted to get some feedback on them. > > The full code can be found at [1] but the basic summary is like this: > > > prompt :: String -> IO String > > Simple prompt - supply a question and receive the user's answer. > > > promptYesNo :: String -> Maybe String -> IO Bool > > A yes/no question, with an optional value to ask about. I suppose this > could be simplified to just one string. > > > promptList :: String -> [String] -> Maybe Integer -> IO Integer > > Ask the user to choose from a list, where the result is the number > chosen. The optional value is a default if the user doesn't pick a > number. > > > promptListEdit :: String -> [String] -> Maybe Integer -> IO String > > As above, but the last option in the list is an invitation to provide > your own answer. Again the optional value is the default choice if > nothing else is chosen. The result here is necessarily the string rather > than the integer cos I didn't want to complicate matters further with > stuff like Either types. > > If you can see any flaws or have any suggestions please let me know! Looks pretty good, though you use case x :: Bool of True -> ... False -> ... when if x then ... else ... would be preferred. I wonder if there's a prompt API out there for python or something you could use for inspiration? -- Don From sethg at ropine.com Thu Nov 23 23:59:56 2006 From: sethg at ropine.com (Seth Gordon) Date: Thu Nov 23 23:58:52 2006 Subject: [Haskell-cafe] strange type mismatch when trying to use takusen Message-ID: <45667C4C.9000305@ropine.com> I have a simple test program for takusen and PostgreSQL: > import Database.Enumerator > import Database.PostgreSQL.Enumerator > import Control.Monad.Trans > > gazdbSession dbname = connect [CAdbname dbname] > > resultCollector :: (Monad m) => String -> IterAct m [String] > resultCollector str accum = result' (str:accum) > > main = do withSession (connect [CAdbname "template1"]) $ main' > > main' = do r <- doQuery (sql "select 'fred'") resultCollector [] > liftIO $ putStrLn $ show r But it won't compile: [1 of 1] Compiling Main ( takusen-test.hs, takusen-test.o ) takusen-test.hs:11:57: Couldn't match expected type `forall mark. DBM mark Session a' against inferred type `DBM mark sess ()' In the second argument of `($)', namely `main'' In the expression: (withSession (connect [CAdbname "template1"])) $ main' In the expression: do (withSession (connect [CAdbname "template1"])) $ main' Adding an explicit "main' :: DBM mark Session ()" type signature doesn't change the error message. The takusen source that I'm using was updated from darcs on November 14 and compiled with ghc 6.6. From luis at arjox.org Fri Nov 24 00:17:25 2006 From: luis at arjox.org (Luis F. Araujo) Date: Fri Nov 24 00:25:33 2006 Subject: [Haskell-cafe] Equivalent of if/then/else for IO Bool? In-Reply-To: <20061123213449.GS22797@glowfish> References: <20061123213449.GS22797@glowfish> Message-ID: <45668065.2040200@arjox.org> Dougal Stanton wrote: > Is there some sort of equivalent of the if/then/else construct for use > in the IO monad? For instance the following can get quite tedious: > > >> do bool <- doesFileExist filename >> if bool >> then sth >> else sth' >> > > Is there a more compact way of writing that? Something akin to: > > >> condM (doesFileExist filename) (sth) (sth') >> > > Or maybe there's a more sensible way of doing the above that I've > missed. I seem to use endless alternate conditions sometimes and there's > bound to be a better way. > > I don't know any existing function like this in the current libs. Here i paste probably a possible implementation for one. if' :: (Monad m) => m Bool -> m b -> m b -> m b if' mb mt mf = mb >>= if'' where if'' b = if b then mt else mf Regards, From taralx at gmail.com Fri Nov 24 01:13:11 2006 From: taralx at gmail.com (Taral) Date: Fri Nov 24 01:11:50 2006 Subject: [Haskell-cafe] strange type mismatch when trying to use takusen In-Reply-To: <45667C4C.9000305@ropine.com> References: <45667C4C.9000305@ropine.com> Message-ID: On 11/23/06, Seth Gordon wrote: > takusen-test.hs:11:57: > Couldn't match expected type `forall mark. DBM mark Session a' > against inferred type `DBM mark sess ()' > In the second argument of `($)', namely `main'' > In the expression: > (withSession (connect [CAdbname "template1"])) $ main' > In the expression: > do (withSession (connect [CAdbname "template1"])) $ main' Ah, the dreaded $ with existential types problem. $ is not quite equivalent to application -- the type checker does something funny with forall types. Just take out the $ and you'll be fine. -- Taral "You can't prove anything." -- G?del's Incompetence Theorem From mvanier at cs.caltech.edu Fri Nov 24 01:29:45 2006 From: mvanier at cs.caltech.edu (Michael Vanier) Date: Fri Nov 24 01:28:32 2006 Subject: [Haskell-cafe] question about "How to Write a Haskell Program" tutorial Message-ID: <45669159.8080405@cs.caltech.edu> First off, I apologize if this has come up before. As far as I can tell, the mailing list archives don't have a search function. I'm running ghc-6.6 and haddock-0.8, both compiled from source. I'm working my way through the "How to Write a Haskell Program" tutorial (which is a great idea, thanks guys!), and everything works fine until I get to the part about creating the haddock documentation. When I run: $ runhaskell Setup.hs haddock I get this: Preprocessing executables for haq-0.0... Running Haddock for haq-0.0... Warning: cannot use package haq-0.0: ghc-pkg failed With verbosity: $ runhaskell Setup.hs haddock -v I get this: Preprocessing executables for haq-0.0... Running Haddock for haq-0.0... /usr/local/packages/haskell-misc/bin/haddock --html --odir=dist/doc/html/haq --title=haq --use-package=haq-0.0 --use-package=base-2.0 dist/build/tmp/Haq.hs Warning: cannot use package haq-0.0: ghc-pkg failed Note that I'm installing into a non-standard location. I have no idea why haddock (called from cabal) is trying to use a package that is in the process of being created. Nevertheless, the documentation does get generated. Is this just something that should be ignored? Is it a Cabal bug? Mike From dons at cse.unsw.edu.au Fri Nov 24 01:51:26 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Fri Nov 24 01:50:11 2006 Subject: [Haskell-cafe] question about "How to Write a Haskell Program" tutorial In-Reply-To: <45669159.8080405@cs.caltech.edu> References: <45669159.8080405@cs.caltech.edu> Message-ID: <20061124065123.GA4582@cse.unsw.EDU.AU> mvanier: > First off, I apologize if this has come up before. As far as I can tell, > the mailing list archives don't have a search function. I'm running > ghc-6.6 and haddock-0.8, both compiled from source. > > I'm working my way through the "How to Write a Haskell Program" tutorial > (which is a great idea, thanks guys!), and everything works fine until I > get to the part about creating the haddock documentation. When I run: > > $ runhaskell Setup.hs haddock > > I get this: > > Preprocessing executables for haq-0.0... > Running Haddock for haq-0.0... > Warning: cannot use package haq-0.0: > ghc-pkg failed > > With verbosity: > > $ runhaskell Setup.hs haddock -v > > I get this: > > Preprocessing executables for haq-0.0... > Running Haddock for haq-0.0... > /usr/local/packages/haskell-misc/bin/haddock --html > --odir=dist/doc/html/haq --title=haq --use-package=haq-0.0 > --use-package=base-2.0 dist/build/tmp/Haq.hs > Warning: cannot use package haq-0.0: > ghc-pkg failed > Ah yes, I get this too when using ghc 6.6. With ghc 6.4.2 the haddock goes through fine. Updating haddock to 0.8 and the ghc-pkg error is still there. But the docs seem to be generated ok: Main Synopsis main :: IO () Documentation main :: IO () main runs the main program Produced by Haddock version 0.8 Simon, know what's going on? -- Don From antti-juhani at kaijanaho.fi Fri Nov 24 01:52:18 2006 From: antti-juhani at kaijanaho.fi (Antti-Juhani Kaijanaho) Date: Fri Nov 24 01:51:06 2006 Subject: [Haskell-cafe] Command line prompt templates In-Reply-To: <20061124020303.GB2428@cse.unsw.EDU.AU> References: <20061124011853.GU22797@glowfish> <20061124020303.GB2428@cse.unsw.EDU.AU> Message-ID: <456696A2.6060500@kaijanaho.fi> Donald Bruce Stewart wrote: > Looks pretty good, though you use > > case x :: Bool of > True -> ... > False -> ... > > when > if x then ... else ... > > would be preferred. Why? Personally, I find boolean case to feel better wrt layout and I see no loss of clarity in its use. From simonpj at microsoft.com Fri Nov 24 03:22:36 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Fri Nov 24 03:21:17 2006 Subject: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: <9BF202E6B745664F896FB822A141D3310BB3BB3B@EA-EXMSG-C303.europe.corp.microsoft.com> References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> <89ca3d1f0611231244j3d6dcaa7i84356813324422be@mail.gmail.com> <9BF202E6B745664F896FB822A141D3310BB3BB3B@EA-EXMSG-C303.europe.corp.microsoft.com> Message-ID: | The basic idea is to provide a way for a transaction to call into transaction-aware libraries. The libraries | can register callbacks for if the transaction commits (to actually do any "O") and for if the transaction | aborts (to re-buffer any "I" that the transaction has consumed). In addition, a library providing access | to another transactional abstraction (e.g. a database supporting transactions) can perform a 2-phase | commit that means that the memory transaction and database transaction either both commit or both | abort. Yes, I have toyed with extending GHC's implementation of STM to support onCommit :: IO a -> STM () The idea is that onCommit would queue up an IO action to be performed when the transaction commits, but without any atomicity guarantee. If the transaction retries, the action is discarded. Now you could say atomic (do { xv <- readTVar x yv <- readTVar y if xv>yv then onCommit launchMissiles else return () }) and the missiles would only get launched when the transaction successfully commits. This is pure programming convenience. It's always possible to make an existing Haskell STM transaction that *returns* an IO action, which is performed by the caller, thus: dO { action <- atomic (do { xv <- readTVar x; yv <- readTVar y; if xv>yv then retur launchMissiles else return (return ()) }) ; action } All onCommit does is make it more convenient. Perhaps a *lot* more convenient. I have also toyed with adding retryWith :: IO a -> STM () The idea here is that the transction is undone (i.e. just like the 'retry' combinator), then the specified action is performed, and then the transaction is retried. Again no atomicity guarantee. If there's an orElse involved, both actions would get done. Unlike onCommit, onRetry adds new power. Suppose you have a memory buffer, with an STM interface: getLine :: Buffer -> STM STring This is the way to do transactional input: if there is not enough input, the transaction retries; and the effects of getLine aren't visible until the transaction commits. The problem is that if there is not enough data in the buffer, getLine will retry; but alas there is no way at present to "tell" someone to fill the buffer with more data. onRetry would fix that. getLine could say if then retryWith It would also make it possible to count how many retries happened: atomic ( `orElse` retryWith ) I have not implemented either of these, but I think they'd be cool. Simon PS: I agree wholeheartedly with this: | Of course, these solutions don't deal with the question of atomic blocks that want to perform output | (e.g. to the console) and receive input in response to that. My view at the moment is _that does not | make sense in an atomic block_ -- the output and input can't be performed atomically because the | intervening state must be visible for the user to respond to. From bulat.ziganshin at gmail.com Thu Nov 23 17:22:55 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Nov 24 03:50:22 2006 Subject: [Haskell-cafe] Equivalent of if/then/else for IO Bool? In-Reply-To: <20061123213449.GS22797@glowfish> References: <20061123213449.GS22797@glowfish> Message-ID: <190737208.20061124012255@gmail.com> Hello Dougal, Friday, November 24, 2006, 12:34:49 AM, you wrote: > Is there some sort of equivalent of the if/then/else construct for use > in the IO monad? For instance the following can get quite tedious: just a list of my control structures: whenM cond action = do allow <- cond when allow action unlessM = whenM . liftM not whenJustM x action = x >>= maybe (return Nothing) action whenJustM_ x action = x >>= maybe (return ()) (action .>> return ()) foreach = flip mapM for = flip mapM_ on = flip when repeat_foreverM action = do action repeat_foreverM action repeat_whileM inp cond out = do x <- inp if (cond x) then do out x repeat_whileM inp cond out else return x repeat_untilM action = do done <- action when (not done) $ do repeat_untilM action doChunks size chunk action = case size of 0 -> return () _ -> do let n = minI size chunk action (fromIntegral n) doChunks (size-n) chunk action recursiveM action x = action x >>= mapM_ (recursiveM action) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From tomasz.zielonka at gmail.com Fri Nov 24 04:02:59 2006 From: tomasz.zielonka at gmail.com (Tomasz Zielonka) Date: Fri Nov 24 04:01:41 2006 Subject: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> <89ca3d1f0611231244j3d6dcaa7i84356813324422be@mail.gmail.com> <9BF202E6B745664F896FB822A141D3310BB3BB3B@EA-EXMSG-C303.europe.corp.microsoft.com> Message-ID: <20061124090259.GA8574@lambda> On Fri, Nov 24, 2006 at 08:22:36AM +0000, Simon Peyton-Jones wrote: > I have also toyed with adding > > retryWith :: IO a -> STM () > > The idea here is that the transction is undone (i.e. just like the 'retry' combinator), then the specified action is performed, and then the transaction is retried. Again no atomicity guarantee. If there's an orElse involved, both actions would get done. > > Unlike onCommit, onRetry adds new power. Suppose you have a memory > buffer, with an STM interface: > getLine :: Buffer -> STM STring [Sorry for a long email, I had no time to make it short ;-)] Another example would be my experiments with supporting time in STM, ie. functions: retryIfBefore :: UTCTime -> STM () retryIfAfter :: UTCTime -> STM () (Current code can be obtained with "darcs get" from http://www.uncurry.com/haskell/stm-time/. BTW, shout if you want such a library - it will motivate me to finally release it officially). The naive implementation could hold UTCTime in a single TVar and update this variable in a loop, say, 100 times a second. Of course, with many threads using retryIfBefore/retryIfAfter this would cause too many retries. In my implementation I split the time TVar into a list of TVars, each holding a bit of time representation. The retryIf* functions are written in such a way, that they retry as soon as they can tell that it's too early or too late. This way the number of retries for (retryIfBefore then) is at most the length of suffix of bits that differ in representation of "now" and "then". But there is still a problem with accuracy. Ideally, we would like to be as accurate as possible. One solution goes like this: if retryIfBefore retries because the time value stored in variables is too low, let's allow it to notify the manager thread what UTCTime it is waiting for, so it can schedule to update the variables exactly at this moment. That's where retryWith would help. Right now I am using something named autonomous transactions: autonomously :: Bool -> STM a -> STM () This basically forks a new thread to perform the given transaction outside of the current transaction. To be fair, I am not sure it is sound - as you can imagine, the implementation uses some dirty tricks like unsafeIOToSTM. I haven't checked what would happen if I used some variables created in the surrounding transaction. BTW, implementing STM.Time was very instructive for me. It made me realize that I didn't understand STM as well as I thought. Perhaps it could be made in a nice tutorial, if it wasn't so riddled with unsafish stuff: unsafeIOToSTM mentioned above, and unsafePerformIO used to initialize a top-level variable *and* spawn a manager thread. Here retryWith could also help - I fork the manager thread with it. > I have not implemented either of these, but I think they'd be cool. I agree especially about retryWith. But I think it's name should include a "danger! sign", because when used wrong, it can "break" the nice properties of STM and cause very surprising bugs. For me one good "danger" indicator is "IO", so perhaps "retryWithIO" ? Best regards Tomasz From tomasz.zielonka at gmail.com Fri Nov 24 04:11:42 2006 From: tomasz.zielonka at gmail.com (Tomasz Zielonka) Date: Fri Nov 24 04:10:24 2006 Subject: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: <20061124090259.GA8574@lambda> References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> <89ca3d1f0611231244j3d6dcaa7i84356813324422be@mail.gmail.com> <9BF202E6B745664F896FB822A141D3310BB3BB3B@EA-EXMSG-C303.europe.corp.microsoft.com> <20061124090259.GA8574@lambda> Message-ID: <20061124091142.GB8574@lambda> On Fri, Nov 24, 2006 at 10:02:59AM +0100, Tomasz Zielonka wrote: > That's where retryWith would help. Right now I am using something named > autonomous transactions: > > autonomously :: Bool -> STM a -> STM () > > This basically forks a new thread to perform the given transaction > outside of the current transaction. Forgot to explain this Bool parameter: it controls whether the enclosing transaction is waiting for the autonomous transaction to finish. I don't really like this idea, but it allowed to gain some small efficiency advantage, decreasing the number of retries. Best regards Tomasz From dagit at eecs.oregonstate.edu Fri Nov 24 04:15:12 2006 From: dagit at eecs.oregonstate.edu (Jason Dagit) Date: Fri Nov 24 04:13:53 2006 Subject: [Haskell-cafe] Equivalent of if/then/else for IO Bool? In-Reply-To: <4566282D.9000300@cs.nott.ac.uk> References: <20061123213449.GS22797@glowfish> <4566282D.9000300@cs.nott.ac.uk> Message-ID: On 11/23/06, Conor McBride wrote: > > *Grr> ifM (Just True) (Just 3) Nothing > Nothing > > More care required! Thank you. Now that you point this out I recall that I've made this mistake in the past with (&&), I once wrote something like liftM2 (&&). I forget that the liftM* family binds the parameters before passing them on. Hopefully the lesson will stick this time. Jason From johan.tibell at gmail.com Fri Nov 24 04:15:47 2006 From: johan.tibell at gmail.com (Johan Tibell) Date: Fri Nov 24 04:14:29 2006 Subject: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> Message-ID: <90889fe70611240115s7950c149u669b5edb5186e546@mail.gmail.com> I would just love to have some Haskell video casts. That would be awesome! Cheers, Johan On 11/23/06, Bayley, Alistair wrote: > http://channel9.msdn.com/Showpost.aspx?postid=231495 > > The links to the video are a couple of yellow buttons at the bottom of > the article: "Watch" or "Download". > > I haven't watched this yet (it's nearly an hour long, I think). Found > via reddit (http://reddit.com). > > Haskeller's on TV (sort of...) woot woot! > > Alistair > ***************************************************************** > Confidentiality Note: The information contained in this message, > and any attachments, may contain confidential and/or privileged > material. It is intended solely for the person(s) or entity to > which it is addressed. Any review, retransmission, dissemination, > or taking of any action in reliance upon this information by > persons or entities other than the intended recipient(s) is > prohibited. If you received this in error, please contact the > sender and delete the material from any computer. > ***************************************************************** > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From tomasz.zielonka at gmail.com Fri Nov 24 04:26:38 2006 From: tomasz.zielonka at gmail.com (Tomasz Zielonka) Date: Fri Nov 24 04:25:20 2006 Subject: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> Message-ID: <20061124092638.GC8574@lambda> On Thu, Nov 23, 2006 at 12:56:00PM -0000, Bayley, Alistair wrote: > http://channel9.msdn.com/Showpost.aspx?postid=231495 > > The links to the video are a couple of yellow buttons at the bottom of > the article: "Watch" or "Download". > > I haven't watched this yet (it's nearly an hour long, I think). Found > via reddit (http://reddit.com). > > Haskeller's on TV (sort of...) woot woot! Does anybody know how to watch this on Linux? I would prefer to simply download the movie file and use MPlayer on that, but I failed. .. or on Mac OS X (haven't tried yet) Best regards Tomasz From lemmih at gmail.com Fri Nov 24 04:31:27 2006 From: lemmih at gmail.com (Lemmih) Date: Fri Nov 24 04:30:09 2006 Subject: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: <20061124092638.GC8574@lambda> References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> <20061124092638.GC8574@lambda> Message-ID: On 11/24/06, Tomasz Zielonka wrote: > On Thu, Nov 23, 2006 at 12:56:00PM -0000, Bayley, Alistair wrote: > > http://channel9.msdn.com/Showpost.aspx?postid=231495 > > > > The links to the video are a couple of yellow buttons at the bottom of > > the article: "Watch" or "Download". > > > > I haven't watched this yet (it's nearly an hour long, I think). Found > > via reddit (http://reddit.com). > > > > Haskeller's on TV (sort of...) woot woot! > > Does anybody know how to watch this on Linux? I would prefer to simply > download the movie file and use MPlayer on that, but I failed. > > .. or on Mac OS X (haven't tried yet) Worked for me with mplayer+w32codecs. -- Cheers, Lemmih From tomasz.zielonka at gmail.com Fri Nov 24 04:47:23 2006 From: tomasz.zielonka at gmail.com (Tomasz Zielonka) Date: Fri Nov 24 04:46:06 2006 Subject: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> <20061124092638.GC8574@lambda> Message-ID: <20061124094723.GA8965@lambda> On Fri, Nov 24, 2006 at 10:31:27AM +0100, Lemmih wrote: > Worked for me with mplayer+w32codecs. Oops! I missed the "Download" link and tried to download through "Watch" ;-) Thanks! Best regards Tomasz From a.d.clark at ed.ac.uk Fri Nov 24 05:00:42 2006 From: a.d.clark at ed.ac.uk (Allan Clark) Date: Fri Nov 24 04:59:21 2006 Subject: [Haskell-cafe] Command line prompt templates In-Reply-To: <20061124011853.GU22797@glowfish> References: <20061124011853.GU22797@glowfish> Message-ID: <4566C2CA.2040903@ed.ac.uk> Dougal Stanton wrote: > I was trying to write my own equivalent to Don Stewart's mkcabal but > ended up getting sidetracked. I made some generalised prompts for use at > the command line and wanted to get some feedback on them. > > The full code can be found at [1] but the basic summary is like this: > Hi, I also have a small module for use in a project I'm writing which I use for command line 'asking', you can find the code at : http://homepages.inf.ed.ac.uk/s9810217/software/fragments/Hask.hs and I guess it's possible something there might be of use to you. regards allan From ctm at cs.nott.ac.uk Fri Nov 24 05:23:59 2006 From: ctm at cs.nott.ac.uk (Conor McBride) Date: Fri Nov 24 05:22:41 2006 Subject: [Haskell-cafe] Equivalent of if/then/else for IO Bool? In-Reply-To: References: <20061123213449.GS22797@glowfish> <4566282D.9000300@cs.nott.ac.uk> Message-ID: <4566C83F.6030803@cs.nott.ac.uk> Jason Dagit wrote: > On 11/23/06, Conor McBride wrote: >> >> *Grr> ifM (Just True) (Just 3) Nothing >> Nothing >> >> More care required! > > Thank you. Now that you point this out I recall that I've made this > mistake in the past You and me both. It's really insidious and can hide for weeks, looking perfectly innocent and doing all sorts of mad stuff. Ross and I talk about this issue in our 'Applicative' paper. It's really what distinguishes monads from applicative functors. Monads let you use the value from one computation to choose which *computation* to run next; applicative functors fix the structure of computations but allow you to do what you like with the *values*. So, again, I know it's not going to happen in the immediate future, but I hope we will eventually adopt Ashley's Functor Hierarchy proposal, then shift the liftM family to the Applicative layer, where they belong. The fact that the above ifM can be typed with Applicative m, not just Monad m, is the clue to why it is broken. All the best Conor From zacara at gmail.com Fri Nov 24 06:07:20 2006 From: zacara at gmail.com (ClareZako) Date: Fri Nov 24 06:05:57 2006 Subject: [Haskell-cafe] Foldl Message-ID: <7524410.post@talk.nabble.com> Hello, i'd like to write a function that given a list like [1,2,3,4...] returns a list of couple where the first element is the corresponding element of the string, and the second is the sum of the previous elements. An example: input: [1,2,3,4] output: [(1,0)(2,1)(3,3)(4,6)] The problem is that I'd like to use foldl and a solution like: buildCouples = snd . foldl op (0,[]) where op (v,xs) x = (v+x,xs++[(x,v)]) is not good since the operator ++ let the function take 2*n time and not n. Can anyone help me please? Clare -- View this message in context: http://www.nabble.com/Foldl-tf2698202.html#a7524410 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From dons at cse.unsw.edu.au Fri Nov 24 06:34:12 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Fri Nov 24 06:32:54 2006 Subject: [Haskell-cafe] Foldl In-Reply-To: <7524410.post@talk.nabble.com> References: <7524410.post@talk.nabble.com> Message-ID: <20061124113412.GA7392@cse.unsw.EDU.AU> zacara: > > Hello, > i'd like to write a function that given a list like [1,2,3,4...] > returns a list of couple where the first element is the corresponding > element of the string, and the second is the sum of the previous > elements. > An example: > input: [1,2,3,4] > output: [(1,0)(2,1)(3,3)(4,6)] > Looks like a scanl (a prefix fold) -- the "of the previous elements" is a clue that you're describing a scan: Prelude> :t scanl scanl :: (a -> b -> a) -> a -> [b] -> [a] Prelude> scanl (+) 0 [1..4] [0,1,3,6,10] You should be able to work out the rest from here (or rewrite it as a fold). -- Don From claus.reinke at talk21.com Fri Nov 24 07:21:35 2006 From: claus.reinke at talk21.com (Claus Reinke) Date: Fri Nov 24 07:20:15 2006 Subject: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM- video References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net><89ca3d1f0611231244j3d6dcaa7i84356813324422be@mail.gmail.com> <9BF202E6B745664F896FB822A141D3310BB3BB3B@EA-EXMSG-C303.europe.corp.microsoft.com> Message-ID: <00ae01c70fc3$16dd7500$9a337ad5@cr3lt> this thread reminds me about something that I wanted to ask you. if I recall correctly, most of the literature references in STM papers are recent, so I wondered whether you are aware of this one: NAMING AND SYNCHRONIZATION IN A DECENTRALIZED COMPUTER SYSTEM SourceTechnical Report: TR-205 Year of Publication: 1978 Author D. P. Reed I'm not entirely sure where I got my version from (it was mentioned as a cornerstone in Alan Kay et al s latest project, Croquet, on which Reed is a collaborator: http://www.opencroquet.org/ ), but here is the abstract: http://portal.acm.org/citation.cfm?coll=GUIDE&dl=GUIDE&id=889815 (note that it mentions both grouping of updates, and synchronized composition of modules with local synchronization constraints) and this might be the official site for the scanned copy (?): http://www.lcs.mit.edu/publications/specpub.php?id=773 just wondering, claus From simonpj at microsoft.com Fri Nov 24 07:26:38 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Fri Nov 24 07:25:17 2006 Subject: [Haskell-cafe] Implicit params and typeclasses In-Reply-To: <73f919100611160809l26936595rd6533b2166e5cf98@mail.gmail.com> References: <73f919100611160809l26936595rd6533b2166e5cf98@mail.gmail.com> Message-ID: Grzegorz A nice example! I don't think I'd really realised before that a type like forall a. (?x::a) => Int is not ambiguous at all, even though the Int part does not mention the 'a'. Why not? Because a call site will give the ?x binding, and that in turn fixes a. I've fixed GHC (the HEAD) to allow this. The patch is in an area that I have upheaved recently, so I doubt it'll appear in 6.6.1. Use the HEAD, or wait for 6.8. Thanks for suggesting this. Your example (and name) are immortalised in the regression test suite. Simon | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of | Grzegorz Chrupala | Sent: 16 November 2006 16:10 | To: Haskell Cafe | Subject: [Haskell-cafe] Implicit params and typeclasses | | Hi all, | When I try to compile the following in GHC (v 6.6) (with | -fno-monomorphism-restriction -fimplicit-params) | class Configuration a where | thestring:: a -> String | foo c = let { ?c = c } in bar | bar = thestring ?c | I get: | Ambiguous type variable `a' in the constraint: | `Configuration a' | arising from use of `thestring' at /home/grzegorz/Foo.hs:9:6-17 | Possible cause: the monomorphism restriction applied to the following: | bar :: (?c::a) => String (bound at /home/grzegorz/Foo.hs:9:0) | foo :: a -> String (bound at /home/grzegorz/Foo.hs:8:0) | Probable fix: give these definition(s) an explicit type signature | or use -fno-monomorphism-restriction | | Adding the type signature bar :: (Configuration a,?c :: a) => String | the compiler says: | Ambiguous constraint `Configuration a' | At least one of the forall'd type variables mentioned by the constraint | must be reachable from the type after the '=>' | In the type signature for `bar': | bar :: (Configuration a, ?c :: a) => String | | Similar code without use of implicit params compiles fine: | class Configuration a where | thestring:: a -> String | foo c = thestring c | | Why do implicit params cause this error and is there a way to make it work? | | Thanks, | -- | Grzegorz | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe From simonpj at microsoft.com Fri Nov 24 07:32:04 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Fri Nov 24 07:30:43 2006 Subject: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM- video In-Reply-To: <00ae01c70fc3$16dd7500$9a337ad5@cr3lt> References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net><89ca3d1f0611231244j3d6dcaa7i84356813324422be@mail.gmail.com> <9BF202E6B745664F896FB822A141D3310BB3BB3B@EA-EXMSG-C303.europe.corp.microsoft.com> <00ae01c70fc3$16dd7500$9a337ad5@cr3lt> Message-ID: Interesting reference. I had never heard of it. From reading section 1.2 it sounds like an early description of the optimistic approach to implementing atomic transactions (which is itself a well-studied field). Simon | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Claus | Reinke | Sent: 24 November 2006 12:22 | To: Simon Peyton-Jones; Tim Harris (RESEARCH) | Cc: haskell-cafe@haskell.org | Subject: Re: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM- video | | this thread reminds me about something that I wanted to ask you. | if I recall correctly, most of the literature references in STM papers | are recent, so I wondered whether you are aware of this one: | | NAMING AND SYNCHRONIZATION IN A | DECENTRALIZED COMPUTER SYSTEM | | SourceTechnical Report: TR-205 | Year of Publication: 1978 | Author D. P. Reed | | I'm not entirely sure where I got my version from (it was mentioned | as a cornerstone in Alan Kay et al s latest project, Croquet, on which | Reed is a collaborator: http://www.opencroquet.org/ ), but here is | the abstract: | | http://portal.acm.org/citation.cfm?coll=GUIDE&dl=GUIDE&id=889815 | | (note that it mentions both grouping of updates, and synchronized | composition of modules with local synchronization constraints) | | and this might be the official site for the scanned copy (?): | | http://www.lcs.mit.edu/publications/specpub.php?id=773 | | just wondering, | claus | | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe From haskell at list.mightyreason.com Fri Nov 24 09:31:05 2006 From: haskell at list.mightyreason.com (Chris Kuklewicz) Date: Fri Nov 24 09:29:43 2006 Subject: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> <89ca3d1f0611231244j3d6dcaa7i84356813324422be@mail.gmail.com> <9BF202E6B745664F896FB822A141D3310BB3BB3B@EA-EXMSG-C303.europe.corp.microsoft.com> Message-ID: <45670229.5050707@list.mightyreason.com> I was inspired by Simon's post to kludge up a working prototype that does what is discussed: Simon Peyton-Jones wrote: > | The basic idea is to provide a way for a transaction to call into transaction-aware libraries. The libraries > | can register callbacks for if the transaction commits (to actually do any "O") and for if the transaction > | aborts (to re-buffer any "I" that the transaction has consumed). In addition, a library providing access > | to another transactional abstraction (e.g. a database supporting transactions) can perform a 2-phase > | commit that means that the memory transaction and database transaction either both commit or both > | abort. > > Yes, I have toyed with extending GHC's implementation of STM to support > > onCommit :: IO a -> STM () > > The idea is that onCommit would queue up an IO action to be performed when > the transaction commits, but without any atomicity guarantee. If the > transaction retries, the action is discarded. Now you could say > > I have also toyed with adding > > retryWith :: IO a -> STM () > > The idea here is that the transction is undone (i.e. just like the 'retry' > combinator), then the specified action is performed, and then the transaction > is retried. Again no atomicity guarantee. If there's an orElse involved, > both actions would get done. > > It would also make it possible to count how many retries happened: atomic > ( `orElse` retryWith ) > > I have not implemented either of these, but I think they'd be cool. > > Simon The prototype is: {- November 24th, 2006 Demonstration Code by Chris Kuklewicz Usual 3 clause BSD Licence Copyright 2006 This is inspired by a post by Simon Peyton-Jones on the haskell-cafe mailing list, in which the type and semantics of onCommit and withRetry were put forth. The semantics of printing the contents of the TVar "v" created in test via retryWith may or may not be well defined. With GHC 6.6 I get *AdvSTM> main "hello world" "retryWith Start" ("retryWith v",7) "Flipped choice to True to avoid infinite loop" "onCommit Start" ("onCommit v",42) ("result","foo") "bye world" Aside from that I think the unsafeIOToSTM is not really unsafe here since it writes to privately created and maintained variables. Since the implementation is hidden it could be changed from ReaderT to some other scheme. Once could also use MonadBase from http://haskell.org/haskellwiki/New_monads/MonadBase to help with the lifting, but this has been commented out below. TODO: figure out semantics of catchAdv. At least it compiles... -} module AdvSTM(MonadAdvSTM(..),AdvSTM,retryWith) where -- import MonadBase import Control.Exception(Exception) import Control.Monad(MonadPlus(..),liftM) import Control.Monad.Reader(MonadReader(..),ReaderT,runReaderT,lift,asks) import Control.Concurrent.STM(STM,orElse,retry,catchSTM,atomically) import Control.Concurrent.STM.TVar(TVar,newTVarIO,newTVar,readTVar,writeTVar) import GHC.Conc(unsafeIOToSTM) import Data.IORef(IORef,newIORef,readIORef,writeIORef,modifyIORef) import Data.Typeable(Typeable) import Data.Generics(Data) class MonadAdvSTM m where onCommit :: IO a -> m () onRetry :: IO a -> m () orElseAdv :: m a -> m a -> m a retryAdv :: m a atomicAdv :: m a -> IO a catchAdv :: m a -> (Exception -> m a) -> m a liftAdv :: STM a -> m a -- Export type but not constructor! newtype AdvSTM a = AdvSTM (ReaderT (CommitVar,RetryVar) STM a) deriving (Functor,Monad,MonadPlus,Typeable) type CommitVar = TVar ([IO ()]->[IO ()]) type RetryVar = IORef ([IO ()]->[IO ()]) {- Since lifting retry and `orElse` gives the semantics Simon wants, use deriving MonadPlus instead instance MonadPlus AdvSTM where mzero = retryAdv mplus = orElseAdv -} -- instance MonadBase STM AdvSTM where liftBase = AdvSTM . lift retryWith :: IO a -> AdvSTM b retryWith io = onRetry io >> retryAdv instance MonadAdvSTM AdvSTM where onCommit io = do cv <- AdvSTM $ asks fst old <- liftAdv $ readTVar cv liftAdv $ writeTVar cv (old . ((io >> return ()):)) onRetry io = do rv <- AdvSTM $ asks snd liftAdv $ unsafeIOToSTM $ modifyIORef rv (\ old -> old . ((io >> return ()):) ) {- orElseAdv (AdvSTM a) (AdvSTM b) = {- If a retries then its onRetry commands are kept on the list of actions to do if the whole command fails. It would be possible to save the "rv" and use unsafeIOToSTM to implement a different policy here -} AdvSTM $ do env <- ask lift $ (runReaderT a env) `orElse` (runReaderT b env) -} orElseAdv = mplus retryAdv = liftAdv retry -- the same as retryAdv = mzero atomicAdv = runAdvSTM catchAdv (AdvSTM action) handler = let h env error = let (AdvSTM cleanup) = handler error in runReaderT cleanup env in AdvSTM $ do env <- ask lift $ catchSTM (runReaderT action env) (h env) liftAdv = AdvSTM . lift -- This replaces "atomically" runAdvSTM :: AdvSTM a -> IO a runAdvSTM (AdvSTM action) = do cv <- newTVarIO id rv <- newIORef id let wrappedAction = (runReaderT (liftM Just action) (cv,rv)) `orElse` (return Nothing) loop = do result <- atomically $ wrappedAction case result of Just answer -> do cFun <- atomically (readTVar cv) sequence_ (cFun []) return answer Nothing -> do rFun <- readIORef rv writeIORef rv id -- must reset the list sequence_ (rFun []) loop loop -- Example code using the above: test :: TVar Bool -> AdvSTM String test todo = do onCommit (print "onCommit Start") onRetry (print "onRetry Start") v <- liftAdv $ newTVar 7 liftAdv $ writeTVar v 42 onCommit (atomically (readTVar v) >>= \x->print ("onCommit v",x)) onRetry (atomically (readTVar v) >>= \x->print ("onRetry v",x)) choice <- liftAdv $ readTVar todo case choice of True -> return "foo" False -> retryWith $ do atomically (writeTVar todo True) print "Flipped choice to True to avoid infinite loop" -- Example similar to Simon's suggested example: countRetries :: IORef Int -> AdvSTM a -> AdvSTM a countRetries ioref action = let incr = do old <- readIORef ioref writeIORef ioref $! (succ old) in action `orElseAdv` (retryWith incr) -- Load this file in GHCI and execute main to run the test: main = do print "hello world" todo <- newTVarIO False counter <- newIORef 0 result <- runAdvSTM (test todo) print ("result",result) print "bye world" From jgoerzen at complete.org Fri Nov 24 11:32:55 2006 From: jgoerzen at complete.org (John Goerzen) Date: Fri Nov 24 11:31:58 2006 Subject: [Haskell-cafe] The Future of MissingH Message-ID: Hi, Josef Svenningsson posted a comment on my blog today that got me to thinking. He suggested that people may be "intimidated by the size of MissingH, confused by the undescriptive name, and don't quite know what's in there." And I think he's right. I've been passively thinking about what MissingH should be for awhile now, and wonder if you all would have some suggestions. First, let me back up and describe a bit of what MissingH is. It gets its name because I think that it has useful functions that are "missing" from the standard Haskell libraries. But I can see how it's not very descriptive. The major features are: * A general-purpose modular logging infrastructure * A virtual filesystem component (similar to VFS in Gnome, but written in Haskell) * A configuration file parser, compatible with Python's and Perl's, which can also modify and generate config files and do variable interpolation * A bunch of tools for setting up pipes to/from processes * Tools to format numbers as quantities, with default configs for the SI system (1000-based) and binary system (1024-based) * Tools to track the progress of long-running actions and display a status bar on the terminal * Pure-Haskell un-gzip code, *DBM infrastructure, etc * Assorted list, string, regexp, bit, pointer, etc. utilities * MIME and email parsers. I wrote most of the code myself, but did pull some large chunks from others where licenses were compatible. The API reference is at http://gopher.quux.org:70/devel/missingh/html/index.html So, some of the questions are: Should this all be one library? I initially wrote it that way to make resolving dependencies easier for end users. Also, it still has utility because modules make use of each other's features. The list and string functions are used almost everywhere, for instance. HVFS support is also fairly pervasive. Should the module naming scheme be changed? Modules are currently named things like MissingH.List, MissingH.IO.HVFS, MissingH.ProgressMeter, etc. I guess these could go to System.ListExt, System.IO.HVFS, System.Console.ProgressMeter, etc. Could, and should, any of this be integrated into the Haskell libraries project? (That set of libraries formerly known as fptools) A few bits of code have already found their way into them. But I bet there could be a lot more. Maybe even the majority of it. How could greater community participation be encouraged, while still encouraging quality control? I have received some very good contributions to MissingH from people, and that's been great. I've also received some that just aren't that great -- they don't have Haddock docs, the code is opaque, they don't come with unit tests, etc. But by and large, I've been maintaining it mostly myself. Whenever I write some code, I think about whether this is generic code that could be useful in other projects. If so, I consider whether it would be appropriate for MissingH (and it usually is). It would be wonderful if others would be interested in contributing code that solves some need as well. There is a public darcs repo already, and I have received some darcs patches from people (thanks!) I'm not trying to rid myself of MissingH, but I think that it could be a nice resource for small tools from the entire community, if we can maintain a structure and QA footprint to it. What else should be done to make this a valuable resource for Haskell programmers? And a showcase for what is possible with Haskell? The floor's open... Thanks, -- John From cmb21 at kent.ac.uk Fri Nov 24 11:37:24 2006 From: cmb21 at kent.ac.uk (C.M.Brown) Date: Fri Nov 24 11:36:35 2006 Subject: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: <20061124162723.GA932@lit.jwp.name> References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> <20061124092638.GC8574@lambda> <20061124162723.GA932@lit.jwp.name> Message-ID: Hi, I got this working on Mac OS X. I had to download media player 9: http://www.microsoft.com/windows/windowsmedia/software/Macintosh/osx/default.aspx This contains the WMV3 codec. Cheers, Chris. On Fri, 24 Nov 2006, James William Pye wrote: > On Fri, Nov 24, 2006 at 10:26:38AM +0100, Tomasz Zielonka wrote: > > Does anybody know how to watch this on Linux? I would prefer to simply > > download the movie file and use MPlayer on that, but I failed. > > > > . or on Mac OS X (haven't tried yet) > > The latest mplayer works for me on FreeBSD/amd64 (1.0rc1, iirc). > _______________________________________________ > Haskell mailing list > Haskell@haskell.org > http://www.haskell.org/mailman/listinfo/haskell > From Malcolm.Wallace at cs.york.ac.uk Fri Nov 24 12:14:30 2006 From: Malcolm.Wallace at cs.york.ac.uk (Malcolm Wallace) Date: Fri Nov 24 12:21:30 2006 Subject: [Haskell-cafe] The Future of MissingH In-Reply-To: References: Message-ID: <20061124171430.343ce81f.Malcolm.Wallace@cs.york.ac.uk> John Goerzen wrote: > The major features [of MissingH] are: > > * A general-purpose modular logging infrastructure > * A virtual filesystem component (similar to VFS in Gnome, but > written in Haskell) > * A configuration file parser, compatible with Python's and Perl's, > which can also modify and generate config files and do variable > interpolation > * A bunch of tools for setting up pipes to/from processes > * Tools to format numbers as quantities, with default configs for > the SI system (1000-based) and binary system (1024-based) > * Tools to track the progress of long-running actions and display a > status bar on the terminal > * Pure-Haskell un-gzip code, *DBM infrastructure, etc > * MIME and email parsers. Each of those bullet points sounds to me like a useful individual package in its own right. Certainly I had no idea that MissingH contained many of these things, and if I had wanted them, the single name MissingH would not have suggested that I look there. I think they could profitably be split off. > * Assorted list, string, regexp, bit, pointer, etc. utilities By contrast, I guess these parts are what I always believed the "MissingH" name to refer to. They are in some sense missing from the original Haskell'98 libraries. But, given that the evolving 'base' package is now pretty-much the de facto standard, rather than the immutable 'haskell98' package, I see no reason for these functions to remain separate from it. There is a community process for adding new functions to the 'standard' libraries. Use it! Let these functions be "missing" no more! If they are truly useful, they will be adopted without too much fuss. (Note, when I say 'base', I might actually mean 'regex-*' or something else. I don't want to prejudge where these things live, just to encourage you to propose them to the whole Haskell community.) > I initially wrote it that way to make resolving dependencies easier > for end users. Also, it still has utility because modules make use > of each other's features. The list and string functions are used > almost everywhere, for instance. HVFS support is also > fairly pervasive. With Cabal packages, you can express dependencies on other packages with ease. Provided it is not a rats nest of mutual recursion, this is the way to go. > Modules are currently named things like MissingH.List, > MissingH.IO.HVFS, MissingH.ProgressMeter, etc. > > I guess these could go to System.ListExt, System.IO.HVFS, > System.Console.ProgressMeter, etc. In general, yes. [ The bikeshed approacheth, but System.ListExt is not very descriptive - what is wrong with proposing additions to Data.List itself? ] > Could, and should, any of this be integrated into the Haskell > libraries project? > (That set of libraries formerly known as fptools) Where your packages are stored, and how they are maintained, is a separate decision from the choices (a) to use the standard packaging mechanism, and (b) to divide the monolith up into smaller, more manageable chunks. > How could greater community participation be encouraged, while still > encouraging quality control? For quality, just maintain your own public darcs repositories. You get to decide which patches to apply and which to reject. For greater community participation, I think the simple strategy of splitting the libs up into smaller, more grok-able packages is the important first step. Publicity about what each package is good for is the next. Then, if you get significant numbers of users for these libraries, patches will arrive. :-) Regards, Malcolm From ndmitchell at gmail.com Fri Nov 24 12:26:39 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Fri Nov 24 12:25:17 2006 Subject: [Haskell-cafe] The Future of MissingH In-Reply-To: References: Message-ID: <404396ef0611240926j6327f5cakfef276213058a748@mail.gmail.com> Hi John, > Should this all be one library? No, several smaller libraries would be nice. > Should the module naming scheme be changed? Yes, MissingH is not the place to put these things. You run the risk of more name clashes, but thats ok. > Could, and should, any of this be integrated into the Haskell libraries > project? Yes, some should, but only after careful review and being split up. Assuming the Haskell libraries project is still something that should be continued, once Hackage is up and running suddenly the distinction becomes minimal. A few of the functions should be picked out and moved into base, where they truely are missing. > How could greater community participation be encouraged, while still > encouraging quality control? Make sure more people know about it. I want to start using MissingH but never got around to it, by continually telling me how great it was I'm sure I would have started using it earlier. I have various bits of general libraries strewn around the place, which I might contribute to MissingH. Thanks Neil From ndmitchell at gmail.com Fri Nov 24 12:38:31 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Fri Nov 24 12:37:08 2006 Subject: [Haskell-cafe] The Future of MissingH In-Reply-To: <404396ef0611240926j6327f5cakfef276213058a748@mail.gmail.com> References: <404396ef0611240926j6327f5cakfef276213058a748@mail.gmail.com> Message-ID: <404396ef0611240938m12cf80a0y9e45365a625e35c7@mail.gmail.com> Hi > > How could greater community participation be encouraged, while still > > encouraging quality control? One thing I forgot, serving the web pages and documentation over port 80 using HTTP would help. Not all people can access port 70 from all places, I can't from the university campus (only from computer science). Thanks Neil From sethg at ropine.com Fri Nov 24 12:37:53 2006 From: sethg at ropine.com (Seth Gordon) Date: Fri Nov 24 12:37:20 2006 Subject: [Haskell-cafe] strange type mismatch when trying to use takusen In-Reply-To: References: <45667C4C.9000305@ropine.com> Message-ID: <45672DF1.5020908@ropine.com> Taral wrote: > Ah, the dreaded $ with existential types problem. $ is not quite > equivalent to application -- the type checker does something funny > with forall types. Just take out the $ and you'll be fine. > Is this a ghc bug, or some subtlety of the type system that I don't understand? From ndmitchell at gmail.com Fri Nov 24 13:17:06 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Fri Nov 24 13:15:43 2006 Subject: [Haskell-cafe] The Future of MissingH In-Reply-To: <404396ef0611240938m12cf80a0y9e45365a625e35c7@mail.gmail.com> References: <404396ef0611240926j6327f5cakfef276213058a748@mail.gmail.com> <404396ef0611240938m12cf80a0y9e45365a625e35c7@mail.gmail.com> Message-ID: <404396ef0611241017i60fc5b5ax9154246d034f2409@mail.gmail.com> Hi > > > How could greater community participation be encouraged, while still > > > encouraging quality control? It also took me quite a while to find the darcs repository, and as far as I can see there is no web page on what MissingH has in it, other than a textual readme and the GNU entry. If there was a single web page which said what MissingH was and where it could be found, that would help people. The darcs repo I found was: http://darcs.complete.org/missingh/ Thanks Neil From lennart at augustsson.net Fri Nov 24 13:17:38 2006 From: lennart at augustsson.net (Lennart Augustsson) Date: Fri Nov 24 13:16:23 2006 Subject: [Haskell-cafe] strange type mismatch when trying to use takusen In-Reply-To: <45672DF1.5020908@ropine.com> References: <45667C4C.9000305@ropine.com> <45672DF1.5020908@ropine.com> Message-ID: It's not a bug. It's what the type of ($) forces. On Nov 24, 2006, at 12:37 , Seth Gordon wrote: > Taral wrote: >> Ah, the dreaded $ with existential types problem. $ is not quite >> equivalent to application -- the type checker does something funny >> with forall types. Just take out the $ and you'll be fine. > > Is this a ghc bug, or some subtlety of the type system that I don't > understand? > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From haskell at list.mightyreason.com Fri Nov 24 13:25:01 2006 From: haskell at list.mightyreason.com (Chris Kuklewicz) Date: Fri Nov 24 13:23:36 2006 Subject: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: <45670229.5050707@list.mightyreason.com> References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> <89ca3d1f0611231244j3d6dcaa7i84356813324422be@mail.gmail.com> <9BF202E6B745664F896FB822A141D3310BB3BB3B@EA-EXMSG-C303.europe.corp.microsoft.com> <45670229.5050707@list.mightyreason.com> Message-ID: <456738FD.4020903@list.mightyreason.com> I posted an improved version of the new monad to the wiki at http://haskell.org/haskellwiki/New_monads/MonadAdvSTM Observations: ** This idiom made it easy for the retrying case to queue an action which ensures success in the next attempt. ** More than one operation can be queued for both the commit and the retry possibilities. ** Reading the TVar in the onRetry/retryWith branch sees the "rolled back" value, which luckily is the initialization value instead of undefined in the case where the TVar was created in the aborted block. ** The new code includes unlift* operations which makes the STM code in testUnlift much easier to write. The relevant example its output are now: -- Example code using the above, lifting into MonadAdvSTM: test ::(Monad m, MonadAdvSTM m) => TVar Bool -> m [Char] test todo = do onCommit (print "onCommit Start") onRetry (print "onRetry Start") v <- liftAdv $ newTVar 7 liftAdv $ writeTVar v 42 onCommit (atomically (readTVar v) >>= \x->print ("onCommit v",x)) onRetry (atomically (readTVar v) >>= \x->print ("onRetry v",x)) choice <- liftAdv $ readTVar todo case choice of True -> return "foo" False -> retryWith $ do atomically (writeTVar todo True) print "Flipped choice to True to avoid infinite loop" -- Same example as test, but unlifting from AdvSTM testUnlift :: TVar Bool -> AdvSTM [Char] testUnlift todo = do onCommit <- unlift1 onCommit onRetry <- unlift1 onRetry retryWith <- unlift1 retryWith liftAdv $ do onCommit (print "onCommit Start") onRetry (print "onRetry Start") v <- newTVar 7 writeTVar v 42 onCommit (atomically (readTVar v) >>= \x->print ("onCommit v",x)) onRetry (atomically (readTVar v) >>= \x->print ("onRetry v",x)) choice <- readTVar todo case choice of True -> return "foo" False -> retryWith $ do atomically (writeTVar todo True) print "Flipped choice to True to avoid infinite loop" -- Example similar to Simon's suggested example: countRetries :: (MonadAdvSTM m, Monad m, Enum a) => IORef a -> m a1 -> m a1 countRetries ioref action = let incr = do old <- readIORef ioref writeIORef ioref $! (succ old) in action `orElseAdv` (retryWith incr) -- Load this file in GHCI and execute main to run the test: main = do counter <- newIORef 0 todo <- newTVarIO False print "test" result <- runAdvSTM (countRetries counter $ test todo) retries <- readIORef counter print ("result",result,"retries",retries) atomically (writeTVar todo False) print "testUnlift" result <- runAdvSTM (countRetries counter $ testUnlift todo) retries <- readIORef counter print ("result",result,"retries",retries) print "bye world" The output in GHCI is *AdvSTM> main "test" "onRetry Start" ("onRetry v",7) "Flipped choice to True to avoid infinite loop" "onCommit Start" ("onCommit v",42) ("result","foo","retries",1) "testUnlift" "onRetry Start" ("onRetry v",7) "Flipped choice to True to avoid infinite loop" "onCommit Start" ("onCommit v",42) ("result","foo","retries",2) "bye world" From jgoerzen at complete.org Fri Nov 24 15:22:52 2006 From: jgoerzen at complete.org (John Goerzen) Date: Fri Nov 24 15:21:53 2006 Subject: [Haskell-cafe] Re: The Future of MissingH References: <404396ef0611240926j6327f5cakfef276213058a748@mail.gmail.com> <404396ef0611240938m12cf80a0y9e45365a625e35c7@mail.gmail.com> <404396ef0611241017i60fc5b5ax9154246d034f2409@mail.gmail.com> Message-ID: On Fri, 24 Nov 2006 18:17:06 +0000, Neil Mitchell wrote: > Hi > >> > > How could greater community participation be encouraged, while still >> > > encouraging quality control? > > It also took me quite a while to find the darcs repository, and as far > as I can see there is no web page on what MissingH has in it, other > than a textual readme and the GNU entry. If there was a single web > page which said what MissingH was and where it could be found, that > would help people. Your comments about the website are right on. I have been shoving stuff at my Gopher server for quite awhile now. Ironically, I tried to switch the whole mess to trac+darcs about a month ago, but trac crashes on the MissingH darcs repo. Go figure. I talked to Lele about it but he was really short on time, and I didn't have time to learn the trac code either. > The darcs repo I found was: > http://darcs.complete.org/missingh/ That's the one. -- John From dagit at eecs.oregonstate.edu Fri Nov 24 15:37:10 2006 From: dagit at eecs.oregonstate.edu (Jason Dagit) Date: Fri Nov 24 15:35:45 2006 Subject: [Haskell-cafe] The Future of MissingH In-Reply-To: References: Message-ID: On 11/24/06, John Goerzen wrote: > What else should be done to make this a valuable resource for Haskell > programmers? And a showcase for what is possible with Haskell? I was going to try MissingH on win32 but when I did it refused to compile due to a dependency on, I think, Posix. It would be great if this could be fixed/relaxed. At the time I was looking forward to trying the logging facilities. Jason From hjgtuyl at chello.nl Fri Nov 24 16:14:47 2006 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Fri Nov 24 16:13:25 2006 Subject: [Haskell-cafe] list monad and controlling the backtracking In-Reply-To: <1164317123.19751.11.camel@localhost.localdomain> References: <1164317123.19751.11.camel@localhost.localdomain> Message-ID: The idea of backtracking is, that you try all options because you can't tell/calulate in advance which parameters lead to a solution; if you have some idea about where and how to limit your search, you may save a lot of time. In your example, you can limit your search by replacing the lines: > a <- lift $ mlist aList > b <- lift $ mlist bList with: > a <- lift $ mlist $ take 4 aList > b <- lift $ mlist $ take 4 bList In some cases you could use the "filter" function: > a <- lift $ mlist $ filter (< 5) aList > b <- lift $ mlist $ filter (< 5) bList Or "takeWhile": > a <- lift $ mlist $ takeWhile (< 5) aList > b <- lift $ mlist $ takeWhile (< 5) bList Etc. Met vriendelijke groet, Henk-Jan van Tuyl -- On Thu, 23 Nov 2006 22:25:23 +0100, isto wrote: > Hi all, > > Weekly news had a link to article > "Local and global side effects with monad transformers" > and the following is from there (minor modification done): > > import Control.Monad.List > import Control.Monad.State > import Control.Monad.Writer > > test5 :: StateT Integer (ListT (Writer [Char])) Integer > > test5 = do > a <- lift $ mlist aList > b <- lift $ mlist bList > lift $ lift $ tell ("trying "++show a++" "++show b++"\n") > modify (+1) > guard $ a+b<5 > return $ a+b > > go5 = runWriter $ runListT $ runStateT test5 0 > > > If the aList = [1..5] as well as bList, then there will be 25 tryings. > If aList and bList are [1..10000000], there will be a lot of tryings... > > However, guard is saying that we are interested in only values > whose sum is less than 5. > > Is it possible to control easily in the above example that when we > have tried out pairs (1,1), (1,2), (1,3), (1,4), that now we are > ready to stop trying from the bList? And then similarly when we > finally arrive to a pair (4,1), that now we are ready to finish > also with aList? > > This would give a nice way to build branch & bounding algorithms, > even though it does not take much more lines to do it in some other way. > > br, Isto > > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe -- http://Van.Tuyl.eu/ -- Using Opera's revolutionary e-mail client: https://secure.bmtmicro.com/opera/buy-opera.html?AID=789433 From comini at dimi.uniud.it Fri Nov 24 16:27:28 2006 From: comini at dimi.uniud.it (Marco Comini) Date: Fri Nov 24 16:26:05 2006 Subject: [Haskell-cafe] Foldl Message-ID: Donald Bruce Stewart: > zacara: > > i'd like to write a function that given a list like [1,2,3,4...] > > returns a list of couple where the first element is the corresponding > > element of the string, and the second is the sum of the previous > > elements. > Looks like a scanl (a prefix fold) -- the "of the previous > elements" is a clue that you're describing a scan: > > Prelude> :t scanl > scanl :: (a -> b -> a) -> a -> [b] -> [a] > > Prelude> scanl (+) 0 [1..4] > [0,1,3,6,10] > > You should be able to work out the rest from here (or rewrite it as a > fold). I agree Don, certainly with scanl one can solve the problem elegantly. [For ClareZako: it could be something like f (x:xs) = scanl acc (x,0) xs where acc (x,s) y = (y, s+x) ] On the contrary a solution in terms of a fold is indeed more tricky. Probably ClareZako was actually looking for a solution in term of a scan instead of a fold... otherwise would be interesting to know why he's willing to solve this problem in such a twisted way... don't you agree? Cheers, -- Marco. From jgoerzen at complete.org Fri Nov 24 16:47:37 2006 From: jgoerzen at complete.org (John Goerzen) Date: Fri Nov 24 16:46:19 2006 Subject: [Haskell-cafe] The Future of MissingH In-Reply-To: References: Message-ID: <20061124214737.GA22520@katherina.lan.complete.org> On Fri, Nov 24, 2006 at 12:37:10PM -0800, Jason Dagit wrote: > On 11/24/06, John Goerzen wrote: > > >What else should be done to make this a valuable resource for Haskell > >programmers? And a showcase for what is possible with Haskell? > > I was going to try MissingH on win32 but when I did it refused to > compile due to a dependency on, I think, Posix. It would be great if > this could be fixed/relaxed. At the time I was looking forward to > trying the logging facilities. That should be completely fixed for a long time now. But I will admit I haven't tried to build the latest version on GHC 6.6. In fact, I wrote an entire module (MissingH.IO.StatCompat) so that Windows users can also enjoy HVFS. -- John From benjamin.franksen at bessy.de Fri Nov 24 16:51:15 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Fri Nov 24 16:50:23 2006 Subject: [Haskell-cafe] Re: Re: [Haskell] Re: SimonPJ and Tim Harris explain STM - video References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> <89ca3d1f0611231244j3d6dcaa7i84356813324422be@mail.gmail.com> Message-ID: Liyang HU wrote: > On 24/11/06, Benjamin Franksen wrote: >> I have a pretty good idea how much data is going to be produced by >> my own code, and if it's a bit more than I calculated then the whole >> process merely uses up some more memory, which is usually not a >> big problem. However, with input things are different: > > Really? I'd have said that I have a pretty good idea how much data is > going to be consumed by my own code, and if it's a bit more than I > calculated then I'd merely read some more at the beginning (putting > any unused bits back on the input queue afterwards of course), which > is usually not a big problem. :) > > Yes, I do get your point. It's easier to allocate a larger buffer for > your output as needed, than to anticipate how much input you might > require. I'd still claim they're different instances of the same > scheme though! > >> [If] I still haven't got enough data, my transaction will be stuck with >> [no way to demand more input. > > Take your output channel idea, and use that for input too? (Separate > thread to read the input and place it at the end of some queue.) You > would basically retry and block (or rather, STM would do the latter > for you) if you haven't enough data, until more came along. Right. I couldn't see it at first but the I and O really are dual to each other. Thanks for pointing this out -- it seems STM is even more useful than I thought. Cheers Ben From haskell at list.mightyreason.com Fri Nov 24 17:30:53 2006 From: haskell at list.mightyreason.com (Chris Kuklewicz) Date: Fri Nov 24 17:29:28 2006 Subject: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> <89ca3d1f0611231244j3d6dcaa7i84356813324422be@mail.gmail.com> <9BF202E6B745664F896FB822A141D3310BB3BB3B@EA-EXMSG-C303.europe.corp.microsoft.com> Message-ID: <4567729D.2000307@list.mightyreason.com> Simon Peyton-Jones wrote: > I have also toyed with adding > > retryWith :: IO a -> STM () > > The idea here is that the transction is undone (i.e. just like the 'retry' combinator), then the specified action is performed, and then the transaction is retried. Again no atomicity guarantee. If there's an orElse involved, both actions would get done. > > Unlike onCommit, onRetry adds new power. Suppose you have a memory buffer, with an STM interface: > getLine :: Buffer -> STM STring > > This is the way to do transactional input: if there is not enough input, the transaction retries; and the effects of getLine aren't visible until the transaction commits. The problem is that if there is not enough data in the buffer, getLine will retry; but alas there is no way at present to "tell" someone to fill the buffer with more data. > > onRetry would fix that. getLine could say > if then retryWith > > It would also make it possible to count how many retries happened: > atomic ( `orElse` retryWith ) > > I have not implemented either of these, but I think they'd be cool. > > Simon After seeing how close I could come to creating onRetry/retryWith I have a question about the semantics of your idea for retryWith. Normally after a retry the STM block is rolled back and put to sleep and will only be awakened and re-executed if one of the STM variables it had read from is committed to by a different STM block. What about retryWith ? Will the STM block be put to sleep under the same conditions? Can the IO action given to retryWith include commits to STM variables? From coffeemug at gmail.com Fri Nov 24 17:42:13 2006 From: coffeemug at gmail.com (Vyacheslav Akhmechet) Date: Fri Nov 24 17:40:49 2006 Subject: [Haskell-cafe] The Future of MissingH In-Reply-To: <20061124214737.GA22520@katherina.lan.complete.org> References: <20061124214737.GA22520@katherina.lan.complete.org> Message-ID: Until this email I was under the impression that the project is dead. For example, if I go to google and type 'MissingH' the first link is fsf's directory page. When I try to get to MissingH website from there the link appears to be down. I can't really figure out what MissingH includes and where to get it from searching the web, not easily anyway. I think fixing this will go a long way to a more widespread adoption of the library. Thanks, - Slava Akhmechet On 11/24/06, John Goerzen wrote: > On Fri, Nov 24, 2006 at 12:37:10PM -0800, Jason Dagit wrote: > > On 11/24/06, John Goerzen wrote: > > > > >What else should be done to make this a valuable resource for Haskell > > >programmers? And a showcase for what is possible with Haskell? > > > > I was going to try MissingH on win32 but when I did it refused to > > compile due to a dependency on, I think, Posix. It would be great if > > this could be fixed/relaxed. At the time I was looking forward to > > trying the logging facilities. > > That should be completely fixed for a long time now. But I will admit > I haven't tried to build the latest version on GHC 6.6. > > In fact, I wrote an entire module (MissingH.IO.StatCompat) so that > Windows users can also enjoy HVFS. > > -- John > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From mnislaih at gmail.com Fri Nov 24 19:32:04 2006 From: mnislaih at gmail.com (Pepe Iborra) Date: Fri Nov 24 19:30:44 2006 Subject: [Haskell-cafe] Foldl In-Reply-To: References: Message-ID: <63C335CD-204B-4741-98E1-F8D147ADCEF2@gmail.com> On 24/11/2006, at 22:27, Marco Comini wrote: > > On the contrary a solution in terms of a fold is indeed more > tricky. Probably ClareZako was actually looking for a solution in > term of a scan instead of a fold... otherwise would be interesting > to know why he's willing to solve this problem in such a twisted > way... don't you agree? > It's clear to me http://www.cse.unsw.edu.au/~dons/haskell-1990-2006/msg13946.html http://www.haskell.org/haskellwiki/Homework_help I only hope this was not Marco's student. Or was it? :) From u.stenzel at web.de Thu Nov 23 18:57:00 2006 From: u.stenzel at web.de (Udo Stenzel) Date: Fri Nov 24 20:28:00 2006 Subject: [Haskell-cafe] Equivalent of if/then/else for IO Bool? In-Reply-To: <20061123213449.GS22797@glowfish> References: <20061123213449.GS22797@glowfish> Message-ID: <20061123235700.GC1535@web.de> Dougal Stanton wrote: > Is there some sort of equivalent of the if/then/else construct for use > in the IO monad? For instance the following can get quite tedious: > > > do bool <- doesFileExist filename > > if bool > > then sth > > else sth' > > Is there a more compact way of writing that? Something akin to: > > > condM (doesFileExist filename) (sth) (sth') I'd suggest cond t f True = t cond t f False = f and then you use it like doesFileExist filename >>= cond sth sth' I find it strange that we have 'maybe' for 'Maybe', 'either' for 'Either', 'foldr' for '[]', but a special syntactic form for 'Bool'. Why is there no 'cond' in the Prelude? -Udo -- There is no snooze button on a cat who wants breakfast. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061124/62f6547d/attachment.bin From dons at cse.unsw.edu.au Fri Nov 24 21:18:17 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Fri Nov 24 21:16:54 2006 Subject: [Haskell-cafe] Starting your own Haskell project: part 2 In-Reply-To: <20061119142037.GA7583@soi.city.ac.uk> References: <20061119044129.GA12107@cse.unsw.EDU.AU> <20061119142037.GA7583@soi.city.ac.uk> Message-ID: <20061125021817.GA7029@cse.unsw.EDU.AU> ross: > On Sun, Nov 19, 2006 at 03:41:29PM +1100, Donald Bruce Stewart wrote: > > http://haskell.org/haskellwiki/How_to_write_a_Haskell_program > > > > Feedback welcome! > > There is inconsistent advice regarding Setup.hs/Setup.lhs. > (#! in .hs files seems to be a feature of GHC Haskell.) Fixed. And mkcabal generates .lhs Setups now. > For releases, another possibility is Cabal's sdist feature. This will > do a bit more checking, and ensure that the tarball has the structure > expected by HackageDB. In the example project, you'd want to add > > extra-source-files: Tests.hs > > to make this work. Thanks for the constructive suggestions Ross. I've added information on Cabal's sdist to the page. -- Don From newsham at lava.net Fri Nov 24 23:02:04 2006 From: newsham at lava.net (Tim Newsham) Date: Fri Nov 24 23:00:39 2006 Subject: [Haskell-cafe] ghc 6.6 crash Message-ID: I just built GHC 6.6 on my linux Fedora Core box (athlon 700mhz). When I run it, it crashes. The 6.4 version works fine (which I also built). # ghc-6.6 Segmentation fault # gdb /usr/local/lib/ghc-6.6/ghc-6.6 GNU gdb Red Hat Linux (6.0post-0.20040223.19rh) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-redhat-linux-gnu"...(no debugging symbols found)...Using host libthread_db library "/lib/libthread_db.so.1". (gdb) run -B/usr/local/lib/ghc-6.6 Starting program: /usr/local/lib/ghc-6.6/ghc-6.6 -B/usr/local/lib/ghc-6.6 Error while mapping shared library sections: : Success. Error while reading shared library symbols: : No such file or directory. (no debugging symbols found)...(no debugging symbols found)...[Thread debugging using libthread_db enabled] [New Thread 16384 (LWP 20880)] Error while reading shared library symbols: : No such file or directory. Error while reading shared library symbols: : No such file or directory. Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 16384 (LWP 20880)] 0x00421d3b in __pthread_clock_gettime () from /lib/i686/libpthread.so.0 (gdb) where #0 0x00421d3b in __pthread_clock_gettime () from /lib/i686/libpthread.so.0 #1 0x00dc0331 in clock_gettime () from /lib/i686/librt.so.1 #2 0x0888fb4d in ?? () #3 0x00000003 in ?? () #4 0xfef22228 in ?? () #5 0xfef222e8 in ?? () #6 0x0888fe26 in ?? () #7 0x09462dd4 in ?? () #8 0x00000000 in ?? () (gdb) x/64 $esp 0xfef221a4: 0x13ea7d62 0x00000000 0x00000003 0x29a79300 0xfef221b4: 0x006ec840 0x00421cf0 0x00dc3ff4 0x00000003 0xfef221c4: 0x00000000 0xfef22208 0x00dc0331 0x00000003 0xfef221d4: 0x29a79300 0x00000000 0xfef22228 0x00dbc7ec 0xfef221e4: 0x09462d88 0x29a79300 0x00000000 0xffffffff 0xfef221f4: 0x006ec840 0x00000000 0x09462d88 0xfef222d0 0xfef22204: 0x00000002 0xfef222e8 0x0888fb4d 0x00000003 0xfef22214: 0xfef22228 0xfef222e8 0x0888fe26 0x09462dd4 0xfef22224: 0x00000000 0x0945c280 0x00000000 0x00000000 0xfef22234: 0x09462d88 0xfef222d0 0x0888f127 0x09462dd4 0xfef22244: 0x08962469 0xfef22268 0x0041d525 0xfef222d4 0xfef22254: 0xfef222d0 0x00000002 0x0888f23d 0xfef222d0 0xfef22264: 0x00000002 0xfef222d4 0x08888c73 0x089e2aa0 0xfef22274: 0x00000000 0x00000000 0x00000000 0x00000000 0xfef22284: 0x00000000 0xfef222d4 0x08890019 0xfef222d4 0xfef22294: 0xfef222d0 0xfef222d4 0x08889bde 0xfef222d0 # uname -a Linux box 2.6.5-1.358 #1 Sat May 8 09:04:50 EDT 2004 i686 athlon i386 GNU/Linux # ls -ld /lib/*pthread* -rwxr-xr-x 1 root root 95012 May 11 2004 /lib/libpthread-0.10.so* lrwxrwxrwx 1 root root 18 Jun 21 15:00 /lib/libpthread.so.0 -> libpthread-0.10.so* Tim Newsham http://www.thenewsh.com/~newsham/ From newsham at lava.net Fri Nov 24 23:34:12 2006 From: newsham at lava.net (Tim Newsham) Date: Fri Nov 24 23:32:47 2006 Subject: [Haskell-cafe] ghc 6.6 crash In-Reply-To: References: Message-ID: Also the build worked fine (as far as I can tell). Wouldn't ghc normally crash when building itself as part of the build process if it was defective in some way? On Fri, 24 Nov 2006, Tim Newsham wrote: > I just built GHC 6.6 on my linux Fedora Core box (athlon 700mhz). > When I run it, it crashes. The 6.4 version works fine (which > I also built). > > # ghc-6.6 > Segmentation fault Tim Newsham http://www.thenewsh.com/~newsham/ From briqueabraque at yahoo.com Sat Nov 25 07:41:56 2006 From: briqueabraque at yahoo.com (=?ISO-8859-1?Q?Maur=ED=ADcio?=) Date: Sat Nov 25 08:40:40 2006 Subject: [Haskell-cafe] Implementations of bit vectors Message-ID: Hi, Does anyone knows of a nice implementation of bit vectors? I like the functions I see in Data.Bits (rotate, shift etc.), but that only works with predefined sizes and I need a bit vector of exactly 33 bits. Thanks, Maur?cio From tomasz.zielonka at gmail.com Sat Nov 25 09:13:55 2006 From: tomasz.zielonka at gmail.com (Tomasz Zielonka) Date: Sat Nov 25 09:12:31 2006 Subject: [Haskell-cafe] Implementations of bit vectors In-Reply-To: References: Message-ID: <20061125141355.GB8796@lambda> On Sat, Nov 25, 2006 at 10:41:56AM -0200, Maur??cio wrote: > Does anyone knows of a nice implementation of bit vectors? > I like the functions I see in Data.Bits (rotate, shift etc.), > but that only works with predefined sizes and I need a bit > vector of exactly 33 bits. Unboxed arrays (UArray, IOUArray, STUArray) of Bools work just like a bit vector, with 8 elements packed in one byte. Best regards Tomasz From igloo at earth.li Sat Nov 25 09:45:25 2006 From: igloo at earth.li (Ian Lynagh) Date: Sat Nov 25 09:44:00 2006 Subject: [Haskell-cafe] Difficult memory leak in array processing In-Reply-To: References: Message-ID: <20061125144525.GB5391@matrix.chaos.earth.li> Hi Niko, On Thu, Nov 23, 2006 at 12:11:43PM +0200, Niko Korhonen wrote: > > I have the following code whose purpose is to add dither (noise) to a given > array. The code looks very straightforward but apparently it has a memory > leak somewhere. Here I try to run the algorithm for an array of 10,000,000 > integers. Ten million unboxed strict integers should equal to 40MB which > should pose no problems to any modern system. However, the program fails > with a stack overflow error. I'm using GHC 6.6 on Windows with 1 GB of RAM. I'm also unable to reproduce this. Can you tell us exactly what commandline you are using to compile and run the program please? Thanks Ian From zhen.sydow at gmail.com Sat Nov 25 10:59:11 2006 From: zhen.sydow at gmail.com (Luis Cabellos) Date: Sat Nov 25 10:57:48 2006 Subject: [Haskell-cafe] Haddock question Message-ID: <3f3964000611250759j35053d91g8f213eca638b06f8@mail.gmail.com> Hello, I follow the How to Write a Haskell program from http://www.haskell.org/haskellwiki/How_to_write_a_Haskell_program, but I have a problem with Haddock. I use Windows XP, I when I install GHC + Haddock I have this warning output C:\code\haskell\test> runhaskell Setup.hs haddock Preprocessing executables for Test-0.0... Running Haddock for Test-0.0... Warning: cannot use package Test-0.0: ghc-pkg failed Warning: cannot use package base-2.0: does not exist.y $topdir\html\libraries\base There is something generated in dist\doc\html\test path but only the main function page but it don't has the comments from *.hs file. I use --prefix=c:\programs instead of --prefix=$HOME in configure. Because I am working on Windows. I don't use darcs, but I think that it's not the problem. -- Thanks a lot, Luis Cabellos From bulat.ziganshin at gmail.com Sat Nov 25 12:26:16 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sat Nov 25 12:25:46 2006 Subject: [Haskell-cafe] Implementations of bit vectors In-Reply-To: <20061125141355.GB8796@lambda> References: <20061125141355.GB8796@lambda> Message-ID: <1151458858.20061125202616@gmail.com> Hello Tomasz, Saturday, November 25, 2006, 5:13:55 PM, you wrote: > On Sat, Nov 25, 2006 at 10:41:56AM -0200, Maur??cio wrote: >> Does anyone knows of a nice implementation of bit vectors? >> I like the functions I see in Data.Bits (rotate, shift etc.), >> but that only works with predefined sizes and I need a bit >> vector of exactly 33 bits. > Unboxed arrays (UArray, IOUArray, STUArray) of Bools work just like a > bit vector, with 8 elements packed in one byte. they don't support rotate/shift operations. i think it's better to implement this himself using Word64 -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From brian at brianweb.net Sat Nov 25 14:49:10 2006 From: brian at brianweb.net (Brian Alliet) Date: Sat Nov 25 14:47:43 2006 Subject: [Haskell-cafe] Implementations of bit vectors In-Reply-To: References: Message-ID: <20061125194910.GA86193@charger.brianweb.net> On Sat, Nov 25, 2006 at 10:41:56AM -0200, Maur??cio wrote: > Does anyone knows of a nice implementation of bit vectors? > I like the functions I see in Data.Bits (rotate, shift etc.), > but that only works with predefined sizes and I need a bit > vector of exactly 33 bits. Check out http://darcs.brianweb.net/hsutils/src/Brianweb/Word.lhs It supports typesafe (and efficient) operations on words of any bit length (including 33-bits). You can also safely split and join words. The type system ensures concatenating a Word16 and a Word32 results in a Word48, etc. -Brian From dons at cse.unsw.edu.au Sat Nov 25 18:35:07 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Sat Nov 25 18:33:44 2006 Subject: [Haskell-cafe] Haddock question In-Reply-To: <3f3964000611250759j35053d91g8f213eca638b06f8@mail.gmail.com> References: <3f3964000611250759j35053d91g8f213eca638b06f8@mail.gmail.com> Message-ID: <20061125233506.GB8572@cse.unsw.EDU.AU> zhen.sydow: > Hello, > > I follow the How to Write a Haskell program from > http://www.haskell.org/haskellwiki/How_to_write_a_Haskell_program, but > I have a problem with Haddock. > > I use Windows XP, I when I install GHC + Haddock I have this warning output > > C:\code\haskell\test> runhaskell Setup.hs haddock > Preprocessing executables for Test-0.0... > Running Haddock for Test-0.0... > Warning: cannot use package Test-0.0: > ghc-pkg failed > Warning: cannot use package base-2.0: > does not exist.y $topdir\html\libraries\base > > There is something generated in dist\doc\html\test path but only the > main function page but it don't has the comments from *.hs file. > > I use --prefix=c:\programs instead of --prefix=$HOME in configure. > Because I am working on Windows. > > I don't use darcs, but I think that it's not the problem. It appears to be an error in current haddock when interacting with ghc 6.6. If you use haddock 0.8, the error message is there, but the documentation is still generated, so should be ok: $ runhaskell Setup.lhs haddock Preprocessing executables for haq-0.0... Running Haddock for haq-0.0... Warning: cannot use package haq-0.0: ghc-pkg failed Warning: cannot use package base-2.0: HTML directory /home/dons/share/ghc-6.6/html/libraries/base does not exist. Warning: Main: the following names could not be resolved: IO $ w3m -dump dist/doc/html/haq/Main.html haq Contents Index Main Synopsis main :: IO () Documentation main :: IO () main runs the main program Produced by Haddock version 0.8 So grab haddock 0.8 and try that. http://haskell.org/haddock/#Download -- Don From dons at cse.unsw.edu.au Sat Nov 25 19:04:52 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Sat Nov 25 19:03:26 2006 Subject: [Haskell-cafe] Improving library documentation Message-ID: <20061126000452.GC8572@cse.unsw.EDU.AU> People sometimes complain that the standard libraries need more documentation. Since we have so many eyes reading the haddock source, a low barrier way for people to improve the docs is needed. I've created a new wiki page, linked from the libraries page: http://haskell.org/haskellwiki/Improving_library_documentation This page is to track documentation improvments suggested by *you*. So if you're reading the haddocks, and notice something's not documented, or missing details, please record it on this page, so it can be improved and committed. -- Don From tomac at pacific.net.au Sat Nov 25 23:12:31 2006 From: tomac at pacific.net.au (Ivan Tomac) Date: Sat Nov 25 23:11:07 2006 Subject: [Haskell-cafe] Optimizing a hash function Message-ID: Hi, Yesterday evening I had a go at porting Bob Jenkins' hash function (http://www.burtleburtle.net/bob/c/lookup3.c) to Haskell. The first version I came up with ran 20 times slower than C. Thanks to Don Stewart's suggestions on IRC, I managed to improve the performance by replacing tuples with a strict type so the current version is about 10 times slower than C code. Is there any way this can be further optimized? To keep things fair I've simplified the C function so it works on one byte at a time as opposed to an int at a time. The code was compiled with GHC-6.6 on a G5 iMac running OS X 10.4. Options used to compile the version using the hash function written in Haskell: ghc -O -funbox-strict-fields -fglasgow-exts -fbang-patterns -cpp -o test hashByteString.hs test.hs Options used to compile the version using the hash function in C: ghc -O -fglasgow-exts -ffi -fbang-patterns -cpp -DCHASH -o ctest ctest.c test.hs Ivan Tomac -------------- next part -------------- A non-text attachment was scrubbed... Name: ctest.c Type: application/octet-stream Size: 2085 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061126/cb6b900b/ctest.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: ctest.h Type: application/octet-stream Size: 101 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061126/cb6b900b/ctest-0001.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: hashByteString.hs Type: application/octet-stream Size: 2561 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061126/cb6b900b/hashByteString.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: test.hs Type: application/octet-stream Size: 650 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061126/cb6b900b/test.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: test.prof Type: application/octet-stream Size: 3134 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061126/cb6b900b/test-0001.obj From tomac at pacific.net.au Sat Nov 25 23:28:13 2006 From: tomac at pacific.net.au (Ivan Tomac) Date: Sat Nov 25 23:26:47 2006 Subject: [Haskell-cafe] SMP support in GHC 6.6 on PPC Macs Message-ID: <62CB5DBC-6687-421F-8BDA-937AAF7848D3@pacific.net.au> I've noticed that code compiled with -threaded doesn't like +RTS - N as an argument. This seems to be the case with both the binary distribution of GHC 6.6 at www.haskell.org/ghc as well as the version I built from sources. I got rid of all the old versions of GHC on my system and ghc -- version reports 6.6. So I'm guessing this is a bug? Ivan From zhen.sydow at gmail.com Sun Nov 26 06:01:41 2006 From: zhen.sydow at gmail.com (Luis Cabellos) Date: Sun Nov 26 06:00:26 2006 Subject: [Haskell-cafe] Haddock question In-Reply-To: <20061125233506.GB8572@cse.unsw.EDU.AU> References: <3f3964000611250759j35053d91g8f213eca638b06f8@mail.gmail.com> <20061125233506.GB8572@cse.unsw.EDU.AU> Message-ID: <3f3964000611260301y1fe8d2dak7d69657a3c428756@mail.gmail.com> Ok, With your example I realized that I don't write the type signature declaration of anything. Without the type Haddock don't put the comments from code in the generated doc. Now it works. Thanks. Luis On 11/26/06, Donald Bruce Stewart wrote: > It appears to be an error in current haddock when interacting with ghc > 6.6. > > If you use haddock 0.8, the error message is there, but the > documentation is still generated, so should be ok: > > $ runhaskell Setup.lhs haddock > Preprocessing executables for haq-0.0... > Running Haddock for haq-0.0... > Warning: cannot use package haq-0.0: > ghc-pkg failed > Warning: cannot use package base-2.0: > HTML directory /home/dons/share/ghc-6.6/html/libraries/base does not exist. > Warning: Main: the following names could not be resolved: > IO > > $ w3m -dump dist/doc/html/haq/Main.html > haq Contents Index > Main > Synopsis > main :: IO () > Documentation > main :: IO () > main runs the main program > Produced by Haddock version 0.8 > > So grab haddock 0.8 and try that. > > http://haskell.org/haddock/#Download > > -- Don > From isto.aho at dnainternet.net Sun Nov 26 08:04:38 2006 From: isto.aho at dnainternet.net (isto) Date: Sun Nov 26 08:03:27 2006 Subject: [Haskell-cafe] Optimizing a hash function In-Reply-To: References: Message-ID: <1164546278.4958.12.camel@localhost.localdomain> su, 2006-11-26 kello 15:12 +1100, Ivan Tomac kirjoitti: > The first version I came up with ran 20 times slower than C. > Thanks to Don Stewart's suggestions on IRC, I managed to improve the > ... > Options used to compile the version using the hash function written > in Haskell: > ghc -O -funbox-strict-fields -fglasgow-exts -fbang-patterns -cpp -o > test hashByteString.hs test.hs > > Options used to compile the version using the hash function in C: > ghc -O -fglasgow-exts -ffi -fbang-patterns -cpp -DCHASH -o ctest > ctest.c test.hs Hi Ivan Tomac, Have you tried -O3 -optc-O3 -funfolding-use-threshold=16 compile flags? Don, Lemmih, Lennart and Bulat helped me to sort out a similar problem a couple of weeks ago. More hints can be found at http://haskell.org/haskellwiki/Performance/GHC Especially, to check generated code by taking a look of core -ddump-simpl > core.txt and to check memory leaks, you could run with +RTS -sstderr br, Isto From clawsie at fastmail.fm Sun Nov 26 10:45:29 2006 From: clawsie at fastmail.fm (brad clawsie) Date: Sun Nov 26 10:43:57 2006 Subject: [Haskell-cafe] re: Improving library documentation Message-ID: <1164555929.29949.277468535@webmail.messagingengine.com> don, i am glad you raised this point, i was going to write a note to this list soon with a similar request i would suggest comparing perldoc to haddock and other haskell documentation tools. generally speaking, i find that documentation for perl libraries is written as if the author is enthusiastic about users understanding it. there are typically detailed function descriptions, and often inlined examples. on the other hand i have found most haddock documentation to consist merely of function signatures. as a result i have to employ spotty supplemental references like the haskell ref at zvon.org (which i am sure is a copy of a well-known reference set floating around out there), which includes some examples, or google's code search with haskell support. furthermore, perldoc has querying capabilities (-f etc) which preclude having to surf around references, another great feature. regardless of format, well-written documentation will go a long way to forwarding haskell adoption. brad From apfelmus at quantentunnel.de Sun Nov 26 12:28:22 2006 From: apfelmus at quantentunnel.de (apfelmus@quantentunnel.de) Date: Sun Nov 26 12:30:32 2006 Subject: [Haskell-cafe] Re: Optimizing a hash function In-Reply-To: References: Message-ID: > Yesterday evening I had a go at porting Bob Jenkins' hash function > (http://www.burtleburtle.net/bob/c/lookup3.c) to Haskell. If you need hash functions, I hope that you don't need them to become a hash table necromancer: this dark data structure simply does not fit well into Haskell. Tries are a better alternative: Ralf Hinze. Generalizing generalized tries. Journal of Functional Programming, 10(4):327-351, July 2000 http://www.informatik.uni-bonn.de/~ralf/publications/GGTries.ps.gz Otherwise, take care to conduct hash experiments inside Otiluke's Resilient Sphere only. Regards, apfelmus From bulat.ziganshin at gmail.com Sun Nov 26 14:54:33 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sun Nov 26 14:55:26 2006 Subject: [Haskell-cafe] The Future of MissingH In-Reply-To: References: Message-ID: <42374139.20061126225433@gmail.com> Hello John, Friday, November 24, 2006, 7:32:55 PM, you wrote: > Josef Svenningsson posted a comment on my blog today that got me to > thinking. He suggested that people may be "intimidated by the size of > MissingH, confused by the undescriptive name, and don't quite know what's > in there." And I think he's right. first, is it possible to integrate MissingH inside existing core libs, i.e. Haskell libs supported by Haskell community? i think that it will be impossible if MissingH will hold its GPL status. i think that such fundamental library as MissingH should be BSDified to allow use it both in commercial and non-commercial code if library will be not BSDified it can remain as a whole or be splitted to smaller conceptual parts (strings, file system, logging...) but these parts should remain separate from other haskell libs and these features can't be made, say, part of a Haskell standard if library will be BSDified, and somewhat "advertized". i hope that its parts will start moving to the more specific libs of core set, say HVFS system into the Files library, logging facilities into the Unix library, so on next. why your library isn't well recognized. i can suggest in each announce of new library version write the full list of its features or at least url to such advertizing page. second, are you included your library in HCAR and hswiki/Libraries_and_tools pages? third, while i personally prefer to read source code and fascinated with quality of code documenting in your lib, most peoples prefer to read Haddocks, which again should be made available on web next, while you accept patches to the lib, this's not declared in your announces. best way is just to open darcs repository - most peoples thinks that having darcs repository and accepting patches is the same thing :) i can also propose you the idea that Pupeno, packager of Streams library used - he included in the tgz files copy of darcs repository, again facilitating use of darcs and developing new patches for library and, about WindowsCompat.hs - stat() function is available on Windows and even used to implement getModificationTime :) > I initially wrote it that way to make resolving dependencies easier > for end users. now Cabal handles this > How could greater community participation be encouraged, while still > encouraging quality control? > I have received some very good contributions to MissingH from people, > and that's been great. I've also received some that just aren't that > great -- they don't have Haddock docs, the code is opaque, they > don't come with unit tests, etc. > But by and large, I've been maintaining it mostly myself. i think that this is more general question for all haskell core libraries -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From dominic.steinitz at blueyonder.co.uk Sun Nov 26 15:26:15 2006 From: dominic.steinitz at blueyonder.co.uk (Dominic Steinitz) Date: Sun Nov 26 15:26:24 2006 Subject: [Haskell-cafe] Implementations of bit vectors Message-ID: <200611262026.16191.dominic.steinitz@blueyonder.co.uk> You could also look at http://darcs.haskell.org/crypto/Data/LargeWord.hs but it would need modifying to produce a 33 bit word. Dominic. From ithika at gmail.com Sun Nov 26 15:32:58 2006 From: ithika at gmail.com (Dougal Stanton) Date: Sun Nov 26 15:28:44 2006 Subject: [Haskell-cafe] The Future of MissingH In-Reply-To: <42374139.20061126225433@gmail.com> References: <42374139.20061126225433@gmail.com> Message-ID: <20061126203258.GA11504@glowfish> Quoth Bulat Ziganshin, nevermore, > while i personally prefer to read source code and fascinated with > quality of code documenting in your lib, most peoples prefer to read > Haddocks, which again should be made available on web I just thought I should point out, cos there appears to be some confusion on the matter, that there is a Haddock API for MissingH, which I've found to be very informative. As Neil Mitchell (I think) mentioned earlier it's not on a standard HTTP port which may be unsuitable for some people. Cheers, D. From ken.takusagawa.2 at gmail.com Sun Nov 26 16:58:13 2006 From: ken.takusagawa.2 at gmail.com (Ken Takusagawa) Date: Sun Nov 26 16:56:44 2006 Subject: [Haskell-cafe] Priority Queue? Message-ID: <4dcea1d80611261358v47260460tc48dfd5342303e56@mail.gmail.com> Is there a Haskell implementation of an efficient priority queue (probably heap-based) out there that I can use? I do not see it in the GHC libraries. From sjanssen at cse.unl.edu Sun Nov 26 17:21:38 2006 From: sjanssen at cse.unl.edu (Spencer Janssen) Date: Sun Nov 26 17:20:20 2006 Subject: [Haskell-cafe] Priority Queue? In-Reply-To: <4dcea1d80611261358v47260460tc48dfd5342303e56@mail.gmail.com> References: <4dcea1d80611261358v47260460tc48dfd5342303e56@mail.gmail.com> Message-ID: <3E92B546-5240-465D-BAAA-D62C4CC8C14D@cse.unl.edu> I recommend the Edison library, which has several heap implementations. http://www.eecs.tufts.edu/~rdocki01/edison.html Cheers, Spencer Janssen On Nov 26, 2006, at 3:58 PM, Ken Takusagawa wrote: > Is there a Haskell implementation of an efficient priority queue > (probably heap-based) out there that I can use? I do not see it in > the GHC libraries. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From benjamin.franksen at bessy.de Sun Nov 26 17:46:34 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Sun Nov 26 17:45:19 2006 Subject: [Haskell-cafe] Re: The Future of MissingH References: <42374139.20061126225433@gmail.com> Message-ID: Bulat Ziganshin wrote: > Friday, November 24, 2006, 7:32:55 PM, you wrote: >> Josef Svenningsson posted a comment on my blog today that got me to >> thinking. He suggested that people may be "intimidated by the size of >> MissingH, confused by the undescriptive name, and don't quite know what's >> in there." And I think he's right. > > first, is it possible to integrate MissingH inside existing core libs, > i.e. Haskell libs supported by Haskell community? i think that it will > be impossible if MissingH will hold its GPL status. i think that > such fundamental library as MissingH should be BSDified to allow use > it both in commercial and non-commercial code I hate to be nitpicking but GPL is not only compatible with but encourages commerce in general and commercial software in particular. It is incompatible with proprietary software. There's a difference. Cheers Ben From benjamin.franksen at bessy.de Sun Nov 26 18:19:20 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Sun Nov 26 18:18:17 2006 Subject: [Haskell-cafe] Re: Priority Queue? References: <4dcea1d80611261358v47260460tc48dfd5342303e56@mail.gmail.com> Message-ID: Ken Takusagawa wrote: > Is there a Haskell implementation of an efficient priority queue > (probably heap-based) out there that I can use? I do not see it in > the GHC libraries. Unfortunately the base package contains only the specialized Data.Sequence and not the general annotated 2-3 finger trees, which could be easily instantiated to an efficient priority queue. I have a package lying around that I wrote 1 or 2 years ago that implements the (much more complicated) search tree version of the 2-3 finger trees. I just managed to compile it again. Can send you a tarball if you are interested. Ben From ross at soi.city.ac.uk Sun Nov 26 20:36:45 2006 From: ross at soi.city.ac.uk (Ross Paterson) Date: Sun Nov 26 20:35:15 2006 Subject: [Haskell-cafe] Priority Queue? In-Reply-To: <4dcea1d80611261358v47260460tc48dfd5342303e56@mail.gmail.com> References: <4dcea1d80611261358v47260460tc48dfd5342303e56@mail.gmail.com> Message-ID: <20061127013645.GB19717@soi.city.ac.uk> On Sun, Nov 26, 2006 at 04:58:13PM -0500, Ken Takusagawa wrote: > Is there a Haskell implementation of an efficient priority queue > (probably heap-based) out there that I can use? I do not see it in > the GHC libraries. As already mentioned, there are several in Edison. If you want to roll your own, you can't get much simpler than Okasaki's lazy skew heaps, from "The Fun of Programming" (the Edison version is a specialized version of this): data Tree a = Null | Fork a (Tree a) (Tree a) isEmpty :: Tree a -> Bool isEmpty Null = True isEmpty _ = False minElem :: Tree a -> a minElem (Fork x a b) = x deleteMin :: Ord a => Tree a -> Tree a deleteMin (Fork x a b) = merge a b insert :: Ord a => a -> Tree a -> Tree a insert x a = merge (singleton x) a where singleton x = Fork x Null Null merge :: Ord a => Tree a -> Tree a -> Tree a merge a Null = a merge Null b = b merge a b | minElem a <= minElem b = join a b | otherwise = join b a where join (Fork x a b) c = Fork x b (merge a c) From mark at ixod.org Sun Nov 26 20:56:15 2006 From: mark at ixod.org (Mark T.B. Carroll) Date: Sun Nov 26 20:54:45 2006 Subject: [Haskell-cafe] Priority Queue? In-Reply-To: <4dcea1d80611261358v47260460tc48dfd5342303e56@mail.gmail.com> (Ken Takusagawa's message of "Sun, 26 Nov 2006 16:58:13 -0500") References: <4dcea1d80611261358v47260460tc48dfd5342303e56@mail.gmail.com> Message-ID: <87bqmt7iv4.fsf@ixod.org> "Ken Takusagawa" writes: > Is there a Haskell implementation of an efficient priority queue > (probably heap-based) out there that I can use? I do not see it in > the GHC libraries. ISTR Okasaki's algorithms book has a suitable one. -- Mark From duncan.coutts at worc.ox.ac.uk Sun Nov 26 22:00:37 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun Nov 26 21:59:39 2006 Subject: [Haskell-cafe] Glade Gtk2Hs Tutorial In-Reply-To: <1162754661.4447.10.camel@localhost.localdomain> References: <1162754661.4447.10.camel@localhost.localdomain> Message-ID: <1164596437.7838.80.camel@localhost> An updated version of the Glade tutorial for Haskell & Gtk2Hs is now available on the Gtk2Hs website: http://haskell.org/gtk2hs/docs/tutorial/glade/ This is of course linked from the documentation page on the Gtk2Hs site: http://haskell.org/gtk2hs/documentation/#tutorials Thanks very much to Eddy Ahmed, the original author and to Hans van Thiel for 'porting' the tutorial from Gtk's C API to Haskell and Gtk2Hs. We are seeking help with writing other tutorials too, in particular an introductory tutorial. If that's something you think you might be interested in helping with then darcs get the Gtk2Hs sources and send in your changes (or if you don't do darcs then email is fine). So far we have just a quick outline: http://haskell.org/gtk2hs/docs/tutorial/intro/ Duncan On Sun, 2006-11-05 at 20:24 +0100, Hans van Thiel wrote: > The Haskell Gtk2Hs adaptation of the 'Developing Gnome Apps with Glade' > tutorial for beginners is now also on http://eddy.writelinux.com/ > Note there are translations there of the original version for C in > French, Dutch, Spanish, Turkish and Korean. Native speakers of those > languages who are interested could use these and check out the Haskell > Gtk2Hs listings later. From max.vasin at gmail.com Mon Nov 27 02:04:15 2006 From: max.vasin at gmail.com (Max Vasin) Date: Mon Nov 27 02:07:34 2006 Subject: [Haskell-cafe] Re: The Future of MissingH References: <42374139.20061126225433@gmail.com> Message-ID: <87wt5hl6a8.fsf@smtp.gmail.com> >>>>> "Benjamin" == Benjamin Franksen writes: Benjamin> Bulat Ziganshin wrote: >> Friday, November 24, 2006, 7:32:55 PM, you wrote: >> Josef Svenningsson posted a comment on my blog today that got me to >>> thinking. He suggested that people may be "intimidated by the >>> size of MissingH, confused by the undescriptive name, and >>> don't quite know what's in there." And I think he's right. >> >> first, is it possible to integrate MissingH inside existing >> core libs, i.e. Haskell libs supported by Haskell community? i >> think that it will be impossible if MissingH will hold its GPL >> status. i think that such fundamental library as MissingH >> should be BSDified to allow use it both in commercial and >> non-commercial code Benjamin> I hate to be nitpicking but GPL is not only compatible Benjamin> with but encourages commerce in general and commercial Benjamin> software in particular. It is incompatible with Benjamin> proprietary software. There's a difference. A small addition: some GPLed libraries (libstdc++ AFAIK) allow linking with proprietary software by adding clause to lisence which relaxes GPL requirements. -- WBR, Max Vasin. From simonpj at microsoft.com Mon Nov 27 03:38:36 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Mon Nov 27 03:37:06 2006 Subject: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: <4567729D.2000307@list.mightyreason.com> References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net> <89ca3d1f0611231244j3d6dcaa7i84356813324422be@mail.gmail.com> <9BF202E6B745664F896FB822A141D3310BB3BB3B@EA-EXMSG-C303.europe.corp.microsoft.com> <4567729D.2000307@list.mightyreason.com> Message-ID: | Normally after a retry the STM block is rolled back and put to sleep and will | only be awakened and re-executed if one of the STM variables it had read from is | committed to by a different STM block. The *semantics* are that it is retried anytime in the future. The *pragmatics* are as you describe. | What about retryWith ? Will the STM block be put to sleep under the same | conditions? Can the IO action given to retryWith include commits to STM variables? The semantics are the same as before: the action passed to retryWith is run, and the block is retried anytime in the future. The pragmatics are the same: the action passed to retryWith is run, and the block is put to sleep only to be awakened if one of the STM variables it has read from has been written to -- which could have happened already if the IO action did so. Simon From bulat.ziganshin at gmail.com Mon Nov 27 04:03:58 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Mon Nov 27 04:21:40 2006 Subject: [Haskell-cafe] Re: The Future of MissingH In-Reply-To: References: <42374139.20061126225433@gmail.com> Message-ID: <428423380.20061127120358@gmail.com> Hello Benjamin, Monday, November 27, 2006, 1:46:34 AM, you wrote: > I hate to be nitpicking but GPL is not only compatible with but encourages > commerce in general and commercial software in particular. It is > incompatible with proprietary software. There's a difference. of course, but on practice most of commercial software are closed-source. i personally use this license when i want to show code to the world but don't want that but will be used in commercial software (without paying royalties). my own program contains several general-purpose modules that is BSDified and rest of program, which is a task-specific, is GPLed -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bulat.ziganshin at gmail.com Mon Nov 27 04:08:14 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Mon Nov 27 04:21:47 2006 Subject: [Haskell-cafe] Re: The Future of MissingH In-Reply-To: <87wt5hl6a8.fsf@smtp.gmail.com> References: <42374139.20061126225433@gmail.com> <87wt5hl6a8.fsf@smtp.gmail.com> Message-ID: <231135055.20061127120814@gmail.com> Hello Max, Monday, November 27, 2006, 10:04:15 AM, you wrote: > A small addition: some GPLed libraries (libstdc++ AFAIK) allow > linking with proprietary software by adding clause to lisence > which relaxes GPL requirements. a GPL license text is the same for any GPLed software, otherwise it cannot be called "GPL" :) this should be a LGPL. also there are many double-licensed libs. you can find details about this in LGPL and GPL pages of wikipedia (where i've read this) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From tomac at pacific.net.au Mon Nov 27 04:27:11 2006 From: tomac at pacific.net.au (Ivan Tomac) Date: Mon Nov 27 04:25:41 2006 Subject: [Haskell-cafe] Optimizing a hash function In-Reply-To: <1164546278.4958.12.camel@localhost.localdomain> References: <1164546278.4958.12.camel@localhost.localdomain> Message-ID: <712AF215-9036-49E0-8629-030FCDDD62E5@pacific.net.au> Hi, I've seen that guide before and followed the suggestions in there but somehow I missed the -funfolding-use-threshhold option. After setting it to 24 the code now runs about 2-3 times slower than C which is a significant improvement from a factor of 10. Thanks :) Ivan On 27/11/2006, at 12:04 AM, isto wrote: > > Have you tried -O3 -optc-O3 -funfolding-use-threshold=16 > compile flags? Don, Lemmih, Lennart and Bulat helped me to sort > out a similar problem a couple of weeks ago. More hints can be > found at > http://haskell.org/haskellwiki/Performance/GHC > Especially, to check generated code by taking a look of core > -ddump-simpl > core.txt > and to check memory leaks, you could run with > +RTS -sstderr > > br, Isto > From dagit at eecs.oregonstate.edu Mon Nov 27 04:35:12 2006 From: dagit at eecs.oregonstate.edu (Jason Dagit) Date: Mon Nov 27 04:33:40 2006 Subject: [Haskell-cafe] ANN: NeHe Tutorials in Haskell Message-ID: Hello, I was recently reminded by http://haskell.org/haskellwiki/How_to_write_a_Haskell_program that you should announce your haskell projects! About a year ago I started converting the (somewhat) famous NeHe tutorials for OpenGL to HOpenGL. I have created a darcs repository for anyone interested (and I welcome darcs patches). You may find it here: http://codersbase.com/index.php/Nehe-tuts If you're interested in contributing, please observe one requirement, I want the examples to be as much in vanilla Haskell98 as possible to help make it accessible to beginners. Also, if you have feedback that is also very welcome. Thanks Jason From asandroq at gmail.com Mon Nov 27 06:35:12 2006 From: asandroq at gmail.com (Alex Queiroz) Date: Mon Nov 27 06:33:41 2006 Subject: [Haskell-cafe] Re: The Future of MissingH In-Reply-To: <87wt5hl6a8.fsf@smtp.gmail.com> References: <42374139.20061126225433@gmail.com> <87wt5hl6a8.fsf@smtp.gmail.com> Message-ID: <54e12800611270335w3c9adfd1t701163682c70d3fc@mail.gmail.com> Hallo, On 11/27/06, Max Vasin wrote: > > A small addition: some GPLed libraries (libstdc++ AFAIK) allow > linking with proprietary software by adding clause to lisence > which relaxes GPL requirements. > Nope, it's LGPL with an extra binary linking permission. Cheers, -- -alex http://www.ventonegro.org/ From simonpj at microsoft.com Mon Nov 27 06:43:55 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Mon Nov 27 06:42:25 2006 Subject: [Haskell-cafe] why are implicit types different? (cleanup) In-Reply-To: References: Message-ID: Implicit parameters have monotypes, not polytypes. So ?f in g gets type (Char->Char). I rather doubt that something more general (implicit parameters get polytypes) would work, given the implicit "improvement" rules that implicit parameters require. Simon | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of S. | Alexander Jacobson | Sent: 21 November 2006 19:28 | To: haskell-cafe@haskell.org | Subject: [Haskell-cafe] why are implicit types different? (cleanup) | | | | Why do g and g' have different types? | | g x y = let ?f = \x-> x in ?f x ++ (show (?f y)) | g :: [Char] -> [Char] -> [Char] | | g' :: (Show t) => [Char] -> t -> [Char] | g' x y = let f = \x-> x in f x ++ (show (f y)) | | Is there a way I can use implicit types and let g be as general as g'? | | -Alex- | | | ______________________________________________________________ | S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe From niko.korhonen at gmail.com Mon Nov 27 07:34:50 2006 From: niko.korhonen at gmail.com (Niko Korhonen) Date: Mon Nov 27 07:33:25 2006 Subject: [Haskell-cafe] Difficult memory leak in array processing In-Reply-To: <20061125144525.GB5391@matrix.chaos.earth.li> References: <20061125144525.GB5391@matrix.chaos.earth.li> Message-ID: <456ADB6A.9030907@gmail.com> I can say neither that I have any idea what an 'undead array' is nor that I would really understand the code you've posted. On the positive side of things, you've given me a lot to think about. Maybe in the fullness of time I shall return and say 'Lo! I can write leakless Haskell code!'. But alas, that time seems so distant now. However, this necromancy business really does sound like an exiting new career prospect. Interesting job opportunities, respect of the community, flexible hours and extremely loyal peers and other commandlings that will literally work for just for the Brain Food. Regards, Nik The Blak, Necromancer of the Glorious Forces of Evil PS: No. PSS: And I shall. apfelmus wrote: > Ah, yet another UndeadArray necromancer exhausting his stack of bones. > May the forces of light suggest to structure the incantation of darkness? > > modifyArray arr i f = > readArray arr i >>= \y -> writeArray arr i (f y) > > accumM :: (MArray a e m, Ix i) => > (e -> e' -> e) -> a i e -> [(i, e')] -> m () > accumM f arr xs = mapM_ chg xs > where chg (i,x) = modifyArray arr i (flip f x) > > twodice (x:x':xs) = (x+x') `div` 2 : twodice xs > noise rng gen = twodice $ randomRs rng gen > > main = do > let bnds = (0, 10000000) > buf <- newArray_ bnds :: IO Buffer > > gen <- getStdGen > accumM (curry snd) buf $ zip (range bnds) $ noise (2,12) gen > > > I absolutely don't know why there is no (accumM) function in the > standard libraries. And having the ByteString API (maybe even the > fusion) for general arrays would be very nice. Maybe (modifyArray) is > missing, too. > > > Regards, > apfelmus > > PS: did you try > worker low (i `seq` i-1) ? > PSS: The strictness analyzer is likely to insert that automatically if > you compile with -O or -O2. From niko.korhonen at gmail.com Mon Nov 27 07:40:14 2006 From: niko.korhonen at gmail.com (Niko Korhonen) Date: Mon Nov 27 07:38:45 2006 Subject: [Haskell-cafe] Difficult memory leak in array processing In-Reply-To: <20061125144525.GB5391@matrix.chaos.earth.li> References: <20061125144525.GB5391@matrix.chaos.earth.li> Message-ID: <456ADCAE.9010004@gmail.com> Ian Lynagh wrote: > I'm also unable to reproduce this. Can you tell us exactly what > commandline you are using to compile and run the program please? In fact it turned out that the example code I posted did not exhibit the memory leak at all. It just took a /very long time/ to complete (compared to a Java version), but it did complete. My complete code, which also counted the instances of a given number from the array, does however exhibit the leak. It is here: module Main where import Data.Array.IO import System.Random type Buffer = IOUArray Int Int -- | Triangular Probability Density Function, equivalent to a roll of two dice. -- The number sums have different probabilities of surfacing. tpdf :: (Int, Int) -> IO Int tpdf (low, high) = do first <- getStdRandom (randomR (low, high)) second <- getStdRandom (randomR (low, high)) return ((first + second) `div` 2) -- | Fills an array with dither generated by the specified function. genSeries :: Buffer -> ((Int, Int) -> IO Int) -> (Int, Int) -> IO () genSeries buf denfun lims = let worker low i | i >= low = do r <- denfun lims writeArray buf i r worker low (i - 1) | otherwise = return () in do (lo, hi) <- getBounds buf worker lo hi countNumbers :: Buffer -> Int -> IO Int countNumbers buf x = let worker lo i acc | i >= lo = do n <- readArray buf i if n == x then worker lo (i - 1) (acc + 1) else worker lo (i - 1) acc | otherwise = return acc in do (lo, hi) <- getBounds buf worker lo hi 0 main = do buf <- newArray_ (0, 10000000) :: IO Buffer genSeries buf tpdf (2, 12) sevens <- countNumbers buf 7 putStrLn ("Magic number sevens: " ++ show sevens) return 0 From max.vasin at gmail.com Mon Nov 27 08:56:46 2006 From: max.vasin at gmail.com (Max Vasin) Date: Mon Nov 27 09:00:29 2006 Subject: [Haskell-cafe] Re: The Future of MissingH References: <42374139.20061126225433@gmail.com> <87wt5hl6a8.fsf@smtp.gmail.com> <231135055.20061127120814@gmail.com> Message-ID: <87slg5kn6p.fsf@smtp.gmail.com> >>>>> "Bulat" == Bulat Ziganshin writes: Bulat> Hello Max, Hello, Bulat> Monday, November 27, 2006, 10:04:15 AM, you wrote: > A small addition: some GPLed libraries (libstdc++ AFAIK) allow >> linking with proprietary software by adding clause to lisence >> which relaxes GPL requirements. Bulat> a GPL license text is the same for any GPLed software, Bulat> otherwise it cannot be called "GPL" :) this should be a Bulat> LGPL. also there are many double-licensed libs. you can Bulat> find details about this in LGPL and GPL pages of wikipedia Bulat> (where i've read this) from /usr/share/doc/libstdc++6/copyright: The libstdc++-v3 library is licensed under the terms of the GNU General Public License, with this special exception: As a special exception, you may use this file as part of a free software library without restriction. Specifically, if other files instantiate templates or use macros or inline functions from this file, or you compile this file and link it with other files to produce an executable, this file does not by itself cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. -- WBR, Max Vasin. From claus.reinke at talk21.com Mon Nov 27 09:21:32 2006 From: claus.reinke at talk21.com (Claus Reinke) Date: Mon Nov 27 09:20:02 2006 Subject: [Haskell-cafe] Difficult memory leak in array processing References: <20061125144525.GB5391@matrix.chaos.earth.li> <456ADCAE.9010004@gmail.com> Message-ID: <00d201c7122f$57816850$b74f7ad5@cr3lt> > In fact it turned out that the example code I posted did not exhibit the > memory leak at all. It just took a /very long time/ to complete > (compared to a Java version), but it did complete. My complete code, > which also counted the instances of a given number from the array, does > however exhibit the leak. It is here: quick guess, and useful pattern-to-avoid: tail-recursive functions with non-strict accumulators may be tail recursive, but they build up unevaluated expressions representing the accumulations; when those are forced by inspection, the evaluator descends non-tail-recursively into those possibly deep accumulations (..(0+1)..+1), possibly resulting in stack overflows. the worker in genSeries inspects its parameters at each call, keeping them evaluated; the worker in countNumbers inspects only its first two parameters, possibly (depending on optimizations) leaving acc unevaluated. try: worker lo (i-1) $! acc hth, claus > module Main where > > import Data.Array.IO > import System.Random > > type Buffer = IOUArray Int Int > > -- | Triangular Probability Density Function, equivalent to a roll of > two dice. > -- The number sums have different probabilities of surfacing. > tpdf :: (Int, Int) -> IO Int > tpdf (low, high) = do > first <- getStdRandom (randomR (low, high)) > second <- getStdRandom (randomR (low, high)) > return ((first + second) `div` 2) > > -- | Fills an array with dither generated by the specified function. > genSeries :: Buffer -> ((Int, Int) -> IO Int) -> (Int, Int) -> IO () > genSeries buf denfun lims = > let worker low i > | i >= low = do > r <- denfun lims > writeArray buf i r > worker low (i - 1) > | otherwise = return () > in do > (lo, hi) <- getBounds buf > worker lo hi > > countNumbers :: Buffer -> Int -> IO Int > countNumbers buf x = > let worker lo i acc > | i >= lo = do > n <- readArray buf i > if n == x > then worker lo (i - 1) (acc + 1) > else worker lo (i - 1) acc > | otherwise = return acc > in do > (lo, hi) <- getBounds buf > worker lo hi 0 > > main = do > buf <- newArray_ (0, 10000000) :: IO Buffer > genSeries buf tpdf (2, 12) > sevens <- countNumbers buf 7 > putStrLn ("Magic number sevens: " ++ show sevens) > return 0 > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From alex at alexjacobson.com Mon Nov 27 11:21:51 2006 From: alex at alexjacobson.com (S. Alexander Jacobson) Date: Mon Nov 27 11:20:18 2006 Subject: [Haskell-cafe] why are implicit types different? (cleanup) In-Reply-To: References: Message-ID: Ok, I'm not sure I understand the answer here, but how about a workaround. My current code looks like this: tt = let ?withPassNet=wpn ?withPassNet'=wpn ?withPassNet''=wpn in passNet "passnet" ["user"] regImpl b The type of wpn is: wpn :: Ev PassNet ev a -> Ev State ev a The individual implicit parameters end up arriving with concrete values for a. If I pass wpn to passNet explicitly, it also appears to get converted to a monotype on arrival at the inside of passNet. So I guess the real question is, how do I pass a polytype* wpn? -Alex- * I would have thought the word was polymorphic, but you obvoiusly know. ______________________________________________________________ S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com On Mon, 27 Nov 2006, Simon Peyton-Jones wrote: > Implicit parameters have monotypes, not polytypes. So ?f in g gets > type (Char->Char). I rather doubt that something more general > (implicit parameters get polytypes) would work, given the implicit > "improvement" rules that implicit parameters require. > > Simon > > | -----Original Message----- > | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of S. > | Alexander Jacobson > | Sent: 21 November 2006 19:28 > | To: haskell-cafe@haskell.org > | Subject: [Haskell-cafe] why are implicit types different? (cleanup) > | > | > | > | Why do g and g' have different types? > | > | g x y = let ?f = \x-> x in ?f x ++ (show (?f y)) > | g :: [Char] -> [Char] -> [Char] > | > | g' :: (Show t) => [Char] -> t -> [Char] > | g' x y = let f = \x-> x in f x ++ (show (f y)) > | > | Is there a way I can use implicit types and let g be as general as g'? > | > | -Alex- > | > | > | ______________________________________________________________ > | S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com > | _______________________________________________ > | Haskell-Cafe mailing list > | Haskell-Cafe@haskell.org > | http://www.haskell.org/mailman/listinfo/haskell-cafe > From apfelmus at quantentunnel.de Mon Nov 27 14:45:10 2006 From: apfelmus at quantentunnel.de (apfelmus@quantentunnel.de) Date: Mon Nov 27 14:47:32 2006 Subject: [Haskell-cafe] Re: Difficult memory leak in array processing In-Reply-To: <456ADCAE.9010004@gmail.com> References: <20061125144525.GB5391@matrix.chaos.earth.li> <456ADCAE.9010004@gmail.com> Message-ID: > nor that I would really understand the code you've posted. On the positive > side of things, you've given me a lot to think about. Maybe in the > fullness of time I shall return and say 'Lo! I can write leakless > Haskell code!'. But alas, that time seems so distant now. I tried to show how the code can be rewritten in a more declarative manner by the use of the higher order function (accumM) which is akin to the accumulation function (Data.Array.accum) for immutable arrays. This removes the need for traversing the array by hand with (worker). As Claus Reinke already pointed out, the accumulating parameter (acc) in your full example has to be evaluated strictly or it will overflow the stack. This is the same situation as in the famous example length' [] n = n length' (_:xs) n = length' xs (n+1) By avoiding (worker) and using higher order functions, you can avoid this kind of accumulating parameters altogether: length xs = foldr (+1) 0 xs Besides, writing things explicitly tail recursive does not help much in Haskell. In the following, I'm going to explain the restructured code posted. First of all, reducing the amount of IOs is always good for code sanity. Formulated with an emotional undertone, IO is "evil". Why do you need IO? There are two reasons: the mutable array and the random numbers. Random numbers clearly are a side-effect, but there is a wonderful trick: you simply fetch a lazy infinite list of random numbers and work with that. With System.Random, you can say do -- get the default pseudo-random number generator, -- it already has good random seed gen <- getStgGen let rs = randomsRs (2,12) gen result = dostuffwith rs return result (rs) is an infinite list of random numbers and (dostuffwith) is a pure function, no IO involved. In our case, twodice (x:x':xs) = (x+x') `div` 2 : twodice xs noise rng gen = twodice $ randomRs rng gen is a combination of (rs) and (dostuff). (noise) simply supplies an infinite list of random numbers to (twodice). (twodice) processes this list by taking pairs and averaging them. Both cover the functionality of your (tpdf) offers. Concerning mutable arrays, > I can say neither that I have any idea what an 'undead array' is "UndeadArray" is a bowdlerization of "Unboxed Array" which is the type you're using as Buffer. They generally are to be considered "evil" as well, hence the renaming. Their only use is to store huge amounts of memory like their most prominent example (ByteString). If you want to add noise to an actual audio channel, then they can be adequate. But if you only want statistics about random numbers, they're completely out of place. In that case, countNumber k xs = length $ filter (k==) xs main = do gen <- getStdGen return $ countNumber 7 (noise (2,12) gen) will do everything you need. If mutable arrays are really unavoidable (hence this is only for "necromancers"), the use of higher order functions is mandatory. One useful higher order function is (accum) from Data.Array. The adaption to the mutable case uses the helper function modifyArray arr i f = readArray arr i >>= \y -> writeArray arr i (f y) which applies f to the array element at position i. accumM f arr xs = mapM_ chg xs where chg (i,x) = modifyArray arr i (flip f x) "takes an array and an association list and accumulates pairs from the list into the array with the accumulating function f" (documentation from Data.Array.accum). For example if arr[0] == 0, arr[1] == 1, arr[2] == 2, arr[3] == 3 then brr = accum (+) arr [(1,2),(1,3),(2,3)] yields brr[0] == 0, brr[1] == 6, brr[2] == 5, brr[3] == 3 As another example, (accum (curry snd) arr xs) replaces the array entries by those listed in xs. Finally, countNumber can be expressed as a fold over the array. In general, every higher order function for lists can be translated to one for arrays. > However, this necromancy business really does sound like an exiting new > career prospect. Interesting job opportunities, respect of the > community, flexible hours and extremely loyal peers and other > commandlings that will literally work for just for the Brain Food. > > Regards, > Nik The Blak, Necromancer of the Glorious Forces of Evil This is indeed very tempting :) Though I suspect that the glory of forces built on (IO a) will be very limited. Regards, apfelmus, Golden Delicious of the Shining Bulbs of Light From magnus at therning.org Mon Nov 27 17:26:58 2006 From: magnus at therning.org (Magnus Therning) Date: Mon Nov 27 17:25:30 2006 Subject: [Haskell-cafe] c2hs and cabal? Message-ID: <20061127222658.GA3769@die.therning.org> Can I use cabal to build packages that incorporates C libraries and FFI Haskell created using c2hs? Any pointers on how to do that? /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus Software is not manufactured, it is something you write and publish. Keep Europe free from software patents, we do not want censorship by patent law on written works. If voting could really change things it would be illegal. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061127/afbdb91b/attachment.bin From escafia at gmail.com Sat Nov 25 14:39:00 2006 From: escafia at gmail.com (escafia) Date: Mon Nov 27 17:39:50 2006 Subject: [Haskell-cafe] Binary code Message-ID: <7541561.post@talk.nabble.com> Hi, i've one fuction receiving an int . The objective is return the respective binary code of that int. For example, if i receive 28 the fuction will return 011100. My question is that there is any fuction in libraries that do this? If not, anyone has any suggestion? Thank you. -- View this message in context: http://www.nabble.com/Binary-code-tf2704645.html#a7541561 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From trevion at gmail.com Mon Nov 27 19:20:15 2006 From: trevion at gmail.com (J. Garrett Morris) Date: Mon Nov 27 19:18:44 2006 Subject: [Haskell-cafe] Binary code In-Reply-To: <7541561.post@talk.nabble.com> References: <7541561.post@talk.nabble.com> Message-ID: <6cf91caa0611271620k1f914630m820c7710349303ff@mail.gmail.com> Hello, First, and forgive me if I'm making unwarranted assumptions, but http://haskell.org/haskellwiki/Homework_help might be useful. Second: div, mod, reverse, and the unfoldr function from Data.List will do what you want. /g On 11/25/06, escafia wrote: > > Hi, > > i've one fuction receiving an int . The objective is return the respective > binary code of that int. > > For example, if i receive 28 the fuction will return 011100. > > My question is that there is any fuction in libraries that do this? > If not, anyone has any suggestion? > > Thank you. > -- > View this message in context: http://www.nabble.com/Binary-code-tf2704645.html#a7541561 > Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- It is myself I have never met, whose face is pasted on the underside of my mind. From duncan.coutts at worc.ox.ac.uk Mon Nov 27 19:33:42 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Mon Nov 27 19:33:01 2006 Subject: [Haskell-cafe] c2hs and cabal? In-Reply-To: <20061127222658.GA3769@die.therning.org> References: <20061127222658.GA3769@die.therning.org> Message-ID: <1164674022.7683.10.camel@localhost> On Mon, 2006-11-27 at 22:26 +0000, Magnus Therning wrote: > Can I use cabal to build packages that incorporates C libraries and FFI > Haskell created using c2hs? Yes you can. Cabal understands a bit about .chs files. I think all you need to do is specify the module in the exposed-modules or other-modules and Cabal will find the .chs file and try to build a .hs file from it. However at the moment your .chs files cannot import each other because Cabal doesn't to any dependency analysis. That means you can't use c2hs's {# import #} hooks. An initial patch was posted to the cabal-devel mailing list to do this properly but it hasn't been integrated yet. Duncan From valentin.gjorgjioski at ijs.si Mon Nov 27 19:39:40 2006 From: valentin.gjorgjioski at ijs.si (Valentin Gjorgjioski) Date: Mon Nov 27 19:38:16 2006 Subject: [Haskell-cafe] Binary code In-Reply-To: <6cf91caa0611271620k1f914630m820c7710349303ff@mail.gmail.com> References: <7541561.post@talk.nabble.com> <6cf91caa0611271620k1f914630m820c7710349303ff@mail.gmail.com> Message-ID: <456B854C.8060504@ijs.si> On 28.11.2006 01:20 J. Garrett Morris wrote: > Hello, > > First, and forgive me if I'm making unwarranted assumptions, but > http://haskell.org/haskellwiki/Homework_help might be useful. > > Second: div, mod, reverse, and the unfoldr function from Data.List > will do what you want. > > /g > > On 11/25/06, escafia wrote: >> >> Hi, >> >> i've one fuction receiving an int . The objective is return the >> respective >> binary code of that int. >> >> For example, if i receive 28 the fuction will return 011100. >> So, if it is really homework, and looks like, here is the start binary :: Int->[Int] binary 0 = [0] binary x = binary.... div and mod are enough for start :) From stefanor at cox.net Mon Nov 27 19:42:44 2006 From: stefanor at cox.net (Stefan O'Rear) Date: Mon Nov 27 19:41:09 2006 Subject: [Haskell-cafe] Binary code In-Reply-To: <6cf91caa0611271620k1f914630m820c7710349303ff@mail.gmail.com> References: <7541561.post@talk.nabble.com> <6cf91caa0611271620k1f914630m820c7710349303ff@mail.gmail.com> Message-ID: <20061128004244.GA5489@localhost.localdomain> On Mon, Nov 27, 2006 at 06:20:15PM -0600, J. Garrett Morris wrote: > First, and forgive me if I'm making unwarranted assumptions, but > http://haskell.org/haskellwiki/Homework_help might be useful. > > On 11/25/06, escafia wrote: > >i've one fuction receiving an int . The objective is return the respective > >binary code of that int. > > > >For example, if i receive 28 the fuction will return 011100. > > > >My question is that there is any fuction in libraries that do this? > >If not, anyone has any suggestion? It depends on how you plan to represent bit strings. One of the best representations of bits strings for computation purposes is packed, rightmost bit at position 0, pad with 0's. If you choose that representation, the function you want is available in the Haskell '98 Prelude. It's called "id". I'd recommend using a newtype, however. From mark at ixod.org Mon Nov 27 19:46:32 2006 From: mark at ixod.org (Mark T.B. Carroll) Date: Mon Nov 27 19:45:04 2006 Subject: [Haskell-cafe] Binary code In-Reply-To: <7541561.post@talk.nabble.com> (escafia@gmail.com's message of "Sat, 25 Nov 2006 11:39:00 -0800 (PST)") References: <7541561.post@talk.nabble.com> Message-ID: <874pskgzyv.fsf@ixod.org> escafia writes: > Hi, > > i've one fuction receiving an int . The objective is return the respective > binary code of that int. > > For example, if i receive 28 the fuction will return 011100. In GHCi, Prelude> Numeric.showIntAtBase 2 (head . show) 28 $ "" "11100" > My question is that there is any fuction in libraries that do this? > If not, anyone has any suggestion? Other alternatives include, import Data.Bits import Data.List toBinary 0 = "0" toBinary i = reverse (unfoldr nextDigit i) where nextDigit 0 = Nothing nextDigit i = Just (head (show (i .&. 1)), shiftR i 1) or maybe, as you seem to want a certain number of digits, toBinary d i = concatMap show [ fromEnum (testBit i n) | n <- reverse [0..d-1] ] or likewise will work. It's probably best to just use showIntAtBase and pad it with however many 0's you want, though. -- Mark From benjamin.franksen at bessy.de Mon Nov 27 21:00:58 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Mon Nov 27 20:59:53 2006 Subject: [Haskell-cafe] Re: Re: The Future of MissingH References: <42374139.20061126225433@gmail.com> <428423380.20061127120358@gmail.com> Message-ID: Bulat Ziganshin wrote: > Monday, November 27, 2006, 1:46:34 AM, you wrote: >> I hate to be nitpicking but GPL is not only compatible with but >> encourages commerce in general and commercial software in particular. It >> is incompatible with proprietary software. There's a difference. > > of course, but on practice most of commercial software are > closed-source. i personally use this license when i want to show code > to the world but don't want that but will be used in commercial > software (without paying royalties). This is impossible. GPL expressly allows commercial use of your software. You cannot license under GPL and at the same time disallow making money out of it, this would be incompatible. If, however, you actually meant to say 'proprietary', then I would kindly ask you to say so. Imprecise usage of the term 'commercial' as a synonym (**) for 'proprietary' only serves to promote common misconceptions. It is neither in the spirit nor the words of the GPL to be opposed to commerce (=earning money by selling work or things of value to others), and there is ample proof(*) that it isn't opposed to commerce in practice, too. And no, I don't intend to pursue this (somewhat off-) topic any further ;-) Cheers Ben (*) anyone know how much Novell paid for buying SuSE? Not that it's gotten any better since... (**) some would say 'euphemism' From benjamin.franksen at bessy.de Mon Nov 27 21:02:29 2006 From: benjamin.franksen at bessy.de (Benjamin Franksen) Date: Mon Nov 27 21:03:36 2006 Subject: [Haskell-cafe] RE: why are implicit types different? (cleanup) References: Message-ID: S. Alexander Jacobson wrote: > Ok, I'm not sure I understand the answer here, but how about a > workaround. My current code looks like this: > > tt = let ?withPassNet=wpn > ?withPassNet'=wpn > ?withPassNet''=wpn > in passNet "passnet" ["user"] regImpl b > > The type of wpn is: > > wpn :: Ev PassNet ev a -> Ev State ev a > > The individual implicit parameters end up arriving with concrete > values for a. If I pass wpn to passNet explicitly, it also appears to > get converted to a monotype on arrival at the inside of passNet. > > So I guess the real question is, how do I pass a polytype* wpn? Wrap it inside a newtype, maybe? Ben From dons at cse.unsw.edu.au Mon Nov 27 22:58:47 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Mon Nov 27 22:57:23 2006 Subject: [Haskell-cafe] Binary code In-Reply-To: <6cf91caa0611271620k1f914630m820c7710349303ff@mail.gmail.com> References: <7541561.post@talk.nabble.com> <6cf91caa0611271620k1f914630m820c7710349303ff@mail.gmail.com> Message-ID: <20061128035847.GC13923@cse.unsw.EDU.AU> trevion: > Hello, > > First, and forgive me if I'm making unwarranted assumptions, but > http://haskell.org/haskellwiki/Homework_help might be useful. Yes, almost certainly this is the case. The same questions were asked on #haskell at pretty much the same time... 15:54:34 --- join: greg_lundien joined #haskell 15:54:51 is there a library function in haskell to convert from decimal to binary?? 15:55:19 @hoogle showIntAtBase 15:55:20 Numeric.showIntAtBase :: Integral a => a -> (Int -> Char) -> a -> ShowS 15:55:39 sjanssen: thanks 15:56:10 > showIntAtBase 100 (head . show) 2 "" 15:56:11 "2" 15:56:30 > showIntAtBase 2 (head . show) 100 "" 15:56:31 "1100100" 15:57:04 greg_lundien: why do you need to convert to binary? 15:57:23 > showIntAtBase 2 Char.intToDigit 100 "" 15:57:24 "1100100" 15:57:42 dons: uh... long story? do you know how to do it? 15:58:29 all ints are binary 15:58:37 the showIntAtBase thing doesn't work with guys 15:58:45 only with girls? 15:58:47 *with hugs, not guys 15:58:50 lolz 15:58:54 :m + Numeric 15:58:56 import Numeric 15:58:59 oic 15:59:01 ?hoogle showIntAtBase 15:59:02 Numeric.showIntAtBase :: Integral a => a -> (Int -> Char) -> a -> ShowS 15:59:36 cant import numeric 15:59:44 --- quit: greg_lundien ("Leaving") -- Don From dons at cse.unsw.edu.au Mon Nov 27 23:01:25 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Mon Nov 27 22:59:56 2006 Subject: [Haskell-cafe] [Redirect] polymorphism and existential types Message-ID: <20061128040125.GE13923@cse.unsw.EDU.AU> Redirected to haskell-cafe@haskell.org, the right list. -- Don ----- Forwarded message from Louis-Julien Guillemette ----- Date: Mon, 27 Nov 2006 16:15:26 -0500 (EST) From: Louis-Julien Guillemette Subject: [Haskell] polymorphism and existential types Supposing a polymorphic value (of type, say, forall a . ExpT a t) is stored inside an existential package (of type, say, forall a . Exp a), I wonder how to recover a polymorphic value when eliminating the existential. The ``natural way'' to write this doesn't work: {-# OPTIONS -fglasgow-exts #-} data ExpT a t data Exp a = forall t . Exp (ExpT a t) f :: (forall a . ExpT a t) -> () f e = () g :: (forall a . ExpT a t) -> () g e = let e1 :: forall a . Exp a e1 = Exp e in case e1 of Exp e' -> f e' {- Test.hs:18:17: Inferred type is less polymorphic than expected Quantified type variable `a' is mentioned in the environment: e' :: ExpT a t (bound at Test.hs:18:11) In the first argument of `f', namely `e'' In the expression: f e' In a case alternative: Exp e' -> f e' Failed, modules loaded: none. -} In particular, the solution of pushing the forall inside doesn't work for me (it breaks other parts of my code...) : data Exp' = forall t . Exp' (forall a . ExpT a t) g' :: (forall a . ExpT a t) -> () g' e = let e1 :: Exp' e1 = Exp' e in case e1 of Exp' e' -> f e' Any help welcome! Louis-Julien _______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell From bonobo at bigpond.net.au Tue Nov 28 02:50:14 2006 From: bonobo at bigpond.net.au (Alexis Hazell) Date: Tue Nov 28 02:48:50 2006 Subject: [Haskell-cafe] GHCi and HXT Message-ID: <200611281850.16017.bonobo@bigpond.net.au> Hi all, i'm having a bit of difficulty using GHCi to try out HXT. i brought the Text.XML.HXT.Arrow module into scope using :m. Then i entered: let contact = mkelem "stream:stream" [ sattr "xmlns:stream" "http://etherx.jabber.org/streams", sattr "xmlns" "jabber:client", sattr "to" "livejournal.com" ] [] and got the error message: :1:14: Ambiguous type variable `a' in the constraint: `ArrowXml a' arising from use of `mkelem' at :1:14-19 Probable fix: add a type signature that fixes these type variable(s) The type signature of mkelem is mkelem :: (ArrowXml a) => String -> [a n XmlTree] -> [a n XmlTree] -> a n XmlTree So then i modified it to: let contact = mkelem "stream:stream" [ sattr "xmlns:stream" "http://etherx.jabber.org/streams", sattr "xmlns" "jabber:client", sattr "to" "livejournal.com" ] [] :: ArrowXml a => a XmlTree XmlTree And got: :1:14: Ambiguous type variable `a' in the constraint: `ArrowXml a' arising from instantiating a type signature at :1:14-194 Probable fix: add a type signature that fixes these type variable(s) i don't understand why i need to specify type signatures when they should already be in scope? And if i /do/ need to specify the type signatures for some reason, how do i do so in a manner that works? Any help much appreciated! Alexis. From dm.maillists at gmail.com Tue Nov 28 03:43:11 2006 From: dm.maillists at gmail.com (Daniel McAllansmith) Date: Tue Nov 28 03:41:44 2006 Subject: [Haskell-cafe] GHCi and HXT In-Reply-To: <200611281850.16017.bonobo@bigpond.net.au> References: <200611281850.16017.bonobo@bigpond.net.au> Message-ID: <200611282143.11305.dm.maillists@gmail.com> On Tuesday 28 November 2006 20:50, Alexis Hazell wrote: > let contact = mkelem "stream:stream" [ sattr "xmlns:stream" > "http://etherx.jabber.org/streams", sattr "xmlns" "jabber:client", sattr > "to" "livejournal.com" ] [] :: ArrowXml a => a XmlTree XmlTree > > And got: > > :1:14: > Ambiguous type variable `a' in the constraint: > `ArrowXml a' > arising from instantiating a type signature at :1:14-194 > Probable fix: add a type signature that fixes these type variable(s) > > i don't understand why i need to specify type signatures when they should > already be in scope? Is this a result of the monomorphism restriction? > And if i /do/ need to specify the type signatures for > some reason, how do i do so in a manner that works? You need to add a type signature that specifies a specific arrow data type 'a' that is an instance of ArrowXml. There are many instances of ArrowXml provided in HXT, eg LA, IOSArrow, IOSLArrow, etc so try something like: let contact = mkelem "stream:stream" [ sattr "xmlns:stream" "http://etherx.jabber.org/streams", sattr "xmlns" "jabber:client", sattr "to" "livejournal.com" ] [] :: IOSArrow XmlTree XmlTree By the way, once you have the declaration of contact in a source file, and it is being used by a function in which the ArrowXml instance is not ambiguous eg: foo = runX contact the type checker will be able to infer the type and you don't have to include the type signature. Daniel From bonobo at bigpond.net.au Tue Nov 28 04:38:43 2006 From: bonobo at bigpond.net.au (Alexis Hazell) Date: Tue Nov 28 04:37:13 2006 Subject: [Haskell-cafe] GHCi and HXT In-Reply-To: <200611282143.11305.dm.maillists@gmail.com> References: <200611281850.16017.bonobo@bigpond.net.au> <200611282143.11305.dm.maillists@gmail.com> Message-ID: <200611282038.45705.bonobo@bigpond.net.au> On Tue, 28 Nov 2006 07:43 pm, Daniel McAllansmith wrote: > On Tuesday 28 November 2006 20:50, Alexis Hazell wrote: > > i don't understand why i need to specify type signatures when they should > > already be in scope? > > Is this a result of the monomorphism restriction? Er . . . . i hadn't heard of this until just now. So i'll have to do some reading on the matter. :-) > You need to add a type signature that specifies a specific arrow data type > 'a' that is an instance of ArrowXml. Ah! i see - thanks. > By the way, once you have the declaration of contact in a source file, and > it is being used by a function in which the ArrowXml instance is not > ambiguous eg: > > foo = runX contact > > the type checker will be able to infer the type and you don't have to > include the type signature. *nod* Thanks again for your help. :-) Alexis. From niko.korhonen at gmail.com Tue Nov 28 05:42:10 2006 From: niko.korhonen at gmail.com (Niko Korhonen) Date: Tue Nov 28 05:40:37 2006 Subject: [Haskell-cafe] Re: Difficult memory leak in array processing In-Reply-To: References: <20061125144525.GB5391@matrix.chaos.earth.li> <456ADCAE.9010004@gmail.com> Message-ID: <456C1282.8000306@gmail.com> apfelmus@quantentunnel.de wrote: > I tried to show how the code can be rewritten in a more declarative > manner by the use of the higher order function (accumM) which is akin to > the accumulation function (Data.Array.accum) for immutable arrays. This Ok, given this explanation and your detailed annotations about the code, the whole thing now makes much more sense to me. This is indeed a much more Haskellish, more beautiful and certainly much less evil way to perform the task that I wanted to perform. Thank you for taking the time to explain the whole thing in such a detail; if nothing else, I've gained some pretty valuable insights on How To Do Things The Functional Way. Later in your reply you suggest that IOUArray would be an overkill for statistical analysis of random numbers, but possibly feasible for an actual audio buffer. I actually had both of these scenarios in mind. I have a version of the code that processes plain'ol Haskell lists instead of evil IOUArrays. Needless to say that this code is much more elegant and heavier on the folds and other higher order functions than the IOUArray code. I personally find doing higher order functions with IO extremely difficult, and the resulting compiler errors are often downright scary. But this is probably a direct consequence my rather limited understanding of the monadic operators that the do notion hides. It seems that one has to be /very/ good in Haskell before one can do IO effectively. Hmm. In imperative languages IO is the first thing one learns, before understanding how to combine a series of operations into a complete algorithm. Hence the 'void doIt()' functions that are so ubiquitous in the C and Java code out there. The folks may say that real-life Haskell code is littered with strictness annotations, but real-life C/C++/C#/Java code is littered with void doIt() functions, which are an order of magnitude worse from code clarity point of view... But back to the point, using Haskell lists for representing a largish buffer of, say, 16-bit samples that is constantly being refreshed from hard disk and sent into the sound system for playback would probably be inefficient beyond imagination. The overhead of one list element is probably larger than the size of the element itself (16 to 32 bit integers) and a new list would have to be generated every time more data is read from the hard disk. So the garbage collector would be working really hard all the time. And this list would have to be converted into an IO buffer for passing it to the C sound API anyway. These were the reasons why I went for the IOUArray way to begin with. For this particular problem, probably the most natural and efficient solution is to have a static buffer in memory to which data is read from the hard drive and which is then passed to the sound API for playback. For me, this seems the best way to do the job. But even this is not so obvious since I don't really know the performance implications of different Haskell constructs and the strong/weak points of the GHC compiler. The initial code I posted (without number counting) seems to take an awful long time to perform the task of filling the array with random numbers, especially compared to a Java (or actually Scala) solution which does more or less the same thing in 1/30 of the time. I will probably run some comparisons of my original code to the code you posted to see if there is a significant difference in not only elegance but performance too. Regards, Niko From magnus at therning.org Tue Nov 28 05:56:32 2006 From: magnus at therning.org (Magnus Therning) Date: Tue Nov 28 05:55:03 2006 Subject: [Haskell-cafe] c2hs and cabal? In-Reply-To: <1164674022.7683.10.camel@localhost> References: <20061127222658.GA3769@die.therning.org> <1164674022.7683.10.camel@localhost> Message-ID: <20061128105632.GA4362@die.therning.org> On Tue, Nov 28, 2006 at 00:33:42 +0000, Duncan Coutts wrote: >On Mon, 2006-11-27 at 22:26 +0000, Magnus Therning wrote: >> Can I use cabal to build packages that incorporates C libraries and FFI >> Haskell created using c2hs? > >Yes you can. Cabal understands a bit about .chs files. I think all you >need to do is specify the module in the exposed-modules or >other-modules and Cabal will find the .chs file and try to build a .hs >file from it. Thanks, that's really good. >However at the moment your .chs files cannot import each other because >Cabal doesn't to any dependency analysis. That means you can't use >c2hs's {# import #} hooks. > >An initial patch was posted to the cabal-devel mailing list to do this >properly but it hasn't been integrated yet. I'll keep that in mind. I'm still having some problems though :-( I thought I'd start with a minimal, rather silly, test to see if I can get Cabal to do what I want. I've stuck what I have at http://www.therning.org/magnus_files/cnh.tar.gz It fails to build for me with the following error: Preprocessing executables for cnh-0.1... Building cnh-0.1... [1 of 2] Compiling Foo ( src/Foo.hs, dist/build/cnh/cnh-tmp/Foo.o ) src/Foo.chs:6:8: parse error on input `import' I tried using '-v5' but it didn't really offer anymore insight for a novice like me :( /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus Software is not manufactured, it is something you write and publish. Keep Europe free from software patents, we do not want censorship by patent law on written works. Increasingly, people seem to misinterpret complexity as sophistication, which is baffling--the incomprehensible should cause suspicion rather than admiration. -- Niklaus Wirth -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061128/6dd37c77/attachment.bin From tharris at microsoft.com Tue Nov 28 06:28:42 2006 From: tharris at microsoft.com (Tim Harris (RESEARCH)) Date: Tue Nov 28 06:27:08 2006 Subject: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: <4567729D.2000307@list.mightyreason.com> Message-ID: <9BF202E6B745664F896FB822A141D3310E19BB70@EA-EXMSG-C303.europe.corp.microsoft.com> Hi, > After seeing how close I could come to creating onRetry/retryWith I have a > question about the semantics of your idea for retryWith. > > Normally after a retry the STM block is rolled back and put to sleep and > will > only be awakened and re-executed if one of the STM variables it had read > from is > committed to by a different STM block. > > What about retryWith ? Will the STM block be put to sleep under the same > conditions? Can the IO action given to retryWith include commits to STM > variables? Starting with this last question -- yes, the example of an STM GetLine using retryWith to pull more input into a buffer relies on an atomic block in the IO action to update the buffer. There are some interesting questions to think about the semantics of "retryWith". The semantics of "retry" in the PPoPP paper say nothing about putting threads to sleep -- it would be correct for an implementation to spin repeatedly executing an "atomic" block until it completes without calling "retry". What should happen with "retryWith" -- should we introduce blocking & wake-up into the semantics, or say that the "retryWith" actions are collected together, executed in place of the transaction (if it does ultimately retry) and then the transaction re-attempted? For simplicity (and to leave flexibility to the implementation) I'd prefer to keep blocking & wake-up out of the semantics. Taking that option, suppose we have "atomic { X }" and X retries with IO action Y. I think I'm saying that that would be equivalent to "Y ; atomic { X }". What are the consequences of this? In the GetLine example it means that an implementation that does put threads to sleep must detect conflicts between the first execution of X and any transactions performed in Y. Are there any interesting problems that come up if "Y" performs transactions that use "retry" or "retryWith"? Tim From mnislaih at gmail.com Tue Nov 28 06:35:09 2006 From: mnislaih at gmail.com (Pepe Iborra) Date: Tue Nov 28 06:33:47 2006 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: Visual Haskell prerelease 0.2 In-Reply-To: References: <456C0D21.1040202@imn.htwk-leipzig.de> Message-ID: <17066A4D-08EE-48C0-9040-60246D727206@gmail.com> On 28/11/2006, at 12:25, Krasimir Angelov wrote: > On 11/28/06, Johannes Waldmann wrote: >> seriously, how hard would it be to adapt VH to Eclipse? >> the interfaces (for syntax highlighting, typechecking etc.) >> should be similar - in theory. > Parsing and typechecking in VH is all done by GHC via the ghc-api. Thus strong interoperability support is needed. > Ah, and about Eclipse. Visual Studio and Eclipse are very different > platforms and you have to rewrite VSHaskell almost from scratch if you > want an Eclipse port. Perhaps the only common parts will be Cabal & > GHC. > Not only the interfaces are completely different, but an entirely new set of interoperability problems would need to be solved. The guys from EclipseFP have a document[1] about that topic. That said I would love being able to run an eclipsified VH in my Mac :) [1] - http://eclipsefp.sourceforge.net/haskell/ ExtendingEclipseInHaskell.pdf Cheers pepe From simonmarhaskell at gmail.com Tue Nov 28 07:05:53 2006 From: simonmarhaskell at gmail.com (Simon Marlow) Date: Tue Nov 28 07:04:19 2006 Subject: [Haskell-cafe] Re: The Future of MissingH In-Reply-To: <404396ef0611240926j6327f5cakfef276213058a748@mail.gmail.com> References: <404396ef0611240926j6327f5cakfef276213058a748@mail.gmail.com> Message-ID: <456C2621.4070108@microsoft.com> Neil Mitchell wrote: >> Could, and should, any of this be integrated into the Haskell libraries >> project? > > > Yes, some should, but only after careful review and being split up. > Assuming the Haskell libraries project is still something that should > be continued, once Hackage is up and running suddenly the distinction > becomes minimal. > > A few of the functions should be picked out and moved into base, where > they truely are missing. Yes please! This is what I hoped would happen to MissingH eventually. Cheers, Simon From slavomir.kaslev at gmail.com Tue Nov 28 07:46:13 2006 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Tue Nov 28 07:44:37 2006 Subject: [Haskell-cafe] [Haskell] Defining Cg, HLSL style vectors in Haskell Message-ID: <171dfd0a0611280446y2e4c4bb3qd36112c0093bb62b@mail.gmail.com> Hello, I have to define a couple of float2, float3, float4 Cg, HLSL style vectors in Haskell. At first I was tempted to make them instances of Num, Floating, RealFrac, etc. but some of the functions defined in those classes have no sense for vectors. One such example is signum from class Num. There are several workarounds for this. One may come up with some meaning for vectors of such functions, for example: instance Num Float3 where ..... signum a | a == Float3 0 0 0 = 0 | otherwise = 1 This is silly. Other option, which I prefer, is to leave such functions undefined (that is signum=undefined, not just not defining them). Is this ok? Are there any other options? Another bugging thing is that some of the functions do have meaning for vectors but they need different signatures. For example (**) :: Floating a => a -> a -> a, for vectors should be (**) :: (Floating a, Vector v) => v -> a -> v, that is (**) applied for every component of the vector. Any workarounds for that? I know that I can scrap all those Num, Floating, RealFrac, etc. classes and define class Vector from scratch, but I really don't want to come up and use different names for +, -, etc. that will bloat the code. Last question: Does haskell have something like C++ templates? For example, some time in the future I may need types like int2, short3, etc., that behave just like float2, float3, but use different types for their components. I really, really wouldn't like to copy-paste the definitions of floatn and manually change their types to intn respectfully. Cheers. -- Slavomir Kaslev From bulat.ziganshin at gmail.com Tue Nov 28 07:10:08 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Nov 28 08:05:26 2006 Subject: WordString Re[2]: [Haskell-cafe] Re: Difficult memory leak in array processing In-Reply-To: <456C1282.8000306@gmail.com> References: <20061125144525.GB5391@matrix.chaos.earth.li> <456ADCAE.9010004@gmail.com> <456C1282.8000306@gmail.com> Message-ID: <1848668746.20061128151008@gmail.com> Hello Niko, Tuesday, November 28, 2006, 1:42:10 PM, you wrote: > I personally find doing higher order functions with IO extremely > difficult, and the resulting compiler errors are often downright scary. > But this is probably a direct consequence my rather limited > understanding of the monadic operators that the do notion hides. It > seems that one has to be /very/ good in Haskell before one can do IO > effectively. i will say that one should be very good in general program optimization and know a few haskell-specific tricks, such as avoiding laziness and boxing optimization is my lovely problem, so i can help you somewhat. first, look at http://haskell.org/haskellwiki/Performance page. second, look at sources of ByteString (FPS) library - because it both shows efficient programming style and can be used for your sound processing > inefficient beyond imagination. The overhead of one list element is 8 bytes on 32-bit system > probably larger than the size of the element itself (16 to 32 bit > integers) and a new list would have to be generated every time more data > is read from the hard disk. So the garbage collector would be working > really hard all the time. And this list would have to be converted into > an IO buffer for passing it to the C sound API anyway. These were the > reasons why I went for the IOUArray way to begin with. For this > particular problem, probably the most natural and efficient solution is > to have a static buffer in memory to which data is read from the hard > drive and which is then passed to the sound API for playback. For me, > this seems the best way to do the job. it seems that you are ideal consumer for unboxed parallel arrays or extended ByteStrings (WordStrings :) we can ask Donald and Duncan whether they interested in implementing such extension? > But even this is not so obvious since I don't really know the > performance implications of different Haskell constructs and the > strong/weak points of the GHC compiler. i can give you pointers to some longer threads which discussed these topics -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From duncan.coutts at worc.ox.ac.uk Tue Nov 28 08:23:55 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Tue Nov 28 08:23:15 2006 Subject: WordString Re[2]: [Haskell-cafe] Re: Difficult memory leak in array processing In-Reply-To: <1848668746.20061128151008@gmail.com> References: <20061125144525.GB5391@matrix.chaos.earth.li> <456ADCAE.9010004@gmail.com> <456C1282.8000306@gmail.com> <1848668746.20061128151008@gmail.com> Message-ID: <1164720236.7683.62.camel@localhost> On Tue, 2006-11-28 at 15:10 +0300, Bulat Ziganshin wrote: > Hello Niko, > > Tuesday, November 28, 2006, 1:42:10 PM, you wrote: > > > I personally find doing higher order functions with IO extremely > > difficult, and the resulting compiler errors are often downright scary. > > But this is probably a direct consequence my rather limited > > understanding of the monadic operators that the do notion hides. It > > seems that one has to be /very/ good in Haskell before one can do IO > > effectively. > > i will say that one should be very good in general program > optimization and know a few haskell-specific tricks, such as avoiding > laziness and boxing > > optimization is my lovely problem, so i can help you somewhat. first, > look at http://haskell.org/haskellwiki/Performance page. second, look > at sources of ByteString (FPS) library - because it both shows efficient > programming style and can be used for your sound processing > > > inefficient beyond imagination. The overhead of one list element is > > 8 bytes on 32-bit system Actually it's 12 bytes. 4 for the cell header, 4 for the head pointer and 4 for the tail pointer. On a 64bit machine it is double that of course. > > probably larger than the size of the element itself (16 to 32 bit > > integers) and a new list would have to be generated every time more data > > is read from the hard disk. So the garbage collector would be working > > really hard all the time. And this list would have to be converted into > > an IO buffer for passing it to the C sound API anyway. These were the > > reasons why I went for the IOUArray way to begin with. For this > > particular problem, probably the most natural and efficient solution is > > to have a static buffer in memory to which data is read from the hard > > drive and which is then passed to the sound API for playback. For me, > > this seems the best way to do the job. > > it seems that you are ideal consumer for unboxed parallel arrays > or extended ByteStrings (WordStrings :) > > we can ask Donald and Duncan whether they interested in implementing such > extension? Spencer Janssen implemented a variant on ByteString for arbitrary instances of the Storable class. Duncan From simonpj at microsoft.com Tue Nov 28 08:25:41 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Tue Nov 28 08:24:06 2006 Subject: [Haskell-cafe] why are implicit types different? (cleanup) In-Reply-To: References: Message-ID: | So I guess the real question is, how do I pass a polytype* wpn? and the answer is: | On Mon, 27 Nov 2006, Simon Peyton-Jones wrote: | | > Implicit parameters have monotypes, not polytypes. So an implicit parameter never has a polymorphic type. You can get around this, as Ben suggested I think, by using a newtype to wrap it up: newtype WPN = WPN (forall a. Ev PassNet ev a -> Ev State ev a) Simon So ?f in g gets | > type (Char->Char). I rather doubt that something more general | > (implicit parameters get polytypes) would work, given the implicit | > "improvement" rules that implicit parameters require. | > | > Simon | > | > | -----Original Message----- | > | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of | S. | > | Alexander Jacobson | > | Sent: 21 November 2006 19:28 | > | To: haskell-cafe@haskell.org | > | Subject: [Haskell-cafe] why are implicit types different? (cleanup) | > | | > | | > | | > | Why do g and g' have different types? | > | | > | g x y = let ?f = \x-> x in ?f x ++ (show (?f y)) | > | g :: [Char] -> [Char] -> [Char] | > | | > | g' :: (Show t) => [Char] -> t -> [Char] | > | g' x y = let f = \x-> x in f x ++ (show (f y)) | > | | > | Is there a way I can use implicit types and let g be as general as g'? | > | | > | -Alex- | > | | > | | > | ______________________________________________________________ | > | S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com | > | _______________________________________________ | > | Haskell-Cafe mailing list | > | Haskell-Cafe@haskell.org | > | http://www.haskell.org/mailman/listinfo/haskell-cafe | > From haskell at list.mightyreason.com Tue Nov 28 10:52:58 2006 From: haskell at list.mightyreason.com (Chris Kuklewicz) Date: Tue Nov 28 10:51:16 2006 Subject: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: <9BF202E6B745664F896FB822A141D3310E19BB70@EA-EXMSG-C303.europe.corp.microsoft.com> References: <9BF202E6B745664F896FB822A141D3310E19BB70@EA-EXMSG-C303.europe.corp.microsoft.com> Message-ID: <456C5B5A.30606@list.mightyreason.com> Here I restate what you obviously know several times, then take a shot at answering your final question. Tim Harris (RESEARCH) wrote: > Hi, > >> After seeing how close I could come to creating onRetry/retryWith I have a >> question about the semantics of your idea for retryWith. >> >> Normally after a retry the STM block is rolled back and put to sleep and >> will >> only be awakened and re-executed if one of the STM variables it had read >> from is >> committed to by a different STM block. >> >> What about retryWith ? Will the STM block be put to sleep under the same >> conditions? Can the IO action given to retryWith include commits to STM >> variables? > > Starting with this last question -- yes, the example of an STM GetLine using retryWith to pull more input into a buffer relies on an atomic block in the IO action to update the buffer. That makes such (atomic X) actions which call (retryWith Y) useful, but will require changing the runtime to do efficiently if the (Y) action does not allow the (atomic X) to succeed/commit on the next attempt. Imaging that getLine does not block and returns no input, so (Y) does not feed (X). Then the next attempt to do (X) will (retryWith Y) and (Y) still fails to get input, so you have a "busy wait" where (Y) and (X) alternately execute. It will require a runtime change to prevent (X) from being retried until more input appears. In pseudocode this would be: X = if tchan is empty then retryWith Y else do work and commit Y = if input is available then feed tchan else return () > > There are some interesting questions to think about the semantics of "retryWith". The semantics of "retry" in the PPoPP paper say nothing about putting threads to sleep -- it would be correct for an implementation to spin repeatedly executing an "atomic" block until it completes without calling "retry". It would indeed be semantically correct, but if you have many spinning threads then the program will grind to a halt and few people would be able to employ STM. So the spec need not mention the blocking, but it should be possible to implement it that way. And GHC does. And onCommit can be implemented without changing from blocking to spinning, while retryWith does change from blocking to spinning (without a runtime change) > What should happen with "retryWith" -- should we introduce blocking & wake-up into the semantics, or say that the "retryWith" actions are collected together, executed in place of the transaction (if it does ultimately retry) and then the transaction re-attempted? Since (retryWith y1) `orElse` (retryWith y2) must execute y1 and y2, I used onRetry to collect such actions: "retryWith io = onRetry io >> retry". After running all the onRetry actions it immediately re-attempts the whole atomic transation without regard for whether any STM variables have been updated, so this causes spinning. [ Aside: I probably will modify it so that a lack of onRetry actions will prevent spinning. ] > For simplicity (and to leave flexibility to the implementation) I'd prefer to keep blocking & wake-up out of the semantics. > Taking that option, suppose we have "atomic { X }" and X retries with IO action Y. I think I'm saying that that would be equivalent to "Y ; atomic { X }". What are the consequences of this? Bad consequences. In particular, Y must finish before X is re-attempted. My implementation does this at the moment, which is bad, but the right solution requires a runtime change. > In the GetLine example it means that an implementation that does put threads to sleep must detect conflicts between the first execution of X and any transactions performed in Y. There may also be a distinction for whether [Existing/retry] If atomic { X } fails with a normal retry then rollback and put X to sleep until an appropriate STM update [Existing/fail] If atomic { X } fails with from a conflicting update then rollback and immediately re-attempt X [New case/retry] If atomic { X } fails with (retryWith Y) then rollback and put X to sleep until an appropriate STM update and then schedule (Y) (e.g. with forkIO). [New case/fail a] If atomic { X } fails with a conflicting update and has a pending (onRetry Y) then rollback and schedule both Y and a re-attempt of X. This last case comes from imagining using orElse: (code calls retryWith Y) `orElse` (code that causes conflicting update) in which case running Y seems like the obvious thing to do. > > Are there any interesting problems that come up if "Y" performs transactions that use "retry" or "retryWith"? > > Tim > In many useful cases, such as the getLine example, the Y action will have its own atomic {} block. In which case the semantics of when it is allowed to re-attempt X are what is important. If you require (Y) to complete before re-attempting (X) then you get an infinite regression where every (atomic block) fails with (retryWith (next atomic block)), and nothing is ever re-attempted. This is why "retryWith Y" meaning rollback X and do "Y >> atomic X" is the wrong implementation. If one takes "retryWith Y" to mean rollback X and do "forkIO Y >> atomic X" then one might spawn many many copies of Y waiting for atomic X to do something novel. Even if Y does not use retry/retryWith it can fail if it writes a conflicting update to an STM variable. Since we want Y to be able to commit updates to STM variables then Y can implicitly fail and retry. So the semantics must be what I said above, which implicitly allow X to be re-attempted as soon as anything performs an STM update without requiring the retryWith actions to finish first. One could imagine (atomic X) fails via (retryWith Y). X is put to sleep and Y is scheduled to run. Meanwhile another action Z executes and commits and updates whatever X is waiting on. So X is awakened and runs and commits. And only later does (Y) execute. -- Chris From magnus at therning.org Tue Nov 28 07:00:50 2006 From: magnus at therning.org (Magnus Therning) Date: Tue Nov 28 11:05:23 2006 Subject: [Haskell-cafe] c2hs and cabal? In-Reply-To: <1164712290.7683.34.camel@localhost> References: <20061127222658.GA3769@die.therning.org> <1164674022.7683.10.camel@localhost> <20061128105632.GA4362@die.therning.org> <1164712290.7683.34.camel@localhost> Message-ID: <20061128120050.GC26646@die.therning.org> On Tue, Nov 28, 2006 at 11:11:30 +0000, Duncan Coutts wrote: >On Tue, 2006-11-28 at 10:56 +0000, Magnus Therning wrote: >> On Tue, Nov 28, 2006 at 00:33:42 +0000, Duncan Coutts wrote: >> >On Mon, 2006-11-27 at 22:26 +0000, Magnus Therning wrote: >> >> Can I use cabal to build packages that incorporates C libraries and FFI >> >> Haskell created using c2hs? >> > >> >Yes you can. Cabal understands a bit about .chs files. I think all you >> >need to do is specify the module in the exposed-modules or >> >other-modules and Cabal will find the .chs file and try to build a .hs >> >file from it. > >> I'm still having some problems though :-( I thought I'd start with a >> minimal, rather silly, test to see if I can get Cabal to do what I want. >> I've stuck what I have at >> http://www.therning.org/magnus_files/cnh.tar.gz >> >> It fails to build for me with the following error: >> >> Preprocessing executables for cnh-0.1... >> Building cnh-0.1... >> [1 of 2] Compiling Foo ( src/Foo.hs, dist/build/cnh/cnh-tmp/Foo.o ) >> src/Foo.chs:6:8: parse error on input `import' >> >> I tried using '-v5' but it didn't really offer anymore insight for a >> novice like me :( > >Check the generated Foo.hs file to see if it looks obviously bogus. Can't really see anything obviously bogus about the following: % cat Foo.chs module Foo where #include "foo.h" fooOne i = {# call foo1 #} i % cat Foo.hs -- GENERATED by C->Haskell Compiler, version 0.14.5 Travelling Lightly, 12 Dec 2005 (Haskell) -- Edit the ORIGNAL .chs file instead! {-# LINE 1 "src/Foo.chs" #-}module Foo where fooOne i = foo1 i foreign import ccall safe "src/Foo.h foo1" foo1 :: (CInt -> (IO CInt)) Or am I missing something? /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus Software is not manufactured, it is something you write and publish. Keep Europe free from software patents, we do not want censorship by patent law on written works. "There are of course many problems connected with life, of which some of the most popular are `Why are people born?' `Why do they die?' `Why do they spend so much of the intervening time wearing digital watches?'" -- The Book. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061128/945f326c/attachment.bin From claus.reinke at talk21.com Tue Nov 28 11:53:16 2006 From: claus.reinke at talk21.com (Claus Reinke) Date: Tue Nov 28 11:51:47 2006 Subject: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explainSTM- video References: <252C89C12FCAD84BA018CAD5268682FD05B5F9FC@GBLONXMB02.corp.amvescap.net><89ca3d1f0611231244j3d6dcaa7i84356813324422be@mail.gmail.com><9BF202E6B745664F896FB822A141D3310BB3BB3B@EA-EXMSG-C303.europe.corp.microsoft.com><00ae01c70fc3$16dd7500$9a337ad5@cr3lt> Message-ID: <00bc01c7130d$b4916ac0$b1747ad5@cr3lt> also on the multi-version approach. but the particular reason I mentioned this was that it also tried to address the issue of composing transactions (discussion of which is explicitly excluded from the section 1.2 you refer to). for instance, compare the discussion and examples in "Composable Memory Transactions" with the one in section 3.11 (pp 80-) of Reed's thesis. not that STM isn't nicer, more complete, and all that;-) but Reed's ideas seemed rather more advanced than I had expected from the discussion of related work in the STM paper. Claus > Interesting reference. I had never heard of it. From reading section 1.2 it sounds like an early > description of > the optimistic approach to implementing atomic transactions (which is itself a > well-studied field). > > Simon | NAMING AND SYNCHRONIZATION IN A | DECENTRALIZED COMPUTER SYSTEM | | SourceTechnical Report: TR-205 | Year of Publication: 1978 | Author D. P. Reed | | I'm not entirely sure where I got my version from (it was mentioned | as a cornerstone in Alan Kay et al s latest project, Croquet, on which | Reed is a collaborator: http://www.opencroquet.org/ ), but here is | the abstract: | | http://portal.acm.org/citation.cfm?coll=GUIDE&dl=GUIDE&id=889815 | | (note that it mentions both grouping of updates, and synchronized | composition of modules with local synchronization constraints) | | and this might be the official site for the scanned copy (?): | | http://www.lcs.mit.edu/publications/specpub.php?id=773 From alex at alexjacobson.com Tue Nov 28 11:59:01 2006 From: alex at alexjacobson.com (S. Alexander Jacobson) Date: Tue Nov 28 11:57:22 2006 Subject: [Haskell-cafe] why are implicit types different? (cleanup) In-Reply-To: References: Message-ID: I ended up solving it by using a typeclass. My general experience of implicit types has been that they end up being a lot less useful than they appear. Getting the types right ends up being difficult and it is usually better just to be in a monad or as in this case to use typeclasses. I've begun to think of use of implicit types as a sign a "bad smell" in the code and if I have used one somewhere, I try to eliminate it because doing so usually results in better code overall. -Alex- ______________________________________________________________ S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com On Tue, 28 Nov 2006, Simon Peyton-Jones wrote: > | So I guess the real question is, how do I pass a polytype* wpn? > > and the answer is: > > | On Mon, 27 Nov 2006, Simon Peyton-Jones wrote: > | > | > Implicit parameters have monotypes, not polytypes. > > So an implicit parameter never has a polymorphic type. You can get around this, as Ben suggested I think, by using a newtype to wrap it up: > > newtype WPN = WPN (forall a. Ev PassNet ev a -> Ev State ev a) > > Simon > > So ?f in g gets > | > type (Char->Char). I rather doubt that something more general > | > (implicit parameters get polytypes) would work, given the implicit > | > "improvement" rules that implicit parameters require. > | > > | > Simon > | > > | > | -----Original Message----- > | > | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of > | S. > | > | Alexander Jacobson > | > | Sent: 21 November 2006 19:28 > | > | To: haskell-cafe@haskell.org > | > | Subject: [Haskell-cafe] why are implicit types different? (cleanup) > | > | > | > | > | > | > | > | Why do g and g' have different types? > | > | > | > | g x y = let ?f = \x-> x in ?f x ++ (show (?f y)) > | > | g :: [Char] -> [Char] -> [Char] > | > | > | > | g' :: (Show t) => [Char] -> t -> [Char] > | > | g' x y = let f = \x-> x in f x ++ (show (f y)) > | > | > | > | Is there a way I can use implicit types and let g be as general as g'? > | > | > | > | -Alex- > | > | > | > | > | > | ______________________________________________________________ > | > | S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com > | > | _______________________________________________ > | > | Haskell-Cafe mailing list > | > | Haskell-Cafe@haskell.org > | > | http://www.haskell.org/mailman/listinfo/haskell-cafe > | > > From magnus at therning.org Tue Nov 28 12:24:11 2006 From: magnus at therning.org (Magnus Therning) Date: Tue Nov 28 12:25:31 2006 Subject: [solved] Re: [Haskell-cafe] c2hs and cabal? In-Reply-To: <20061128120050.GC26646@die.therning.org> References: <20061127222658.GA3769@die.therning.org> <1164674022.7683.10.camel@localhost> <20061128105632.GA4362@die.therning.org> <1164712290.7683.34.camel@localhost> <20061128120050.GC26646@die.therning.org> Message-ID: <20061128172411.GI26646@die.therning.org> On Tue, Nov 28, 2006 at 12:00:50 +0000, Magnus Therning wrote: [..] >Can't really see anything obviously bogus about the following: > > % cat Foo.chs > module Foo where > > #include "foo.h" > > fooOne i = {# call foo1 #} i I solved my problem, but thought I'd send a mail to the list for anyone who's struggling as much as me (if that's even possible). The problem was that GHC requires a commandline argument telling it to deal with FFI. Including the following in Foo.chs resulted in successful compilation: {-# OPTIONS_GHC -fffi #-} /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus Software is not manufactured, it is something you write and publish. Keep Europe free from software patents, we do not want censorship by patent law on written works. Good powers of observation are frequently called "cynicism" by those that don't have them. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061128/e1eec14a/attachment-0001.bin From bulat.ziganshin at gmail.com Tue Nov 28 08:13:30 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Nov 28 12:28:55 2006 Subject: [Haskell-cafe] [Haskell] Defining Cg, HLSL style vectors in Haskell In-Reply-To: <171dfd0a0611280446y2e4c4bb3qd36112c0093bb62b@mail.gmail.com> References: <171dfd0a0611280446y2e4c4bb3qd36112c0093bb62b@mail.gmail.com> Message-ID: <138489427.20061128161330@gmail.com> Hello Slavomir, Tuesday, November 28, 2006, 3:46:13 PM, you wrote: > Last question: Does haskell have something like C++ templates? For > example, some time in the future I may need types like int2, short3, > etc., that behave just like float2, float3, but use different types > for their components. I really, really wouldn't like to copy-paste the > definitions of floatn and manually change their types to intn > respectfully. yes, it's named parameterized types: data Vec2 a = Vec2 !a !a instance (Num a) => Num (Vec2 a) where (Vec2 a1 a2) + (Vec2 b1 b2) = Vec2 (a1+b1) (a2+b2) .... type Float2 = Vec2 Float -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From noteed at gmail.com Tue Nov 28 12:41:19 2006 From: noteed at gmail.com (minh thu) Date: Tue Nov 28 12:39:43 2006 Subject: [Haskell-cafe] Re : Defining Cg, HLSL style vectors in Haskell In-Reply-To: <171dfd0a0611280446y2e4c4bb3qd36112c0093bb62b@mail.gmail.com> References: <171dfd0a0611280446y2e4c4bb3qd36112c0093bb62b@mail.gmail.com> Message-ID: <40a414c20611280941k66bb2846m7b3cf637e0b68f18@mail.gmail.com> 2006/11/28, Slavomir Kaslev : > Hello, > > I have to define a couple of float2, float3, float4 Cg, HLSL style > vectors in Haskell. At first I was tempted to make them instances of > Num, Floating, RealFrac, etc. but some of the functions defined in > those classes have no sense for vectors. One such example is signum > from class Num. > > There are several workarounds for this. One may come up with some > meaning for vectors of such functions, for example: > > instance Num Float3 where > ..... > signum a | a == Float3 0 0 0 = 0 > | otherwise = 1 > > This is silly. Other option, which I prefer, is to leave such > functions undefined (that is signum=undefined, not just not defining > them). Is this ok? Are there any other options? > > Another bugging thing is that some of the functions do have meaning > for vectors but they need different signatures. For example (**) :: > Floating a => a -> a -> a, for vectors should be (**) :: (Floating a, > Vector v) => v -> a -> v, that is (**) applied for every component of > the vector. Any workarounds for that? Those are the type signatures of +, ... you can't break them. So it won't be possible to use + to add two values of different types. > > I know that I can scrap all those Num, Floating, RealFrac, etc. > classes and define class Vector from scratch, but I really don't want > to come up and use different names for +, -, etc. that will bloat the > code. > > Last question: Does haskell have something like C++ templates? For > example, some time in the future I may need types like int2, short3, > etc., that behave just like float2, float3, but use different types > for their components. I really, really wouldn't like to copy-paste the > definitions of floatn and manually change their types to intn > respectfully. Yep, you have to learn that you can parametrise a type (constructor). For exemple, realise that [1], ["hello"] and "hello" are values of different types, i.e. different list types. The first one is of type [Int], the second one is [String] and the third [Char] (so you see that String is simply [Char]). In your case, you would want to define something like: Data Float2 a = Float2 a a then, optionnaly type Float2Int = Fl2 Int Bye, thu > > Cheers. > > -- > Slavomir Kaslev > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From slavomir.kaslev at gmail.com Tue Nov 28 13:26:13 2006 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Tue Nov 28 13:24:43 2006 Subject: [Haskell-cafe] [Haskell] Defining Cg, HLSL style vectors in Haskell In-Reply-To: <138489427.20061128161330@gmail.com> References: <171dfd0a0611280446y2e4c4bb3qd36112c0093bb62b@mail.gmail.com> <138489427.20061128161330@gmail.com> Message-ID: <171dfd0a0611281026x6e0ab565o4455b59a1106067d@mail.gmail.com> On 11/28/06, Bulat Ziganshin wrote: > Hello Slavomir, > > Tuesday, November 28, 2006, 3:46:13 PM, you wrote: > > > Last question: Does haskell have something like C++ templates? For > > example, some time in the future I may need types like int2, short3, > > etc., that behave just like float2, float3, but use different types > > for their components. I really, really wouldn't like to copy-paste the > > definitions of floatn and manually change their types to intn > > respectfully. > > yes, it's named parameterized types: > > data Vec2 a = Vec2 !a !a > > instance (Num a) => Num (Vec2 a) where > (Vec2 a1 a2) + (Vec2 b1 b2) = Vec2 (a1+b1) (a2+b2) > .... > > type Float2 = Vec2 Float > I wasn't aware of parameterized types, they are sweet. Thank you very much. What about my other questions? Do you have any suggestions? I know that this is very library specific. All I am asking is for some Haskell common sense. What would you do, if you were writing this kind of library? Cheers. -- Slavomir Kaslev From slavomir.kaslev at gmail.com Tue Nov 28 13:45:42 2006 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Tue Nov 28 13:44:06 2006 Subject: [Haskell-cafe] [Haskell] Defining Cg, HLSL style vectors in Haskell In-Reply-To: <171dfd0a0611281026x6e0ab565o4455b59a1106067d@mail.gmail.com> References: <171dfd0a0611280446y2e4c4bb3qd36112c0093bb62b@mail.gmail.com> <138489427.20061128161330@gmail.com> <171dfd0a0611281026x6e0ab565o4455b59a1106067d@mail.gmail.com> Message-ID: <171dfd0a0611281045p29b45d05r36c78aedecb97fea@mail.gmail.com> On 11/28/06, Slavomir Kaslev wrote: > On 11/28/06, Bulat Ziganshin wrote: > > Hello Slavomir, > > > > Tuesday, November 28, 2006, 3:46:13 PM, you wrote: > > > > > Last question: Does haskell have something like C++ templates? For > > > example, some time in the future I may need types like int2, short3, > > > etc., that behave just like float2, float3, but use different types > > > for their components. I really, really wouldn't like to copy-paste the > > > definitions of floatn and manually change their types to intn > > > respectfully. > > > > yes, it's named parameterized types: > > > > data Vec2 a = Vec2 !a !a > > > > instance (Num a) => Num (Vec2 a) where > > (Vec2 a1 a2) + (Vec2 b1 b2) = Vec2 (a1+b1) (a2+b2) > > .... > > > > type Float2 = Vec2 Float > > > > I wasn't aware of parameterized types, they are sweet. Thank you very much. > > What about my other questions? Do you have any suggestions? I know > that this is very library specific. All I am asking is for some > Haskell common sense. What would you do, if you were writing this kind > of library? > > Cheers. > > -- > Slavomir Kaslev > Err... Actually I *am* aware of parameterized types. Almost every function function from the Prelude on lists is parameterized. I was confused by you post that parameterized types have something to do with the strictness flag '!'. Sorry for that, going home embarrassed. -- Slavomir Kaslev From robdockins at fastmail.fm Tue Nov 28 13:52:42 2006 From: robdockins at fastmail.fm (Robert Dockins) Date: Tue Nov 28 13:47:10 2006 Subject: [Haskell-cafe] [Haskell] Defining Cg, HLSL style vectors in Haskell In-Reply-To: <171dfd0a0611280446y2e4c4bb3qd36112c0093bb62b@mail.gmail.com> References: <171dfd0a0611280446y2e4c4bb3qd36112c0093bb62b@mail.gmail.com> Message-ID: <5560241A-AD79-4CC0-B6E7-94D03E615F01@fastmail.fm> On Nov 28, 2006, at 7:46 AM, Slavomir Kaslev wrote: > Hello, > > I have to define a couple of float2, float3, float4 Cg, HLSL style > vectors in Haskell. At first I was tempted to make them instances of > Num, Floating, RealFrac, etc. but some of the functions defined in > those classes have no sense for vectors. One such example is signum > from class Num. > > There are several workarounds for this. One may come up with some > meaning for vectors of such functions, for example: > > instance Num Float3 where > ..... > signum a | a == Float3 0 0 0 = 0 > | otherwise = 1 > > This is silly. Other option, which I prefer, is to leave such > functions undefined (that is signum=undefined, not just not defining > them). Is this ok? Are there any other options? This will work. So long as you don't call signum, all will be well. > Another bugging thing is that some of the functions do have meaning > for vectors but they need different signatures. For example (**) :: > Floating a => a -> a -> a, for vectors should be (**) :: (Floating a, > Vector v) => v -> a -> v, that is (**) applied for every component of > the vector. Any workarounds for that? > > I know that I can scrap all those Num, Floating, RealFrac, etc. > classes and define class Vector from scratch, but I really don't want > to come up and use different names for +, -, etc. that will bloat the > code. The inflexibility of the numeric classes is one of the well-known problems with the definition of the Haskell prelude. As you say, there are a number of things for which only a subset of the operations make sense, or where more general types are needed for the operations. There have been a couple of attempts to reformulate these classes so that they are more flexible. Here is one that I know of: http://darcs.haskell.org/numericprelude/ I haven't used it, so I can't really comment, other than to say it exists. I seem to recall that there were several other attempts in a similar vein, but my brief google search didn't turn them up. Can someone else fill in? If you want to roll your own, you can still use the nice names if you explicitly import the prelude and hide names. Eg, import Prelude hiding ( (+), (-), .... etc .... ) Hope that helps. > Last question: Does haskell have something like C++ templates? For > example, some time in the future I may need types like int2, short3, > etc., that behave just like float2, float3, but use different types > for their components. I really, really wouldn't like to copy-paste the > definitions of floatn and manually change their types to intn > respectfully. > > Cheers. > > -- > Slavomir Kaslev > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe Speak softly and drive a Sherman tank. Laugh hard; it's a long way to the bank. -- TMBG From brianh at metamilk.com Tue Nov 28 14:25:35 2006 From: brianh at metamilk.com (Brian Hulley) Date: Tue Nov 28 14:23:41 2006 Subject: [Haskell-cafe] [Haskell] Defining Cg, HLSL style vectors in Haskell References: <171dfd0a0611280446y2e4c4bb3qd36112c0093bb62b@mail.gmail.com><138489427.20061128161330@gmail.com> <171dfd0a0611281026x6e0ab565o4455b59a1106067d@mail.gmail.com> Message-ID: <001101c71322$fb614460$96f82950@osmet> Slavomir Kaslev wrote: > I have to define a couple of float2, float3, float4 Cg, HLSL style > vectors in Haskell. At first I was tempted to make them instances of > Num, Floating, RealFrac, etc. but some of the functions defined in > those classes have no sense for vectors. I'd suggest that this implies that these classes are not suitable for Vectors. > One such example is signum from class Num. > > There are several workarounds for this. One may come up with some > meaning for vectors of such functions, for example: > > instance Num Float3 where > ..... > signum a | a == Float3 0 0 0 = 0 > | otherwise = 1 This looks a bit unnatural. Also, testing equality of Floats is not generally recommended. > > [snip] > I know that I can scrap all those Num, Floating, RealFrac, etc. > classes and define class Vector from scratch, but I really don't want > to come up and use different names for +, -, etc. that will bloat the > code. While it may be tempting to want to use symbolic operators like + and -, these quickly become very confusing when more distinctions need to be made (eg between cross product, dot product, and scaling, or between transforming a position versus transforming a direction) so I'd argue that for readability descriptive names are better than symbols: class Num a => Vector v a where plus :: v a -> v a -> v a minus :: v a -> v a -> v a cross :: v a -> v a -> v a dot :: v a -> v a -> a scale :: a -> v a -> v a magSquared :: v a -> a class Num a => Transform mat vec a where transformPosition :: mat a -> vec a -> vec a transformDirection :: mat a -> vec a -> vec a instance Num a => Transform Mat44 Vec4 a where -- ... If you're doing matrix transformations, you might also like to consider using separate PositionN and DirectionN types instead of VecN to make use of the type system to catch some math bugs but I haven't looked into this myself yet so I don't know whether this would be practical or not. Best regards, Brian. -- http://www.metamilk.com From slavomir.kaslev at gmail.com Tue Nov 28 16:15:46 2006 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Tue Nov 28 16:14:10 2006 Subject: [Haskell-cafe] [Haskell] Defining Cg, HLSL style vectors in Haskell In-Reply-To: <001101c71322$fb614460$96f82950@osmet> References: <171dfd0a0611280446y2e4c4bb3qd36112c0093bb62b@mail.gmail.com> <138489427.20061128161330@gmail.com> <171dfd0a0611281026x6e0ab565o4455b59a1106067d@mail.gmail.com> <001101c71322$fb614460$96f82950@osmet> Message-ID: <171dfd0a0611281315x394f2e22sf2fb0b255fe0d749@mail.gmail.com> On 11/28/06, Brian Hulley wrote: > Slavomir Kaslev wrote: > > I have to define a couple of float2, float3, float4 Cg, HLSL style > > vectors in Haskell. At first I was tempted to make them instances of > > Num, Floating, RealFrac, etc. but some of the functions defined in > > those classes have no sense for vectors. > > I'd suggest that this implies that these classes are not suitable for > Vectors. > > > One such example is signum from class Num. > > > > There are several workarounds for this. One may come up with some > > meaning for vectors of such functions, for example: > > > > instance Num Float3 where > > ..... > > signum a | a == Float3 0 0 0 = 0 > > | otherwise = 1 > > This looks a bit unnatural. Also, testing equality of Floats is not > generally recommended. > Agreed about the testing floats remark. The former definition was just to scratch the point that it's silly to come up with new meanings of such operations. It's not well typed either. signum is Num a => a->a, while the former is (Vector b, Num a) => b -> a. After giving some thought on signum, I got to the point, that signum should be defined so that abs x * signum x = x holds. So it can be defined as signum (Vec2 x y) = Vec 2 (signum x) (signum y). It turns out that all the functions in Num, Floating, etc. classes can be given meaningful definitions for vectors in this pattern. That is f (Vecn x1 x2 .. xn) = Vecn (f x1) ... (f xn). And all expected laws just work. One can think of that like the way SIMD processor works, it does the same operations as on floats but on four floats at parallel. So vectors can be instances of Num, Floating, etc., after all. > > > > [snip] > > I know that I can scrap all those Num, Floating, RealFrac, etc. > > classes and define class Vector from scratch, but I really don't want > > to come up and use different names for +, -, etc. that will bloat the > > code. > > While it may be tempting to want to use symbolic operators like + and -, > these quickly become very confusing when more distinctions need to be made > (eg between cross product, dot product, and scaling, or between transforming > a position versus transforming a direction) so I'd argue that for > readability descriptive names are better than symbols: > > class Num a => Vector v a where > plus :: v a -> v a -> v a > minus :: v a -> v a -> v a > cross :: v a -> v a -> v a > dot :: v a -> v a -> a > scale :: a -> v a -> v a > magSquared :: v a -> a > As I already said, I am leaning toward making vectors instances of Num. > class Num a => Transform mat vec a where > transformPosition :: mat a -> vec a -> vec a > transformDirection :: mat a -> vec a -> vec a > > instance Num a => Transform Mat44 Vec4 a where > -- ... > > If you're doing matrix transformations, you might also like to consider > using separate PositionN and DirectionN types instead of VecN to make use of > the type system to catch some math bugs but I haven't looked into this > myself yet so I don't know whether this would be practical or not. > The point of library is to define vectors, not as mathematical entities, but just like data representation, as they are defined in Cg/HLSL. One can take other approach and differentiate vectors between positions and directions as you suggested. In Renderman shading language, for example, those two different types are called 'point' and 'normal'. Cheers -- Slavomir Kaslev From mutjida at gmail.com Tue Nov 28 18:36:13 2006 From: mutjida at gmail.com (jeff p) Date: Tue Nov 28 18:34:37 2006 Subject: [Haskell-cafe] generating javascript Message-ID: Hello, Are there any Haskell tools to generate javascript? Has anyone made a combinator library for javascript? thanks, Jeff From alfonso.acosta at gmail.com Tue Nov 28 18:48:16 2006 From: alfonso.acosta at gmail.com (Alfonso Acosta) Date: Tue Nov 28 18:46:39 2006 Subject: [Haskell-cafe] generating javascript In-Reply-To: References: Message-ID: <6a7c66fc0611281548q676edcefwe6eed5287d4cf2cb@mail.gmail.com> You can generate Javascript from haskell using Yhc, check http://haskell.org/haskellwiki/Yhc/Javascript On 11/29/06, jeff p wrote: > Hello, > > Are there any Haskell tools to generate javascript? Has anyone made > a combinator library for > javascript? > > thanks, > Jeff > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From igloo at earth.li Tue Nov 28 21:19:16 2006 From: igloo at earth.li (Ian Lynagh) Date: Tue Nov 28 21:17:37 2006 Subject: [Haskell-cafe] Re: help with threadDelay In-Reply-To: <37c497340611220737pde4003ald4966848f25a8242@mail.gmail.com> References: <37c497340611220737pde4003ald4966848f25a8242@mail.gmail.com> Message-ID: <20061129021916.GA23086@matrix.chaos.earth.li> On Wed, Nov 22, 2006 at 03:37:05PM +0000, Neil Davies wrote: > Ian/Simon(s) Thanks - looking forward to the fix. I've now pushed it to the HEAD. > It will help with the real time enviroment that I've got. Lazy evaluation and GHC's garbage collector will probably cause headaches if you want true real time stuff. > Follow on query: Is there a way of seeing the value of this interval > from within the Haskell program? Helps in the calibration loop. I don't follow - what interval do you want to know? You can't find out how long threadDelay took, but the lower bound (in a correct implementation) is what you ask for and the upper bound is what you get by measuring it, as you did in your original message. Thanks Ian From moonlite at dtek.chalmers.se Tue Nov 28 22:14:05 2006 From: moonlite at dtek.chalmers.se (Mattias Bengtsson) Date: Tue Nov 28 22:12:28 2006 Subject: [Haskell-cafe] generating javascript In-Reply-To: References: Message-ID: <1164770045.32686.5.camel@localhost.localdomain> On Tue, 2006-11-28 at 18:36 -0500, jeff p wrote: > Hello, > > Are there any Haskell tools to generate javascript? Has anyone made > a combinator library for > javascript? There's a Google SoC-project made by a friend of mine for JavaScript support in Haskell Server Pages: http://csmisc14.cs.chalmers.se/~bjornson/soc/ It's a combinator library, but i'm not sure it's what you really need though. :) regards Mattias -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061129/ab773eee/attachment.bin From duncan.coutts at worc.ox.ac.uk Tue Nov 28 22:38:24 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Tue Nov 28 22:37:39 2006 Subject: [solved] Re: [Haskell-cafe] c2hs and cabal? In-Reply-To: <20061128172411.GI26646@die.therning.org> References: <20061127222658.GA3769@die.therning.org> <1164674022.7683.10.camel@localhost> <20061128105632.GA4362@die.therning.org> <1164712290.7683.34.camel@localhost> <20061128120050.GC26646@die.therning.org> <20061128172411.GI26646@die.therning.org> Message-ID: <1164771505.12454.5.camel@localhost> On Tue, 2006-11-28 at 17:24 +0000, Magnus Therning wrote: > On Tue, Nov 28, 2006 at 12:00:50 +0000, Magnus Therning wrote: > [..] > >Can't really see anything obviously bogus about the following: > > > > % cat Foo.chs > > module Foo where > > > > #include "foo.h" > > > > fooOne i = {# call foo1 #} i > > I solved my problem, but thought I'd send a mail to the list for anyone > who's struggling as much as me (if that's even possible). > > The problem was that GHC requires a commandline argument telling it to > deal with FFI. Including the following in Foo.chs resulted in > successful compilation: > > {-# OPTIONS_GHC -fffi #-} Or the simpler way is to include in your .cabal file: extensions: ForeignFunctionInterface That then applies to every module in the lib and has the advantage of being portable between compilers. Duncan From mutjida at gmail.com Tue Nov 28 22:44:09 2006 From: mutjida at gmail.com (jeff p) Date: Tue Nov 28 22:42:32 2006 Subject: [Haskell-cafe] generating javascript In-Reply-To: <1164770045.32686.5.camel@localhost.localdomain> References: <1164770045.32686.5.camel@localhost.localdomain> Message-ID: Hello, > There's a Google SoC-project made by a friend of mine for JavaScript > support in Haskell Server Pages: > http://csmisc14.cs.chalmers.se/~bjornson/soc/ > > It's a combinator library, but i'm not sure it's what you really need > though. :) > This seems to contain just what I was looking for. Although I'm not using HSP, it looks like the HSPClientside library can be used (in conjunction with Text.XHtml) to generate webpages with embedded scripts. thanks, Jeff From nicolas.frisby at gmail.com Tue Nov 28 23:36:59 2006 From: nicolas.frisby at gmail.com (Nicolas Frisby) Date: Tue Nov 28 23:35:20 2006 Subject: [Haskell-cafe] haddock infix questions Message-ID: <5ce89fb50611282036o71374012t9cf0ba33809a6f1f@mail.gmail.com> I found nothing in the Gmane archives, so I turn to you. I'm hoping to Haddock-a-chop my library but the ole infix type constructor (and there are many of them) is causing a parse error. It seems a common enough problem, so I was wondering... 1) What ended up happening with David Waern's SoC project? I tried the darcs repo at http://darcs.haskell.org/SoC/haddock.ghc/, but got some error messages that I think indicate I don't have an appropriate GHC As a Library package ("`HsDoc' not in scope"). I'm running GHC 6.6 on a Mac. I'll avoid a manual build of a snapshot GHC until it's my last option, so I haven't made strides to check if HsDoc is actually in the dev GHC repo. 2) Is there a good workaround out there for such a parse error? I'm thinking someone might have a handy pre-processor to help out Haddock? Thanks for your time, Nick From kr.angelov at gmail.com Wed Nov 29 03:18:25 2006 From: kr.angelov at gmail.com (Krasimir Angelov) Date: Wed Nov 29 03:16:49 2006 Subject: [Haskell-cafe] [Haskell] Defining Cg, HLSL style vectors in Haskell In-Reply-To: <171dfd0a0611280446y2e4c4bb3qd36112c0093bb62b@mail.gmail.com> References: <171dfd0a0611280446y2e4c4bb3qd36112c0093bb62b@mail.gmail.com> Message-ID: Hi Slavomir, On 11/28/06, Slavomir Kaslev wrote: > instance Num Float3 where > ..... > signum a | a == Float3 0 0 0 = 0 > | otherwise = 1 signum has a natural generalization for vectors. signum v = vector with the same direction as v but with |v| = 1 where |v| is the absolute length of v. The problematic function in Num is abs. Ideally abs should be defined as: abs v = |v| but its type is Float3 -> Float while the Num class requires Float3 -> Float3. Cheers, Krasimir From Alistair_Bayley at invescoperpetual.co.uk Wed Nov 29 04:02:30 2006 From: Alistair_Bayley at invescoperpetual.co.uk (Bayley, Alistair) Date: Wed Nov 29 04:00:52 2006 Subject: [Haskell-cafe] RE: [Haskell] ANNOUNCE: Visual Haskell prerelease 0.2 In-Reply-To: <456C0D21.1040202@imn.htwk-leipzig.de> Message-ID: <252C89C12FCAD84BA018CAD5268682FD05B5FA05@GBLONXMB02.corp.amvescap.net> > From: haskell-bounces@haskell.org > [mailto:haskell-bounces@haskell.org] On Behalf Of Johannes Waldmann > > sounds great - but can I use this without buying Visual Studio first, > i. e. does it work with some free beta version or similar? > > and, does it then work under wine :-) > > seriously, how hard would it be to adapt VH to Eclipse? > the interfaces (for syntax highlighting, typechecking etc.) > should be similar - in theory. Johannes, Are you aware that there is a Haskell plugin for eclipse? http://eclipsefp.sourceforge.net/ It's probably not as sophisticated as VH (I haven't tried VH, so cannot comment with authority), but you get syntax highlighting/colouring, compile-on-save, and compile errors are highlighted in the source editor. Alistair ***************************************************************** Confidentiality Note: The information contained in this message, and any attachments, may contain confidential and/or privileged material. It is intended solely for the person(s) or entity to which it is addressed. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient(s) is prohibited. If you received this in error, please contact the sender and delete the material from any computer. ***************************************************************** From ndmitchell at gmail.com Wed Nov 29 04:38:57 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Nov 29 04:37:18 2006 Subject: [Haskell-cafe] generating javascript In-Reply-To: References: <1164770045.32686.5.camel@localhost.localdomain> Message-ID: <404396ef0611290138l1eba10eaq544bc84d65e3965f@mail.gmail.com> Hi Jeff, It all depends how you want to write your code. The two options are full Haskell (Yhc) or combinators (HSPClientSide). Thanks Neil On 11/29/06, jeff p wrote: > Hello, > > > > There's a Google SoC-project made by a friend of mine for JavaScript > > support in Haskell Server Pages: > > http://csmisc14.cs.chalmers.se/~bjornson/soc/ > > > > It's a combinator library, but i'm not sure it's what you really need > > though. :) > > > This seems to contain just what I was looking for. Although I'm not > using HSP, it looks like the HSPClientside library can be used (in > conjunction with Text.XHtml) to generate webpages with embedded > scripts. > > thanks, > Jeff > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From simonpj at microsoft.com Wed Nov 29 05:33:16 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Wed Nov 29 05:31:40 2006 Subject: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: <456C5B5A.30606@list.mightyreason.com> References: <9BF202E6B745664F896FB822A141D3310E19BB70@EA-EXMSG-C303.europe.corp.microsoft.com> <456C5B5A.30606@list.mightyreason.com> Message-ID: | In many useful cases, such as the getLine example, the Y action will have its | own atomic {} block. In which case the semantics of when it is allowed to | re-attempt X are what is important. If you require (Y) to complete before | re-attempting (X) then you get an infinite regression where every (atomic block) | fails with (retryWith (next atomic block)), and nothing is ever re-attempted. | This is why "retryWith Y" meaning rollback X and do "Y >> atomic X" is the wrong | implementation. I don't agree. I think it's quite reasonable. Not many atomic blocks will finish with retryWith. Of course there is a possibility of an infinite loop, but we already have that: f x = f x. Of course, Y can always choose to do a forkIO, but it shouldn't hav to. For me the only difficulty is the implementation. We'd like to block X on the TVars it read (as usual), *unless* executing Y wrote to any of them. That requires a bit more cleverness in the commit code, but not a great deal I think. Simon From semanticphilosopher at googlemail.com Wed Nov 29 05:57:52 2006 From: semanticphilosopher at googlemail.com (Neil Davies) Date: Wed Nov 29 05:56:16 2006 Subject: [Haskell-cafe] Re: help with threadDelay In-Reply-To: <20061129021916.GA23086@matrix.chaos.earth.li> References: <37c497340611220737pde4003ald4966848f25a8242@mail.gmail.com> <20061129021916.GA23086@matrix.chaos.earth.li> Message-ID: <37c497340611290257l445cc3p71bb64923a9808bf@mail.gmail.com> On 29/11/06, Ian Lynagh wrote: > On Wed, Nov 22, 2006 at 03:37:05PM +0000, Neil Davies wrote: > > Ian/Simon(s) Thanks - looking forward to the fix. > > I've now pushed it to the HEAD. Thanks - I'll pull it down and give it a try. > > > It will help with the real time enviroment that I've got. > > Lazy evaluation and GHC's garbage collector will probably cause > headaches if you want true real time stuff. So the wisdom goes, but I decided to try it and it works really nicely. Yes, the GC can introduce additional "jitter", but I can arrange for GC's to be performed at times more convinient and not on the time critical path. I'm reliably able to get sub-millisecond jitter in the wakeup times - which is fine for the application. Laziness is fine - It'll help later when I can arrange evaluation outside the time critical path. Yea, I'd love a non-locking, incremental GC that returned within a fixed (configurable) time - but until that time.... > > > Follow on query: Is there a way of seeing the value of this interval > > from within the Haskell program? Helps in the calibration loop. > > I don't follow - what interval do you want to know? You can't find out > how long threadDelay took, but the lower bound (in a correct > implementation) is what you ask for and the upper bound is what you get > by measuring it, as you did in your original message. I was trying to find out (in the running haskell) the value supplied by (for example) -V RTS flag. In order to get low jitter you have to deliberately wake up early and spin - hey what are all these extra cores for! - knowing the quantisation of the RTS is useful in calibration loop for how much to wake up early. > > > Thanks > Ian > > From lemming at henning-thielemann.de Wed Nov 29 06:16:11 2006 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Wed Nov 29 06:15:29 2006 Subject: [Haskell-cafe] [Haskell] Defining Cg, HLSL style vectors in Haskell In-Reply-To: <001101c71322$fb614460$96f82950@osmet> References: <171dfd0a0611280446y2e4c4bb3qd36112c0093bb62b@mail.gmail.com> <138489427.20061128161330@gmail.com> <171dfd0a0611281026x6e0ab565o4455b59a1106067d@mail.gmail.com> <001101c71322$fb614460$96f82950@osmet> Message-ID: On Tue, 28 Nov 2006, Brian Hulley wrote: > While it may be tempting to want to use symbolic operators like + and -, > these quickly become very confusing when more distinctions need to be made > (eg between cross product, dot product, and scaling, or between transforming > a position versus transforming a direction) so I'd argue that for > readability descriptive names are better than symbols: > > class Num a => Vector v a where > plus :: v a -> v a -> v a > minus :: v a -> v a -> v a > cross :: v a -> v a -> v a > dot :: v a -> v a -> a > scale :: a -> v a -> v a > magSquared :: v a -> a I'm currently even thinking about an alternative of the multi-parameter class Vector that is Haskell 98. The problem with the multi-parameter type class is, that you cannot define instances where 'a' is a complex number type, say Num a => Vector [Complex a] (Complex a) From magnus at therning.org Wed Nov 29 06:26:47 2006 From: magnus at therning.org (Magnus Therning) Date: Wed Nov 29 06:28:39 2006 Subject: [solved] Re: [Haskell-cafe] c2hs and cabal? In-Reply-To: <1164771505.12454.5.camel@localhost> References: <20061127222658.GA3769@die.therning.org> <1164674022.7683.10.camel@localhost> <20061128105632.GA4362@die.therning.org> <1164712290.7683.34.camel@localhost> <20061128120050.GC26646@die.therning.org> <20061128172411.GI26646@die.therning.org> <1164771505.12454.5.camel@localhost> Message-ID: <20061129112647.GA6610@die.therning.org> On Wed, Nov 29, 2006 at 03:38:24 +0000, Duncan Coutts wrote: >On Tue, 2006-11-28 at 17:24 +0000, Magnus Therning wrote: >> On Tue, Nov 28, 2006 at 12:00:50 +0000, Magnus Therning wrote: >> [..] >> >Can't really see anything obviously bogus about the following: >> > >> > % cat Foo.chs >> > module Foo where >> > >> > #include "foo.h" >> > >> > fooOne i = {# call foo1 #} i >> >> I solved my problem, but thought I'd send a mail to the list for anyone >> who's struggling as much as me (if that's even possible). >> >> The problem was that GHC requires a commandline argument telling it to >> deal with FFI. Including the following in Foo.chs resulted in >> successful compilation: >> >> {-# OPTIONS_GHC -fffi #-} > >Or the simpler way is to include in your .cabal file: > >extensions: ForeignFunctionInterface > >That then applies to every module in the lib and has the advantage of >being portable between compilers. Ah, good point. Now, where could I have turned to find this out myself? I can't find it in the Cabal User's Guide[1]. /M [1]: http://www.haskell.org/cabal/release/latest/doc/users-guide/ -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus Software is not manufactured, it is something you write and publish. Keep Europe free from software patents, we do not want censorship by patent law on written works. I have steadily endeavored to keep my mind free, so as to give up any hypothesis, however much beloved -- and I cannot resist forming one on every subject -- as soon as facts are shown to be opposed to it. -- Charles Darwin (1809-1882) -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061129/005066aa/attachment.bin From bulat.ziganshin at gmail.com Wed Nov 29 07:43:09 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Wed Nov 29 07:43:00 2006 Subject: [Haskell-cafe] haddock infix questions In-Reply-To: <5ce89fb50611282036o71374012t9cf0ba33809a6f1f@mail.gmail.com> References: <5ce89fb50611282036o71374012t9cf0ba33809a6f1f@mail.gmail.com> Message-ID: <1879684817.20061129154309@gmail.com> Hello Nicolas, Wednesday, November 29, 2006, 7:36:59 AM, you wrote: > 1) What ended up happening with David Waern's SoC project? I tried the > darcs repo at http://darcs.haskell.org/SoC/haddock.ghc/, but got some now it's integrated in ghc 6.7 (HEAD) version. unfortunately, this years SoC projects don't had chances to be included in ghc 6.6. it was release-candidated in august or september and it will be bad to include new functionality just before RCing ghc -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From duncan.coutts at worc.ox.ac.uk Wed Nov 29 08:12:50 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Wed Nov 29 08:12:03 2006 Subject: [solved] Re: [Haskell-cafe] c2hs and cabal? In-Reply-To: <20061129112647.GA6610@die.therning.org> References: <20061127222658.GA3769@die.therning.org> <1164674022.7683.10.camel@localhost> <20061128105632.GA4362@die.therning.org> <1164712290.7683.34.camel@localhost> <20061128120050.GC26646@die.therning.org> <20061128172411.GI26646@die.therning.org> <1164771505.12454.5.camel@localhost> <20061129112647.GA6610@die.therning.org> Message-ID: <1164805970.12454.12.camel@localhost> On Wed, 2006-11-29 at 11:26 +0000, Magnus Therning wrote: > >Or the simpler way is to include in your .cabal file: > > > >extensions: ForeignFunctionInterface > > > >That then applies to every module in the lib and has the advantage of > >being portable between compilers. > > Ah, good point. > > Now, where could I have turned to find this out myself? I can't find it > in the Cabal User's Guide[1]. > > /M > > [1]: http://www.haskell.org/cabal/release/latest/doc/users-guide/ http://www.haskell.org/cabal/release/latest/doc/users-guide/x30.html#buildinfo Section 2.1.4, though I do notice that the link to the full list of extensions is broken. Duncan From neil at integility.com Wed Nov 29 08:12:49 2006 From: neil at integility.com (Neil Bartlett) Date: Wed Nov 29 08:14:08 2006 Subject: [Haskell-cafe] Compatibility between Data.ByteString.Base and Data.ByteString.Lazy Message-ID: <53231.204.4.130.140.1164805969.squirrel@integ-45100-001.dsvr.co.uk> Hi, Firstly my apologies if this is an outrageously newbie question. I am trying to write a binary protocol parser using Data.ByteString. I have created a module "ByteParser" containing my parsing utilities, which imports ByteString as: import qualified Data.ByteString as B In my Main module, where all the IO happens, I want to use lazy ByteStrings so I ask for the following imports: import ByteParser import qualified Data.ByteString.Lazy as L The problem is that when I try to call a function in ByteParser with an L.ByteString, the compiler complains that: Couldn't match expected type `Data.ByteString.Base.ByteString' against inferred type `L.ByteString' Does this mean that the lazy version of ByteString is a completely separate, incompatible type from the base version? Obviously I can work around this problem by making ByteParser import Data.ByteString.Lazy instead of Data.ByteString, but then ByteParser would not be able to work with strict ByteStrings. Ideally I would like ByteParser to be agnostic about the use of lazy versus strict ByteStrings. Is this a sensible and/or possible thing to do? Many thanks, Neil From dons at cse.unsw.edu.au Wed Nov 29 08:21:14 2006 From: dons at cse.unsw.edu.au (Donald Bruce Stewart) Date: Wed Nov 29 08:19:40 2006 Subject: [Haskell-cafe] Compatibility between Data.ByteString.Base and Data.ByteString.Lazy In-Reply-To: <53231.204.4.130.140.1164805969.squirrel@integ-45100-001.dsvr.co.uk> References: <53231.204.4.130.140.1164805969.squirrel@integ-45100-001.dsvr.co.uk> Message-ID: <20061129132114.GA20193@cse.unsw.EDU.AU> neil: > Hi, > > Firstly my apologies if this is an outrageously newbie question. > > I am trying to write a binary protocol parser using Data.ByteString. I > have created a module "ByteParser" containing my parsing utilities, which > imports ByteString as: > > import qualified Data.ByteString as B > > In my Main module, where all the IO happens, I want to use lazy > ByteStrings so I ask for the following imports: > > import ByteParser > import qualified Data.ByteString.Lazy as L > > The problem is that when I try to call a function in ByteParser with an > L.ByteString, the compiler complains that: > > Couldn't match expected type `Data.ByteString.Base.ByteString' > against inferred type `L.ByteString' > > Does this mean that the lazy version of ByteString is a completely > separate, incompatible type from the base version? Obviously I can work Yes, they're completely different. One is a strict, unboxed array of bytes. The other is a lazy list of cache-sized array chunks. You can convert between the two. But usually its best to pick one and stick to it. > around this problem by making ByteParser import Data.ByteString.Lazy > instead of Data.ByteString, but then ByteParser would not be able to work > with strict ByteStrings. Ideally I would like ByteParser to be agnostic > about the use of lazy versus strict ByteStrings. Is this a sensible and/or > possible thing to do? You could make your binary parser polymorphic on the string type, and used a String class that both bytestrings are instances of. -- Don From ross at soi.city.ac.uk Wed Nov 29 08:56:18 2006 From: ross at soi.city.ac.uk (Ross Paterson) Date: Wed Nov 29 08:54:39 2006 Subject: [solved] Re: [Haskell-cafe] c2hs and cabal? In-Reply-To: <1164805970.12454.12.camel@localhost> References: <20061127222658.GA3769@die.therning.org> <1164674022.7683.10.camel@localhost> <20061128105632.GA4362@die.therning.org> <1164712290.7683.34.camel@localhost> <20061128120050.GC26646@die.therning.org> <20061128172411.GI26646@die.therning.org> <1164771505.12454.5.camel@localhost> <20061129112647.GA6610@die.therning.org> <1164805970.12454.12.camel@localhost> Message-ID: <20061129135618.GA12778@soi.city.ac.uk> On Wed, Nov 29, 2006 at 01:12:50PM +0000, Duncan Coutts wrote: > http://www.haskell.org/cabal/release/latest/doc/users-guide/x30.html#buildinfo > > Section 2.1.4, though I do notice that the link to the full list of > extensions is broken. This version works (and looks better too): http://www.haskell.org/ghc/docs/latest/html/Cabal/ From joel.bjornson at gmail.com Wed Nov 29 09:14:58 2006 From: joel.bjornson at gmail.com (=?ISO-8859-1?Q?Joel_Bj=F6rnson?=) Date: Wed Nov 29 09:13:26 2006 Subject: [Haskell-cafe] generating javascript In-Reply-To: References: <1164770045.32686.5.camel@localhost.localdomain> Message-ID: <658ffcc20611290614q42fd0141vb43f534398ffa47b@mail.gmail.com> 2006/11/29, jeff p : > > This seems to contain just what I was looking for. Although I'm not > using HSP, it looks like the HSPClientside library can be used (in > conjunction with Text.XHtml) to generate webpages with embedded > scripts. It sure should be possible to use HSPClientside with Text.XHtml, but off course with exceptions to all Haskell Server Pages (HSP) specific functions. Anyway I encourage you to have a look at HSP as well :-) It's quite nice to be able to use regular XML syntax within the Haskell code. /Joel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061129/d3212e49/attachment.htm From ndmitchell at gmail.com Wed Nov 29 09:23:42 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Nov 29 09:22:04 2006 Subject: [Haskell-cafe] generating javascript In-Reply-To: <658ffcc20611290614q42fd0141vb43f534398ffa47b@mail.gmail.com> References: <1164770045.32686.5.camel@localhost.localdomain> <658ffcc20611290614q42fd0141vb43f534398ffa47b@mail.gmail.com> Message-ID: <404396ef0611290623q5df3864ch79de802baac2972a@mail.gmail.com> Hi > Anyway I encourage you to have a look at HSP as well :-) > It's quite nice to be able to use regular XML syntax within the Haskell > code. I think it should be entirely possible to use Haskell with Yhc and HSX (http://www.cs.chalmers.se/~d00nibro/haskell-src-exts/), so you can still write proper XML for your client side HTML. This is the way Hoogle 4 is going to be written. Thanks Neil From noteed at gmail.com Wed Nov 29 10:52:37 2006 From: noteed at gmail.com (minh thu) Date: Wed Nov 29 10:51:05 2006 Subject: [Haskell-cafe] Re : Defining Cg, HLSL style vectors in Haskell In-Reply-To: <001101c71322$fb614460$96f82950@osmet> References: <171dfd0a0611280446y2e4c4bb3qd36112c0093bb62b@mail.gmail.com> <138489427.20061128161330@gmail.com> <171dfd0a0611281026x6e0ab565o4455b59a1106067d@mail.gmail.com> <001101c71322$fb614460$96f82950@osmet> Message-ID: <40a414c20611290752h451135d2v4f73081b379cacad@mail.gmail.com> > [snip] > If you're doing matrix transformations, you might also like to consider > using separate PositionN and DirectionN types instead of VecN to make use of > the type system to catch some math bugs but I haven't looked into this > myself yet so I don't know whether this would be practical or not. > Indeed, not only bug catching : actually, some operations on points, vectors and normals have to be done differently. Thu > Best regards, > Brian. From ctm at cs.nott.ac.uk Wed Nov 29 13:14:56 2006 From: ctm at cs.nott.ac.uk (Conor McBride) Date: Wed Nov 29 13:13:21 2006 Subject: [Haskell-cafe] known, I know: class contexts and mutual recursion Message-ID: <456DCE20.9060807@cs.nott.ac.uk> Hi folks I just tripped over the "Contexts differ in length" error message. I know it's not a new problem, but I thought I'd enquire as to its status. For those of you who haven't seen it, here's an example, contrived but compact. > data Thing > = Val Int > | Grok Thing (Maybe Int -> Int) > eval :: Monad m => Thing -> m Int > eval (Val i) = return i > eval (Grok t f) = return (f (eval t)) My eval function compiles ok. See? The recursive call to eval targets the Maybe monad, so I get *Mmm> eval (Grok (Val 5) (maybe 0 (1 +))) :: Maybe Int Just 6 However, when I try to decompose eval as a pair of mutually recursive functions, namely > foo :: Monad m => Thing -> m Int > foo (Val i) = return i > foo (Grok t f) = return (goo t f) > goo :: Thing -> (Maybe Int -> Int) -> Int > goo t f = f (foo t) I get Mmm.lhs:15:1: Contexts differ in length When matching the contexts of the signatures for foo :: forall (m :: * -> *). (Monad m) => Thing -> m Int goo :: Thing -> (Maybe Int -> Int) -> Int The signature contexts in a mutually recursive group should all be identical Poking about on the web, I got the impression that this was a known infelicity in ghc 6.4 (which I'm using), due to be ironed out. However, an early-adopting colleague with 6.6 alleges that foo-goo is still poisonous. I'm wondering what the story is. I mean, is there some nasty problem lurking here which prevents the lifting of this peculiar restriction? I'm not in a panic about this. I have a workaround for the problem as I encountered it in practice. Mind you, it's the sort of thing that's likely to happen more often, the more you localise the effects you tend to use. In the above, goo doesn't throw exceptions; rather, because goo has a handler, it can offer a /local/ exception-throwing capability to foo. Curious Conor From apfelmus at quantentunnel.de Wed Nov 29 14:27:50 2006 From: apfelmus at quantentunnel.de (apfelmus@quantentunnel.de) Date: Wed Nov 29 14:30:07 2006 Subject: [Haskell-cafe] Re: Difficult memory leak in array processing In-Reply-To: <456C1282.8000306@gmail.com> References: <20061125144525.GB5391@matrix.chaos.earth.li> <456ADCAE.9010004@gmail.com> <456C1282.8000306@gmail.com> Message-ID: > I personally find doing higher order functions with IO extremely > difficult, and the resulting compiler errors are often downright scary. > But this is probably a direct consequence my rather limited > understanding of the monadic operators that the do notion hides. It > seems that one has to be /very/ good in Haskell before one can do IO > effectively. Hmm. Well, as good as a necromancer has to be :) But seriously, I think the most mind boggling point about IO actions is that those are higher order, too. I for myself have taken the point of view that values of type (IO a) are just "plans" that will be executed when the main Haskell program has done its work. The programs task is to assemble the "main plan" by sequencing smaller "plans" with (>>=). > But back to the point, using Haskell lists for representing a largish > buffer of, say, 16-bit samples that is constantly being refreshed from > hard disk and sent into the sound system for playback would probably be > inefficient beyond imagination. Lists are indeed not suited for massive byte crunching. If they fit into a black box, you can of course outsource things into C. In case you were writing a track scheduler ? la iTunes, the black box most likely would be a single function (playSoundFile) which does the job of handling data from disk to the sound card. Actual sound processing with Haskell functions is more involved. As already said, specifying loops over the samples as higher order functions will save you a lot of headaches. The point is that one just cannot start writing Haskell code and hope that it will run as fast as a tight loop in C. Instead, one should do aggressive optimizations at a few critical points only. And these are exactly the higher order loops. I have to admit that (accumM) is not very fast because it is able to change data at arbitrary indexes which therefore have to be kept around. Most often, you want to process each index exactly once which is better expressed as a (map) or a (fold). As Bulat and Duncan already said, Data.ByteString does exactly this for arrays of bytes. Using it or the generalization promised by Duncan is likely to be the best way to go. On the implementation level, lazy evaluation is in the way when crunching bytes. So be sure to tell GHC to make things strict and to unbox and inline everything it can put its hands on by giving appropriate command line options. As others already pointed out, the details are on http://haskell.org/haskellwiki/Performance As a first test, you may want to compile your original code with -O3 -optc-O3 -funfolding-use-threshold=16 and explore what happens. GHC does a good job with strictness analysis and it's of no use to drown your code in strictness annotations. Of course, some well placed ones may hint GHC about things it overlooked. To mention yet another approach, the image synthesis library Pan http://conal.net/pan/ pretends that the programmer writes ordinary Haskell functions, but under the hood, it's a tiny programming language that gets compiled to C++. Of course, the main point is that the image synthesis combinators are strictly less powerful than full Haskell. But as the full power is unneeded in that context, this doesn't hurt. While there are audio related projects, http://haskell.org/haskellwiki/Libraries_and_tools/Music_and_sound I don't know whether they focus on speed. Regards, afpelmus From slavomir.kaslev at gmail.com Wed Nov 29 14:53:41 2006 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Wed Nov 29 14:52:04 2006 Subject: [Haskell-cafe] [Haskell] Defining Cg, HLSL style vectors in Haskell In-Reply-To: References: <171dfd0a0611280446y2e4c4bb3qd36112c0093bb62b@mail.gmail.com> Message-ID: <171dfd0a0611291153r606c231fld0e2de7131961486@mail.gmail.com> On 11/29/06, Krasimir Angelov wrote: > Hi Slavomir, > > On 11/28/06, Slavomir Kaslev wrote: > > instance Num Float3 where > > ..... > > signum a | a == Float3 0 0 0 = 0 > > | otherwise = 1 > > signum has a natural generalization for vectors. > > signum v = vector with the same direction as v but with |v| = 1 > > where |v| is the absolute length of v. The problematic function in Num > is abs. Ideally abs should be defined as: > > abs v = |v| > > but its type is Float3 -> Float while the Num class requires Float3 -> Float3. > You mean signum = normalize? What do you think of my comments here: > After giving some thought on signum, I got to the point, that signum > should be defined so that abs x * signum x = x holds. So it can be > defined as signum (Vec2 x y) = Vec 2 (signum x) (signum y). > It turns out that all the functions in Num, Floating, etc. classes can > be given meaningful definitions for vectors in this pattern. That is f > (Vecn x1 x2 .. xn) = Vecn (f x1) ... (f xn). And all expected laws > just work. One can think of that like the way SIMD processor works, it > does the same operations as on floats but on four floats at parallel. I think this is the way to define vector instances for Num, Floating, etc. For vector specific operations, such as normalize, len, dot, cross, etc. are declared in class Vector. -- Slavomir Kaslev From kr.angelov at gmail.com Wed Nov 29 15:05:00 2006 From: kr.angelov at gmail.com (Krasimir Angelov) Date: Wed Nov 29 15:03:20 2006 Subject: [Haskell-cafe] [Haskell] Defining Cg, HLSL style vectors in Haskell In-Reply-To: <171dfd0a0611291153r606c231fld0e2de7131961486@mail.gmail.com> References: <171dfd0a0611280446y2e4c4bb3qd36112c0093bb62b@mail.gmail.com> <171dfd0a0611291153r606c231fld0e2de7131961486@mail.gmail.com> Message-ID: It is possible of course but your definition doesn't correspond to any operation in the usual vector algebra. By the way how do you define (*)? Isn't it 3D vector multiplication? Krasimir On 11/29/06, Slavomir Kaslev wrote: > You mean signum = normalize? What do you think of my comments here: > > > After giving some thought on signum, I got to the point, that signum > > should be defined so that abs x * signum x = x holds. So it can be > > defined as signum (Vec2 x y) = Vec 2 (signum x) (signum y). > > > It turns out that all the functions in Num, Floating, etc. classes can > > be given meaningful definitions for vectors in this pattern. That is f > > (Vecn x1 x2 .. xn) = Vecn (f x1) ... (f xn). And all expected laws > > just work. One can think of that like the way SIMD processor works, it > > does the same operations as on floats but on four floats at parallel. > > I think this is the way to define vector instances for Num, Floating, > etc. For vector specific operations, such as normalize, len, dot, > cross, etc. are declared in class Vector. > > -- > Slavomir Kaslev > From duncan.coutts at worc.ox.ac.uk Wed Nov 29 20:25:42 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Wed Nov 29 20:24:53 2006 Subject: [Haskell-cafe] Re: Difficult memory leak in array processing In-Reply-To: References: <20061125144525.GB5391@matrix.chaos.earth.li> <456ADCAE.9010004@gmail.com> <456C1282.8000306@gmail.com> Message-ID: <1164849943.12454.41.camel@localhost> On Wed, 2006-11-29 at 20:27 +0100, apfelmus@quantentunnel.de wrote: > On the implementation level, lazy evaluation is in the way when > crunching bytes. Something I rather enjoyed when hacking on the ByteString lib is finding that actually lazy evaluation is great when crunching bytes, though you do need to know exactly when to use it. Lazy ByteStrings rely on lazy evaluation of course. Demanding a lazy ByteString alternates between strictly filling in big chunks of data in memory with lazily suspending before producing the next chunk. As many people have observed before, FP optimisation is to a great extent about thinking more carefully about a better evaluation order for a computation and making some bits stricter and some bits lazier to get that better evaluation order. Duncan From mutjida at gmail.com Wed Nov 29 22:47:44 2006 From: mutjida at gmail.com (jeff p) Date: Wed Nov 29 22:46:04 2006 Subject: [Haskell-cafe] generating javascript In-Reply-To: <658ffcc20611290614q42fd0141vb43f534398ffa47b@mail.gmail.com> References: <1164770045.32686.5.camel@localhost.localdomain> <658ffcc20611290614q42fd0141vb43f534398ffa47b@mail.gmail.com> Message-ID: Hello, > It sure should be possible to use HSPClientside with Text.XHtml, > but off course with exceptions to all Haskell Server Pages (HSP) specific > functions. > Anyway I encourage you to have a look at HSP as well :-) > It's quite nice to be able to use regular XML syntax within the Haskell > code. > Currently I am dynamically generating webpages using HAppS; thus my desire for a combinator library for use directly in Haskell. If I start using static web pages then I'll likely use HSP. Is the JavaScript embedding in HSPClientside essentially the same as the embedding explained in Broberg's thesis? thanks, Jeff From golubovsky at gmail.com Thu Nov 30 00:04:19 2006 From: golubovsky at gmail.com (Dimitry Golubovsky) Date: Thu Nov 30 00:02:39 2006 Subject: [Haskell-cafe] Haskell source transformer? Message-ID: Hi, In order to automatize the creation of W3C DOM typesafe wrapper (this is needed for my Haskell->Javascript stuff) I am processing the OMG IDL files that contain interface definitions for DOM methods and attributes with HDirect. It works in general (for some reason it didn't like "boolean" type, so I used a preprocessor to redefine it as "Boolean"), and outputs some Haskell code full of foreign calls, yet it contains what I need: type signatures. For example, for the method "appendChild" it outputs: appendChild :: Node a1 -> Node a0 -> Prelude.IO (Node ()) appendChild newChild iptr = do o_appendChild <- Com.invokeIt (\ methPtr iptr -> Foreign.ForeignPtr.withForeignPtr newChild (\ new unmarshallNode o_appendChild (above lines of code may be truncated, they are just for illustration) This is almost it, but I need to replace the return type (using the JS monad instead of IO), and replace the method implementation with something else, based on unsafeJS. In some other cases I may need to modify type declarations, etc. I know there is a Haskell syntax parser around (maybe, more than one). Does anybody know of any utility based on such parser that does things I need, or rather a library on top of the parser? I just would like to avoid reinventing the wheel. Last thing I want to do is to change sources of HDirect. Thanks. -- Dimitry Golubovsky Anywhere on the Web From waldmann at imn.htwk-leipzig.de Thu Nov 30 03:15:35 2006 From: waldmann at imn.htwk-leipzig.de (Johannes Waldmann) Date: Thu Nov 30 03:13:53 2006 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: Visual Haskell prerelease 0.2 Message-ID: <456E9327.5050001@imn.htwk-leipzig.de> > > Not only the interfaces [Visual Studio vs. Eclipse] > > are completely different, but an entirely new > > set of interoperability problems would need to be solved. ... I still don't see what would be the fundamental difference. (Except perhaps that the Eclipse interfaces are easily available and well documented so it is at least possible to describe the interface problems...) The main advantage (Visual Haskell over eclipsefp) at the moment is that VH uses incremental (on-the-fly) typechecking/compilation while eclipsefp calls the compiler for whole modules? What source text transformations (refactorings) does VH support? Best regards, -- -- Johannes Waldmann -- Tel/Fax (0341) 3076 6479/80 -- ---- http://www.imn.htwk-leipzig.de/~waldmann/ ------- From slavomir.kaslev at gmail.com Thu Nov 30 03:21:50 2006 From: slavomir.kaslev at gmail.com (Slavomir Kaslev) Date: Thu Nov 30 03:20:09 2006 Subject: [Haskell-cafe] [Haskell] Defining Cg, HLSL style vectors in Haskell In-Reply-To: References: <171dfd0a0611280446y2e4c4bb3qd36112c0093bb62b@mail.gmail.com> <171dfd0a0611291153r606c231fld0e2de7131961486@mail.gmail.com> Message-ID: <171dfd0a0611300021g1cfc609eu38f21d0b2d384dc4@mail.gmail.com> On 11/29/06, Krasimir Angelov wrote: > It is possible of course but your definition doesn't correspond to any > operation in the usual vector algebra. By the way how do you define > (*)? Isn't it 3D vector multiplication? > (*) is per component multiplication, as it is in Cg/HLSL. For vector to vector, vector to matrix, etc. multiplication there is mul. Cheers. -- Slavomir Kaslev From ndmitchell at gmail.com Thu Nov 30 05:50:46 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Thu Nov 30 05:49:04 2006 Subject: [Haskell-cafe] Haskell source transformer? In-Reply-To: References: Message-ID: <404396ef0611300250jeb550fai61c343245f5f95da@mail.gmail.com> Hi Dimitry, > I know there is a Haskell syntax parser around (maybe, more than one). > Does anybody know of any utility based on such parser that does things > I need, or rather a library on top of the parser? I just would like to > avoid reinventing the wheel. I have a Haskell parser here: http://www.cs.york.ac.uk/fp/darcs/catch/src/Haskell/ - originally from GHC but modified slightly by the Hacle project to work in Hugs and be Haskell 98 (I think). I am also intending to write a Yhc.Parser library, but haven't got round to that yet. Thanks Neil From haskell at list.mightyreason.com Thu Nov 30 06:12:51 2006 From: haskell at list.mightyreason.com (Chris Kuklewicz) Date: Thu Nov 30 06:11:02 2006 Subject: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video In-Reply-To: References: <9BF202E6B745664F896FB822A141D3310E19BB70@EA-EXMSG-C303.europe.corp.microsoft.com> <456C5B5A.30606@list.mightyreason.com> Message-ID: <456EBCB3.3030900@list.mightyreason.com> Eureka, I claim to have written an implementation which agrees with all the semantics that Simon Peyton-Jones wants for onCommit/onRetry/retryWith. See below: Simon Peyton-Jones wrote: > | In many useful cases, such as the getLine example, the Y action will have its > | own atomic {} block. In which case the semantics of when it is allowed to > | re-attempt X are what is important. If you require (Y) to complete before > | re-attempting (X) then you get an infinite regression where every (atomic block) > | fails with (retryWith (next atomic block)), and nothing is ever re-attempted. > | This is why "retryWith Y" meaning rollback X and do "Y >> atomic X" is the wrong > | implementation. > > I don't agree. I think it's quite reasonable. Not many atomic blocks will > finish with retryWith. Of course there is a possibility of an infinite loop, but > we already have that: f x = f x. Of course, Y can always choose to do a forkIO, > but it shouldn't hav to. > > For me the only difficulty is the implementation. We'd like to block X on the > TVars it read (as usual), *unless* executing Y wrote to any of them. That > requires a bit more cleverness in the commit code, but not a great deal I think. > > Simon It is the Helper Thread code version on the wiki at http://haskell.org/haskellwiki/New_monads/MonadAdvSTM#Helper_Thread_Code Quick explanation of the code for runAdvSTM (usually called with atomicAdv): When the action X in (atomicAdv X) ends with (retryWith Y) the job Y is put into an MVar. Then a retry causes the orElse in wrappedAction to perform check'retry. This sees the job Y and then *) if this is the first retry job: creates and cache a channel and spawn the helper thread *) push the retry job Y into the channel *) call retry to cause action X to cause the current GHC runtime to block on whatever STM-variables it used The wrappedAction commits if and only if the action X commits. In which case the commit action stored in the TVar is read and performed. Then a check is performed to see if the helper thread was spawned, and if so tell the helper thread to quit and block until the helper thread is done. Note that the action X can be re-attempted by the runtime before the retry job Y is run or before it has finished running. But this will only happen in the usual cases where there was an STM update, instead of the possible busy wait in the Single Thread code example on the wiki page. Does this meet your specifications, Simon? -- Chris From apfelmus at quantentunnel.de Thu Nov 30 06:17:06 2006 From: apfelmus at quantentunnel.de (apfelmus@quantentunnel.de) Date: Thu Nov 30 06:18:48 2006 Subject: [Haskell-cafe] Re: Difficult memory leak in array processing In-Reply-To: <1164849943.12454.41.camel@localhost> References: <20061125144525.GB5391@matrix.chaos.earth.li> <456ADCAE.9010004@gmail.com> <456C1282.8000306@gmail.com> <1164849943.12454.41.camel@localhost> Message-ID: Duncan Coutts wrote: > On Wed, 2006-11-29 at 20:27 +0100, apfelmus@quantentunnel.de wrote: > >> On the implementation level, lazy evaluation is in the way when >> crunching bytes. > > Something I rather enjoyed when hacking on the ByteString lib is finding > that actually lazy evaluation is great when crunching bytes, though you > do need to know exactly when to use it. > > Lazy ByteStrings rely on lazy evaluation of course. Demanding a lazy > ByteString alternates between strictly filling in big chunks of data in > memory with lazily suspending before producing the next chunk. > > As many people have observed before, FP optimisation is to a great > extent about thinking more carefully about a better evaluation order for > a computation and making some bits stricter and some bits lazier to get > that better evaluation order. I completely agree. My statement was not well formulated, I actually meant that the overhead implied by lazy evaluation occurring at every single byte to be crunched is in the way. In this case, the cost is too high to pay off as the bytes are most likely consumed anyway. The detailed account keeping about every byte ("is it _|_ or not?") is unnecessary for a (map) which invariably does look at every byte. The situation is already different for a (fold), though: any p = foldr (\x b -> p x `or` b) False Here, the computation may stop at any position in the list. In a sense, lazy ByteStrings just reduce the "cost of lazy evaluation" / byte ratio by grouping bytes strictly. Bookkeeping becomes cheaper because one doesn't look up so often. Of course, with a stricter fold, (any) gets more costly. The aim is to make the former ratio smaller while not raising the latter too much. One may say that ByteString makes explicit what the "Optimistic Haskell Compiler" aimed to make implicit. IMHO, lazy evaluation is always the better choice (in theory). In practice, the only problem about lazy evaluation is the overhead (which hurts mostly at (large -> small)) which is *not* a consequence of "no free lunch" but stems from the fact that current machine architecture is not very friendly to purely functional things. In a sense, the natural complexity measure in Haskell is the number of reductions in "hugs +s" whereas the natural complexity measure on RAM machines is the number of operations in 0xDEADBEAF-arithmetic. Unfortunately, it's the latter which is inside Intel. Regards, apfelmus From thiago.arrais at gmail.com Thu Nov 30 06:58:27 2006 From: thiago.arrais at gmail.com (Thiago Arrais) Date: Thu Nov 30 06:56:45 2006 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: Visual Haskell prerelease 0.2 In-Reply-To: <456E9327.5050001@imn.htwk-leipzig.de> References: <456E9327.5050001@imn.htwk-leipzig.de> Message-ID: On 11/30/06, Johannes Waldmann wrote: > The main advantage (Visual Haskell over eclipsefp) at the moment > is that VH uses incremental (on-the-fly) typechecking/compilation > while eclipsefp calls the compiler for whole modules? I would say this is one of the greatest advantages of VH, don't know if it is the main one, but it surely is an advantage. I wonder how VH achieves that. I imagine it manages to run GHC (it uses GHC, right?) inside the .Net VM or at least access it through some programmatic interface using some kind of native/VM data conversion. GHC code (and not VH code) do the typechecking/compilation tricks. Is that right? Eclipse is Java and I am pretty sure we can do something similar with it and we actually did something like the second approach prior to version 0.9.1, but just for source code parsing. What do we need for that? Cheers, Thiago Arrais -- Mergulhando no Caos - http://thiagoarrais.wordpress.com Pensamentos, id?ias e devaneios sobre desenvolvimento de software e tecnologia em geral From joel.bjornson at gmail.com Thu Nov 30 07:10:23 2006 From: joel.bjornson at gmail.com (=?ISO-8859-1?Q?Joel_Bj=F6rnson?=) Date: Thu Nov 30 07:08:41 2006 Subject: [Haskell-cafe] generating javascript In-Reply-To: References: <1164770045.32686.5.camel@localhost.localdomain> <658ffcc20611290614q42fd0141vb43f534398ffa47b@mail.gmail.com> Message-ID: <658ffcc20611300410x4d239cbbx47eaf21be50a5eb5@mail.gmail.com> 2006/11/30, jeff p : > Is the JavaScript embedding in HSPClientside essentially the same as > the embedding explained in Broberg's thesis? Yes, in principal the core modules are based on the thesis. Combinators and higher level functions are built on top of these. /Joel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061130/d384b65e/attachment.htm From kr.angelov at gmail.com Thu Nov 30 07:41:34 2006 From: kr.angelov at gmail.com (Krasimir Angelov) Date: Thu Nov 30 07:39:58 2006 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: Visual Haskell prerelease 0.2 In-Reply-To: References: <456E9327.5050001@imn.htwk-leipzig.de> Message-ID: VSHaskell isn't interfacing with .NET but is a COM server written in Haskell. The VStudio IDE is actually implemented in C but is using COM as an interface to the various plugins. That way you can implement the plugin in C++/.NET/Haskell or what ever you want. For Eclipse you need a bridge between JVM and Haskell. In addition you have find some way to build .so library for Linux. Cheers, Krasimir On 11/30/06, Thiago Arrais wrote: > On 11/30/06, Johannes Waldmann wrote: > > The main advantage (Visual Haskell over eclipsefp) at the moment > > is that VH uses incremental (on-the-fly) typechecking/compilation > > while eclipsefp calls the compiler for whole modules? > > I would say this is one of the greatest advantages of VH, don't know if it is > the main one, but it surely is an advantage. I wonder how VH achieves that. > I imagine it manages to run GHC (it uses GHC, right?) inside the .Net VM > or at least access it through some programmatic interface using some kind > of native/VM data conversion. GHC code (and not VH code) do the > typechecking/compilation tricks. Is that right? > > Eclipse is Java and I am pretty sure we can do something similar with it > and we actually did something like the second approach prior to version > 0.9.1, but just for source code parsing. What do we need for that? > > Cheers, > > Thiago Arrais > -- > Mergulhando no Caos - http://thiagoarrais.wordpress.com > Pensamentos, id?ias e devaneios sobre desenvolvimento de software e > tecnologia em geral > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From jgoerzen at complete.org Thu Nov 30 08:47:42 2006 From: jgoerzen at complete.org (John Goerzen) Date: Thu Nov 30 08:46:58 2006 Subject: [Haskell-cafe] Re: Lazy data from pipe using MissingH module References: <20061109153757.GB18621@glowfish> Message-ID: Dougal Stanton wrote: > Newbie here working on a little program for fetching podcasts. I've been > using the MissingH.Cmd module in concert with curl to download the RSS > feeds like this: First off, check out http://quux.org/devel/hpodder -- it is a podcast downloader written in Haskell that uses MissingH.Cmd. And Curl, Might just do what you want. >> fetchFeed :: Subscription -> IO (Either Error [Episode]) >> fetchFeed sub = do >> (pid, feed) <- pipeFrom "curl" (curlOpts ++ >> ["--url", (slocation sub)]) >> let eps = parseEpisodes (stitle sub) feed >> forceSuccess pid >> return eps > > According to the API docs I have to forceSuccess pid *after* I use the > data. Will this construct do that, or does the compiler have free reign > to move the line beginning 'let ...' wherever it feels? No, it won't. I'd suggest adding something like: evaluate (length eps) before the forceSuccess. What happens is that, since Haskell is lazy, it won't actually consume the data from the pipe until it is needed -- which looks like it could even be after this function returns. forceSuccess waits for the process to die. The process won't die until you've consumed all its output. Therefore your program will hang at forceSuccess. -- John From jgoerzen at complete.org Thu Nov 30 08:56:16 2006 From: jgoerzen at complete.org (John Goerzen) Date: Thu Nov 30 08:55:03 2006 Subject: [Haskell-cafe] Re: The Future of MissingH References: <42374139.20061126225433@gmail.com> Message-ID: Bulat Ziganshin wrote: Hi Bulat, Many thanks for the *great* comments. > first, is it possible to integrate MissingH inside existing core libs, > i.e. Haskell libs supported by Haskell community? i think that it will > be impossible if MissingH will hold its GPL status. i think that > such fundamental library as MissingH should be BSDified to allow use > it both in commercial and non-commercial code As others have pointed out, the GPL is not a commercial vs. non-commercial license. That said, I am scrupulous about copyrights and licensing. I know exactly which bits of MissingH I own the copyright to, and which bits are under which license. I have, for quite some time already, maintained an LGPL branch of MissingH. This branch contains all of the code in MissingH that is: a) compatible with the LGPL b) not depending on LGPL-incompatible components That means basically the code I wrote, plus any LGPL or BSD code others wrote. It would be easy enough to figure out which bits can suitably fall under BSD license; it would be nearly the same bits as can fall under LGPL. Again, since I own copyright to most of the code, I can put it under as many different licenses as I like, so long as I respect everyone else's copyrights properly. In any case, most of the stuff that would be suitable for base was written by me anyway. > if library will be BSDified, and somewhat "advertized". i hope that > its parts will start moving to the more specific libs of core set, say > HVFS system into the Files library, logging facilities into the Unix > library, so on Planning to do so. > quality of code documenting in your lib, most peoples prefer to read > Haddocks, which again should be made available on web Already are, and will continue to be. > next, while you accept patches to the lib, this's not declared in your > announces. best way is just to open darcs repository - most peoples > thinks that having darcs repository and accepting patches is the same > thing :) i can also propose you the idea that Pupeno, packager of Have it, but it's under-documented. That will change. See http://software.complete.org/offlineimap/ for an example of what I intend to do with MissingH as well. > Streams library used - he included in the tgz files copy of darcs > repository, again facilitating use of darcs and developing new patches > for library That is an interesting idea, but the MissingH repo has nearly 1000 darcs patches by now. This would seriously bloat the tarball, plus it's easy enough to just download it off the 'net with darcs. > and, about WindowsCompat.hs - stat() function is available on Windows > and even used to implement getModificationTime :) Err, how? Is this new in ghc 6.6? Last I tried, -package unix wouldn't even work on Windows. >> I initially wrote it that way to make resolving dependencies easier >> for end users. > > now Cabal handles this No, it just complains when dependencies aren't resolved. People still have to go out and download/install each piece manually. -- John From zunino at di.unipi.it Thu Nov 30 08:59:05 2006 From: zunino at di.unipi.it (Roberto Zunino) Date: Thu Nov 30 08:58:12 2006 Subject: [Haskell-cafe] [Redirect] polymorphism and existential types In-Reply-To: <20061128040125.GE13923@cse.unsw.EDU.AU> References: <20061128040125.GE13923@cse.unsw.EDU.AU> Message-ID: <456EE3A9.9080303@di.unipi.it> Donald Bruce Stewart wrote: > Supposing a polymorphic value (of type, say, forall a . ExpT a t) is > stored inside an existential package (of type, say, forall a . Exp a), > I wonder how to recover a polymorphic value when eliminating the > existential. The ``natural way'' to write this doesn't work: > > {-# OPTIONS -fglasgow-exts #-} > > data ExpT a t > data Exp a = forall t . Exp (ExpT a t) > > f :: (forall a . ExpT a t) -> () > f e = () > > g :: (forall a . ExpT a t) -> () > g e = > let e1 :: forall a . Exp a > e1 = Exp e > in case e1 of > Exp e' -> f e' IIUC, this is not possible. I believe that the type given for e1 is strictly weaker than the type of e, so that recovering the type of e from that of e1 can not be done. This is because (up-to iso) e :: exists t . forall a . ExpT a t e1:: forall a . exists t . ExpT a t Clearly, the first one (where t is fixed) is stronger than the second, (where t might depend on a). Regards, Roberto Zunino. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 249 bytes Desc: OpenPGP digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061130/355995fe/signature.bin From jgoerzen at complete.org Thu Nov 30 08:58:27 2006 From: jgoerzen at complete.org (John Goerzen) Date: Thu Nov 30 08:58:37 2006 Subject: [Haskell-cafe] New Name for MissingH? Message-ID: Quick feedback time... One comment people made in the Future of MissingH thread was that the name isn't very suggestive of what the library does. I'm planning to follow the advice of many people and split the major MissingH components off into smaller bits (ConfigParser, HVFS, etc). MissingH itself will then contain any small utility functions (probably mainly string and list-related) that for whatever reason aren't suitable to go into base. What should it be called? Should it keep the MissingH name? The alternative I've been thinking of is something like Haskell Utility Library (HUL). Ideas? From ndmitchell at gmail.com Thu Nov 30 09:06:55 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Thu Nov 30 09:05:12 2006 Subject: [Haskell-cafe] New Name for MissingH? In-Reply-To: References: Message-ID: <404396ef0611300606n3f5698a0q668dfd939f178437@mail.gmail.com> Hi > The alternative I've been thinking of is something like Haskell Utility > Library (HUL). Yuk. I like MissingH. MissingH suggests things that are missing from the standard set and provided here. HsMissing would be my preferred choice, but its not really important. Haskell says which language its written in, library says its a library, and utility tells me nothing (the word is too overloaded). By the end I know its a Haskell library... I think the problem isn't that the name is confusing, but that no one knows it exists or what it does. Things like adding it to the Hoogle database would probably help, along with greater "there is a function for that in MissingH" posts to the haskell-cafe list as people ask. Thanks Neil From Alistair_Bayley at invescoperpetual.co.uk Thu Nov 30 09:07:25 2006 From: Alistair_Bayley at invescoperpetual.co.uk (Bayley, Alistair) Date: Thu Nov 30 09:05:42 2006 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: Visual Haskell prerelease0.2 In-Reply-To: Message-ID: <252C89C12FCAD84BA018CAD5268682FD05B5FA0C@GBLONXMB02.corp.amvescap.net> (not sure if this is the best place for questions about VisualHaskell) I've just installed VisualHaskell, and I've noticed that some of the hierarchical libraries are missing/hidden: - Control.Monad.State (and other chunks of the Control.Monad hierarchy, like Control.Monad.Error/Identity/List/Trans) - Test.HUnit (in fact Test.* is gone) and I'm sure there's plenty more missing. ? Alistair ***************************************************************** Confidentiality Note: The information contained in this message, and any attachments, may contain confidential and/or privileged material. It is intended solely for the person(s) or entity to which it is addressed. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient(s) is prohibited. If you received this in error, please contact the sender and delete the material from any computer. ***************************************************************** From bulat.ziganshin at gmail.com Thu Nov 30 09:11:14 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Nov 30 09:10:46 2006 Subject: [Haskell-cafe] New Name for MissingH? In-Reply-To: <404396ef0611300606n3f5698a0q668dfd939f178437@mail.gmail.com> References: <404396ef0611300606n3f5698a0q668dfd939f178437@mail.gmail.com> Message-ID: <1721540614.20061130171114@gmail.com> Hello Neil, Thursday, November 30, 2006, 5:06:55 PM, you wrote: > I think the problem isn't that the name is confusing, but that no one > knows it exists or what it does. Things like adding it to the Hoogle > database would probably help, along with greater "there is a function > for that in MissingH" posts to the haskell-cafe list as people ask. there is one idea: one shouldn't have internet access to be able to use Haskell effectively. so, good organization and proper names would be useful -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From flippa at flippac.org Thu Nov 30 09:21:58 2006 From: flippa at flippac.org (Philippa Cowderoy) Date: Thu Nov 30 09:21:01 2006 Subject: [Haskell-cafe] New Name for MissingH? In-Reply-To: <1721540614.20061130171114@gmail.com> References: <404396ef0611300606n3f5698a0q668dfd939f178437@mail.gmail.com> <1721540614.20061130171114@gmail.com> Message-ID: On Thu, 30 Nov 2006, Bulat Ziganshin wrote: > there is one idea: one shouldn't have internet access to be able to > use Haskell effectively. so, good organization and proper names would > be useful > In that vein, Hoogle as an offline tool probably helps. I should play with it sometime. -- flippa@flippac.org "My religion says so" explains your beliefs. But it doesn't explain why I should hold them as well, let alone be restricted by them. From durden at gmail.com Thu Nov 30 09:32:46 2006 From: durden at gmail.com (Nicola Paolucci) Date: Thu Nov 30 09:31:03 2006 Subject: [Haskell-cafe] Command line utility that shrinks/simplifies functions applications ? Message-ID: Hi All! Haskell newbie here with a very simple question because google and hoogle are of no help. On the IRC channel #haskell (which I cannot access now from work) I saw somebody using a tool which automatically simplifies expressions,composition of multiple functions to the bare minimum. It was a query to lambdabot I think. Is that tool/library also standalone ? What's its name ? Where can I find it ? That really rocked ... Thanks, Nick From bulat.ziganshin at gmail.com Thu Nov 30 10:55:17 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Nov 30 10:54:55 2006 Subject: [Haskell-cafe] Command line utility that shrinks/simplifies functions applications ? In-Reply-To: References: Message-ID: <354398065.20061130185517@gmail.com> Hello Nicola, Thursday, November 30, 2006, 5:32:46 PM, you wrote: > On the IRC channel #haskell (which I cannot access now from work) I > saw somebody using a tool which automatically simplifies > expressions,composition of multiple functions to the bare minimum. it is the IRC channel itself -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From clifford.beshers at linspire.com Thu Nov 30 11:00:09 2006 From: clifford.beshers at linspire.com (Clifford Beshers) Date: Thu Nov 30 10:58:26 2006 Subject: [Haskell-cafe] New Name for MissingH? In-Reply-To: References: Message-ID: <456F0009.7070903@linspire.com> John Goerzen wrote: > Quick feedback time... > > One comment people made in the Future of MissingH thread was that the name > isn't very suggestive of what the library does. My colleague uses modules called `My' to hold functions that seem like they should be in a library, but which aren't yet mature enough to be promoted. I've always thought of MissingH the same way. It would make a good place for new functions like intercalate to be placed while they are being considered. But eventually, good functions and modules should graduate. ConfigParser and HVFS are good candidates to be standalone libraries, as you say. I've been meaning to submit the 'merge' function that we sent you, as well. If MissingH acted as a general waystation, we could keep a stable library base installed on our systems, but get the latest that people are talking about by pulling in that one package. From sjanssen at cse.unl.edu Thu Nov 30 11:04:20 2006 From: sjanssen at cse.unl.edu (Spencer Janssen) Date: Thu Nov 30 11:02:56 2006 Subject: [Haskell-cafe] Command line utility that shrinks/simplifies functions applications ? In-Reply-To: References: Message-ID: <3F4E3C18-818D-4EE6-B452-C5E6B3803489@cse.unl.edu> I believe you're talking about the `pl' plugin for lambdabot. Lambdabot has an offline mode, visit the homepage for the source: http://www.cse.unsw.edu.au/~dons/lambdabot.html There is also a web interface to lambdabot, but I can't seem to find the link. Cheers, Spencer Janssen On Nov 30, 2006, at 8:32 AM, Nicola Paolucci wrote: > Hi All! > > Haskell newbie here with a very simple question because google and > hoogle are of no help. > > On the IRC channel #haskell (which I cannot access now from work) I > saw somebody using a tool which automatically simplifies > expressions,composition of multiple functions to the bare minimum. It > was a query to lambdabot I think. > > Is that tool/library also standalone ? What's its name ? Where can > I find it ? > That really rocked ... > > Thanks, > Nick > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From durden at gmail.com Thu Nov 30 11:06:50 2006 From: durden at gmail.com (Nicola Paolucci) Date: Thu Nov 30 11:05:07 2006 Subject: [Haskell-cafe] Command line utility that shrinks/simplifies functions applications ? In-Reply-To: <3F4E3C18-818D-4EE6-B452-C5E6B3803489@cse.unl.edu> References: <3F4E3C18-818D-4EE6-B452-C5E6B3803489@cse.unl.edu> Message-ID: Hi Spencer, On 11/30/06, Spencer Janssen wrote: > I believe you're talking about the `pl' plugin for lambdabot. > Lambdabot has an offline mode, visit the homepage for the source: > http://www.cse.unsw.edu.au/~dons/lambdabot.html That's exactly what I was looking for! Thank you very much ! Regards, Nick From jgoerzen at complete.org Thu Nov 30 11:06:26 2006 From: jgoerzen at complete.org (John Goerzen) Date: Thu Nov 30 11:05:28 2006 Subject: [Haskell-cafe] Re: New Name for MissingH? References: <404396ef0611300606n3f5698a0q668dfd939f178437@mail.gmail.com> Message-ID: Neil Mitchell wrote: > Hi > >> The alternative I've been thinking of is something like Haskell Utility >> Library (HUL). > > Yuk. I like MissingH. MissingH suggests things that are missing from > the standard set and provided here. HsMissing would be my preferred > choice, but its not really important. Makes sense. > I think the problem isn't that the name is confusing, but that no one > knows it exists or what it does. Things like adding it to the Hoogle I'm working on that. There should be a real homepage with a wiki for it soon. It's already in HCAR, and I think it's on the wiki list of libraries. But I'll try to help it along, too. I couldn't figure out how to add it to hoogle. Does anyone have a pointer for that? > database would probably help, along with greater "there is a function > for that in MissingH" posts to the haskell-cafe list as people ask. True, too. I didn't want to be too annoying, so I have tried to not do that too much. But since you asked, I'll try to step in more. -- John From mnislaih at gmail.com Thu Nov 30 11:17:10 2006 From: mnislaih at gmail.com (Pepe Iborra) Date: Thu Nov 30 11:15:34 2006 Subject: [Haskell-cafe] Command line utility that shrinks/simplifies functions applications ? In-Reply-To: <3F4E3C18-818D-4EE6-B452-C5E6B3803489@cse.unl.edu> References: <3F4E3C18-818D-4EE6-B452-C5E6B3803489@cse.unl.edu> Message-ID: On 30/11/2006, at 17:04, Spencer Janssen wrote: > I believe you're talking about the `pl' plugin for lambdabot. > Lambdabot has an offline mode, visit the homepage for the source: > http://www.cse.unsw.edu.au/~dons/lambdabot.html > > There is also a web interface to lambdabot, but I can't seem to > find the link. http://lambdabot.codersbase.com/ It's really nice, I use it all the time. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061130/27507c75/attachment.htm From ndmitchell at gmail.com Thu Nov 30 11:52:54 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Thu Nov 30 11:51:16 2006 Subject: [Haskell-cafe] Re: New Name for MissingH? In-Reply-To: References: <404396ef0611300606n3f5698a0q668dfd939f178437@mail.gmail.com> Message-ID: <404396ef0611300852n32c8e563w5c915e0b6bc92936@mail.gmail.com> Hi > I couldn't figure out how to add it to hoogle. Does anyone have a pointer > for that? Wait for Hoogle 4, and bug me. Hoogle 4 will allow additional libraries to be searched. Once its ready I'll add MissingH. > > database would probably help, along with greater "there is a function > > for that in MissingH" posts to the haskell-cafe list as people ask. > > True, too. I didn't want to be too annoying, so I have tried to not do that > too much. But since you asked, I'll try to step in more. I think its a great way to both promote MissingH, and help newcomers at the same time. Thanks Neil From kr.angelov at gmail.com Thu Nov 30 12:07:58 2006 From: kr.angelov at gmail.com (Krasimir Angelov) Date: Thu Nov 30 12:06:17 2006 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: Visual Haskell prerelease0.2 In-Reply-To: <252C89C12FCAD84BA018CAD5268682FD05B5FA0C@GBLONXMB02.corp.amvescap.net> References: <252C89C12FCAD84BA018CAD5268682FD05B5FA0C@GBLONXMB02.corp.amvescap.net> Message-ID: Hi Alistair, Visual Haskell is packaged with just the core libraries. Control.Monad.* modules are part of mtl and Test.HUnit is part of HUnit which aren't core libraries and aren't installed. It was long time ago when I was using the official Windows installer for last time. Is it still packaged with all libraries? Krasimir On 11/30/06, Bayley, Alistair wrote: > (not sure if this is the best place for questions about VisualHaskell) > > I've just installed VisualHaskell, and I've noticed that some of the > hierarchical libraries are missing/hidden: > - Control.Monad.State (and other chunks of the Control.Monad hierarchy, > like Control.Monad.Error/Identity/List/Trans) > - Test.HUnit (in fact Test.* is gone) > > and I'm sure there's plenty more missing. > > ? > > Alistair > ***************************************************************** > Confidentiality Note: The information contained in this message, > and any attachments, may contain confidential and/or privileged > material. It is intended solely for the person(s) or entity to > which it is addressed. Any review, retransmission, dissemination, > or taking of any action in reliance upon this information by > persons or entities other than the intended recipient(s) is > prohibited. If you received this in error, please contact the > sender and delete the material from any computer. > ***************************************************************** > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From kr.angelov at gmail.com Thu Nov 30 12:18:19 2006 From: kr.angelov at gmail.com (Krasimir Angelov) Date: Thu Nov 30 12:16:42 2006 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: Visual Haskell prerelease 0.2 In-Reply-To: References: <456C0D21.1040202@imn.htwk-leipzig.de> Message-ID: Hi Shelarcy, Could you check whether you have this registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\InstallDir and tell me its value? Typically its value should be such that the following script to work. Set shell = CreateObject("WScript.Shell") vstudioPath = shell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\InstallDir") shell.Run ("""" & vstudioPath & "devenv.exe"" /Setup",0,true) Cheers, Krasimir On 11/30/06, shelarcy wrote: > Hi Krasimir, > > > On 11/30/06, shelarcy wrote: > >> But ... I can't install Visual Haskell prerelease 0.2. Near > >> the end of install process, Microsoft Development Environment > >> cause error. > On Thu, 30 Nov 2006 17:03:22 +0900, Krasimir Angelov wrote: > > Could you tell me what error message you see during the installation? > > If it is in Japan then translate it in English ;-). > > It's not good error message. Anyway, I translate it. > > Near the end of install process, error dialog opened and says: > > --- > The problem happende, so exit Microsoft Development Environment. > I'm sorry for causing inconvenience to you. > > (under its message, error dialog has form that send error report > for Microsoft or shows error detail. These messages are not > important, so I don't translate that.) > --- > > And click form that shows error detail, another dialog opened. > It shows: > > --- > :Error ditail: > An unhandled exception has been caught by the VSW exception filter. > :Error Signature: > AppName: devenv.exe AppVer: 7.10.6030.0 ModName: unknown > ModVer: 0.0.0.0 Offset: 00bbbacc > :Report Detail: > (Below meassage attetion to user that error report send what. > So these messages are not important, too.) > --- > > > Also it can help > > if you run the installer with logging: > > > > $ msiexec VSHaskell71.msi /l log.txt > > msiexec doesn't run its command. And error dialog noticed that > you forgot /i optio. So I used below command. > > $ msiexec /i VSHaskell71.msi /l log.txt > > I think log.txt is much more useful than previous messages. > log.txt also has Japanese messages. So I translated that part. > > --- > (snip) > > Action 20:38:17: CA_RegisterHelpFile.3643236F_FC70_11D3_A536_0090278A1BB8. > IHxRegisterSession::ContinueTransaction() returned 0. > Helpfile: C:\Program Files\Visual Haskell\doc\alex.HxS was successfully registered to namespace vs_haskell. > ????elpfile: C:\Program Files\Visual Haskell\doc\building.HxS was successfully registered to namespace vs_haskell. > Helpfile: C:\Program Files\Visual Haskell\doc\Cabal.HxS was successfully registered to namespace vs_haskell. > Helpfile: C:\Program Files\Visual Haskell\doc\haddock.HxS was successfully registered to namespace vs_haskell. > Helpfile: C:\Program Files\Visual Haskell\doc\happy.HxS was successfully registered to namespace vs_haskell. > Helpfile: C:\Program Files\Visual Haskell\doc\libraries.HxS was successfully registered to namespace vs_haskell. > Helpfile: C:\Program Files\Visual Haskell\doc\users_guide.HxS was successfully registered to namespace vs_haskell. > Helpfile: C:\Program Files\Visual Haskell\doc\vh.HxS was successfully registered to namespace vs_haskell. > Action 20:38:17: CA_RegisterPlugIn.3643236F_FC70_11D3_A536_0090278A1BB8. > IHxRegisterSession::ContinueTransaction() returned 0. > IHxPlugIn::RegisterHelpPlugIn() returned 0. > Namespace: vs_haskell was successfully plugged into namespace MS.VSCC.2003. > Action 20:38:17: CA_CommitHelpTransaction.3643236F_FC70_11D3_A536_0090278A1BB8. > Action 20:38:17: RegisterProduct. Registering product > RegisterProduct: {FEC3263A-9034-49C5-8C5D-902231009894} > Action 20:38:18: PublishFeatures. Publishing Product Features > PublishFeatures: Feature: Complete > Action 20:38:18: PublishProduct. Publishing product information > 1: {FEC3263A-9034-49C5-8C5D-902231009894} > Action 20:38:18: RollbackCleanup. Removing backup files > IHxRegisterSession::ContinueTransaction() returned 0. > Registration session: {FEC3263A-9034-49C5-8C5D-902231009894} was successfully committed. > RollbackCleanup: File: C:\Config.Msi\fc3d12.rbf > RollbackCleanup: File: C:\Config.Msi\fc3d13.rbf > RollbackCleanup: File: C:\Config.Msi\fc3d14.rbf > RollbackCleanup: File: C:\Config.Msi\fc3d15.rbf > RollbackCleanup: File: C:\Config.Msi\fc3d16.rbf > Action ended 20:38:18: InstallFinalize. Return value 1. > Action 20:38:18: CA_HxMerge_VSCC.3643236F_FC70_11D3_A536_0090278A1BB8. > Action start 20:38:18: CA_HxMerge_VSCC.3643236F_FC70_11D3_A536_0090278A1BB8. > ????tion ended 20:40:09: CA_HxMerge_VSCC.3643236F_FC70_11D3_A536_0090278A1BB8. Return value 1. > Action 20:40:09: CA_RemoveTempHxDs.3643236F_FC70_11D3_A536_0090278A1BB8. > Action start 20:40:09: CA_RemoveTempHxDs.3643236F_FC70_11D3_A536_0090278A1BB8. > Action ended 20:40:09: CA_RemoveTempHxDs.3643236F_FC70_11D3_A536_0090278A1BB8. Return value 1. > Action 20:40:09: VSHaskellInstall. Register Visual Haskell Plugin > Action start 20:40:09: VSHaskellInstall. > Error 1720. There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor. Custom action VSHaskellInstall script error -2146828275, Microsoft VBScript Runtime Error: Couldn't match types.: 'Return' Line 55, Column 5, > MSI (s) (0C:D4) [20:51:43:359]: Product: Visual Haskell 0.2 for Visual Studio 2003 -- Error 1720. There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor. Custom action VSHaskellInstall script error -2146828275, Microsoft VBScript Runtime Error: Couldn't match types.: 'Return' Line 55, Column 5, > > Action ended 20:51:43: VSHaskellInstall. Return value 3. > Action ended 20:51:43: INSTALL. Return value 3. > Action ended 20:51:43: ExecuteAction. Return value 3. > Action 20:51:43: FatalError. > Action start 20:51:43: FatalError. > Action 20:51:43: FatalError. Dialog created > Action ended 20:51:46: FatalError. Return value 2. > Action ended 20:51:46: INSTALL. Return value 3. > === Logging stopped: 2006/11/30 20:51:46 === > MSI (c) (B8:C4) [20:51:46:046]: Product: Visual Haskell 0.2 for Visual Studio 2003 -- Installation failed. > --- > > > > In the Visual Haskell\bin directory you can see one directory called > > 1033 with vs_haskell_ui.dll in it. vs_haskell_ui.dll contains various > > string resources used in Visual Haskell. For each supported language > > you need to have a different directory and 1033 is the code used for > > English. I don't know the code required for Japan but you can look at > > C:\Program Files\Microsoft Visual Studio 8\VC\bin directory and see > > what code VC++ is using. After that try to rename the 1033 directory > > to what is required for Japan. Tell me whether that works. > > Japanese diretory is 1041. > > After rename it, I tried to use Visual Haskell 0.2. But same error dialog > opened and exit Visual Studio, too. > > > -- > shelarcy > http://page.freett.com/shelarcy/ > From kr.angelov at gmail.com Thu Nov 30 12:26:23 2006 From: kr.angelov at gmail.com (Krasimir Angelov) Date: Thu Nov 30 12:24:40 2006 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: Visual Haskell prerelease 0.2 In-Reply-To: References: <456C0D21.1040202@imn.htwk-leipzig.de> Message-ID: You can try to setup it manually using the following commands: $ regsvr32 /i:8.0 /n vs_haskell.dll $ regsvr32 /i:8.0 /n vs_haskell_babel.dll $ regsvr32 /i:8.0 /n vs_haskell_dlg.dll $ devenv.exe /Setup On 11/30/06, Krasimir Angelov wrote: > Hi Shelarcy, > > Could you check whether you have this registry key: > > HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\InstallDir > > and tell me its value? Typically its value should be such that the > following script to work. > > Set shell = CreateObject("WScript.Shell") > vstudioPath = shell.RegRead > ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\InstallDir") > shell.Run ("""" & vstudioPath & "devenv.exe"" /Setup",0,true) > > Cheers, > Krasimir > > > On 11/30/06, shelarcy wrote: > > Hi Krasimir, > > > > > On 11/30/06, shelarcy wrote: > > >> But ... I can't install Visual Haskell prerelease 0.2. Near > > >> the end of install process, Microsoft Development Environment > > >> cause error. > > On Thu, 30 Nov 2006 17:03:22 +0900, Krasimir Angelov wrote: > > > Could you tell me what error message you see during the installation? > > > If it is in Japan then translate it in English ;-). > > > > It's not good error message. Anyway, I translate it. > > > > Near the end of install process, error dialog opened and says: > > > > --- > > The problem happende, so exit Microsoft Development Environment. > > I'm sorry for causing inconvenience to you. > > > > (under its message, error dialog has form that send error report > > for Microsoft or shows error detail. These messages are not > > important, so I don't translate that.) > > --- > > > > And click form that shows error detail, another dialog opened. > > It shows: > > > > --- > > :Error ditail: > > An unhandled exception has been caught by the VSW exception filter. > > :Error Signature: > > AppName: devenv.exe AppVer: 7.10.6030.0 ModName: unknown > > ModVer: 0.0.0.0 Offset: 00bbbacc > > :Report Detail: > > (Below meassage attetion to user that error report send what. > > So these messages are not important, too.) > > --- > > > > > Also it can help > > > if you run the installer with logging: > > > > > > $ msiexec VSHaskell71.msi /l log.txt > > > > msiexec doesn't run its command. And error dialog noticed that > > you forgot /i optio. So I used below command. > > > > $ msiexec /i VSHaskell71.msi /l log.txt > > > > I think log.txt is much more useful than previous messages. > > log.txt also has Japanese messages. So I translated that part. > > > > --- > > (snip) > > > > Action 20:38:17: CA_RegisterHelpFile.3643236F_FC70_11D3_A536_0090278A1BB8. > > IHxRegisterSession::ContinueTransaction() returned 0. > > Helpfile: C:\Program Files\Visual Haskell\doc\alex.HxS was successfully registered to namespace vs_haskell. > > ????elpfile: C:\Program Files\Visual Haskell\doc\building.HxS was successfully registered to namespace vs_haskell. > > Helpfile: C:\Program Files\Visual Haskell\doc\Cabal.HxS was successfully registered to namespace vs_haskell. > > Helpfile: C:\Program Files\Visual Haskell\doc\haddock.HxS was successfully registered to namespace vs_haskell. > > Helpfile: C:\Program Files\Visual Haskell\doc\happy.HxS was successfully registered to namespace vs_haskell. > > Helpfile: C:\Program Files\Visual Haskell\doc\libraries.HxS was successfully registered to namespace vs_haskell. > > Helpfile: C:\Program Files\Visual Haskell\doc\users_guide.HxS was successfully registered to namespace vs_haskell. > > Helpfile: C:\Program Files\Visual Haskell\doc\vh.HxS was successfully registered to namespace vs_haskell. > > Action 20:38:17: CA_RegisterPlugIn.3643236F_FC70_11D3_A536_0090278A1BB8. > > IHxRegisterSession::ContinueTransaction() returned 0. > > IHxPlugIn::RegisterHelpPlugIn() returned 0. > > Namespace: vs_haskell was successfully plugged into namespace MS.VSCC.2003. > > Action 20:38:17: CA_CommitHelpTransaction.3643236F_FC70_11D3_A536_0090278A1BB8. > > Action 20:38:17: RegisterProduct. Registering product > > RegisterProduct: {FEC3263A-9034-49C5-8C5D-902231009894} > > Action 20:38:18: PublishFeatures. Publishing Product Features > > PublishFeatures: Feature: Complete > > Action 20:38:18: PublishProduct. Publishing product information > > 1: {FEC3263A-9034-49C5-8C5D-902231009894} > > Action 20:38:18: RollbackCleanup. Removing backup files > > IHxRegisterSession::ContinueTransaction() returned 0. > > Registration session: {FEC3263A-9034-49C5-8C5D-902231009894} was successfully committed. > > RollbackCleanup: File: C:\Config.Msi\fc3d12.rbf > > RollbackCleanup: File: C:\Config.Msi\fc3d13.rbf > > RollbackCleanup: File: C:\Config.Msi\fc3d14.rbf > > RollbackCleanup: File: C:\Config.Msi\fc3d15.rbf > > RollbackCleanup: File: C:\Config.Msi\fc3d16.rbf > > Action ended 20:38:18: InstallFinalize. Return value 1. > > Action 20:38:18: CA_HxMerge_VSCC.3643236F_FC70_11D3_A536_0090278A1BB8. > > Action start 20:38:18: CA_HxMerge_VSCC.3643236F_FC70_11D3_A536_0090278A1BB8. > > ????tion ended 20:40:09: CA_HxMerge_VSCC.3643236F_FC70_11D3_A536_0090278A1BB8. Return value 1. > > Action 20:40:09: CA_RemoveTempHxDs.3643236F_FC70_11D3_A536_0090278A1BB8. > > Action start 20:40:09: CA_RemoveTempHxDs.3643236F_FC70_11D3_A536_0090278A1BB8. > > Action ended 20:40:09: CA_RemoveTempHxDs.3643236F_FC70_11D3_A536_0090278A1BB8. Return value 1. > > Action 20:40:09: VSHaskellInstall. Register Visual Haskell Plugin > > Action start 20:40:09: VSHaskellInstall. > > Error 1720. There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor. Custom action VSHaskellInstall script error -2146828275, Microsoft VBScript Runtime Error: Couldn't match types.: 'Return' Line 55, Column 5, > > MSI (s) (0C:D4) [20:51:43:359]: Product: Visual Haskell 0.2 for Visual Studio 2003 -- Error 1720. There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor. Custom action VSHaskellInstall script error -2146828275, Microsoft VBScript Runtime Error: Couldn't match types.: 'Return' Line 55, Column 5, > > > > Action ended 20:51:43: VSHaskellInstall. Return value 3. > > Action ended 20:51:43: INSTALL. Return value 3. > > Action ended 20:51:43: ExecuteAction. Return value 3. > > Action 20:51:43: FatalError. > > Action start 20:51:43: FatalError. > > Action 20:51:43: FatalError. Dialog created > > Action ended 20:51:46: FatalError. Return value 2. > > Action ended 20:51:46: INSTALL. Return value 3. > > === Logging stopped: 2006/11/30 20:51:46 === > > MSI (c) (B8:C4) [20:51:46:046]: Product: Visual Haskell 0.2 for Visual Studio 2003 -- Installation failed. > > --- > > > > > > > In the Visual Haskell\bin directory you can see one directory called > > > 1033 with vs_haskell_ui.dll in it. vs_haskell_ui.dll contains various > > > string resources used in Visual Haskell. For each supported language > > > you need to have a different directory and 1033 is the code used for > > > English. I don't know the code required for Japan but you can look at > > > C:\Program Files\Microsoft Visual Studio 8\VC\bin directory and see > > > what code VC++ is using. After that try to rename the 1033 directory > > > to what is required for Japan. Tell me whether that works. > > > > Japanese diretory is 1041. > > > > After rename it, I tried to use Visual Haskell 0.2. But same error dialog > > opened and exit Visual Studio, too. > > > > > > -- > > shelarcy > > http://page.freett.com/shelarcy/ > > > From jgbailey at gmail.com Thu Nov 30 13:48:49 2006 From: jgbailey at gmail.com (Justin Bailey) Date: Thu Nov 30 13:47:06 2006 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: Visual Haskell prerelease 0.2 In-Reply-To: References: <456C0D21.1040202@imn.htwk-leipzig.de> Message-ID: On 11/30/06, Krasimir Angelov wrote: > > You can try to setup it manually using the following commands: > > $ regsvr32 /i:8.0 /n vs_haskell.dll > $ regsvr32 /i:8.0 /n vs_haskell_babel.dll > $ regsvr32 /i:8.0 /n vs_haskell_dlg.dll > $ devenv.exe /Setup I am having similar problems with the Visual Haskell install, and the commands given did not help. When I open Visual Studios Help | About dialog, I get an error about the package failing to initialize. I am installing to an English copy, however. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061130/88a0b4fc/attachment.htm From jgoerzen at complete.org Thu Nov 30 14:46:05 2006 From: jgoerzen at complete.org (John Goerzen) Date: Thu Nov 30 14:45:30 2006 Subject: [Haskell-cafe] Building Binaries with Cabal Message-ID: Hi folks, I'm in need of some Cabal assistance. I want to build the unit tests for MissingH using Cabal. According to the docs, this should require me to list all of the exposed modules from the library as other modules to the binary. Since there are dozens of these, I thought a simple hook could do the trick. I tried hooking into the confHook (which I have already used successfully to add "unix" as a build-dep on non-Windows platforms), and thought I could just pull the exposedModules list from the package and add those as otherModules to the executable. But it had no effect. So I tried hooking in to customBuildHook to do the same thing. Again, no effect. Here's the code I've tried. Suggestions appreciated. import Distribution.Simple import Distribution.PackageDescription import Distribution.Version import System.Info import Data.Maybe winHooks = defaultUserHooks {confHook = customConfHook} customConfHook descrip flags = let mydescrip = case System.Info.os of "mingw32" -> descrip _ -> descrip {buildDepends = (Dependency "unix" AnyVersion) : buildDepends descrip} in (confHook defaultUserHooks) mydescrip flags customBuildHook descrip lbi uh flags = let myexecutables = map bdfix (executables descrip) bdfix exe = exe {buildInfo = (buildInfo exe) {otherModules = exposedModules . fromJust . library $ descrip}} mydescrip = descrip {executables = myexecutables} in (buildHook defaultUserHooks) mydescrip flags main = defaultMainWithHooks winHooks From jgoerzen at complete.org Thu Nov 30 14:52:47 2006 From: jgoerzen at complete.org (John Goerzen) Date: Thu Nov 30 14:51:22 2006 Subject: [Haskell-cafe] Re: Building Binaries with Cabal References: Message-ID: I posted a weird version of the code. Here's the real version. Same problem I described, though. Distribution.Simple import Distribution.PackageDescription import Distribution.Version import System.Info import Data.Maybe winHooks = defaultUserHooks {confHook = customConfHook, buildHook = customBuildHook} customConfHook descrip flags = let mydescrip = case System.Info.os of "mingw32" -> descrip _ -> descrip {buildDepends = (Dependency "unix" AnyVersion) : buildDepends descrip} in (confHook defaultUserHooks) mydescrip flags customBuildHook descrip lbi uh flags = let myexecutables = map bdfix (executables descrip) bdfix exe = exe {buildInfo = (buildInfo exe) {otherModules = exposedModules . fromJust . library $ descrip}} mydescrip = descrip {executables = myexecutables} in do print mydescrip (buildHook defaultUserHooks) mydescrip lbi uh flags main = defaultMainWithHooks winHooks From ndmitchell at gmail.com Thu Nov 30 15:53:36 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Thu Nov 30 15:51:52 2006 Subject: [Haskell-cafe] Building Binaries with Cabal In-Reply-To: References: Message-ID: <404396ef0611301253h18231678lb3208f97c1fef90@mail.gmail.com> Hi > let mydescrip = case System.Info.os of > "mingw32" -> descrip > _ -> descrip {buildDepends = Arrrrggggghhhhhhh! To test if the operating system is windows you compare against a hard coded string which _isn't_ an OS, but _is_ an optional component by a 3rd party. It's required to build some Haskell compilers, but for Yhc and Hugs its not required at any stage, and its presence is optional! I know this isn't your fault, it just scares me deeply that "os" could return something that isn't an os! How about we add a cpu string, which returns the amount of RAM installed. Or how about we add a compiler string, which returns the users surname... Thanks Neil From jgoerzen at complete.org Thu Nov 30 16:13:37 2006 From: jgoerzen at complete.org (John Goerzen) Date: Thu Nov 30 16:11:57 2006 Subject: [Haskell-cafe] Building Binaries with Cabal In-Reply-To: <404396ef0611301253h18231678lb3208f97c1fef90@mail.gmail.com> References: <404396ef0611301253h18231678lb3208f97c1fef90@mail.gmail.com> Message-ID: <20061130211337.GB14357@excelhustler.com> On Thu, Nov 30, 2006 at 08:53:36PM +0000, Neil Mitchell wrote: > Arrrrggggghhhhhhh! To test if the operating system is windows you > compare against a hard coded string which _isn't_ an OS, but _is_ an > optional component by a 3rd party. It's required to build some Haskell > compilers, but for Yhc and Hugs its not required at any stage, and its > presence is optional! Your point is well-taken, but the distinction is useful. If running on cygwin, my platform is essentially POSIX, even though the OS is Windows. And yes, I do claim that this isn't my fault ;-) -- John From ndmitchell at gmail.com Thu Nov 30 16:32:29 2006 From: ndmitchell at gmail.com (Neil Mitchell) Date: Thu Nov 30 16:30:47 2006 Subject: [Haskell-cafe] Building Binaries with Cabal In-Reply-To: <20061130211337.GB14357@excelhustler.com> References: <404396ef0611301253h18231678lb3208f97c1fef90@mail.gmail.com> <20061130211337.GB14357@excelhustler.com> Message-ID: <404396ef0611301332p398cddffn1de367ccaa0ef1a0@mail.gmail.com> Hi > Your point is well-taken, but the distinction is useful. If running on > cygwin, my platform is essentially POSIX, even though the OS is Windows. Yes, but _my_ OS is reported as "mingw32", even though its never been installed on this computer... Thanks Neil From hankgong at nm.gist.ac.kr Thu Nov 30 20:47:43 2006 From: hankgong at nm.gist.ac.kr (Huazhi (Hank) Gong) Date: Thu Nov 30 20:45:59 2006 Subject: [Haskell-cafe] How to get subset of a list? Message-ID: <7631994.post@talk.nabble.com> Like given a string list s="This is the string I want to test", I want to get the substring. In ruby or other language, it's simple like s[2..10], but how to do it in Haskell? -- View this message in context: http://www.nabble.com/How-to-get-subset-of-a-list--tf2735647.html#a7631994 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From stefanor at cox.net Thu Nov 30 20:53:00 2006 From: stefanor at cox.net (Stefan O'Rear) Date: Thu Nov 30 20:51:17 2006 Subject: [Haskell-cafe] How to get subset of a list? In-Reply-To: <7631994.post@talk.nabble.com> References: <7631994.post@talk.nabble.com> Message-ID: <20061201015300.GA3935@localhost.localdomain> On Thu, Nov 30, 2006 at 05:47:43PM -0800, Huazhi (Hank) Gong wrote: > > Like given a string list s="This is the string I want to test", I want to get > the substring. In ruby or other language, it's simple like s[2..10], but how > to do it in Haskell? Use take and drop, from the Prelude: (ghci session) Prelude> "Hello world" "Hello world" Prelude> drop 3 "Hello world" "lo world" Prelude> take 7 (drop 3 "Hello world") "lo worl" Prelude> From hankgong at nm.gist.ac.kr Thu Nov 30 21:04:10 2006 From: hankgong at nm.gist.ac.kr (Huazhi (Hank) Gong) Date: Thu Nov 30 21:02:25 2006 Subject: [Haskell-cafe] How to get subset of a list? In-Reply-To: <20061201015300.GA3935@localhost.localdomain> References: <7631994.post@talk.nabble.com> <20061201015300.GA3935@localhost.localdomain> Message-ID: <7632145.post@talk.nabble.com> Thanks, it make sense here. However, like I want to choose s[1,3,6,10] or something like this. Are there some straightforward function or operator for doing this job? The !! operator in haskell seems does not support multiple indecies. Hank Stefan O wrote: > > On Thu, Nov 30, 2006 at 05:47:43PM -0800, Huazhi (Hank) Gong wrote: >> >> Like given a string list s="This is the string I want to test", I want to >> get >> the substring. In ruby or other language, it's simple like s[2..10], but >> how >> to do it in Haskell? > > Use take and drop, from the Prelude: > > (ghci session) > Prelude> "Hello world" > "Hello world" > Prelude> drop 3 "Hello world" > "lo world" > Prelude> take 7 (drop 3 "Hello world") > "lo worl" > Prelude> > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -- View this message in context: http://www.nabble.com/How-to-get-subset-of-a-list--tf2735647.html#a7632145 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From taralx at gmail.com Thu Nov 30 21:08:18 2006 From: taralx at gmail.com (Taral) Date: Thu Nov 30 21:06:34 2006 Subject: [Haskell-cafe] How to get subset of a list? In-Reply-To: <7632145.post@talk.nabble.com> References: <7631994.post@talk.nabble.com> <20061201015300.GA3935@localhost.localdomain> <7632145.post@talk.nabble.com> Message-ID: On 11/30/06, Huazhi (Hank) Gong wrote: > Thanks, it make sense here. > However, like I want to choose s[1,3,6,10] or something like this. Are there > some straightforward function or operator for doing this job? The !! > operator in haskell seems does not support multiple indecies. If you're trying to do random access on a list, you should rethink why you're using a list. -- Taral "You can't prove anything." -- G?del's Incompetence Theorem From westondan at imageworks.com Thu Nov 30 21:15:40 2006 From: westondan at imageworks.com (Dan Weston) Date: Thu Nov 30 21:14:38 2006 Subject: [Haskell-cafe] How to get subset of a list? In-Reply-To: References: <7631994.post@talk.nabble.com> <20061201015300.GA3935@localhost.localdomain> <7632145.post@talk.nabble.com> Message-ID: <456F904C.9030008@imageworks.com> Your curious example suggests you might be solving a more specialized problem, like selecting the diagonal of a flattened matrix. In this case, there are much better (and more efficient) data structures that enforce invariants (like squareness of a matrix), if that is what you in fact are doing. Taral wrote: > On 11/30/06, Huazhi (Hank) Gong wrote: >> Thanks, it make sense here. >> However, like I want to choose s[1,3,6,10] or something like this. Are >> there >> some straightforward function or operator for doing this job? The !! >> operator in haskell seems does not support multiple indecies. > > If you're trying to do random access on a list, you should rethink why > you're using a list. > From shelarcy at gmail.com Thu Nov 30 22:06:02 2006 From: shelarcy at gmail.com (shelarcy) Date: Thu Nov 30 22:03:31 2006 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: Visual Haskell prerelease 0.2 In-Reply-To: References: <456C0D21.1040202@imn.htwk-leipzig.de> Message-ID: Hi Krasimir, On Fri, 01 Dec 2006 02:18:19 +0900, Krasimir Angelov wrote: > Could you check whether you have this registry key: > > HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\InstallDir > > and tell me its value? "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.1\InstallDir" value is "C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\". > Typically its value should be such that the > following script to work. > > Set shell = CreateObject("WScript.Shell") > vstudioPath = shell.RegRead > ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\InstallDir") > shell.Run ("""" & vstudioPath & "devenv.exe"" /Setup",0,true) I saw your message, then I checked vshaskell darcs repository and I saw vs_haskell_setup/setup.vbs. Okay, I know I forgot to tell popup message what made by VBScript. I saw just one popup message. It says "Failed to setup VStudio". > On 11/30/06, shelarcy wrote: >> Hi Krasimir, >> >> > On 11/30/06, shelarcy wrote: >> >> But ... I can't install Visual Haskell prerelease 0.2. Near >> >> the end of install process, Microsoft Development Environment >> >> cause error. >> On Thu, 30 Nov 2006 17:03:22 +0900, Krasimir Angelov wrote: >> > Could you tell me what error message you see during the installation? >> > If it is in Japan then translate it in English ;-). >> >> It's not good error message. Anyway, I translate it. Best Regards, -- shelarcy http://page.freett.com/shelarcy/ From shelarcy at gmail.com Thu Nov 30 22:10:40 2006 From: shelarcy at gmail.com (shelarcy) Date: Thu Nov 30 22:08:07 2006 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: Visual Haskell prerelease 0.2 In-Reply-To: References: <456C0D21.1040202@imn.htwk-leipzig.de> Message-ID: Hi Krasimir, > On 11/30/06, Krasimir Angelov wrote: >> >> You can try to setup it manually using the following commands: >> >> $ regsvr32 /i:8.0 /n vs_haskell.dll >> $ regsvr32 /i:8.0 /n vs_haskell_babel.dll >> $ regsvr32 /i:8.0 /n vs_haskell_dlg.dll >> $ devenv.exe /Setup Why you always show 8.0 instead of 7.1? On Fri, 01 Dec 2006 03:48:49 +0900, Justin Bailey wrote: > I am having similar problems with the Visual Haskell install, and the > commands given did not help. When I open Visual Studios Help | About dialog, > I get an error about the package failing to initialize. I am installing to > an English copy, however. Their commands didn't help for my environment too. I saw same error dialog that I sent previous mail. >> On 11/30/06, shelarcy wrote: >> > It's not good error message. Anyway, I translate it. >> > >> > Near the end of install process, error dialog opened and says: >> > >> > --- >> > The problem happende, so exit Microsoft Development Environment. >> > I'm sorry for causing inconvenience to you. >> > >> > (under its message, error dialog has form that send error report >> > for Microsoft or shows error detail. These messages are not >> > important, so I don't translate that.) >> > --- >> > >> > And click form that shows error detail, another dialog opened. >> > It shows: >> > >> > --- >> > :Error ditail: >> > An unhandled exception has been caught by the VSW exception filter. >> > :Error Signature: >> > AppName: devenv.exe AppVer: 7.10.6030.0 ModName: unknown >> > ModVer: 0.0.0.0 Offset: 00bbbacc >> > :Report Detail: >> > (Below meassage attetion to user that error report send what. >> > So these messages are not important, too.) >> > --- Best Regards, -- shelarcy http://page.freett.com/shelarcy/ From bjpop at csse.unimelb.edu.au Thu Nov 30 22:28:06 2006 From: bjpop at csse.unimelb.edu.au (Bernie Pope) Date: Thu Nov 30 22:25:01 2006 Subject: [Haskell-cafe] How to get subset of a list? In-Reply-To: <7631994.post@talk.nabble.com> References: <7631994.post@talk.nabble.com> Message-ID: <40619050-41D7-467D-895A-05877C2990EB@csse.unimelb.edu.au> On 01/12/2006, at 12:47 PM, Huazhi (Hank) Gong wrote: > > Like given a string list s="This is the string I want to test", I > want to get > the substring. In ruby or other language, it's simple like s > [2..10], but how > to do it in Haskell? If your indices are in ascending order, and unique, then something like this might do the trick: els1 indexes list = els' (zip [0..] list) indexes where els' [] _ = [] els' _ [] = [] els' ((j,x):xs) indexes@(i:is) | i == j = x : els' xs is | otherwise = els' xs indexes Of course this is a right fold, so you ought to be able to use foldr. Here's an attempt: els2 indexes list = foldr comb undefined [0..] list indexes where comb _ _ [] _ = [] comb _ _ _ [] = [] comb j rec (x:xs) indexes@(i:is) | j == i = x : rec xs is | otherwise = rec xs indexes Bonus marks for figuring out why I used "undefined". Warning: this is largely untested code. Cheers, Bernie. From oleg at pobox.com Thu Nov 30 23:02:21 2006 From: oleg at pobox.com (oleg@pobox.com) Date: Thu Nov 30 23:01:08 2006 Subject: [Haskell-cafe] Re: How to get subset of a list? Message-ID: <20061201040221.19166AB40@Adric.metnet.fnmoc.navy.mil> Huazhi (Hank) Gong wrote: > Like given a string list s="This is the string I want to test", I want to get > the substring. In ruby or other language, it's simple like s[2..10], but how > to do it in Haskell? Quite simply, actually: > infixl 1 %% > str %% idxs = map (str !!) idxs That is it. Not the most efficient, but gets the job done. > tstring = "This is the string I want to test" > test1 = tstring %% [2..10] *Sub> test1 "is is the" > However, like I want to choose s[1,3,6,10] or something like this. > Are there some straightforward function or operator for doing this > job? Yes, see above. > test2 = tstring %% [1,3,6,10] *Sub> test2 "hsse" Indices don't have to be in the increasing order > test3 = tstring %% [10,6,3,1] *Sub> test3 "essh" or in any order... > test4 = tstring %% [10,6,3,1]++[2..10] *Sub> test4 "esshis is the" Of course if one cares about the overhead of running code (rather than the overhead of writing code), one would probably ask, as several posters did, if the list of characters is the right data structure and if the problem indeed calls for random access to the elements of the list. From jgoerzen at complete.org Thu Nov 30 23:06:08 2006 From: jgoerzen at complete.org (John Goerzen) Date: Thu Nov 30 23:04:38 2006 Subject: [Haskell-cafe] Draft MissingH Reorg Plan Message-ID: Please tell me if I should just go away or go to another list here. Thanks again for all the feedback you've sent. I've got the new MissingH website getting started, and I've posted there the draft reorganization, module rename, and package split plan here: http://software.complete.org/missingh/wiki/TransitionPlanning Your comments (and edits! -- must register/login first) are welcome. I have not yet audited the plan for dependency sanity. This could complicate things a few places, but hopefully not too many. -- John