Re: [Haskell-cafe] learning advanced haskell
Thanks for the great responses. My haskell-learning todo list is refreshed and renewed :) I would point out, though, that had I followed a Learn when needed philosophy more broadly I would never have come to Haskell or even functional programming in general. Aran On Mon, Jun 14, 2010 at 12:33 PM, Andrew Coppin andrewcop...@btinternet.com wrote: John Lato wrote: I sort of agree with this, with some very large caveats. Well, yes. If you don't know what a feature does, then you won't know that it solves the problem you have. However, there's a lot to be said for both intellectual curiosity and learning for the sake of knowledge. Just because you may never need to use a feature doesn't mean you shouldn't be able to understand it. There is that. However, in my experience, most of the advanced techniques tend to be described in language beyond my comprehension. (And most examples seem overly complex - although maybe that's just a reflection of the fact that simple problems don't require sophisticated techniques in the first place.) Having a specific problem to solve can be quite helpful. Unlike an example, you already understand what the problem is, and why it can't easily be solved any other way. ___ 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] learning advanced haskell
Hi Cafe, I've been doing Haskell for a few months, and I've written some mid-sized programs and many small ones. I've read lots of documentation and many papers, but I'm having difficulty making the jump into some of the advanced concepts I've read about. How do people build intuitions for things like RankNTypes and arrows? (Is the answer Get a PhD in type theory?) Normally I learn by coding up little exercise programs, but for these I don't have good intuitions about the kinds of toy problems I ought to try to solve that would lead me to understand these tools better. For systems like Template Haskell and SYB, I have difficulty judging when I should use Haskell's simpler built-in semantic abstractions like functions and typeclasses and when I should look to these other mechanisms. I understand the motivation for other concepts like iteratees, zippers and functional reactive programming, but there seem to be few entry-level resources. John Lato's recent Iteratee article is a notable exception*. Hints? Tips? Here's how I did it? ___ is a great program to write to get to learn __? Thanks in advance, Aran * Even in this article, he busted out (=). And it appears that the iteratee library's actual design is more sophisticated than the design presented. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: Monad.Reader Issue 16
If I notice a new library version I'll be happy to make the requisite changes myself, too :) Aran On Fri, May 14, 2010 at 9:30 AM, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: Brent Yorgey byor...@seas.upenn.edu writes: On Fri, May 14, 2010 at 02:37:19PM +1000, Ivan Miljenovic wrote: On 13 May 2010 04:12, Brent Yorgey byor...@seas.upenn.edu wrote: * Demand More of Your Automata by Aran Donohue Great, because of Aran I now can't change some of the bits of API in graphviz without making the code examples in his article break... If/when you change the API, just send me a darcs patch fixing Aran's code examples, and no one will ever be the wiser. This is the advantage of an electronic-only publication. ;) Works for me! So, I take it TMR now has minor versions as well? ;-) -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ 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] debugging a hanging program: where to start?
Thanks folks! Forward progress is made... Unfortunately, programs don't seem to write out their threadscope event logs until they terminate, and mine hangs until I kill it, so I can't get at the event log. Tracing has taught me that before the hang-cause, my program splits its time in pthread_cond_wait in two different threads, and select in a third. After the hang, it no longer calls select and one of those pthread_cond_waits in the other. In the version without -threaded that doesn't hang, it never does any pthread_cond_wait and never misses the select. Now to go figure out what impossible condition it's waiting on, I guess. Aran On Thu, May 13, 2010 at 2:13 AM, Ketil Malde ke...@malde.org wrote: Aran Donohue aran.dono...@gmail.com writes: I have a program that I can reliably cause to hang. It's concurrent using STM, so I think it could be a deadlock or related issue. I also do some IO, so I think it could be blocking in a system call. If it's the latter, 'strace' might help you. Use 'strace -p PID' to attach to a running process. Similarly, 'ltrace' can trace library calls (but probably less useful in this context?) (This is on Linux, but other OSes are likely to have similar tools.) -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] debugging a hanging program: where to start?
I have an accept-loop: do (conn, _saddr) - accept sock forkIO $ initializeConnection conn Which allocates memory iff accept allocates, I suppose. To test the theory, is there a way I can force an allocation that won't get optimized away? According to the old print-statement debugging method, it is accept that causes the problem. The accept is the last thing that happens before the hang. I created a test program to hammer on accept. {-# LANGUAGE OverloadedStrings #-} module Main where import Control.Concurrent (forkIO) import Control.Concurrent.MVar import Control.Monad (forever, liftM) import Network (listenOn, withSocketsDo, PortID(..)) import Network.BSD (getProtocolNumber) import Network.Socket (Family(..), SockAddr(..), SocketType(..), Socket(..), accept, connect, inet_addr, socket, sClose) import Network.Socket.ByteString import Data.ByteString.Char8 () import System.Environment (getArgs) import System.IO (stdout, hFlush) port = 8080 main = do args - getArgs if length args 1 || (head args /= client head args /= server) then putStrLn say client or server else withSocketsDo $ case head args of client - client server - server client = do putStrLn Client mode tcp - getProtocolNumber tcp forever $ do sock - socket AF_INET Stream tcp localhost - inet_addr 127.0.0.1 putStr Making a connection... connect sock (SockAddrInet port localhost) send sock a _ - recv sock 1 sClose sock putStrLn done client connection server = do putStrLn Server mode sock - listenOn (PortNumber port) count - newMVar 0 forever $ do count' - modifyMVar count (\c - return (c+1,c+1)) putStr $ (show count') ++ About to accept... (conn, _saddr) - accept sock putStrLn accepted. hFlush stdout forkIO $ handleServerConnection conn count' handleServerConnection conn count = do putStr $ (show count) ++ Handling a server connection... rd - recv conn 1 send conn a sClose conn putStrLn done server connection. hFlush stdout While it doesn't seem to fully hang, it does go through mysterious hiccups in which an accept call takes many seconds to return. I'm on Mac OS X Snow Leopard, ghc 6.12.1. I'm not quite sure how I ought to proceed. I'm still very open to debugging tools and techniques I could use to approach the problem! Aran On Thu, May 13, 2010 at 12:10 PM, Jason Dagit da...@codersbase.com wrote: On Thu, May 13, 2010 at 5:53 AM, Aran Donohue aran.dono...@gmail.comwrote: Thanks folks! Forward progress is made... Unfortunately, programs don't seem to write out their threadscope event logs until they terminate, and mine hangs until I kill it, so I can't get at the event log. Tracing has taught me that before the hang-cause, my program splits its time in pthread_cond_wait in two different threads, and select in a third. After the hang, it no longer calls select and one of those pthread_cond_waits in the other. In the version without -threaded that doesn't hang, it never does any pthread_cond_wait and never misses the select. Now to go figure out what impossible condition it's waiting on, I guess. The select sounds like the IO manager thread (a thread in the RTS not your code). Is it possible that one of your threads does work but never allocates memory? I've heard in some cases that can lead to starvation. I think the explanation was that thread switching happens on allocation? Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Concurrent Rings in Erlang and Haskell: A Haskell answer to Joe Armstrong's Erlang Challenge
I wrote this a couple of weeks ago and forgot about it. I thought it might be of interest to some on this list: http://workshop.arandonohue.com/ring/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] debugging a hanging program: where to start?
The memory allocation / threadDelay 0 has no effect, so it isn't *that* bug. I've noticed something new, too. I have some other sleeping threads in the system. When those sleep for short threadDelays compared to the frequency of accepts, the problem is accelerated. However when the other threads have threadDelays that go longer than the accept frequency, the problem doesn't seem to occur. That is, it seems that having pending thread-awakenings prevents the issue. I'm stumped! On Thu, May 13, 2010 at 3:51 PM, Daniel Fischer daniel.is.fisc...@web.dewrote: On Thursday 13 May 2010 21:28:21, Aran Donohue wrote: I have an accept-loop: do (conn, _saddr) - accept sock forkIO $ initializeConnection conn Which allocates memory iff accept allocates, I suppose. To test the theory, is there a way I can force an allocation that won't get optimized away? t - getCPUTime let n = t `rem` 12345 s = sum [1 .. n] s `seq` doSomething could work. Another option is to insert a threadDelay 0 in your forever loops to enable context-switching if some other thread is runnable. I'm not quite sure how I ought to proceed. I'm still very open to debugging tools and techniques I could use to approach the problem! Aran ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] debugging a hanging program: where to start?
Hi Cafe, I have a program that I can reliably cause to hang. It's concurrent using STM, so I think it could be a deadlock or related issue. I also do some IO, so I think it could be blocking in a system call. It only hangs when compiled with -threaded. I tried building with -prof, and running with -hc -xt to get a clue where in which function it is stopping, but the resulting profile didn't help much. I've started sprinkling print statements, but I thought I'd trawl for better tips and techniques. Any suggestions on approaches? Thanks, Aran ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] are forkIO threads event-driven?
Thanks for the excellent links, that's exactly what I wanted. It's interesting that they've chosen not to base the new work on libevent. As an aside, I really don't think that the case study should be given any more linkjuice as a response to GHC/Haskell IO concurrency questions. While it's a wonderful tutorial on the programming technique side, it's a decade old and was written at a time when serving 4000 requests was a reasonable benchmark. These days modern web servers are moving more and more toward handling tens of thousands of concurrent held-open *connections*---a different metric and a different scale. Cheers, Aran On Fri, Apr 30, 2010 at 2:51 AM, Don Stewart d...@galois.com wrote: bulat.ziganshin: Hello Aran, Friday, April 30, 2010, 2:26:20 AM, you wrote: In GHC, if a thread spawned by forkIO blocks on some network or disk IO, is the threading system smart enough not to wake the thread afaik, yes. it's controlled by special i/o thread that multiplexes all i/o done via stdlibs. but ghc i/o manager can't use epoll/kqueue so it's appropriate only for small (or medium?) servers Look at the recent work on the event library and replacing the IO manager. http://www.serpentine.com/blog/2010/01/22/new-ghc-io-manager-first-benchmark-numbers/ There's much more background on the new code here, http://www.serpentine.com/blog/2009/12/17/making-ghcs-io-manager-more-scalable/ and some nice benchmarks http://blog.johantibell.com/2010/01/scalable-timeout-support-for-ghcs-io.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] are forkIO threads event-driven?
Hi Cafe, In GHC, if a thread spawned by forkIO blocks on some network or disk IO, is the threading system smart enough not to wake the thread until an IO event occurs on its input/output? The Control.Concurrent documentation doesn't specify, and the previous discussions I could find on this topic are out-of-date. There is a years-old GHC ticket, too, recently revived[2]. Put another way, is it possible yet to use forkIO for making a server to handle tens of thousands of concurrent network connections? If not, what is the best current Haskell/GHC way? Thanks, Aran [1] http://www.monkey.org/~provos/libevent/ [2] http://hackage.haskell.org/trac/ghc/ticket/635 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Difficulties installing LLVM bindings
To actually build the examples, I also needed to remove references to the addCondPropagation optimization pass. I don't know why. I attached the darcs patch I'm using. Aran On Sat, Apr 10, 2010 at 4:42 PM, Aran Donohue aran.dono...@gmail.comwrote: UNIVERSAL=1 worked for me too. Is there a way for cabal install to detect if LLVM wasn't built with this required flag and give a more informative error message? Aran On Sat, Apr 10, 2010 at 2:28 AM, Max Bolingbroke batterseapo...@hotmail.com wrote: On 10 April 2010 03:18, Aran Donohue aran.dono...@gmail.com wrote: problems with ghc-pkg. I think we need to rebuild LLVM forcing 32-mode, but I haven't yet found the results of this. I'd love to hear what you did if you manage to get it going and compile programs. My LLVM checkout was still recompiling when I sent that email, but it's now finished and it fixed the problem. All you need to do is compile LLVM as follows: $ UNIVERSAL=1 make Then make install the result. That made the LLVM bindings configure and compile fine for me. Cheers, Max addCondPropRemoved.dpatch Description: Binary data ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Difficulties installing LLVM bindings
UNIVERSAL=1 worked for me too. Is there a way for cabal install to detect if LLVM wasn't built with this required flag and give a more informative error message? Aran On Sat, Apr 10, 2010 at 2:28 AM, Max Bolingbroke batterseapo...@hotmail.com wrote: On 10 April 2010 03:18, Aran Donohue aran.dono...@gmail.com wrote: problems with ghc-pkg. I think we need to rebuild LLVM forcing 32-mode, but I haven't yet found the results of this. I'd love to hear what you did if you manage to get it going and compile programs. My LLVM checkout was still recompiling when I sent that email, but it's now finished and it fixed the problem. All you need to do is compile LLVM as follows: $ UNIVERSAL=1 make Then make install the result. That made the LLVM bindings configure and compile fine for me. Cheers, Max ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Difficulties installing LLVM bindings
Hi Haskell-Cafe, I can't get the LLVM bindings for Haskell to install. Does anyone know what I might need to do? Has anyone seen this error before? Here's the problem: (Installing from latest darcs source) llvm-haskell aran$ cabal install Resolving dependencies... ...snip... checking for unistd.h... yes checking llvm-c/Core.h usability... yes checking llvm-c/Core.h presence... yes checking for llvm-c/Core.h... yes checking for LLVMModuleCreateWithName in -lLLVMCore... no configure: error: could not find LLVM C bindings cabal: Error: some packages failed to install: llvm-0.7.0.1 failed during the configure step. The exception was: exit: ExitFailure 1 I've got the latest LLVM (from source) installed using the default sudo make install, i.e. into /usr/local. Using cabal install --configure-option --with-llvm-prefix=/usr/local doesn't change the result. LLVM is indeed based in /usr/local. The binaries are in /usr/local/bin/, libLLVM*.a is in /usr/local/lib, etc. Google just shows that this error has cropped up a couple times before. I tried manually disabling the check in the configure script but then generating code fails with massive run-time errors that look like link problems. I'm on an up-to-date Snow Leopard, using the latest llvm bindings from darcs, cabal-install 0.8.0, cabal library 1.8.0.2, ghc 6.12.1, and LLVM from svn. LLVM works fine from C++, at least. I worked through the Kaleidoscope tutorial and a few hand-coded .ll files without a hitch. Have you seen anything like this before? Any tips or things to try? I can't think of what magic setting I'm missing. Thanks, Aran ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Difficulties installing LLVM bindings
Thomas---The new Mac patches have been integrated in the version I'm using, according to the darcs log. Thanks Felipe---indeed, llvm-config is on the path. Max---I had the same realization about config.log. I managed to get past it by forcing the Haskell-LLVM build into 64-bit mode, but that led to new problems with ghc-pkg. I think we need to rebuild LLVM forcing 32-mode, but I haven't yet found the results of this. I'd love to hear what you did if you manage to get it going and compile programs. Thanks, Aran On Fri, Apr 9, 2010 at 7:07 PM, Thomas Schilling nomin...@googlemail.comwrote: Bryan said a while ago that Manuel Chakravarty had some Mac related patches for LLVM, don't know if they have been integrated yet. On 9 April 2010 23:11, Max Bolingbroke batterseapo...@hotmail.com wrote: On 9 April 2010 18:38, Aran Donohue aran.dono...@gmail.com wrote: Hi Haskell-Cafe, I can't get the LLVM bindings for Haskell to install. Does anyone know what I might need to do? Has anyone seen this error before? Here's the problem: (Installing from latest darcs source) I just tried this on my Mac and got the same problem. The problem is described in config.log: configure:3659: g++ -o conftest -g -O2 -I/usr/local/include -D_DEBUG -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -m32 -L/usr/local/lib -lpthread -lmconftest.c -lLLVMCore -lLLVMSupport -lLLVMSystem 5 ld: warning: in /usr/local/lib/libLLVMCore.a, file is not of required architecture ld: warning: in /usr/local/lib/libLLVMSupport.a, file is not of required architecture ld: warning: in /usr/local/lib/libLLVMSystem.a, file is not of required architecture Undefined symbols: _LLVMModuleCreateWithName, referenced from: _main in cc5D6X0z.o So perhaps LLVM needs to be built universal or something? Cheers, Max ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Push the envelope. Watch it bend. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] a beginner question: decorate-op-undecorate
One way or the other, this has been a very productive question for getting good pointers on what to read about next... Thanks again. Aran On Sat, Feb 6, 2010 at 8:18 AM, Stephen Tetley stephen.tet...@gmail.comwrote: Hi John I'm not sure about making Binding polymorphic to get Functor, Traversable, Foldable... While I think you're correct that partitionEithers might not be a useful example to draw from in this case, I'd assume that Binding would be part of a larger syntax-tree, thus there might not be a appropriate single leaf to make the tree polymorphic on. Felipe Lessa's point - to use Uniplate or one of the Generics packages - might be a better candidate for implementing traversals. Best wishes Stephen ___ 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] a beginner question: decorate-op-undecorate
Hi Haskell-Cafe, Consider a data type such as data Binding = Binding Var (Either Value [Value]) representing a variable bound either to a fixed value or that has a list of possible values. I'd like to perform an operation on say, the fixed-value members of a list of bindings. Data.Either has partitionEithers---I'd essentially like to use partitionEithers, but in a way that it peeks into the value field of the binding. For the sake of argument, let's say I can't or can't modify Binding to move the Either to the outside. What would be an idiomatic Haskell way to accomplish this? Currently I've got liftedPartitionEithers :: [a] - (a - Either b c) - ([a], [a]) which is my own version of partitionEithers that calls a selector first. Another option would be to map each Binding to a new datatype that has the Either on the outside, use partitionEithers, and map back. Thanks, Aran ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] a beginner question: decorate-op-undecorate
Thanks for the helpful thoughts. I guess I was just reaching for a Haskell version of a programming pattern from other languages---dealing with baggage if you will. Thanks, Aran On Fri, Feb 5, 2010 at 7:24 PM, Luke Palmer lrpal...@gmail.com wrote: On Fri, Feb 5, 2010 at 10:34 AM, Aran Donohue aran.dono...@gmail.com wrote: What would be an idiomatic Haskell way to accomplish this? Currently I've got liftedPartitionEithers :: [a] - (a - Either b c) - ([a], [a]) which is my own version of partitionEithers that calls a selector first. Since you are not using b or c anywhere else, the only thing you care about in that Either is whether it is Left or Right. Which makes it seem much more like a Bool. After this conversion, I can hoogle for your signature. http://haskell.org/hoogle/?hoogle=[a]+-%3E+%28a+-%3E+Bool%29+-%3E+%28[a]%2C[a]%29 Which gives, among other things, Data.List.partition :: (a - Bool) - [a] - ([a],[a]). Without more details about the precise thing you want to accomplish, I don't know what else to say. Many idioms are about the details of the problem, even down to argument order. Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe