Re: [Haskell-cafe] how can this code be less?
cetin tozkoparan [EMAIL PROTECTED] writes: sublist :: Eq a = [a] - [a] - Bool sublist [] _ = True sublist (_:_) [] = False This can be simplified a bit, I think (Reformatted to one line): sublist (x:xs) (y:ys) | x == y = if isEqual (x:xs) (y:ys) == False then sublist (x:xs) ys else True I don't like the == False for boolean expressions, so I'd write: sublist (x:xs) (y:ys) | x == y = if not (isEqual (x:xs) (y:ys)) then sublist (x:xs) ys else True Or, swithing then and else clauses: sublist (x:xs) (y:ys) | x == y = if isEqual (x:xs) (y:ys) then True else sublist (x:xs) ys If you look at the following clause: | otherwise = sublist (x:xs) ys you'll notice that it is the same as the else clause. We can therefore write: sublist (x:xs) (y:ys) | x == y isEqual (x:xs) (y:ys) = True | otherwise = sublist (x:xs) ys isEqual will re-test x==y, so this is redundant: sublist (x:xs) (y:ys) | isEqual (x:xs) (y:ys) = True | otherwise = sublist (x:xs) ys The pattern guard is a bit gratuitious, why not write: sublist (x:xs) (y:ys) = isEqual (x:xs) (y:ys) || sublist (x:xs) ys Which is how you'd define the problem: a list xs is a sublist of ys if they have equal prefixes, or if xs is a sublist of the tail of ys. isEqual :: Eq a = [a] - [a] - Bool Slightly misleading name, since it checks a prefix, not complete equality. isEqual [] _ = True isEqual (_:_) [] = False isEqual (x:xs) (y:ys) | x==y= isEqual xs ys | otherwise= False Similar to the above, you could write: isEqual (x:xs) (y:ys) = x == y isEqual xs ys lists (x:xs) and (y:ys) 'isEqual' if x == y and xs 'isEqual' ys As pointed out, you could (and should) write this using a couple of Prelude functions. Oh, any errors in the code are left as excercises for the reader (in other words, I didn't test this code at all, but don't want to be perceived as lazy.) -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Stronger STM primitives needed? Or am I just doing it wrong?
On 24 Apr 2008, at 12:02, apfelmus wrote: Sounds good. But I wonder what obscure optimization comes next; can we have a toy-model of STM? I mean, it should be possible to express both the continuation-logging and read-only-fail optimization in terms of type STM a = Maybe a or similar? There's a pure version of STM in the latest version of the IOSpec library: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/IOSpec-0.2 I've used it to test a few non-trivial applications. I should warn you that it does use a very simple stop-the-world semantics - the model may not be fine-grained enough to try out all kinds of optimisations. Wouter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: Re[2]: a faster, accumulating mapM (was Re: [Haskell-cafe] mapM vs mapM_ performance)
| 1) Why is the Prelude mapM so slow? It seems like running 10x slower | than mapM_ when generating only 50,000 return values is a problem. All this does seem odd. I've submitted a ticket so we don't forget it http://hackage.haskell.org/trac/ghc/ticket/2236 It appears to be some bad (possibly even non-linear) run-time system or garbage collector effect, caused by the very deep stack. Thanks for persisting with this. I'd expect mapM to be a bit slower, but not *that* much. Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] looking for examples of non-full Functional Dependencies
On 18 Apr 2008, at 20:04, Martin Sulzmann wrote: Let's consider our running example class D a b | a - b instance D a b = D [a] [b] which we can write in CHR notation D a b, D a c == b=c(FD) D [a] [b] = D a b (Inst) These rules overlap. I experimented with translations into GNU Prolog (gprolog). Since = is hard to get working in Prolog unless integrated into unification, I tried (using the idea of rewriting unique existence as functions, possible if one assumes the axiom of choice): class(d, A, b(A)). instance(d, l(A), l(B)) :- class(d, A, B). Then: ?- instance(d, l(A), l(B)). B = b(A) ?- instance(d, l(A), C). C = l(b(A)) ?- instance(d, l(A), l(B)), instance(d, l(A), C). B = b(A) C = l(b(A)) Though I am not sure about the intended semantics, it does produce unique solutions. Hans ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Help me refactor this type!
Ryan Ingram wrote: More FRP stuff: a new type for Future that came to me in an inspiration this morning. But it's ugly and I need someone with better theoretical underpinnings than me to tell me what I've really built :) data Future t a = Known t a | Unknown (t - IO (STM (Maybe (Future t a This is a composition of (applicative) functors. Not sure whether this helps from the theoretical side, but it can be used to considerably shorten your code: type Tower t b = t - IO (STM (Maybe b)) fmap4 :: (a - b) - Tower a - Tower b fmap4 f = fmap . fmap . fmap . fmap $ f delayF :: Ord t = t - Future t a - Future t a delayF t0 (Known t a) = Known (max t0 t) a delayF t0 (Unknown f) = Unknown $ fmap4 (delayF0 t0) f instance (Ord t, Bounded t) = Monad (Future t) where return = Known minBound Known t a = g = delayF t (g a) Unknown f = g = Unknown $ fmap4 (= g) f Regards, apfelmus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: how can this code be less?
You may want to study the code form Data.List first: isInfixOf :: (Eq a) = [a] - [a] - Bool isInfixOf needle haystack = any (isPrefixOf needle) (tails haystack) cetin tozkoparan wrote: I wrote this code and Can it be less? [2,4,5] list is sub list of [3,7,*2,4,5*,9] list and return True but not of [3,7,*4,2,5*,9] list ; return False sublist :: Eq a = [a] - [a] - Bool sublist [] _ = True sublist (_:_) [] = False sublist (x:xs) (y:ys) | x == y = if isEqual (x:xs) (y:ys) == False then sublist (x:xs) ys else True | otherwise = sublist (x:xs) ys isEqual :: Eq a = [a] - [a] - Bool isEqual [] _ = True isEqual (_:_) [] = False isEqual (x:xs) (y:ys) | x==y = isEqual xs ys | otherwise= False isEqual is not needed, because Eq provides == over lists, too. HTH Christian ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: how can this code be less?
Christian Maeder wrote: isEqual :: Eq a = [a] - [a] - Bool isEqual [] _ = True isEqual (_:_) [] = False isEqual (x:xs) (y:ys) | x==y = isEqual xs ys | otherwise= False isEqual is not needed, because Eq provides == over lists, too. Ah, isEqual isn't ==, but isPrefixOf. C. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] looking for examples of non-full Functional Dependencies
On Fri, 25 Apr 2008, Hans Aberg wrote: On 18 Apr 2008, at 20:04, Martin Sulzmann wrote: Let's consider our running example class D a b | a - b instance D a b = D [a] [b] which we can write in CHR notation D a b, D a c == b=c(FD) D [a] [b] = D a b (Inst) These rules overlap. I experimented with translations into GNU Prolog (gprolog). Since = is hard to get working in Prolog unless integrated into unification, I tried (using the idea of rewriting unique existence as functions, possible if one assumes the axiom of choice): class(d, A, b(A)). instance(d, l(A), l(B)) :- class(d, A, B). Then: ?- instance(d, l(A), l(B)). B = b(A) ?- instance(d, l(A), C). C = l(b(A)) ?- instance(d, l(A), l(B)), instance(d, l(A), C). B = b(A) C = l(b(A)) Though I am not sure about the intended semantics, it does produce unique solutions. Prolog works under the assumption of a closed world. That's contrary to the open world view of regular type classes. So these aren't the intended semantics. Tom -- Tom Schrijvers Department of Computer Science K.U. Leuven Celestijnenlaan 200A B-3001 Heverlee Belgium tel: +32 16 327544 e-mail: [EMAIL PROTECTED] url: http://www.cs.kuleuven.be/~toms/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Higher order randomness and the fat tails
Hi, Haskellers, This email is only remotely connected to this list. Recently I am doing some research on the fat tails (in fact, I simply bumped into it) on the stock market. I came up with an equation which I think solves the fat tails -- which is really the Levy stable distribution. During the complex arguments that led to the solution, I coined a term called Higher order randomness. This is inspired by the concept of higher order function in Haskell. * Higher order function operates on another function, instead on an ordinary value. So higher order randomness operates on another randomness, instead of directly producing the time series. The request is the following. I know there are many scientists on this list. If you or your colleagues happen to be involved or know any scenario that has fat tail distribution, can you let me know? I only solved one scenario -- numerically, not even analytically. Probability-wise, it is a dangerous thing to claim I solve the problem. So I'd like to collect as many scenarios as I can. It can be financial related, or in other fields of science. PS. I'd like to have some operational details and numbers. Not just a general statement like fat tail is observed in astronomy. Thanks and sorry for the spam, Steve ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] looking for examples of non-full Functional Dependencies
On 25 Apr 2008, at 14:20, Tom Schrijvers wrote: Prolog works under the assumption of a closed world. That's contrary to the open world view of regular type classes. So these aren't the intended semantics. By which I gather you mean the interpretation of :- as logical connective = rather than provability |-? My point, though, was to interpret class a b | a - b as a functional dependency b = b(a) rather than as D a b, D a c == b=c Thus trying to eliminate the use of =. Might that be exploited in the type theory context? Hans ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] looking for examples of non-full Functional Dependencies
On Fri, 25 Apr 2008, Hans Aberg wrote: On 25 Apr 2008, at 14:20, Tom Schrijvers wrote: Prolog works under the assumption of a closed world. That's contrary to the open world view of regular type classes. So these aren't the intended semantics. By which I gather you mean the interpretation of :- as logical connective = rather than provability |-? What I meant was that when Prolog says there are no more solutions, it doesn't know of any more. In realtiy it means there no more solutions under the closed world assumption. That means there could be more solutions if you haven't told Prolog everything. In this context, there may be more class instances (you simply haven't told the system yet). My point, though, was to interpret class a b | a - b as a functional dependency b = b(a) rather than as D a b, D a c == b=c Thus trying to eliminate the use of =. I don't follow you here. Tom -- Tom Schrijvers Department of Computer Science K.U. Leuven Celestijnenlaan 200A B-3001 Heverlee Belgium tel: +32 16 327544 e-mail: [EMAIL PROTECTED] url: http://www.cs.kuleuven.be/~toms/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] lookup tables style guidelines
On Apr 24, 2008, at 11:33 AM, Adrian Hey wrote: Also, if you're likely to be using union/intersection a lot you should know that Data.Map/Set are very slow for this because they use the not efficient hedge algorithm :-) OK, I'm going to bite here: What's the efficient algorithm for union on balanced trees, given that hedge union was chosen as being more efficient than naive alternatives (split and merge, repeated insertion)? My going hypothesis has been hedge union is an inefficient algorithm, except that it's better than all those other inefficient algorithms. For IntSet/IntMap of course the split structure of the tree is fixed (we can think of these as being compressed versions of a complete binary tree) and union and intersection are quite efficient. -Jan-Willem Maessen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Haskell Web server
Hi, What is the fastest way to set up a web server that can redirect requests to a haskell application and serve results returned by it? I need to demonstrate a simple visualization tool I have written for analytic tableaux on Monday and need something easy and simple. Best Regards, Cetin Sert ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] looking for examples of non-full Functional Dependencies
On 25 Apr 2008, at 15:38, Tom Schrijvers wrote: Prolog works under the assumption of a closed world. That's contrary to the open world view of regular type classes. So these aren't the intended semantics. By which I gather you mean the interpretation of :- as logical connective = rather than provability |-? What I meant was that when Prolog says there are no more solutions, it doesn't know of any more. In realtiy it means there no more solutions under the closed world assumption. That means there could be more solutions if you haven't told Prolog everything. In this context, there may be more class instances (you simply haven't told the system yet). I had no intention to deal with that problem. Just forget what Prolog says, and when it says there are no more solutions think of it as no more solutions determined. (If one interprets :- as provability |-, there needs to be additional axioms for the object theory, and if the theory is consistent, it becomes possible to prove that there are no more solutions.) My point, though, was to interpret class a b | a - b as a functional dependency b = b(a) rather than as D a b, D a c == b=c Thus trying to eliminate the use of =. I don't follow you here. I got ?- instance(d, l(A), l(B)). B = b(A) ?- instance(d, l(A), C). C = l(b(A)) so pattern-wise C and l(B) are the same. But I do not bother introduce an explicit operator =. So at least in this case, if say D [a] Int will be reject as Int is not of the feom l(_). If one has D [Int] [Char] and tries to define D [Int] [Float], the leads to trying to associate the implicit b(Int) with both Char and Float, which would be rejected. Hans ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell Web server
cetin.sert: Hi, What is the fastest way to set up a web server that can redirect requests to a haskell application and serve results returned by it? I need to demonstrate a simple visualization tool I have written for analytic tableaux on Monday and need something easy and simple. apache and cgi? -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Why doesn't GHC use the Hugs definition of splitAt to avoid traversing the first part of the list twice?
I've just been investigating a performance oddity in using splitAt on a long stream of random numbers. I don't understand why GHC appears to want to traverse the first part of the list twice. GHC seems to implement the splitAt function something like splitAt n xs = (take n xs, drop n xs) whereas Hugs is something like splitAt n (x : xs) = (x : xs', xs'') where (xs', xs'') = splitAt (n-1) xs which seems much more sensible to me. Wouldn't it be better to change GHC to the Hugs method? Have I misunderstood something? Richard. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] n00b circular dep question
Hi all, This is my first post, and I'm a n00b, so go easy if I breach protocol. :-) I have a graph where the nodes contain a number of fields of various types. The values for one of those fields -- call it Mass -- need to reside in a separate file from the main graph definition (this is for workflow reasons and is given to me as a constraint). In order to set the Mass for a particular node, I need access to the other fields of that node. The other constraint is that the graph needs to be available in an interpreter (eg GHCi). So, I have a circular dependency in my modules that I don't know how to resolve in Haskell. I went looking for the equivalent of #include which is how I would have solved this in C++. I'm sure there is a simple answer to this and I'm hoping this group can point me in the right direction. Many thanks, ogina ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] functional update
Thanks everyone, this is all good stuff. I did look at Clean and it looks like it has somewhat nicer record syntax... but it doesn't look like anything haskell couldn't do better if it one day got a real record system. As for the rest of Clean, I'm afraid that spending too much time with it will just make me wish for more features in haskell :) I'm going to experiment with the TH and FRef stuff. Maybe someday when we have a nice record system, these techniques can be standardized and integrated into the standard library. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] n00b circular dep question
On Apr 25, 2008, at 11:54 AM, Jennifer Miller wrote: I have a circular dependency in my modules that I don't know how to resolve in Haskell. I'm pretty sure that GHC will sort out those dependencies for you as long as you are exporting the correct things from each module. - Jake ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] n00b circular dep question
On Apr 25, 2008, at 9:54 AM, Jennifer Miller wrote: So, I have a circular dependency in my modules that I don't know how to resolve in Haskell. I went looking for the equivalent of #include which is how I would have solved this in C++. I'm sure there is a simple answer to this and I'm hoping this group can point me in the right direction. GHC supports CPP, so you could take the same approach in Haskell. # cat Main.hs data Foo = Foo { x :: Int, y :: Int } deriving Show foo = Foo { x = 2, #include y.hs } # cat y.hs y = (x foo) + 2 # ghci -cpp Main.hs GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help Loading package base ... linking ... done. [1 of 1] Compiling Main ( Main.hs, interpreted ) Ok, modules loaded: Main. *Main foo Foo {x = 2, y = 4} *Main Aaron ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] n00b circular dep question
Hello Jennifer, Friday, April 25, 2008, 8:54:42 PM, you wrote: So, I have a circular dependency in my modules that I don't know how to resolve in Haskell. 1. haskell standard allows circular deps between modules 2. ghc supports this part of standard in a rather awkward way - you need to generate .hs-boot files using some switch (look into docs). which is like .h files generated automatic from .cpp. once these files aregenerated, your circular deps will be ok -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] My try for a CoroutineT monad tranformer
Hi, (for those who follow planet.haskell.org this is old news, but I thought I’d tell the others) In http://www.joachim-breitner.de/blog/archives/291-Pausable-IO-actions-for-better-GUI-responsiveness.html I describe how I wrote a monad transformer that allows me to pause a computation from within by returning another computation that I can use to re-start the computation (or to throw it away if I want). I needed this for a long running drawing computation in a gtk2hs program that I want to pause at convenient points (to allow user interaction), and that I need to abort when what I’m drawing is not up-to-date anymore. The API basically consists of the function runCoroutineT :: Monad m = CoroutineT m () - m (Maybe (CoroutineT m ())) which runs the pausable computation, any Maybe returns Just the resume action, and the function pause :: Monad m = CoroutineT m () to be used inside the computation, which pauses it. I have put the complete module in the darcs repository that might later also contain the GUI program at http://darcs.nomeata.de/FrakView/ What do you think of CoroutineT? Could it have been easily implemented using the existing monad transformers? Is it useful enough so that it should be included somewhere, and where? Are there any problems with strictness or other tripping points that I have overlooked? Greetings, Joachim -- Joachim Breitner e-Mail: [EMAIL PROTECTED] Homepage: http://www.joachim-breitner.de ICQ#: 74513189 Jabber-ID: [EMAIL PROTECTED] signature.asc Description: Dies ist ein digital signierter Nachrichtenteil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] My try for a CoroutineT monad tranformer
I guess like minds think alike! See the very recent e-mail thread started by Ryan Ingram: http://thread.gmane.org/gmane.comp.lang.haskell.cafe/39155/focus=39159 Take a look at the code referenced in Luke Palmer's reply: http://luqui.org/git/?p=luqui-misc.git;a=blob;f=work/code/haskell/frp/Fregl/Suspend.hs A snippet follows: class (Monad m) = MonadSuspend v m | m - v where attempt :: m a - m (Either a (v - m a)) suspend :: m v newtype SuspendT v m a = SuspendT { runSuspendT :: m (Either a (v - SuspendT v m a)) } Your (Coroutine m a) appears to be isomorphic to (SuspendT () m a) [so Coroutine m () = SuspendT () m ()] Your runCoroutineT appears to be isomorphic to a specialization of runSuspendT: runSuspendT' :: SuspendT () m () - m (Either () (() - SuspendT () m ())) Here the () - a ~ a and Either () a ~ Maybe a Dan Joachim Breitner wrote: Hi, (for those who follow planet.haskell.org this is old news, but I thought I’d tell the others) In http://www.joachim-breitner.de/blog/archives/291-Pausable-IO-actions-for-better-GUI-responsiveness.html I describe how I wrote a monad transformer that allows me to pause a computation from within by returning another computation that I can use to re-start the computation (or to throw it away if I want). I needed this for a long running drawing computation in a gtk2hs program that I want to pause at convenient points (to allow user interaction), and that I need to abort when what I’m drawing is not up-to-date anymore. The API basically consists of the function runCoroutineT :: Monad m = CoroutineT m () - m (Maybe (CoroutineT m ())) which runs the pausable computation, any Maybe returns Just the resume action, and the function pause :: Monad m = CoroutineT m () to be used inside the computation, which pauses it. I have put the complete module in the darcs repository that might later also contain the GUI program at http://darcs.nomeata.de/FrakView/ What do you think of CoroutineT? Could it have been easily implemented using the existing monad transformers? Is it useful enough so that it should be included somewhere, and where? Are there any problems with strictness or other tripping points that I have overlooked? Greetings, Joachim ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] My try for a CoroutineT monad tranformer
Hi, Am Freitag, den 25.04.2008, 11:49 -0700 schrieb Dan Weston: I guess like minds think alike! See the very recent e-mail thread started by Ryan Ingram: http://thread.gmane.org/gmane.comp.lang.haskell.cafe/39155/focus=39159 Take a look at the code referenced in Luke Palmer's reply: http://luqui.org/git/?p=luqui-misc.git;a=blob;f=work/code/haskell/frp/Fregl/Suspend.hs A snippet follows: class (Monad m) = MonadSuspend v m | m - v where attempt :: m a - m (Either a (v - m a)) suspend :: m v newtype SuspendT v m a = SuspendT { runSuspendT :: m (Either a (v - SuspendT v m a)) } Your (Coroutine m a) appears to be isomorphic to (SuspendT () m a) [so Coroutine m () = SuspendT () m ()] Your runCoroutineT appears to be isomorphic to a specialization of runSuspendT: runSuspendT' :: SuspendT () m () - m (Either () (() - SuspendT () m ())) Here the () - a ~ a and Either () a ~ Maybe a You are quite right, it really is the same thing. The implementation behind runCoroutineT is not just a specialization, but the exact same thing (with Left and Right switched). I just put the specialization there because I had no need for a return value in my use case. And interesting how Ryan and me had the same thoughts on the same day. Maybe the April 24th should be considered Suspend You Monadic Action Day. Greetings, Joachim -- Joachim Breitner e-Mail: [EMAIL PROTECTED] Homepage: http://www.joachim-breitner.de ICQ#: 74513189 Jabber-ID: [EMAIL PROTECTED] signature.asc Description: Dies ist ein digital signierter Nachrichtenteil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] My try for a CoroutineT monad tranformer
Is there a Haskell Wiki page (or blog) on Monad Suspension? This looks like a nice paradigm that apfelmus points out can be used to considerably shorten your code, but only if the rest of us learn how! If not, maybe someone can be persuaded to write one? Dan Joachim Breitner wrote: Hi, Am Freitag, den 25.04.2008, 11:49 -0700 schrieb Dan Weston: I guess like minds think alike! See the very recent e-mail thread started by Ryan Ingram: http://thread.gmane.org/gmane.comp.lang.haskell.cafe/39155/focus=39159 Take a look at the code referenced in Luke Palmer's reply: http://luqui.org/git/?p=luqui-misc.git;a=blob;f=work/code/haskell/frp/Fregl/Suspend.hs A snippet follows: class (Monad m) = MonadSuspend v m | m - v where attempt :: m a - m (Either a (v - m a)) suspend :: m v newtype SuspendT v m a = SuspendT { runSuspendT :: m (Either a (v - SuspendT v m a)) } Your (Coroutine m a) appears to be isomorphic to (SuspendT () m a) [so Coroutine m () = SuspendT () m ()] Your runCoroutineT appears to be isomorphic to a specialization of runSuspendT: runSuspendT' :: SuspendT () m () - m (Either () (() - SuspendT () m ())) Here the () - a ~ a and Either () a ~ Maybe a You are quite right, it really is the same thing. The implementation behind runCoroutineT is not just a specialization, but the exact same thing (with Left and Right switched). I just put the specialization there because I had no need for a return value in my use case. And interesting how Ryan and me had the same thoughts on the same day. Maybe the April 24th should be considered Suspend You Monadic Action Day. Greetings, Joachim ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[2]: a faster, accumulating mapM (was Re: [Haskell-cafe] mapM vs mapM_ performance)
2008/4/25, Niklas Broberg [EMAIL PROTECTED]: Wow. A 10x slowdown for a very commonly used function that in 99.8% of all use cases has no need for the extra laziness at all. No wonder some people say Haskell is a toy language... A toy language that is still much faster than many currently popular languages so... Is Ruby/Python/... a toy too ? Still these numbers seems odd, there's probably something that don't optimize very well here. -- Jedaï ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: I hate Haskell's typeclasses
Jonathan Cast wrote: Type case is easy: genericShow :: Typeable a = a - String genericShow x = fromJust $ do s - cast x :: Maybe String return s `mplus` do n - cast x :: Maybe Int return (show n) `mplus` do return unknown This is a nice idiom I didn't know before. Definitely worth page on the wiki or two. Cheers Ben ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[2]: a faster, accumulating mapM (was Re: [Haskell-cafe] mapM vs mapM_ performance)
Wow. A 10x slowdown for a very commonly used function that in 99.8% of all use cases has no need for the extra laziness at all. No wonder some people say Haskell is a toy language... A toy language that is still much faster than many currently popular languages so... Is Ruby/Python/... a toy too ? I didn't say I agree, I most certainly don't. What I meant with my comment was that a slowdown of 10x, just to preserve laziness, is perfect fuel for those who claim that laziness is good in theory but bad in practice. And my alarm was more directed towards the fact that others seemed to find that perfectly acceptable. There are of course mitigating factors, in particular that mapM is rather uncommon over input lists that size, and for smaller list (say 50k instead of 500k) the slowdown isn't even half as bad (more like 2-3x). But I'm glad to hear that Simon is alarmed too. ;-) Cheers, /Niklas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] n00b circular dep question
On Fri, 25 Apr 2008, Jennifer Miller wrote: I have a graph where the nodes contain a number of fields of various types. The values for one of those fields -- call it Mass -- need to reside in a separate file from the main graph definition (this is for workflow reasons and is given to me as a constraint). In order to set the Mass for a particular node, I need access to the other fields of that node. The other constraint is that the graph needs to be available in an interpreter (eg GHCi). So, I have a circular dependency in my modules that I don't know how to resolve in Haskell. I went looking for the equivalent of #include which is how I would have solved this in C++. I'm sure there is a simple answer to this and I'm hoping this group can point me in the right direction. Sometimes circular module dependencies can be solved by using a type parameter. mutually recursive: module A where data LabeledTree label = LabeledTree label (Tree label) module B where data Tree label = Branch (LabeledTree label) (LabeledTree label) | Leaf no mutual recursion: module A where data LabeledTreeGen tree label = LabeledTree label (tree label) module B where type LabeledTree label = LabeledTreeGen Tree label data Tree label = Branch (LabeledTree label) (LabeledTree label) | Leaf ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] My try for a CoroutineT monad tranformer
On Fri, Apr 25, 2008 at 3:45 PM, Dan Weston [EMAIL PROTECTED] wrote: Is there a Haskell Wiki page (or blog) on Monad Suspension? This looks like a nice paradigm that apfelmus points out can be used to considerably shorten your code, but only if the rest of us learn how! There are a few papers which deal with resumption monads, which appear to be closely related. You can also express CoroutineT (or something very much like it) using a free monad. data Term f a = Var a | Branch (f (Term f a)) instance Functor f = Monad (Term f) where return = Var Var a = f = f a Branch as = f = Branch (fmap (= f) as) lift :: (Functor f) = f a - Term f a lift m = Branch (fmap Var m) runTerm :: (Monad m) = Term m () - m (Maybe (Term m ())) runTerm (Var ()) = return Nothing runTerm (Branch m) = fmap Just m pause :: (Monad m) = Term m () pause = Branch (return (Var ())) Note that runTerm and pause really only require Applicative. I believe Suspend can be implemented similarly. Note that SuspendT v m a is isomorphic to m (Term (ReaderT v m) a). -- Dave Menendez [EMAIL PROTECTED] http://www.eyrie.org/~zednenem/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Trying to build a stand-alone executable GLUT app with ghc, Windows XP
Problem summary Trying to build a stand-alone executable GLUT app with ghc, Windows XP Problem description I compile and link (without errors) a simple GLUT application under Windows XP. When I run it, XP pops an error window saying the app cannot start due to a missing glut32.dll. I want to do a static build to create a stand-alone executable GLUT app under Windows XP, without using DLL files, or placing any files in the Windows system dir. This is my first GUI code in Haskell, and I chose GLUT because it is a standard library. Following are some details. Thanks much for any advice. Source code -- Simple GLUT app to create a window module Main(main) where import Graphics.Rendering.OpenGL import Graphics.UI.GLUT main = do (progname, _) - getArgsAndInitialize createWindow Hello World mainLoop Compile/run Environment ghc-6.8.2 on a USB flashdrive under a non-admin Windows XP account ghc dir is not on C: E:\apps\ghc\ghc-6.8.2 XP shell used: cmd.exe shell path E:\ghcTestpath PATH=C:\WINDOWS\system32;C:\WINDOWS;E:\apps\ghc\ghc-6.8.2\bin;.\ ghc library path E:\ghcTestghc --print-libdir E:/apps/ghc/ghc-6.8.2 compile/link output E:\ghcTestghc --make x -package GLUT [1 of 1] Compiling Main ( x.hs, x.o ) Linking x.exe ... E:\ghcTest files (sizes in bytes) 186 x.hs 387 x.hi 3,184 x.o 498 x.exe.manifest 609,222 x.exe When application is run Error dialog window pops up window title a.exe - Unable To Locate Component window text The application has failed to start because glut32.dll was not found. Re-installing the application may fix this problem. No output in shell; no glut window is created. Other builds tried; same runtime error ghc --make x -package GLUT -static ghc -package GLUT x.hs -o x ghc --make x -package GLUT -LE:\apps\ghc\ghc-6.8.2\lib\GLUT-2.1.1.1 ghc --make x -LE:\apps\ghc\ghc-6.8.2\lib\GLUT-2.1.1.1 -- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Trying to build a stand-alone executable GLUT app with ghc, Windows XP
Perhaps try: $ ghc --make -static -optl-static -lpath to libHSGLUT.a here x.hs The -optl-static passes the '-static' argument to ld so it will link statically; you may also need a copy of a compatable GLUT library in .a format on your windows machine which should be linked in with -l as well (where you can get this, I do not know.) -- It was in the days of the rains that their prayers went up, not from the fingering of knotted prayer cords or the spinning of prayer wheels, but from the great pray-machine in the monastery of Ratri, goddess of the Night. Roger Zelazny ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Trying to build a stand-alone executable GLUT app with ghc, Windows XP
Google download glut32.dll and pull that file down and put it in the directory with your executable. I'd attach it myself, but gmail won't let me. I use that all the time, though. 2008/4/25 Peter Schmitz [EMAIL PROTECTED]: Problem summary Trying to build a stand-alone executable GLUT app with ghc, Windows XP Problem description I compile and link (without errors) a simple GLUT application under Windows XP. When I run it, XP pops an error window saying the app cannot start due to a missing glut32.dll. I want to do a static build to create a stand-alone executable GLUT app under Windows XP, without using DLL files, or placing any files in the Windows system dir. This is my first GUI code in Haskell, and I chose GLUT because it is a standard library. Following are some details. Thanks much for any advice. Source code -- Simple GLUT app to create a window module Main(main) where import Graphics.Rendering.OpenGL import Graphics.UI.GLUT main = do (progname, _) - getArgsAndInitialize createWindow Hello World mainLoop Compile/run Environment ghc-6.8.2 on a USB flashdrive under a non-admin Windows XP account ghc dir is not on C: E:\apps\ghc\ghc-6.8.2 XP shell used: cmd.exe shell path E:\ghcTestpath PATH=C:\WINDOWS\system32;C:\WINDOWS;E:\apps\ghc\ghc-6.8.2\bin;.\ ghc library path E:\ghcTestghc --print-libdir E:/apps/ghc/ghc-6.8.2 compile/link output E:\ghcTestghc --make x -package GLUT [1 of 1] Compiling Main ( x.hs, x.o ) Linking x.exe ... E:\ghcTest files (sizes in bytes) 186 x.hs 387 x.hi 3,184 x.o 498 x.exe.manifest 609,222 x.exe When application is run Error dialog window pops up window title a.exe - Unable To Locate Component window text The application has failed to start because glut32.dll was not found. Re-installing the application may fix this problem. No output in shell; no glut window is created. Other builds tried; same runtime error ghc --make x -package GLUT -static ghc -package GLUT x.hs -o x ghc --make x -package GLUT -LE:\apps\ghc\ghc-6.8.2\lib\GLUT-2.1.1.1 ghc --make x -LE:\apps\ghc\ghc-6.8.2\lib\GLUT-2.1.1.1 -- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- I try to take things like a crow; war and chaos don't always ruin a picnic, they just mean you have to be careful what you swallow. -- Jessica Edwards ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] n00b circular dep question
Thanks for the suggestions. The #include worked but I will look for ways to remove the circular dependency altogether. Jennifer On Friday, April 25, 2008, at 02:48PM, Henning Thielemann [EMAIL PROTECTED] wrote: On Fri, 25 Apr 2008, Jennifer Miller wrote: I have a graph where the nodes contain a number of fields of various types. The values for one of those fields -- call it Mass -- need to reside in a separate file from the main graph definition (this is for workflow reasons and is given to me as a constraint). In order to set the Mass for a particular node, I need access to the other fields of that node. The other constraint is that the graph needs to be available in an interpreter (eg GHCi). So, I have a circular dependency in my modules that I don't know how to resolve in Haskell. I went looking for the equivalent of #include which is how I would have solved this in C++. I'm sure there is a simple answer to this and I'm hoping this group can point me in the right direction. Sometimes circular module dependencies can be solved by using a type parameter. mutually recursive: module A where data LabeledTree label = LabeledTree label (Tree label) module B where data Tree label = Branch (LabeledTree label) (LabeledTree label) | Leaf no mutual recursion: module A where data LabeledTreeGen tree label = LabeledTree label (tree label) module B where type LabeledTree label = LabeledTreeGen Tree label data Tree label = Branch (LabeledTree label) (LabeledTree label) | Leaf ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe