From gue.schmidt at web.de Sat Aug 1 00:15:31 2009 From: gue.schmidt at web.de (=?iso-8859-15?Q?G=FCnther_Schmidt?=) Date: Fri Jul 31 23:56:43 2009 Subject: [Haskell-cafe] Database written in Haskell? Message-ID: Hi, is there an SQL database written in Haskell like HSQLDB which is written in Java? G?nther From bulat.ziganshin at gmail.com Sat Aug 1 00:28:23 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sat Aug 1 00:09:50 2009 Subject: [Haskell-cafe] why does the binary library require so much memory? In-Reply-To: <87ljm45ts9.wl%jeremy@n-heptane.com> References: <87prbg607u.wl%jeremy@n-heptane.com> <20090731212730.GX809@whirlpool.galois.com> <87ocr05y27.wl%jeremy@n-heptane.com> <20090731214903.GA809@whirlpool.galois.com> <87my6k5vlo.wl%jeremy@n-heptane.com> <20090731224349.GB3854@whirlpool.galois.com> <87ljm45ts9.wl%jeremy@n-heptane.com> Message-ID: <266568198.20090801082823@gmail.com> Hello Jeremy, Saturday, August 1, 2009, 3:15:02 AM, you wrote: > So, the desired experience would be: > 1. A program starts running and populates an IxSet. At this point in > time n MB of RAM are being used. > 2. We use Binary to snapshot the entire IxSet to disk. Since encode > outputs an lazy ByteString, I would expect only a modest amount of > additional memory to be required during this process. what really happens here: while you expect that intermediate list produced lazily (it's haskell, after all!) and immediately stored to disk in chunks, "length l" in Binary instance forces entire list to be calculated before producing any output it should be easy to fix: if your IxSet have builtin elements counter or way to measure it without allocating tons of memory, you just need to make something like the following instance: instance Binary a => Binary (IxSet a) where put l = put (IxSet.length l) >> mapM_ put l get = fmap list_to_IxSet get -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From andrewcoppin at btinternet.com Sat Aug 1 04:46:01 2009 From: andrewcoppin at btinternet.com (Andrew Coppin) Date: Sat Aug 1 04:27:01 2009 Subject: [Haskell-cafe] ANNOUNCE: The Haskell Platform 2009.2.0.2 In-Reply-To: <20090801000107.GM3854@whirlpool.galois.com> References: <20090801000107.GM3854@whirlpool.galois.com> Message-ID: <4A7400C9.4030206@btinternet.com> Don Stewart wrote: > We're pleased to announce the third release of the Haskell Platform: a > single, standard Haskell distribution for everyone. > > The specification, along with installers (including Windows and Unix > installers for a full Haskell environment) are available. > > Download the Haskell Platform 2009.2.0.2: > > http://hackage.haskell.org/platform/ > Maybe I'm being dense... Is there somewhere which lists what's changed from the last release? From bertram.felgenhauer at googlemail.com Sat Aug 1 09:31:07 2009 From: bertram.felgenhauer at googlemail.com (Bertram Felgenhauer) Date: Sat Aug 1 09:12:10 2009 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: OpenGL 2.3.0.0 In-Reply-To: <351ff25e0907301723m479cd3b6yb5090067c6d14a23@mail.gmail.com> References: <200907291826.30307.Sven.Panne@aedion.de> <20090729165525.GA23329@kira.casa> <351ff25e0907291817i2391f592qff2441deb0bfaf7d@mail.gmail.com> <351ff25e0907291824g68de211id52c58939c2d275@mail.gmail.com> <20090730014703.GA19555@kira.casa> <351ff25e0907301631h2ab2201cwf854ce294ada1d83@mail.gmail.com> <351ff25e0907301723m479cd3b6yb5090067c6d14a23@mail.gmail.com> Message-ID: <4a74439f.0a1ad00a.551b.2069@mx.google.com> Rafael Gustavo da Cunha Pereira Pinto wrote: > Sorry for all this annoyance, but I was starting to study those libraries > (OpenGL, GLUT and GLFW) using Haskell and the update broke some of my code. > > Here is a patch that makes it compile, but then it breaks all code developed > for GLFW-0.3, as all Floats need to be changed to CFloat. > > --- GLFW-0.3/Graphics/UI/GLFW.hs 2008-01-15 20:23:18.000000000 -0200 > +++ GLFW.hs 2009-07-30 21:09:55.000000000 -0300 > @@ -517,11 +517,11 @@ > _GLFW_INFINITY = 100000.0 :: Double > > -- Callback function type > -type GLFWwindowsizefun = Int32 -> Int32 -> IO () > +type GLFWwindowsizefun = CInt -> CInt -> IO () [snip] You should use the type aliases GLint, GLfloat, etc. HTH, Bertram From p.f.moore at gmail.com Sat Aug 1 09:44:39 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Sat Aug 1 09:25:39 2009 Subject: [Haskell-cafe] Efficient functional idiom for histogram In-Reply-To: <79990c6b0907311539t545c650bw521a437324c58922@mail.gmail.com> References: <79990c6b0907311339o17930eaej193b39e176f601a4@mail.gmail.com> <87y6q4lgn9.fsf@gregorycollins.net> <79990c6b0907311539t545c650bw521a437324c58922@mail.gmail.com> Message-ID: <79990c6b0908010644w108ea9ddh9bb5b1d262d2c2ed@mail.gmail.com> 2009/7/31 Paul Moore : > 2009/7/31 Gregory Collins : >> Paul Moore writes: >> >>> How would I efficiently write a function in Haskell to count >>> occurrences of unique elements in a (potentially very large) list? For >>> example, given the list [1,2,3,4,5,3,4,2,4] I would like the output >>> [[1,1], [2,2], [3,2], [4,3], [5,1]] (or some equivalent >>> representation). >> >> ? ?import qualified Data.Map as Map >> ? ?import ? ? ? ? ? Data.Map (Map) >> >> ? ?histogram :: Ord a => [a] -> [(a,Int)] >> ? ?histogram = Map.assocs . foldl f Map.empty >> ? ? ?where >> ? ? ? ?f m k = Map.insertWith (+) k 1 m > > Right. I see how that works, and can work out how to think about this > sort of thing from your example. Thanks very much. > > BTW, I did know that Haskell had an efficient map implementation, I > just wasn't sure how to use it "functionally" - I probably should have > searched a bit harder for examples before posting. Thanks for the help > in any case. Hmm, I'm obviously still mucking up the performance somehow. My full program (still a toy, but a step on the way to what I'm aiming at) is as follows. It's rolling 3 6-sided dice 100000 times, and printing a summary of the results. import System.Random import qualified Data.Map as Map import Data.Map (Map) import Data.List dice :: Int -> Int -> IO Int dice 0 n = return 0 dice m n = do total <- dice (m - 1) n roll <- randomRIO (1, n) return (total + roll) simulate count m n = do mapM (dice m) (replicate count n) histogram :: Ord a => [a] -> [(a,Int)] histogram = Map.assocs . foldl f Map.empty where f m k = Map.insertWith (+) k 1 m simulation = do lst <- simulate 100000 3 6 return (histogram lst) main = do s <- simulation putStrLn (show s) When compiled, this takes over twice as long as a naively implemented Python program. What am I doing wrong here? I'd have expected compiled Haskell to be faster than interpreted Python, so obviously my approach is wrong. I'm expecting the answer to be that I've got unnecessary laziness - which is fine, but ultimately my interest is in ease of expression and performance combined, so I'm looking for beginner-level improvements rather than subtle advanced techniques like unboxing. Thanks, Paul. PS I know my code is probably fairly clumsy - I'd appreciate style suggestions, but my main interest here is whether a beginner, with a broad programming background, a basic understanding of Haskell, and access to Google, put together a clear, efficient, program (ie, the case where my usual scripting language is too slow and I want to knock something up quickly in a high-level, high-performance language). From p3k at iki.fi Sat Aug 1 10:58:15 2009 From: p3k at iki.fi (Pekka Karjalainen) Date: Sat Aug 1 10:39:13 2009 Subject: [Haskell-cafe] Efficient functional idiom for histogram In-Reply-To: <79990c6b0908010644w108ea9ddh9bb5b1d262d2c2ed@mail.gmail.com> References: <79990c6b0907311339o17930eaej193b39e176f601a4@mail.gmail.com> <87y6q4lgn9.fsf@gregorycollins.net> <79990c6b0907311539t545c650bw521a437324c58922@mail.gmail.com> <79990c6b0908010644w108ea9ddh9bb5b1d262d2c2ed@mail.gmail.com> Message-ID: <233457100908010758t19467655r203d3e321163975f@mail.gmail.com> On Sat, Aug 1, 2009 at 4:44 PM, Paul Moore wrote: > PS I know my code is probably fairly clumsy - I'd appreciate style > suggestions, but my main interest here is whether a beginner, with a > broad programming background, a basic understanding of Haskell, and > access to Google, put together a clear, efficient, program (ie, the > case where my usual scripting language is too slow and I want to knock > something up quickly in a high-level, high-performance language). Here is one way to rewrite your program. It improved the speed somewhat for me. I timed both programs on my computer. I suppose one could try using an array for calculating the histogram as well, but I only tried the simples thing here. I hope someone can weigh in with a more thorough analysis. Please note how I've avoided including the IO Monad in some type signatures by extracting the data from it locally (with <-). It is quite possible to apply the histogram function to the data before going through the IO Monad as well, but it doesn't appear to change the execution speed much here. Caveat: My testing wasn't extensive. I just compiled with -O and timed the programs a couple of times. import System.Random import qualified Data.Map as Map import Data.Map (Map) import Data.List diceRolls :: Int -> IO [Int] diceRolls highVal = do generator <- getStdGen return (randomRs (1, highVal) generator) groupDice :: Int -> [Int] -> [[Int]] groupDice chunk rolls = map (take chunk) $ iterate (drop chunk) rolls simulate :: Int -> Int -> Int -> IO [Int] simulate count m n = do rolls <- diceRolls n let sums = map sum $ groupDice m rolls return (take count sums) histogram :: Ord a => [a] -> [(a,Int)] histogram = Map.assocs . foldl f Map.empty where f m k = Map.insertWith (+) k 1 m simulation = do lst <- simulate 100000 3 6 return (histogram $ lst) main = do s <- simulation putStrLn (show s) From mads_lindstroem at yahoo.dk Sat Aug 1 13:06:05 2009 From: mads_lindstroem at yahoo.dk (Mads =?ISO-8859-1?Q?Lindstr=F8m?=) Date: Sat Aug 1 12:47:02 2009 Subject: [Haskell-cafe] Possible bug in Data.IP (network-data package) Message-ID: <1249146365.4643.19.camel@supermule.opasia.dk> Hi The network-data (version 0.0.2) [1] contains the module Data.IP. This modules encapsulates IPv4 headers. The Data.IP modules contains the type IPv4Header: data IPv4Header = IPv4Hdr { hdrLength :: Int , version :: Int , tos :: Int , payloadLength :: Int ... The code to turn IPv4 packages into IPv4Heder looks like [2]: instance Binary IPv4Header where put (IPv4Hdr ihl ver tos len id flags off ttl prot csum src dst) = do pW8 $ (ihl .&. 0xF) .|. (ver `shiftL` 4 .&. 0xF0) pW8 tos pW16 len pW16 id let offFlags = (off .&. 0x1FFF) .|. fromIntegral (fromEnum flags `shiftL` 13) pW16 offFlags pW8 ttl pW8 prot put csum put src put dst That is, the payload length is the 16-31'th bit of the IPv4 header. This field is according to [3] and [4] referred to as "total length" - not "payload length". The total length include both the length of the data and the header. When I read the term "payload length" I first thought it referred to the length of the package excluding the header. So I am right to see this as a bug in network-data ? Regards, Mads Lindstr?m [1] http://hackage.haskell.org/package/network-data [2] http://hackage.haskell.org/packages/archive/network-data/0.0.2/doc/html/src/Data-IP.html [3] http://tools.ietf.org/html/rfc791 [4] http://en.wikipedia.org/wiki/IPv4#Header -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090801/3b2e1207/attachment.bin From ketil at malde.org Sat Aug 1 13:10:40 2009 From: ketil at malde.org (Ketil Malde) Date: Sat Aug 1 12:51:27 2009 Subject: [Haskell-cafe] Re: Strange memory usage problem In-Reply-To: <9979e72e0907311645m598444b6vf362cf12d909b304@mail.gmail.com> (John Lato's message of "Sat\, 1 Aug 2009 00\:45\:58 +0100") References: <9979e72e0907311645m598444b6vf362cf12d909b304@mail.gmail.com> Message-ID: <87fxcb31f3.fsf@malde.org> John Lato writes: > I can confirm this behavior on GHC 6.10.4 on OSX 10.5.7. Great, thanks! > Try adding > {-# INLINE getRB #-} > above the getRB definition. That fixes it for me. And I especially appreciate this, of course. It appears to do the trick here, too. > I think that when the rest of the code is commented out, getRB is only > called in one location, so GHC inlines it automatically. Since getRB > is also called in the commented-out code, it probably isn't > automatically inlined when that code is available. I suspect that the > inlining allows GHC to infer some strictness property it otherwise > can't. Sounds reasonable. The getRB function 'get's a couple of bytestrings and lazy bytestrings from the input - apparently these aren't fully evaluated by the Get monad? I thought it might be the lazy ones, but I replaced them with strict bytestrings with no noticable success. I'm not entirely happy with the inline pragma as a solution, since it indicates that I'm depending on the optimizing-fu of GHC to make my program work, and this seems fragile. So far, it appears to be the best solution. -k -- If I haven't seen further, it is by standing in the footprints of giants From ketil at malde.org Sat Aug 1 13:36:32 2009 From: ketil at malde.org (Ketil Malde) Date: Sat Aug 1 13:17:23 2009 Subject: [Haskell-cafe] Efficient functional idiom for histogram In-Reply-To: <79990c6b0908010644w108ea9ddh9bb5b1d262d2c2ed@mail.gmail.com> (Paul Moore's message of "Sat\, 1 Aug 2009 14\:44\:39 +0100") References: <79990c6b0907311339o17930eaej193b39e176f601a4@mail.gmail.com> <87y6q4lgn9.fsf@gregorycollins.net> <79990c6b0907311539t545c650bw521a437324c58922@mail.gmail.com> <79990c6b0908010644w108ea9ddh9bb5b1d262d2c2ed@mail.gmail.com> Message-ID: <877hxn307z.fsf@malde.org> Paul Moore writes: > What am I doing wrong here? I'd have expected compiled Haskell to be > faster than interpreted Python, so obviously my approach is wrong. Two things from my experience: Python associative arrays are fast, and Haskell random numbers are slow. So by building a map from random numbers, you are likely doing a fairly pessimal comparison. Did you profile to see where the time is spent? > I'm expecting the answer to be that I've got unnecessary laziness IME, laziness usually affects space, but not so much time performance. Although 'insertWith (+)' looks like it would build unevaluated thunks for the sums. -k -- If I haven't seen further, it is by standing in the footprints of giants From p.f.moore at gmail.com Sat Aug 1 14:06:48 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Sat Aug 1 13:47:47 2009 Subject: [Haskell-cafe] Efficient functional idiom for histogram In-Reply-To: <877hxn307z.fsf@malde.org> References: <79990c6b0907311339o17930eaej193b39e176f601a4@mail.gmail.com> <87y6q4lgn9.fsf@gregorycollins.net> <79990c6b0907311539t545c650bw521a437324c58922@mail.gmail.com> <79990c6b0908010644w108ea9ddh9bb5b1d262d2c2ed@mail.gmail.com> <877hxn307z.fsf@malde.org> Message-ID: <79990c6b0908011106n75d60eeeqf54740d73dfc05a8@mail.gmail.com> 2009/8/1 Ketil Malde : > Paul Moore writes: > >> What am I doing wrong here? I'd have expected compiled Haskell to be >> faster than interpreted Python, so obviously my approach is wrong. > > Two things from my experience: Python associative arrays are fast, and > Haskell random numbers are slow. ?So by building a map from random > numbers, you are likely doing a fairly pessimal comparison. Hmm, I think you're saying that for this problem, Haskell is likely to be worse than Python. Interesting. I guess I'd assumed that something CPU-intensive like this would benefit from a compiled language. Just goes to show that intuition about performance is usually wrong (something I really should know by now :-)) Is the issue with random numbers just the implementation, or is it something inherent in the non-pure nature of a random number generator that makes it hard for Haskell to implement efficiently? If the latter, that probably makes Haskell a somewhat poor choice for simulation-type programs. > Did you profile to see where the time is spent? Not until you suggested it :-) I was pleasantly surprised by how easy it was to do. The results bear out what you were saying, the bottleneck is entirely in the "dice" function. >> I'm expecting the answer to be that I've got unnecessary laziness > > IME, laziness usually affects space, but not so much time > performance. ?Although 'insertWith (+)' looks like it would build > unevaluated thunks for the sums. That'll teach me to bandy about technical terms as if I understand them :-) Thanks for the comments, Paul. From phil at beadling.co.uk Sat Aug 1 14:06:45 2009 From: phil at beadling.co.uk (phil@beadling.co.uk) Date: Sat Aug 1 13:47:48 2009 Subject: [Haskell-cafe] Retrieving inner state from outside the transformer In-Reply-To: <2f9b2d30907302039u7d4b5f23n5d2ebfe9d2681fbe@mail.gmail.com> References: <89bc5e540907301706t46c0a9c6neb4abc4249618660@mail.gmail.com> <2f9b2d30907302039u7d4b5f23n5d2ebfe9d2681fbe@mail.gmail.com> Message-ID: <51F84BED-CE37-46E2-ACAF-249EC8587B7B@beadling.co.uk> Thanks very much for both replies. I think I get this now. Simply, my choice of evaluation functions (evalStateT, execStateT and execState) ensured that the states are not returned. It was obvious. I can get this working, but I have one more more question to make sure I actually understand this. Below is a very simple and pointless example I wrote to grasp the concept. This returns ((1,23),21) which is clear to me. import Control.Monad.State myOuter :: StateT Int (State Int) Int myOuter = StateT $ \s -> do p <- get return (s,p+s+1) main :: IO() main = do let innerMonad = runStateT myOuter 1 y = runState innerMonad 21 print y Thus we are saying that a=(1,23) and s=21 for the state monad, and that a=1 and s=23 for the state transformer. That is the return value of the state monad is the (a,s) tuple of the transformer and it's own state is of course 21. This got me thinking - the return value's type of the state monad is dictated by the evaluation function used on the state transformer - it could be a, s, or (a,s) depending which function is used. Thus if I edit the code to to: do let innerMonad = evalStateT myOuter 1 I get back (1,21) - which is the problem I had - we've lost the transformer's state. Look at the Haskell docs I get: evalStateT :: Monad m => StateT s m a -> s -> m a runStateT :: s -> m (a, s) So the transformer valuation functions are returning a State monad initialized with either a or (a,s). Now I know from messing around with this that the initialization is the return value, from the constructor: newtype State s a = State { runState :: s -> (a, s) } Am I right in assuming that I can read this as: m (a,s_outer) returned from runStateT is equivalent to calling the constructor as (State s_inner) (a,s_outer) This makes sense because in the definition of myOuter we don't specify the return value type of the inner monad: myOuter :: StateT Int (State Int) Int The problem is whilst I can see that we've defined the inner monad's return value to equal the *type* of the transformer's evaluation function, I'm loosing the plot trying to see how the *values* returned by the transformer are ending up there. We haven't specified what the state monad actually does? If I look at a very simple example: simple :: State Int Int simple = State $ \s -> (s,s+1) This is blindly obvious, is I call 'runState simple 8', I will get back (8,9). Because I've specified that the return value is just the state. In the more original example, I can see that the 'return (s,p+s+1)' must produce a state monad where a=(1,23), and the state of this monad is just hardcoded in the code = 21. I guess what I'm trying to say is - where is the plumbing that ensures that this returned value in the state/transformer stack is just the (a,s) of the transformer? I have a terrible feeling this is a blindly obvious question - apologies if it is! Thanks again! Phil. On 31 Jul 2009, at 04:39, Ryan Ingram wrote: > StateT is really simple, so you should be able to figure it out: > > runStateT :: StateT s m a -> s -> m (a,s) > runState :: State s a -> s -> (a,s) > > So if you have > m :: StateT s1 (StateT s2 (State s3)) a > > runStateT m :: s1 -> StateT s2 (State s3) (a,s) > > \s1 s2 s3 -> runState (runStateT (runStateT m s1) s2) s3) > :: s1 -> s2 -> s3 -> (((a,s1), s2), s3) > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090801/2e104e25/attachment.html From malcolm.wallace at cs.york.ac.uk Sat Aug 1 14:14:51 2009 From: malcolm.wallace at cs.york.ac.uk (Malcolm Wallace) Date: Sat Aug 1 13:55:49 2009 Subject: [Haskell-cafe] Efficient functional idiom for histogram In-Reply-To: <79990c6b0908010644w108ea9ddh9bb5b1d262d2c2ed@mail.gmail.com> References: <79990c6b0907311339o17930eaej193b39e176f601a4@mail.gmail.com> <87y6q4lgn9.fsf@gregorycollins.net> <79990c6b0907311539t545c650bw521a437324c58922@mail.gmail.com> <79990c6b0908010644w108ea9ddh9bb5b1d262d2c2ed@mail.gmail.com> Message-ID: <24DCDFCD-37F2-480A-862E-D4F4668AF88B@cs.york.ac.uk> > I'm expecting the answer to be that I've got unnecessary laziness - > which > is fine, but ultimately my interest is in ease of expression and > performance combined, so I'm looking for beginner-level improvements > rather than subtle advanced techniques like unboxing. You're right, it is too lazy. Here are a couple of strictifications that should help: > histogram :: Ord a => [a] -> [(a,Int)] > histogram = Map.assocs . foldl f Map.empty > where > f m k = Map.insertWith (+) k 1 m Turn foldl into foldl' (from Data.List) and Map.insertWith into Map.insertWith'. The strict versions simply force the intermediate structures to be evaluated, rather than hanging around as large accumulations of closures. Regards, Malcolm From daniel.is.fischer at web.de Sat Aug 1 14:31:32 2009 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Sat Aug 1 14:13:24 2009 Subject: [Haskell-cafe] Efficient functional idiom for histogram In-Reply-To: <79990c6b0908010644w108ea9ddh9bb5b1d262d2c2ed@mail.gmail.com> References: <79990c6b0907311339o17930eaej193b39e176f601a4@mail.gmail.com> <79990c6b0907311539t545c650bw521a437324c58922@mail.gmail.com> <79990c6b0908010644w108ea9ddh9bb5b1d262d2c2ed@mail.gmail.com> Message-ID: <200908012031.34156.daniel.is.fischer@web.de> Am Samstag 01 August 2009 15:44:39 schrieb Paul Moore: > 2009/7/31 Paul Moore : > > 2009/7/31 Gregory Collins : > > Hmm, I'm obviously still mucking up the performance somehow. My full > program (still a toy, but a step on the way to what I'm aiming at) is > as follows. It's rolling 3 6-sided dice 100000 times, and printing a > summary of the results. > > import System.Random > import qualified Data.Map as Map > import Data.Map (Map) > import Data.List > > dice :: Int -> Int -> IO Int > dice 0 n = return 0 > dice m n = do > total <- dice (m - 1) n > roll <- randomRIO (1, n) > return (total + roll) Don't do too much in IO, it's better to separate the pure parts from the IO. IMO, this would better have signature dice :: RandomGen g => Int -> Int -> g -> (Int,g) dice 0 _ g = (0,g) dice m n g = case dice (m-1) n g of (total,g1) -> case randomR (1,n) g1 of (roll,g2) -> (total+roll,g2) or, better still be in a State monad or the Random monad ( http://hackage.haskell.org/package/MonadRandom ) die :: RandomGen g => Int -> State g Int die n = State $ randomR (1,n) dice :: RandomGen g => Int -> Int -> State g Int dice m n = liftM sum $ replicateM m (die n) > -- the "do" is superfluous > simulate count m n = do > mapM (dice m) (replicate count n) Ouch, that hurts (not yet so incredibly much for 100000 rolls, but if you try 1000000, it'll really hurt). Since you're doing it in IO, the whole list must be built before any further processing can begin, so you're building up a largish list, only to destroy it immediately afterwards, much work for the garbage collector. If you can accumulate the scores as they come, the intermediate list can be fused away and the garbage collector is kept idle. If you absolutely have to do it in IO, use import System.IO.Unsafe simulate 0 _ _ = return [] simulate count m n = unsafeInterleaveIO $ do val <- dice m n rst <- simulate (count-1) m n return (val:rst) to avoid building a large list. If you use the (lazy) State monad, that's automatically done :). simulate count m n = replicateM count (dice m n) -- now in State histogram :: Ord a => [a] -> [(a,Int)] histogram = Map.assocs . foldl f Map.empty ? where ? ? f m k = Map.insertWith (+) k 1 m -- simulation :: RandomGen g => State g [(Int,Int)] simulation = do ? lst <- simulate 1000000 3 6 ? return (histogram lst) main = do sg <- getStdGen print $ evalState simulation sg much faster, still not very fast, since StdGen isn't a particularly fast PRNG. Another method is to create an infinite list of random numbers and use it as needed: ------------------------------------------------------- module Main (main) where import System.Random import Data.Array.Unboxed import Data.List import System.Environment (getArgs) dice :: RandomGen g => g -> Int -> [Int] dice g mx = randomRs (1,mx) g splits :: Int -> [a] -> [[a]] splits l = unfoldr f where f xs = case splitAt l xs of r@(h,t) | null t -> Nothing | otherwise -> Just r simulation :: RandomGen g => g -> Int -> Int -> Int -> UArray Int Int simulation g rep dn df = accumArray (+) 0 (dn,dn*df) lst where rls = dice g df scs = splits dn rls lst = take rep [(sum rll,1) | rll <- scs] main :: IO () main = do (rp:dn:df:_) <- getArgs sg <- getStdGen print $ assocs $ simulation sg (read rp) (read dn) (read df) ------------------------------------------------------------- Using an unboxed array instead of a Map gives a little extra speed, but not much. > > histogram :: Ord a => [a] -> [(a,Int)] > histogram = Map.assocs . foldl f Map.empty > where > f m k = Map.insertWith (+) k 1 m For some reason it doesn't make much difference here, but it should be the strict versions, foldl' and insertWith' in general. > > simulation = do > lst <- simulate 100000 3 6 > return (histogram lst) > > main = do > s <- simulation > putStrLn (show s) > > When compiled, this takes over twice as long as a naively implemented > Python program. > > What am I doing wrong here? I'd have expected compiled Haskell to be > faster than interpreted Python, so obviously my approach is wrong. I'm > expecting the answer to be that I've got unnecessary laziness Quite on the contrary, it's unnecessary strictness here :D > - which is fine, but ultimately my interest is in ease of expression and > performance combined, so I'm looking for beginner-level improvements > rather than subtle advanced techniques like unboxing. Nothing advanced with using unboxed arrays. > > Thanks, > Paul. > > PS I know my code is probably fairly clumsy Actually, the style is rather good, I think (mine's worse, usually). You shouldn't use IO so much, though, and your code betrays a certain level of unfamiliarity with strictness/performance characteristics of the libraries. But that's natural. > - I'd appreciate style > suggestions, but my main interest here is whether a beginner, with a > broad programming background, a basic understanding of Haskell, and > access to Google, put together a clear, efficient, program (ie, the > case where my usual scripting language is too slow and I want to knock > something up quickly in a high-level, high-performance language). Performance is a nontrivial thing, it takes some experience to know which data structures to use when. And, as said above, Haskell's StdGen isn't fast, the above programme spends about 90% of the time creating pseudo random numbers. From leepike at gmail.com Sat Aug 1 14:33:37 2009 From: leepike at gmail.com (Lee Pike) Date: Sat Aug 1 14:15:10 2009 Subject: [Haskell-cafe] ANN: atom 0.1.0 Message-ID: <08231E08-13A5-4048-8A4A-927E20BBEAB1@gmail.com> Note too that there's an example Atom program included with the source: http://hackage.haskell.org/packages/archive/atom/0.1.0/doc/html/Language-Atom-Example.html Lee > dons wrote: > We've had a few people playing with Atom to program the Arduino, and > John van Enk's been hacking too, > > Atom & Arduino :: Some Hacking (pt. 1) > http://blog.sw17ch.com/wordpress/?p=84 > > > An Atomic Fibonacci Server: Exploring the Atom (Haskell) DSL > http://leepike.wordpress.com/2009/05/05/an-atomic-fibonacci-server-exploring-the-atom-haskell-dsl/ > > Galois will prob. have a tech talk soon. > > -- Don > > thomas.dubuisson: >> Tom, >> I was asking earlier about any good sources of information for atom. >> It seems the once-good wiki is gone - are there tutorials for Atom >> hiding in forgotten corners? >> >> Thomas >> >> On Fri, Jul 31, 2009 at 1:49 PM, Tom Hawkins >> wrote: >>> Atom is a Haskell DSL for hard realtime applications. This release >>> includes support for assertions and functional coverage to aid >>> simulation and testing. The rev of the minor version indicates a >>> bit >>> of library stability. This is the version we're using for our >>> application, which officially went into production and hit the road >>> last month -- literally. >>> >>> http://hackage.haskell.org/package/atom >>> >>> -Tom >>> _______________________________________________ >>> Haskell-Cafe mailing list >>> Haskell-Cafe@haskell.org >>> http://www.haskell.org/mailman/listinfo/haskell-cafe >> From s.clover at gmail.com Sat Aug 1 14:50:10 2009 From: s.clover at gmail.com (Sterling Clover) Date: Sat Aug 1 14:30:27 2009 Subject: [Haskell-cafe] Efficient functional idiom for histogram In-Reply-To: <79990c6b0908011106n75d60eeeqf54740d73dfc05a8@mail.gmail.com> References: <79990c6b0907311339o17930eaej193b39e176f601a4@mail.gmail.com> <87y6q4lgn9.fsf@gregorycollins.net> <79990c6b0907311539t545c650bw521a437324c58922@mail.gmail.com> <79990c6b0908010644w108ea9ddh9bb5b1d262d2c2ed@mail.gmail.com> <877hxn307z.fsf@malde.org> <79990c6b0908011106n75d60eeeqf54740d73dfc05a8@mail.gmail.com> Message-ID: <2ABA1D95-6C50-4C2D-9EE1-4AAD377FA6D0@gmail.com> On Aug 1, 2009, at 2:06 PM, Paul Moore wrote: > Is the issue with random numbers just the implementation, or is it > something inherent in the non-pure nature of a random number generator > that makes it hard for Haskell to implement efficiently? If the > latter, that probably makes Haskell a somewhat poor choice for > simulation-type programs. > Well, I'm not sure of the details, but in your original implementation, you're performing IO to pull the seed out of a ref at every iteration. Pekka Karjalainen's doesn't do that, which probably helps with the speedup. Along with that, Haskell has a fairly slow random implementation. As I recall however, this is partially because it hasn't received a great deal of optimization, but mainly because the algorithm itself fulfills some rather strong properties -- in particular it must be fairly statistically robust, and it must provide a "split" function which produces generators that are independently robust [1]. This limits algorithm choice quite a bit. For other random numbers, with different properties (faster, but with tradeoffs in robustness, or ability to split, or both), you can check hackage for at least mersenne-random and gsl-random. There may be others that I don't recall. Cheers, Sterl. [1] http://www.haskell.org/onlinereport/random.html From ryani.spam at gmail.com Sat Aug 1 15:17:13 2009 From: ryani.spam at gmail.com (Ryan Ingram) Date: Sat Aug 1 14:58:10 2009 Subject: [Haskell-cafe] Retrieving inner state from outside the transformer In-Reply-To: <51F84BED-CE37-46E2-ACAF-249EC8587B7B@beadling.co.uk> References: <89bc5e540907301706t46c0a9c6neb4abc4249618660@mail.gmail.com> <2f9b2d30907302039u7d4b5f23n5d2ebfe9d2681fbe@mail.gmail.com> <51F84BED-CE37-46E2-ACAF-249EC8587B7B@beadling.co.uk> Message-ID: <2f9b2d30908011217p65f5b14cu2d0ad3375287bc3a@mail.gmail.com> I am not sure I entirely understand your question; it sounds like you are confused and thus your question is a bit confused. So instead, I'll explain in a bit more detail. A common pattern in Haskell is that you have a type that you want to perform some operations on, and then afterwards you "observe" the type to convert it to some simpler type that no longer has those operations. To see why the "observation" is important, consider this type: > newtype StupidT s m a = StupidT () Would you believe that StupidT is a state monad transformer? > instance Monad StupidT s m where > return _ = StupidT () > StupidT () >>= f = StupidT () > instance MonadState s (StupidT s m) where > get = StupidT () > put _ = StupidT () > instance MonadTrans (StupidT s) where > lift _ = StupidT () StupidT follows all the laws for these typeclasses, because they all have to do with observational equality of different sets of operations. Since all operations are equal, the laws all trivially hold. For example: Proof: get >>= put = return () (this is one of the laws every MonadState needs to fulfill) get >>= put apply (>>=) = StupidT () unapply return = return () All of the other laws are proved similarily. Obviously, you can't do much with StupidT; the thing that makes StateT useful is its observation function "runStateT" runStateT :: StateT s m a -> (s -> m (a,s)) which converts from (StateT s m a), into (s -> m (a,s)). You'll often find that the most elegant implementation of a type in Haskell is to use the observation function's return type as the representation type of the object! So since we want runStateT with this particular type, we just make StateT hold that type: > newtype StateT s m a = StateT { runStateT :: s -> m (a,s) } Now, of course, we have to implement all the operations we care about (return, (>>=), get, put, lift), such that they obey the laws those operations are supposed to fulfill, but implementing the observation function is trivial! So, how does the plumbing convert the "s" you give it into a "m (a,s)" result? Simple, there is no plumbing. You just call the function! Of course, there is some plumbing in the implementation of the operations on the transformer: > instance Monad m => Monad (StateT s m) where > return a = StateT $ \s -> return (a,s) > m >>= f = StateT $ \s0 -> do > (a, s1) <- runStateT m s0 > (b, s2) <- runStateT (f a) s1 > return (b,s2) > > instance Monad m => MonadState s (StateT s m) where > get = StateT $ \s -> return (s,s) > put s = StateT $ \_ -> return ((), s) > > instance MonadTrans (StateT s) where > lift m = StateT $ \s -> do > a <- m > return (a,s) You should notice that all this makes runStateT "just work"; there's no need to call additional code to get the (s -> m (a,s)) back out of the StateT. You should also notice that these are the *only* type-correct, non-_|_-using implementations for most of the functions; the only places where we could make a semantic error that wasn't also a type error are putting the wrong states through (put) and (>>=). By choosing a representation that matches the observable value we want, implementing the operations becomes much simpler! -- ryan On Sat, Aug 1, 2009 at 11:06 AM, wrote: > Thanks very much for both replies. > I think I get this now. > Simply, my choice of evaluation functions (evalStateT, execStateT and > execState) ensured that the states are not returned. ?It was obvious. > I can get this working, but I have one more more question to make sure I > actually understand this. > Below is a very simple and pointless example I wrote to grasp the > concept.??This?returns?((1,23),21)?which?is?clear?to?me. > import Control.Monad.State > myOuter :: StateT Int (State Int) Int > myOuter = StateT $ \s -> do p <- get > ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?return (s,p+s+1) > main :: IO() > main = do let innerMonad = runStateT myOuter 1 > ?? ? ? ? ? ? ? ? ? ? y = runState innerMonad 21 > ?? ? ? ? ? ? ? ?print y > Thus we are saying that a=(1,23) and s=21 for the state monad, and that a=1 > and s=23 for the state > transformer.??That?is?the?return?value?of?the?state?monad?is?the?(a,s)?tuple?of?the?transformer?and?it's?own?state?is?of?course?21. > This?got?me?thinking?-?the?return?value's?type?of?the?state?monad?is?dictated?by?the?evaluation?function?used > on?the?state?transformer?-?it?could?be?a,?s,?or?(a,s)?depending?which?function?is?used.??Thus?if?I?edit?the?code?to?to: > do let innerMonad = evalStateT myOuter 1 > I get back (1,21) - which is the problem I had - we've lost the > transformer's state. > Look at the Haskell docs I get: > evalStateT :: Monad m => StateT s m a -> s -> m a > runStateT :: s -> m (a, s) > So the transformer valuation functions are returning a State monad > initialized with either a or (a,s). > Now I know from messing around with this that the initialization is the > return value, from the constructor: > newtype State s a = State { > runState :: s -> (a, s) > } > Am I right in assuming that I can read this as: > m (a,s_outer) returned from runStateT is equivalent to calling the > constructor as (State s_inner) (a,s_outer) > This makes sense because in the definition of myOuter we don't specify the > return value type of the inner monad: > myOuter :: StateT Int (State Int) Int > > The problem is whilst I can see that we've defined the inner monad's return > value to equal the *type* of the transformer's evaluation function, I'm > loosing the plot trying to see how the *values* returned by the transformer > are ending up there. ?We haven't specified what the state monad actually > does? > If I look at a very simple example: > simple :: State Int Int > simple = State $ \s -> (s,s+1) > This is blindly obvious, is I call 'runState simple 8', I will get back > (8,9). ?Because I've specified that the return value is just the state. > In the more original example, I can see that the 'return (s,p+s+1)' must > produce a state monad where a=(1,23), and the state of this monad is just > hardcoded in the code = 21. > I guess what I'm trying to say is - where is the plumbing that ensures that > this returned value in the state/transformer stack is just the (a,s) of the > transformer? > > I have a terrible feeling this is a blindly obvious question - apologies if > it is! > > Thanks again! > > Phil. > > > On 31 Jul 2009, at 04:39, Ryan Ingram wrote: > > StateT is really simple, so you should be able to figure it out: > > runStateT :: StateT s m a -> s -> m (a,s) > runState :: State s a -> s -> (a,s) > > So if you have > m :: StateT s1 (StateT s2 (State s3)) a > > runStateT m :: s1 -> StateT s2 (State s3) (a,s) > > \s1 s2 s3 -> runState (runStateT (runStateT m s1) s2) s3) > :: s1 -> s2 -> s3 -> (((a,s1), s2), s3) > > > From anton at appsolutions.com Sat Aug 1 15:40:40 2009 From: anton at appsolutions.com (Anton van Straaten) Date: Sat Aug 1 15:21:44 2009 Subject: [Haskell-cafe] Efficient functional idiom for histogram In-Reply-To: <2ABA1D95-6C50-4C2D-9EE1-4AAD377FA6D0@gmail.com> References: <79990c6b0907311339o17930eaej193b39e176f601a4@mail.gmail.com> <87y6q4lgn9.fsf@gregorycollins.net> <79990c6b0907311539t545c650bw521a437324c58922@mail.gmail.com> <79990c6b0908010644w108ea9ddh9bb5b1d262d2c2ed@mail.gmail.com> <877hxn307z.fsf@malde.org> <79990c6b0908011106n75d60eeeqf54740d73dfc05a8@mail.gmail.com> <2ABA1D95-6C50-4C2D-9EE1-4AAD377FA6D0@gmail.com> Message-ID: <4A749A38.1060300@appsolutions.com> Sterling Clover wrote: > For other random numbers, with different properties (faster, but with > tradeoffs in robustness, or ability to split, or both), you can check > hackage for at least mersenne-random and gsl-random. gsl-random is definitely worth a try for performance. I recently did a rough benchmark (not rigorous) of Control.Monad.Random, which uses System.Random, and Control.Monad.MC, which uses GSL.Random. Control.Monad.Random took about 3.6 times longer to generate a few million random numbers compared to Control.Monad.MC, and used five times as much heap. The GSL-based version generated about 340,000 random numbers per second on a 1.8GHz notebook. Anton From daniel.is.fischer at web.de Sat Aug 1 16:38:05 2009 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Sat Aug 1 16:19:54 2009 Subject: [Haskell-cafe] Efficient functional idiom for histogram In-Reply-To: <2ABA1D95-6C50-4C2D-9EE1-4AAD377FA6D0@gmail.com> References: <79990c6b0907311339o17930eaej193b39e176f601a4@mail.gmail.com> <79990c6b0908011106n75d60eeeqf54740d73dfc05a8@mail.gmail.com> <2ABA1D95-6C50-4C2D-9EE1-4AAD377FA6D0@gmail.com> Message-ID: <200908012238.06096.daniel.is.fischer@web.de> Am Samstag 01 August 2009 20:50:10 schrieb Sterling Clover: > On Aug 1, 2009, at 2:06 PM, Paul Moore wrote: > > Is the issue with random numbers just the implementation, or is it > > something inherent in the non-pure nature of a random number generator > > that makes it hard for Haskell to implement efficiently? If the > > latter, that probably makes Haskell a somewhat poor choice for > > simulation-type programs. If you view a PRNG as a function from the seed to the sequence of generated numbers or as a function state -> (bitpattern, newstate), PRNGs are pure (at least, I know no counterexample), so it's not inherently inefficient in Haskell, though it's probably still faster in C. One thing that makes StdGen slow is splittability, as Sterling points out below. For a simulation programme where you don't need splittability, choose a different PRNG. > > Well, I'm not sure of the details, but in your original > implementation, you're performing IO to pull the seed out of a ref at > every iteration. Pekka Karjalainen's doesn't do that, which probably > helps with the speedup. Along with that, Haskell has a fairly slow > random implementation. As I recall however, this is partially because > it hasn't received a great deal of optimization, but mainly because > the algorithm itself fulfills some rather strong properties -- in > particular it must be fairly statistically robust, and it must > provide a "split" function which produces generators that are > independently robust [1]. This limits algorithm choice quite a bit. > > For other random numbers, with different properties (faster, but with > tradeoffs in robustness, or ability to split, or both), you can check > hackage for at least mersenne-random and gsl-random. I didn't get much speedup with System.Random.Mersenne.Pure64 (might be because I have a 32-bit system and Word64 goes through foreign calls, if that is still the case), but GSL.Random.Gen reduced the time by a factor of over 5. It forces you back into IO and is a little less convenient, but if speed is a concern, it's a price worth to pay. --------------------------------------- module Main (main) where import GSL.Random.Gen import qualified Data.Map as Map import Data.Map (Map) import Data.List import System.IO.Unsafe import System.Time import Data.Word dice :: RNG -> Int -> Int -> IO Int dice _ 0 n = return 0 dice rng m n = do ? total <- dice rng (m - 1) n ? roll <- fmap (+1) $ getUniformInt rng n ? return (total + roll) simulate _ 0 _ _ = return [] simulate rng count m n = unsafeInterleaveIO $ do val <- dice rng m n tl <- simulate rng (count-1) m n return (val:tl) histogram :: Ord a => [a] -> [(a,Int)] histogram = Map.assocs . foldl' f Map.empty ? where ? ? f m k = Map.insertWith' (+) k 1 m simulation rng = do ? lst <- simulate rng 1000000 3 6 ? return (histogram lst) main = do rng <- newRNG mt19937 sd <- getTimeSeed setSeed rng sd -- omit seeding for reproducible results ? s <- simulation rng ? putStrLn (show s) getTimeSeed :: IO Word64 getTimeSeed = do TOD a b <- getClockTime return . fromInteger $ 10^6*a + b `quot` (10^6) -------------------------------------------------- > There may be others that I don't recall. > > Cheers, > Sterl. From qdunkan at gmail.com Sat Aug 1 18:58:20 2009 From: qdunkan at gmail.com (Evan Laforge) Date: Sat Aug 1 18:39:18 2009 Subject: [Haskell-cafe] Proposal: TypeDirectedNameResolution In-Reply-To: <4A6DCE93.5020700@imn.htwk-leipzig.de> References: <4A6DCE93.5020700@imn.htwk-leipzig.de> Message-ID: <2518b95d0908011558o46dfddady99d89a8876be6ec@mail.gmail.com> One issue I have which I haven't seen anyone mention is that it's not useful with qualified names, by which I mean always importing qualified. Of course if you have no problem always using qualified names, the problem this extension is solving doesn't exist. Though I do like short names I'm not terribly bothered by writing Map.map and List.map. Most calls in a module are within the module after all, which is as it should be in most cases. So this extension would do nothing for me. I like the explicitness of qualified names, and I find it hard to read someone's module when they call some function that comes somewhere out of a list of 15 imports at the top, and this extension would make it even harder to find the definition of the function... though tags would narrow down the search a lot. But with modules, often the prepended module name is all the information I need at the moment. On the other hand, I do acknowledge that I'm pretty used to seeing x.y in an OO language and often don't mind that I need to know the type of 'x' and maybe even find the constructor call to know where to look for 'y'. So maybe it's not that big of a deal. From thomas.dubuisson at gmail.com Sat Aug 1 23:19:22 2009 From: thomas.dubuisson at gmail.com (Thomas DuBuisson) Date: Sat Aug 1 23:00:18 2009 Subject: [Haskell-cafe] Possible bug in Data.IP (network-data package) In-Reply-To: <1249146365.4643.19.camel@supermule.opasia.dk> References: <1249146365.4643.19.camel@supermule.opasia.dk> Message-ID: <4c44d90b0908012019ieabc183naf5802ae4fdb4a91@mail.gmail.com> > > So I am right to see this as a bug in network-data ? > Yes, the "payloadLength" field was poorly (read: incorrectly) named perhaps due to having recently read IPv6 specs. This will be corrected in version 0.1.0 which I plan on uploading soon (tonight). Thanks! Thomas From michal.dobrogost at gmail.com Sun Aug 2 01:25:40 2009 From: michal.dobrogost at gmail.com (Michal D.) Date: Sun Aug 2 01:06:36 2009 Subject: [Haskell-cafe] Cyclic data declarations Message-ID: <4eff48ac0908012225j3a1dc7abh901859b95c5fa660@mail.gmail.com> I'm in the process of writing a toy compiler but I'm having some trouble trying to make my datatypes general. For example, using parsec I parse statements as: data Stmt = SIf Test [Stmt] [Stmt] | ... However, when it's time to create a control flow graph it would be nice to represent statements as (the Int's signify the node id's for either case of the if statement): data Stmt = SIf Test Int Int | ... So, in a eureka moment I decided that this should be allowable with the following declaration: data Stmt link = SIf Test link link | ... Ofcourse, the problem is trying to declare the resulting type for parsing: "parse -> Stmt [Stmt [Stmt ....]]". Any hints on whether there is a way to accomplish what I'm trying to do or do I have to bite the bullet and declare two seperate datatypes? I tried being clever and declaring a 'helper' type as "type StmtRec = Stmt [StmtRec]" but to no avail... GHC won't let it slide: "Cycle in type synonym declarations"! Cheers, Michal From bulat.ziganshin at gmail.com Sun Aug 2 01:46:47 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sun Aug 2 01:28:18 2009 Subject: [Haskell-cafe] Cyclic data declarations In-Reply-To: <4eff48ac0908012225j3a1dc7abh901859b95c5fa660@mail.gmail.com> References: <4eff48ac0908012225j3a1dc7abh901859b95c5fa660@mail.gmail.com> Message-ID: <1882659088.20090802094647@gmail.com> Hello Michal, Sunday, August 2, 2009, 9:25:40 AM, you wrote: > data Stmt = SIf Test [Stmt] [Stmt] | ... > data Stmt = SIf Test Int Int | ... data Stmt a = SIf Test [Stmt a] [Stmt a] | ... where a will represent type of your statement. this may be read as "IF statement with a left and right parts consisting of sequence of statements returning a, have type a" btw, you may need to use GADTs to implement more complex statement types machinery, this is rather popular example in various GADT papers, f.e. http://www.iai.uni-bonn.de/~ralf/publications/With.pdf -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From dagit at codersbase.com Sun Aug 2 01:50:57 2009 From: dagit at codersbase.com (Jason Dagit) Date: Sun Aug 2 01:31:53 2009 Subject: [Haskell-cafe] Cyclic data declarations In-Reply-To: <4eff48ac0908012225j3a1dc7abh901859b95c5fa660@mail.gmail.com> References: <4eff48ac0908012225j3a1dc7abh901859b95c5fa660@mail.gmail.com> Message-ID: On Sat, Aug 1, 2009 at 10:25 PM, Michal D. wrote: > I'm in the process of writing a toy compiler but I'm having some > trouble trying to make my datatypes general. For example, using parsec > I parse statements as: > > data Stmt = SIf Test [Stmt] [Stmt] | ... One of your types could be: newtype Block = Block [Stmt] Then you could have: data Stmt = SIf Test Block Block | ... > > > However, when it's time to create a control flow graph it would be > nice to represent statements as (the Int's signify the node id's for > either case of the if statement): > > data Stmt = SIf Test Int Int | ... Depending on the amount of code duplication, I think I'd actually make two separate data types. data GStmt = GIf Test Int Int | ... And have a function: toFlowGraph :: Stmt -> GStmt > > > So, in a eureka moment I decided that this should be allowable with > the following declaration: > > data Stmt link = SIf Test link link | ... Clever, but I don't think I would do it this way. > > > Ofcourse, the problem is trying to declare the resulting type for > parsing: "parse -> Stmt [Stmt [Stmt ....]]". Any hints on whether > there is a way to accomplish what I'm trying to do or do I have to > bite the bullet and declare two seperate datatypes? I tried being > clever and declaring a 'helper' type as "type StmtRec = Stmt [StmtRec]" > but to no avail... GHC won't let it slide: "Cycle in type synonym > declarations"! I'd have to see your parser, but it shouldn't be too hard to work around this depending on how you want to solve it. By the way, for your StmtRec you probably want a newtype instead of a type. Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090802/c8ad96b5/attachment.html From apfelmus at quantentunnel.de Sun Aug 2 03:34:21 2009 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Sun Aug 2 03:15:04 2009 Subject: [Haskell-cafe] Re: Cyclic data declarations In-Reply-To: <4eff48ac0908012225j3a1dc7abh901859b95c5fa660@mail.gmail.com> References: <4eff48ac0908012225j3a1dc7abh901859b95c5fa660@mail.gmail.com> Message-ID: Michal D. wrote: > I'm in the process of writing a toy compiler but I'm having some > trouble trying to make my datatypes general. For example, using parsec > I parse statements as: > > data Stmt = SIf Test [Stmt] [Stmt] | ... > > However, when it's time to create a control flow graph it would be > nice to represent statements as (the Int's signify the node id's for > either case of the if statement): > > data Stmt = SIf Test Int Int | ... (I recommend to replace Int with something more descriptive, like type Id = Int ) > So, in a eureka moment I decided that this should be allowable with > the following declaration: > > data Stmt link = SIf Test link link | ... > > Ofcourse, the problem is trying to declare the resulting type for > parsing: "parse -> Stmt [Stmt [Stmt ....]]". Any hints on whether > there is a way to accomplish what I'm trying to do or do I have to > bite the bullet and declare two seperate datatypes? I tried being > clever and declaring a 'helper' type as "type StmtRec = Stmt [StmtRec]" > but to no avail... GHC won't let it slide: "Cycle in type synonym declarations"! newtype StmtRec = StmtRec (Stmt [StmtRec]) will do. More generally, you can use newtype Fix f = In { out :: f (Fix f) } and define type StmtRec = Fix ([] `O` Stmt) where O denotes composition of functors newtype O f g a = O (f (g a)) Introducing a parameter in Stmt like you did and tying the recursion afterwards is a known technique, but I can't seem to find a wiki page that concisely explains it right now. Regards, apfelmus -- http://apfelmus.nfshost.com From deb at pudlak.name Sun Aug 2 06:25:02 2009 From: deb at pudlak.name (Petr Pudlak) Date: Sun Aug 2 06:06:00 2009 Subject: [Haskell-cafe] funct.prog. vs logic prog., practical Haskell Message-ID: <20090802102501.GA25860@pudlak.name> Hi all, I'd like to convince people at our university to pay more attention to functional languages, especially Haskell. Their arguments were that (1) Functional programming is more academic than practical. (2) They are using logic programming already (Prolog); why is Haskell better than Prolog (or generally a functional language better than a logic programming language)? (1) is easier to answer, there are a lots of applications at HaskellWiki, or elsewhere around the Internet, written in Haskell, OCaml, etc. Still, I welcome comments on your experience, for example, if you have written some larger-scale application in Haskell (or another a functional language) that is not at HaskellWiki, and perhaps if/why you would recommend doing so to other people. (2) is harder for me, since I've never programmed in Prolog or another language for logic programming. I'd be happy if anyone who is experienced in both Prolog and Haskell could elaborate the differences, pros & cons etc. Thanks, Petr From patai_gergely at fastmail.fm Sun Aug 2 07:37:07 2009 From: patai_gergely at fastmail.fm (Patai Gergely) Date: Sun Aug 2 07:18:02 2009 Subject: [Haskell-cafe] Heap profiling project update Message-ID: <1249213027.16263.1327908961@webmail.messagingengine.com> Hi all, It's been a while since I announced anything about the project on the list, but I've been regularly posting about it on my blog [1]. Everyone should feel encouraged to check out the cabalised code [2] and play with it, stress test it. Adventurous ones can also look at the source. ;) Gergely [1] http://just-bottom.blogspot.com/ [2] http://code.google.com/p/hp2any/source/checkout -- http://www.fastmail.fm - Send your email first class From carter.schonwald at gmail.com Sun Aug 2 08:36:27 2009 From: carter.schonwald at gmail.com (Carter Schonwald) Date: Sun Aug 2 08:17:43 2009 Subject: [Haskell-cafe] funct.prog. vs logic prog., practical Haskell In-Reply-To: <20090802102501.GA25860@pudlak.name> References: <20090802102501.GA25860@pudlak.name> Message-ID: <931b9490908020536g58b6814al3dc8c6fa4d40e3e1@mail.gmail.com> are you a student (undergrad or grad) or faculty (junior or senior)? These are all very different scenarios and accordingly different goals are realistic. For example, if you're a student, it might be more realistic to start with finding a professor who will be willing to supervise an independent study class. On Sun, Aug 2, 2009 at 6:25 AM, Petr Pudlak wrote: > Hi all, > > I'd like to convince people at our university to pay more attention to > functional languages, especially Haskell. Their arguments were that > > (1) Functional programming is more academic than practical. > (2) They are using logic programming already (Prolog); why is Haskell > better than Prolog (or generally a functional language better than a > logic programming language)? > > (1) is easier to answer, there are a lots of applications at HaskellWiki, > or > elsewhere around the Internet, written in Haskell, OCaml, etc. Still, I > welcome comments on your experience, for example, if you have written some > larger-scale application in Haskell (or another a functional language) that > is > not at HaskellWiki, and perhaps if/why you would recommend doing so to > other > people. > > (2) is harder for me, since I've never programmed in Prolog or another > language > for logic programming. I'd be happy if anyone who is experienced in both > Prolog > and Haskell could elaborate the differences, pros & cons etc. > > Thanks, > Petr > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090802/3aa13713/attachment.html From deb at pudlak.name Sun Aug 2 08:52:08 2009 From: deb at pudlak.name (Petr Pudlak) Date: Sun Aug 2 08:33:04 2009 Subject: [Haskell-cafe] funct.prog. vs logic prog., practical Haskell In-Reply-To: <931b9490908020536g58b6814al3dc8c6fa4d40e3e1@mail.gmail.com> References: <20090802102501.GA25860@pudlak.name> <931b9490908020536g58b6814al3dc8c6fa4d40e3e1@mail.gmail.com> Message-ID: <20090802125207.GA10173@pudlak.name> On Sun, Aug 02, 2009 at 08:36:27AM -0400, Carter Schonwald wrote: > are you a student (undergrad or grad) or faculty (junior or senior)? These > are all very different scenarios and accordingly different goals are > realistic. I'm a faculty member (postdoc). I've been working in the field of automated theorem proving, but for about a year I'm also very interested in Haskell and in general in the theory behind functional languages. Since I find FP to be a very important programming concept, I'd like to achieve that we start teaching it at the university. Petr From carter.schonwald at gmail.com Sun Aug 2 09:03:14 2009 From: carter.schonwald at gmail.com (Carter Schonwald) Date: Sun Aug 2 08:44:30 2009 Subject: [Haskell-cafe] funct.prog. vs logic prog., practical Haskell In-Reply-To: <20090802125207.GA10173@pudlak.name> References: <20090802102501.GA25860@pudlak.name> <931b9490908020536g58b6814al3dc8c6fa4d40e3e1@mail.gmail.com> <20090802125207.GA10173@pudlak.name> Message-ID: <931b9490908020603r3b7b65b2p99c9a6681a4035d3@mail.gmail.com> Have you considered say proposing a class on theorem proving that uses coq? www.*coq*.inria.fr . Such a class would entail teaching how to program using the coq term language, which is itself a pure functional language, albeit one with some restrictions related to everything impure. As a matter of course in such a class you would naturally also mention that there are languages such as haskell which lack such restrictions/ have clever ways around them. -Carter On Sun, Aug 2, 2009 at 8:52 AM, Petr Pudlak wrote: > On Sun, Aug 02, 2009 at 08:36:27AM -0400, Carter Schonwald wrote: > > are you a student (undergrad or grad) or faculty (junior or senior)? > These > > are all very different scenarios and accordingly different goals are > > realistic. > > I'm a faculty member (postdoc). I've been working in the field of automated > theorem proving, but for about a year I'm also very interested in Haskell > and > in general in the theory behind functional languages. Since I find FP to be > a > very important programming concept, I'd like to achieve that we start > teaching > it at the university. > > Petr > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090802/ed6b19fe/attachment.html From deb at pudlak.name Sun Aug 2 09:26:19 2009 From: deb at pudlak.name (Petr Pudlak) Date: Sun Aug 2 09:07:15 2009 Subject: [Haskell-cafe] funct.prog. vs logic prog., practical Haskell In-Reply-To: <931b9490908020603r3b7b65b2p99c9a6681a4035d3@mail.gmail.com> References: <20090802102501.GA25860@pudlak.name> <931b9490908020536g58b6814al3dc8c6fa4d40e3e1@mail.gmail.com> <20090802125207.GA10173@pudlak.name> <931b9490908020603r3b7b65b2p99c9a6681a4035d3@mail.gmail.com> Message-ID: <20090802132619.GC10173@pudlak.name> That's actually a good idea. I haven't considered this alternative so far, probably because I have always been working with first-order theorem provers. But I guess eventually I'll merge my interests in ATP and FP and start doing some serious work with higher-order theorem provers like coq or Isabelle. Petr On Sun, Aug 02, 2009 at 09:03:14AM -0400, Carter Schonwald wrote: > Have you considered say proposing a class on theorem proving that uses coq? > www.coq.inria.fr . Such a class would entail teaching how to program using the > coq term language, which is itself a pure functional language, albeit one with > some restrictions related to everything impure. As a matter of course in such > a class you would naturally also mention that there are languages such as > haskell which lack such restrictions/ have clever ways around them. > > -Carter > > On Sun, Aug 2, 2009 at 8:52 AM, Petr Pudlak wrote: > I'm a faculty member (postdoc). I've been working in the field of > automated > theorem proving, but for about a year I'm also very interested in Haskell > and > in general in the theory behind functional languages. Since I find FP to > be a > very important programming concept, I'd like to achieve that we start > teaching > it at the university. > > Petr > > > From ifl2009 at shu.edu Sun Aug 2 09:29:39 2009 From: ifl2009 at shu.edu (IFL 2009) Date: Sun Aug 2 09:10:35 2009 Subject: [Haskell-cafe] IFL 2009: Call for Papers and Participation Message-ID: An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090802/f301b8ca/attachment.html From ck_kashyap at yahoo.com Sun Aug 2 11:00:56 2009 From: ck_kashyap at yahoo.com (CK Kashyap) Date: Sun Aug 2 10:41:51 2009 Subject: [Haskell-cafe] Writing a pnm file Message-ID: <752929.99696.qm@web112511.mail.gq1.yahoo.com> Hi, Now that I've understood how to generate raster points of a line in Haskell - the next thing I want to do is generate a pnm file with it. I've done it in perl as of now. In perl, I can have a scalar variable $x contain a string of 256*256*3 bytes (for 24-bit 256x256 image) and set pixels using substr on LHS. I was wondering how I could do something similar in Haskell? sub setPixel{ my($x,$y,$red,$green,$blue)=@_; my$pixel=pack "CCC",$red,$green,$blue; my$offset=$WIDTH*$y*3 + $x*3; substr($image,$offset,3) = $pixel; } Regards, Kashyap -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090802/ee5bb01d/attachment.html From sebastian.sylvan at gmail.com Sun Aug 2 12:00:08 2009 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Sun Aug 2 11:41:04 2009 Subject: [Haskell-cafe] Writing a pnm file In-Reply-To: <752929.99696.qm@web112511.mail.gq1.yahoo.com> References: <752929.99696.qm@web112511.mail.gq1.yahoo.com> Message-ID: <3d96ac180908020900s2fad3769h516ac0e7f677b303@mail.gmail.com> On Sun, Aug 2, 2009 at 4:00 PM, CK Kashyap wrote: > Hi, > Now that I've understood how to generate raster points of a line in Haskell > - the next thing I want to do is generate a pnm file with it. I've done it > in perl as of now. In perl, I can have a scalar variable $x contain a string > of 256*256*3 bytes (for 24-bit 256x256 image) and set pixels using substr on > LHS. I was wondering how I could do something similar in Haskell? > > sub setPixel{ > my($x,$y,$red,$green,$blue)=@_; > my$pixel=pack "CCC",$red,$green,$blue; > my$offset=$WIDTH*$y*3 + $x*3; > substr($image,$offset,3) = $pixel; > } > There's a library on hackage which does this http://hackage.haskell.org/package/ppm You can install this by doing >cabal install ppm Here's an example usage (this uses the binary version of ppm, the docs for ppm has an example for the ASCII version): writePPM fname img = withBinaryFile fname WriteMode (\h -> hPutStr h (ppm_p6 img) ) If you're looking for the learning experience, you could always read the source for the library (which is pretty tiny). -- Sebastian Sylvan +44(0)7857-300802 UIN: 44640862 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090802/5b7e59eb/attachment.html From ttencate at gmail.com Sun Aug 2 14:47:47 2009 From: ttencate at gmail.com (Thomas ten Cate) Date: Sun Aug 2 14:28:42 2009 Subject: [Haskell-cafe] funct.prog. vs logic prog., practical Haskell In-Reply-To: <20090802102501.GA25860@pudlak.name> References: <20090802102501.GA25860@pudlak.name> Message-ID: On Sun, Aug 2, 2009 at 12:25, Petr Pudlak wrote: > ? ?Hi all, > > I'd like to convince people at our university to pay more attention to > functional languages, especially Haskell. Their arguments were that > > ? ?(1) Functional programming is more academic than practical. Which, even if it were true, is an argument *for* instead of *against* teaching it at a university; that is what the word "academic" means, after all... Thomas From william.wood3 at comcast.net Sun Aug 2 16:01:27 2009 From: william.wood3 at comcast.net (Bill Wood) Date: Sun Aug 2 15:42:21 2009 Subject: [Haskell-cafe] funct.prog. vs logic prog., practical Haskell In-Reply-To: <20090802102501.GA25860@pudlak.name> References: <20090802102501.GA25860@pudlak.name> Message-ID: <1249243287.25240.6.camel@ubuntu> On Sun, 2009-08-02 at 12:25 +0200, Petr Pudlak wrote: > (2) is harder for me, since I've never programmed in Prolog or another language > for logic programming. I'd be happy if anyone who is experienced in both Prolog > and Haskell could elaborate the differences, pros & cons etc. I have done some "real-world" programming in Prolog and SML. The conventional wisdom in the LP community seems to be that the primary path to performance improvement of logic programs is by reduction of non-determinism. To a first approximation, when you have eliminated all the non-determinism from a logic program what you have left is a functional program. The work I was involved with, trying to get quasi-real-time performance from Prolog, bore this out. -- Bill Wood From bulat.ziganshin at gmail.com Sun Aug 2 16:24:24 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sun Aug 2 16:05:56 2009 Subject: [Haskell-cafe] funct.prog. vs logic prog., practical Haskell In-Reply-To: <1249243287.25240.6.camel@ubuntu> References: <20090802102501.GA25860@pudlak.name> <1249243287.25240.6.camel@ubuntu> Message-ID: <1283503538.20090803002424@gmail.com> Hello Bill, Monday, August 3, 2009, 12:01:27 AM, you wrote: > I have done some "real-world" programming in Prolog and SML. The > conventional wisdom in the LP community seems to be that the primary > path to performance improvement of logic programs is by reduction of > non-determinism. and the primary way to make haskell program faster is to emulate imperative language. and the best way to optimize C program is to use it as cpu-independent assembler. it's all natural in von-Neumann world and i personally don't buy these as arguments against everything developed since 1956 actually it supports their's POV: LP is an FP plus non-determinism so why buy a part instead of whole thing? if they need to teach students how to optimize programs, Haskell will be out of luck anyway -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From dons at galois.com Sun Aug 2 19:41:43 2009 From: dons at galois.com (Don Stewart) Date: Sun Aug 2 19:24:47 2009 Subject: [Haskell-cafe] ANNOUNCE: The Haskell Platform 2009.2.0.2 In-Reply-To: <4A7400C9.4030206@btinternet.com> References: <20090801000107.GM3854@whirlpool.galois.com> <4A7400C9.4030206@btinternet.com> Message-ID: <20090802234143.GF13973@whirlpool.galois.com> andrewcoppin: > Don Stewart wrote: >> We're pleased to announce the third release of the Haskell Platform: a >> single, standard Haskell distribution for everyone. >> >> The specification, along with installers (including Windows and Unix >> installers for a full Haskell environment) are available. >> >> Download the Haskell Platform 2009.2.0.2: >> >> http://hackage.haskell.org/platform/ >> > > Maybe I'm being dense... Is there somewhere which lists what's changed > from the last release? > Oh, sorry, that will be in the web announcement tomorrow. Essentially, * GHC 6.10.4 * network upgraded to 2.2.1.4 * Improvements to the MacOSX installer * Improvements to crazy popular Windows installer * Significant improvements in Debian support for Haskell * Gentoo now has full support for the Haskell Platform From bugfact at gmail.com Sun Aug 2 19:48:36 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Sun Aug 2 19:29:31 2009 Subject: [Haskell-cafe] ANNOUNCE: The Haskell Platform 2009.2.0.2 In-Reply-To: <20090802234143.GF13973@whirlpool.galois.com> References: <20090801000107.GM3854@whirlpool.galois.com> <4A7400C9.4030206@btinternet.com> <20090802234143.GF13973@whirlpool.galois.com> Message-ID: On Mon, Aug 3, 2009 at 1:41 AM, Don Stewart wrote: > * Improvements to crazy popular Windows installer Are you kidding or are indeed many Windows users playing with Haskell these days? Cheers, Peter -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090802/69453fb3/attachment.html From dons at galois.com Sun Aug 2 20:00:50 2009 From: dons at galois.com (Don Stewart) Date: Sun Aug 2 19:43:52 2009 Subject: [Haskell-cafe] ANNOUNCE: The Haskell Platform 2009.2.0.2 In-Reply-To: References: <20090801000107.GM3854@whirlpool.galois.com> <4A7400C9.4030206@btinternet.com> <20090802234143.GF13973@whirlpool.galois.com> Message-ID: <20090803000050.GG13973@whirlpool.galois.com> bugfact: > On Mon, Aug 3, 2009 at 1:41 AM, Don Stewart wrote: > > * Improvements to crazy popular Windows installer > > > Are you kidding or are indeed many Windows users playing with Haskell these > days? > No, literally, http://donsbot.wordpress.com/2009/07/26/haskell-platform-progress-report/ From the first few minutes of the release, downloads of the various windows installer were running at many times the rate as that for other platforms (there had until now been no single Haskell package for Windows, after all). This surprised us. By the end of July 2009, 90 days later, there had been: * 114,790 downloads of the Windows installer (!!) * 2,790 installs of the generic unix source tarball (complementing the packages provided on each distro). On June 1, the Mac OSX package went live, complementing the MacPorts GHC version. * 1,300 installs of the Mac OSX package. Since that was published there have been another 13.9k downloads of the Windows installer -- Don From ok at cs.otago.ac.nz Sun Aug 2 20:59:05 2009 From: ok at cs.otago.ac.nz (Richard O'Keefe) Date: Sun Aug 2 20:40:06 2009 Subject: [Haskell-cafe] funct.prog. vs logic prog., practical Haskell In-Reply-To: <931b9490908020536g58b6814al3dc8c6fa4d40e3e1@mail.gmail.com> References: <20090802102501.GA25860@pudlak.name> <931b9490908020536g58b6814al3dc8c6fa4d40e3e1@mail.gmail.com> Message-ID: <0D721E2A-5432-4423-A1AC-E9D02B98E77E@cs.otago.ac.nz> > > On Sun, Aug 2, 2009 at 6:25 AM, Petr Pudlak wrote: > Hi all, > > I'd like to convince people at our university to pay more attention to > functional languages, especially Haskell. Their arguments were that > > (1) Functional programming is more academic than practical. > (2) They are using logic programming already (Prolog); why is > Haskell > better than Prolog (or generally a functional language better > than a > logic programming language)? Why can't a language be both? Get them to take a look at Mercury, which is *both* a logic programming language *and* a (strict) functional programming language, with Haskell-style type-classes and Clean-style uniqueness types. Mercury has been described as "Prolog for serious software engineers". From jgm at berkeley.edu Sun Aug 2 21:05:00 2009 From: jgm at berkeley.edu (John MacFarlane) Date: Sun Aug 2 20:46:10 2009 Subject: [Haskell-cafe] ANN: yst 0.2.1 Message-ID: <20090803010500.GA13034@protagoras.phil.berkeley.edu> I'm pleased to announce the release of yst, now available on HackageDB. yst generates static websites from YAML or CSV data files and StringTemplates. This approach combines the speed, security, and ease of deployment of a static website with the flexibility and maintainability of a dynamic site that separates presentation and data. The easiest way to get a feel for yst is to try it: cabal update cabal install yst yst create testsite cd testsite yst yst attempts to fill a niche between two kinds of site creation tools. On the one hand you have simple static site generators like webgen, webby, nanoc, and my old custom system using make and pandoc. On the other hand, you have dynamic web frameworks like rails and django. For my own smallish websites, I found that the dynamic frameworks were overkill. Nobody but me was going to edit the pages, and I didn't want the trouble of writing and deploying a dynamic site, setting up a web server, and administering a database. A static site would be faster, easier to deploy, and more secure. But the dynamic frameworks offered one thing that the static site generators did not: an easy way to separate data from presentation. This was becoming increasingly important to me as I found myself constantly updating the same information (say, publication data for a paper) in multiple places (say, a LaTeX CV and a differently formatted web listing of papers). What I wanted was a site generation tool that used YAML text files as a database and allowed different kinds of documents to be produced from the same data. I couldn't find anything that did just what I wanted, so I wrote yst. By way of illustration, here are the build instructions for HTML and LaTeX versions of a CV, plus a web page with a list of papers: - url: cv.html title: CV template: cv.st data_common: &cvdata contact: from contact.yaml jobsbyemployer: from jobs.yaml order by start group by employer degrees: from degrees.yaml order by year desc awards: from awards.yaml order by year desc group by title papers: from papers.yaml order by year desc where (not (type = 'review')) reviews: from papers.yaml order by year desc where type = 'review' talks: from talks.yaml where date < '2009-09-01' order by date desc group by title dissertations: from dissertations.yaml order by role then year group by role theses: from theses.yaml order by year then student courses: from courses.yaml order by number group by title data: <<: *cvdata html: yes - url: cv.tex title: CV inmenu: no template: cv.st layout: layout.tex.st data: <<: *cvdata html: yes - url: papers.html title: Papers template: papers.st data: papersbyyear: from papers.yaml order by year desc then title group by year yst's query language is limited, and there are lots of things you can do with a full-fledged database that you can't do with yst. But yst is ideal, I think, for small to medium data-driven sites that are maintained by a single person who likes working with plain text. It scratched my itch, anyway, and I release it in case anyone else has the same itch. Code, documentation, and bug reports: http://github.com/jgm/yst/tree/master John From michal.dobrogost at gmail.com Sun Aug 2 21:06:27 2009 From: michal.dobrogost at gmail.com (Michal D.) Date: Sun Aug 2 20:47:21 2009 Subject: [Haskell-cafe] Re: Cyclic data declarations In-Reply-To: References: <4eff48ac0908012225j3a1dc7abh901859b95c5fa660@mail.gmail.com> Message-ID: <4eff48ac0908021806r71622b21oc9f0799acccd5d13@mail.gmail.com> > > ? newtype StmtRec = StmtRec (Stmt [StmtRec]) > That's pretty much were I threw in the towel last night. Except I had a bunch of places where I had to add the extra constructor statements. I wish there was a solution that didn't require these... they really butcher pattern matching clarity. > will do. More generally, you can use > > ? newtype Fix f = In { out :: f (Fix f) } > > and define > > ? type StmtRec = Fix ([] `O` Stmt) > > where ?O ?denotes composition of functors > > ? newtype O f g a = O (f (g a)) > Thanks for that! This provoked some thought on my part about what exactly is going on. I think I could solve this if I added some way to identify that a type parameter is actually referring to the whole type. Say we had a reserved word "fixpoint" for this. Then we'd have something like: data Stmt x = SIf x x then when we actually go to use it, it would be referred to as the type: "Stmt [fixpoint]" Which would get treated exactly like the data declaration: data Stmt = SIf [Stmt] [Stmt] I'll need to add the newtype declaration for the code but I'd be interested if anyone had further thoughts on this topic. I have an implementation of both approaches on a toy parser, but I doubt anyone's interested in seeing that. Michal From jvlask at hotmail.com Sun Aug 2 21:08:54 2009 From: jvlask at hotmail.com (John Lask) Date: Sun Aug 2 20:53:30 2009 Subject: [Haskell-cafe] funct.prog. vs logic prog., practical Haskell References: <20090802102501.GA25860@pudlak.name> Message-ID: I would have thought that a major motivation for the study of haskell,or for that matter ML, Clean, would be their type systems: statically typed higher order parametric polymorphism which is certainlly different enough from that of prolog to warrant study. So from the perspective of type systems and associated gaurantees functional programming languages probably represent the best environment in which to study these concepts. ----- Original Message ----- From: "Petr Pudlak" To: "Haskell Cafe" Sent: Sunday, August 02, 2009 8:25 PM Subject: [Haskell-cafe] funct.prog. vs logic prog., practical Haskell > Hi all, > > I'd like to convince people at our university to pay more attention to > functional languages, especially Haskell. Their arguments were that > > (1) Functional programming is more academic than practical. > (2) They are using logic programming already (Prolog); why is Haskell > better than Prolog (or generally a functional language better than a > logic programming language)? > > (1) is easier to answer, there are a lots of applications at HaskellWiki, > or > elsewhere around the Internet, written in Haskell, OCaml, etc. Still, I > welcome comments on your experience, for example, if you have written some > larger-scale application in Haskell (or another a functional language) > that is > not at HaskellWiki, and perhaps if/why you would recommend doing so to > other > people. > > (2) is harder for me, since I've never programmed in Prolog or another > language > for logic programming. I'd be happy if anyone who is experienced in both > Prolog > and Haskell could elaborate the differences, pros & cons etc. > > Thanks, > Petr > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From tomahawkins at gmail.com Sun Aug 2 23:33:14 2009 From: tomahawkins at gmail.com (Tom Hawkins) Date: Sun Aug 2 23:14:08 2009 Subject: [Haskell-cafe] ANN: atom 0.1.0 In-Reply-To: <4c44d90b0907311433q44b29308h1173e365f0a668b8@mail.gmail.com> References: <594c1e830907311349q50fb4e5dyc67457de4840b2e3@mail.gmail.com> <4c44d90b0907311433q44b29308h1173e365f0a668b8@mail.gmail.com> Message-ID: <594c1e830908022033m2fb17b3bme1b782c57a42a410@mail.gmail.com> Hi Thomas, No, unfortunately the documentation is limited to the sparse Haddock comments. We intend to assemble more detailed examples, but our program is consuming all our time at the moment. With the limited documentation, frankly I was a bit surprised folks where able to pick it up and run with it. Don, I'm eagerly awaiting a Galois tech talk. Though Haskell is well entrenched in my group, it has yet to spread to other programs in the company despite our best marketing efforts. Sometimes it helps if words of wisdom come from the outside. -Tom On Fri, Jul 31, 2009 at 4:33 PM, Thomas DuBuisson wrote: > Tom, > I was asking earlier about any good sources of information for atom. > It seems the once-good wiki is gone - are there tutorials for Atom > hiding in forgotten corners? > > Thomas > > On Fri, Jul 31, 2009 at 1:49 PM, Tom Hawkins wrote: >> Atom is a Haskell DSL for hard realtime applications. ?This release >> includes support for assertions and functional coverage to aid >> simulation and testing. ?The rev of the minor version indicates a bit >> of library stability. ?This is the version we're using for our >> application, which officially went into production and hit the road >> last month -- literally. >> >> http://hackage.haskell.org/package/atom >> >> -Tom >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> > From ck_kashyap at yahoo.com Mon Aug 3 01:38:47 2009 From: ck_kashyap at yahoo.com (CK Kashyap) Date: Mon Aug 3 01:19:42 2009 Subject: [Haskell-cafe] Writing a pnm file In-Reply-To: <3d96ac180908020900s2fad3769h516ac0e7f677b303@mail.gmail.com> References: <752929.99696.qm@web112511.mail.gq1.yahoo.com> <3d96ac180908020900s2fad3769h516ac0e7f677b303@mail.gmail.com> Message-ID: <925823.69827.qm@web112512.mail.gq1.yahoo.com> Thanks Sebastian, ppm module is indeed very useful. So, I guess my question then just boils down to, how can I write a function to mimic the setPixel function -> Basically, a blank white image would look like this (as per ppm module) [ [ (255, 255, 255) , (255, 255, 255) , (255, 255, 255) ] , -- 3 columns of row 1 [ (255, 255, 255) , (255, 255, 255) , (255, 255, 255) ] --- 3 columns of row 2 ] setPixel x y r g b when called like this - setPixel 0,0,255,0,0 [ [ (255, 0, 0) , (255, 255, 255) , (255, 255, 255) ] , -- 3 columns of row 1 [ (255, 255, 255) , (255, 255, 255) , (255, 255, 255) ] --- 3 columns of row 2 ] What would be a good way to implement such a function? Regards, Kashyap ________________________________ From: Sebastian Sylvan To: CK Kashyap Cc: haskell-cafe@haskell.org Sent: Sunday, August 2, 2009 9:30:08 PM Subject: Re: [Haskell-cafe] Writing a pnm file On Sun, Aug 2, 2009 at 4:00 PM, CK Kashyap wrote: Hi, >Now that I've understood how to generate raster points of a line in Haskell - the next thing I want to do is generate a pnm file with it. I've done it in perl as of now. In perl, I can have a scalar variable $x contain a string of 256*256*3 bytes (for 24-bit 256x256 image) and set pixels using substr on LHS. I was wondering how I could do something similar in Haskell? > > >sub setPixel{ >my($x,$y,$red,$green,$blue)=@_; >my$pixel=pack "CCC",$red,$green,$blue; >my$offset=$WIDTH*$y*3 + $x*3; >substr($image,$offset,3) = $pixel; >} There's a library on hackage which does this http://hackage.haskell.org/package/ppm You can install this by doing >cabal install ppm Here's an example usage (this uses the binary version of ppm, the docs for ppm has an example for the ASCII version): writePPM fname img = withBinaryFile fname WriteMode (\h -> hPutStr h (ppm_p6 img) ) If you're looking for the learning experience, you could always read the source for the library (which is pretty tiny). -- Sebastian Sylvan +44(0)7857-300802 UIN: 44640862 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090803/6a877f51/attachment.html From william.wood3 at comcast.net Mon Aug 3 02:24:19 2009 From: william.wood3 at comcast.net (Bill Wood) Date: Mon Aug 3 02:05:14 2009 Subject: [Haskell-cafe] funct.prog. vs logic prog., practical Haskell In-Reply-To: <1283503538.20090803002424@gmail.com> References: <20090802102501.GA25860@pudlak.name> <1249243287.25240.6.camel@ubuntu> <1283503538.20090803002424@gmail.com> Message-ID: <1249280659.9810.5.camel@ubuntu> On Mon, 2009-08-03 at 00:24 +0400, Bulat Ziganshin wrote: . . . > and the primary way to make haskell program faster is to emulate > imperative language. and the best way to optimize C program is to use > it as cpu-independent assembler. > > it's all natural in von-Neumann world and i personally don't buy these as > arguments against everything developed since 1956 > > actually it supports their's POV: LP is an FP plus non-determinism so > why buy a part instead of whole thing? if they need to teach students > how to optimize programs, Haskell will be out of luck anyway This seems largely tangential to my point, which was that logic programmers can well benefit from exposure to functional programming since 1) one important approach to improving the performance of logic programs is reduction of non-determinism, and 2) often times a deterministic logic program is very similar to a functional program. -- Bill Wood From alecsk at gmail.com Mon Aug 3 02:27:57 2009 From: alecsk at gmail.com (Alecs King) Date: Mon Aug 3 02:09:05 2009 Subject: [Haskell-cafe] ANNOUNCE: The Haskell Platform 2009.2.0.2 In-Reply-To: <20090801000107.GM3854@whirlpool.galois.com> References: <20090801000107.GM3854@whirlpool.galois.com> Message-ID: <20090803062757.GA16033@narnia> On Fri, Jul 31, 2009 at 05:01:07PM -0700, Don Stewart wrote: > > We're pleased to announce the third release of the Haskell Platform: a > single, standard Haskell distribution for everyone. > > The specification, along with installers (including Windows and Unix > installers for a full Haskell environment) are available. > > Download the Haskell Platform 2009.2.0.2: > > http://hackage.haskell.org/platform/ Thanks for the hard work. But there's a problem of the source tarball. scripts/build.sh skips building already-installed pkgs -- but scripts/install.sh does not skip installing them. So 'make install' fails (err: "The ${PKG}/Setup script does not exist or cannot be run") if there are some pkgs that have been skipped building. A quick(-and-dirty) hot fix: -- code copied from build.sh --- scripts/install.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) Index: haskell-platform-2009.2.0.2/scripts/install.sh =================================================================== --- haskell-platform-2009.2.0.2.orig/scripts/install.sh +++ haskell-platform-2009.2.0.2/scripts/install.sh @@ -34,13 +34,23 @@ install_pkg () { fi } +# Is this exact version of the package already installed? +is_pkg_installed () { + PKG_VER=$1 + grep " ${PKG_VER} " installed.packages > /dev/null 2>&1 +} + # Actually do something! cd packages for pkg in `cat platform.packages`; do - cd "${pkg}" || die "The directory for the component ${PKG} is missing" - echo "Installing ${pkg}..." - install_pkg ${pkg} - cd .. + if is_pkg_installed "${pkg}"; then + echo "Platform package ${pkg} is already installed. Skipping..." + else + cd "${pkg}" || die "The directory for the component ${PKG} is missing" + echo "Installing ${pkg}..." + install_pkg ${pkg} + cd .. + fi done echo -- Alecs King From Paul.Brauner at loria.fr Mon Aug 3 02:47:11 2009 From: Paul.Brauner at loria.fr (Paul.Brauner@loria.fr) Date: Mon Aug 3 02:28:06 2009 Subject: [Haskell-cafe] haskell code pretty printer ? Message-ID: <20090803064711.GB3604@loria.fr> Hello, is there a pretty printer for haskell code somewhere ? I've googled and caballisted for this without success. I've written some small script using Language.Haskell.Pretty and Language.Haskell.Parser but the result isn't that 'pretty'. I mean, it outputs readable code but supercombinator's definitions aren't separated by a blank line for instance (despite having put 'spacing' to 'True'). Do you know of such a tool ? Regards, Paul From tom.davie at gmail.com Mon Aug 3 02:51:46 2009 From: tom.davie at gmail.com (Thomas Davie) Date: Mon Aug 3 02:32:45 2009 Subject: [Haskell-cafe] ANNOUNCE: The Haskell Platform 2009.2.0.2 In-Reply-To: <20090803000050.GG13973@whirlpool.galois.com> References: <20090801000107.GM3854@whirlpool.galois.com> <4A7400C9.4030206@btinternet.com> <20090802234143.GF13973@whirlpool.galois.com> <20090803000050.GG13973@whirlpool.galois.com> Message-ID: I tried the Mac OS X package yesterday, after getting frustrated with random crashes in my broken GHC 6.9 install... It worked flawlessly, and got me set up in minutes. Great job everyone associated with building this installer -- it's now definitely my preferred way of getting GHC on a mac. Bob On 3 Aug 2009, at 02:00, Don Stewart wrote: > bugfact: >> On Mon, Aug 3, 2009 at 1:41 AM, Don Stewart wrote: >> >> * Improvements to crazy popular Windows installer >> >> >> Are you kidding or are indeed many Windows users playing with >> Haskell these >> days? >> > > No, literally, > > http://donsbot.wordpress.com/2009/07/26/haskell-platform-progress-report/ > > From the first few minutes of the release, downloads of the > various windows > installer were running at many times the rate as that for other > platforms > (there had until now been no single Haskell package for Windows, > after all). > This surprised us. By the end of July 2009, 90 days later, there > had been: > > * 114,790 downloads of the Windows installer (!!) > * 2,790 installs of the generic unix source tarball > (complementing the > packages provided on each distro). > > On June 1, the Mac OSX package went live, complementing the > MacPorts GHC version. > > * 1,300 installs of the Mac OSX package. > > Since that was published there have been another 13.9k downloads of > the Windows installer > > -- Don > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From niklas.broberg at gmail.com Mon Aug 3 03:38:35 2009 From: niklas.broberg at gmail.com (Niklas Broberg) Date: Mon Aug 3 03:19:28 2009 Subject: [Haskell-cafe] haskell code pretty printer ? In-Reply-To: <20090803064711.GB3604@loria.fr> References: <20090803064711.GB3604@loria.fr> Message-ID: Hi Paul, > is there a pretty printer for haskell code somewhere ? I've googled and > caballisted for this without success. I've written some small script > using Language.Haskell.Pretty and Language.Haskell.Parser but the result > isn't that 'pretty'. I mean, it outputs readable code but > supercombinator's definitions aren't separated by a blank line for > instance (despite having put 'spacing' to 'True'). > > Do you know of such a tool ? haskell-src-exts [1] is probably as pretty as you get, but it doesn't differ much at all from haskell-src in its output. I'd be happy to have any specific complaints about it reported on my trac [2] though, I'm always keen to improve the product, and if you make your voice heard then chances are quite good that you get your wish. :-) Cheers, /Niklas [1] http://hackage.haskell.org/package/haskell-src-exts [2] http://trac.haskell.org/haskell-src-exts From wrwills at gmail.com Mon Aug 3 05:29:20 2009 From: wrwills at gmail.com (Robert Wills) Date: Mon Aug 3 05:10:16 2009 Subject: [Haskell-cafe] ANN: yst 0.2.1 In-Reply-To: <20090803010500.GA13034@protagoras.phil.berkeley.edu> References: <20090803010500.GA13034@protagoras.phil.berkeley.edu> Message-ID: <4A76ADF0.3020603@gmail.com> I had a play with this yesterday and thought it looked very useful (like all of John MacFarlane's tools). I'm probably going to use it for a site I'm working on. -Rob From sebastian.sylvan at gmail.com Mon Aug 3 05:44:47 2009 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Mon Aug 3 05:25:41 2009 Subject: [Haskell-cafe] Writing a pnm file In-Reply-To: <925823.69827.qm@web112512.mail.gq1.yahoo.com> References: <752929.99696.qm@web112511.mail.gq1.yahoo.com> <3d96ac180908020900s2fad3769h516ac0e7f677b303@mail.gmail.com> <925823.69827.qm@web112512.mail.gq1.yahoo.com> Message-ID: <3d96ac180908030244j229a884bvb2734fe9a585a95e@mail.gmail.com> On Mon, Aug 3, 2009 at 6:38 AM, CK Kashyap wrote: > Thanks Sebastian, > ppm module is indeed very useful. So, I guess my question then just boils > down to, how can I write a function to mimic the setPixel function -> > > Basically, a blank white image would look like this (as per ppm module) > [ > [ (255, 255, 255) , (255, 255, 255) , (255, 255, 255) ] , -- 3 columns > of row 1 > [ (255, 255, 255) , (255, 255, 255) , (255, 255, 255) ] --- 3 > columns of row 2 > ] > > setPixel x y r g b when called like this - setPixel 0,0,255,0,0 > > [ > [ (255, 0, 0) , (255, 255, 255) , (255, 255, 255) ] , -- 3 columns of > row 1 > [ (255, 255, 255) , (255, 255, 255) , (255, 255, 255) ] --- 3 > columns of row 2 > ] > > What would be a good way to implement such a function? > Well you could start by writing a function like: adjustElem :: Int -> ( a -> a ) -> [a] -> [a] That would basically apply a function to a specific element in a list (indexed by the first parameter). Look at splitAt in Data.List, it may be useful. Then you can use this in a nested way, by calling adjustElem to modify the row you're interested in, and the function you pass in to adjust that row would in turn call adjustElem on the specific pixel in that row). However, this may be very slow. If you don't care about speed it'll work fine, but if you really do want to build up an image by successive single-pixel modifications, you should consider first using an Array and accumArray, this will be much faster as internally accumArray can use a mutable array (while the external interface is still pure). Sebastian -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090803/98808b13/attachment.html From ck_kashyap at yahoo.com Mon Aug 3 06:17:27 2009 From: ck_kashyap at yahoo.com (CK Kashyap) Date: Mon Aug 3 05:58:24 2009 Subject: [Haskell-cafe] Writing a pnm file In-Reply-To: <3d96ac180908030244j229a884bvb2734fe9a585a95e@mail.gmail.com> References: <752929.99696.qm@web112511.mail.gq1.yahoo.com> <3d96ac180908020900s2fad3769h516ac0e7f677b303@mail.gmail.com> <925823.69827.qm@web112512.mail.gq1.yahoo.com> <3d96ac180908030244j229a884bvb2734fe9a585a95e@mail.gmail.com> Message-ID: <929139.71841.qm@web112503.mail.gq1.yahoo.com> Thanks Sebastian, Array/accumArray sounds like what I am looking for. Int -> ( a -> a ) -> [a] -> [a] approach, would it not be expensive on memory as well? Or is it just speed? Regards, Kashyap ________________________________ From: Sebastian Sylvan To: CK Kashyap Cc: haskell-cafe@haskell.org Sent: Monday, August 3, 2009 3:14:47 PM Subject: Re: [Haskell-cafe] Writing a pnm file On Mon, Aug 3, 2009 at 6:38 AM, CK Kashyap wrote: Thanks Sebastian, >ppm module is indeed very useful. So, I guess my question then just boils down to, how can I write a function to mimic the setPixel function -> > >Basically, a blank white image would look like this (as per ppm module) >[ > [ (255, 255, 255) , (255, 255, 255) , (255, 255, 255) ] , -- 3 columns of row 1 > [ (255, 255, 255) , (255, 255, 255) , (255, 255, 255) ] --- 3 columns of row 2 >>] > >setPixel x y r g b when called like this - setPixel 0,0,255,0,0 > >[ > [ (255, 0, 0) , (255, 255, 255) , (255, 255, 255) ] , -- 3 columns of row 1 > [ (255, 255, 255) , (255, 255, 255) , (255, 255, 255) ] --- 3 columns of row 2 >>] > >What would be a good way to implement such a function? > Well you could start by writing a function like: adjustElem :: Int -> ( a -> a ) -> [a] -> [a] That would basically apply a function to a specific element in a list (indexed by the first parameter). Look at splitAt in Data.List, it may be useful. Then you can use this in a nested way, by calling adjustElem to modify the row you're interested in, and the function you pass in to adjust that row would in turn call adjustElem on the specific pixel in that row). However, this may be very slow. If you don't care about speed it'll work fine, but if you really do want to build up an image by successive single-pixel modifications, you should consider first using an Array and accumArray, this will be much faster as internally accumArray can use a mutable array (while the external interface is still pure). Sebastian -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090803/45c3fe07/attachment-0001.html From nfjinjing at gmail.com Mon Aug 3 06:17:59 2009 From: nfjinjing at gmail.com (Jinjing Wang) Date: Mon Aug 3 05:58:52 2009 Subject: [Haskell-cafe] ANN: yst 0.2.1 In-Reply-To: <20090803010500.GA13034@protagoras.phil.berkeley.edu> References: <20090803010500.GA13034@protagoras.phil.berkeley.edu> Message-ID: <81ea7d400908030317v4dbaddc9t2b622a7a9fc87050@mail.gmail.com> It's possible to serve the generated site with maid, in case apache is not available: cabal update cabal install maid yst create testsite cd testsite yst cd site maid now goto http://localhost:3000/ On Mon, Aug 3, 2009 at 9:05 AM, John MacFarlane wrote: > I'm pleased to announce the release of yst, now available on HackageDB. > yst generates static websites from YAML or CSV data files and > StringTemplates. This approach combines the speed, security, and ease of > deployment of a static website with the flexibility and maintainability > of a dynamic site that separates presentation and data. > > The easiest way to get a feel for yst is to try it: > > cabal update > cabal install yst > yst create testsite > cd testsite > yst > > yst attempts to fill a niche between two kinds of site creation tools. > On the one hand you have simple static site generators like webgen, > webby, nanoc, and my old custom system using make and pandoc. On the > other hand, you have dynamic web frameworks like rails and django. > For my own smallish websites, I found that the dynamic frameworks were > overkill. Nobody but me was going to edit the pages, and I didn't > want the trouble of writing and deploying a dynamic site, setting up > a web server, and administering a database. A static site would be > faster, easier to deploy, and more secure. But the dynamic frameworks > offered one thing that the static site generators did not: an easy way > to separate data from presentation. This was becoming increasingly > important to me as I found myself constantly updating the same > information (say, publication data for a paper) in multiple places (say, > a LaTeX CV and a differently formatted web listing of papers). > > What I wanted was a site generation tool that used YAML text files > as a database and allowed different kinds of documents to be produced > from the same data. ?I couldn't find anything that did just what I > wanted, so I wrote yst. By way of illustration, here are the build > instructions for HTML and LaTeX versions of a CV, plus a web page with a > list of papers: > > - url: cv.html > ?title: CV > ?template: cv.st > ?data_common: ?&cvdata > ? ?contact: from contact.yaml > ? ?jobsbyemployer: from jobs.yaml order by start group by employer > ? ?degrees: from degrees.yaml order by year desc > ? ?awards: from awards.yaml order by year desc group by title > ? ?papers: from papers.yaml order by year desc where (not (type = 'review')) > ? ?reviews: from papers.yaml order by year desc where type = 'review' > ? ?talks: from talks.yaml where date < '2009-09-01' order by date desc group by title > ? ?dissertations: from dissertations.yaml order by role then year group by role > ? ?theses: from theses.yaml order by year then student > ? ?courses: from courses.yaml order by number group by title > ?data: > ? ?<<: ?*cvdata > ? ?html: yes > > - url: cv.tex > ?title: CV > ?inmenu: no > ?template: cv.st > ?layout: layout.tex.st > ?data: > ? ?<<: ?*cvdata > ? ?html: yes > > - url: papers.html > ?title: Papers > ?template: papers.st > ?data: > ? ?papersbyyear: ?from papers.yaml order by year desc then title group by year > > yst's query language is limited, and there are lots of things you can > do with a full-fledged database that you can't do with yst. But yst > is ideal, I think, for small to medium data-driven sites that are > maintained by a single person who likes working with plain text. It > scratched my itch, anyway, and I release it in case anyone else has the > same itch. > > Code, documentation, and bug reports: ?http://github.com/jgm/yst/tree/master > > John > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- jinjing From asviraspossible at gmail.com Mon Aug 3 08:32:07 2009 From: asviraspossible at gmail.com (Victor Nazarov) Date: Mon Aug 3 08:13:01 2009 Subject: [Haskell-cafe] FastCGI error handling Message-ID: I've been trying to write some simple web application in haskell using FastCGI, HDBC and HStringTemplate. I've got stuck with the following problem. HDBC throws some exceptions and I wanted them to be caught and logged. The code was: -- Main.hs module Main (main) where ... import Control.Concurrent import Network.FastCGI driver :: CGI CGIResult driver = ... main :: IO () main = runFastCGIConcurrent' forkIO 10 (handleErrors test) But all I've got on the page and in the log is "SomeException" string. I've tried the workaround: -- Main.hs module Main (main) where import Network.FastCGI import Control.Exception import System.IO driver :: CGI CGIResult driver = ... ... main :: IO () main = runFastCGI driver `catch` \ex -> hPutStr stderr $ show (ex::SomeException) And this worked fine. I've got a detaied SqlException string in the log file. So I've decided to update exception handling in CGI package and written the following module: -- Network/CGI/Monad/NewException.hs module Network.CGI.Monad.NewException where import Prelude hiding (catch) import Control.Exception import Control.Monad import Control.Monad.Writer import Control.Monad.Reader import Network.CGI.Monad hiding (throwCGI, catchCGI, tryCGI) import Network.CGI (outputInternalServerError) -- | Throw an exception in a CGI monad. The monad is required to be -- a 'MonadIO', so that we can use 'throwIO' to guarantee ordering. throwCGI :: (MonadCGI m, MonadIO m, Exception e) => e -> m a throwCGI = liftIO . throwIO -- | Catches any expection thrown by a CGI action, and uses the given -- exception handler if an exception is thrown. catchCGI :: (Exception e) => CGI a -> (e -> CGI a) -> CGI a catchCGI c h = tryCGI c >>= either h return handleCGI :: (Exception e) => (e -> CGI a) -> CGI a -> CGI a handleCGI = flip catchCGI -- | Catches any exception thrown by an CGI action, and returns either -- the exception, or if no exception was raised, the result of the action. tryCGI :: (Exception e) => CGI a -> CGI (Either e a) tryCGI (CGIT c) = CGIT (ReaderT (\r -> WriterT (f (runWriterT (runReaderT c r))))) where f = liftM (either (\ex -> (Left ex,mempty)) (\(a,w) -> (Right a,w))) . try handleErrors = handleCGI outputException outputException e = outputInternalServerError [show (e :: SomeException)] Then I've updated Main.hs accordingly: module Main (main) where ... import Control.Concurrent import Network.FastCGI hiding (throwCGI, catchCGI, tryCGI, handleErrors, outputException) import Network.CGI.Monad.NewException driver :: CGI CGIResult driver = ... main :: IO () -- main = runFastCGIConcurrent' forkIO 10 (handleErrors test) -- This allways gives internal error without a chance to find out what happens main = runFastCGI $ handleErrors test -- This works fine So one variant of main function works, the other allways gives no output. What can be the case? -- Victor Nazarov From asviraspossible at gmail.com Mon Aug 3 08:51:24 2009 From: asviraspossible at gmail.com (Victor Nazarov) Date: Mon Aug 3 08:32:17 2009 Subject: [Haskell-cafe] Re: FastCGI error handling In-Reply-To: References: Message-ID: On Mon, Aug 3, 2009 at 4:32 PM, Victor Nazarov wrote: > I've been trying to write some simple web application in haskell using > FastCGI, HDBC and HStringTemplate. I've got stuck with the following > problem. > [snip] > > main :: IO () > -- main = runFastCGIConcurrent' forkIO 10 (handleErrors test) -- This > allways gives internal error without a chance to find out what happens > main = runFastCGI $ handleErrors test -- This works fine > > So one variant of main function works, the other allways gives no > output. What can be the case? > The problem seems to be GHC's -threaded flag. Everything works fine with this flag. -- Victor Nazarov From tanimoto at arizona.edu Mon Aug 3 10:20:43 2009 From: tanimoto at arizona.edu (Paulo Tanimoto) Date: Mon Aug 3 10:01:56 2009 Subject: [Haskell-cafe] ANNOUNCE: The Haskell Platform 2009.2.0.2 In-Reply-To: <20090803062757.GA16033@narnia> References: <20090801000107.GM3854@whirlpool.galois.com> <20090803062757.GA16033@narnia> Message-ID: Hi Alecs, On Mon, Aug 3, 2009 at 1:27 AM, Alecs King wrote: > Thanks for the hard work. > > But there's a problem of the source tarball. ?scripts/build.sh skips > building already-installed pkgs -- but scripts/install.sh does not skip > installing them. ?So 'make install' fails (err: "The ${PKG}/Setup script > does not exist or cannot be run") if there are some pkgs that have been > skipped building. > > A quick(-and-dirty) hot fix: -- code copied from build.sh > > --- > ?scripts/install.sh | ? 18 ++++++++++++++---- > ?1 file changed, 14 insertions(+), 4 deletions(-) > > Index: haskell-platform-2009.2.0.2/scripts/install.sh > =================================================================== > --- haskell-platform-2009.2.0.2.orig/scripts/install.sh > +++ haskell-platform-2009.2.0.2/scripts/install.sh > @@ -34,13 +34,23 @@ install_pkg () { > ? fi > ?} > > +# Is this exact version of the package already installed? > +is_pkg_installed () { > + ?PKG_VER=$1 > + ?grep " ${PKG_VER} " installed.packages > /dev/null 2>&1 > +} > + > ?# Actually do something! > ?cd packages > ?for pkg in `cat platform.packages`; do > - ?cd "${pkg}" || die "The directory for the component ${PKG} is missing" > - ?echo "Installing ${pkg}..." > - ?install_pkg ${pkg} > - ?cd .. > + ?if is_pkg_installed "${pkg}"; then > + ? ?echo "Platform package ${pkg} is already installed. Skipping..." > + ?else > + ? ?cd "${pkg}" || die "The directory for the component ${PKG} is missing" > + ? ?echo "Installing ${pkg}..." > + ? ?install_pkg ${pkg} > + ? ?cd .. > + ?fi > ?done > > ?echo > > > -- > Alecs King Yes, I ran into that too. There's a ticket here: http://trac.haskell.org/haskell-platform/ticket/84 Thanks! Paulo From jgm at berkeley.edu Mon Aug 3 12:12:11 2009 From: jgm at berkeley.edu (John MacFarlane) Date: Mon Aug 3 11:53:18 2009 Subject: [Haskell-cafe] Re: ANN: yst 0.2.1 In-Reply-To: <81ea7d400908030317v4dbaddc9t2b622a7a9fc87050@mail.gmail.com> References: <20090803010500.GA13034@protagoras.phil.berkeley.edu> <81ea7d400908030317v4dbaddc9t2b622a7a9fc87050@mail.gmail.com> Message-ID: <20090803161211.GA20467@protagoras.phil.berkeley.edu> Thanks. I'll put a note to this effect in the README. John +++ Jinjing Wang [Aug 03 09 18:17 ]: > It's possible to serve the generated site with maid, in case apache is > not available: > > cabal update > cabal install maid > > yst create testsite > cd testsite > yst > > cd site > maid > > now goto http://localhost:3000/ > > On Mon, Aug 3, 2009 at 9:05 AM, John MacFarlane wrote: > > I'm pleased to announce the release of yst, now available on HackageDB. > > yst generates static websites from YAML or CSV data files and > > StringTemplates. This approach combines the speed, security, and ease of > > deployment of a static website with the flexibility and maintainability > > of a dynamic site that separates presentation and data. > > > > The easiest way to get a feel for yst is to try it: > > > > cabal update > > cabal install yst > > yst create testsite > > cd testsite > > yst > > > > yst attempts to fill a niche between two kinds of site creation tools. > > On the one hand you have simple static site generators like webgen, > > webby, nanoc, and my old custom system using make and pandoc. On the > > other hand, you have dynamic web frameworks like rails and django. > > For my own smallish websites, I found that the dynamic frameworks were > > overkill. Nobody but me was going to edit the pages, and I didn't > > want the trouble of writing and deploying a dynamic site, setting up > > a web server, and administering a database. A static site would be > > faster, easier to deploy, and more secure. But the dynamic frameworks > > offered one thing that the static site generators did not: an easy way > > to separate data from presentation. This was becoming increasingly > > important to me as I found myself constantly updating the same > > information (say, publication data for a paper) in multiple places (say, > > a LaTeX CV and a differently formatted web listing of papers). > > > > What I wanted was a site generation tool that used YAML text files > > as a database and allowed different kinds of documents to be produced > > from the same data. ?I couldn't find anything that did just what I > > wanted, so I wrote yst. By way of illustration, here are the build > > instructions for HTML and LaTeX versions of a CV, plus a web page with a > > list of papers: > > > > - url: cv.html > > ?title: CV > > ?template: cv.st > > ?data_common: ?&cvdata > > ? ?contact: from contact.yaml > > ? ?jobsbyemployer: from jobs.yaml order by start group by employer > > ? ?degrees: from degrees.yaml order by year desc > > ? ?awards: from awards.yaml order by year desc group by title > > ? ?papers: from papers.yaml order by year desc where (not (type = 'review')) > > ? ?reviews: from papers.yaml order by year desc where type = 'review' > > ? ?talks: from talks.yaml where date < '2009-09-01' order by date desc group by title > > ? ?dissertations: from dissertations.yaml order by role then year group by role > > ? ?theses: from theses.yaml order by year then student > > ? ?courses: from courses.yaml order by number group by title > > ?data: > > ? ?<<: ?*cvdata > > ? ?html: yes > > > > - url: cv.tex > > ?title: CV > > ?inmenu: no > > ?template: cv.st > > ?layout: layout.tex.st > > ?data: > > ? ?<<: ?*cvdata > > ? ?html: yes > > > > - url: papers.html > > ?title: Papers > > ?template: papers.st > > ?data: > > ? ?papersbyyear: ?from papers.yaml order by year desc then title group by year > > > > yst's query language is limited, and there are lots of things you can > > do with a full-fledged database that you can't do with yst. But yst > > is ideal, I think, for small to medium data-driven sites that are > > maintained by a single person who likes working with plain text. It > > scratched my itch, anyway, and I release it in case anyone else has the > > same itch. > > > > Code, documentation, and bug reports: ?http://github.com/jgm/yst/tree/master > > > > John > > > > _______________________________________________ > > Haskell-Cafe mailing list > > Haskell-Cafe@haskell.org > > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > > > > -- > jinjing > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From psujkov at gmail.com Mon Aug 3 13:46:30 2009 From: psujkov at gmail.com (Paul Sujkov) Date: Mon Aug 3 13:27:22 2009 Subject: [Haskell-cafe] [Haskell Cafe] Troubles with StateT and Parsec Message-ID: <9760562b0908031046p6bebe3s4261bddabb8eb46c@mail.gmail.com> Hi haskellers, I have a few problems using monad transformers. I have such two functions: parseSyslog :: StateT Integer Parser TimeStamp parseString :: StateT Integer Parser LogString and the following code: parseString = do -- string parse here, all in the form of lift $ stamp <- lift $ lexeme parseTimestamp -- "timestamp" message <- lift $ manyTill anyToken eof -- "message" return (LogString <...parsed values here...> (check stamp console message) <...more parsed values here...>) where check :: (Maybe TimeStamp) -> Console -> String -> Maybe TimeStamp check Nothing Syslog message = case (lift parse $ parseSyslog "" message) of Left err -> Nothing Right res -> Just res <...other clauses here...> this code seems quite intuitive to me, however it doesn't compile with a king error: Couldn't match kind `(* -> *) -> * -> *' against `?? -> ? -> *' When matching the kinds of `t :: (* -> *) -> * -> *' and `(->) :: ?? -> ? -> *' Probable cause: `lift' is applied to too many arguments In the first argument of `($)', namely `lift parse' I'm not so familiar with monad transformers whatsoever, so I'll be very happy if someone can show me the right way. The code compile nicely if I use "parse" line in a such way: check Nothing Syslog message = case (parse (evalStateT parseSyslog 0) "" message) of but this is not what I really want. To be accurate, here is the sequence which I do want to have in the code: some user state is initialized; parseString gets called many times and changes the state via call to the parseSyslog (that is the only function that really uses/affects user state, everything else is pure Parsec code with it's own internal state). Two main problems that I have now is: 1) impossibility to use parse/parseTest functions with the (StateT Parser ) argument. I want it to be lifted somehow, but cannot see how 2) too many lifts in the code. I have only one function that really affects state, but code is filled with lifts from StateT to underlying Parser Sorry if the questions are silly; any help is appreciated -- Regards, Paul Sujkov -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090803/6f44599b/attachment.html From dvde at gmx.net Mon Aug 3 14:35:25 2009 From: dvde at gmx.net (Daniel van den Eijkel) Date: Mon Aug 3 14:16:36 2009 Subject: [Haskell-cafe] [Haskell Cafe] Troubles with StateT and Parsec In-Reply-To: <9760562b0908031046p6bebe3s4261bddabb8eb46c@mail.gmail.com> References: <9760562b0908031046p6bebe3s4261bddabb8eb46c@mail.gmail.com> Message-ID: <4A772DED.1030607@gmx.net> Hi Paul, the expression (lift parse $ parseSyslog "" message) has the same meaning as (lift parse (parseSyslog "" message)), so you are indeed applying lift to two arguments, while it expects one. Probably you forgot the $ after lift? Best regards, Daniel Paul Sujkov schrieb: > Hi haskellers, > > I have a few problems using monad transformers. I have such two functions: > > parseSyslog :: StateT Integer Parser TimeStamp > parseString :: StateT Integer Parser LogString > > and the following code: > parseString = do > -- string parse here, all in the form of lift $ > stamp <- lift $ lexeme parseTimestamp -- "timestamp" > message <- lift $ manyTill anyToken eof -- "message" > return (LogString <...parsed values here...> (check stamp console > message) <...more parsed values here...>) > where check :: (Maybe TimeStamp) -> Console -> String -> Maybe > TimeStamp > check Nothing Syslog message = case (lift parse $ > parseSyslog "" message) of > Left err -> Nothing > Right res -> Just res > <...other clauses here...> > > this code seems quite intuitive to me, however it doesn't compile with > a king error: > > Couldn't match kind `(* -> *) -> * -> *' against `?? -> ? -> *' > When matching the kinds of `t :: (* -> *) -> * -> *' and > `(->) :: ?? -> ? -> *' > Probable cause: `lift' is applied to too many arguments > In the first argument of `($)', namely `lift parse' > > I'm not so familiar with monad transformers whatsoever, so I'll be > very happy if someone can show me the right way. The code compile > nicely if I use "parse" line in a such way: > > check Nothing Syslog message = case (parse (evalStateT parseSyslog 0) > "" message) of > > but this is not what I really want. To be accurate, here is the > sequence which I do want to have in the code: > > some user state is initialized; parseString gets called many times and > changes the state via call to the parseSyslog (that is the only > function that really uses/affects user state, everything else is pure > Parsec code with it's own internal state). Two main problems that I > have now is: > > 1) impossibility to use parse/parseTest functions with the (StateT > Parser ) argument. I want it to be lifted > somehow, but cannot see how > 2) too many lifts in the code. I have only one function that really > affects state, but code is filled with lifts from StateT to underlying > Parser > > Sorry if the questions are silly; any help is appreciated > > -- > Regards, Paul Sujkov > ------------------------------------------------------------------------ > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From michael at snoyman.com Mon Aug 3 15:20:08 2009 From: michael at snoyman.com (Michael Snoyman) Date: Mon Aug 3 15:01:03 2009 Subject: [Haskell-cafe] Re: ANN: yst 0.2.1 In-Reply-To: <20090803161211.GA20467@protagoras.phil.berkeley.edu> References: <20090803010500.GA13034@protagoras.phil.berkeley.edu> <81ea7d400908030317v4dbaddc9t2b622a7a9fc87050@mail.gmail.com> <20090803161211.GA20467@protagoras.phil.berkeley.edu> Message-ID: <29bf512f0908031220xf0795eekdbc05a00c0504129@mail.gmail.com> Hey John, I noticed that your code is using the Syck library for Yaml. How were you able to get it to deal with Unicode characters? I just wrote a new yaml library based on libyaml if you want to give it a shot (yaml on hackage). It doesn't support aliases, but is otherwise feature complete. Michael On Mon, Aug 3, 2009 at 7:12 PM, John MacFarlane wrote: > Thanks. I'll put a note to this effect in the README. > > John > > +++ Jinjing Wang [Aug 03 09 18:17 ]: > > It's possible to serve the generated site with maid, in case apache is > > not available: > > > > cabal update > > cabal install maid > > > > yst create testsite > > cd testsite > > yst > > > > cd site > > maid > > > > now goto http://localhost:3000/ > > > > On Mon, Aug 3, 2009 at 9:05 AM, John MacFarlane wrote: > > > I'm pleased to announce the release of yst, now available on HackageDB. > > > yst generates static websites from YAML or CSV data files and > > > StringTemplates. This approach combines the speed, security, and ease > of > > > deployment of a static website with the flexibility and maintainability > > > of a dynamic site that separates presentation and data. > > > > > > The easiest way to get a feel for yst is to try it: > > > > > > cabal update > > > cabal install yst > > > yst create testsite > > > cd testsite > > > yst > > > > > > yst attempts to fill a niche between two kinds of site creation tools. > > > On the one hand you have simple static site generators like webgen, > > > webby, nanoc, and my old custom system using make and pandoc. On the > > > other hand, you have dynamic web frameworks like rails and django. > > > For my own smallish websites, I found that the dynamic frameworks were > > > overkill. Nobody but me was going to edit the pages, and I didn't > > > want the trouble of writing and deploying a dynamic site, setting up > > > a web server, and administering a database. A static site would be > > > faster, easier to deploy, and more secure. But the dynamic frameworks > > > offered one thing that the static site generators did not: an easy way > > > to separate data from presentation. This was becoming increasingly > > > important to me as I found myself constantly updating the same > > > information (say, publication data for a paper) in multiple places > (say, > > > a LaTeX CV and a differently formatted web listing of papers). > > > > > > What I wanted was a site generation tool that used YAML text files > > > as a database and allowed different kinds of documents to be produced > > > from the same data. I couldn't find anything that did just what I > > > wanted, so I wrote yst. By way of illustration, here are the build > > > instructions for HTML and LaTeX versions of a CV, plus a web page with > a > > > list of papers: > > > > > > - url: cv.html > > > title: CV > > > template: cv.st > > > data_common: &cvdata > > > contact: from contact.yaml > > > jobsbyemployer: from jobs.yaml order by start group by employer > > > degrees: from degrees.yaml order by year desc > > > awards: from awards.yaml order by year desc group by title > > > papers: from papers.yaml order by year desc where (not (type = > 'review')) > > > reviews: from papers.yaml order by year desc where type = 'review' > > > talks: from talks.yaml where date < '2009-09-01' order by date desc > group by title > > > dissertations: from dissertations.yaml order by role then year group > by role > > > theses: from theses.yaml order by year then student > > > courses: from courses.yaml order by number group by title > > > data: > > > <<: *cvdata > > > html: yes > > > > > > - url: cv.tex > > > title: CV > > > inmenu: no > > > template: cv.st > > > layout: layout.tex.st > > > data: > > > <<: *cvdata > > > html: yes > > > > > > - url: papers.html > > > title: Papers > > > template: papers.st > > > data: > > > papersbyyear: from papers.yaml order by year desc then title group > by year > > > > > > yst's query language is limited, and there are lots of things you can > > > do with a full-fledged database that you can't do with yst. But yst > > > is ideal, I think, for small to medium data-driven sites that are > > > maintained by a single person who likes working with plain text. It > > > scratched my itch, anyway, and I release it in case anyone else has the > > > same itch. > > > > > > Code, documentation, and bug reports: > http://github.com/jgm/yst/tree/master > > > > > > John > > > > > > _______________________________________________ > > > Haskell-Cafe mailing list > > > Haskell-Cafe@haskell.org > > > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > > > > > > > > > -- > > jinjing > > _______________________________________________ > > 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090803/a8123fc7/attachment.html From lemming at henning-thielemann.de Mon Aug 3 15:38:55 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Mon Aug 3 15:17:45 2009 Subject: [Haskell-cafe] Hackage and version control In-Reply-To: <20090720042525.3e02b4ae@fedora> References: <5ae4f2ba0907200126j56a497earb06ae885dbb7bb81@mail.gmail.com> <20090720042525.3e02b4ae@fedora> Message-ID: <4A773CCF.6000203@henning-thielemann.de> Robin Green schrieb: > Yes, and darcs repos can also be hosted on patch-tag.com. > community.haskell.org requires you to wait for a volunteer to review > every new project request. Although, you don't need to make a > project request if you only want a 1-developer repository. And by the > way, it only hosts Haskell-related projects, not arbitrary darcs > repositories. You can put repositories into your public_html and see them under code.haskell.org/~user/ . I use this often for small projects. As soon as more people become interested in a package I request a new project. From bos at serpentine.com Mon Aug 3 15:50:09 2009 From: bos at serpentine.com (Bryan O'Sullivan) Date: Mon Aug 3 15:31:01 2009 Subject: [Haskell-cafe] [Haskell Cafe] Troubles with StateT and Parsec In-Reply-To: <9760562b0908031046p6bebe3s4261bddabb8eb46c@mail.gmail.com> References: <9760562b0908031046p6bebe3s4261bddabb8eb46c@mail.gmail.com> Message-ID: On Mon, Aug 3, 2009 at 10:46 AM, Paul Sujkov wrote: > parseSyslog :: StateT Integer Parser TimeStamp > parseString :: StateT Integer Parser LogString > > and the following code: > parseString = do [...] > Without real code to look at, it's impossible to properly debug the errors in your pseudocode above. For instance, your type signatures aren't real, and you don't mention which version of Parsec you're using. Regardless, you shouldn't need to use monad transformers with Parsec, as it has its own support for managing state that gives you exactly the same features as StateT. See the getState, setState, and updateState functions. I notice that you try to explain why you are using StateT later in your message, but I don't understand your description. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090803/f656ef83/attachment.html From lrpalmer at gmail.com Mon Aug 3 15:55:09 2009 From: lrpalmer at gmail.com (Luke Palmer) Date: Mon Aug 3 15:36:01 2009 Subject: [Haskell-cafe] [Haskell Cafe] Troubles with StateT and Parsec In-Reply-To: <9760562b0908031046p6bebe3s4261bddabb8eb46c@mail.gmail.com> References: <9760562b0908031046p6bebe3s4261bddabb8eb46c@mail.gmail.com> Message-ID: <7ca3f0160908031255x63cde9baye043b576b5bde80a@mail.gmail.com> On Mon, Aug 3, 2009 at 11:46 AM, Paul Sujkov wrote: > 2) too many lifts in the code. I have only one function that really affects > state, but code is filled with lifts from StateT to underlying Parser You do know you can do this, right? do x <- get put (x + 1) lift $ do etc etc etc If you only have one use of the state, you should be able to write the rest of the parser as a regular Parsec without the StateT (including type signatures), and lift it all at once. Luke From nicolas.pouillard at gmail.com Mon Aug 3 16:01:02 2009 From: nicolas.pouillard at gmail.com (Nicolas Pouillard) Date: Mon Aug 3 15:43:23 2009 Subject: [Haskell-cafe] ANN: yst 0.2.1 In-Reply-To: <20090803010500.GA13034@protagoras.phil.berkeley.edu> References: <20090803010500.GA13034@protagoras.phil.berkeley.edu> Message-ID: <1249329568-sup-6635@ausone.home> Excerpts from John MacFarlane's message of Mon Aug 03 03:05:00 +0200 2009: > I'm pleased to announce the release of yst, now available on HackageDB. Great! I've used it for a web site of mine today with success. -- Nicolas Pouillard http://nicolaspouillard.fr From sebastian.sylvan at gmail.com Mon Aug 3 16:19:21 2009 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Mon Aug 3 16:00:14 2009 Subject: [Haskell-cafe] Writing a pnm file In-Reply-To: <929139.71841.qm@web112503.mail.gq1.yahoo.com> References: <752929.99696.qm@web112511.mail.gq1.yahoo.com> <3d96ac180908020900s2fad3769h516ac0e7f677b303@mail.gmail.com> <925823.69827.qm@web112512.mail.gq1.yahoo.com> <3d96ac180908030244j229a884bvb2734fe9a585a95e@mail.gmail.com> <929139.71841.qm@web112503.mail.gq1.yahoo.com> Message-ID: <3d96ac180908031319x6d67c195pca13ef22c1c9af8@mail.gmail.com> On Mon, Aug 3, 2009 at 11:17 AM, CK Kashyap wrote: > Thanks Sebastian, > Array/accumArray sounds like what I am looking for. > > Int -> ( a -> a ) -> [a] -> [a] > approach, would it not be expensive on memory as well? Or is it just speed? > Well memory will be garbage collected fairly quickly so I don' think that's an issue, other than the effects on speed that the extra allocations would have. It's probably mainly speed because each pixel would have time complexity O(n+m) rather than O(1) for an n*m image... -- Sebastian Sylvan +44(0)7857-300802 UIN: 44640862 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090803/6d4475da/attachment.html From jgm at berkeley.edu Mon Aug 3 16:23:11 2009 From: jgm at berkeley.edu (John MacFarlane) Date: Mon Aug 3 16:04:17 2009 Subject: [Haskell-cafe] Re: ANN: yst 0.2.1 In-Reply-To: <29bf512f0908031220xf0795eekdbc05a00c0504129@mail.gmail.com> References: <20090803010500.GA13034@protagoras.phil.berkeley.edu> <81ea7d400908030317v4dbaddc9t2b622a7a9fc87050@mail.gmail.com> <20090803161211.GA20467@protagoras.phil.berkeley.edu> <29bf512f0908031220xf0795eekdbc05a00c0504129@mail.gmail.com> Message-ID: <20090803202311.GA22390@protagoras.phil.berkeley.edu> +++ Michael Snoyman [Aug 03 09 22:20 ]: > Hey John, > > I noticed that your code is using the Syck library for Yaml. How were you > able to get it to deal with Unicode characters? I just wrote a new yaml > library based on libyaml if you want to give it a shot (yaml on hackage). > It doesn't support aliases, but is otherwise feature complete. > > Michael Oh, rats, I hadn't realized that Syck had that limitation! I think I can work around it, but I'll have to look into it. I wasn't able to install your yaml library: % cabal install yaml Resolving dependencies... Configuring yaml-0.0.0... Preprocessing library yaml-0.0.0... dist/build/Text/Libyaml.chs.h:2:31: error: ../../../c/helper.h: No such file or directory c2hs: Error during preprocessing custom header file cabal: Error: some packages failed to install: yaml-0.0.0 failed during the building phase. The exception was: exit: ExitFailure 1 I have debian libyaml-dev installed. Any ideas? Also, how hard would it be to support aliases in your package? I use them. John From lemming at henning-thielemann.de Mon Aug 3 16:25:35 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Mon Aug 3 16:04:22 2009 Subject: [Haskell-cafe] Re: Simple quirk in behavior of `mod` In-Reply-To: References: <20090722113413.75469f813b58c2e0e98e8a30424d5d59.b2fbb0df6d.wbe@email03.secureserver.net> <50c1e0910907222209l75632f50xbb56ec82e3f7aceb@mail.gmail.com> Message-ID: <4A7747BF.3080406@henning-thielemann.de> Matthias G?rgens schrieb: >> Round-to-even means x.5 gets rounded to x if x is even and x+1 if x is >> odd. This is sometimes known as banker's rounding. > > OK. That's slightly unusual indeed. Modula-3 makes it too. Accidentally, I recently had a case where this rounding mode was really bad. I wanted to reduce pictures by arbitrary factors and for the sake of speed it was enough to just move the pixels from the source to their target position and don't do any interpolation. However for factor 2 reduction I got ugly patterns, because pixels accumulated around even target coordinates. From jgm at berkeley.edu Mon Aug 3 16:38:30 2009 From: jgm at berkeley.edu (John MacFarlane) Date: Mon Aug 3 16:19:37 2009 Subject: [Haskell-cafe] Re: ANN: yst 0.2.1 In-Reply-To: <20090803202311.GA22390@protagoras.phil.berkeley.edu> References: <20090803010500.GA13034@protagoras.phil.berkeley.edu> <81ea7d400908030317v4dbaddc9t2b622a7a9fc87050@mail.gmail.com> <20090803161211.GA20467@protagoras.phil.berkeley.edu> <29bf512f0908031220xf0795eekdbc05a00c0504129@mail.gmail.com> <20090803202311.GA22390@protagoras.phil.berkeley.edu> Message-ID: <20090803203830.GA22582@protagoras.phil.berkeley.edu> +++ John MacFarlane [Aug 03 09 13:23 ]: > +++ Michael Snoyman [Aug 03 09 22:20 ]: > > Hey John, > > > > I noticed that your code is using the Syck library for Yaml. How were you > > able to get it to deal with Unicode characters? I just wrote a new yaml > > library based on libyaml if you want to give it a shot (yaml on hackage). > > It doesn't support aliases, but is otherwise feature complete. > > > > Michael > > Oh, rats, I hadn't realized that Syck had that limitation! I think I > can work around it, but I'll have to look into it. Okay, I've found a workaround -- use Syck to parse a bytestring, then do my own decoding on string buffers in the resulting parse tree. Unicode in data files now works well. (Code now on github -- will be released soon.) John From jvranish at gmail.com Mon Aug 3 17:07:20 2009 From: jvranish at gmail.com (Job Vranish) Date: Mon Aug 3 16:48:12 2009 Subject: [Haskell-cafe] Re: Cyclic data declarations In-Reply-To: <4eff48ac0908021806r71622b21oc9f0799acccd5d13@mail.gmail.com> References: <4eff48ac0908012225j3a1dc7abh901859b95c5fa660@mail.gmail.com> <4eff48ac0908021806r71622b21oc9f0799acccd5d13@mail.gmail.com> Message-ID: I ran into exactly the same problem while working on my own toy language :) I used a fixed point datatype to solve it as well. This is really the best way, as it lets your expression (or statment) type be a member of functor/foldable/traversable, which is super handy. I made a graph module that lets me convert any fixpointed functor into a graph, which made the rest of that whole process much nicer. If you're interested in the graph module, let me know :) I think that in an ideal world haskell would have some way of allowing infinite types if you asked for them explicitly (say in the type signature somehow) and then just automatically wrap/unwrap everything with newtypes behind the scenes (well maybe in an ideal world it wouldn't have to do this either). This wouldn't change the underlying semantics, but would get rid of alot of messyness. Infinite types are possible, My toy language infers infinite types just fine :) and I think Ocaml has an option for them, but niether of those have type classes so I'm not sure how compatable the idea is with haskell in general. - Job On Sun, Aug 2, 2009 at 9:06 PM, Michal D. wrote: > > > > newtype StmtRec = StmtRec (Stmt [StmtRec]) > > > > That's pretty much were I threw in the towel last night. Except I had > a bunch of places where I had to add the extra constructor statements. > I wish there was a solution that didn't require these... they really > butcher pattern matching clarity. > > > will do. More generally, you can use > > > > newtype Fix f = In { out :: f (Fix f) } > > > > and define > > > > type StmtRec = Fix ([] `O` Stmt) > > > > where O denotes composition of functors > > > > newtype O f g a = O (f (g a)) > > > > Thanks for that! This provoked some thought on my part about what > exactly is going on. I think I could solve this if I added some way to > identify that a type parameter is actually referring to the whole > type. Say we had a reserved word "fixpoint" for this. Then we'd have > something like: > > data Stmt x = SIf x x > > then when we actually go to use it, it would be referred to as the type: > > "Stmt [fixpoint]" > > Which would get treated exactly like the data declaration: > > data Stmt = SIf [Stmt] [Stmt] > > I'll need to add the newtype declaration for the code but I'd be > interested if anyone had further thoughts on this topic. I have an > implementation of both approaches on a toy parser, but I doubt > anyone's interested in seeing that. > > Michal > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090803/7e4c707c/attachment.html From agocorona at gmail.com Mon Aug 3 17:41:29 2009 From: agocorona at gmail.com (Alberto G. Corona ) Date: Mon Aug 3 17:22:21 2009 Subject: Fwd: [Haskell-cafe] funct.prog. vs logic prog., practical Haskell In-Reply-To: References: <20090802102501.GA25860@pudlak.name> Message-ID: The middle road could be Curry , sorry, this Curry , a functional-logic language. I know that curry has gained a lot of interest from prolog programmers. There are compilers from Curry to Prolog. It is a haskell 98 implementation (more or less) with all logic programming features. It can be seen also as a logic language with haskell syntax. Therefore, its syntax is more mathematical, rather that the ugly clause-based syntax of Prolog, that is at odds with anything except with pure aristothelian logic. 2009/8/2 Thomas ten Cate On Sun, Aug 2, 2009 at 12:25, Petr Pudlak wrote: > > Hi all, > > > > I'd like to convince people at our university to pay more attention to > > functional languages, especially Haskell. Their arguments were that > > > > (1) Functional programming is more academic than practical. > > Which, even if it were true, is an argument *for* instead of *against* > teaching it at a university; that is what the word "academic" means, > after all... > > Thomas > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090803/444730a3/attachment.html From lemming at henning-thielemann.de Mon Aug 3 17:56:25 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Mon Aug 3 17:35:57 2009 Subject: [Haskell-cafe] Re: Proposal: TypeDirectedNameResolution In-Reply-To: References: <4A6DCE93.5020700@imn.htwk-leipzig.de> <89ca3d1f0907270929u53c3ae8ey14758557bf07e29b@mail.gmail.com> <2f9b2d30907281005u5bff3db4h19c59290b166a9ef@mail.gmail.com> Message-ID: <4A775D09.4080507@henning-thielemann.de> Heinrich Apfelmus schrieb: > Sure, overloading is useful. But to avoid headache in a polymorphic > language, I'd prefer a principled approach to it. Hence, I'm convinced > that there should be only one mechanism for overloading in Haskell; > which is type classes at the moment. > > It appears that type direction name disambiguation can be implemented > with (automatically generated) type classes? When thinking about how to make Haskell familiar to SQL programmers I also thought that a Haskell compiler might automatically generate a type class and according instances, such that an identifier like 'field' can be used for all record types that have a field with name 'field'. I'm sure Template Haskell programmers can achieve this already with todays GHC. In the meantime I'm happy with writing qualifications, type signatures and so on. I don't know why people like to avoid them at all costs. From lemming at henning-thielemann.de Mon Aug 3 17:59:48 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Mon Aug 3 17:38:35 2009 Subject: [Haskell-cafe] Re: Proposal: TypeDirectedNameResolution In-Reply-To: References: <4A6DCE93.5020700@imn.htwk-leipzig.de> <89ca3d1f0907270929u53c3ae8ey14758557bf07e29b@mail.gmail.com> <87ljm54w6b.fsf@malde.org> Message-ID: <4A775DD4.7050105@henning-thielemann.de> Heinrich Apfelmus schrieb: > Note that there are alternative solution for this particular problem. > For instance, a version of qualified with different semantics will do; > something like this > > import Data.List > import sometimes qualified Data.Map as Map Isn't that quite the same as import Data.Map as Map ? But you risk breaking packages when new qualifiers are added to imported modules. > > foo :: Map k a -- accepted with out qualifier 'Map' > -- because it's unambiguous > > bar m = map show m -- defaults to Data.List.map , > -- 'Map' prefix would be need in > -- cases of ambiguity > > The idea being that names only need to be qualified when they are > ambiguous, which Map and ByteString are not. From psujkov at gmail.com Mon Aug 3 18:42:12 2009 From: psujkov at gmail.com (Paul Sujkov) Date: Mon Aug 3 18:23:06 2009 Subject: [Haskell-cafe] [Haskell Cafe] Troubles with StateT and Parsec In-Reply-To: References: <9760562b0908031046p6bebe3s4261bddabb8eb46c@mail.gmail.com> Message-ID: <9760562b0908031542m3b269b5eod23ccfc1c4a84e6e@mail.gmail.com> Hi Bryan, GHC 6.10.1, Parsec 3.0.0 and type signatures are right from the code: they are actually real (except the ones with the ). I see now that it is really a better idea to use internal Parser state to collect the data I need to carry through, so in any case thank you I've sent two letters on topic not to the mail-list, so I'll quote them here: "to make the problem clear: I've changed parseSyslog function from Parser type to StateT Parser type (a parser with some additional user state); the question is: how should I use "parse" function, which expects Parser type signature for it's first argument? Am I right that I should lift parse function to the StateT transformer to achieve this?" "the Parser datatype from the Parsec library is itself a State monad; however, it's internal state is used for parsing purposes. What is a good practice to implement stateful parsers with Parsec? Using StateT transformer on top of the Parser type, or using it's own internal state? Or maybe there is some better way, that I am anaware of?" that's the state of things right now actually, but I think the solution is already clear. Thanks to everyone in the conversation :) 2009/8/3 Bryan O'Sullivan > On Mon, Aug 3, 2009 at 10:46 AM, Paul Sujkov wrote: > > >> parseSyslog :: StateT Integer Parser TimeStamp >> parseString :: StateT Integer Parser LogString >> >> and the following code: >> parseString = do [...] >> > > Without real code to look at, it's impossible to properly debug the errors > in your pseudocode above. For instance, your type signatures aren't real, > and you don't mention which version of Parsec you're using. > > Regardless, you shouldn't need to use monad transformers with Parsec, as it > has its own support for managing state that gives you exactly the same > features as StateT. See the getState, setState, and updateState functions. I > notice that you try to explain why you are using StateT later in your > message, but I don't understand your description. > -- Regards, Paul Sujkov -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090803/b3027646/attachment-0001.html From michael at snoyman.com Tue Aug 4 00:07:54 2009 From: michael at snoyman.com (Michael Snoyman) Date: Mon Aug 3 23:48:47 2009 Subject: [Haskell-cafe] C2HS issues on Hackage Message-ID: <29bf512f0908032107j37fbfa02x6239ac1d242c7cfb@mail.gmail.com> Hi all, I've written a Yaml library built on top of libyaml (the same C library at the core of Python's yaml library). All is well on my local system and my server; I'm currently using it in production. However, the build is failing on Hackage with the following build log: http://hackage.haskell.org/packages/archive/yaml/0.0.1/logs/failure/ghc-6.10 . It seems that whichever version of C2HS is installed on the server does not allow "type" (or perhaps other keywords?) to be used as C identifiers. Unfortunately, "type" is the name of a field in a C struct I need to integrate with. It's obviously not vital that I get it to compile on hackage, but 1) I'm worried this is a sign of a bigger problem, and 2) it's always nice to have the API documentation available online. Any suggestions? Thanks, Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090803/59170fc2/attachment.html From howard_b_golden at yahoo.com Tue Aug 4 00:50:28 2009 From: howard_b_golden at yahoo.com (Howard B. Golden) Date: Tue Aug 4 00:31:19 2009 Subject: [Haskell-cafe] Haskell interface files: Why used? What about same data in object files? Message-ID: <107818.80337.qm@web34307.mail.mud.yahoo.com> Hi, I am trying to understand the design of the Haskell interface files. Why are they a separate file rather than having the same data in the object file generated by the compiler? (Naively, it seems to me this would work also. Am I missing something?) Thanks. Howard B. Golden Northridge, California, USA From alexander.dunlap at gmail.com Tue Aug 4 01:40:31 2009 From: alexander.dunlap at gmail.com (Alexander Dunlap) Date: Tue Aug 4 01:21:43 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: <20090803234432.GK17991@whirlpool.galois.com> References: <20090803234432.GK17991@whirlpool.galois.com> Message-ID: <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> On Mon, Aug 3, 2009 at 4:44 PM, Don Stewart wrote: > > Following Simon M's advice, I look over the typical "batteries" > categories, using Python as input: > > ? ?http://docs.python.org/library/index.html > > The following things were missing from the current Platform. There are many. > How would you identify the top, say, 5 libs to add? > > -- Don > > > ? ?* String support > ? ? ? ? ?o pcre regexes [pcre-light] [regex-pcre] ? what?s our best regex lib? For something like this, it seems like all of the regex libs probably have pros and cons. It would be good if we could identify what these are and create a library that was the "best of all worlds" instead of just picking one and going with it. > ? ? ? ? ?o unicode text [text] [text-icu] ? packed, unicode text This is essential, although I don't know if it is stable enough for the platform (?). > ? ?* text > ? ? ? ? ?o pandoc ? markdown, reStructuredText, HTML, LaTeX, ConTeXt, Docbook, OpenDocument, ODT, RTF, MediaWiki, groff No. Pandoc is too actively developed to go into the HP. It's also much more of an end-user application than a "standard library" - it's applications are not general enough to be included in the standard distribution. > ? ?* math and numerics > ? ? ? ? ?o blas ? BLAS > ? ? ? ? ?o cmath ? C math functions > ? ? ? ? ?o dimensional ? physical dimensions > ? ? ? ? ?o fftw > ? ? ? ? ?o mersenne-random ? fast randoms The interfaces here should be unified more to create a general Haskell numerical library, IMO. > ? ?* compression > ? ? ? ? ?o bzip2 > ? ? ? ? ?o zip > ? ? ? ? ?o tar Definitely. > ? ?* file formats > ? ? ? ? ?o config parser This would be quite useful. > ? ?* crypto > ? ? ? ? ?o hmac, md5, sha, hashing Yes. > ? ?* systems > ? ? ? ? ?o getopt > ? ? ? ? ?o logging > ? ? ? ? ?o termio > ? ? ? ? ?o editline > ? ? ? ? ?o mmap All of these, at some point. > ? ?* Internet > ? ? ? ? ?o network-bytestring > ? ? ? ? ?o ssl > ? ? ? ? ?o json > ? ? ? ? ?o feed (rss, atom) > ? ? ? ? ?o mime > ? ? ? ? ?o base64 et al > ? ? ? ? ?o uuencode > ? ? ? ? ?o cgi > ? ? ? ? ?o fastcgi > ? ? ? ? ?o urls > ? ? ? ? ?o ftp, http, imap, smtp clients > ? ? ? ? ?o uuid > ? ? ? ? ?o url parsing > ? ? ? ? ?o http server > ? ? ? ? ?o xml-rpc Interface unification would help. Especially network-bytestring seems to be too ad-hoc for me - it would probably be better to put ByteString support into the regular Network library.... > ? ?* Internationalization > ? ? ? ? ?o gettext > ? ? ? ? ?o locale > ? ? ? ? ?o i18n Yes, although again, maturity? > ? ?* Development > ? ? ? ? ?o hscolour Yes. My main concern is with libraries like attoparsec and network-bytestring - these libraries seem to be somewhat ad-hoc conversion of traditional libraries to use ByteStrings. We should come up with a cleaner, more elegant way of dealing with the String/Text/Strict ByteString/Lazy ByteSTring gap, as most libraries that apply to one of those types also apply to the other two, as the first two and last two especially and more generally all four essentially represent the same thing. We shouldn't bless libraries that don't have a good way of applying equally to these three. A possible solution could be a standardized package-common, package-string, package-text, package-bytestring, package-lazybytestring naming convention, or a Category.Module, Category.Module.String, Category.Module.ByteString.Strict, Category.Module.ByteString.Lazy, Category.Module.Text convention. We could also work something up with type classes. I just don't like how a lot of libraries implement support for various string types just based on need rather than creating a clean, comprehensive interface. Alex From dons at galois.com Tue Aug 4 01:53:19 2009 From: dons at galois.com (Don Stewart) Date: Tue Aug 4 01:36:14 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> Message-ID: <20090804055319.GA20525@whirlpool.galois.com> alexander.dunlap: > > ? ? ? ? ?o pandoc ? markdown, reStructuredText, HTML, LaTeX, ConTeXt, Docbook, OpenDocument, ODT, RTF, MediaWiki, groff > > No. Pandoc is too actively developed to go into the HP. It's also much > more of an end-user application than a "standard library" - it's > applications are not general enough to be included in the standard > distribution. > One comment on your thoughtful post. What role does having unique capabilities for the Haskell Platform play? Our base library is already notable for having OpenGL support out of the box. Maybe markup/markdown formats (for example) would also help Haskell stand out from the crowd. A similar case would be gtk2hs out of the box (Python supplied Tcl guis). On the other hand, maybe the HP should be aiming to be comprehensive enough to /support/ pandoc without additional dependencies. We don't have to decide this now. There's more than enough "core" components missing to keep us busy for a while. -- Don From lennart at augustsson.net Tue Aug 4 03:38:53 2009 From: lennart at augustsson.net (Lennart Augustsson) Date: Tue Aug 4 03:19:44 2009 Subject: [Haskell-cafe] Re: Simple quirk in behavior of `mod` In-Reply-To: References: <20090722113413.75469f813b58c2e0e98e8a30424d5d59.b2fbb0df6d.wbe@email03.secureserver.net> <50c1e0910907222209l75632f50xbb56ec82e3f7aceb@mail.gmail.com> Message-ID: That how I was taught to round in school, so it doesn't seem at all unusual to me. 2009/7/23 Matthias G?rgens : >> Round-to-even means x.5 gets rounded to x if x is even and x+1 if x is >> odd. This is sometimes known as banker's rounding. > > OK. ?That's slightly unusual indeed. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From greenspan.levi at googlemail.com Tue Aug 4 04:06:16 2009 From: greenspan.levi at googlemail.com (Levi Greenspan) Date: Tue Aug 4 03:47:06 2009 Subject: [Haskell-cafe] FFI: Problem with Signal Handler Interruptions Message-ID: <3e62d4360908040106v24e87d3as987979d3e34943ff@mail.gmail.com> Dear list members, In February this year there was a posting "Why does sleep not work?" (http://www.haskell.org/pipermail/haskell-cafe/2009-February/055400.html). The problem was apparently caused by signal handler interruptions. I noticed the same (not with sleep though) when doing some FFI work and compiled the following test program: {-# LANGUAGE ForeignFunctionInterface #-} module Main where import Foreign.C.Types import Control.Concurrent sleep :: IO () sleep = c_sleep 3 >>= print fails :: IO () fails = sleep works :: IO () works = forkIO sleep >> return () main :: IO () main = fails >> works >> threadDelay 3000000 foreign import ccall unsafe "unistd.h sleep" c_sleep :: CUInt -> IO CUInt When compiled with GHC (using --make -threaded), it will print 3 immediately (from the "fails" function) and after 3 seconds 0 (from "works"), before it finally exits. man sleep(3) tells me that sleep returns 0 on success and if interrupted by a signal the number of seconds left to sleep. Clearly "fails" is interrupted by a signal (which seems to be SIGVTALRM). This was mentioned in the discussion from February. I would like to know why "fails" fails and "works" works, i.e. why is "sleep" not interrupted when run in a separate thread? And what can be done to make "sleep" work in the main thread? It wouldn't be wise to block SIGVTALRM, wouldn't it? Many thanks, Levi From apfelmus at quantentunnel.de Tue Aug 4 04:10:50 2009 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Tue Aug 4 03:51:27 2009 Subject: [Haskell-cafe] Re: Proposal: TypeDirectedNameResolution In-Reply-To: <4A775DD4.7050105@henning-thielemann.de> References: <4A6DCE93.5020700@imn.htwk-leipzig.de> <89ca3d1f0907270929u53c3ae8ey14758557bf07e29b@mail.gmail.com> <87ljm54w6b.fsf@malde.org> <4A775DD4.7050105@henning-thielemann.de> Message-ID: Henning Thielemann wrote: > Heinrich Apfelmus schrieb: > >> Note that there are alternative solution for this particular problem. >> For instance, a version of qualified with different semantics will do; >> something like this >> >> import Data.List >> import sometimes qualified Data.Map as Map > > Isn't that quite the same as > > import Data.Map as Map > > ? Not quite. The intended difference is that ambiguous names default to the module that imports them unqualified. I.e. import Data.List import sometimes qualified Data.Map as Map map -- Data.List.map or Data.Map.map ? will silently default to Data.List.map . > But you risk breaking packages when new qualifiers are added to imported > modules. Yeah, that's kinda unavoidable if you don't want to qualify so many names. Regards, apfelmus -- http://apfelmus.nfshost.com From apfelmus at quantentunnel.de Tue Aug 4 04:23:50 2009 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Tue Aug 4 04:04:25 2009 Subject: [Haskell-cafe] Re: Cyclic data declarations In-Reply-To: References: <4eff48ac0908012225j3a1dc7abh901859b95c5fa660@mail.gmail.com> <4eff48ac0908021806r71622b21oc9f0799acccd5d13@mail.gmail.com> Message-ID: Job Vranish wrote: > > I think that in an ideal world haskell would have some way of allowing > infinite types if you asked for them explicitly (say in the type signature > somehow) and then just automatically wrap/unwrap everything with newtypes > behind the scenes (well maybe in an ideal world it wouldn't have to do this > either). This wouldn't change the underlying semantics, but would get rid of > alot of messyness. > > Infinite types are possible, My toy language infers infinite types just fine > :) and I think Ocaml has an option for them, but niether of those have type > classes so I'm not sure how compatable the idea is with haskell in general. There was a thread with a compelling reason against vanilla infinite types some time ago: http://thread.gmane.org/gmane.comp.lang.haskell.cafe/17103 Of course, you can have all the recursion you want by using newtype , it's just that you need to annotate them with the extraneous constructor. In fact, that's exactly the purpose of the constructor; think of it as an aid for the type checker. Regards, apfelmus -- http://apfelmus.nfshost.com From andrewcoppin at btinternet.com Tue Aug 4 07:16:10 2009 From: andrewcoppin at btinternet.com (Andrew Coppin) Date: Tue Aug 4 06:57:01 2009 Subject: [Haskell-cafe] ANNOUNCE: The Haskell Platform 2009.2.0.2 In-Reply-To: <20090802234143.GF13973@whirlpool.galois.com> References: <20090801000107.GM3854@whirlpool.galois.com> <4A7400C9.4030206@btinternet.com> <20090802234143.GF13973@whirlpool.galois.com> Message-ID: <4A78187A.10902@btinternet.com> Don Stewart wrote: > andrewcoppin: > >> Maybe I'm being dense... Is there somewhere which lists what's changed >> from the last release? > > Oh, sorry, that will be in the web announcement tomorrow. > No problem. ;-) Given the Platform's aims, I think it would be a good idea to make it blindingly obvious how to find a complete changelog for every version of the platform yet released (plus a release date for each). > Essentially, > > * GHC 6.10.4 > * network upgraded to 2.2.1.4 > * Improvements to the MacOSX installer > * Improvements to crazy popular Windows installer > * Significant improvements in Debian support for Haskell > * Gentoo now has full support for the Haskell Platform > So... mostly just improvements to the installer then? ;-) (Oh, and new GHC - which AFAIK is mostly a bugfix update anyway...) From bugfact at gmail.com Tue Aug 4 07:26:07 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Tue Aug 4 07:06:59 2009 Subject: [Haskell-cafe] funct.prog. vs logic prog., practical Haskell In-Reply-To: <20090802102501.GA25860@pudlak.name> References: <20090802102501.GA25860@pudlak.name> Message-ID: On Sun, Aug 2, 2009 at 12:25 PM, Petr Pudlak wrote: > I'd like to convince people at our university to pay more attention to > functional languages, especially Haskell. Their arguments were that > > (1) Functional programming is more academic than practical. > (2) They are using logic programming already (Prolog); why is Haskell > better than Prolog (or generally a functional language better than a > logic programming language)? Regarding (1), today it's common to do functional programming in "industrially accepted" languages, at least if you want to be productive :) Take for example the following C# code, taken from production code: var graphs = selection.SelectMany( e => e.SelfAndIntraGraphAncestors() .OfType() .Take(1) .SelectMany(gc => gc.ChildGraphs)); Each of these C# methods work on lazy streams, so this even lazy functional programming in a sense :) (albeit with potential side effects) I could write this in imperative style, something like this (but it's not the same, the code below is strict, a lazy version would be much longer, unless I cheat and use C#'s yield statement) var graphContainers = new List(); foreach( var entity in selection ) { foreach( var ancestor in entity.SelfAndIntraGraphAncestors() ) { var graphContainer = ancestor as IGraphContainer; if( graphContainer != null ) { foreach( var childGraph in graphContainer.ChildGraphs ) { graphContainers.Add(childGraph); } break; } } } Obviously the second one is much less declarative and more difficult to read (and maintain). So really, any good industrial programmer should master at least the basics of functional programming. Haskell might be one of the most beautiful and elegant languages to use for learning functional programming. Also IMHO any experienced programmer should understand that although popular imperative programming languages like C++, C#, Java, Python, etc are more "powerful" than pure functional languages (in these sense that you can peek and poke around without restrictions like a crazy chicken), in practice this power is so difficult to control that it's a bit like giving everybody the right to carry a gun in public so people would feel safer ;-) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090804/89106798/attachment.html From malcolm.wallace at cs.york.ac.uk Tue Aug 4 07:43:46 2009 From: malcolm.wallace at cs.york.ac.uk (Malcolm Wallace) Date: Tue Aug 4 07:24:35 2009 Subject: [Haskell-cafe] Haskell interface files: Why used? What about same data in object files? In-Reply-To: <107818.80337.qm@web34307.mail.mud.yahoo.com> References: <107818.80337.qm@web34307.mail.mud.yahoo.com> Message-ID: > I am trying to understand the design of the Haskell interface files. > Why > are they a separate file rather than having the same data in the > object > file generated by the compiler? (Naively, it seems to me this would > work > also. Am I missing something?) Placing interface information into object files would be a perfectly reasonable design decision for a compiler. The language standard itself does not mandate the use of interface files (although it did once, around Haskell 1.2), nor any particular format, so a compiler is free to use whatever strategy it wishes. Some good reasons for having a separate interface are: they can be human-readable and human-writable (ghc's do not fulfill this criterion); they can be used to bootstrap mutually recursive modules in the absence of any object files (ghc uses .hs-boot files instead); other tools can extract information about modules without having to understand either the full Haskell syntax or the object language. Regards, Malcolm From spoon at killersmurf.com Tue Aug 4 09:20:35 2009 From: spoon at killersmurf.com (spoon) Date: Tue Aug 4 09:02:16 2009 Subject: [Haskell-cafe] Re: ANN: yst 0.2.1 In-Reply-To: <20090803222309.C6FF23245C0@www.haskell.org> References: <20090803222309.C6FF23245C0@www.haskell.org> Message-ID: <1249392035.3874.22.camel@utensil> This sounds great! I really like using yaml for web development. However, my last use case was for a non-techie, so I created a little desktop application for editing the "yamlbase", if you excuse the neologism. I think it worked quite well, because the user was then presented with a friendly looking system ( I even wrote a little calendar widget :) without having to spend the precious moneys on dynamic hosting. In the end, everyone was very happy. Actually, it was written in Ruby, and Shoes, and the data part was a lot less powerful than the yst query language there - but I think that an analogous tool would be useful; a GUI which creates yst scripts, would make yst a very powerful tool for non-techies. John From ndmitchell at gmail.com Tue Aug 4 09:50:22 2009 From: ndmitchell at gmail.com (Neil Mitchell) Date: Tue Aug 4 09:31:13 2009 Subject: [Haskell-cafe] Haskell interface files: Why used? What about same data in object files? In-Reply-To: References: <107818.80337.qm@web34307.mail.mud.yahoo.com> Message-ID: <404396ef0908040650v6136e97fk98a2f7086d24e816@mail.gmail.com> Hi > Some good reasons for having a separate interface are: ?they can be > human-readable and human-writable (ghc's do not fulfill this criterion); > they can be used to bootstrap mutually recursive modules in the absence of > any object files (ghc uses .hs-boot files instead); other tools can extract > information about modules without having to understand either the full > Haskell syntax or the object language. An additional reason is that for some changes of .hs file (where just the implementation changes) the .o file can be regenerated without touching the .hi file. This allows more accurate build dependencies and less recompilation. Thanks Neil From jvranish at gmail.com Tue Aug 4 10:34:24 2009 From: jvranish at gmail.com (Job Vranish) Date: Tue Aug 4 10:15:14 2009 Subject: [Haskell-cafe] Re: Cyclic data declarations In-Reply-To: References: <4eff48ac0908012225j3a1dc7abh901859b95c5fa660@mail.gmail.com> <4eff48ac0908021806r71622b21oc9f0799acccd5d13@mail.gmail.com> Message-ID: In a lot of cases though annotating all the recursive aspects with newtypes is a _royal_ pain, and is even worse if you want the datatypes to be instances of common type classes like Functor, Applicative, etc... (try it sometime) I don't advocate allowing infinite types wholesale, just in specific cases with a special annotation (like a type signature specifying the allowed infinite type). I think this would be the best of both worlds. - Job On Tue, Aug 4, 2009 at 4:23 AM, Heinrich Apfelmus wrote: > Job Vranish wrote: > > > > I think that in an ideal world haskell would have some way of allowing > > infinite types if you asked for them explicitly (say in the type > signature > > somehow) and then just automatically wrap/unwrap everything with newtypes > > behind the scenes (well maybe in an ideal world it wouldn't have to do > this > > either). This wouldn't change the underlying semantics, but would get rid > of > > alot of messyness. > > > > Infinite types are possible, My toy language infers infinite types just > fine > > :) and I think Ocaml has an option for them, but niether of those have > type > > classes so I'm not sure how compatable the idea is with haskell in > general. > > There was a thread with a compelling reason against vanilla infinite > types some time ago: > > http://thread.gmane.org/gmane.comp.lang.haskell.cafe/17103 > > > Of course, you can have all the recursion you want by using newtype , > it's just that you need to annotate them with the extraneous > constructor. In fact, that's exactly the purpose of the constructor; > think of it as an aid for the type checker. > > > Regards, > apfelmus > > -- > http://apfelmus.nfshost.com > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090804/b9753d08/attachment.html From jgm at berkeley.edu Tue Aug 4 11:54:14 2009 From: jgm at berkeley.edu (John MacFarlane) Date: Tue Aug 4 11:35:22 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: <20090804055319.GA20525@whirlpool.galois.com> References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <20090804055319.GA20525@whirlpool.galois.com> Message-ID: <20090804155414.GB31891@protagoras.phil.berkeley.edu> +++ Don Stewart [Aug 03 09 22:53 ]: > alexander.dunlap: > > > ? ? ? ? ?o pandoc ? markdown, reStructuredText, HTML, LaTeX, ConTeXt, Docbook, OpenDocument, ODT, RTF, MediaWiki, groff > > > > No. Pandoc is too actively developed to go into the HP. It's also much > > more of an end-user application than a "standard library" - it's > > applications are not general enough to be included in the standard > > distribution. > > > > One comment on your thoughtful post. > > What role does having unique capabilities for the Haskell Platform play? > > Our base library is already notable for having OpenGL support out of the > box. Maybe markup/markdown formats (for example) would also help Haskell > stand out from the crowd. A similar case would be gtk2hs out of the box > (Python supplied Tcl guis). > > On the other hand, maybe the HP should be aiming to be comprehensive > enough to /support/ pandoc without additional dependencies. I agree that pandoc shouldn't be in the HP. Also, although we ought to have a zip encoding package, I'm not sure it should be zip-archive (I'm the author). zip-archive is not complete; there are some kinds of zip files it can't parse. Quoting the documentation: "there is no support for encryption, zip files that span multiple disks, ZIP64, OS-specific file attributes, or compression methods other than Deflate." A better solution, perhaps, would be a binding to libzip. In this connection, I want to make a general point about the HP: In a way, it doesn't matter so much which additional pure Haskell libraries it includes, because once you have cabal install, you can get anything easily. For bindings to C libraries, it's another story. pcre-light is a good example. If I want to tell someone how to install pandoc with syntax highlighting, I can't just say, "Get the HP and then cabal install pandoc -fhighlighting". I have to say: "First, install the pcre library, if it's not already on your system..." -- and you lose a lot of users at this step. Havig high-quality, high-level bindings to standard libraries like pcre, libzip, etc., together with the C libraries themselves, in HP would be very useful. John From gdweber at iue.edu Tue Aug 4 12:03:42 2009 From: gdweber at iue.edu (Gregory D. Weber) Date: Tue Aug 4 11:44:35 2009 Subject: [Haskell-cafe] Split package organization (AntTweakBar, Cabal, darcs) Message-ID: <20090804160342.GA2642@squirrel.localdomain> I'm working on a Haskell binding for AntTweakBar, a light user interface for OpenGL applications (http://www.antisphere.com/Wiki/tools:anttweakbar). I have three questions about how to organize it as a Haskell package or packages, Cabal, and darcs. First, since AntTweakBar provides support for handling events from GLUT, GLFW, and SDL, as well as customizable event handling from other sources, would it be best to divide it into four packages -- AntTweakBar (core), AntTweakBar-GLUT, AntTweakBar-GLFW, and AntTweakBar-SDL? A few other "package groups" on Hackage have taken this approach of splitting according to the user interface: for example, grapefruit-ui-gtk, reactive-glut, though not on such a large scale as I am proposing. Advantages of four packages rather than one: -- Fewer build dependencies, for example, for users who want to use just SDL and not have to install GLUT or GLFW. -- If one of the build dependencies is broken (as for example GLFW is just at the moment with the latest OpenGL), users could still build the other AntTweakBar-* packages. Disadvantages: -- More packages to install, for those who want it all. -- I might seem to be grabbing an undue share of the package namespace. And it could get way out of hand if I further split the examples from the library, making AntTweakBar-(base|GLUT|GLFW|SDL)-(lib|examples) = 8 packages! Would that be a problem? -- Possible inconvenience for the developer (see second question). Second question, assuming the four-way split is the best way to package this: my impression is that a directory can have only one cabal package file and one Setup.hs file. (http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html, "Creating a Package") So for example I could not have, in the same directory, AntTweakBar.cabal, AntTweakBar-GLUT.cabal, etc. That means the four packages would each have to have their own directories, and it is sometimes inconvenient to be jumping back and forth between them. Any good way around that? Third question, assuming four separate directories for the four Cabal package files. Putting all four into one darcs repo (i.e., the darcs repo would have one main directory and a subdirectory for each package) seems to make it easier to coordinate development of the related packages -- for example, a single 'darcs rec -a' takes care of recording the related changes in all four subdirectories. Any reason not to do it that way? -- ___ ___ __ _ / _ \ / _ \| | | | Gregory D. Weber, Associate Professor / /_\// / | | | /\ | | Indiana University East / /_\\/ /__| | |/ \| | http://mypage.iu.edu/~gdweber/ \____/\_____/\___/\__/ Tel. (765) 973-8420; FAX (765) 973-8550 From magnus at therning.org Tue Aug 4 12:13:57 2009 From: magnus at therning.org (Magnus Therning) Date: Tue Aug 4 11:54:47 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: <20090804155414.GB31891@protagoras.phil.berkeley.edu> References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <20090804055319.GA20525@whirlpool.galois.com> <20090804155414.GB31891@protagoras.phil.berkeley.edu> Message-ID: On Tue, Aug 4, 2009 at 4:54 PM, John MacFarlane wrote: [..] > In this connection, I want to make a general point about the HP: > In a way, it doesn't matter so much which additional pure Haskell > libraries it includes, because once you have cabal install, you can get > anything easily. For bindings to C libraries, it's another story. AFAIU the plan is to separate GHC and its "platform packages", so in the future it might not be that easy to get to the point where you _can_ run 'cabal install'. > pcre-light is a good example. If I want to tell someone how to install > pandoc with syntax highlighting, I can't just say, "Get the HP and > then cabal install pandoc -fhighlighting". I have to say: "First, > install the pcre library, if it's not already on your system..." -- and > you lose a lot of users at this step. This is a good point, but to some extent this brings us back to a discussion that's specific to systems with broken or non-existing package managers. Wouldn't it be better to deal with _that_ outside of HP? /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?org http://therning.org/magnus identi.ca|twitter: magthe From max.rabkin at gmail.com Tue Aug 4 12:22:14 2009 From: max.rabkin at gmail.com (Max Rabkin) Date: Tue Aug 4 12:04:47 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <20090804055319.GA20525@whirlpool.galois.com> <20090804155414.GB31891@protagoras.phil.berkeley.edu> Message-ID: On Tue, Aug 4, 2009 at 6:13 PM, Magnus Therning wrote: > AFAIU the plan is to separate GHC and its "platform packages", so in > the future it might not be that easy to get to the point where you > _can_ run 'cabal install'. Absolutely not. The point of HP is to make the path from bare OS to complete Haskell installation including cabal-install consist of a single step: 1. Install Haskell Platform > This is a good point, but to some extent this brings us back to a > discussion that's specific to systems with broken or non-existing > package managers. ?Wouldn't it be better to deal with _that_ outside > of HP? AIUI, on systems with working package managers, HP will be a metapackage which depends on the appropriate "real" packages. --Max From bulat.ziganshin at gmail.com Tue Aug 4 12:31:45 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Aug 4 12:12:47 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: <20090804155414.GB31891@protagoras.phil.berkeley.edu> References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <20090804055319.GA20525@whirlpool.galois.com> <20090804155414.GB31891@protagoras.phil.berkeley.edu> Message-ID: <183275681.20090804203145@gmail.com> Hello John, Tuesday, August 4, 2009, 7:54:14 PM, you wrote: > methods other than Deflate." A better solution, perhaps, would be a > binding to libzip. it's hard to find feature list for libzip, but i suggest to look into 7zip library support. it supports lot of archive formats, including zip, rar, 7z, and for zip supports zip64, unicode filenames, aes encryption, bzip2/lzma. license is lgpl, API is COM-like that may be a hard part -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bos at serpentine.com Tue Aug 4 12:56:55 2009 From: bos at serpentine.com (Bryan O'Sullivan) Date: Tue Aug 4 12:37:44 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> Message-ID: On Mon, Aug 3, 2009 at 10:40 PM, Alexander Dunlap < alexander.dunlap@gmail.com> wrote: > > o unicode text [text] [text-icu] ? packed, unicode text > > This is essential, although I don't know if it is stable enough for > the platform (?). > I'm doing some cleaning up of the APIs at the moment for usability purposes, but it would be really, really nice to have some help with testing, performance measurement, and tuning. The code is very clean and easy to understand :-) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090804/e769f389/attachment.html From ekmett at gmail.com Tue Aug 4 15:30:03 2009 From: ekmett at gmail.com (Edward Kmett) Date: Tue Aug 4 15:10:52 2009 Subject: [Haskell-cafe] Cyclic data declarations In-Reply-To: <4eff48ac0908012225j3a1dc7abh901859b95c5fa660@mail.gmail.com> References: <4eff48ac0908012225j3a1dc7abh901859b95c5fa660@mail.gmail.com> Message-ID: <7fb8f82f0908041230l2710c843j69a105c87b10801e@mail.gmail.com> There are a number of ways to fix this of various complexity, depending on how many kinds of statements you have in your language and how adverse you are to code duplication. One option is to remove the recursion from your statement type and to make a 'base functor' like you've proposed with your link based ADT. data Stmt a = Slf Test [a] [a] | ... and then make that recursive by using a newtype to make the folding explicit. newtype Mu f = In { out :: f (Mu f) } Now you can work on Mu Stmt which is a fixed point of your statement data type and get your original meaning, or work with Stmt Int and have a statement type that indexes statements by # and can look them up in a control flow graph or some such. You can even attach annotations at every level by using a different ADT to wrap yourself up. (For the category-theory inclined, this gives rise to something known as the cofree comonad of your base functor) newtype Ann f e = Ann e (f (Ann f e)) So now you can have something like: Ann 2 (SIf ... (Ann 1 (Var "X")) (Ann 1 (Var "Y")) if you wanted to count the number of variable references in a subtree for instance. On the other hand, rarely does a programming language consist solely of statements. You often have expressions and other types floating around and tying with an explicit Mu can sometimes get in the way of that. Forgetting those definitions for a moment, we can try to fix the one statement type problem. You can use some interesting GADT based solutions to fix that, but another approach that I've been using recently is to use explicit recursion in a slightly different place. type (v :> f) = f (v f) data Var (f :: * -> *) = V String data Exp f = App (Exp :> f) (Exp :> f) | Lam (Var :> f) (Exp :> f) | Var (Var :> f) data Stmt f = If (Exp :> f) [Stmt :> f] [Stmt :> f] | ... Now we can have a lot of different kinds of expressions based on what we substitute in for f. data Ann a e = Ann a e newtype Mu e = Mu e data Free a e = Return a | Free e newtype Base a e = Base a now: Stmt (Base Int) -- is a statement wrapped around integers Stmt (Ann Int) -- is a statement wrapped around subtrees of various types annotated with integers Stmt Mu -- is your old statement type with newtype Mu wrappers on its children. Stmt (Free Int) is your old statement data type, with occasional integer place holders for unexpanded portions of the tree, they can act as standins for Exps, Vars, etc. You can then borrow a trick from a recent post of mine: http://comonad.com/reader/2009/incremental-folds/ with some minor modifications to extract data incrementally or return results as you grow the syntax tree. The design space is large and there are a lot of options to explore around here, so don't take any of this as the one and only way to implement a syntax ADT. =) -Edward Kmett On Sun, Aug 2, 2009 at 1:25 AM, Michal D. wrote: > I'm in the process of writing a toy compiler but I'm having some > trouble trying to make my datatypes general. For example, using parsec > I parse statements as: > > data Stmt = SIf Test [Stmt] [Stmt] | ... > > However, when it's time to create a control flow graph it would be > nice to represent statements as (the Int's signify the node id's for > either case of the if statement): > > data Stmt = SIf Test Int Int | ... > > So, in a eureka moment I decided that this should be allowable with > the following declaration: > > data Stmt link = SIf Test link link | ... > > Ofcourse, the problem is trying to declare the resulting type for > parsing: "parse -> Stmt [Stmt [Stmt ....]]". Any hints on whether > there is a way to accomplish what I'm trying to do or do I have to > bite the bullet and declare two seperate datatypes? I tried being > clever and declaring a 'helper' type as "type StmtRec = Stmt [StmtRec]" > but to no avail... GHC won't let it slide: "Cycle in type synonym > declarations"! > > Cheers, > > Michal > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090804/dc27e8cd/attachment.html From magnus at therning.org Tue Aug 4 17:56:43 2009 From: magnus at therning.org (Magnus Therning) Date: Tue Aug 4 17:37:40 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <20090804055319.GA20525@whirlpool.galois.com> <20090804155414.GB31891@protagoras.phil.berkeley.edu> Message-ID: <4A78AE9B.4080506@therning.org> Max Rabkin wrote: > On Tue, Aug 4, 2009 at 6:13 PM, Magnus Therning wrote: >> AFAIU the plan is to separate GHC and its "platform packages", so in >> the future it might not be that easy to get to the point where you >> _can_ run 'cabal install'. > > Absolutely not. The point of HP is to make the path from bare OS to > complete Haskell installation including cabal-install consist of a > single step: > 1. Install Haskell Platform Yes, indeed, if there exists a pre-compiled, binary version of HP for your platform. Also, note that you _didn't_ say that the goal of HP is to limit the pain of installing bindings to C libraries. >> This is a good point, but to some extent this brings us back to a >> discussion that's specific to systems with broken or non-existing >> package managers. Wouldn't it be better to deal with _that_ outside >> of HP? > > AIUI, on systems with working package managers, HP will be a > metapackage which depends on the appropriate "real" packages. Yes, but again, the role of HP shouldn't be to limit the pain of installing bindings to C libraries. What I'm saying is that it's a worthwhile goal to limit that pain, but it should be handled outside of HP. /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?org http://therning.org/magnus identi.ca|twitter: magthe -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: OpenPGP digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090804/8c8cf4b6/signature.bin From max.rabkin at gmail.com Tue Aug 4 18:05:27 2009 From: max.rabkin at gmail.com (Max Rabkin) Date: Tue Aug 4 17:46:37 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: <4A78AE9B.4080506@therning.org> References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <20090804055319.GA20525@whirlpool.galois.com> <20090804155414.GB31891@protagoras.phil.berkeley.edu> <4A78AE9B.4080506@therning.org> Message-ID: On Tue, Aug 4, 2009 at 11:56 PM, Magnus Therning wrote: >> >> AIUI, on systems with working package managers, HP will be a >> metapackage which depends on the appropriate "real" packages. > > Yes, but again, the role of HP shouldn't be to limit the pain of installing > bindings to C libraries. ?What I'm saying is that it's a worthwhile goal to > limit that pain, but it should be handled outside of HP. How could one do that? On systems with package managers, the platform won't bundle C libraries, but depend on them (this is correct: if software does in fact depend on a C library, it should declare that dependency). On systems without package managers, we could provide some form of "sub-platform" containing C libraries or a system for installing them, but then installing a Haskell system is no longer a one-step process. It's been a while since I was a regular Windows user, but it seemed then that bundling dependencies was the most common (only?) solution. > /M --Max From dons at galois.com Tue Aug 4 20:04:32 2009 From: dons at galois.com (Don Stewart) Date: Tue Aug 4 19:47:22 2009 Subject: [Haskell-cafe] Hackage Download Rankings August 2009 Message-ID: <20090805000432.GH23958@whirlpool.galois.com> Total package downloads on Hackage, by August 1 2009, http://www.galois.com/~dons/hackage/august-2009/popularity-august-2009.html All packages by month: http://www.galois.com/~dons/hackage/august-2009/hackage-august-2009.html Raw data: http://www.galois.com/~dons/hackage/august-2009/hackage-downloads-august-2009.csv Enjoy. -- Don P.S. For reference, here's the data from March, http://www.galois.com/~dons/hackage/popularity.html and analysis at the time http://www.galois.com/blog/2009/03/23/one-million-haskell-downloads/ From haskellmail at gmail.com Tue Aug 4 21:52:08 2009 From: haskellmail at gmail.com (kenny lu) Date: Tue Aug 4 21:32:57 2009 Subject: [Haskell-cafe] A problem with bytestring 0.9.1.4 "hGetBuf: invalid argument" Message-ID: <90bba1dc0908041852r54336adbv5b0d61afff7cde70@mail.gmail.com> Hi all, I've recently came across a problem when processing a large text file (around 2G in size). I wrote a Haskell program to count the number of lines in the file. module Main where import System import qualified Data.ByteString.Char8 as S -- import Prelude as S main :: IO () main = do { args <- getArgs ; case args of { [ filename ] -> do { content <- S.readFile filename ; let lns = S.lines content ; putStrLn (show $ length lns) } ; _ -> error "Usage : Wc " } } I get this error, if I use the ByteString module, ./Wc a.out Wc: {handle: a.out}: hGetBuf: invalid argument (illegal buffer size (-1909953139)) Otherwise, it returns me the result. Another observation is that if I reduce the size of the file, the ByteString version works too. Is it a known limitation? Regards, Kenny A generator program that generate large file. (Warning, it is very slow, I don't know how to speed it up) -- generate a file module Main where import System import qualified Data.ByteString.Char8 as S l :: S.ByteString l = S.pack "All work, no fun, make Kenny a dull boy. " main :: IO () main = do { args <- getArgs ; case args of { [ n, fn ] -> do { let i = read n ; mapM_ (\s -> S.appendFile fn s) (take i $ repeat l) } ; _ -> return () } } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090804/2483613e/attachment.html From dons at galois.com Tue Aug 4 22:06:49 2009 From: dons at galois.com (Don Stewart) Date: Tue Aug 4 21:49:43 2009 Subject: [Haskell-cafe] A problem with bytestring 0.9.1.4 "hGetBuf: invalid argument" In-Reply-To: <90bba1dc0908041852r54336adbv5b0d61afff7cde70@mail.gmail.com> References: <90bba1dc0908041852r54336adbv5b0d61afff7cde70@mail.gmail.com> Message-ID: <20090805020649.GA24924@whirlpool.galois.com> haskellmail: > Hi all, > > I've recently came across a problem when processing a large text file (around > 2G in size). > > I wrote a Haskell program to count the number of lines in the file. > > > module Main where > > import System > import qualified Data.ByteString.Char8 as S > -- import Prelude as S > > main :: IO () > main = do { args <- getArgs > ; case args of > { [ filename ] -> > do { content <- S.readFile filename > ; let lns = S.lines content > ; putStrLn (show $ length lns) > } > ; _ -> error "Usage : Wc " > } > } > > > I get this error, if I use the ByteString module, > ./Wc a.out > Wc: {handle: a.out}: hGetBuf: invalid argument (illegal buffer size > (-1909953139)) > Otherwise, it returns me the result. > > Another observation is that if I reduce the size of the file, the ByteString > version works too. > > Is it a known limitation? > Yes, you need to use Data.ByteString.Lazy.Char8 to process files larger than this on a 32 bit machine (you'll have more space on a 64 bit machine). -- Don From haskellmail at gmail.com Tue Aug 4 22:59:46 2009 From: haskellmail at gmail.com (kenny lu) Date: Tue Aug 4 22:40:35 2009 Subject: [Haskell-cafe] A problem with bytestring 0.9.1.4 "hGetBuf: invalid argument" In-Reply-To: <20090805020649.GA24924@whirlpool.galois.com> References: <90bba1dc0908041852r54336adbv5b0d61afff7cde70@mail.gmail.com> <20090805020649.GA24924@whirlpool.galois.com> Message-ID: <90bba1dc0908041959r313c2d72n248c0de7bf21dc97@mail.gmail.com> Oh right. Thanks for pointing out. :) On Wed, Aug 5, 2009 at 10:06 AM, Don Stewart wrote: > haskellmail: > > Hi all, > > > > I've recently came across a problem when processing a large text file > (around > > 2G in size). > > > > I wrote a Haskell program to count the number of lines in the file. > > > > > > module Main where > > > > import System > > import qualified Data.ByteString.Char8 as S > > -- import Prelude as S > > > > main :: IO () > > main = do { args <- getArgs > > ; case args of > > { [ filename ] -> > > do { content <- S.readFile filename > > ; let lns = S.lines content > > ; putStrLn (show $ length lns) > > } > > ; _ -> error "Usage : Wc " > > } > > } > > > > > > I get this error, if I use the ByteString module, > > ./Wc a.out > > Wc: {handle: a.out}: hGetBuf: invalid argument (illegal buffer size > > (-1909953139)) > > Otherwise, it returns me the result. > > > > Another observation is that if I reduce the size of the file, the > ByteString > > version works too. > > > > Is it a known limitation? > > > > Yes, you need to use Data.ByteString.Lazy.Char8 to process files larger > than this on a 32 bit machine (you'll have more space on a 64 bit > machine). > > -- Don > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090804/9bb1426c/attachment.html From magnus at therning.org Wed Aug 5 03:37:23 2009 From: magnus at therning.org (Magnus Therning) Date: Wed Aug 5 03:18:12 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <20090804055319.GA20525@whirlpool.galois.com> <20090804155414.GB31891@protagoras.phil.berkeley.edu> <4A78AE9B.4080506@therning.org> Message-ID: On Tue, Aug 4, 2009 at 11:05 PM, Max Rabkin wrote: > On Tue, Aug 4, 2009 at 11:56 PM, Magnus Therning wrote: >>> >>> AIUI, on systems with working package managers, HP will be a >>> metapackage which depends on the appropriate "real" packages. >> >> Yes, but again, the role of HP shouldn't be to limit the pain of installing >> bindings to C libraries. ?What I'm saying is that it's a worthwhile goal to >> limit that pain, but it should be handled outside of HP. > > How could one do that? On systems with package managers, the platform > won't bundle C libraries, but depend on them (this is correct: if > software does in fact depend on a C library, it should declare that > dependency). On systems without package managers, we could provide > some form of "sub-platform" containing C libraries or a system for > installing them, but then installing a Haskell system is no longer a > one-step process. Well, I'd hope that the stuff that's being built around _building_ HP (helper scripts / procedures for putting together binary installers on Mac and Win) is general enough so that it can be used to do a HP+ (or a number of installers) that includes different C lib bindings. In essence, that would result in a set of prepared Haskell packages for the platforms that lack a good package manager. > It's been a while since I was a regular Windows user, but it seemed > then that bundling dependencies was the most common (only?) solution. I don't know of any other way either. I just strongly oppose the idea that HP should take on the role of providing C lib bindings just because on some platforms it's hard to satisfy the C dependencies. /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?org http://therning.org/magnus identi.ca|twitter: magthe From bulat.ziganshin at gmail.com Wed Aug 5 03:59:14 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Wed Aug 5 03:40:24 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <20090804055319.GA20525@whirlpool.galois.com> <20090804155414.GB31891@protagoras.phil.berkeley.edu> <4A78AE9B.4080506@therning.org> Message-ID: <1823692928.20090805115914@gmail.com> Hello Magnus, Wednesday, August 5, 2009, 11:37:23 AM, you wrote: > I don't know of any other way either. I just strongly oppose the idea > that HP should take on the role of providing C lib bindings just > because on some platforms it's hard to satisfy the C dependencies. those some platfroms are 97% of all dowanloads and success on these platforms is the key to overall Haskell success. moreover, asd i understand the situation, lack of package manager on Windows was main motivation to establish HP - for unicies it's not really required -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From iavor.diatchki at gmail.com Wed Aug 5 04:11:40 2009 From: iavor.diatchki at gmail.com (Iavor Diatchki) Date: Wed Aug 5 03:52:29 2009 Subject: [Haskell-cafe] Haskell interface files: Why used? What about same data in object files? In-Reply-To: <404396ef0908040650v6136e97fk98a2f7086d24e816@mail.gmail.com> References: <107818.80337.qm@web34307.mail.mud.yahoo.com> <404396ef0908040650v6136e97fk98a2f7086d24e816@mail.gmail.com> Message-ID: <5ab17e790908050111q59ff10c1ie08f592ca312f127@mail.gmail.com> Hello, On Tue, Aug 4, 2009 at 2:50 PM, Neil Mitchell wrote: > Hi > >> Some good reasons for having a separate interface are: ?they can be >> human-readable and human-writable (ghc's do not fulfill this criterion); >> they can be used to bootstrap mutually recursive modules in the absence of >> any object files (ghc uses .hs-boot files instead); other tools can extract >> information about modules without having to understand either the full >> Haskell syntax or the object language. > > An additional reason is that for some changes of .hs file (where just > the implementation changes) the .o file can be regenerated without > touching the .hi file. This allows more accurate build dependencies > and less recompilation. Is that really the case? I thought that GHC may add code to the interface files for cross-module inlining purposes, which means that changing the implementation might change the interface too. -Iavor From magnus at therning.org Wed Aug 5 04:49:00 2009 From: magnus at therning.org (Magnus Therning) Date: Wed Aug 5 04:29:48 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: <1823692928.20090805115914@gmail.com> References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <20090804055319.GA20525@whirlpool.galois.com> <20090804155414.GB31891@protagoras.phil.berkeley.edu> <4A78AE9B.4080506@therning.org> <1823692928.20090805115914@gmail.com> Message-ID: On Wed, Aug 5, 2009 at 8:59 AM, Bulat Ziganshin wrote: > Hello Magnus, > > Wednesday, August 5, 2009, 11:37:23 AM, you wrote: > >> I don't know of any other way either. ?I just strongly oppose the idea >> that HP should take on the role of providing C lib bindings just >> because on some platforms it's hard to satisfy the C dependencies. > > those some platfroms are 97% of all dowanloads and success on these > platforms is the key to overall Haskell success. moreover, asd i > understand the situation, lack of package manager on Windows was main > motivation to establish HP - for unicies it's not really required 80% of all internet-related statistics are made dubious ;-) I strongly doubt the "97% of all downloads" statement. However, that's not really what we are discussing here. This is the statement on the Haskell Platform page: "The Haskell Platform is a blessed library and tool suite for Haskell distilled from Hackage, along with installers for a wide variety of machines. The contents of the platform is specified here: Haskell: Batteries Included. "The platform saves you the task of picking and choosing the best Haskell libraries and tools to use for a task. Distro maintainers that support the Haskell Platform can be confident they're fully supporting Haskell as the developers intend it. Developers targetting the platform can be confident they have a trusted base of code to work with." The way _I_ read it, HP is a set of libraries that form a supplement to a Haskell compiler/interpreter. Developers can feel confident writing code against this set of libraries and it's the goal to make HP available on as many platforms as possible. I don't think that establishing HP was mainly motivated by the lack of a package manager for windows, I also don't think that HP is un-needed on Unices. AFAIU the motivation was to 1) separate the compiler/interpreter (especially GHC) from "base libraries", 2) to clearly communicate what Haskell packages a developer can expect to find on a "Haskell system", and 3) to provide users/developers with an easy route to setting up a "Haskell system" on different OSs. Difficulty to build a C dependency of a Haskell library should _not_ be a criterion used to decide whether the Haskell library goes into HP or not. Cabal is great for source distribution, but apparently there's a need for a binary packager, especially for Windows. /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?org http://therning.org/magnus identi.ca|twitter: magthe From gwern0 at gmail.com Wed Aug 5 04:51:15 2009 From: gwern0 at gmail.com (gwern0@gmail.com) Date: Wed Aug 5 04:32:11 2009 Subject: [Haskell-cafe] Getting highest sum of list elements with Map Message-ID: Skipped content of type multipart/signed-------------- next part -------------- A non-text attachment was scrubbed... Name: hcorpus.hs Type: text/x-haskell Size: 3734 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090805/b7b93233/hcorpus.bin From jon.fairbairn at cl.cam.ac.uk Wed Aug 5 05:11:52 2009 From: jon.fairbairn at cl.cam.ac.uk (Jon Fairbairn) Date: Wed Aug 5 04:52:50 2009 Subject: [Haskell-cafe] ANN: Typeful/Text/HTMLs (for AngloHaskell/for scrap?) Message-ID: A while ago I wrote this rather pedantic html library (it guarantees standards compliance via types, even down to the nesting restrictions). I announced it on the libraries list, but chronic fatigue gets in the way of following things up, so I haven't taken it any further until recently. And recently there have been other efforts in the HTML area that may make it out of date. Anyway, I think there are one or two useful ideas in it, and if I manage to get to AngloHaskell, I'd like to discuss it a bit, hence the announcement (rather closer to AH than I intended). You can get the whole thing with darcs get --partial http://homepage.ntlworld.com/jon.fairbairn/Typeful/Text/nHTMLs It should build with ghc 6.10 and haddock 2.4.2 or you can browse the documentation starting at and AngloHaskell people who are interested might want to look at -- J?n Fairbairn Jon.Fairbairn@cl.cam.ac.uk From gale at sefer.org Wed Aug 5 06:53:48 2009 From: gale at sefer.org (Yitzchak Gale) Date: Wed Aug 5 06:34:57 2009 Subject: [Haskell-cafe] Getting highest sum of list elements with Map In-Reply-To: References: Message-ID: <2608b8a80908050353t2d5a4b14na63e5a6139ed3cf8@mail.gmail.com> Hi Gwern, gwern0 wrote: > ...efficiency is an issue. Here are a few efficiency issues that I noticed in your algorithm after a quick look (none of these have to do with Haskell really): o ranks sorts the entire set, then discards all but the maximum. It would be better to use maximum or maximumBy. If you are worried about the empty set, check that separately. o You recompute the same rank value repeatedly for every word in each sentence. Use a "let" clause in your list comprehension to do it only once per sentence. o approximation rescans the entire corpus after discarding each word. Try to think of a way to recompute only those sentences that contained the word. Hope this helps, Yitz From taruti at taruti.net Wed Aug 5 07:24:35 2009 From: taruti at taruti.net (Taru Karttunen) Date: Wed Aug 5 07:05:24 2009 Subject: [Haskell-cafe] Typeclass for functions taking different kinds of strings Message-ID: <1249471244-sup-5217@oz.taruti.net> Hello It seems like a very common issue to have an API like: foo :: String -> Foo fooBS :: ByteString -> Foo fooLBS:: L.ByteString -> Foo is there currently a library that makes unifying them easy? Below is attached one try at this, does it make sense? I'm thinking of uploading it to Hackage but would like comments first. With the library the above code is transformed into: foo :: StringLike string => string -> Foo - Taru Karttunen -------------- next part -------------- A non-text attachment was scrubbed... Name: StringLike.hs Type: application/octet-stream Size: 2260 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090805/67858356/StringLike.obj From johan.tibell at gmail.com Wed Aug 5 08:01:50 2009 From: johan.tibell at gmail.com (Johan Tibell) Date: Wed Aug 5 07:42:56 2009 Subject: [Haskell-cafe] Typeclass for functions taking different kinds of strings In-Reply-To: <1249471244-sup-5217@oz.taruti.net> References: <1249471244-sup-5217@oz.taruti.net> Message-ID: <90889fe70908050501i2b2e7dqd6e36b27dc1db1c1@mail.gmail.com> On Wed, Aug 5, 2009 at 1:24 PM, Taru Karttunen wrote: > Hello > > It seems like a very common issue to have an API like: > > foo :: String -> Foo > fooBS :: ByteString -> Foo > fooLBS:: L.ByteString -> Foo > > is there currently a library that makes unifying them easy? > They cannot be completely unified. A sequence of Unicode characters (String) is not the same kind of thing as a sequence of bytes (ByteString). Going between the two requires an encoding. A shared abstraction would support a subset of operations that make sense on all sequences. Cheers, Johan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090805/b84a3bce/attachment.html From jac at informatik.uni-kiel.de Wed Aug 5 08:03:44 2009 From: jac at informatik.uni-kiel.de (Jan Christiansen) Date: Wed Aug 5 07:44:43 2009 Subject: [Haskell-cafe] powerSet = filterM (const [True, False]) and Data.List permutation In-Reply-To: <2f9b2d30907281010v13162a44x6a55e1ad463b2ac4@mail.gmail.com> References: <910ddf450907170235n68abf28q4513fc62da5b8a37@mail.gmail.com> <7ca3f0160907170245x659523c3pdb7efc5cd4a59307@mail.gmail.com> <16442B752A06A74AB4D9F9A5FF076E4B03B9F829@ELON17P32001A.csfb.cs-group.com> <2f9b2d30907281010v13162a44x6a55e1ad463b2ac4@mail.gmail.com> Message-ID: <53533A04-3C00-4A5F-AA42-F005189782B1@informatik.uni-kiel.de> Hi, i am replying to a thread called "Data.List permutations" on ghc- users and a thread called "powerSet = filterM (const [True, False]) ... is this obfuscated haskell?" on haskell cafe. On 04.08.2009, at 19:48, Slavomir Kaslev wrote: > A friend mine, new to functional programming, was entertaining > himself by > writing different combinatorial algorithms in Haskell. He asked me > for some > help so I sent him my quick and dirty solutions for generating > variations and > permutations: On the haskell cafe thread it was observed that you can implement the permutations function in a non-deterministic favour. The ideas behind these implementations closely resemble implementations of corresponding functions in Curry. We can generalise your implementation to an arbitrary MonadPlus. The idea is that the MonadPlus represents non-determinism. `inter` non- deterministically inserts an element to every possible position of its argument list. inter x [] = [[x]] >> inter x yys@(y:ys) = [x:yys] ++ map (y:) (inter x ys) interM :: MonadPlus m => a -> [a] -> m [a] interM x [] = return [x] interM x yys@(y:ys) = return (x:yys) `mplus` liftM (y:) (interM x ys) >> perm [] = [[]] >> perm (x:xs) = concatMap (inter x) (perm xs) permM :: MonadPlus m => [a] -> m [a] permM [] = return [] permM (x:xs) = interM x =<< permM xs Alternatively we can implement permM by means of foldM. permM :: MonadPlus m => [a] -> m [a] permM = foldM (flip interM) [] A standard example for the use of non-determinism in Curry is a perm function that looks very similar to `permM` with the slight difference that you do not need the monad in Curry. An alternative to this definition is to define a monadic version of insertion sort. First we define a monadic equivalent of the `insertBy` function as follows: -- insertBy :: (a -> a -> Bool) -> a -> [a] -> [a] -- insertBy _ x [] = [x] -- insertBy le x (y:ys) =-- if le x y-- then x:y:ys -- else y:insertBy le x ys insertByM :: MonadPlus m => (a -> a -> m Bool) -> a -> [a] -> m [a] insertByM _ x [] = return [x] insertByM le x (y:ys) = do b <- le x y if b then return (x:y:ys) else liftM (y:) (insertByM le x ys) Note that this function is very similar to interM, that is, we have interM = insertByM (\_ _ -> return False `mplus` return True) On basis of `insertBy` we can define insertion sort. -- sortBy :: (a -> a -> Bool) -> [a] -> [a] -- sortBy le = foldr (insertBy le) [] In the same manner we can define a function `sortByM` by means of `insertByM`. sortByM :: MonadPlus m => (a -> a -> m Bool) -> [a] -> m [a] sortByM le = foldM (flip (insertByM le)) [] Now we can define a function that enumerates all permutations by means of `sortByM`. permM :: MonadPlus m => [a] -> m [a] permM = sortByM (\_ _ -> return False `mplus` return True) Interestingly we can also define permM by means of monadic counterparts of other sorting algorithms like mergeSort. Although there were some arguments on haskell cafe that this would not work for other sorting algorithms it looks like this is not the case. At least the corresponding implementation of perm by means of mergeSort in Curry works well for lists that I can test in reasonable time. Cheers, Jan From malcolm.wallace at cs.york.ac.uk Wed Aug 5 08:43:13 2009 From: malcolm.wallace at cs.york.ac.uk (Malcolm Wallace) Date: Wed Aug 5 08:23:59 2009 Subject: [Haskell-cafe] Haskell interface files: Why used? What about same data in object files? In-Reply-To: <5ab17e790908050111q59ff10c1ie08f592ca312f127@mail.gmail.com> References: <107818.80337.qm@web34307.mail.mud.yahoo.com> <404396ef0908040650v6136e97fk98a2f7086d24e816@mail.gmail.com> <5ab17e790908050111q59ff10c1ie08f592ca312f127@mail.gmail.com> Message-ID: <2A6F2DDE-238F-49A1-B4EE-F5F3D47682C6@cs.york.ac.uk> >> for some changes of .hs file (where just >> the implementation changes) the .o file can be regenerated without >> touching the .hi file. This allows more accurate build dependencies >> and less recompilation. > > Is that really the case? I thought that GHC may add code to the > interface files for cross-module inlining purposes, which means that > changing the implementation might change the interface too. Indeed, GHC _may_ change the interface file for such reasons, but it may equally decide to leave the interface untouched, e.g. if there are no new inlinings. Regards, Malcolm From olshanskydr at gmail.com Wed Aug 5 09:14:33 2009 From: olshanskydr at gmail.com (Dmitry Olshansky) Date: Wed Aug 5 08:55:20 2009 Subject: [Haskell-cafe] Efficient functional idiom for histogram In-Reply-To: <200908012238.06096.daniel.is.fischer@web.de> References: <79990c6b0907311339o17930eaej193b39e176f601a4@mail.gmail.com> <79990c6b0908011106n75d60eeeqf54740d73dfc05a8@mail.gmail.com> <2ABA1D95-6C50-4C2D-9EE1-4AAD377FA6D0@gmail.com> <200908012238.06096.daniel.is.fischer@web.de> Message-ID: <741612210908050614w6dbc6356o10f65cb6252a096d@mail.gmail.com> My measurements show that - using strict version of insertWith doesn't improve performance. - in case of compilation with -O2 flag foldl' also is equal to foldl (-O2 gives approx 2 time impovements).- using RandomGen and State monad to generate a list gives at least 4 times improvements (on 1 000 000 items). More complicated improvements (using Array, PRNG and so on) were not tested by me. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090805/139ff27e/attachment.html From gale at sefer.org Wed Aug 5 09:28:33 2009 From: gale at sefer.org (Yitzchak Gale) Date: Wed Aug 5 09:09:43 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> Message-ID: <2608b8a80908050628k11d93bf6jda3904370771ef55@mail.gmail.com> I agree with most of Alexander's many thoughtful comments about Don's list of potential additions to HP. But I disagree about pandoc. Alexander Dunlap wrote: > No. Pandoc is too actively developed to go into the HP. It depends on the nature of the development. If the API is currently very unstable and is expected to stabilize soon, then wait a little bit. Otherwise, that is no excuse to exclude something worthwhile. Choose a well-tested numbered version and include it. Later, if we want to upgrade, just follow the usual deprecation-upgrade process. Umm - we do have a well-defined deprecation-upgrade process, don't we? > It's also much more of an end-user application than > a "standard library" pandoc provides an extensive library, and also a command-line app. Is it a policy that in such a case, we require the command-line app to be split off into a separate package before we can include it? I'm not sure that's so important, but if so, it should not be hard to do that for pandoc. > its applications are not general > enough to be included in the standard > distribution. Text with markup is used in some way for almost every application. This library provides tools to convert between a wide variety of markup formats. Sounds pretty general to me. Other "batteries included" platforms contain various tools for processing markup that are far less general than pandoc. This is a place where Haskell can shine. So yes, pandoc should definitely be included in the platform. All that said, though, I will certainly agree that it is not currently in the top 5. Regards, Yitz From ndmitchell at gmail.com Wed Aug 5 09:36:06 2009 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Aug 5 09:16:52 2009 Subject: [Haskell-cafe] Typeclass for functions taking different kinds of strings In-Reply-To: <1249471244-sup-5217@oz.taruti.net> References: <1249471244-sup-5217@oz.taruti.net> Message-ID: <404396ef0908050636n7c41b09as58ba30e01db52116@mail.gmail.com> Hi > is there currently a library that makes unifying them easy? I currently use this library: http://community.haskell.org/~ndm/darcs/tagsoup/Text/StringLike.hs Not yet released, and rather specific to what I was wanting to do, but does work for me. I'm happy for people to steal bits from that as they want. Thanks Neil From taruti at taruti.net Wed Aug 5 10:51:11 2009 From: taruti at taruti.net (Taru Karttunen) Date: Wed Aug 5 10:31:58 2009 Subject: [Haskell-cafe] Typeclass for functions taking different kinds of strings In-Reply-To: <404396ef0908050636n7c41b09as58ba30e01db52116@mail.gmail.com> References: <1249471244-sup-5217@oz.taruti.net> <404396ef0908050636n7c41b09as58ba30e01db52116@mail.gmail.com> Message-ID: <1249483715-sup-7510@oz.taruti.net> Excerpts from Neil Mitchell's message of Wed Aug 05 16:36:06 +0300 2009: > I currently use this library: > > http://community.haskell.org/~ndm/darcs/tagsoup/Text/StringLike.hs > It looks nice but is not really a solution for passing large amounts of data efficiently. Converting everything to String creates too much overhead for large chunks of data. - Taru Karttunen From gale at sefer.org Wed Aug 5 11:01:56 2009 From: gale at sefer.org (Yitzchak Gale) Date: Wed Aug 5 10:43:04 2009 Subject: [Haskell-cafe] Efficient functional idiom for histogram In-Reply-To: <741612210908050614w6dbc6356o10f65cb6252a096d@mail.gmail.com> References: <79990c6b0907311339o17930eaej193b39e176f601a4@mail.gmail.com> <79990c6b0908011106n75d60eeeqf54740d73dfc05a8@mail.gmail.com> <2ABA1D95-6C50-4C2D-9EE1-4AAD377FA6D0@gmail.com> <200908012238.06096.daniel.is.fischer@web.de> <741612210908050614w6dbc6356o10f65cb6252a096d@mail.gmail.com> Message-ID: <2608b8a80908050801l597afd4fv991ef313ac3b7fd5@mail.gmail.com> Dmitry Olshansky wrote: > My measurements show that... > (-O2 gives approx 2 time impovements). > ...using RandomGen and State monad to generate a list gives at least 4 times > improvements (on 1 000 000 items). You earlier said: > this takes over twice as long as a naively implemented Python program So now our "naive" Haskell - ordinary usage of Data.Map and System.Random, without resorting to things like unboxed arrays - is beating naive Python handily. Correct? Or is this with an alternate RNG? Although I think even that would be fair, since Python uses Mersenne. Regards, Yitz From korpios at korpios.com Wed Aug 5 11:07:11 2009 From: korpios at korpios.com (Tom Tobin) Date: Wed Aug 5 10:47:57 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: <2608b8a80908050628k11d93bf6jda3904370771ef55@mail.gmail.com> References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <2608b8a80908050628k11d93bf6jda3904370771ef55@mail.gmail.com> Message-ID: On Wed, Aug 5, 2009 at 8:28 AM, Yitzchak Gale wrote: > I agree with most of Alexander's many thoughtful comments > about Don's list of potential additions to HP. But I > disagree about pandoc. [...] > So yes, pandoc should definitely be included > in the platform. I should preface this by saying that while I'm an experienced Python programmer, I'm *very* new to Haskell. As I understand it, Pandoc is entirely under the GPL (not LGPL). I'd be very wary of accepting a GPL'd library as a blessed "standard" library, since it would be completely unusable for non-GPL projects. One of the nice things about the Python standard library is that you know it's liberally licensed; a programmer can feel free to use it for any project, whether proprietary or copyleft or otherwise. I don't think I'd feel comfortable using or recommending the Haskell Platform if "batteries included" came with such a serious caveat. From gale at sefer.org Wed Aug 5 11:12:55 2009 From: gale at sefer.org (Yitzchak Gale) Date: Wed Aug 5 10:54:01 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <2608b8a80908050628k11d93bf6jda3904370771ef55@mail.gmail.com> Message-ID: <2608b8a80908050812l5d654ffcke94179fc5f72ae61@mail.gmail.com> Tom Tobin wrote: > As I understand it, Pandoc is entirely under the GPL (not LGPL). Oh. That would be an issue, yes. Too bad. Thanks, Yitz From colin at colina.demon.co.uk Wed Aug 5 11:19:49 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Wed Aug 5 11:00:52 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: (Tom Tobin's message of "Wed\, 5 Aug 2009 10\:07\:11 -0500") References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <2608b8a80908050628k11d93bf6jda3904370771ef55@mail.gmail.com> Message-ID: >>>>> "Tom" == Tom Tobin writes: Tom> As I understand it, Pandoc is entirely under the GPL (not Tom> LGPL). I'd be very wary of accepting a GPL'd library as a I'd be very upset if pandoc weren't blessed. Tom> blessed "standard" library, since it would be completely Tom> unusable for non-GPL projects. This can surely be tackled by cabal, as it already has the license information. So if you were to specify you project has a BSD license, and it requires use of a library licensed under the GPL, then cabal configure should fail with an error message. Just because a library is blessed, doesn't mean you have to use it. -- Colin Adams Preston Lancashire From korpios at korpios.com Wed Aug 5 11:37:46 2009 From: korpios at korpios.com (Tom Tobin) Date: Wed Aug 5 11:18:34 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <2608b8a80908050628k11d93bf6jda3904370771ef55@mail.gmail.com> Message-ID: On Wed, Aug 5, 2009 at 10:19 AM, Colin Paul Adams wrote: > Just because a library is blessed, doesn't mean you have to use it. Then I'm not sure I understand the point of blessing it in a set of libraries that "saves you the task of picking and choosing the best Haskell libraries and tools to use for a task" if "task" (in the second mention) is limited to "developing GPL'd software". The "picking and choosing" problem immediately comes back for everyone else, leaving the platform with second-class users who are forced to evaluate the libraries to make sure they're legally compatible ? defeating the purpose of the platform. > This can surely be tackled by cabal, as it already has the license information. I don't see this as a real solution; why would a package be added to the platform in the first place if a large proportion of developers couldn't make use of it? From p.f.moore at gmail.com Wed Aug 5 11:42:26 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Wed Aug 5 11:23:13 2009 Subject: [Haskell-cafe] Efficient functional idiom for histogram In-Reply-To: <2608b8a80908050801l597afd4fv991ef313ac3b7fd5@mail.gmail.com> References: <79990c6b0907311339o17930eaej193b39e176f601a4@mail.gmail.com> <79990c6b0908011106n75d60eeeqf54740d73dfc05a8@mail.gmail.com> <2ABA1D95-6C50-4C2D-9EE1-4AAD377FA6D0@gmail.com> <200908012238.06096.daniel.is.fischer@web.de> <741612210908050614w6dbc6356o10f65cb6252a096d@mail.gmail.com> <2608b8a80908050801l597afd4fv991ef313ac3b7fd5@mail.gmail.com> Message-ID: <79990c6b0908050842v2d495838t9417c3168615c48c@mail.gmail.com> 2009/8/5 Yitzchak Gale : > Dmitry Olshansky wrote: >> My measurements show that... >> (-O2 gives approx 2 time impovements). >> ...using RandomGen and State monad to generate a list gives at least 4 times >> improvements (on 1 000 000 items). > > You earlier said: > >> this takes over twice as long as a naively implemented > Python program The latter was me :-) > So now our "naive" Haskell - ordinary usage of Data.Map > and System.Random, without resorting to things like > unboxed arrays - is beating naive Python handily. Correct? I haven't checked myself (and won't have time in the next couple of weeks, as I'm on holiday - but I'll pick this up when I get back)., but it sounds like it. I'd like to check Dmitry's suggestions, mainly to see how they fit with my feel for "naive" (ie, at my beginner level, do I understand why they are more efficient). But I'd expect (compiled) Haskell to beat (interpreted) Python. That's sort of the point, really... The big measures for me are (1) by how much, and (2) how readable is the code. > Or is this with an alternate RNG? Although I think even that > would be fair, since Python uses Mersenne. I got the impression Dmitry was using Haskell's standard RNG, not Mersenne Twister. If so, then we'd get further improvements with MT, but that's still a hit against Haskell, as I'd interpret it as meaning that Haskell supplies as default a PRNG which costs noticeable performance in order to provide guarantees that "ordinary" programs don't need. Paul. From colin at colina.demon.co.uk Wed Aug 5 11:46:07 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Wed Aug 5 11:27:06 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: (Tom Tobin's message of "Wed\, 5 Aug 2009 10\:37\:46 -0500") References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <2608b8a80908050628k11d93bf6jda3904370771ef55@mail.gmail.com> Message-ID: >>>>> "Tom" == Tom Tobin writes: >> This can surely be tackled by cabal, as it already has the >> license information. Tom> I don't see this as a real solution; why would a package be It should be done anyway, irrespective of the platform. Tom> added to the platform in the first place if a large Tom> proportion of developers couldn't make use of it? Anyone can make use of it. You may choose not to (or your boss may choose for you), but that doesn't mean you can't. -- Colin Adams Preston Lancashire From pumpkingod at gmail.com Wed Aug 5 12:00:06 2009 From: pumpkingod at gmail.com (Daniel Peebles) Date: Wed Aug 5 11:40:52 2009 Subject: [Haskell-cafe] Improving MPTC usability when fundeps aren't appropriate? Message-ID: Hi all, I've been playing with multiparameter typeclasses recently and have written a few "uncallable methods" in the process. For example, in class Moo a b where moo :: a -> a the moo function is effectively impossible to call (no amount of type annotations can tell the compiler what you intended b to be there). Some might suggest adding an a -> b functional dependency, but in some cases that is not appropriate, as there are multiple possible instances. Another solution would be to artificially force moo to take a "dummy" b so that the compiler can figure out which instance you meant. That's what I've been doing in the mean time, but wouldn't it be simpler and less hackish to add a some form of "instance annotation", like a type annotation, that would make it possible to specify what instance you wanted when it's ambiguous? I'm not sure what syntax might be appropriate here, but it could also be seen as "opening" a particular instance, so something "open"-like might be good. I don't know whether this has already been discussed much, but I was unable to find anything that seemed relevant (beyond discussing relationships between parametrized modules and typeclasses) but I wanted to know if anyone had any opinion on adding such a feature to (a future revision of) Haskell? I know people are generally reluctant to add new syntax elements to a language, but considering the lack of such a feature and the impossibility of writing such a thing in the language itself, it seems like it'd be useful to add to the language itself. Thanks, Dan From greenspan.levi at googlemail.com Wed Aug 5 12:01:07 2009 From: greenspan.levi at googlemail.com (Levi Greenspan) Date: Wed Aug 5 11:41:53 2009 Subject: [Haskell-cafe] Re: FFI: Problem with Signal Handler Interruptions In-Reply-To: <3e62d4360908040106v24e87d3as987979d3e34943ff@mail.gmail.com> References: <3e62d4360908040106v24e87d3as987979d3e34943ff@mail.gmail.com> Message-ID: <3e62d4360908050901u392ae7e2m5a48d177cd90435b@mail.gmail.com> Nobody? On Tue, Aug 4, 2009 at 10:06 AM, Levi Greenspan wrote: > Dear list members, > > In February this year there was a posting "Why does sleep not work?" > (http://www.haskell.org/pipermail/haskell-cafe/2009-February/055400.html). > The problem was apparently caused by signal handler interruptions. I > noticed the same (not with sleep though) when doing some FFI work and > compiled the following test program: > > > {-# LANGUAGE ForeignFunctionInterface #-} > module Main where > > import Foreign.C.Types > import Control.Concurrent > > sleep :: IO () > sleep = c_sleep 3 >>= print > > fails :: IO () > fails = sleep > > works :: IO () > works = forkIO sleep >> return () > > main :: IO () > main = fails >> works >> threadDelay 3000000 > > foreign import ccall unsafe "unistd.h sleep" > ? ?c_sleep :: CUInt -> IO CUInt > > > When compiled with GHC (using --make -threaded), it will print 3 > immediately (from the "fails" function) and after 3 seconds 0 (from > "works"), before it finally exits. man sleep(3) tells me that sleep > returns 0 on success and if interrupted by a signal the number of > seconds left to sleep. Clearly "fails" is interrupted by a signal > (which seems to be SIGVTALRM). This was mentioned in the discussion > from February. > > I would like to know why "fails" fails and "works" works, i.e. why is > "sleep" not interrupted when run in a separate thread? And what can be > done to make "sleep" work in the main thread? It wouldn't be wise to > block SIGVTALRM, wouldn't it? > > Many thanks, > Levi > From korpios at korpios.com Wed Aug 5 12:03:55 2009 From: korpios at korpios.com (Tom Tobin) Date: Wed Aug 5 11:44:42 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <2608b8a80908050628k11d93bf6jda3904370771ef55@mail.gmail.com> Message-ID: On Wed, Aug 5, 2009 at 10:46 AM, Colin Paul Adams wrote: >>>>>> "Tom" == Tom Tobin writes: > > ? ?>> This can surely be tackled by cabal, as it already has the > ? ?>> license information. > > ? ?Tom> I don't see this as a real solution; why would a package be > > It should be done anyway, irrespective of the platform. Yes, that would be handy option for cabal-install in general. > ? ?Tom> added to the platform in the first place if a large > ? ?Tom> proportion of developers couldn't make use of it? > > Anyone can make use of it. You may choose not to (or your boss may > choose for you), but that doesn't mean you can't. The benefit of a standard library is that you can say "I need a library to handle X" and if a library addressing X is in the standard library, you're set. If you then need to worry about the GPL ??and this is a reality that can't be written off as a mere "choice" ? why bother with the platform in the first place? Non-GPL developers would be better off sticking with hackage in that case. From ndmitchell at gmail.com Wed Aug 5 12:20:13 2009 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Aug 5 12:00:58 2009 Subject: [Haskell-cafe] Typeclass for functions taking different kinds of strings In-Reply-To: <1249483715-sup-7510@oz.taruti.net> References: <1249471244-sup-5217@oz.taruti.net> <404396ef0908050636n7c41b09as58ba30e01db52116@mail.gmail.com> <1249483715-sup-7510@oz.taruti.net> Message-ID: <404396ef0908050920x2d3f6f8ak77657a3e20b9ca84@mail.gmail.com> Hi > It looks nice but is not really a solution for passing large amounts > of data efficiently. Converting everything to String creates too much > overhead for large chunks of data. There is uncons, which never creates big strings. But yes, adding more bulk operations (i.e. lookup) might be necessary to make it widely useful. Thanks Neil From jon.fairbairn at cl.cam.ac.uk Wed Aug 5 12:30:57 2009 From: jon.fairbairn at cl.cam.ac.uk (Jon Fairbairn) Date: Wed Aug 5 12:11:57 2009 Subject: [Haskell-cafe] Re: ANN: Typeful/Text/HTMLs (for AngloHaskell/for scrap?) References: Message-ID: I wrote: > You can get the whole thing with > > darcs get --partial http://homepage.ntlworld.com/jon.fairbairn/Typeful/Text/nHTMLs but that was a temporary url that I copied and pasted. The correct one: darcs get --partial http://homepage.ntlworld.com/jon.fairbairn/Typeful/Text/HTMLs And I uploaded only a partial get because I don't have much space on that server, but apparently darcs 2.3 can't get --partial from that repo, so I've uploaded the whole thing for now. Thanks to Max Desyatov for pointing out these problems. And one of the tests failed because Bolivia is now the Plurinational State of Bolivia, so I've add a patch for that. I've seen politics get in the way of programming, but I've never had a bug caused by /international/ politics before. -- J?n Fairbairn Jon.Fairbairn@cl.cam.ac.uk From john at n-brain.net Wed Aug 5 12:33:34 2009 From: john at n-brain.net (John A. De Goes) Date: Wed Aug 5 12:14:47 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <2608b8a80908050628k11d93bf6jda3904370771ef55@mail.gmail.com> Message-ID: <2199741E-125C-44FF-ABC9-63C7AEDB5115@n-brain.net> Tom is exactly right here. GPL is the kiss of death in the commercial world. Haskell Platform exists in part to encourage industry use of Haskell -- and to encourage "braindead" use of blessed libraries. GPL libraries have no place in HP. Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 On Aug 5, 2009, at 9:03 AM, Tom Tobin wrote: > On Wed, Aug 5, 2009 at 10:46 AM, Colin Paul > Adams wrote: >>>>>>> "Tom" == Tom Tobin writes: >> >> >> This can surely be tackled by cabal, as it already has the >> >> license information. >> >> Tom> I don't see this as a real solution; why would a package be >> >> It should be done anyway, irrespective of the platform. > > Yes, that would be handy option for cabal-install in general. > > >> Tom> added to the platform in the first place if a large >> Tom> proportion of developers couldn't make use of it? >> >> Anyone can make use of it. You may choose not to (or your boss may >> choose for you), but that doesn't mean you can't. > > The benefit of a standard library is that you can say "I need a > library to handle X" and if a library addressing X is in the standard > library, you're set. If you then need to worry about the GPL ? and > this is a reality that can't be written off as a mere "choice" ? why > bother with the platform in the first place? Non-GPL developers would > be better off sticking with hackage in that case. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From greenrd at greenrd.org Wed Aug 5 12:46:24 2009 From: greenrd at greenrd.org (Robin Green) Date: Wed Aug 5 12:27:29 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <2608b8a80908050628k11d93bf6jda3904370771ef55@mail.gmail.com> Message-ID: <20090805174624.7c24afa0@fedora> On Wed, 5 Aug 2009 11:03:55 -0500 Tom Tobin wrote: > On Wed, Aug 5, 2009 at 10:46 AM, Colin Paul > Adams wrote: > >>>>>> "Tom" == Tom Tobin writes: > > > > ? ?>> This can surely be tackled by cabal, as it already has the > > ? ?>> license information. > > > > ? ?Tom> I don't see this as a real solution; why would a package be > > > > It should be done anyway, irrespective of the platform. > > Yes, that would be handy option for cabal-install in general. My feature request for this is here: http://hackage.haskell.org/trac/hackage/ticket/481 where you can read a reply by Duncan listing some problems with this idea. -- Robin From greenrd at greenrd.org Wed Aug 5 12:49:36 2009 From: greenrd at greenrd.org (Robin Green) Date: Wed Aug 5 12:30:38 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: <2199741E-125C-44FF-ABC9-63C7AEDB5115@n-brain.net> References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <2608b8a80908050628k11d93bf6jda3904370771ef55@mail.gmail.com> <2199741E-125C-44FF-ABC9-63C7AEDB5115@n-brain.net> Message-ID: <20090805174936.36bc4a97@fedora> And even if you don't agree with that, it would likely lead to accidental use of GPL software in proprietary software, which is not a good thing. -- Robin On Wed, 5 Aug 2009 09:33:34 -0700 "John A. De Goes" wrote: > > Tom is exactly right here. GPL is the kiss of death in the > commercial world. Haskell Platform exists in part to encourage > industry use of Haskell -- and to encourage "braindead" use of > blessed libraries. GPL libraries have no place in HP. > > Regards, > > John A. De Goes > N-Brain, Inc. > The Evolution of Collaboration > > http://www.n-brain.net | 877-376-2724 x 101 > > On Aug 5, 2009, at 9:03 AM, Tom Tobin wrote: > > > On Wed, Aug 5, 2009 at 10:46 AM, Colin Paul > > Adams wrote: > >>>>>>> "Tom" == Tom Tobin writes: > >> > >> >> This can surely be tackled by cabal, as it already has the > >> >> license information. > >> > >> Tom> I don't see this as a real solution; why would a package be > >> > >> It should be done anyway, irrespective of the platform. > > > > Yes, that would be handy option for cabal-install in general. > > > > > >> Tom> added to the platform in the first place if a large > >> Tom> proportion of developers couldn't make use of it? > >> > >> Anyone can make use of it. You may choose not to (or your boss may > >> choose for you), but that doesn't mean you can't. > > > > The benefit of a standard library is that you can say "I need a > > library to handle X" and if a library addressing X is in the > > standard library, you're set. If you then need to worry about the > > GPL ? and this is a reality that can't be written off as a mere > > "choice" ? why bother with the platform in the first place? > > Non-GPL developers would be better off sticking with hackage in > > that case. _______________________________________________ > > 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 -- Robin From bulat.ziganshin at gmail.com Wed Aug 5 12:56:36 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Wed Aug 5 12:37:42 2009 Subject: [Haskell-cafe] Improving MPTC usability when fundeps aren't appropriate? In-Reply-To: References: Message-ID: <16625829.20090805205636@gmail.com> Hello Daniel, Wednesday, August 5, 2009, 8:00:06 PM, you wrote: > class Moo a b where > moo :: a -> a > instances. Another solution would be to artificially force moo to take > a "dummy" b so that the compiler can figure out which instance you > meant. That's what I've been doing in the mean time, but wouldn't it > be simpler and less hackish to add a some form of "instance > annotation", like a type annotation, that would make it possible to > specify what instance you wanted when it's ambiguous? imho, no. you propose to add one more feature when existing features can serve: class Moo a b where moo :: a -> b -> a f x = moo x (undefined::Int) btw, may be associated types or associated type synonyms (these are novel features superseding FDs) is what you need? -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From apfelmus at quantentunnel.de Wed Aug 5 13:09:43 2009 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Wed Aug 5 12:50:14 2009 Subject: [Haskell-cafe] Re: Improving MPTC usability when fundeps aren't appropriate? In-Reply-To: References: Message-ID: Daniel Peebles wrote: > > I've been playing with multiparameter typeclasses recently and have > written a few "uncallable methods" in the process. For example, in > > class Moo a b where > moo :: a -> a > > the moo function is effectively impossible to call (no amount of type > annotations can tell the compiler what you intended b to be there). > Some might suggest adding an a -> b functional dependency, but in some > cases that is not appropriate, as there are multiple possible > instances. You can factor out moo into a type class involving only a . And if you can't do that, then you've got a problem with ambiguous instances anyway. > Another solution would be to artificially force moo to take > a "dummy" b so that the compiler can figure out which instance you > meant. That's what I've been doing in the mean time, but wouldn't it > be simpler and less hackish to add a some form of "instance > annotation", like a type annotation, that would make it possible to > specify what instance you wanted when it's ambiguous? I'm not sure > what syntax might be appropriate here, but it could also be seen as > "opening" a particular instance, so something "open"-like might be > good. I don't think that the syntax for such a feature will be very different from a dummy argument. Also note that instead of using the actual type b as argument, as in moo :: b -> a -> a moo (undefined :: Foo) ... -- usage , you can use a phantom type data Instance a = I moo :: Instance b -> a -> a bar = I :: Instance Bar moo bar ... -- usage Regards, apfelmus -- http://apfelmus.nfshost.com From dons at galois.com Wed Aug 5 13:38:06 2009 From: dons at galois.com (Don Stewart) Date: Wed Aug 5 13:20:56 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: <1823692928.20090805115914@gmail.com> References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <20090804055319.GA20525@whirlpool.galois.com> <20090804155414.GB31891@protagoras.phil.berkeley.edu> <4A78AE9B.4080506@therning.org> <1823692928.20090805115914@gmail.com> Message-ID: <20090805173806.GC27736@whirlpool.galois.com> bulat.ziganshin: > Hello Magnus, > > Wednesday, August 5, 2009, 11:37:23 AM, you wrote: > > > I don't know of any other way either. I just strongly oppose the idea > > that HP should take on the role of providing C lib bindings just > > because on some platforms it's hard to satisfy the C dependencies. > > those some platfroms are 97% of all dowanloads and success on these > platforms is the key to overall Haskell success. moreover, asd i > understand the situation, lack of package manager on Windows was main > motivation to establish HP - for unicies it's not really required The motivation was to have a high quality Haskell environment on every system. That the unicies would all agree on what they provide was "Haskell". Fixing up Windows was a nice side effect. -- Don From dons at galois.com Wed Aug 5 13:39:13 2009 From: dons at galois.com (Don Stewart) Date: Wed Aug 5 13:22:03 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: <2608b8a80908050628k11d93bf6jda3904370771ef55@mail.gmail.com> References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <2608b8a80908050628k11d93bf6jda3904370771ef55@mail.gmail.com> Message-ID: <20090805173913.GD27736@whirlpool.galois.com> gale: > Other "batteries included" platforms contain > various tools for processing markup that are > far less general than pandoc. This is a place > where Haskell can shine. > > So yes, pandoc should definitely be included > in the platform. All that said, though, I will > certainly agree that it is not currently in the top 5. > I agree with this. We would shine, but maybe not for the first cut. Especially since the maintainer has requested this. Note also: pandoc is GPL -- Don From psujkov at gmail.com Wed Aug 5 13:42:16 2009 From: psujkov at gmail.com (Paul Sujkov) Date: Wed Aug 5 13:23:16 2009 Subject: [Haskell-cafe] [Haskell Cafe] Parsec: using two different parser for the same string Message-ID: <9760562b0908051042p97be03tb5f49a0905ef44d5@mail.gmail.com> Hi everybody, suppose I have two different parsers: one just reads the string, and another one parses some values from it. E.g.: parseIntList :: Parser [Integer] parseIntList = do char '(' res <- liftM (map read) (sepBy1 (many1 digit) (char ';')) char ')' return res parseIntString :: Parser String parseIntString = manyTill anyChar eof so for some input like this - "(1;2;3;4)" - I will have two different result: *Parlog> parseTest parseIntList "(1;2;3;4)" [1,2,3,4] *Parlog> parseTest parseIntString "(1;2;3;4)" "(1;2;3;4)" but the thing that I actually want is something like Parser ([Integer], String) - results from both parsers at a time, no matter whether one of them fails or not: *Parlog> parseTest parseIntListAndString "(1;2;3;4)" ([1,2,3,4], "(1;2;3;4)") it is impossible at first sight, because first parser to use will consume all the input, and there will be nothing to parse for the second one Parsec contains "choice" function, but it is implemented via <|> and that is mplus - so it tries second alternative only if the first one fails. Is it possible to use two parsers for the same string (with try-like backtracking, no input actually consumed till the second parser finishes)? I can assume only dirty hacks with the GenParser internals - manual position storing and backtracking - but that is obviously not good however, my first attempt to solve the problem was kind a like that: to parse string to String, and then to use it as an input for the next level parse call: parseIntListAndString :: Parser ([Integer], String) parseIntListAndString = do str <- parseIntString return (res str, str) where res str = case (parse parseIntList "" str) of Left err -> [] Right val -> val but the problems with such a method began when I switched from Parser to GenParser with user state: function parseIntList have to update the state, but it can't have the same state as the parseIntListAndString any more: it has it's own. I can explicitly pass the state from parseIntListAndString to parseIntList, but I see no suitable way for the parseIntList to update it. I can return the updated state value from the parseIntList function, and call setState on a result - but it seems rather ugly to mee. However, if nothing else will do, that is an alternative it is of course possible to use two different parsers sequentially, but it is also very ineffective: I need to use such multiple parsing on a relatively small substring of the actual input, so little backtracking would be a much nicier approach. Any suggestions? -- Regards, Paul Sujkov -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090805/c5f554cc/attachment.html From psujkov at gmail.com Wed Aug 5 13:51:36 2009 From: psujkov at gmail.com (Paul Sujkov) Date: Wed Aug 5 13:32:39 2009 Subject: [Haskell-cafe] Re: [Haskell Cafe] Parsec: using two different parser for the same string In-Reply-To: <9760562b0908051042p97be03tb5f49a0905ef44d5@mail.gmail.com> References: <9760562b0908051042p97be03tb5f49a0905ef44d5@mail.gmail.com> Message-ID: <9760562b0908051051yf6bc42bp63f266350c550c6b@mail.gmail.com> Well, I was too optimistic saying "I can return the updated state". I don't know how to do that actually. Maybe someone else here knows? 2009/8/5 Paul Sujkov > Hi everybody, > > suppose I have two different parsers: one just reads the string, and > another one parses some values from it. E.g.: > > parseIntList :: Parser [Integer] > parseIntList = do > char '(' > res <- liftM (map read) (sepBy1 (many1 digit) (char ';')) > char ')' > return res > > parseIntString :: Parser String > parseIntString = manyTill anyChar eof > > so for some input like this - "(1;2;3;4)" - I will have two different > result: > > *Parlog> parseTest parseIntList "(1;2;3;4)" > [1,2,3,4] > *Parlog> parseTest parseIntString "(1;2;3;4)" > "(1;2;3;4)" > > but the thing that I actually want is something like Parser ([Integer], > String) - results from both parsers at a time, no matter whether one of them > fails or not: > > *Parlog> parseTest parseIntListAndString "(1;2;3;4)" > ([1,2,3,4], "(1;2;3;4)") > > it is impossible at first sight, because first parser to use will consume > all the input, and there will be nothing to parse for the second one > > Parsec contains "choice" function, but it is implemented via <|> and that > is mplus - so it tries second alternative only if the first one fails. Is it > possible to use two parsers for the same string (with try-like backtracking, > no input actually consumed till the second parser finishes)? I can assume > only dirty hacks with the GenParser internals - manual position storing and > backtracking - but that is obviously not good > > however, my first attempt to solve the problem was kind a like that: to > parse string to String, and then to use it as an input for the next level > parse call: > > parseIntListAndString :: Parser ([Integer], String) > parseIntListAndString = do > str <- parseIntString > return (res str, str) > where res str = case (parse parseIntList "" str) of > Left err -> [] > Right val -> val > > but the problems with such a method began when I switched from Parser to > GenParser with user state: function parseIntList have to update the state, > but it can't have the same state as the parseIntListAndString any more: it > has it's own. I can explicitly pass the state from parseIntListAndString to > parseIntList, but I see no suitable way for the parseIntList to update it. I > can return the updated state value from the parseIntList function, and call > setState on a result - but it seems rather ugly to mee. However, if nothing > else will do, that is an alternative > > it is of course possible to use two different parsers sequentially, but it > is also very ineffective: I need to use such multiple parsing on a > relatively small substring of the actual input, so little backtracking would > be a much nicier approach. Any suggestions? > > -- > Regards, Paul Sujkov > -- Regards, Paul Sujkov -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090805/e52207ea/attachment.html From witzel.thomas at gmail.com Wed Aug 5 13:59:00 2009 From: witzel.thomas at gmail.com (Thomas Witzel) Date: Wed Aug 5 13:39:45 2009 Subject: [Haskell-cafe] Basic questions about concurrency in Haskell Message-ID: Hello all, I'm new to Haskell, but have a good background in LISP/Scheme and do mostly C/C++ programming on a daily basis. I'm learning Haskell mainly because it provides facilities for concurrency on the language level, and I'm mainly interested in implementing parallel or massively parallel algorithms with Haskell. I have two questions that bother me. 1. Does the Haskell compiler make sure that there is no page sharing between threads, in order to avoid cache thrashing between cpus (a real killer on large SMP or ccNUMA systems) ? If so, are there functions/options to control this ? 2. I started with the very simple nfib example given in the manual for Control.Parallel (Section 7.18). On my systems using multiple cores makes the code actually slower than just using a single core. While the manual cautions that this could be the case for certain algorithms, I'm wondering whether this is the desired behaviour for this example. I'm using ghc 6.10.4 right now. Thank you for your help getting me started here. Thomas From douyaxu at gmail.com Wed Aug 5 14:04:40 2009 From: douyaxu at gmail.com (xu zhang) Date: Wed Aug 5 13:45:27 2009 Subject: [Haskell-cafe] About the import module Message-ID: Hi there, If I import a module and do not explicitly point out the entities I have imported. And I want the ghc to point out the entities automatically. Is there any method to do this? any methods to have the ghc point out the entities I import and export? Because there are so many files and I don't want to change them one by one, so I just want to find if there is a simple and automatic way to have the entities pointed out. Thank you in advance! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090805/63272503/attachment.html From gue.schmidt at web.de Wed Aug 5 14:05:21 2009 From: gue.schmidt at web.de (=?iso-8859-15?Q?G=FCnther_Schmidt?=) Date: Wed Aug 5 13:46:23 2009 Subject: [Haskell-cafe] SQL Database in Haskell? Message-ID: Hi all, is there an SQL Database in Haskell or is there a project trying to implement one? G?nther From pumpkingod at gmail.com Wed Aug 5 14:11:44 2009 From: pumpkingod at gmail.com (Daniel Peebles) Date: Wed Aug 5 13:52:30 2009 Subject: [Haskell-cafe] Improving MPTC usability when fundeps aren't appropriate? In-Reply-To: <16625829.20090805205636@gmail.com> References: <16625829.20090805205636@gmail.com> Message-ID: Adding a dummy argument is what I've been doing so far, but it feels hackish. Typeclasses add an implicit parameter containing the dictionary of methods, and it seemed reasonable for me to have a more direct influence over its value. If I must add another explicit parameter to specify which dictionary to use, I might as well just pass the dictionary around myself. On Wed, Aug 5, 2009 at 12:56 PM, Bulat Ziganshin wrote: > Hello Daniel, > > Wednesday, August 5, 2009, 8:00:06 PM, you wrote: > >> class Moo a b where >> ? moo :: a -> a > >> instances. Another solution would be to artificially force moo to take >> a "dummy" b so that the compiler can figure out which instance you >> meant. That's what I've been doing in the mean time, but wouldn't it >> be simpler and less hackish to add a some form of "instance >> annotation", like a type annotation, that would make it possible to >> specify what instance you wanted when it's ambiguous? > > imho, no. you propose to add one more feature when existing features > can serve: > > class Moo a b where > ?moo :: a -> b -> a > > f x = moo x (undefined::Int) > > btw, may be associated types or associated type synonyms (these are > novel features superseding FDs) is what you need? > > > > -- > Best regards, > ?Bulat ? ? ? ? ? ? ? ? ? ? ? ? ? ?mailto:Bulat.Ziganshin@gmail.com > > From bulat.ziganshin at gmail.com Wed Aug 5 14:13:09 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Wed Aug 5 13:57:51 2009 Subject: [Haskell-cafe] Basic questions about concurrency in Haskell In-Reply-To: References: Message-ID: <1522878001.20090805221309@gmail.com> Hello Thomas, Wednesday, August 5, 2009, 9:59:00 PM, you wrote: > because it provides facilities for concurrency on the language level, > and I'm mainly interested in implementing parallel or massively > parallel algorithms with Haskell. I have two questions that bother me. if you plan to implement high-performance low-level algos, haskell/ghc is definitely not the language you need. haskell concurrency features are great in erlang-style situations when you need to manage many threads that interacts in complex way. but don't expect to get any C-level performance > 1. Does the Haskell compiler make sure that there is no page sharing > between threads no > 2. I started with the very simple nfib example given in the manual for > Control.Parallel (Section 7.18). standard optimization for this example is to use par only for large enough n, otherwise you will lose much more time on synchronization. ghc doesn't parallelize code in some wizardry way, it just have 4 worker threads, for example, and each spark created with par, becomes one more job for these threads o execute -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From mauricio.antunes at gmail.com Wed Aug 5 14:37:39 2009 From: mauricio.antunes at gmail.com (=?ISO-8859-1?Q?Maur=ED=ADcio_CA?=) Date: Wed Aug 5 14:18:37 2009 Subject: [Haskell-cafe] Space for commentaries on hackage Message-ID: It would be nice to have a place for anonimous comments below each page of a hackage package, maybe with a cabal option to enable/disable that for a particular package. Authors of packages with few users may want that as a way to get first impressions on their work they would otherwise not get. (At least, I am, so I thought maybe others probably would.) Best, Maur?cio From sebastian.sylvan at gmail.com Wed Aug 5 15:01:09 2009 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Wed Aug 5 14:41:54 2009 Subject: [Haskell-cafe] Basic questions about concurrency in Haskell In-Reply-To: References: Message-ID: <3d96ac180908051201v731122d4ub2f4ca67aa6b9466@mail.gmail.com> On Wed, Aug 5, 2009 at 6:59 PM, Thomas Witzel wrote: > > > 2. I started with the very simple nfib example given in the manual for > Control.Parallel (Section 7.18). On my systems using multiple cores > makes the code actually slower than just using a single core. While > the manual cautions that this could be the case for certain > algorithms, I'm wondering whether this is the desired behaviour for > this example. > > I'm using ghc 6.10.4 right now. > IIRC the development version of GHC has some major work to optimize concurrency, so it may be worth trying that. In particular I believe it executes sparks in batches, to reduce the overhead (which hopefully fixes your issue). -- Sebastian Sylvan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090805/3bc4c3cb/attachment.html From olshanskydr at gmail.com Wed Aug 5 15:11:42 2009 From: olshanskydr at gmail.com (Dmitry Olshansky) Date: Wed Aug 5 14:52:29 2009 Subject: [Haskell-cafe] Efficient functional idiom for histogram In-Reply-To: <79990c6b0908050842v2d495838t9417c3168615c48c@mail.gmail.com> References: <79990c6b0907311339o17930eaej193b39e176f601a4@mail.gmail.com> <79990c6b0908011106n75d60eeeqf54740d73dfc05a8@mail.gmail.com> <2ABA1D95-6C50-4C2D-9EE1-4AAD377FA6D0@gmail.com> <200908012238.06096.daniel.is.fischer@web.de> <741612210908050614w6dbc6356o10f65cb6252a096d@mail.gmail.com> <2608b8a80908050801l597afd4fv991ef313ac3b7fd5@mail.gmail.com> <79990c6b0908050842v2d495838t9417c3168615c48c@mail.gmail.com> Message-ID: <741612210908051211p32b6d0a9v3b49b8ff048ad8eb@mail.gmail.com> Skipped content of type multipart/alternative-------------- next part -------------- A non-text attachment was scrubbed... Name: histogram.hs Type: application/octet-stream Size: 833 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090805/9ff7f8bc/histogram.obj From olshanskydr at gmail.com Wed Aug 5 15:49:26 2009 From: olshanskydr at gmail.com (Dmitry Olshansky) Date: Wed Aug 5 15:30:12 2009 Subject: [Haskell-cafe] Haskell2Xml Message-ID: <741612210908051249ya47b732ne8f06010204b5090@mail.gmail.com> Hello all, I need a convenient tool to generate Haskell types from XML W3C Schema Definition (xsd) and vice versa - generate instances for Haskell ADT's to make corresponding XML. It is just the same that HaXml do with DTD. I need - using XSD - support for unicode - using xml-attributes as far as elements are very desirable - by my opinion TemplateHaskell for generate instances is prefferable than using DrIFT (which used in HaXml) - both possibilities is great of course - generation of xsd by Haskell type is a good feature also and so on... Does this tool exist? Do some articles / thoughts / standards / recomendations about correspondence between XML and Haskell ADT's exist? Best wishes, Dmitry -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090805/f9ec7b52/attachment.html From andy at adradh.org.uk Wed Aug 5 15:56:42 2009 From: andy at adradh.org.uk (andy morris) Date: Wed Aug 5 15:37:47 2009 Subject: [Haskell-cafe] About the import module In-Reply-To: References: Message-ID: 2009/8/5 xu zhang : > Hi there, > > If I import a module and do not explicitly point out the entities I have > imported. And I want the ghc to point out the entities automatically. Is > there any method to do this? any methods to have the ghc point out the > entities I import and export? > Because there are so many files and I don't want to change them one by one, > so I just want to find if there is a simple and automatic way to have the > entities pointed out. > > Thank you in advance! > `ghc --make -ddump-minimal-imports Main.hs` will output *.imports files containing what you want. From dons at galois.com Wed Aug 5 16:32:37 2009 From: dons at galois.com (Don Stewart) Date: Wed Aug 5 16:15:29 2009 Subject: [Haskell-cafe] SQL Database in Haskell? In-Reply-To: References: Message-ID: <20090805203237.GE28722@whirlpool.galois.com> gue.schmidt: > Hi all, > > is there an SQL Database in Haskell or is there a project trying to > implement one? > There are several bindings, http://hackage.haskell.org/packages/archive/pkg-list.html#cat:database Are you asking for an implementation of SQL though? -- Don From westondan at imageworks.com Wed Aug 5 17:33:49 2009 From: westondan at imageworks.com (Dan Weston) Date: Wed Aug 5 17:14:39 2009 Subject: [Haskell-cafe] Parsec: using two different parser for the same string In-Reply-To: <9760562b0908051042p97be03tb5f49a0905ef44d5@mail.gmail.com> References: <9760562b0908051042p97be03tb5f49a0905ef44d5@mail.gmail.com> Message-ID: <4A79FABD.3080000@imageworks.com> I think parsecMap does the job here: ----------------------- import Text.ParserCombinators.Parsec hiding ((<|>)) import Text.Parsec.Prim(parsecMap) import Control.Applicative((<|>)) import Control.Arrow((|||),(&&&)) -- Tagged (:) (<>) :: Either Char Char -> Either String String -> Either String String Left a <> Left b = Left (a:b) Left a <> Right b = Left (a:b) Right a <> Left b = Left (a:b) Right a <> Right b = Right (a:b) -- Tagged concat stringParser :: [Either Char Char] -> Either String String stringParser = foldr (<>) (Right "") -- Parse Integer if properly tagged, keeping unparsed string maybeToInteger :: Either String String -> (Maybe Integer, String) maybeToInteger = (const Nothing ||| Just . read) &&& (id ||| id) -- Tagged-choice parser intOrStringParser = parsecMap (maybeToInteger . stringParser) $ many1 (parsecMap Right digit <|> parsecMap Left (noneOf ";)")) -- Parse between parentheses intOrStringListParser = between (char '(') (char ')') (sepBy1 intOrStringParser (char ';')) ----------------------- Then you get a tagged version of each string, along with the string itself: *P> parseTest intOrStringListParser $ "(1;2w4;8;85)" [(Just 1,"1"),(Nothing,"2w4"),(Just 8,"8"),(Just 85,"85")] There may be some parsecMap-fold fusion optimization possible, though I haven't looked into that. Dan Paul Sujkov wrote: > Hi everybody, > > suppose I have two different parsers: one just reads the string, and > another one parses some values from it. E.g.: > > parseIntList :: Parser [Integer] > parseIntList = do > char '(' > res <- liftM (map read) (sepBy1 (many1 digit) (char ';')) > char ')' > return res > > parseIntString :: Parser String > parseIntString = manyTill anyChar eof > > so for some input like this - "(1;2;3;4)" - I will have two different > result: > > *Parlog> parseTest parseIntList "(1;2;3;4)" > [1,2,3,4] > *Parlog> parseTest parseIntString "(1;2;3;4)" > "(1;2;3;4)" > > but the thing that I actually want is something like Parser ([Integer], > String) - results from both parsers at a time, no matter whether one of > them fails or not: > > *Parlog> parseTest parseIntListAndString "(1;2;3;4)" > ([1,2,3,4], "(1;2;3;4)") > > it is impossible at first sight, because first parser to use will > consume all the input, and there will be nothing to parse for the second one > > Parsec contains "choice" function, but it is implemented via <|> and > that is mplus - so it tries second alternative only if the first one > fails. Is it possible to use two parsers for the same string (with > try-like backtracking, no input actually consumed till the second parser > finishes)? I can assume only dirty hacks with the GenParser internals - > manual position storing and backtracking - but that is obviously not good > > however, my first attempt to solve the problem was kind a like that: to > parse string to String, and then to use it as an input for the next > level parse call: > > parseIntListAndString :: Parser ([Integer], String) > parseIntListAndString = do > str <- parseIntString > return (res str, str) > where res str = case (parse parseIntList "" str) of > Left err -> [] > Right val -> val > > but the problems with such a method began when I switched from Parser to > GenParser with user state: function parseIntList have to update the > state, but it can't have the same state as the parseIntListAndString any > more: it has it's own. I can explicitly pass the state from > parseIntListAndString to parseIntList, but I see no suitable way for the > parseIntList to update it. I can return the updated state value from the > parseIntList function, and call setState on a result - but it seems > rather ugly to mee. However, if nothing else will do, that is an alternative > > it is of course possible to use two different parsers sequentially, but > it is also very ineffective: I need to use such multiple parsing on a > relatively small substring of the actual input, so little backtracking > would be a much nicier approach. Any suggestions? > > -- > Regards, Paul Sujkov > From gue.schmidt at web.de Wed Aug 5 18:04:02 2009 From: gue.schmidt at web.de (=?iso-8859-15?Q?G=FCnther_Schmidt?=) Date: Wed Aug 5 17:44:48 2009 Subject: [Haskell-cafe] SQL Database in Haskell? In-Reply-To: <20090805203237.GE28722@whirlpool.galois.com> References: <20090805203237.GE28722@whirlpool.galois.com> Message-ID: Hi Don, I actually meant an SQL database written in Haskell, same as Derby or HSQLDB in Java. I'm currently using Sqlite3 with HDBC but would prefer one entirely in Haskell (but still SQL though, because of persistence and performance). G?nther Am 05.08.2009, 22:32 Uhr, schrieb Don Stewart : > gue.schmidt: >> Hi all, >> >> is there an SQL Database in Haskell or is there a project trying to >> implement one? >> > > There are several bindings, > > http://hackage.haskell.org/packages/archive/pkg-list.html#cat:database > > Are you asking for an implementation of SQL though? > > -- Don From allbery at ece.cmu.edu Wed Aug 5 18:34:00 2009 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Wed Aug 5 18:14:48 2009 Subject: [Haskell-cafe] Space for commentaries on hackage In-Reply-To: References: Message-ID: On Aug 5, 2009, at 14:37 , Maur? cio CA wrote: > It would be nice to have a place for anonimous In these days of web spam, anonymous is not such a good idea. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 195 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090805/3651798d/PGP.bin From mauricio.antunes at gmail.com Wed Aug 5 19:21:49 2009 From: mauricio.antunes at gmail.com (=?ISO-8859-1?Q?Maur=ED=ADcio_CA?=) Date: Wed Aug 5 19:02:50 2009 Subject: [Haskell-cafe] Re: Space for commentaries on hackage In-Reply-To: References: Message-ID: >> It would be nice to have a place for anonimous > > > In these days of web spam, anonymous is not such a good idea. Sure! Replace "anonymous" for "easy to write". Although, thinking better, this should be something to ask at repository hosters, not at hackage. Best, Maur?cio From westondan at imageworks.com Wed Aug 5 19:33:34 2009 From: westondan at imageworks.com (Dan Weston) Date: Wed Aug 5 19:14:23 2009 Subject: [Haskell-cafe] Parsec: using two different parser for the same string In-Reply-To: <4A79FABD.3080000@imageworks.com> References: <9760562b0908051042p97be03tb5f49a0905ef44d5@mail.gmail.com> <4A79FABD.3080000@imageworks.com> Message-ID: <4A7A16CE.4070209@imageworks.com> Of course, since ParsecT s u m is a functor, feel free to use fmap instead of parsecMap. Then you don't need to import from Text.Parsec.Prim. And in hindsight, I might prefer the name (<:>) or cons to (<>) for the first function, but now I'm just obsessing. :) Dan Dan Weston wrote: > I think parsecMap does the job here: > > ----------------------- > import Text.ParserCombinators.Parsec hiding ((<|>)) > import Text.Parsec.Prim(parsecMap) > import Control.Applicative((<|>)) > import Control.Arrow((|||),(&&&)) > > -- Tagged (:) > (<>) :: Either Char Char -> Either String String -> Either String String > Left a <> Left b = Left (a:b) > Left a <> Right b = Left (a:b) > Right a <> Left b = Left (a:b) > Right a <> Right b = Right (a:b) > > -- Tagged concat > stringParser :: [Either Char Char] -> Either String String > stringParser = foldr (<>) (Right "") > > -- Parse Integer if properly tagged, keeping unparsed string > maybeToInteger :: Either String String -> (Maybe Integer, String) > maybeToInteger = (const Nothing ||| Just . read) &&& (id ||| id) > > -- Tagged-choice parser > intOrStringParser = parsecMap (maybeToInteger . stringParser) > $ many1 (parsecMap Right digit <|> parsecMap Left (noneOf ";)")) > > -- Parse between parentheses > intOrStringListParser = between (char '(') > (char ')') > (sepBy1 intOrStringParser (char ';')) > ----------------------- > > Then you get a tagged version of each string, along with the string itself: > > *P> parseTest intOrStringListParser $ "(1;2w4;8;85)" > [(Just 1,"1"),(Nothing,"2w4"),(Just 8,"8"),(Just 85,"85")] > > There may be some parsecMap-fold fusion optimization possible, though I > haven't looked into that. > > Dan > > Paul Sujkov wrote: >> Hi everybody, >> >> suppose I have two different parsers: one just reads the string, and >> another one parses some values from it. E.g.: >> >> parseIntList :: Parser [Integer] >> parseIntList = do >> char '(' >> res <- liftM (map read) (sepBy1 (many1 digit) (char ';')) >> char ')' >> return res >> >> parseIntString :: Parser String >> parseIntString = manyTill anyChar eof >> >> so for some input like this - "(1;2;3;4)" - I will have two different >> result: >> >> *Parlog> parseTest parseIntList "(1;2;3;4)" >> [1,2,3,4] >> *Parlog> parseTest parseIntString "(1;2;3;4)" >> "(1;2;3;4)" >> >> but the thing that I actually want is something like Parser ([Integer], >> String) - results from both parsers at a time, no matter whether one of >> them fails or not: >> >> *Parlog> parseTest parseIntListAndString "(1;2;3;4)" >> ([1,2,3,4], "(1;2;3;4)") >> >> it is impossible at first sight, because first parser to use will >> consume all the input, and there will be nothing to parse for the second one >> >> Parsec contains "choice" function, but it is implemented via <|> and >> that is mplus - so it tries second alternative only if the first one >> fails. Is it possible to use two parsers for the same string (with >> try-like backtracking, no input actually consumed till the second parser >> finishes)? I can assume only dirty hacks with the GenParser internals - >> manual position storing and backtracking - but that is obviously not good >> >> however, my first attempt to solve the problem was kind a like that: to >> parse string to String, and then to use it as an input for the next >> level parse call: >> >> parseIntListAndString :: Parser ([Integer], String) >> parseIntListAndString = do >> str <- parseIntString >> return (res str, str) >> where res str = case (parse parseIntList "" str) of >> Left err -> [] >> Right val -> val >> >> but the problems with such a method began when I switched from Parser to >> GenParser with user state: function parseIntList have to update the >> state, but it can't have the same state as the parseIntListAndString any >> more: it has it's own. I can explicitly pass the state from >> parseIntListAndString to parseIntList, but I see no suitable way for the >> parseIntList to update it. I can return the updated state value from the >> parseIntList function, and call setState on a result - but it seems >> rather ugly to mee. However, if nothing else will do, that is an alternative >> >> it is of course possible to use two different parsers sequentially, but >> it is also very ineffective: I need to use such multiple parsing on a >> relatively small substring of the actual input, so little backtracking >> would be a much nicier approach. Any suggestions? >> >> -- >> Regards, Paul Sujkov >> > From aslatter at gmail.com Wed Aug 5 19:36:42 2009 From: aslatter at gmail.com (Antoine Latter) Date: Wed Aug 5 19:17:27 2009 Subject: [Haskell-cafe] Re: Space for commentaries on hackage In-Reply-To: References: Message-ID: <694519c50908051636w39326307n79a28c7f6766c6f9@mail.gmail.com> 2009/8/5 Maur??cio CA : > > Sure! Replace "anonymous" for "easy to write". Although, > thinking better, this should be something to ask at repository > hosters, not at hackage. > If we're getting rid of the anonymous requirement - every package I upload to hackage includes my email address in the "maintainer" field, and I love getting emails from people who use anything I maintain (even if they're asking me to do work! I may not do it, but it's nice to know that people care). Antoine From wren at freegeek.org Wed Aug 5 19:57:37 2009 From: wren at freegeek.org (wren ng thornton) Date: Wed Aug 5 19:38:25 2009 Subject: [Haskell-cafe] Efficient functional idiom for histogram In-Reply-To: <79990c6b0908050842v2d495838t9417c3168615c48c@mail.gmail.com> References: <79990c6b0907311339o17930eaej193b39e176f601a4@mail.gmail.com> <79990c6b0908011106n75d60eeeqf54740d73dfc05a8@mail.gmail.com> <2ABA1D95-6C50-4C2D-9EE1-4AAD377FA6D0@gmail.com> <200908012238.06096.daniel.is.fischer@web.de> <741612210908050614w6dbc6356o10f65cb6252a096d@mail.gmail.com> <2608b8a80908050801l597afd4fv991ef313ac3b7fd5@mail.gmail.com> <79990c6b0908050842v2d495838t9417c3168615c48c@mail.gmail.com> Message-ID: <4A7A1C71.5040303@freegeek.org> Paul Moore wrote: > 2009/8/5 Yitzchak Gale : >> Or is this with an alternate RNG? Although I think even that >> would be fair, since Python uses Mersenne. > > I got the impression Dmitry was using Haskell's standard RNG, not > Mersenne Twister. If so, then we'd get further improvements with MT, > but that's still a hit against Haskell, as I'd interpret it as meaning > that Haskell supplies as default a PRNG which costs noticeable > performance in order to provide guarantees that "ordinary" programs > don't need. I'm not sure how fair that is. For most "ordinary" programs I've written that use randomness anywhere, they have many different places that want randomness. Having a single global seed can suffice for this, but it introduces severe constraints that are seldom noticed. Namely, these are in fact *P*RNGs. If every place needing randomness is given its own seed, then it becomes possible to store all those seeds, allowing for replay. Replay can be good for capturing the history of a particular run of a simulation/game ---which is difficult at best in non-Haskell approaches. And more critically the seeds can be stored in a "core dump" allowing replay as a debugging tool, allowing reproduction of 'random' bugs which are otherwise quite difficult to track down. Imperative languages could use the same algorithms as Haskell, but they do not; which means these benefits of PRNGs are seldom even thought of. By separating concerns, the Haskell approach not only leads to cleaner code, but that separation can also be used to add new capabilities. The invisible manacles of imperativism should not be looked upon lightly. -- Live well, ~wren From keithshep at gmail.com Wed Aug 5 20:10:45 2009 From: keithshep at gmail.com (Keith Sheppard) Date: Wed Aug 5 19:51:29 2009 Subject: [Haskell-cafe] Haskell2Xml In-Reply-To: <741612210908051249ya47b732ne8f06010204b5090@mail.gmail.com> References: <741612210908051249ya47b732ne8f06010204b5090@mail.gmail.com> Message-ID: <92e42b740908051710t1765909cg6e38f665bf221449@mail.gmail.com> Hello Dmitry, I too was looking for something like this and came up empty. I proposed something similar on the haskell_proposals reddit... http://www.reddit.com/r/haskell_proposals/comments/8zhkx/haxb_and_haxws/ ... but I was left with the impression that there isn't much interest. -Keith On Wed, Aug 5, 2009 at 3:49 PM, Dmitry Olshansky wrote: > Hello all, > I need a convenient tool to generate Haskell types from XML W3C Schema > Definition (xsd) and vice versa - generate instances for Haskell ADT's?to > make corresponding XML. > It is just the same that HaXml do with DTD. > I need > - using XSD > - support for unicode > - using xml-attributes as far as elements are very desirable > - by my opinion TemplateHaskell for generate instances is prefferable than > using DrIFT (which used in HaXml) - both possibilities is great of course > - generation of xsd by Haskell type is a good feature also > and so on... > Does this tool exist? > Do?some articles / thoughts / standards / recomendations about > correspondence between XML and Haskell ADT's?exist? > Best wishes, > Dmitry > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -- keithsheppard.name From moonlite at dtek.chalmers.se Wed Aug 5 20:16:12 2009 From: moonlite at dtek.chalmers.se (Mattias Bengtsson) Date: Wed Aug 5 19:56:55 2009 Subject: [Haskell-cafe] SQL Database in Haskell? In-Reply-To: References: <20090805203237.GE28722@whirlpool.galois.com> Message-ID: <1249517772.10884.1.camel@moonlite> On Thu, 2009-08-06 at 00:04 +0200, G?nther Schmidt wrote: > Hi Don, > > I actually meant an SQL database written in Haskell, same as Derby or > HSQLDB in Java. > > I'm currently using Sqlite3 with HDBC but would prefer one entirely in > Haskell (but still SQL though, because of persistence and performance). SQL is just a query language and the use of it is, as far as i can tell, orthogonal to the need for persistence and performance. From dons at galois.com Wed Aug 5 20:32:07 2009 From: dons at galois.com (Don Stewart) Date: Wed Aug 5 20:15:01 2009 Subject: [Haskell-cafe] SQL Database in Haskell? In-Reply-To: <1249517772.10884.1.camel@moonlite> References: <20090805203237.GE28722@whirlpool.galois.com> <1249517772.10884.1.camel@moonlite> Message-ID: <20090806003207.GK29323@whirlpool.galois.com> moonlite: > On Thu, 2009-08-06 at 00:04 +0200, G?nther Schmidt wrote: > > Hi Don, > > > > I actually meant an SQL database written in Haskell, same as Derby or > > HSQLDB in Java. > > > > I'm currently using Sqlite3 with HDBC but would prefer one entirely in > > Haskell (but still SQL though, because of persistence and performance). > > SQL is just a query language and the use of it is, as far as i can tell, > orthogonal to the need for persistence and performance. > For pure Haskell persistance, there is TCache: A Transactional data cache with configurable persistence http://hackage.haskell.org/package/TCache io-storage: A key-value store in the IO monad. http://hackage.haskell.org/package/io-storage There may be others. From gue.schmidt at web.de Wed Aug 5 20:36:09 2009 From: gue.schmidt at web.de (=?iso-8859-15?Q?G=FCnther_Schmidt?=) Date: Wed Aug 5 20:17:10 2009 Subject: [Haskell-cafe] Re: SQL Database in Haskell? References: <20090805203237.GE28722@whirlpool.galois.com> <1249517772.10884.1.camel@moonlite> Message-ID: Hi, well I tried to do some stuff in memory, and the app ended up using a couple of gigs. I not only have a very large amount of dynamic data, CSV files, but also quite a large amount of static data, and wasted 3 months trying to do this all in-memory. The problem was finally solved once I used SQLite and SQL. The other day I had one last go at trying to compile the static data in a literal list in my haskell code. That was 80.000 rows, it was just not even possible As far as I'm concerned this discussion is settled in favor of SQL once and for all. The part I didn't like about SQLite is encryption, you need to buy that extra and then hope that it fits the current version and future ones too. HSQLDB or Derby for Java give you this option and also with in-memory database, alas they are for Java only. G?nther Am 06.08.2009, 02:16 Uhr, schrieb Mattias Bengtsson : > On Thu, 2009-08-06 at 00:04 +0200, G?nther Schmidt wrote: >> Hi Don, >> >> I actually meant an SQL database written in Haskell, same as Derby or >> HSQLDB in Java. >> >> I'm currently using Sqlite3 with HDBC but would prefer one entirely in >> Haskell (but still SQL though, because of persistence and performance). > > SQL is just a query language and the use of it is, as far as i can tell, > orthogonal to the need for persistence and performance. From dons at galois.com Wed Aug 5 20:37:48 2009 From: dons at galois.com (Don Stewart) Date: Wed Aug 5 20:20:36 2009 Subject: [Haskell-cafe] Re: SQL Database in Haskell? In-Reply-To: References: <20090805203237.GE28722@whirlpool.galois.com> <1249517772.10884.1.camel@moonlite> Message-ID: <20090806003748.GN29323@whirlpool.galois.com> gue.schmidt: > Hi, > > well I tried to do some stuff in memory, and the app ended up using a > couple of gigs. I not only have a very large amount of dynamic data, CSV > files, but also quite a large amount of static data, and wasted 3 months > trying to do this all in-memory. The problem was finally solved once I > used SQLite and SQL. > > The other day I had one last go at trying to compile the static data in a > literal list in my haskell code. That was 80.000 rows, it was just not > even possible Don't compile in static data (or if you do, use -Onot, so that GHC won't try to analyze it)! Use some kind of binary on-disk storage. > As far as I'm concerned this discussion is settled in favor of SQL once > and for all. > > The part I didn't like about SQLite is encryption, you need to buy that > extra and then hope that it fits the current version and future ones too. > HSQLDB or Derby for Java give you this option and also with in-memory > database, alas they are for Java only. You might also want to look at the HAppS disk-backed persistence model, http://hackage.haskell.org/package/HAppS-State Or the holumbus distributed storage layer, http://hackage.haskell.org/package/Holumbus-Storage From gue.schmidt at web.de Wed Aug 5 20:56:55 2009 From: gue.schmidt at web.de (=?iso-8859-15?Q?G=FCnther_Schmidt?=) Date: Wed Aug 5 20:37:54 2009 Subject: [Haskell-cafe] Re: About the import module References: Message-ID: Hi all, I appreciate all the suggestions but I'd like to stress that in this particular case, the app I'm developing, SQL has proven to be the ideal solution, the input data is table based, I need to group, find maxes, do joins, whathaveyou. SQLite did miracles to memory problems and performance and HaskellDB made it a breeze to generate the proper SQL. Back to my original question, is there an SQL RDBM system written in Haskell, for use disk- or memory based? G?nther Am 05.08.2009, 20:04 Uhr, schrieb xu zhang : > Hi there, > > If I import a module and do not explicitly point out the entities I have > imported. And I want the ghc to point out the entities automatically. Is > there any method to do this? any methods to have the ghc point out the > entities I import and export? > Because there are so many files and I don't want to change them one by > one, > so I just want to find if there is a simple and automatic way to have the > entities pointed out. > > Thank you in advance! From mauricio.antunes at gmail.com Wed Aug 5 21:56:32 2009 From: mauricio.antunes at gmail.com (=?ISO-8859-1?Q?Maur=ED=ADcio_CA?=) Date: Wed Aug 5 21:37:36 2009 Subject: [Haskell-cafe] Re: Space for commentaries on hackage In-Reply-To: <694519c50908051636w39326307n79a28c7f6766c6f9@mail.gmail.com> References: <694519c50908051636w39326307n79a28c7f6766c6f9@mail.gmail.com> Message-ID: >> Sure! Replace "anonymous" for "easy to write". [...] > [...] every package I upload to hackage includes my email > address in the "maintainer" field, and I love getting emails > from people who use anything I maintain (even if they're asking > me to do work! I may not do it, but it's nice to know that > people care). My motivation for this post is that I'm also interested on the comments from those who don't :) Seriously, it may be usefull to get comments like "why would I use this, if package X already do that better?" But, for politeness if for no other reason, people won't write you to say that. Best, Maur?cio From mauricio.antunes at gmail.com Wed Aug 5 22:14:40 2009 From: mauricio.antunes at gmail.com (=?ISO-8859-1?Q?Maur=ED=ADcio_CA?=) Date: Wed Aug 5 21:55:37 2009 Subject: [Haskell-cafe] Do you understand posix well? Message-ID: I've beeing writing a low-level binding to posix that can be usefull if you want to use posix but has no time to learn FFI: http://hackage.haskell.org/package/bindings-posix However, my understandment of posix is barely nothing, and I see that many of its functionality is enabled or disabled by macros, and I don't know which ones are related to what functionality. So, if you know about that: would you be able to list all macros (or at least most important ones, if there are too many) that enable all (or most) of posix? In exchange, you get a posix binding that is actually comprehensive :) Thanks, Maur?cio From leaveye.guo at gmail.com Wed Aug 5 23:33:47 2009 From: leaveye.guo at gmail.com (L.Guo) Date: Wed Aug 5 23:22:21 2009 Subject: [Haskell-cafe] A mistake in haskellwiki Message-ID: <200908061133440318575@gmail.com> Hi haskellers: There is a mistake in http://www.haskell.org/haskellwiki/State_Monad It post two functions like this : evalState :: State s a -> s -> a evalState act = fst $ runState act execState :: State s a -> s -> s execState act = snd $ runState act Both the '$' operators should be '.'. Anyone would correct it ? Regards -------------- L.Guo 2009-08-06 From dons at galois.com Wed Aug 5 23:43:06 2009 From: dons at galois.com (Don Stewart) Date: Wed Aug 5 23:25:54 2009 Subject: [Haskell-cafe] A mistake in haskellwiki In-Reply-To: <200908061133440318575@gmail.com> References: <200908061133440318575@gmail.com> Message-ID: <20090806034306.GA30435@whirlpool.galois.com> leaveye.guo: > Hi haskellers: > > There is a mistake in http://www.haskell.org/haskellwiki/State_Monad > > It post two functions like this : > > evalState :: State s a -> s -> a > evalState act = fst $ runState act > > execState :: State s a -> s -> s > execState act = snd $ runState act > > Both the '$' operators should be '.'. > > Anyone would correct it ? Well, it's a wiki ... :-) -- Don From ck_kashyap at yahoo.com Thu Aug 6 00:45:44 2009 From: ck_kashyap at yahoo.com (CK Kashyap) Date: Thu Aug 6 00:26:29 2009 Subject: [Haskell-cafe] Re: SQL Database in Haskell? In-Reply-To: <20090806003748.GN29323@whirlpool.galois.com> References: <20090805203237.GE28722@whirlpool.galois.com> <1249517772.10884.1.camel@moonlite> <20090806003748.GN29323@whirlpool.galois.com> Message-ID: <741022.97004.qm@web112514.mail.gq1.yahoo.com> I'd be very interested to see a rdbms implementation in Haskell ... perhaps a port of sqlite Regards, Kashyap ________________________________ From: Don Stewart To: G?nther Schmidt Cc: haskell-cafe@haskell.org Sent: Thursday, August 6, 2009 6:07:48 AM Subject: Re: [Haskell-cafe] Re: SQL Database in Haskell? gue.schmidt: > Hi, > > well I tried to do some stuff in memory, and the app ended up using a > couple of gigs. I not only have a very large amount of dynamic data, CSV > files, but also quite a large amount of static data, and wasted 3 months > trying to do this all in-memory. The problem was finally solved once I > used SQLite and SQL. > > The other day I had one last go at trying to compile the static data in a > literal list in my haskell code. That was 80.000 rows, it was just not > even possible Don't compile in static data (or if you do, use -Onot, so that GHC won't try to analyze it)! Use some kind of binary on-disk storage. > As far as I'm concerned this discussion is settled in favor of SQL once > and for all. > > The part I didn't like about SQLite is encryption, you need to buy that > extra and then hope that it fits the current version and future ones too. > HSQLDB or Derby for Java give you this option and also with in-memory > database, alas they are for Java only. You might also want to look at the HAppS disk-backed persistence model, http://hackage.haskell.org/package/HAppS-State Or the holumbus distributed storage layer, http://hackage.haskell.org/package/Holumbus-Storage _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090806/fde023fd/attachment.html From explicitcall at googlemail.com Thu Aug 6 01:19:14 2009 From: explicitcall at googlemail.com (Max Desyatov) Date: Thu Aug 6 00:59:55 2009 Subject: [Haskell-cafe] Re: SQL Database in Haskell? In-Reply-To: CK Kashyap's message of "Wed\, 5 Aug 2009 21\:45\:44 -0700 \(PDT\)" Message-ID: <87fxc5jz8t.fsf@zagan.made.you> As I can say from my experience of usage of hdbc-sqlite3 and happstack-state, the latter covers everything you ever wanted from sqlite3 and more. It you aren't too concerned about performance, you can free yourself from many tedious routines that are imminent when you work with relational database. Elaborated data model design coupled with some generics technique (uniplate with derive, e.g.) gives you a possibility to write down your domain problem directly to haskell. CK Kashyap writes: > I'd be very interested to see a rdbms implementation in Haskell ... > perhaps a port of sqlite > > Regards, > Kashyap From gwern0 at gmail.com Thu Aug 6 02:11:50 2009 From: gwern0 at gmail.com (Gwern Branwen) Date: Thu Aug 6 01:52:42 2009 Subject: [Haskell-cafe] Getting highest sum of list elements with Map In-Reply-To: <2608b8a80908050353t2d5a4b14na63e5a6139ed3cf8@mail.gmail.com> Message-ID: Skipped content of type multipart/signed-------------- next part -------------- A non-text attachment was scrubbed... Name: hcorpus.hs Type: text/x-haskell Size: 3425 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090806/43634746/hcorpus.bin From thaldyron at gmail.com Thu Aug 6 03:09:47 2009 From: thaldyron at gmail.com (Peter Robinson) Date: Thu Aug 6 02:50:51 2009 Subject: [Haskell-cafe] SQL Database in Haskell? In-Reply-To: <20090806003207.GK29323@whirlpool.galois.com> References: <20090805203237.GE28722@whirlpool.galois.com> <1249517772.10884.1.camel@moonlite> <20090806003207.GK29323@whirlpool.galois.com> Message-ID: 2009/8/6 Don Stewart : > For pure Haskell persistance, there is > > ? ?TCache: A Transactional data cache with configurable persistence > ? ? ? ?http://hackage.haskell.org/package/TCache > > ? ?io-storage: A key-value store in the IO monad. > ? ? ? ?http://hackage.haskell.org/package/io-storage > > There may be others. persistent-map: A thread-safe (STM) persistency interface for finite map types. http://hackage.haskell.org/package/persistent-map (still experimental) Peter From shinnonoir at gmail.com Thu Aug 6 05:22:19 2009 From: shinnonoir at gmail.com (Raynor Vliegendhart) Date: Thu Aug 6 05:03:04 2009 Subject: [Haskell-cafe] A mistake in haskellwiki In-Reply-To: <20090806034306.GA30435@whirlpool.galois.com> References: <200908061133440318575@gmail.com> <20090806034306.GA30435@whirlpool.galois.com> Message-ID: <6d961e560908060222g53792591kf16e69f0515f3171@mail.gmail.com> On 8/6/09, Don Stewart wrote: > leaveye.guo: > > Hi haskellers: > > > > There is a mistake in http://www.haskell.org/haskellwiki/State_Monad > > > > It post two functions like this : > > > > evalState :: State s a -> s -> a > > evalState act = fst $ runState act > > > > execState :: State s a -> s -> s > > execState act = snd $ runState act > > > > Both the '$' operators should be '.'. > > > > Anyone would correct it ? Fixed :) > Well, it's a wiki ... :-) > > -- Don That might be true, but not everyone has an account :) From marlowsd at gmail.com Thu Aug 6 06:17:28 2009 From: marlowsd at gmail.com (Simon Marlow) Date: Thu Aug 6 05:58:13 2009 Subject: [Haskell-cafe] Re: FFI: Problem with Signal Handler Interruptions In-Reply-To: <3e62d4360908050901u392ae7e2m5a48d177cd90435b@mail.gmail.com> References: <3e62d4360908040106v24e87d3as987979d3e34943ff@mail.gmail.com> <3e62d4360908050901u392ae7e2m5a48d177cd90435b@mail.gmail.com> Message-ID: <4A7AADB8.7040802@gmail.com> The SIGVTALRM signal is delivered to one (random) thread in the program, so I imagine it just isn't being delivered to the thread that runs your second call to sleep. (the main Haskell thread is a "bound thread" and hence gets an OS thread to itself). Is there some reason you can't use threadDelay? threadDelay is much more friendly: it doesn't require another OS thread for each sleeping Haskell thread. Cheers, Simon On 05/08/2009 17:01, Levi Greenspan wrote: > Nobody? > > On Tue, Aug 4, 2009 at 10:06 AM, Levi > Greenspan wrote: >> Dear list members, >> >> In February this year there was a posting "Why does sleep not work?" >> (http://www.haskell.org/pipermail/haskell-cafe/2009-February/055400.html). >> The problem was apparently caused by signal handler interruptions. I >> noticed the same (not with sleep though) when doing some FFI work and >> compiled the following test program: >> >> >> {-# LANGUAGE ForeignFunctionInterface #-} >> module Main where >> >> import Foreign.C.Types >> import Control.Concurrent >> >> sleep :: IO () >> sleep = c_sleep 3>>= print >> >> fails :: IO () >> fails = sleep >> >> works :: IO () >> works = forkIO sleep>> return () >> >> main :: IO () >> main = fails>> works>> threadDelay 3000000 >> >> foreign import ccall unsafe "unistd.h sleep" >> c_sleep :: CUInt -> IO CUInt >> >> >> When compiled with GHC (using --make -threaded), it will print 3 >> immediately (from the "fails" function) and after 3 seconds 0 (from >> "works"), before it finally exits. man sleep(3) tells me that sleep >> returns 0 on success and if interrupted by a signal the number of >> seconds left to sleep. Clearly "fails" is interrupted by a signal >> (which seems to be SIGVTALRM). This was mentioned in the discussion >> from February. >> >> I would like to know why "fails" fails and "works" works, i.e. why is >> "sleep" not interrupted when run in a separate thread? And what can be >> done to make "sleep" work in the main thread? It wouldn't be wise to >> block SIGVTALRM, wouldn't it? >> >> Many thanks, >> Levi >> From daniel.schoepe at googlemail.com Thu Aug 6 06:57:54 2009 From: daniel.schoepe at googlemail.com (Daniel Schoepe) Date: Thu Aug 6 06:38:36 2009 Subject: [Haskell-cafe] n00b question: defining datatype In-Reply-To: References: <4A68B2CB.4060308@gmail.com> Message-ID: <20090806105754.GA5917@nemesis> On Thu, Jul 23, 2009 at 08:17:34PM +0100, Iain Barnett wrote: > [..] > against the empty list it's not really a problem to have it there. I didn't > realise I could use Maybe in the constructor because it's a monad, but > that's good because I was wondering about the best way to make a nullable > value. Actually, this has nothing to do with Maybe being a monad. The reason you can do this is because "Maybe" itself is not a type, but a (unary) type constructor(It has kind * -> *), so you need to apply it to another type. Doing something like "test :: Maybe" would be an error. > That Data.Tree module looks interesting too! It does seem to be a > naturally recursive type, but I'm still trying to become easy with that sort > of thought :) > [..] A list is also recursively defined, so it is not really more difficult to use a Tree instead. E.g. one could define a list type like this: data List a = Nil | Cons a (List a) - Daniel -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090806/ac1ad0e5/attachment.bin From greenspan.levi at googlemail.com Thu Aug 6 07:10:09 2009 From: greenspan.levi at googlemail.com (Levi Greenspan) Date: Thu Aug 6 06:50:55 2009 Subject: [Haskell-cafe] Re: FFI: Problem with Signal Handler Interruptions In-Reply-To: <4A7AADB8.7040802@gmail.com> References: <3e62d4360908040106v24e87d3as987979d3e34943ff@mail.gmail.com> <3e62d4360908050901u392ae7e2m5a48d177cd90435b@mail.gmail.com> <4A7AADB8.7040802@gmail.com> Message-ID: <3e62d4360908060410w40986096k94b514619a1b5813@mail.gmail.com> Hi Simon, Many thanks for your reply. I am not actually using sleep in my code. I only used it for here for highlighting the problem. It will be the same when using poll(2) for instance. Does this mean that because of SIGVTALRM I can always get an EINTR when calling a foreign function that blocks on a system call? Cheers, Levi On Thu, Aug 6, 2009 at 12:17 PM, Simon Marlow wrote: > The SIGVTALRM signal is delivered to one (random) thread in the program, so > I imagine it just isn't being delivered to the thread that runs your second > call to sleep. ?(the main Haskell thread is a "bound thread" and hence gets > an OS thread to itself). > > Is there some reason you can't use threadDelay? ?threadDelay is much more > friendly: it doesn't require another OS thread for each sleeping Haskell > thread. > > Cheers, > ? ? ? ?Simon > > On 05/08/2009 17:01, Levi Greenspan wrote: >> >> Nobody? >> >> On Tue, Aug 4, 2009 at 10:06 AM, Levi >> Greenspan ?wrote: >>> >>> Dear list members, >>> >>> In February this year there was a posting "Why does sleep not work?" >>> >>> (http://www.haskell.org/pipermail/haskell-cafe/2009-February/055400.html). >>> The problem was apparently caused by signal handler interruptions. I >>> noticed the same (not with sleep though) when doing some FFI work and >>> compiled the following test program: >>> >>> >>> {-# LANGUAGE ForeignFunctionInterface #-} >>> module Main where >>> >>> import Foreign.C.Types >>> import Control.Concurrent >>> >>> sleep :: IO () >>> sleep = c_sleep 3>>= print >>> >>> fails :: IO () >>> fails = sleep >>> >>> works :: IO () >>> works = forkIO sleep>> ?return () >>> >>> main :: IO () >>> main = fails>> ?works>> ?threadDelay 3000000 >>> >>> foreign import ccall unsafe "unistd.h sleep" >>> ? ?c_sleep :: CUInt -> ?IO CUInt >>> >>> >>> When compiled with GHC (using --make -threaded), it will print 3 >>> immediately (from the "fails" function) and after 3 seconds 0 (from >>> "works"), before it finally exits. man sleep(3) tells me that sleep >>> returns 0 on success and if interrupted by a signal the number of >>> seconds left to sleep. Clearly "fails" is interrupted by a signal >>> (which seems to be SIGVTALRM). This was mentioned in the discussion >>> from February. >>> >>> I would like to know why "fails" fails and "works" works, i.e. why is >>> "sleep" not interrupted when run in a separate thread? And what can be >>> done to make "sleep" work in the main thread? It wouldn't be wise to >>> block SIGVTALRM, wouldn't it? >>> >>> Many thanks, >>> Levi >>> > > From jake.mcarthur at gmail.com Thu Aug 6 09:36:57 2009 From: jake.mcarthur at gmail.com (Jake McArthur) Date: Thu Aug 6 09:17:44 2009 Subject: [Haskell-cafe] A mistake in haskellwiki In-Reply-To: <20090806034306.GA30435@whirlpool.galois.com> References: <200908061133440318575@gmail.com> <20090806034306.GA30435@whirlpool.galois.com> Message-ID: <4A7ADC79.2010807@gmail.com> Don Stewart wrote: > leaveye.guo: >> Hi haskellers: >> >> There is a mistake in http://www.haskell.org/haskellwiki/State_Monad >> >> It post two functions like this : >> >> evalState :: State s a -> s -> a >> evalState act = fst $ runState act >> >> execState :: State s a -> s -> s >> execState act = snd $ runState act >> >> Both the '$' operators should be '.'. >> >> Anyone would correct it ? > > > Well, it's a wiki ... :-) Which requires registration and has not been open for registration for some time now. - Jake From gwern0 at gmail.com Thu Aug 6 09:52:00 2009 From: gwern0 at gmail.com (Gwern Branwen) Date: Thu Aug 6 09:32:54 2009 Subject: [Haskell-cafe] A mistake in haskellwiki In-Reply-To: <4A7ADC79.2010807@gmail.com> Message-ID: On Thu, Aug 6, 2009 at 9:36 AM, Jake McArthur wrote: > Which requires registration and has not been open for registration for some > time now. > > - Jake It's been open for registration for some time now. -- gwern -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: OpenPGP digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090806/57249573/signature.bin From leather at cs.uu.nl Thu Aug 6 10:01:22 2009 From: leather at cs.uu.nl (Sean Leather) Date: Thu Aug 6 09:42:25 2009 Subject: [Haskell-cafe] A mistake in haskellwiki In-Reply-To: References: <4A7ADC79.2010807@gmail.com> Message-ID: <3c6288ab0908060701u34d30e8dsd40f6b4a4730d198@mail.gmail.com> On Thu, Aug 6, 2009 at 15:52, Gwern Branwen wrote: > On Thu, Aug 6, 2009 at 9:36 AM, Jake McArthur wrote: > >> Which requires registration and has not been open for registration for >> some >> time now. >> > > It's been open for registration for some time now. > In that case, how about changing the site notice[1] from "Note: new account creation has been disabled as an anti-spam measure," which seems to indicate otherwise, to something more informative. Alternatively, add an informative link to the login page[2] and clear the site notice. Regards, Sean [1] http://www.haskell.org/haskellwiki/MediaWiki:Sitenotice [2] http://www.haskell.org/haskellwiki/Special:Userlogin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090806/e64d5ffa/attachment.html From mail at joachim-breitner.de Thu Aug 6 10:27:56 2009 From: mail at joachim-breitner.de (Joachim Breitner) Date: Thu Aug 6 10:08:39 2009 Subject: [Haskell-cafe] Request for Changelogs Message-ID: <1249568876.10202.65.camel@localhost> Hi, (this is mostly a rant, but hopefully a constructive one) the Haskell/cabal/hackage eco system is pretty great, as we all know. But there is one huge gaping omission there: Changelogs! I?m involved in packaging Haskell stuff for Debian. Now, the Debian tools we have for that tell me ?Hlint has a new version, 1.6.5, which is newer than the one you packages, 1.6.4. Huh, nice. What has changed? Is it relevant for Debian? Is it worth a new upload? There is no easy way to find out: http://hackage.haskell.org/package/hlint lists no changes http://community.haskell.org/~ndm/hlint/ lists no changes (and not every package has a homepage) http://community.haskell.org/~ndm/darcs/hlint/ contains on Changes file (and not every package has a (linked) darcs repository) http://community.haskell.org/~ndm/darcs/hlint/ also has no web frontend. Which leaves me with the option of getting the darcs repo and looking through "darcs changes". If I know of a repository for the package. So please, package authors, put Changes files in your packages and keep the current for now. And cabal/hackage guys: Llease introduce a standard Changes format for cabal packages so that http://hackage.haskell.org/package/hlint readily lists (or links to) changes. Thanks, Joachim -- Joachim "nomeata" Breitner Debian Developer nomeata@debian.org | ICQ# 74513189 | GPG-Keyid: 4743206C JID: nomeata@joachim-breitner.de | http://people.debian.org/~nomeata -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: Dies ist ein digital signierter Nachrichtenteil Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090806/f61b60b3/attachment.bin From jeff at nokrev.com Thu Aug 6 10:30:27 2009 From: jeff at nokrev.com (Jeff Wheeler) Date: Thu Aug 6 10:11:31 2009 Subject: [Haskell-cafe] Request for Changelogs In-Reply-To: <1249568876.10202.65.camel@localhost> References: <1249568876.10202.65.camel@localhost> Message-ID: <50c1e0910908060730n79c452ddn9dbecdd3cf82e98e@mail.gmail.com> On Thu, Aug 6, 2009 at 9:27 AM, Joachim Breitner wrote: > And cabal/hackage guys: Llease introduce a standard Changes format for > cabal packages so that http://hackage.haskell.org/package/hlint readily > lists (or links to) changes. (+1) Standardizing a CHANGES format and linking to from Hackage would be a very simple way to do changelogs in Hackage. I like this solution. Jeff Wheeler From felipe.lessa at gmail.com Thu Aug 6 10:39:02 2009 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Thu Aug 6 10:19:52 2009 Subject: [Haskell-cafe] Request for Changelogs In-Reply-To: <1249568876.10202.65.camel@localhost> References: <1249568876.10202.65.camel@localhost> Message-ID: <20090806143902.GA13649@kira.casa> On Thu, Aug 06, 2009 at 04:27:56PM +0200, Joachim Breitner wrote: > And cabal/hackage guys: Llease introduce a standard Changes format for > cabal packages so that http://hackage.haskell.org/package/hlint readily > lists (or links to) changes. I second that! +1 -- Felipe. From ndmitchell at gmail.com Thu Aug 6 10:39:26 2009 From: ndmitchell at gmail.com (Neil Mitchell) Date: Thu Aug 6 10:20:09 2009 Subject: [Haskell-cafe] Request for Changelogs In-Reply-To: <1249568876.10202.65.camel@localhost> References: <1249568876.10202.65.camel@localhost> Message-ID: <404396ef0908060739m350040se604debc9b104690@mail.gmail.com> Hi > I?m involved in packaging Haskell stuff for Debian. Now, the Debian > tools we have for that tell me ?Hlint has a new version, 1.6.5, which is > newer than the one you packages, 1.6.4. > > Huh, nice. What has changed? Is it relevant for Debian? Is it worth a > new upload? There is no easy way to find out: I went to my bug tracker, which informs me that: http://code.google.com/p/ndmitchell/issues/detail?id=206 http://code.google.com/p/ndmitchell/issues/detail?id=208 Were both fixed in this release. I don't think this is a practical way for people to find out what gets fixed, since it was rather difficult to get the information out, but it is the answer if you were interested in this case. > http://community.haskell.org/~ndm/darcs/hlint/ also has no web frontend. > > Which leaves me with the option of getting the darcs repo and looking > through "darcs changes". If I know of a repository for the package. I also don't tag the darcs version when I make a release - I probably should... > So please, package authors, put Changes files in your packages and keep > the current for now. The problem is that this is the kind of dull administration stuff that isn't coding in Haskell, so tends to get neglected. If I know there is a user demand for a changelog I'm happy to provide one, but I don't want to waste time on something that isn't useful. For people who have a near zero-upgrade cost (anyone who is using Cabal) I'd suggest they upgrade to all of my packages immediately. For this change, I'd say it probably isn't worth rolling a new debian binary unless it's particularly easy. I will start a changelog in hlint - and for some of my projects (tagsoup) I do include a changelog in the user manual. Thanks Neil From gwern0 at gmail.com Thu Aug 6 10:12:52 2009 From: gwern0 at gmail.com (Gwern Branwen) Date: Thu Aug 6 10:22:49 2009 Subject: [Haskell-cafe] A mistake in haskellwiki In-Reply-To: <3c6288ab0908060701u34d30e8dsd40f6b4a4730d198@mail.gmail.com> Message-ID: On Thu, Aug 6, 2009 at 10:01 AM, Sean Leather wrote: > > On Thu, Aug 6, 2009 at 15:52, Gwern Branwen?wrote: >> >> On Thu, Aug 6, 2009 at 9:36 AM, Jake McArthur wrote: >>> >>> Which requires registration and has not been open for registration for >>> some >>> time now. >> >> It's been open for registration for some time now. > > In that case, how about changing the site notice[1] from "Note: new account > creation has been disabled as an anti-spam measure," which seems to indicate > otherwise, to something more informative. Alternatively, add an informative > link to the login page[2] and clear the site notice. > > Regards, > Sean > > [1] http://www.haskell.org/haskellwiki/MediaWiki:Sitenotice > [2] http://www.haskell.org/haskellwiki/Special:Userlogin > Only admins can edit the sitenotice, and the only active admin is Ashley, who I emailed earlier about this. -- gwern -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: OpenPGP digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090806/4ec6c0e9/signature.bin From mail at joachim-breitner.de Thu Aug 6 10:49:32 2009 From: mail at joachim-breitner.de (Joachim Breitner) Date: Thu Aug 6 10:30:15 2009 Subject: [Haskell-cafe] Request for Changelogs In-Reply-To: <404396ef0908060739m350040se604debc9b104690@mail.gmail.com> References: <1249568876.10202.65.camel@localhost> <404396ef0908060739m350040se604debc9b104690@mail.gmail.com> Message-ID: <1249570172.10202.76.camel@localhost> Hi, Am Donnerstag, den 06.08.2009, 15:39 +0100 schrieb Neil Mitchell: > > So please, package authors, put Changes files in your packages and keep > > the current for now. > > The problem is that this is the kind of dull administration stuff that > isn't coding in Haskell, so tends to get neglected. If I know there is > a user demand for a changelog I'm happy to provide one, but I don't > want to waste time on something that isn't useful. For people who have > a near zero-upgrade cost (anyone who is using Cabal) I'd suggest they > upgrade to all of my packages immediately. For this change, I'd say it > probably isn't worth rolling a new debian binary unless it's > particularly easy. > > I will start a changelog in hlint - and for some of my projects > (tagsoup) I do include a changelog in the user manual. thanks, a changelog in the manual is at least a start. But the point I?d like to make is that even if everyone provides a changelog somewhere, if you need to keep track of four dozen packages[1], finding out where that is on a per-package base is quite some hassle. And even ordinary users are curious about the improvements that were made between two releases! If the changelog had a properly specified format and location, cabal upgrade could, if the user wants it, tell him all the downloaded changes. This really helps him to keep up-to-date. It is also a good channel for the authors to talk to his users (?see this nice module I added to the package?, ?some parts of the API are deprecated now, please move to this part?). Last but not least having documented changes is QA measure that the Haskell platform in the wider sense deserves. Greetings, Joachim -- Joachim "nomeata" Breitner mail: mail@joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C JID: nomeata@joachim-breitner.de | http://www.joachim-breitner.de/ Debian Developer: nomeata@debian.org -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: Dies ist ein digital signierter Nachrichtenteil Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090806/3ecc0ef1/attachment.bin From magnus at therning.org Thu Aug 6 11:23:37 2009 From: magnus at therning.org (Magnus Therning) Date: Thu Aug 6 11:04:21 2009 Subject: [Haskell-cafe] A mistake in haskellwiki In-Reply-To: <3c6288ab0908060701u34d30e8dsd40f6b4a4730d198@mail.gmail.com> References: <4A7ADC79.2010807@gmail.com> <3c6288ab0908060701u34d30e8dsd40f6b4a4730d198@mail.gmail.com> Message-ID: On Thu, Aug 6, 2009 at 3:01 PM, Sean Leather wrote: > > On Thu, Aug 6, 2009 at 15:52, Gwern Branwen?wrote: >> >> On Thu, Aug 6, 2009 at 9:36 AM, Jake McArthur wrote: >>> >>> Which requires registration and has not been open for registration for >>> some >>> time now. >> >> It's been open for registration for some time now. > > In that case, how about changing the site notice[1] from "Note: new account > creation has been disabled as an anti-spam measure," which seems to indicate > otherwise, to something more informative. Alternatively, add an informative > link to the login page[2] and clear the site notice. If you click the link ("new account creation") you will be lead to the information about how to get an account. Perhaps not the best way to lead people to that info, but it's all there. /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?org http://therning.org/magnus identi.ca|twitter: magthe From dagit at codersbase.com Thu Aug 6 11:39:02 2009 From: dagit at codersbase.com (Jason Dagit) Date: Thu Aug 6 11:19:45 2009 Subject: [Haskell-cafe] Haskell2Xml In-Reply-To: <92e42b740908051710t1765909cg6e38f665bf221449@mail.gmail.com> References: <741612210908051249ya47b732ne8f06010204b5090@mail.gmail.com> <92e42b740908051710t1765909cg6e38f665bf221449@mail.gmail.com> Message-ID: On Wed, Aug 5, 2009 at 5:10 PM, Keith Sheppard wrote: > Hello Dmitry, > > I too was looking for something like this and came up empty. I > proposed something similar on the haskell_proposals reddit... > > http://www.reddit.com/r/haskell_proposals/comments/8zhkx/haxb_and_haxws/ > > ... but I was left with the impression that there isn't much interest. Several years ago, (probably 2005) I wanted this as well. I ended up hand crafting a DTD from the xsd and then using haxml. Since xsd is xml maybe it's easiest to use xslt (or use haxml) and write it yourself? I'm sure it would catch on once it exists. Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090806/6984d458/attachment.html From ndmitchell at gmail.com Thu Aug 6 11:46:39 2009 From: ndmitchell at gmail.com (Neil Mitchell) Date: Thu Aug 6 11:27:22 2009 Subject: [Haskell-cafe] Request for Changelogs In-Reply-To: <1249570172.10202.76.camel@localhost> References: <1249568876.10202.65.camel@localhost> <404396ef0908060739m350040se604debc9b104690@mail.gmail.com> <1249570172.10202.76.camel@localhost> Message-ID: <404396ef0908060846n1cafd4d9lc77e14ca4bb948fa@mail.gmail.com> Hi http://community.haskell.org/~ndm/darcs/hlint/CHANGES.txt That will now be updated for future HLint releases. Thanks, Neil On Thu, Aug 6, 2009 at 3:49 PM, Joachim Breitner wrote: > Hi, > > Am Donnerstag, den 06.08.2009, 15:39 +0100 schrieb Neil Mitchell: >> > So please, package authors, put Changes files in your packages and keep >> > the current for now. >> >> The problem is that this is the kind of dull administration stuff that >> isn't coding in Haskell, so tends to get neglected. If I know there is >> a user demand for a changelog I'm happy to provide one, but I don't >> want to waste time on something that isn't useful. For people who have >> a near zero-upgrade cost (anyone who is using Cabal) I'd suggest they >> upgrade to all of my packages immediately. For this change, I'd say it >> probably isn't worth rolling a new debian binary unless it's >> particularly easy. >> >> I will start a changelog in hlint - and for some of my projects >> (tagsoup) I do include a changelog in the user manual. > > thanks, a changelog in the manual is at least a start. But the point I?d > like to make is that even if everyone provides a changelog somewhere, if > you need to keep track of four dozen packages[1], finding out where that > is on a per-package base is quite some hassle. And even ordinary users > are curious about the improvements that were made between two releases! > > If the changelog had a properly specified format and location, cabal > upgrade could, if the user wants it, tell him all the downloaded > changes. This really helps him to keep up-to-date. It is also a good > channel for the authors to talk to his users (?see this nice module I > added to the package?, ?some parts of the API are deprecated now, please > move to this part?). Last but not least having documented changes is QA > measure that the Haskell platform in the wider sense deserves. > > Greetings, > Joachim > > -- > Joachim "nomeata" Breitner > ?mail: mail@joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C > ?JID: nomeata@joachim-breitner.de | http://www.joachim-breitner.de/ > ?Debian Developer: nomeata@debian.org > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > From psujkov at gmail.com Thu Aug 6 11:59:31 2009 From: psujkov at gmail.com (Paul Sujkov) Date: Thu Aug 6 11:40:17 2009 Subject: [Haskell-cafe] Parsec: using two different parser for the same string In-Reply-To: <4A7A16CE.4070209@imageworks.com> References: <9760562b0908051042p97be03tb5f49a0905ef44d5@mail.gmail.com> <4A79FABD.3080000@imageworks.com> <4A7A16CE.4070209@imageworks.com> Message-ID: <9760562b0908060859m5c49d9f0te659c5c75086753e@mail.gmail.com> Hi Dan, thank you for the solution. It looks pretty interesting and usable, however I'll have to spend some time understanding arrows: I never had an opportunity to use them before. Anyway, it looks very close to what I actually need, and in any case much less ugly than breaking the GenParser encapsulation 2009/8/6 Dan Weston > Of course, since ParsecT s u m is a functor, feel free to use fmap instead > of parsecMap. Then you don't need to import from Text.Parsec.Prim. > And in hindsight, I might prefer the name (<:>) or cons to (<>) for the > first function, but now I'm just obsessing. :) > > Dan > > > Dan Weston wrote: > >> I think parsecMap does the job here: >> >> ----------------------- >> import Text.ParserCombinators.Parsec hiding ((<|>)) >> import Text.Parsec.Prim(parsecMap) >> import Control.Applicative((<|>)) >> import Control.Arrow((|||),(&&&)) >> >> -- Tagged (:) >> (<>) :: Either Char Char -> Either String String -> Either String String >> Left a <> Left b = Left (a:b) >> Left a <> Right b = Left (a:b) >> Right a <> Left b = Left (a:b) >> Right a <> Right b = Right (a:b) >> >> -- Tagged concat >> stringParser :: [Either Char Char] -> Either String String >> stringParser = foldr (<>) (Right "") >> >> -- Parse Integer if properly tagged, keeping unparsed string >> maybeToInteger :: Either String String -> (Maybe Integer, String) >> maybeToInteger = (const Nothing ||| Just . read) &&& (id ||| id) >> >> -- Tagged-choice parser >> intOrStringParser = parsecMap (maybeToInteger . stringParser) >> $ many1 (parsecMap Right digit <|> parsecMap Left (noneOf ";)")) >> >> -- Parse between parentheses >> intOrStringListParser = between (char '(') >> (char ')') >> (sepBy1 intOrStringParser (char ';')) >> ----------------------- >> >> Then you get a tagged version of each string, along with the string >> itself: >> >> *P> parseTest intOrStringListParser $ "(1;2w4;8;85)" >> [(Just 1,"1"),(Nothing,"2w4"),(Just 8,"8"),(Just 85,"85")] >> >> There may be some parsecMap-fold fusion optimization possible, though I >> haven't looked into that. >> >> Dan >> >> Paul Sujkov wrote: >> >>> Hi everybody, >>> >>> suppose I have two different parsers: one just reads the string, and >>> another one parses some values from it. E.g.: >>> >>> parseIntList :: Parser [Integer] >>> parseIntList = do >>> char '(' >>> res <- liftM (map read) (sepBy1 (many1 digit) (char ';')) >>> char ')' >>> return res >>> >>> parseIntString :: Parser String >>> parseIntString = manyTill anyChar eof >>> >>> so for some input like this - "(1;2;3;4)" - I will have two different >>> result: >>> >>> *Parlog> parseTest parseIntList "(1;2;3;4)" >>> [1,2,3,4] >>> *Parlog> parseTest parseIntString "(1;2;3;4)" >>> "(1;2;3;4)" >>> >>> but the thing that I actually want is something like Parser ([Integer], >>> String) - results from both parsers at a time, no matter whether one of them >>> fails or not: >>> >>> *Parlog> parseTest parseIntListAndString "(1;2;3;4)" >>> ([1,2,3,4], "(1;2;3;4)") >>> >>> it is impossible at first sight, because first parser to use will consume >>> all the input, and there will be nothing to parse for the second one >>> >>> Parsec contains "choice" function, but it is implemented via <|> and that >>> is mplus - so it tries second alternative only if the first one fails. Is it >>> possible to use two parsers for the same string (with try-like backtracking, >>> no input actually consumed till the second parser finishes)? I can assume >>> only dirty hacks with the GenParser internals - manual position storing and >>> backtracking - but that is obviously not good >>> >>> however, my first attempt to solve the problem was kind a like that: to >>> parse string to String, and then to use it as an input for the next level >>> parse call: >>> >>> parseIntListAndString :: Parser ([Integer], String) >>> parseIntListAndString = do >>> str <- parseIntString >>> return (res str, str) >>> where res str = case (parse parseIntList "" str) of >>> Left err -> [] >>> Right val -> val >>> >>> but the problems with such a method began when I switched from Parser to >>> GenParser with user state: function parseIntList have to update the state, >>> but it can't have the same state as the parseIntListAndString any more: it >>> has it's own. I can explicitly pass the state from parseIntListAndString to >>> parseIntList, but I see no suitable way for the parseIntList to update it. I >>> can return the updated state value from the parseIntList function, and call >>> setState on a result - but it seems rather ugly to mee. However, if nothing >>> else will do, that is an alternative >>> >>> it is of course possible to use two different parsers sequentially, but >>> it is also very ineffective: I need to use such multiple parsing on a >>> relatively small substring of the actual input, so little backtracking would >>> be a much nicier approach. Any suggestions? >>> >>> -- >>> Regards, Paul Sujkov >>> >>> >> > -- Regards, Paul Sujkov -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090806/7475105a/attachment.html From explicitcall at googlemail.com Thu Aug 6 13:07:47 2009 From: explicitcall at googlemail.com (Max Desyatov) Date: Thu Aug 6 12:48:25 2009 Subject: [Haskell-cafe] Request for Changelogs In-Reply-To: <1249570172.10202.76.camel@localhost> (Joachim Breitner's message of "Thu, 06 Aug 2009 16:49:32 +0200") References: <1249568876.10202.65.camel@localhost> <404396ef0908060739m350040se604debc9b104690@mail.gmail.com> <1249570172.10202.76.camel@localhost> Message-ID: <871vnox44c.fsf@zagan.made.you> Did you see these tickets http://hackage.haskell.org/trac/hackage/ticket/299 http://hackage.haskell.org/trac/hackage/ticket/244 ? Probably the real proposal could be fixed in comments for that tickets, so anyone who wants to implement that feature would see all possible solutions in one place, without browsing through haskell-cafe archives. Joachim Breitner writes: > If the changelog had a properly specified format and location, cabal > upgrade could, if the user wants it, tell him all the downloaded > changes. This really helps him to keep up-to-date. It is also a good > channel for the authors to talk to his users (?see this nice module I > added to the package?, ?some parts of the API are deprecated now, please > move to this part?). Last but not least having documented changes is QA > measure that the Haskell platform in the wider sense deserves. > > Greetings, > Joachim From mail at joachim-breitner.de Thu Aug 6 13:29:29 2009 From: mail at joachim-breitner.de (Joachim Breitner) Date: Thu Aug 6 13:10:11 2009 Subject: [Haskell-cafe] Request for Changelogs In-Reply-To: <871vnox44c.fsf@zagan.made.you> References: <1249568876.10202.65.camel@localhost> <404396ef0908060739m350040se604debc9b104690@mail.gmail.com> <1249570172.10202.76.camel@localhost> <871vnox44c.fsf@zagan.made.you> Message-ID: <1249579769.32163.1.camel@localhost> Hi, Am Donnerstag, den 06.08.2009, 20:07 +0300 schrieb Max Desyatov: > Did you see these tickets > http://hackage.haskell.org/trac/hackage/ticket/299 > http://hackage.haskell.org/trac/hackage/ticket/244 ? > > Probably the real proposal could be fixed in comments for that tickets, > so anyone who wants to implement that feature would see all possible > solutions in one place, without browsing through haskell-cafe archives. no, given that I wrote a rant, I did not do research :-). These tickets describe what I want, and I?ll be watching them, and hope for progress :-) Thanks, Joachim -- Joachim "nomeata" Breitner mail: mail@joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C JID: nomeata@joachim-breitner.de | http://www.joachim-breitner.de/ Debian Developer: nomeata@debian.org -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: Dies ist ein digital signierter Nachrichtenteil Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090806/27d414b7/attachment.bin From jefferson.r.heard at gmail.com Thu Aug 6 14:15:57 2009 From: jefferson.r.heard at gmail.com (Jeff Heard) Date: Thu Aug 6 13:56:59 2009 Subject: [Haskell-cafe] Looking to check on some capabilities of Data.Colour Message-ID: <4165d3a70908061115v2ac7b5b8v7afe4e060977a92b@mail.gmail.com> I was wondering if Data.Colour supported Double-valued colour components > 1.0 or less than 0. I'm looking to create an HDR image processing library, and Haskell has one of the most extensive and correct colour models around, thanks to Russell. With 16bpcc or 32bpcc images, however, I need to be sure to be able to correctly calculate colour values that fall outside the usual [0.0,1.0] gamut. Does Data.Colour support this functionality? -- Jeff From roconnor at theorem.ca Thu Aug 6 15:46:03 2009 From: roconnor at theorem.ca (roconnor@theorem.ca) Date: Thu Aug 6 15:26:47 2009 Subject: [Haskell-cafe] Looking to check on some capabilities of Data.Colour In-Reply-To: <4165d3a70908061115v2ac7b5b8v7afe4e060977a92b@mail.gmail.com> References: <4165d3a70908061115v2ac7b5b8v7afe4e060977a92b@mail.gmail.com> Message-ID: On Thu, 6 Aug 2009, Jeff Heard wrote: > I was wondering if Data.Colour supported Double-valued colour > components > 1.0 or less than 0. I'm looking to create an HDR image > processing library, and Haskell has one of the most extensive and > correct colour models around, thanks to Russell. With 16bpcc or > 32bpcc images, however, I need to be sure to be able to correctly > calculate colour values that fall outside the usual [0.0,1.0] gamut. > Does Data.Colour support this functionality? Data.Colour supports values outside the range [0,1] for most computations. Components are clamped when extracting to Bounded component types such as Word8 (see toSRGBBounded). There may also some issues with negaive values when converting to non-linear coordinate systems via a transfer function. This is an area I haven't thought to much about, so there could be a few "bugs" lurking here. If found they should be fixed, assuming "right" behaviour can be found. > > -- Jeff > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Russell O'Connor ``All talk about `theft,''' the general counsel of the American Graphophone Company wrote, ``is the merest claptrap, for there exists no property in ideas musical, literary or artistic, except as defined by statute.'' From roconnor at theorem.ca Thu Aug 6 16:01:10 2009 From: roconnor at theorem.ca (roconnor@theorem.ca) Date: Thu Aug 6 15:41:55 2009 Subject: [Haskell-cafe] Looking to check on some capabilities of Data.Colour In-Reply-To: References: <4165d3a70908061115v2ac7b5b8v7afe4e060977a92b@mail.gmail.com> Message-ID: On Thu, 6 Aug 2009, roconnor@theorem.ca wrote: > On Thu, 6 Aug 2009, Jeff Heard wrote: > >> I was wondering if Data.Colour supported Double-valued colour >> components > 1.0 or less than 0. I'm looking to create an HDR image >> processing library, and Haskell has one of the most extensive and >> correct colour models around, thanks to Russell. With 16bpcc or >> 32bpcc images, however, I need to be sure to be able to correctly >> calculate colour values that fall outside the usual [0.0,1.0] gamut. >> Does Data.Colour support this functionality? > > Data.Colour supports values outside the range [0,1] for most computations. To be slightly more techinical, I want add that Data.Colour.Colour is abstract and its interface cares nothing about [0,1]. Gammut issue only arise when converting the abstract data type to and from concrete coordinates, and which colours are outside [0,1]*[0,1]*[0,1] is coorinate system dependent. Since Data.Colour.Colour is abstract and coordinate system indepenent, it cannot (or at least should not) care about such issues for oprations that deal only with abstract colours (operations such as blending, etc.) > Components are clamped when extracting to Bounded component types such as > Word8 (see toSRGBBounded). There may also some issues with negaive values > when converting to non-linear coordinate systems via a transfer function. > This is an area I haven't thought to much about, so there could be a few > "bugs" lurking here. If found they should be fixed, assuming "right" > behaviour can be found. > >> >> -- Jeff >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> > > -- Russell O'Connor ``All talk about `theft,''' the general counsel of the American Graphophone Company wrote, ``is the merest claptrap, for there exists no property in ideas musical, literary or artistic, except as defined by statute.'' From jefferson.r.heard at gmail.com Thu Aug 6 16:02:27 2009 From: jefferson.r.heard at gmail.com (Jeff Heard) Date: Thu Aug 6 15:43:29 2009 Subject: [Haskell-cafe] Looking to check on some capabilities of Data.Colour In-Reply-To: References: <4165d3a70908061115v2ac7b5b8v7afe4e060977a92b@mail.gmail.com> Message-ID: <4165d3a70908061302sb629a2cm12cf235dd609c6db@mail.gmail.com> Excellent. That's what I wanted to know :-) On Thu, Aug 6, 2009 at 4:01 PM, wrote: > On Thu, 6 Aug 2009, roconnor@theorem.ca wrote: > >> On Thu, 6 Aug 2009, Jeff Heard wrote: >> >>> I was wondering if Data.Colour supported Double-valued colour >>> components > 1.0 or less than 0. ?I'm looking to create an HDR image >>> processing library, and Haskell has one of the most extensive and >>> correct colour models around, thanks to Russell. ?With 16bpcc or >>> 32bpcc images, however, I need to be sure to be able to correctly >>> calculate colour values that fall outside the usual [0.0,1.0] gamut. >>> Does Data.Colour support this functionality? >> >> Data.Colour supports values outside the range [0,1] for most computations. > > To be slightly more techinical, I want add that Data.Colour.Colour is > abstract and its interface cares nothing about [0,1]. ?Gammut issue only > arise when converting the abstract data type to and from concrete > coordinates, and which colours are outside [0,1]*[0,1]*[0,1] is coorinate > system dependent. ?Since Data.Colour.Colour is abstract and coordinate > system indepenent, it cannot (or at least should not) care about such issues > for oprations that deal only with abstract colours (operations such as > blending, etc.) > >> Components are clamped when extracting to Bounded component types such as >> Word8 (see toSRGBBounded). ?There may also some issues with negaive values >> when converting to non-linear coordinate systems via a transfer function. >> This is an area I haven't thought to much about, so there could be a few >> "bugs" lurking here. ?If found they should be fixed, assuming "right" >> behaviour can be found. >> >>> >>> -- Jeff >>> _______________________________________________ >>> Haskell-Cafe mailing list >>> Haskell-Cafe@haskell.org >>> http://www.haskell.org/mailman/listinfo/haskell-cafe >>> >> >> > > -- > Russell O'Connor ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ``All talk about `theft,''' the general counsel of the American Graphophone > Company wrote, ``is the merest claptrap, for there exists no property in > ideas musical, literary or artistic, except as defined by statute.'' > From westondan at imageworks.com Thu Aug 6 15:03:25 2009 From: westondan at imageworks.com (Dan Weston) Date: Thu Aug 6 15:43:52 2009 Subject: [Haskell-cafe] Parsec: using two different parser for the same string In-Reply-To: <9760562b0908060859m5c49d9f0te659c5c75086753e@mail.gmail.com> References: <9760562b0908051042p97be03tb5f49a0905ef44d5@mail.gmail.com> <4A79FABD.3080000@imageworks.com> <4A7A16CE.4070209@imageworks.com> <9760562b0908060859m5c49d9f0te659c5c75086753e@mail.gmail.com> Message-ID: <4A7B28FD.9090603@imageworks.com> Paul, Arrows (and category theory in general) are interesting, but you certainly don't need to understand them for this. The only arrow in this code is the lowly function arrow (->). (&&&) and (|||) are duals of each other and mean, respectively, "both" and "either" (though for some bizarre reason, "both" is usually called "fanout"!) This style of pointfree (or "pointless") code is clearer to me because I don't have a bunch of variable names to invent and have lying around. Anyway, if you prefer, don't import Control.Arrow at all, and just use: -- |Both: Apply two functions to same argument and tuple the results infixr 3 &&& (&&&) :: (a -> b) -> (a -> c) -> a -> (b,c) (f &&& g) x = (f x, g x) -- |Either: If argument is Left, apply Left function, else apply Right function infixr 2 ||| (|||) :: (a -> c) -> (b -> c) -> Either a b -> c (|||) = either either is implicitly imported from the Prelude and is defined as: -- | Case analysis for the 'Either' type. -- If the value is @'Left' a@, apply the first function to @a@; -- if it is @'Right' b@, apply the second function to @b@. either :: (a -> c) -> (b -> c) -> Either a b -> c either f _ (Left x) = f x either _ g (Right y) = g y Dan Paul Sujkov wrote: > Hi Dan, > > thank you for the solution. It looks pretty interesting and usable, > however I'll have to spend some time understanding arrows: I never had > an opportunity to use them before. Anyway, it looks very close to what I > actually need, and in any case much less ugly than breaking the > GenParser encapsulation > > 2009/8/6 Dan Weston > > > Of course, since ParsecT s u m is a functor, feel free to use fmap > instead of parsecMap. Then you don't need to import from > Text.Parsec.Prim. > And in hindsight, I might prefer the name (<:>) or cons to (<>) for > the first function, but now I'm just obsessing. :) > > Dan > > > Dan Weston wrote: > > I think parsecMap does the job here: > > ----------------------- > import Text.ParserCombinators.Parsec hiding ((<|>)) > import Text.Parsec.Prim(parsecMap) > import Control.Applicative((<|>)) > import Control.Arrow((|||),(&&&)) > > -- Tagged (:) > (<>) :: Either Char Char -> Either String String -> Either > String String > Left a <> Left b = Left (a:b) > Left a <> Right b = Left (a:b) > Right a <> Left b = Left (a:b) > Right a <> Right b = Right (a:b) > > -- Tagged concat > stringParser :: [Either Char Char] -> Either String String > stringParser = foldr (<>) (Right "") > > -- Parse Integer if properly tagged, keeping unparsed string > maybeToInteger :: Either String String -> (Maybe Integer, String) > maybeToInteger = (const Nothing ||| Just . read) &&& (id ||| id) > > -- Tagged-choice parser > intOrStringParser = parsecMap (maybeToInteger . stringParser) > $ many1 (parsecMap Right digit <|> parsecMap Left (noneOf ";)")) > > -- Parse between parentheses > intOrStringListParser = between (char '(') > (char ')') > (sepBy1 intOrStringParser (char > ';')) > ----------------------- > > Then you get a tagged version of each string, along with the > string itself: > > *P> parseTest intOrStringListParser $ "(1;2w4;8;85)" > [(Just 1,"1"),(Nothing,"2w4"),(Just 8,"8"),(Just 85,"85")] > > There may be some parsecMap-fold fusion optimization possible, > though I haven't looked into that. > > Dan > > Paul Sujkov wrote: > > Hi everybody, > > suppose I have two different parsers: one just reads the > string, and another one parses some values from it. E.g.: > > parseIntList :: Parser [Integer] > parseIntList = do > char '(' > res <- liftM (map read) (sepBy1 (many1 digit) (char ';')) > char ')' > return res > > parseIntString :: Parser String > parseIntString = manyTill anyChar eof > > so for some input like this - "(1;2;3;4)" - I will have two > different result: > > *Parlog> parseTest parseIntList "(1;2;3;4)" > [1,2,3,4] > *Parlog> parseTest parseIntString "(1;2;3;4)" > "(1;2;3;4)" > > but the thing that I actually want is something like Parser > ([Integer], String) - results from both parsers at a time, > no matter whether one of them fails or not: > > *Parlog> parseTest parseIntListAndString "(1;2;3;4)" > ([1,2,3,4], "(1;2;3;4)") > > it is impossible at first sight, because first parser to use > will consume all the input, and there will be nothing to > parse for the second one > > Parsec contains "choice" function, but it is implemented via > <|> and that is mplus - so it tries second alternative only > if the first one fails. Is it possible to use two parsers > for the same string (with try-like backtracking, no input > actually consumed till the second parser finishes)? I can > assume only dirty hacks with the GenParser internals - > manual position storing and backtracking - but that is > obviously not good > > however, my first attempt to solve the problem was kind a > like that: to parse string to String, and then to use it as > an input for the next level parse call: > > parseIntListAndString :: Parser ([Integer], String) > parseIntListAndString = do > str <- parseIntString > return (res str, str) > where res str = case (parse parseIntList "" str) of > Left err -> [] > Right val -> val > > but the problems with such a method began when I switched > from Parser to GenParser with user state: function > parseIntList have to update the state, but it can't have the > same state as the parseIntListAndString any more: it has > it's own. I can explicitly pass the state from > parseIntListAndString to parseIntList, but I see no suitable > way for the parseIntList to update it. I can return the > updated state value from the parseIntList function, and call > setState on a result - but it seems rather ugly to mee. > However, if nothing else will do, that is an alternative > > it is of course possible to use two different parsers > sequentially, but it is also very ineffective: I need to use > such multiple parsing on a relatively small substring of the > actual input, so little backtracking would be a much nicier > approach. Any suggestions? > > -- > Regards, Paul Sujkov > > > > > > > -- > Regards, Paul Sujkov From lemming at henning-thielemann.de Thu Aug 6 16:39:36 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Thu Aug 6 16:20:56 2009 Subject: [Haskell-cafe] Hugs faster and more reliable than GHC for large list monad 'do' block Message-ID: Today a student has shown me a program that consists of a large 'do' block for the list monad. The program looks like do x1 <- [0..3] x2 <- [0..2] ... x600 <- [0..5] guard (x1+x2+2*x3 >= 0) ... return (x1,x2,....,x600) It was actually generated by another program. The results were: GHC-6.4 was not able to compile that program at all, because it stopped because of memory exhaustion. GHC-6.8.2 finished compilation after two minutes but the program aborted quickly because of a corrupt thunk identifier. GHC-6.10 not yet tested. Hugs-2006 executed the program without complaining and showed the first result after a few seconds: (0,0,0,0,0,...,0). Eventually the program must run on a Linux cluster with a not up-to-date Linux kernel, that is, I suspect newer GHC versions cannot be used due to the 'timer_create' problem. (At least, the 'cabal' executable that I generated with a GHC-6.8.2 had this problem when running on the cluster which reminded me on the problems with GHC-6.8 itself running on older Linux kernels.) Since the list monad sorts the variable values in lexicographic order which is inappropriate for the considered problem, I recommended the use of control-monad-omega. Luke, I hope this monad can cope with 600 variables. :-) From dagit at codersbase.com Thu Aug 6 16:51:17 2009 From: dagit at codersbase.com (Jason Dagit) Date: Thu Aug 6 16:32:01 2009 Subject: [Haskell-cafe] Hugs faster and more reliable than GHC for large list monad 'do' block In-Reply-To: References: Message-ID: On Thu, Aug 6, 2009 at 1:39 PM, Henning Thielemann < lemming@henning-thielemann.de> wrote: > > Today a student has shown me a program that consists of a large 'do' block > for the list monad. The program looks like > > do x1 <- [0..3] > x2 <- [0..2] > ... > x600 <- [0..5] > guard (x1+x2+2*x3 >= 0) > ... > return (x1,x2,....,x600) > > It was actually generated by another program. The results were: > > GHC-6.4 was not able to compile that program at all, because it stopped > because of memory exhaustion. Did you try playing with optimization options? I think someone just mentioned that compiling large amounts of static data in GHC is problematic and recommended something like -O0 to prevent GHC from analyzing it. Of course, I wouldn't recommend having unoptimized code, but I'm curious how that changes the results here. > > GHC-6.8.2 finished compilation after two minutes but the program aborted > quickly because of a corrupt thunk identifier. Oh that's icky. > > GHC-6.10 not yet tested. > Hugs-2006 executed the program without complaining and showed the first > result after a few seconds: (0,0,0,0,0,...,0). > > Eventually the program must run on a Linux cluster with a not up-to-date > Linux kernel, that is, I suspect newer GHC versions cannot be used due to > the 'timer_create' problem. (At least, the 'cabal' executable that I > generated with a GHC-6.8.2 had this problem when running on the cluster > which reminded me on the problems with GHC-6.8 itself running on older Linux > kernels.) I just googled this and found this: http://www.haskell.org/pipermail/glasgow-haskell-users/2008-March/014498.html That was linked from this discussion: http://www.nabble.com/ghc-6.8.2-and-timer_create-error-td16160635.html The second link seems to indicate that it's not a problem of antiquity but instead one related to what configure finds when building GHC for that system. In other words, it should be possible to make a version of GHC locally that doesn't use timer_create and then your student should be good to go. Hope that helps, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090806/78f33441/attachment-0001.html From westondan at imageworks.com Thu Aug 6 16:59:45 2009 From: westondan at imageworks.com (Dan Weston) Date: Thu Aug 6 16:40:31 2009 Subject: [Haskell-cafe] Hugs faster and more reliable than GHC for large list monad 'do' block In-Reply-To: References: Message-ID: <4A7B4441.4040100@imageworks.com> I assume for the return line, you meant to return a list, not a tuple. ghc doesn't support a 600-tuple. In any case, returning a list, I have verified that this problem exists in ghc 6.10.3, for -O0 and -O2. For -O0, it compiles and links fine, but gives this runtime message: z: internal error: scavenge: unimplemented/strange closure type -1 @ 0x2a95a8e000 (GHC version 6.10.3 for x86_64_unknown_linux) Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug Abort Maybe it is attempting to unroll these loops, even with -O0? Dan Henning Thielemann wrote: > Today a student has shown me a program that consists of a large 'do' > block for the list monad. The program looks like > > do x1 <- [0..3] > x2 <- [0..2] > ... > x600 <- [0..5] > guard (x1+x2+2*x3 >= 0) > ... > return (x1,x2,....,x600) > > It was actually generated by another program. The results were: > > GHC-6.4 was not able to compile that program at all, because it stopped > because of memory exhaustion. > GHC-6.8.2 finished compilation after two minutes but the program aborted > quickly because of a corrupt thunk identifier. > GHC-6.10 not yet tested. > Hugs-2006 executed the program without complaining and showed the first > result after a few seconds: (0,0,0,0,0,...,0). > > Eventually the program must run on a Linux cluster with a not up-to-date > Linux kernel, that is, I suspect newer GHC versions cannot be used due to > the 'timer_create' problem. (At least, the 'cabal' executable that I > generated with a GHC-6.8.2 had this problem when running on the cluster > which reminded me on the problems with GHC-6.8 itself running on older > Linux kernels.) > > Since the list monad sorts the variable values in lexicographic order > which is inappropriate for the considered problem, I recommended the use > of control-monad-omega. Luke, I hope this monad can cope with 600 > variables. :-) > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > From ndmitchell at gmail.com Thu Aug 6 17:26:08 2009 From: ndmitchell at gmail.com (Neil Mitchell) Date: Thu Aug 6 17:06:51 2009 Subject: [Haskell-cafe] Hugs faster and more reliable than GHC for large list monad 'do' block In-Reply-To: <4A7B4441.4040100@imageworks.com> References: <4A7B4441.4040100@imageworks.com> Message-ID: <404396ef0908061426o4a0e2929kfa8bcd9f58313902@mail.gmail.com> Hi I think the issue you're running in to with 6.4 is this one: http://hackage.haskell.org/trac/ghc/ticket/830 - known and fixed a while back. Thanks Neil On Thu, Aug 6, 2009 at 9:59 PM, Dan Weston wrote: > I assume for the return line, you meant to return a list, not a tuple. ghc > doesn't support a 600-tuple. > In any case, returning a list, I have verified that this problem exists in > ghc 6.10.3, for -O0 and -O2. > > For -O0, it compiles and links fine, but gives this runtime message: > > z: internal error: scavenge: unimplemented/strange closure type -1 @ > 0x2a95a8e000 > ? ?(GHC version 6.10.3 for x86_64_unknown_linux) > ? ?Please report this as a GHC bug: ?http://www.haskell.org/ghc/reportabug > Abort > > Maybe it is attempting to unroll these loops, even with -O0? > > Dan > > Henning Thielemann wrote: >> >> Today a student has shown me a program that consists of a large 'do' block >> for the list monad. The program looks like >> >> ? ?do x1 <- [0..3] >> ? ? ? x2 <- [0..2] >> ? ? ? ... >> ? ? ? x600 <- [0..5] >> ? ? ? guard (x1+x2+2*x3 >= 0) >> ? ? ? ... >> ? ? ? return (x1,x2,....,x600) >> >> It was actually generated by another program. The results were: >> >> ?GHC-6.4 was not able to compile that program at all, because it stopped >> because of memory exhaustion. >> ?GHC-6.8.2 finished compilation after two minutes but the program aborted >> quickly because of a corrupt thunk identifier. >> ?GHC-6.10 not yet tested. >> ?Hugs-2006 executed the program without complaining and showed the first >> result after a few seconds: (0,0,0,0,0,...,0). >> >> Eventually the program must run on a Linux cluster with a not up-to-date >> Linux kernel, that is, I suspect newer GHC versions cannot be used due to >> the 'timer_create' problem. (At least, the 'cabal' executable that I >> generated with a GHC-6.8.2 had this problem when running on the cluster >> which reminded me on the problems with GHC-6.8 itself running on older Linux >> kernels.) >> >> Since the list monad sorts the variable values in lexicographic order >> which is inappropriate for the considered problem, I recommended the use of >> control-monad-omega. Luke, I hope this monad can cope with 600 variables. >> :-) >> _______________________________________________ >> 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 lemming at henning-thielemann.de Thu Aug 6 17:58:46 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Thu Aug 6 17:40:29 2009 Subject: [Haskell-cafe] Hugs faster and more reliable than GHC for large list monad 'do' block In-Reply-To: <4A7B4441.4040100@imageworks.com> References: <4A7B4441.4040100@imageworks.com> Message-ID: On Thu, 6 Aug 2009, Dan Weston wrote: > I assume for the return line, you meant to return a list, not a tuple. ghc > doesn't support a 600-tuple. Maybe that it was a list. > In any case, returning a list, I have verified that this problem exists in > ghc 6.10.3, for -O0 and -O2. > > For -O0, it compiles and links fine, but gives this runtime message: > > z: internal error: scavenge: unimplemented/strange closure type -1 @ > 0x2a95a8e000 > (GHC version 6.10.3 for x86_64_unknown_linux) > Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug > Abort Indeed, this is also what we got from the executable built by GHC-6.8.2. From lemming at henning-thielemann.de Thu Aug 6 17:59:54 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Thu Aug 6 17:41:24 2009 Subject: [Haskell-cafe] Hugs faster and more reliable than GHC for large list monad 'do' block In-Reply-To: References: Message-ID: On Thu, 6 Aug 2009, Jason Dagit wrote: > 'timer_create' problem. (At least, the 'cabal' executable that I generated with a > GHC-6.8.2 had this problem when running on the cluster which reminded me on the > problems with GHC-6.8 itself running on older Linux kernels.) > > > I just googled this and found this: > http://www.haskell.org/pipermail/glasgow-haskell-users/2008-March/014498.html > That was linked from this discussion: > http://www.nabble.com/ghc-6.8.2-and-timer_create-error-td16160635.html > > The second link seems to indicate that it's not a problem of antiquity but instead one > related to what configure finds when building GHC for that system.? In other words, it should > be possible to make a version of GHC locally that doesn't use timer_create and then your > student should be good to go. Thanks for the pointer. But it means building GHC myself, which I have no experience with. :-( From lambda-belka at yandex.ru Thu Aug 6 19:13:06 2009 From: lambda-belka at yandex.ru (Belka) Date: Thu Aug 6 18:53:48 2009 Subject: [Haskell-cafe] Seeking for an extention (functional incapsulation) Message-ID: <24856249.post@talk.nabble.com> Hello, cafe visitors! :) This is a double topic: 1. Can't find any good informative resource with descriptions of Haskell extensions. Could anybody please share good one if it exists? The only "good" one I found: http://hackage.haskell.org/trac/haskell-prime/wiki/HaskellExtensions But it's a bit too old and not that full... I undestand, that Haskell is kind of "boiling" language, in a sense of being neverending experiment. It develops all the time, extensions show up and drop out. So it's not that easy to support community with a fresh information about them. But on the other side, the property (of being "boiling" language) makes such information really important for community members... I think. :) 2. Consider situation: ----------------------------------- data SomeDataType = SomeDataType { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type} sdtField3 :: SomeDataType -> SDT_Field3Type sdtField3 sdt = f (sdtField1 sdt) (sdtField2 sdt) ----------------------------------- I induced recently, that it would be very comfortable if I could perform in a way like this: ----------------------------------- data SomeDataType = SomeDataType { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type, sdtField3 :: SDT_Field2Type, sdtField3 = f sdtField1 sdtField2} ----------------------------------- The situation is not that rare, when dealing with nonprimitive data constructions. Moreover would be really comfortable to reduce ----------------------------------- data SomeDataType = SomeDataType_111 { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type} | SomeDataType_222 { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type, sdtField5 :: SDT_Field5Type} sdtField3 :: SomeDataType -> SDT_Field3Type sdtField3 sdt = case sdt of {SomeDataType_111 -> f (sdtField1 sdt) (sdtField2 sdt) ; SomeDataType_222 -> g (sdtField1 sdt) (sdtField2 sdt) (sdtField5 sdt)} \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ data SomeDataType = SomeDataType_111 { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type, sdtField3 :: SDT_Field3Type, sdtField3 = f sdtField1 sdtField2} | SomeDataType_222 { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type, sdtField5 :: SDT_Field5Type, sdtField3 :: SDT_Field3Type, sdtField3 = g sdtField1 sdtField2 sdtField5} ----------------------------------- Usable mechanics for realization would be: 1. Funtion similar to Data.Function.on (example: (*) `on` f = \x y -> f x * f y), but opposite - I called it under. t `under` f = \x y -> (x f) `t` (y f) 2. currying and uncurrying Is there any such extension? Belka -- View this message in context: http://www.nabble.com/Seeking-for-an-extention-%28functional-incapsulation%29-tp24856249p24856249.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From westondan at imageworks.com Thu Aug 6 19:25:07 2009 From: westondan at imageworks.com (Dan Weston) Date: Thu Aug 6 19:05:56 2009 Subject: [Haskell-cafe] Hugs faster and more reliable than GHC for large list monad 'do' block In-Reply-To: <404396ef0908061426o4a0e2929kfa8bcd9f58313902@mail.gmail.com> References: <4A7B4441.4040100@imageworks.com> <404396ef0908061426o4a0e2929kfa8bcd9f58313902@mail.gmail.com> Message-ID: <4A7B6653.7090104@imageworks.com> No, I am using the latest released ghc: > ghc --version The Glorious Glasgow Haskell Compilation System, version 6.10.4 [ z.hs is attached ] > time ghc -O0 --make z.hs [1 of 1] Compiling Main ( z.hs, z.o ) Linking z ... 14.422u 0.630s 0:15.10 99.6% 0+0k 0+0io 0pf+0w > time ./z z: internal error: scavenge: unimplemented/strange closure type -1 @ 0x2a95a8e000 (GHC version 6.10.4 for x86_64_unknown_linux) Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug Abort 0.007u 0.007s 0:00.02 0.0% 0+0k 0+0io 0pf+0w Dan Neil Mitchell wrote: > Hi > > I think the issue you're running in to with 6.4 is this one: > http://hackage.haskell.org/trac/ghc/ticket/830 - known and fixed a > while back. > > Thanks > > Neil > > On Thu, Aug 6, 2009 at 9:59 PM, Dan Weston wrote: >> I assume for the return line, you meant to return a list, not a tuple. ghc >> doesn't support a 600-tuple. >> In any case, returning a list, I have verified that this problem exists in >> ghc 6.10.3, for -O0 and -O2. >> >> For -O0, it compiles and links fine, but gives this runtime message: >> >> z: internal error: scavenge: unimplemented/strange closure type -1 @ >> 0x2a95a8e000 >> (GHC version 6.10.3 for x86_64_unknown_linux) >> Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug >> Abort >> >> Maybe it is attempting to unroll these loops, even with -O0? >> >> Dan >> >> Henning Thielemann wrote: >>> Today a student has shown me a program that consists of a large 'do' block >>> for the list monad. The program looks like >>> >>> do x1 <- [0..3] >>> x2 <- [0..2] >>> ... >>> x600 <- [0..5] >>> guard (x1+x2+2*x3 >= 0) >>> ... >>> return (x1,x2,....,x600) >>> >>> It was actually generated by another program. The results were: >>> >>> GHC-6.4 was not able to compile that program at all, because it stopped >>> because of memory exhaustion. >>> GHC-6.8.2 finished compilation after two minutes but the program aborted >>> quickly because of a corrupt thunk identifier. >>> GHC-6.10 not yet tested. >>> Hugs-2006 executed the program without complaining and showed the first >>> result after a few seconds: (0,0,0,0,0,...,0). >>> >>> Eventually the program must run on a Linux cluster with a not up-to-date >>> Linux kernel, that is, I suspect newer GHC versions cannot be used due to >>> the 'timer_create' problem. (At least, the 'cabal' executable that I >>> generated with a GHC-6.8.2 had this problem when running on the cluster >>> which reminded me on the problems with GHC-6.8 itself running on older Linux >>> kernels.) >>> >>> Since the list monad sorts the variable values in lexicographic order >>> which is inappropriate for the considered problem, I recommended the use of >>> control-monad-omega. Luke, I hope this monad can cope with 600 variables. >>> :-) >>> _______________________________________________ >>> 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 >> > > -------------- next part -------------- A non-text attachment was scrubbed... Name: z.hs Type: text/x-haskell Size: 19108 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090806/ce9fe8bc/z.bin From jefferson.r.heard at gmail.com Thu Aug 6 19:34:03 2009 From: jefferson.r.heard at gmail.com (Jeff Heard) Date: Thu Aug 6 19:15:04 2009 Subject: [Haskell-cafe] Hugs faster and more reliable than GHC for large list monad 'do' block In-Reply-To: References: Message-ID: <4165d3a70908061634n52f50ffdsdcefba229d4f66af@mail.gmail.com> Yes, the GHC compiler will work on older kernels and CentOS kernels if you bootstrap it with 6.4 On Thu, Aug 6, 2009 at 4:51 PM, Jason Dagit wrote: > > > On Thu, Aug 6, 2009 at 1:39 PM, Henning Thielemann > wrote: >> >> Today a student has shown me a program that consists of a large 'do' block >> for the list monad. The program looks like >> >> ? do x1 <- [0..3] >> ? ? ?x2 <- [0..2] >> ? ? ?... >> ? ? ?x600 <- [0..5] >> ? ? ?guard (x1+x2+2*x3 >= 0) >> ? ? ?... >> ? ? ?return (x1,x2,....,x600) >> >> It was actually generated by another program. The results were: >> >> ?GHC-6.4 was not able to compile that program at all, because it stopped >> because of memory exhaustion. > > Did you try playing with optimization options?? I think someone just > mentioned that compiling large amounts of static data in GHC is problematic > and recommended something like -O0 to prevent GHC from analyzing it.? Of > course, I wouldn't recommend having unoptimized code, but I'm curious how > that changes the results here. > > >> >> ?GHC-6.8.2 finished compilation after two minutes but the program aborted >> quickly because of a corrupt thunk identifier. > > Oh that's icky. > >> >> ?GHC-6.10 not yet tested. >> ?Hugs-2006 executed the program without complaining and showed the first >> result after a few seconds: (0,0,0,0,0,...,0). >> >> Eventually the program must run on a Linux cluster with a not up-to-date >> Linux kernel, that is, I suspect newer GHC versions cannot be used due to >> the 'timer_create' problem. (At least, the 'cabal' executable that I >> generated with a GHC-6.8.2 had this problem when running on the cluster >> which reminded me on the problems with GHC-6.8 itself running on older Linux >> kernels.) > > I just googled this and found this: > http://www.haskell.org/pipermail/glasgow-haskell-users/2008-March/014498.html > That was linked from this discussion: > http://www.nabble.com/ghc-6.8.2-and-timer_create-error-td16160635.html > > The second link seems to indicate that it's not a problem of antiquity but > instead one related to what configure finds when building GHC for that > system.? In other words, it should be possible to make a version of GHC > locally that doesn't use timer_create and then your student should be good > to go. > > Hope that helps, > Jason > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > From westondan at imageworks.com Thu Aug 6 19:37:29 2009 From: westondan at imageworks.com (Dan Weston) Date: Thu Aug 6 19:18:15 2009 Subject: [Haskell-cafe] Hugs faster and more reliable than GHC for large list monad 'do' block In-Reply-To: <4A7B6653.7090104@imageworks.com> References: <4A7B4441.4040100@imageworks.com> <404396ef0908061426o4a0e2929kfa8bcd9f58313902@mail.gmail.com> <4A7B6653.7090104@imageworks.com> Message-ID: <4A7B6939.8040705@imageworks.com> I should clarify that this was done on an older kernel (bootstrapped from ghc 6.4 as Jeff Heard suggested), in case that makes any difference: Main memory size: 7971 Mbytes 1 GenuineIntel Intel(R) Xeon(TM) CPU 3.40GHz processor Swap Size: 2047 Mbytes Num Processors: 1 Processor Type: Intel(R) Xeon(TM) CPU 3.40GHz x64 Clock Speed: 3400 MHZ OS: Linux 2.6.9-42.0.3.EL.spi OS-VERSION: CentOS release 4.4 (Final) OS-HW: x86_64 Dan Weston wrote: > No, I am using the latest released ghc: > > > ghc --version > The Glorious Glasgow Haskell Compilation System, version 6.10.4 > > [ z.hs is attached ] > > > time ghc -O0 --make z.hs > [1 of 1] Compiling Main ( z.hs, z.o ) > Linking z ... > 14.422u 0.630s 0:15.10 99.6% 0+0k 0+0io 0pf+0w > > > time ./z > z: internal error: scavenge: unimplemented/strange closure type -1 @ > 0x2a95a8e000 > (GHC version 6.10.4 for x86_64_unknown_linux) > Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug > Abort > 0.007u 0.007s 0:00.02 0.0% 0+0k 0+0io 0pf+0w > > Dan > > Neil Mitchell wrote: >> Hi >> >> I think the issue you're running in to with 6.4 is this one: >> http://hackage.haskell.org/trac/ghc/ticket/830 - known and fixed a >> while back. >> >> Thanks >> >> Neil >> >> On Thu, Aug 6, 2009 at 9:59 PM, Dan Weston wrote: >>> I assume for the return line, you meant to return a list, not a tuple. ghc >>> doesn't support a 600-tuple. >>> In any case, returning a list, I have verified that this problem exists in >>> ghc 6.10.3, for -O0 and -O2. >>> >>> For -O0, it compiles and links fine, but gives this runtime message: >>> >>> z: internal error: scavenge: unimplemented/strange closure type -1 @ >>> 0x2a95a8e000 >>> (GHC version 6.10.3 for x86_64_unknown_linux) >>> Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug >>> Abort >>> >>> Maybe it is attempting to unroll these loops, even with -O0? >>> >>> Dan >>> >>> Henning Thielemann wrote: >>>> Today a student has shown me a program that consists of a large 'do' block >>>> for the list monad. The program looks like >>>> >>>> do x1 <- [0..3] >>>> x2 <- [0..2] >>>> ... >>>> x600 <- [0..5] >>>> guard (x1+x2+2*x3 >= 0) >>>> ... >>>> return (x1,x2,....,x600) >>>> >>>> It was actually generated by another program. The results were: >>>> >>>> GHC-6.4 was not able to compile that program at all, because it stopped >>>> because of memory exhaustion. >>>> GHC-6.8.2 finished compilation after two minutes but the program aborted >>>> quickly because of a corrupt thunk identifier. >>>> GHC-6.10 not yet tested. >>>> Hugs-2006 executed the program without complaining and showed the first >>>> result after a few seconds: (0,0,0,0,0,...,0). >>>> >>>> Eventually the program must run on a Linux cluster with a not up-to-date >>>> Linux kernel, that is, I suspect newer GHC versions cannot be used due to >>>> the 'timer_create' problem. (At least, the 'cabal' executable that I >>>> generated with a GHC-6.8.2 had this problem when running on the cluster >>>> which reminded me on the problems with GHC-6.8 itself running on older Linux >>>> kernels.) >>>> >>>> Since the list monad sorts the variable values in lexicographic order >>>> which is inappropriate for the considered problem, I recommended the use of >>>> control-monad-omega. Luke, I hope this monad can cope with 600 variables. >>>> :-) >>>> _______________________________________________ >>>> 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 westondan at imageworks.com Thu Aug 6 19:37:48 2009 From: westondan at imageworks.com (Dan Weston) Date: Thu Aug 6 19:18:35 2009 Subject: [Haskell-cafe] Seeking for an extention (functional incapsulation) In-Reply-To: <24856249.post@talk.nabble.com> References: <24856249.post@talk.nabble.com> Message-ID: <4A7B694C.40803@imageworks.com> Is there any good extension? Yes, it's in Control.Applicative. Belka wrote: > Hello, cafe visitors! :) > > This is a double topic: > 1. Can't find any good informative resource with descriptions of Haskell > extensions. Could anybody please share good one if it exists? > The only "good" one I found: > http://hackage.haskell.org/trac/haskell-prime/wiki/HaskellExtensions > But it's a bit too old and not that full... > I undestand, that Haskell is kind of "boiling" language, in a sense of being > neverending experiment. It develops all the time, extensions show up and > drop out. So it's not that easy to support community with a fresh > information about them. But on the other side, the property (of being > "boiling" language) makes such information really important for community > members... I think. :) > > 2. Consider situation: > ----------------------------------- > data SomeDataType = SomeDataType { sdtField1 :: SDT_Field1Type, sdtField2 :: > SDT_Field2Type} > sdtField3 :: SomeDataType -> SDT_Field3Type > sdtField3 sdt = f (sdtField1 sdt) (sdtField2 sdt) > ----------------------------------- > I induced recently, that it would be very comfortable if I could perform in > a way like this: > ----------------------------------- > data SomeDataType = SomeDataType { sdtField1 :: SDT_Field1Type, sdtField2 :: > SDT_Field2Type, sdtField3 :: SDT_Field2Type, sdtField3 = f sdtField1 > sdtField2} > ----------------------------------- > The situation is not that rare, when dealing with nonprimitive data > constructions. Moreover would be really comfortable to reduce > ----------------------------------- > data SomeDataType = SomeDataType_111 { sdtField1 :: SDT_Field1Type, > sdtField2 :: SDT_Field2Type} | SomeDataType_222 { sdtField1 :: > SDT_Field1Type, sdtField2 :: SDT_Field2Type, sdtField5 :: SDT_Field5Type} > > sdtField3 :: SomeDataType -> SDT_Field3Type > sdtField3 sdt = case sdt of {SomeDataType_111 -> f (sdtField1 sdt) > (sdtField2 sdt) ; SomeDataType_222 -> g (sdtField1 sdt) (sdtField2 sdt) > (sdtField5 sdt)} > > \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ > > data SomeDataType = SomeDataType_111 { sdtField1 :: SDT_Field1Type, > sdtField2 :: SDT_Field2Type, sdtField3 :: SDT_Field3Type, sdtField3 = f > sdtField1 sdtField2} | SomeDataType_222 { sdtField1 :: SDT_Field1Type, > sdtField2 :: SDT_Field2Type, sdtField5 :: SDT_Field5Type, sdtField3 :: > SDT_Field3Type, sdtField3 = g sdtField1 sdtField2 sdtField5} > ----------------------------------- > > Usable mechanics for realization would be: > 1. Funtion similar to Data.Function.on (example: (*) `on` f = \x y -> f x * > f y), but opposite - I called it under. > t `under` f = \x y -> (x f) `t` (y f) > 2. currying and uncurrying > > Is there any such extension? > > Belka From westondan at imageworks.com Thu Aug 6 19:39:12 2009 From: westondan at imageworks.com (Dan Weston) Date: Thu Aug 6 19:20:01 2009 Subject: [Haskell-cafe] Seeking for an extention (functional incapsulation) In-Reply-To: <4A7B694C.40803@imageworks.com> References: <24856249.post@talk.nabble.com> <4A7B694C.40803@imageworks.com> Message-ID: <4A7B69A0.3050606@imageworks.com> More specifically: sdtField3 sdt = f <$> sdtField1 <*> sdtField2 You don't really need this inline in the record syntax, do you? Dan Weston wrote: > Is there any good extension? Yes, it's in Control.Applicative. > > > > Belka wrote: >> Hello, cafe visitors! :) >> >> This is a double topic: >> 1. Can't find any good informative resource with descriptions of Haskell >> extensions. Could anybody please share good one if it exists? >> The only "good" one I found: >> http://hackage.haskell.org/trac/haskell-prime/wiki/HaskellExtensions >> But it's a bit too old and not that full... >> I undestand, that Haskell is kind of "boiling" language, in a sense of being >> neverending experiment. It develops all the time, extensions show up and >> drop out. So it's not that easy to support community with a fresh >> information about them. But on the other side, the property (of being >> "boiling" language) makes such information really important for community >> members... I think. :) >> >> 2. Consider situation: >> ----------------------------------- >> data SomeDataType = SomeDataType { sdtField1 :: SDT_Field1Type, sdtField2 :: >> SDT_Field2Type} >> sdtField3 :: SomeDataType -> SDT_Field3Type >> sdtField3 sdt = f (sdtField1 sdt) (sdtField2 sdt) >> ----------------------------------- >> I induced recently, that it would be very comfortable if I could perform in >> a way like this: >> ----------------------------------- >> data SomeDataType = SomeDataType { sdtField1 :: SDT_Field1Type, sdtField2 :: >> SDT_Field2Type, sdtField3 :: SDT_Field2Type, sdtField3 = f sdtField1 >> sdtField2} >> ----------------------------------- >> The situation is not that rare, when dealing with nonprimitive data >> constructions. Moreover would be really comfortable to reduce >> ----------------------------------- >> data SomeDataType = SomeDataType_111 { sdtField1 :: SDT_Field1Type, >> sdtField2 :: SDT_Field2Type} | SomeDataType_222 { sdtField1 :: >> SDT_Field1Type, sdtField2 :: SDT_Field2Type, sdtField5 :: SDT_Field5Type} >> >> sdtField3 :: SomeDataType -> SDT_Field3Type >> sdtField3 sdt = case sdt of {SomeDataType_111 -> f (sdtField1 sdt) >> (sdtField2 sdt) ; SomeDataType_222 -> g (sdtField1 sdt) (sdtField2 sdt) >> (sdtField5 sdt)} >> >> \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ >> >> data SomeDataType = SomeDataType_111 { sdtField1 :: SDT_Field1Type, >> sdtField2 :: SDT_Field2Type, sdtField3 :: SDT_Field3Type, sdtField3 = f >> sdtField1 sdtField2} | SomeDataType_222 { sdtField1 :: SDT_Field1Type, >> sdtField2 :: SDT_Field2Type, sdtField5 :: SDT_Field5Type, sdtField3 :: >> SDT_Field3Type, sdtField3 = g sdtField1 sdtField2 sdtField5} >> ----------------------------------- >> >> Usable mechanics for realization would be: >> 1. Funtion similar to Data.Function.on (example: (*) `on` f = \x y -> f x * >> f y), but opposite - I called it under. >> t `under` f = \x y -> (x f) `t` (y f) >> 2. currying and uncurrying >> >> Is there any such extension? >> >> Belka > From lambda-belka at yandex.ru Thu Aug 6 20:39:40 2009 From: lambda-belka at yandex.ru (Belka) Date: Thu Aug 6 20:20:21 2009 Subject: [Haskell-cafe] Seeking for an extention (functional incapsulation) In-Reply-To: <4A7B69A0.3050606@imageworks.com> References: <24856249.post@talk.nabble.com> <4A7B694C.40803@imageworks.com> <4A7B69A0.3050606@imageworks.com> Message-ID: <24856983.post@talk.nabble.com> Thank you, for your reply, Dan! :) > You don't really need this inline in the record syntax, do you? In fact, that was the point. To enclose direct functional dependants into the record declaration. To achieve better pithiness - it's valuable, and the value grows exponentially with LOC (lines of code) count. :) > sdtField3 sdt = f <$> sdtField1 <*> sdtField2 Doesn't look much better than my "under" function (t `under` f = \x y -> (x f) `t` (y f)). What did I miss? I believe, there are good reasons to use Control.Applicative for lots purposes, but unfortunately, yet haven't had time to try it in my practice. Belka -- View this message in context: http://www.nabble.com/Seeking-for-an-extention-%28functional-incapsulation%29-tp24856249p24856983.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From westondan at imageworks.com Thu Aug 6 20:55:21 2009 From: westondan at imageworks.com (Dan Weston) Date: Thu Aug 6 20:36:07 2009 Subject: [Haskell-cafe] Seeking for an extention (functional incapsulation) In-Reply-To: <24856983.post@talk.nabble.com> References: <24856249.post@talk.nabble.com> <4A7B694C.40803@imageworks.com> <4A7B69A0.3050606@imageworks.com> <24856983.post@talk.nabble.com> Message-ID: <4A7B7B79.3090403@imageworks.com> > the value grows exponentially with LOC (lines of code) count. :) Exponentially? Now I'm missing something... Your way has 156 chars: data SomeDataType = SomeDataType { sdtField1 :: SDT_Field1Type, sdtField2 :: > SDT_Field2Type, sdtField3 :: SDT_Field2Type, sdtField3 = f sdtField1 > sdtField2} This way has 162 chars: data SomeDataType = SomeDataType { sdtField1 :: SDT_Field1Type, sdtField2 :: SDT_Field2Type} sdtField3 :: SDT_Field2Type sdtField3 = f <$> sdtField1 <*> sdtField2 This adds 6 characters per dependent deconstructor function. As a fraction of total LOC, this is insignificant. Belka wrote: > Thank you, for your reply, Dan! :) > >> You don't really need this inline in the record syntax, do you? > In fact, that was the point. To enclose direct functional dependants into > the record declaration. To achieve better pithiness - it's valuable, and the > value grows exponentially with LOC (lines of code) count. :) > >> sdtField3 sdt = f <$> sdtField1 <*> sdtField2 > Doesn't look much better than my "under" function (t `under` f = \x y -> (x > f) `t` (y f)). What did I miss? > I believe, there are good reasons to use Control.Applicative for lots > purposes, but unfortunately, yet haven't had time to try it in my practice. > > Belka From phil at beadling.co.uk Thu Aug 6 21:38:29 2009 From: phil at beadling.co.uk (phil@beadling.co.uk) Date: Thu Aug 6 21:19:14 2009 Subject: [Haskell-cafe] Linking failing due to Control.Monad.State.Strict? Message-ID: <6D413D9B-0476-42B3-9FC8-7C9F8C26647E@beadling.co.uk> Hi, I'm getting a linker error when generating makefile dependencies on the below library for a program I'm using. It links fine under 'ghc -- make'. I'm using (more or less) the makefile from the haskell docs. I am using the Strict State Monad in the object files it is complaining about, the compile is fine, just the linker which is blowing up. Any ideas what is causing this? I'm using GHC 6.10.4 on PPC Mac OS X 10.5. I've included the makefile below the error. Cheers! Phil. ghc -o OptionCalculator -O2 -Wall ./FrameworkInterface.o ./Maths/ Prime.o ./Misc/Debug.o ./MonteCarlo/DataStructures.o ./MonteCarlo/ European.o ./MonteCarlo/Framework.o ./MonteCarlo/Interface.o ./ MonteCarlo/Lookback.o ./Normal/Acklam.o ./Normal/BoxMuller.o ./Normal/ Framework.o ./Normal/Interface.o ./OptionCalculator.o ./Random/ Framework.o ./Random/Halton.o ./Random/Interface.o ./Random/Ranq1.o Undefined symbols: "_mtlzm1zi1zi0zi2_ControlziMonadziStateziStrict_a29_info", referenced from: _r1hl_info in Acklam.o _rGL_info in BoxMuller.o "_mtlzm1zi1zi0zi2_ControlziMonadziStateziStrict_a29_closure", referenced from: _r1hl_srt in Acklam.o _rGL_srt in BoxMuller.o "___stginit_mtlzm1zi1zi0zi2_ControlziMonadziStateziStrict_", referenced from: ___stginit_FrameworkInterface_ in FrameworkInterface.o ___stginit_FrameworkInterface_ in FrameworkInterface.o ___stginit_MonteCarloziEuropean_ in European.o ___stginit_MonteCarloziEuropean_ in European.o ___stginit_MonteCarloziFramework_ in Framework.o ___stginit_MonteCarloziFramework_ in Framework.o ___stginit_MonteCarloziLookback_ in Lookback.o ___stginit_MonteCarloziLookback_ in Lookback.o ___stginit_NormalziAcklam_ in Acklam.o ___stginit_NormalziAcklam_ in Acklam.o ___stginit_NormalziBoxMuller_ in BoxMuller.o ___stginit_NormalziBoxMuller_ in BoxMuller.o ___stginit_NormalziFramework_ in Framework.o ___stginit_NormalziFramework_ in Framework.o ___stginit_RandomziFramework_ in Framework.o ___stginit_RandomziFramework_ in Framework.o ___stginit_RandomziHalton_ in Halton.o ___stginit_RandomziHalton_ in Halton.o ___stginit_RandomziRanq1_ in Ranq1.o ___stginit_RandomziRanq1_ in Ranq1.o ld: symbol(s) not found collect2: ld returned 1 exit status make: *** [OptionCalculator] Error 1 Makefile: HC = ghc HC_OPTS = -O2 -Wall $(EXTRA_HC_OPTS) SRCS := $(shell find . -name "*.hs" -print) OBJS = $(SRCS:.hs=.o) PROG = OptionCalculator .SUFFIXES : .o .hs .hi .lhs .hc .s ${PROG} : $(OBJS) rm -f $@ $(HC) -o $@ $(HC_OPTS) $(OBJS) # Standard suffix rules .o.hi: @: .lhs.o: $(HC) -c $< $(HC_OPTS) .hs.o: $(HC) -c $< $(HC_OPTS) .o-boot.hi-boot: @: .lhs-boot.o-boot: $(HC) -c $< $(HC_OPTS) .hs-boot.o-boot: $(HC) -c $< $(HC_OPTS) clean : find . -name "*.hi" -exec rm -f {} \; find . -name "*.o" -exec rm -f {} \; rm -f ${PROG} depend : ghc -M $(HC_OPTS) $(SRCS) From pumpkingod at gmail.com Thu Aug 6 21:43:44 2009 From: pumpkingod at gmail.com (Daniel Peebles) Date: Thu Aug 6 21:24:26 2009 Subject: [Haskell-cafe] Linking failing due to Control.Monad.State.Strict? In-Reply-To: <6D413D9B-0476-42B3-9FC8-7C9F8C26647E@beadling.co.uk> References: <6D413D9B-0476-42B3-9FC8-7C9F8C26647E@beadling.co.uk> Message-ID: Try with ghc --make ? On Thu, Aug 6, 2009 at 9:38 PM, wrote: > Hi, > > I'm getting a linker error when generating makefile dependencies on the > below library for a program I'm using. ?It links fine under 'ghc --make'. > ?I'm using (more or less) the makefile from the haskell docs. ?I am using > the Strict State Monad in the object files it is complaining about, the > compile is fine, just the linker which is blowing up. Any ideas what is > causing this? > > I'm using GHC 6.10.4 on PPC Mac OS X 10.5. > > I've included the makefile below the error. > > Cheers! > > Phil. > > > ghc -o OptionCalculator -O2 -Wall ?./FrameworkInterface.o ./Maths/Prime.o > ./Misc/Debug.o ./MonteCarlo/DataStructures.o ./MonteCarlo/European.o > ./MonteCarlo/Framework.o ./MonteCarlo/Interface.o ./MonteCarlo/Lookback.o > ./Normal/Acklam.o ./Normal/BoxMuller.o ./Normal/Framework.o > ./Normal/Interface.o ./OptionCalculator.o ./Random/Framework.o > ./Random/Halton.o ./Random/Interface.o ./Random/Ranq1.o > Undefined symbols: > ?"_mtlzm1zi1zi0zi2_ControlziMonadziStateziStrict_a29_info", referenced from: > ? ? ?_r1hl_info in Acklam.o > ? ? ?_rGL_info in BoxMuller.o > ?"_mtlzm1zi1zi0zi2_ControlziMonadziStateziStrict_a29_closure", referenced > from: > ? ? ?_r1hl_srt in Acklam.o > ? ? ?_rGL_srt in BoxMuller.o > ?"___stginit_mtlzm1zi1zi0zi2_ControlziMonadziStateziStrict_", referenced > from: > ? ? ?___stginit_FrameworkInterface_ in FrameworkInterface.o > ? ? ?___stginit_FrameworkInterface_ in FrameworkInterface.o > ? ? ?___stginit_MonteCarloziEuropean_ in European.o > ? ? ?___stginit_MonteCarloziEuropean_ in European.o > ? ? ?___stginit_MonteCarloziFramework_ in Framework.o > ? ? ?___stginit_MonteCarloziFramework_ in Framework.o > ? ? ?___stginit_MonteCarloziLookback_ in Lookback.o > ? ? ?___stginit_MonteCarloziLookback_ in Lookback.o > ? ? ?___stginit_NormalziAcklam_ in Acklam.o > ? ? ?___stginit_NormalziAcklam_ in Acklam.o > ? ? ?___stginit_NormalziBoxMuller_ in BoxMuller.o > ? ? ?___stginit_NormalziBoxMuller_ in BoxMuller.o > ? ? ?___stginit_NormalziFramework_ in Framework.o > ? ? ?___stginit_NormalziFramework_ in Framework.o > ? ? ?___stginit_RandomziFramework_ in Framework.o > ? ? ?___stginit_RandomziFramework_ in Framework.o > ? ? ?___stginit_RandomziHalton_ in Halton.o > ? ? ?___stginit_RandomziHalton_ in Halton.o > ? ? ?___stginit_RandomziRanq1_ in Ranq1.o > ? ? ?___stginit_RandomziRanq1_ in Ranq1.o > ld: symbol(s) not found > collect2: ld returned 1 exit status > make: *** [OptionCalculator] Error 1 > > > > > Makefile: > > > HC ? ? ?= ghc > HC_OPTS = -O2 -Wall $(EXTRA_HC_OPTS) > > SRCS := $(shell find . -name "*.hs" -print) > OBJS = $(SRCS:.hs=.o) > PROG = OptionCalculator > > .SUFFIXES : .o .hs .hi .lhs .hc .s > > ${PROG} : $(OBJS) > ? ? ? ? ?rm -f $@ > ? ? ? ? ?$(HC) -o $@ $(HC_OPTS) $(OBJS) > > # Standard suffix rules > .o.hi: > ? ? ? ?@: > > .lhs.o: > ? ? ? ?$(HC) -c $< $(HC_OPTS) > > .hs.o: > ? ? ? ?$(HC) -c $< $(HC_OPTS) > > .o-boot.hi-boot: > ? ? ? ?@: > > .lhs-boot.o-boot: > ? ? ? ?$(HC) -c $< $(HC_OPTS) > > .hs-boot.o-boot: > ? ? ? ?$(HC) -c $< $(HC_OPTS) > > clean : > ? ? ? ?find . -name "*.hi" -exec rm -f {} \; > ? ? ? ?find . -name "*.o" -exec rm -f {} \; > ? ? ? ?rm -f ${PROG} > > depend : > ? ? ? ?ghc -M $(HC_OPTS) $(SRCS) > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From pumpkingod at gmail.com Thu Aug 6 21:46:58 2009 From: pumpkingod at gmail.com (Daniel Peebles) Date: Thu Aug 6 21:27:40 2009 Subject: [Haskell-cafe] Linking failing due to Control.Monad.State.Strict? In-Reply-To: References: <6D413D9B-0476-42B3-9FC8-7C9F8C26647E@beadling.co.uk> Message-ID: Sorry, I missed that you'd tried that. Why would you not want to use --make? The issue is that when you import a module in your standard library, you need to link to it, and ghc --make takes care of figuring out what to link to for you. Otherwise, you'll need to go digging in your library for the .o files to link to by hand. There's nothing stopping you from using ghc --make along with a makefile, if you have various other complex things to do in your build. Also, people in the Haskell community tend to not use makefiles much, instead opting for the much more "Haskellish" cabal build and packaging system. If you haven't tried it, I recommend it :) Hope this helps (more than my previous email at least!), Dan On Thu, Aug 6, 2009 at 9:43 PM, Daniel Peebles wrote: > Try with ghc --make ? > > On Thu, Aug 6, 2009 at 9:38 PM, wrote: >> Hi, >> >> I'm getting a linker error when generating makefile dependencies on the >> below library for a program I'm using. ?It links fine under 'ghc --make'. >> ?I'm using (more or less) the makefile from the haskell docs. ?I am using >> the Strict State Monad in the object files it is complaining about, the >> compile is fine, just the linker which is blowing up. Any ideas what is >> causing this? >> >> I'm using GHC 6.10.4 on PPC Mac OS X 10.5. >> >> I've included the makefile below the error. >> >> Cheers! >> >> Phil. >> >> >> ghc -o OptionCalculator -O2 -Wall ?./FrameworkInterface.o ./Maths/Prime.o >> ./Misc/Debug.o ./MonteCarlo/DataStructures.o ./MonteCarlo/European.o >> ./MonteCarlo/Framework.o ./MonteCarlo/Interface.o ./MonteCarlo/Lookback.o >> ./Normal/Acklam.o ./Normal/BoxMuller.o ./Normal/Framework.o >> ./Normal/Interface.o ./OptionCalculator.o ./Random/Framework.o >> ./Random/Halton.o ./Random/Interface.o ./Random/Ranq1.o >> Undefined symbols: >> ?"_mtlzm1zi1zi0zi2_ControlziMonadziStateziStrict_a29_info", referenced from: >> ? ? ?_r1hl_info in Acklam.o >> ? ? ?_rGL_info in BoxMuller.o >> ?"_mtlzm1zi1zi0zi2_ControlziMonadziStateziStrict_a29_closure", referenced >> from: >> ? ? ?_r1hl_srt in Acklam.o >> ? ? ?_rGL_srt in BoxMuller.o >> ?"___stginit_mtlzm1zi1zi0zi2_ControlziMonadziStateziStrict_", referenced >> from: >> ? ? ?___stginit_FrameworkInterface_ in FrameworkInterface.o >> ? ? ?___stginit_FrameworkInterface_ in FrameworkInterface.o >> ? ? ?___stginit_MonteCarloziEuropean_ in European.o >> ? ? ?___stginit_MonteCarloziEuropean_ in European.o >> ? ? ?___stginit_MonteCarloziFramework_ in Framework.o >> ? ? ?___stginit_MonteCarloziFramework_ in Framework.o >> ? ? ?___stginit_MonteCarloziLookback_ in Lookback.o >> ? ? ?___stginit_MonteCarloziLookback_ in Lookback.o >> ? ? ?___stginit_NormalziAcklam_ in Acklam.o >> ? ? ?___stginit_NormalziAcklam_ in Acklam.o >> ? ? ?___stginit_NormalziBoxMuller_ in BoxMuller.o >> ? ? ?___stginit_NormalziBoxMuller_ in BoxMuller.o >> ? ? ?___stginit_NormalziFramework_ in Framework.o >> ? ? ?___stginit_NormalziFramework_ in Framework.o >> ? ? ?___stginit_RandomziFramework_ in Framework.o >> ? ? ?___stginit_RandomziFramework_ in Framework.o >> ? ? ?___stginit_RandomziHalton_ in Halton.o >> ? ? ?___stginit_RandomziHalton_ in Halton.o >> ? ? ?___stginit_RandomziRanq1_ in Ranq1.o >> ? ? ?___stginit_RandomziRanq1_ in Ranq1.o >> ld: symbol(s) not found >> collect2: ld returned 1 exit status >> make: *** [OptionCalculator] Error 1 >> >> >> >> >> Makefile: >> >> >> HC ? ? ?= ghc >> HC_OPTS = -O2 -Wall $(EXTRA_HC_OPTS) >> >> SRCS := $(shell find . -name "*.hs" -print) >> OBJS = $(SRCS:.hs=.o) >> PROG = OptionCalculator >> >> .SUFFIXES : .o .hs .hi .lhs .hc .s >> >> ${PROG} : $(OBJS) >> ? ? ? ? ?rm -f $@ >> ? ? ? ? ?$(HC) -o $@ $(HC_OPTS) $(OBJS) >> >> # Standard suffix rules >> .o.hi: >> ? ? ? ?@: >> >> .lhs.o: >> ? ? ? ?$(HC) -c $< $(HC_OPTS) >> >> .hs.o: >> ? ? ? ?$(HC) -c $< $(HC_OPTS) >> >> .o-boot.hi-boot: >> ? ? ? ?@: >> >> .lhs-boot.o-boot: >> ? ? ? ?$(HC) -c $< $(HC_OPTS) >> >> .hs-boot.o-boot: >> ? ? ? ?$(HC) -c $< $(HC_OPTS) >> >> clean : >> ? ? ? ?find . -name "*.hi" -exec rm -f {} \; >> ? ? ? ?find . -name "*.o" -exec rm -f {} \; >> ? ? ? ?rm -f ${PROG} >> >> depend : >> ? ? ? ?ghc -M $(HC_OPTS) $(SRCS) >> >> >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> > From felipe.lessa at gmail.com Thu Aug 6 22:02:50 2009 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Thu Aug 6 21:43:37 2009 Subject: [Haskell-cafe] Hugs faster and more reliable than GHC for large list monad 'do' block In-Reply-To: <4A7B6653.7090104@imageworks.com> References: <4A7B4441.4040100@imageworks.com> <404396ef0908061426o4a0e2929kfa8bcd9f58313902@mail.gmail.com> <4A7B6653.7090104@imageworks.com> Message-ID: <20090807020250.GA7349@kira.casa> On Thu, Aug 06, 2009 at 04:25:07PM -0700, Dan Weston wrote: > > ghc --version > The Glorious Glasgow Haskell Compilation System, version 6.10.4 Confirmed on Gento amd64 with custom-built GHC from Haskell overlay: $ ghc --version The Glorious Glasgow Haskell Compilation System, version 6.10.4 $ uname -a Linux kira 2.6.30-tuxonice-r4 #1 SMP Sat Jul 25 15:28:05 BRT 2009 x86_64 Intel(R) Core(TM)2 Duo CPU T5450 @ 1.66GHz GenuineIntel GNU/Linux -- Felipe. From dons at galois.com Thu Aug 6 22:34:56 2009 From: dons at galois.com (Don Stewart) Date: Thu Aug 6 22:17:42 2009 Subject: [Haskell-cafe] Hugs faster and more reliable than GHC for large list monad 'do' block In-Reply-To: <20090807020250.GA7349@kira.casa> References: <4A7B4441.4040100@imageworks.com> <404396ef0908061426o4a0e2929kfa8bcd9f58313902@mail.gmail.com> <4A7B6653.7090104@imageworks.com> <20090807020250.GA7349@kira.casa> Message-ID: <20090807023456.GB2894@whirlpool.galois.com> felipe.lessa: > On Thu, Aug 06, 2009 at 04:25:07PM -0700, Dan Weston wrote: > > > ghc --version > > The Glorious Glasgow Haskell Compilation System, version 6.10.4 > > Confirmed on Gento amd64 with custom-built GHC from Haskell overlay: > > $ ghc --version > The Glorious Glasgow Haskell Compilation System, version 6.10.4 > > $ uname -a > Linux kira 2.6.30-tuxonice-r4 #1 SMP Sat Jul 25 15:28:05 BRT 2009 x86_64 Intel(R) Core(TM)2 Duo CPU T5450 @ 1.66GHz GenuineIntel GNU/Linux Someone please file a bug report, http://hackage.haskell.org/trac/ghc/newticket?type=bug From phil at beadling.co.uk Fri Aug 7 00:08:58 2009 From: phil at beadling.co.uk (phil@beadling.co.uk) Date: Thu Aug 6 23:49:43 2009 Subject: [Haskell-cafe] Linking failing due to Control.Monad.State.Strict? In-Reply-To: References: <6D413D9B-0476-42B3-9FC8-7C9F8C26647E@beadling.co.uk> Message-ID: <2D89E7D5-0FEF-4654-AE52-DFC27DFBAF7F@beadling.co.uk> Thanks for the reply. > Otherwise, you'll need to go digging in > your library for the .o files to link to by hand. If I look with '-v' tho it seems to include Haskell libs in the underlying link - see below? Plus it only complains about this library, I use many other standard libs too? Looks like something stranger is going on? Also I've tried using --include-pkg-deps (perhaps incorrectly) - it doesn't help. Phil. rm -f OptionCalculator ghc -o OptionCalculator -O2 -Wall -v ./FrameworkInterface.o ./Maths/ Prime.o ./Misc/Debug.o ./MonteCarlo/DataStructures.o ./MonteCarlo/ European.o ./MonteCarlo/Framework.o ./MonteCarlo/Interface.o ./ MonteCarlo/Lookback.o ./Normal/Acklam.o ./Normal/BoxMuller.o ./Normal/ Framework.o ./Normal/Interface.o ./OptionCalculator.o ./Random/ Framework.o ./Random/Halton.o ./Random/Interface.o ./Random/Ranq1.o Glasgow Haskell Compiler, Version 6.10.4, for Haskell 98, stage 2 booted by GHC version 6.10.3 Using package config file: /usr/local/lib/ghc-6.10.4/./package.conf hiding package base-3.0.3.1 to avoid conflict with later version base-4.1.0.0 wired-in package ghc-prim mapped to ghc-prim-0.1.0.0 wired-in package integer mapped to integer-0.1.0.1 wired-in package base mapped to base-4.1.0.0 wired-in package rts mapped to rts-1.0 wired-in package haskell98 mapped to haskell98-1.0.1.0 wired-in package syb mapped to syb-0.1.0.1 wired-in package template-haskell mapped to template-haskell-2.3.0.1 wired-in package dph-seq mapped to dph-seq-0.3 wired-in package dph-par mapped to dph-par-0.3 Hsc static flags: -static *** Linker: gcc -v -o OptionCalculator FrameworkInterface.o Maths/Prime.o Misc/ Debug.o MonteCarlo/DataStructures.o MonteCarlo/European.o MonteCarlo/ Framework.o MonteCarlo/Interface.o MonteCarlo/Lookback.o Normal/ Acklam.o Normal/BoxMuller.o Normal/Framework.o Normal/Interface.o OptionCalculator.o Random/Framework.o Random/Halton.o Random/ Interface.o Random/Ranq1.o -L/usr/local/lib/ghc-6.10.4/ haskell98-1.0.1.0 -L/usr/local/lib/ghc-6.10.4/random-1.0.0.1 -L/usr/ local/lib/ghc-6.10.4/process-1.0.1.1 -L/usr/local/lib/ghc-6.10.4/ directory-1.0.0.3 -L/usr/local/lib/ghc-6.10.4/unix-2.3.2.0 -L/usr/ local/lib/ghc-6.10.4/old-time-1.0.0.2 -L/usr/local/lib/ghc-6.10.4/old- locale-1.0.0.1 -L/usr/local/lib/ghc-6.10.4/filepath-1.1.0.2 -L/usr/ local/lib/ghc-6.10.4/array-0.2.0.0 -L/usr/local/lib/ghc-6.10.4/ syb-0.1.0.1 -L/usr/local/lib/ghc-6.10.4/base-4.1.0.0 -L/usr/local/lib/ ghc-6.10.4/integer-0.1.0.1 -L/usr/local/lib/ghc-6.10.4/ghc- prim-0.1.0.0 -L/usr/local/lib/ghc-6.10.4 -lHShaskell98-1.0.1.0 - lHSrandom-1.0.0.1 -lHSprocess-1.0.1.1 -lHSdirectory-1.0.0.3 - lHSunix-2.3.2.0 -ldl -lHSold-time-1.0.0.2 -lHSold-locale-1.0.0.1 - lHSfilepath-1.1.0.2 -lHSarray-0.2.0.0 -lHSsyb-0.1.0.1 -lHSbase-4.1.0.0 -lHSinteger-0.1.0.1 -lHSghc-prim-0.1.0.0 -lHSrts -lm -lffi -lgmp -ldl - u _ghczmprim_GHCziTypes_Izh_static_info -u _ghczmprim_GHCziTypes_Czh_static_info -u _ghczmprim_GHCziTypes_Fzh_static_info -u _ghczmprim_GHCziTypes_Dzh_static_info -u _base_GHCziPtr_Ptr_static_info -u _base_GHCziWord_Wzh_static_info -u _base_GHCziInt_I8zh_static_info -u _base_GHCziInt_I16zh_static_info -u _base_GHCziInt_I32zh_static_info -u _base_GHCziInt_I64zh_static_info - u _base_GHCziWord_W8zh_static_info -u _base_GHCziWord_W16zh_static_info -u _base_GHCziWord_W32zh_static_info -u _base_GHCziWord_W64zh_static_info -u _base_GHCziStable_StablePtr_static_info -u _ghczmprim_GHCziTypes_Izh_con_info -u _ghczmprim_GHCziTypes_Czh_con_info -u _ghczmprim_GHCziTypes_Fzh_con_info -u _ghczmprim_GHCziTypes_Dzh_con_info -u _base_GHCziPtr_Ptr_con_info -u _base_GHCziPtr_FunPtr_con_info -u _base_GHCziStable_StablePtr_con_info -u _ghczmprim_GHCziBool_False_closure -u _ghczmprim_GHCziBool_True_closure -u _base_GHCziPack_unpackCString_closure -u _base_GHCziIOBase_stackOverflow_closure -u _base_GHCziIOBase_heapOverflow_closure -u _base_ControlziExceptionziBase_nonTermination_closure -u _base_GHCziIOBase_blockedOnDeadMVar_closure -u _base_GHCziIOBase_blockedIndefinitely_closure -u _base_ControlziExceptionziBase_nestedAtomically_closure -u _base_GHCziWeak_runFinalizzerBatch_closure -u _base_GHCziTopHandler_runIO_closure -u _base_GHCziTopHandler_runNonIO_closure -u _base_GHCziConc_runHandlers_closure -u _base_GHCziConc_ensureIOManagerIsRunning_closure -Wl,- search_paths_first -read_only_relocs warning Using built-in specs. Target: powerpc-apple-darwin9 Configured with: /var/tmp/gcc/gcc-5490~1/src/configure --disable- checking -enable-werror --prefix=/usr --mandir=/share/man --enable- languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/ $/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/ lib --build=i686-apple-darwin9 --program-prefix= --host=powerpc-apple- darwin9 --target=powerpc-apple-darwin9 Thread model: posix gcc version 4.0.1 (Apple Inc. build 5490) /usr/libexec/gcc/powerpc-apple-darwin9/4.0.1/collect2 -dynamic -arch ppc -macosx_version_min 10.5.7 -read_only_relocs warning - weak_reference_mismatches non-weak -u _ghczmprim_GHCziTypes_Izh_static_info -u _ghczmprim_GHCziTypes_Czh_static_info -u _ghczmprim_GHCziTypes_Fzh_static_info -u _ghczmprim_GHCziTypes_Dzh_static_info -u _base_GHCziPtr_Ptr_static_info -u _base_GHCziWord_Wzh_static_info -u _base_GHCziInt_I8zh_static_info -u _base_GHCziInt_I16zh_static_info -u _base_GHCziInt_I32zh_static_info -u _base_GHCziInt_I64zh_static_info - u _base_GHCziWord_W8zh_static_info -u _base_GHCziWord_W16zh_static_info -u _base_GHCziWord_W32zh_static_info -u _base_GHCziWord_W64zh_static_info -u _base_GHCziStable_StablePtr_static_info -u _ghczmprim_GHCziTypes_Izh_con_info -u _ghczmprim_GHCziTypes_Czh_con_info -u _ghczmprim_GHCziTypes_Fzh_con_info -u _ghczmprim_GHCziTypes_Dzh_con_info -u _base_GHCziPtr_Ptr_con_info -u _base_GHCziPtr_FunPtr_con_info -u _base_GHCziStable_StablePtr_con_info -u _ghczmprim_GHCziBool_False_closure -u _ghczmprim_GHCziBool_True_closure -u _base_GHCziPack_unpackCString_closure -u _base_GHCziIOBase_stackOverflow_closure -u _base_GHCziIOBase_heapOverflow_closure -u _base_ControlziExceptionziBase_nonTermination_closure -u _base_GHCziIOBase_blockedOnDeadMVar_closure -u _base_GHCziIOBase_blockedIndefinitely_closure -u _base_ControlziExceptionziBase_nestedAtomically_closure -u _base_GHCziWeak_runFinalizzerBatch_closure -u _base_GHCziTopHandler_runIO_closure -u _base_GHCziTopHandler_runNonIO_closure -u _base_GHCziConc_runHandlers_closure -u _base_GHCziConc_ensureIOManagerIsRunning_closure -o OptionCalculator - lcrt1.10.5.o -L/usr/local/lib/ghc-6.10.4/haskell98-1.0.1.0 -L/usr/ local/lib/ghc-6.10.4/random-1.0.0.1 -L/usr/local/lib/ghc-6.10.4/ process-1.0.1.1 -L/usr/local/lib/ghc-6.10.4/directory-1.0.0.3 -L/usr/ local/lib/ghc-6.10.4/unix-2.3.2.0 -L/usr/local/lib/ghc-6.10.4/old- time-1.0.0.2 -L/usr/local/lib/ghc-6.10.4/old-locale-1.0.0.1 -L/usr/ local/lib/ghc-6.10.4/filepath-1.1.0.2 -L/usr/local/lib/ghc-6.10.4/ array-0.2.0.0 -L/usr/local/lib/ghc-6.10.4/syb-0.1.0.1 -L/usr/local/lib/ ghc-6.10.4/base-4.1.0.0 -L/usr/local/lib/ghc-6.10.4/integer-0.1.0.1 -L/ usr/local/lib/ghc-6.10.4/ghc-prim-0.1.0.0 -L/usr/local/lib/ghc-6.10.4 - L/usr/lib/powerpc-apple-darwin9/4.0.1 -L/usr/lib/gcc/powerpc-apple- darwin9/4.0.1 -L/usr/lib/gcc/powerpc-apple-darwin9/4.0.1 -L/usr/lib/ gcc/powerpc-apple-darwin9/4.0.1/../../../powerpc-apple-darwin9/4.0.1 - L/usr/lib/gcc/powerpc-apple-darwin9/4.0.1/../../.. FrameworkInterface.o Maths/Prime.o Misc/Debug.o MonteCarlo/ DataStructures.o MonteCarlo/European.o MonteCarlo/Framework.o MonteCarlo/Interface.o MonteCarlo/Lookback.o Normal/Acklam.o Normal/ BoxMuller.o Normal/Framework.o Normal/Interface.o OptionCalculator.o Random/Framework.o Random/Halton.o Random/Interface.o Random/Ranq1.o - lHShaskell98-1.0.1.0 -lHSrandom-1.0.0.1 -lHSprocess-1.0.1.1 - lHSdirectory-1.0.0.3 -lHSunix-2.3.2.0 -ldl -lHSold-time-1.0.0.2 - lHSold-locale-1.0.0.1 -lHSfilepath-1.1.0.2 -lHSarray-0.2.0.0 - lHSsyb-0.1.0.1 -lHSbase-4.1.0.0 -lHSinteger-0.1.0.1 -lHSghc- prim-0.1.0.0 -lHSrts -lm -lffi -lgmp -ldl -search_paths_first -lgcc_s. 10.5 -lgcc -lSystemStubs -lSystem Undefined symbols: "_mtlzm1zi1zi0zi2_ControlziMonadziStateziStrict_a29_info", referenced from: _r1hl_info in Acklam.o _rGL_info in BoxMuller.o "_mtlzm1zi1zi0zi2_ControlziMonadziStateziStrict_a29_closure", referenced from: _r1hl_srt in Acklam.o _rGL_srt in BoxMuller.o "___stginit_mtlzm1zi1zi0zi2_ControlziMonadziStateziStrict_", referenced from: ___stginit_FrameworkInterface_ in FrameworkInterface.o ___stginit_FrameworkInterface_ in FrameworkInterface.o ___stginit_MonteCarloziEuropean_ in European.o ___stginit_MonteCarloziEuropean_ in European.o ___stginit_MonteCarloziFramework_ in Framework.o ___stginit_MonteCarloziFramework_ in Framework.o ___stginit_MonteCarloziLookback_ in Lookback.o ___stginit_MonteCarloziLookback_ in Lookback.o ___stginit_NormalziAcklam_ in Acklam.o ___stginit_NormalziAcklam_ in Acklam.o ___stginit_NormalziBoxMuller_ in BoxMuller.o ___stginit_NormalziBoxMuller_ in BoxMuller.o ___stginit_NormalziFramework_ in Framework.o ___stginit_NormalziFramework_ in Framework.o ___stginit_RandomziFramework_ in Framework.o ___stginit_RandomziFramework_ in Framework.o ___stginit_RandomziHalton_ in Halton.o ___stginit_RandomziHalton_ in Halton.o ___stginit_RandomziRanq1_ in Ranq1.o ___stginit_RandomziRanq1_ in Ranq1.o ld: symbol(s) not found collect2: ld returned 1 exit status *** Deleting temp files: Deleting: *** Deleting temp dirs: Deleting: make: *** [OptionCalculator] Error 1 Cheers, Phil. On 7 Aug 2009, at 02:46, Daniel Peebles wrote: > Sorry, I missed that you'd tried that. Why would you not want to use > --make? The issue is that when you import a module in your standard > library, you need to link to it, and ghc --make takes care of figuring From porges at porg.es Fri Aug 7 01:45:46 2009 From: porges at porg.es (George Pollard) Date: Fri Aug 7 01:26:27 2009 Subject: [Haskell-cafe] Request for Changelogs In-Reply-To: <404396ef0908060739m350040se604debc9b104690@mail.gmail.com> References: <1249568876.10202.65.camel@localhost> <404396ef0908060739m350040se604debc9b104690@mail.gmail.com> Message-ID: <6d942a4a0908062245h4ca9f23axf4ec1af2ae0c8f16@mail.gmail.com> 2009/8/7 Neil Mitchell : >> Which leaves me with the option of getting the darcs repo and looking >> through "darcs changes". If I know of a repository for the package. > > I also don't tag the darcs version when I make a release - I probably should... This could be a nice feature for cabal (or an external tool... cabal-release?): auto-increment the version number (of course, the 'level' of release would have to be specified) and tag the current darcs repo accordingly, then 'cabal upload' it. - George From lambda-belka at yandex.ru Fri Aug 7 04:43:08 2009 From: lambda-belka at yandex.ru (Belka) Date: Fri Aug 7 04:23:49 2009 Subject: [Haskell-cafe] Seeking for an extention (functional incapsulation) In-Reply-To: <4A7B7B79.3090403@imageworks.com> References: <24856249.post@talk.nabble.com> <4A7B694C.40803@imageworks.com> <4A7B69A0.3050606@imageworks.com> <24856983.post@talk.nabble.com> <4A7B7B79.3090403@imageworks.com> Message-ID: <24861049.post@talk.nabble.com> > Exponentially? Now I'm missing something... I meant: in as-is version you have 3 declarations (data, sdtField2 :: ..., sdtField2 = ...), but in a proposed one - only one, with subdeclarations. My perception is more oriented on that compositional criterion, than calculates char counts. Besides, syntactically proposed version sticks together entities that are very closely related. -- View this message in context: http://www.nabble.com/Seeking-for-an-extention-%28functional-incapsulation%29-tp24856249p24861049.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From lambda-belka at yandex.ru Fri Aug 7 04:50:25 2009 From: lambda-belka at yandex.ru (Belka) Date: Fri Aug 7 04:31:06 2009 Subject: [Haskell-cafe] Seeking for an extention (functional incapsulation) In-Reply-To: <24861049.post@talk.nabble.com> References: <24856249.post@talk.nabble.com> <4A7B694C.40803@imageworks.com> <4A7B69A0.3050606@imageworks.com> <24856983.post@talk.nabble.com> <4A7B7B79.3090403@imageworks.com> <24861049.post@talk.nabble.com> Message-ID: <24861154.post@talk.nabble.com> Belka wrote: > >> Exponentially? Now I'm missing something... > I meant: in as-is version you have 3 declarations (data, sdtField2 :: ..., > sdtField2 = ...), but in a proposed one - only one, with subdeclarations. > My perception is more oriented on that compositional criterion, than > calculates char counts. Besides, syntactically proposed version sticks > together entities that are very closely related. > I guess, I was too fast calling it (growth of code units with LOC in as-is version against proposed one) exponential. :) It is not. Proportional. But that's not that important. -- View this message in context: http://www.nabble.com/Seeking-for-an-extention-%28functional-incapsulation%29-tp24856249p24861154.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From malcolm.wallace at cs.york.ac.uk Fri Aug 7 05:14:42 2009 From: malcolm.wallace at cs.york.ac.uk (Malcolm Wallace) Date: Fri Aug 7 04:55:22 2009 Subject: [Haskell-cafe] Linking failing due to Control.Monad.State.Strict? In-Reply-To: <2D89E7D5-0FEF-4654-AE52-DFC27DFBAF7F@beadling.co.uk> References: <6D413D9B-0476-42B3-9FC8-7C9F8C26647E@beadling.co.uk> <2D89E7D5-0FEF-4654-AE52-DFC27DFBAF7F@beadling.co.uk> Message-ID: > If I look with '-v' tho it seems to include Haskell libs in the > underlying link - see below? Plus it only complains about this > library, I use many other standard libs too? Looks like something > stranger is going on? Looks like you need to add -package mtl to the ghc commandline. If you don't use --make, then you need to be explicit about which packages to link against. Regards, Malcolm From lemming at henning-thielemann.de Fri Aug 7 05:29:12 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Fri Aug 7 05:10:23 2009 Subject: [Haskell-cafe] Hugs faster and more reliable than GHC for large list monad 'do' block In-Reply-To: <4A7B6653.7090104@imageworks.com> References: <4A7B4441.4040100@imageworks.com> <404396ef0908061426o4a0e2929kfa8bcd9f58313902@mail.gmail.com> <4A7B6653.7090104@imageworks.com> Message-ID: On Thu, 6 Aug 2009, Dan Weston wrote: > Neil Mitchell wrote: >> Hi >> >> I think the issue you're running in to with 6.4 is this one: >> http://hackage.haskell.org/trac/ghc/ticket/830 - known and fixed a >> while back. >> > No, I am using the latest released ghc: I think Neil refered to my experiences with GHC-6.4, namely that the 'do' block could not be compiled, at all. Neil, thanks for pointing to the ticket. I think it is the problem we encountered. From olshanskydr at gmail.com Fri Aug 7 05:31:28 2009 From: olshanskydr at gmail.com (Dmitry Olshansky) Date: Fri Aug 7 05:12:08 2009 Subject: [Haskell-cafe] Haskell2Xml In-Reply-To: References: <741612210908051249ya47b732ne8f06010204b5090@mail.gmail.com> <92e42b740908051710t1765909cg6e38f665bf221449@mail.gmail.com> Message-ID: <741612210908070231j409cb0ecwaf1cb694d860a8f9@mail.gmail.com> Like in Keith proposal I need it for working with web-services, maybe Xml transformations and so on. And I tried to make it by self with a partial success. To work with xml I only used "xml" package (Text.XML.Light). Now I am going to work a little (?) on this task to provide more standard and regular tool than I have now. So it is very interesting for me to learn any ideas (if exists) on this thing from community. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090807/63183565/attachment.html From jvlask at hotmail.com Fri Aug 7 06:05:52 2009 From: jvlask at hotmail.com (John Lask) Date: Fri Aug 7 05:50:41 2009 Subject: [Haskell-cafe] Haskell2Xml References: <741612210908051249ya47b732ne8f06010204b5090@mail.gmail.com><92e42b740908051710t1765909cg6e38f665bf221449@mail.gmail.com> <741612210908070231j409cb0ecwaf1cb694d860a8f9@mail.gmail.com> Message-ID: the paper: Scripting XML with Generic Haskell Frank Atanassow, Dave Clarke and Johan Jeuring October 14, 2003 describes a translation from XML Schema to Haskell data types (like dtd2haskell) in generic haskell, I believe that the code for the tool described may also be available, how hard it would be to migrate over to vanilla haskell+generics is another question.... ----- Original Message ----- From: Dmitry Olshansky To: Haskell cafe Sent: Friday, August 07, 2009 7:31 PM Subject: Re: [Haskell-cafe] Haskell2Xml Like in Keith proposal I need it for working with web-services, maybe Xml transformations and so on. And I tried to make it by self with a partial success. To work with xml I only used "xml" package (Text.XML.Light). Now I am going to work a little (?) on this task to provide more standard and regular tool than I have now. So it is very interesting for me to learn any ideas (if exists) on this thing from community. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe From jvlask at hotmail.com Fri Aug 7 06:08:46 2009 From: jvlask at hotmail.com (John Lask) Date: Fri Aug 7 05:53:17 2009 Subject: [Haskell-cafe] Haskell2Xml References: <741612210908051249ya47b732ne8f06010204b5090@mail.gmail.com><92e42b740908051710t1765909cg6e38f665bf221449@mail.gmail.com> <741612210908070231j409cb0ecwaf1cb694d860a8f9@mail.gmail.com> Message-ID: link to paper: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.1.7362 ----- Original Message ----- From: Dmitry Olshansky To: Haskell cafe Sent: Friday, August 07, 2009 7:31 PM Subject: Re: [Haskell-cafe] Haskell2Xml Like in Keith proposal I need it for working with web-services, maybe Xml transformations and so on. And I tried to make it by self with a partial success. To work with xml I only used "xml" package (Text.XML.Light). Now I am going to work a little (?) on this task to provide more standard and regular tool than I have now. So it is very interesting for me to learn any ideas (if exists) on this thing from community. ------------------------------------------------------------------------------ _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090807/8d829545/attachment.html From leather at cs.uu.nl Fri Aug 7 06:29:47 2009 From: leather at cs.uu.nl (Sean Leather) Date: Fri Aug 7 06:10:48 2009 Subject: [Haskell-cafe] Haskell2Xml In-Reply-To: References: <741612210908051249ya47b732ne8f06010204b5090@mail.gmail.com> <92e42b740908051710t1765909cg6e38f665bf221449@mail.gmail.com> <741612210908070231j409cb0ecwaf1cb694d860a8f9@mail.gmail.com> Message-ID: <3c6288ab0908070329v9aaeec8h74c8da9b5bd72fd7@mail.gmail.com> On Fri, Aug 7, 2009 at 12:05, John Lask wrote: > the paper: > > Scripting XML with Generic Haskell > Frank Atanassow, Dave Clarke and Johan Jeuring > October 14, 2003 > > describes a translation from XML Schema to Haskell data types (like > dtd2haskell) in generic haskell, I believe that the code for the tool > described may also be available, how hard it would be to migrate over to > vanilla haskell+generics is another question.... > It looks like this almost might work in EMGM. They use a Label in addition to all the other representation structure elements. EMGM doesn't have a Label, but it might be useful to add it... With any needed changes such as the Label done, migrating this Generic Haskell code to EMGM would not be difficult. Sean -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090807/dd739cfc/attachment.html From greenspan.levi at googlemail.com Fri Aug 7 06:39:19 2009 From: greenspan.levi at googlemail.com (Levi Greenspan) Date: Fri Aug 7 06:19:59 2009 Subject: [Haskell-cafe] Re: FFI: Problem with Signal Handler Interruptions In-Reply-To: <4A7AADB8.7040802@gmail.com> References: <3e62d4360908040106v24e87d3as987979d3e34943ff@mail.gmail.com> <3e62d4360908050901u392ae7e2m5a48d177cd90435b@mail.gmail.com> <4A7AADB8.7040802@gmail.com> Message-ID: <3e62d4360908070339h3fc3b9a2ld5e03a273889272e@mail.gmail.com> On Thu, Aug 6, 2009 at 12:17 PM, Simon Marlow wrote: > The SIGVTALRM signal is delivered to one (random) thread in the program, so > I imagine it just isn't being delivered to the thread that runs your second > call to sleep. ?(the main Haskell thread is a "bound thread" and hence gets > an OS thread to itself). In addition to my last e-mail - would you say that blocking SIGVTALRM in the thread that runs sleep (or poll etc.) is the right thing to do in order to avoid the problem of getting EINTR? E.g. for the main thread: {-# LANGUAGE ForeignFunctionInterface #-} module Main where import Foreign.C.Types import Control.Concurrent import System.Posix.Signals import Control.Monad blockSIGVTALRM :: IO () blockSIGVTALRM = addSignal virtualTimerExpired `liftM` getSignalMask >>= blockSignals >> return () sleep :: IO () sleep = blockSIGVTALRM >> c_sleep 3 >>= print main :: IO () main = sleep foreign import ccall safe "unistd.h sleep" c_sleep :: CUInt -> IO CUInt How much would the thread scheduling be affected by this? Many thanks, Levi From olshanskydr at gmail.com Fri Aug 7 07:04:37 2009 From: olshanskydr at gmail.com (Dmitry Olshansky) Date: Fri Aug 7 06:45:18 2009 Subject: [Haskell-cafe] Haskell2Xml In-Reply-To: <3c6288ab0908070329v9aaeec8h74c8da9b5bd72fd7@mail.gmail.com> References: <741612210908051249ya47b732ne8f06010204b5090@mail.gmail.com> <92e42b740908051710t1765909cg6e38f665bf221449@mail.gmail.com> <741612210908070231j409cb0ecwaf1cb694d860a8f9@mail.gmail.com> <3c6288ab0908070329v9aaeec8h74c8da9b5bd72fd7@mail.gmail.com> Message-ID: <741612210908070404m397a9f70u94504adb8cb1ce39@mail.gmail.com> Well, great thanks for interesting links. But definitely at first I need a time to try to understand what Generic Haskell and EMGM are. Does it stronger than Template Haskell? Could it be explained briefly and simplistic for first impression? Could it be compared with SYB or TH? Would it be applied to realisation of translation or to target Haskell code? Regards, Dmitry 2009/8/7 Sean Leather > > On Fri, Aug 7, 2009 at 12:05, John Lask wrote: > >> the paper: >> >> Scripting XML with Generic Haskell >> Frank Atanassow, Dave Clarke and Johan Jeuring >> October 14, 2003 >> >> describes a translation from XML Schema to Haskell data types (like >> dtd2haskell) in generic haskell, I believe that the code for the tool >> described may also be available, how hard it would be to migrate over to >> vanilla haskell+generics is another question.... >> > > It looks like this almost might work in EMGM. They use a Label in addition > to all the other representation structure elements. EMGM doesn't have a > Label, but it might be useful to add it... > > With any needed changes such as the Label done, migrating this Generic > Haskell code to EMGM would not be difficult. > > Sean > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090807/9921637c/attachment.html From bulat.ziganshin at gmail.com Fri Aug 7 07:15:51 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Aug 7 06:59:33 2009 Subject: [Haskell-cafe] Haskell2Xml In-Reply-To: <741612210908070404m397a9f70u94504adb8cb1ce39@mail.gmail.com> References: <741612210908051249ya47b732ne8f06010204b5090@mail.gmail.com> <92e42b740908051710t1765909cg6e38f665bf221449@mail.gmail.com> <741612210908070231j409cb0ecwaf1cb694d860a8f9@mail.gmail.com> <3c6288ab0908070329v9aaeec8h74c8da9b5bd72fd7@mail.gmail.com> <741612210908070404m397a9f70u94504adb8cb1ce39@mail.gmail.com> Message-ID: <1892368765.20090807151551@gmail.com> Hello Dmitry, Friday, August 7, 2009, 3:04:37 PM, you wrote: generic programming in haskell generally means SYB-like things and Generic Haskell (at least i have read description of) was a extended version of Haskell with built-in support for generic programming. i.e. those type-specific operations that was implemented in SYB using type hackery, were built-in in GH. you may also read Comparing Libraries for Generic Programming in Haskell [http://www.cs.uu.nl/research/techreps/repo/CS-2008/2008-010.pdf] Comparing Approaches to Generic Programming in Haskell [http://www.cs.uu.nl/~johanj/publications/ComparingGP.pdf] > Well, great thanks for interesting links.? > But?definitely?at first I need a time to try to understand what Generic Haskell and EMGM are. > Does it stronger than Template Haskell? Could it be explained > briefly and simplistic for first impression? Could it be compared with SYB or TH? > > Would it be applied to realisation of translation or to target Haskell code?? > Regards, > Dmitry > 2009/8/7 Sean Leather > > On Fri, Aug 7, 2009 at 12:05, John Lask wrote: > > the paper: > > Scripting XML with Generic Haskell > Frank Atanassow, Dave Clarke and Johan Jeuring > October 14, 2003 > > describes a translation from XML Schema to Haskell data types > (like dtd2haskell) in generic haskell, I believe that the code for > the tool described may also be available, how hard it would be to > migrate over to vanilla haskell+generics is another question.... > > It looks like this almost might work in EMGM. They use a Label in > addition to all the other representation structure elements. EMGM > doesn't have a Label, but it might be useful to add it... > > With any needed changes such as the Label done, migrating this > Generic Haskell code to EMGM would not be difficult. > Sean > > -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From leather at cs.uu.nl Fri Aug 7 07:37:06 2009 From: leather at cs.uu.nl (Sean Leather) Date: Fri Aug 7 07:18:06 2009 Subject: [Haskell-cafe] Haskell2Xml In-Reply-To: <741612210908070404m397a9f70u94504adb8cb1ce39@mail.gmail.com> References: <741612210908051249ya47b732ne8f06010204b5090@mail.gmail.com> <92e42b740908051710t1765909cg6e38f665bf221449@mail.gmail.com> <741612210908070231j409cb0ecwaf1cb694d860a8f9@mail.gmail.com> <3c6288ab0908070329v9aaeec8h74c8da9b5bd72fd7@mail.gmail.com> <741612210908070404m397a9f70u94504adb8cb1ce39@mail.gmail.com> Message-ID: <3c6288ab0908070437ja6519b6l7d0c99e5b287b39d@mail.gmail.com> Hi Dmitry, Well, great thanks for interesting links. > > But definitely at first I need a time to try to understand what Generic > Haskell and EMGM are. > Generic Haskell (GH) is a language extension implementing datatype-generic programming features on top of Haskell. It is implemented using a preprocessor that compiles source to Haskell. EMGM ("Extensible and Modular Generics for the Masses") is an example of a Haskell library that allows you to implement many of the GH functions directly in Haskell without a preprocessor. > Does it stronger than Template Haskell? Could it be explained briefly and > simplistic for first impression? Could it be compared with SYB or TH? > Template Haskell is a syntax-based metaprogramming extension to Haskell. Many datatype-generic things can be done in TH, but it often takes a lot of work because you're generating syntax. EMGM actually uses TH to generate representation values of datatypes. SYB is another example of a datatype-generic library. It uses a different representation of datatypes than EMGM and GH. As a result, the libraries support different kinds of functions (sometimes completely different, but sometimes the same and implemented differently). > Would it be applied to realisation of translation or to target Haskell > code? > To use something like EMGM or SYB, one uses or develops functions for manipulating values of arbitrary datatypes. Think of what happens when you "derive (Eq, Read, Show)" for example. You are getting functions (==), read, and show that work for your datatype. You can do this same sort of thing with other functions in SYB and EMGM. As for your use case, I don't know if one of the libraries can help you directly. You wanted to first get the datatypes from XML Schemas, and that's going to require something like HaXml. But once you do get those datatypes, you can use one of the many generic programming libraries to manipulate values without having to write your own functions. For a tutorial on using EMGM and SYB, see our recently published tech. report: Libraries for Generic Programming in Haskell Johan Jeuring, Sean Leather, Jos? Pedro Magalh?es, and Alexey Rodriguez Yakushev http://www.cs.uu.nl/research/techreps/UU-CS-2008-025.html Sean -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090807/99349cd1/attachment.html From johan.tibell at gmail.com Fri Aug 7 07:40:28 2009 From: johan.tibell at gmail.com (Johan Tibell) Date: Fri Aug 7 07:21:27 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> Message-ID: <90889fe70908070440i4e5e18b3t612dc2ca33e7a9b0@mail.gmail.com> On Tue, Aug 4, 2009 at 7:40 AM, Alexander Dunlap wrote: > Interface unification would help. Especially network-bytestring seems > to be too ad-hoc for me - it would probably be better to put > ByteString support into the regular Network library.... It's my intention to get it merged into network now when I'm the maintainer of both libraries. There's an open ticket for this task and I will propose the merge on the libraries mailing list shortly. Cheers, Johan From sebastian.sylvan at gmail.com Fri Aug 7 11:13:15 2009 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Fri Aug 7 10:53:55 2009 Subject: [Haskell-cafe] Basic questions about concurrency in Haskell In-Reply-To: References: <3d96ac180908051201v731122d4ub2f4ca67aa6b9466@mail.gmail.com> <3d96ac180908051216g47e36b04g8c5b491d9cbd9221@mail.gmail.com> Message-ID: <3d96ac180908070813w7604214cwa09ab96c5f51ac1f@mail.gmail.com> Bringing the cafe back in. If I remember correctly tuning the GC is one of the things they worked on for the next release (in relation to parallelism).Here's a link to the paper: http://research.microsoft.com/en-us/um/people/simonpj/papers/parallel/multicore-ghc.pdf You can allocate dynamic memory on the C heap using the Foreign.Marshal.Alloc stuff. The Storable class allows you to specify alignment. However it's not clear you will need it in all cases. Most of the time IME all you really need is for "the business end" of object A and B to end up on different cache lines, padding them with the size of a cache line will accomplish that even if each object starts in the middle of a cache line. In other words, as long as you ensure that there's at least CACHE_LINE bytes difference between the last bit of data in A and the first bit of data in B, they won't exhibit false sharing. I'm not sure if any of the "standard" mutable references etc. respect this. Maybe someone can clarify? If you modify a thread-local IORef will that cause another thread to stall because it has it's own thread-local IORef on the same cache line? On Fri, Aug 7, 2009 at 12:42 PM, Thomas Witzel wrote: > I have not yet been able to get the dev version compiled, but I'm > looking into it (basically compiles to 99% and then stops because of a > missing or defective .mk file). Anyhow, I played more with the release > version and one thing I noticed is that the GC time increases almost > linearly with the number of cores. Is there somewhere a document that > explains the overall architecture of the GHC/RTS and how in especially > the GC acts in concurrent situations ? > > As for your comment regarding the padding the data-structures, I'll of > course also need to control the alignment in such a case. Is there > such a thing as explicit dynamic memory allocation in Haskell ? > > Thanks, Thomas > > On Wed, Aug 5, 2009 at 3:16 PM, Sebastian > Sylvan wrote: > > GHC doesn't have per-thread allocation so it's probably a bit tricky to > get > > that working. Plus, for parallelism it's not clear that a piece of data > is > > necessarily "owned" by one thead, since it could be produced by a spark > and > > consumed by another spark, those two independent sparks may not > necessarily > > occupy the same thread, which means that any *other* data accessed by the > > firs thread could thrash the cache. So really you'd need per-spark > > allocation areas which would probably make sparks very heavy weight. > > In other words, I think there's plenty of research that needs to be done > > w.r.t. scheduling things in time and space so as to avoid false sharing. > You > > could, of course, always chunk your work manually, and make sure that > each > > "chunk" works on a big block that won't share cache lines with anything > else > > (e.g. by padding the data structures). > > Also, while GHC does a fair bit of mutation on its own internal data > (thunks > > etc.), most of the "user data" is read-only, which should help. I.e. once > a > > cache line has been filled up, there won't be any synchronisation needed > on > > that data again. > > > > On Wed, Aug 5, 2009 at 8:04 PM, Thomas Witzel > > wrote: > >> > >> I'll try that. I'd like to stick with it. As for the memory, although > >> its probably quite a bit of work, it should be doable to have code > >> generated where the threads have their own, non-overlapping, memory > >> pages, so that the CPUs don't go into a cache-thrashing death-match. > >> I'll spend some more time with Haskell and then go from there. > >> > >> On Wed, Aug 5, 2009 at 3:01 PM, Sebastian > >> Sylvan wrote: > >> > > >> > > >> > On Wed, Aug 5, 2009 at 6:59 PM, Thomas Witzel < > witzel.thomas@gmail.com> > >> > wrote: > >> >> > >> >> 2. I started with the very simple nfib example given in the manual > for > >> >> Control.Parallel (Section 7.18). On my systems using multiple cores > >> >> makes the code actually slower than just using a single core. While > >> >> the manual cautions that this could be the case for certain > >> >> algorithms, I'm wondering whether this is the desired behaviour for > >> >> this example. > >> >> > >> >> I'm using ghc 6.10.4 right now. > >> > > >> > IIRC the development version of GHC has some major work to optimize > >> > concurrency, so it may be worth trying that. In particular I believe > it > >> > executes sparks in batches, to reduce the overhead (which hopefully > >> > fixes > >> > your issue). > >> > > >> > -- > >> > Sebastian Sylvan > >> > > > > > > > > > -- > > Sebastian Sylvan > > > -- Sebastian Sylvan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090807/61a183a0/attachment.html From phil at beadling.co.uk Fri Aug 7 19:20:52 2009 From: phil at beadling.co.uk (phil@beadling.co.uk) Date: Fri Aug 7 19:01:33 2009 Subject: [Haskell-cafe] Linking failing due to Control.Monad.State.Strict? In-Reply-To: References: <6D413D9B-0476-42B3-9FC8-7C9F8C26647E@beadling.co.uk> <2D89E7D5-0FEF-4654-AE52-DFC27DFBAF7F@beadling.co.uk> Message-ID: That's the puppy! Thanks so much for your help! Phil. On 7 Aug 2009, at 10:14, Malcolm Wallace wrote: >> If I look with '-v' tho it seems to include Haskell libs in the >> underlying link - see below? Plus it only complains about this >> library, I use many other standard libs too? Looks like something >> stranger is going on? > > Looks like you need to add -package mtl to the ghc commandline. If > you don't use --make, then you need to be explicit about which > packages to link against. > > Regards, > Malcolm > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From alex at alexjacobson.com Fri Aug 7 19:43:46 2009 From: alex at alexjacobson.com (S. Alexander Jacobson) Date: Fri Aug 7 19:24:37 2009 Subject: [Haskell-cafe] Database written in Haskell? In-Reply-To: References: Message-ID: <4A7CBC32.7090201@alexjacobson.com> HAppS' IxSet library gives relational operations but does not have a SQL interface. Am thinking of changing the name to RelSet to make the functionality clear. You can use HAppS.State to give ACID properties to operations on this data structure. -Alex- On 8/1/09 12:15 AM, G?nther Schmidt wrote: > Hi, > > is there an SQL database written in Haskell like HSQLDB which is > written in Java? > > G?nther > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From gue.schmidt at web.de Fri Aug 7 20:15:22 2009 From: gue.schmidt at web.de (=?iso-8859-15?Q?G=FCnther_Schmidt?=) Date: Fri Aug 7 19:56:03 2009 Subject: [Haskell-cafe] Database written in Haskell? In-Reply-To: <4A7CBC32.7090201@alexjacobson.com> References: <4A7CBC32.7090201@alexjacobson.com> Message-ID: Hi Alex, very nice to hear from you and thank you very much for Happs. I'm quite familiar with IxSet and loved it, however there where a few things that made it unfeasable for the particular application. It must be able run on Win2k machines so you can imagine the hardware is rather low end. As Happs-IxSet runs, to my knowledge, entirely in memory, that was a problem right there, SQLite does not. The other thing was that Happs-IxSet uses Data.Set as its backend so to speak. That meant that duplicates (some of the records are duplicates and I can't help that) gotten "swallowed" with out me noticing at first, well apart from the sums no longer adding up of course. Also Happs IxSet creates elements of the same type or tuple, they are no projections out of the box. G?nther Am 08.08.2009, 01:43 Uhr, schrieb S. Alexander Jacobson : > HAppS' IxSet library gives relational operations but does not have a SQL > interface. Am thinking of changing the name to RelSet to make the > functionality clear. You can use HAppS.State to give ACID properties > to operations on this data structure. > > -Alex- > > On 8/1/09 12:15 AM, G?nther Schmidt wrote: >> Hi, >> >> is there an SQL database written in Haskell like HSQLDB which is >> written in Java? >> >> G?nther >> >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe > From gue.schmidt at web.de Fri Aug 7 20:23:25 2009 From: gue.schmidt at web.de (=?iso-8859-15?Q?G=FCnther_Schmidt?=) Date: Fri Aug 7 20:04:17 2009 Subject: [Haskell-cafe] Re: Re: SQL Database in Haskell? References: <87fxc5jz8t.fsf@zagan.made.you> Message-ID: Hi Max, thanks for that hint. I had tried IxSet by itself and was unaware that Happs-state might be a solution. Performance *is* a problem, not time but space. If you meant a time performance problem, that'd be acceptable, the app with SQLite is running too fast as it is. But the machines this app is supposed to be able to run are Win2k machines, so a space performance problem *is* a problem. Which one did you mean? G?nther Am 06.08.2009, 07:19 Uhr, schrieb Max Desyatov : > As I can say from my experience of usage of hdbc-sqlite3 and > happstack-state, the latter covers everything you ever wanted from > sqlite3 and more. It you aren't too concerned about performance, you > can free yourself from many tedious routines that are imminent when you > work with relational database. Elaborated data model design coupled > with some generics technique (uniplate with derive, e.g.) gives you a > possibility to write down your domain problem directly to haskell. > > CK Kashyap writes: > >> I'd be very interested to see a rdbms implementation in Haskell ... >> perhaps a port of sqlite >> >> Regards, >> Kashyap From axman6 at gmail.com Fri Aug 7 23:08:55 2009 From: axman6 at gmail.com (Alex Mason) Date: Fri Aug 7 22:49:42 2009 Subject: [Haskell-cafe] What would be required to make a LLVM backend for GHC Message-ID: <31423307-836F-49B2-ACC0-2A03406A8FA9@gmail.com> Hi all, I've been talking to one of the LLVM developers, who's working on an operating system called AuroraUX, which, among other things, is trying to use LLVM as much as possible in the system (using clang as the default compiler, compiler-rt [libgcc replacement from the LLVM team], etc.). He would like to know exactly what would need to be implemented in LLVM to allow ghc to be ported to LLVM, and he would do his best to get these features implemented. I know the LLVM guys are quite open to suggestions, and want to get people using it as much as possible, so if we can let them know what we need, hopefully they can help make life easier for us. Thanks, Alex Mason From gwern0 at gmail.com Fri Aug 7 23:41:06 2009 From: gwern0 at gmail.com (Gwern Branwen) Date: Fri Aug 7 23:21:58 2009 Subject: [Haskell-cafe] What would be required to make a LLVM backend for GHC In-Reply-To: <31423307-836F-49B2-ACC0-2A03406A8FA9@gmail.com> Message-ID: On Fri, Aug 7, 2009 at 11:08 PM, Alex Mason wrote: > Hi all, > > I've been talking to one of the LLVM developers, who's working on an > operating system called AuroraUX, which, among other things, is trying to > use LLVM as much as possible in the system (using clang as the default > compiler, compiler-rt [libgcc replacement from the LLVM team], etc.). > > He would like to know exactly what would need to be implemented in LLVM to > allow ghc to be ported to LLVM, and he would do his best to get these > features implemented. I know the LLVM guys are quite open to suggestions, > and want to get people using it as much as possible, so if we can let them > know what we need, hopefully they can help make life easier for us. > > Thanks, > Alex Mason Have you seen the LHC blog posts and the llvm discussion thereof? http://lhc-compiler.blogspot.com/2009/01/case-against-cllvm.html http://lhc-compiler.blogspot.com/2009/01/why-llvm-probably-wont-replace-c.html -- gwern -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: OpenPGP digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090807/9e07f0ce/signature-0001.bin From mxcantor at gmail.com Sat Aug 8 02:27:00 2009 From: mxcantor at gmail.com (Max Cantor) Date: Sat Aug 8 02:17:06 2009 Subject: [Haskell-cafe] Haskell2Xml - Suggest looking at HXT In-Reply-To: <741612210908070404m397a9f70u94504adb8cb1ce39@mail.gmail.com> References: <741612210908051249ya47b732ne8f06010204b5090@mail.gmail.com> <92e42b740908051710t1765909cg6e38f665bf221449@mail.gmail.com> <741612210908070231j409cb0ecwaf1cb694d860a8f9@mail.gmail.com> <3c6288ab0908070329v9aaeec8h74c8da9b5bd72fd7@mail.gmail.com> <741612210908070404m397a9f70u94504adb8cb1ce39@mail.gmail.com> Message-ID: <14ABF7EC-CD5B-49E6-A5CB-110D4404DF0B@gmail.com> Hi Dmitry, I've been using HXT and its XmlPickler class for encoding and decoding between XML <-> Haskell types. It takes a while to wrap your brain around the arrows based API for HXT (something I'm still working on) but it seems to be quite powerful and well maintained. Also, I've written some Template Haskell code to derive instances for the XmlPickler class (so that types can automatically be encoded and decoded as XML. Its not pretty, has bugs, and is far from perfect but I can send that to you if you'd like a way to get stared. Max On Aug 7, 2009, at 7:04 PM, Dmitry Olshansky wrote: > Well, great thanks for interesting links. > > But definitely at first I need a time to try to understand what > Generic Haskell and EMGM are. > > Does it stronger than Template Haskell? Could it be explained > briefly and simplistic for first impression? Could it be compared > with SYB or TH? > > Would it be applied to realisation of translation or to target > Haskell code? > > Regards, > Dmitry > > > 2009/8/7 Sean Leather > > On Fri, Aug 7, 2009 at 12:05, John Lask wrote: > the paper: > > Scripting XML with Generic Haskell > Frank Atanassow, Dave Clarke and Johan Jeuring > October 14, 2003 > > describes a translation from XML Schema to Haskell data types (like > dtd2haskell) in generic haskell, I believe that the code for the > tool described may also be available, how hard it would be to > migrate over to vanilla haskell+generics is another question.... > > It looks like this almost might work in EMGM. They use a Label in > addition to all the other representation structure elements. EMGM > doesn't have a Label, but it might be useful to add it... > > With any needed changes such as the Label done, migrating this > Generic Haskell code to EMGM would not be difficult. > > Sean > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From dons at galois.com Sat Aug 8 03:47:23 2009 From: dons at galois.com (Don Stewart) Date: Sat Aug 8 03:30:34 2009 Subject: [Haskell-cafe] Re: What would be required to make a LLVM backend for GHC In-Reply-To: <31423307-836F-49B2-ACC0-2A03406A8FA9@gmail.com> References: <31423307-836F-49B2-ACC0-2A03406A8FA9@gmail.com> Message-ID: <20090808074723.GA8898@whirlpool.galois.com> axman6: > Hi all, > > I've been talking to one of the LLVM developers, who's working on an > operating system called AuroraUX, which, among other things, is trying > to use LLVM as much as possible in the system (using clang as the > default compiler, compiler-rt [libgcc replacement from the LLVM team], > etc.). > > He would like to know exactly what would need to be implemented in LLVM > to allow ghc to be ported to LLVM, and he would do his best to get these > features implemented. I know the LLVM guys are quite open to > suggestions, and want to get people using it as much as possible, so if > we can let them know what we need, hopefully they can help make life > easier for us. There's a project underway at UNSW to add an LLVM backend to GHC. You should talk to them :-) -- Don From andrewcoppin at btinternet.com Sat Aug 8 07:29:02 2009 From: andrewcoppin at btinternet.com (Andrew Coppin) Date: Sat Aug 8 07:09:41 2009 Subject: [Haskell-cafe] Examples Message-ID: <4A7D617E.9010103@btinternet.com> As some of you may remember, I recently released a couple of packages on Hackage. I'd like to also release some example programs using these packages, but I'm not sure of the best way to do this. Do I make the example programs part of the package itself? Do I release a seperate package which just contains the example code? Something else entirely? What's the recommendation here? From psarge+haskell at gmail.com Sat Aug 8 08:55:49 2009 From: psarge+haskell at gmail.com (Paul Sargent) Date: Sat Aug 8 08:36:27 2009 Subject: [Haskell-cafe] Complex numbers and (**) In-Reply-To: <8964FD69-1DA5-4A1D-A32D-38C6F28B27A5@gmail.com> References: <8964FD69-1DA5-4A1D-A32D-38C6F28B27A5@gmail.com> Message-ID: <68aed4c30908080555l5bb99b5erf60b1e45686f2252@mail.gmail.com> Hi, First post to the cafe, so "Hello everybody!". Hope this is reasonable subject matter and not too long. I've been working on some algorithms that involved taking the n-th root of complex numbers. In my code I've implemented this as raising the complex number ('z') to 1/n using the (**) operator. Obviously, there are n roots, but I only need one of them so this is fine. Q1) Have I missed a method that's a little less general than 'raising to a Complex'? We have integer powers, but not integer roots? All seems to work fine, except I have a little wrapper function to prefer real roots of real numbers, until I started seeing NaNs appearing. This happened when I tried to take the root of 0+0i. In fact raising 0+0i to any power with (**) causes NaNs to appear. (^) and (^^) have no problem, assuming the calculation is one that can be represented with those operators. Neither is there a problem when the values being raised are not in complex form. Prelude Data.Complex> let xs = [0.0 :+ 0.0, 1.0 :+ 0.0, 2.0 :+ 0.0, 3.0 :+ 0.0] Prelude Data.Complex> [x ^ 2 | x <- xs] [0.0 :+ 0.0,1.0 :+ 0.0,4.0 :+ 0.0,9.0 :+ 0.0] Prelude Data.Complex> [x ^^ 2 | x <- xs] [0.0 :+ 0.0,1.0 :+ 0.0,4.0 :+ 0.0,9.0 :+ 0.0] Prelude Data.Complex> [x ** 2 | x <- xs] [NaN :+ NaN,1.0 :+ 0.0,4.0 :+ 0.0,9.000000000000002 :+ 0.0] Prelude Data.Complex> let xs = [0.0,1.0,2.0,3.0] Prelude Data.Complex> [x ** 2 | x <- xs] [0.0,1.0,4.0,9.0] Digging deeper I've discovered this is because Complex inherits it's definition of (**) as "x ** y = exp (log x * y)". Well... the log of 0+0i is -Inf+0i. Multiply this by a real number in complex form and you end up with -Infinity * 0.0 as one of the terms. According to the IEEE floating point spec, this is NaN. That NaN propagates through exp, and you end up with NaN :+ NaN as the result. Q2) Do people agree this is a bug in the definition of Data.Complex? Seems like the thing to do to fix this is have an instance of (**) for Data.Complex that special cases (0 :+ 0) ** _ to always return (0 :+ 0). An alternative would be to use the underlying non-complex (**) operator for arguments with no imaginary parts. One downside is that this would change the output of Complex (**) so that raising a real argument to a real power always produced a real result (which is actually what I want, but may not be what others expect / have got used to) Q3) Do people agree with these options? Any opinions? How would I submit a patch? I did send a mail to the glasgow-haskell-bugs list, but it doesn't appear to shown up in the archives, so I assume it didn't make it. It also didn't seem quite the right place as this is in the libraries. Apologies if anybody reading this is getting deja-vu. Paul -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090808/d65950ba/attachment.html From lennart at augustsson.net Sat Aug 8 11:45:35 2009 From: lennart at augustsson.net (Lennart Augustsson) Date: Sat Aug 8 11:26:12 2009 Subject: [Haskell-cafe] Complex numbers and (**) In-Reply-To: <68aed4c30908080555l5bb99b5erf60b1e45686f2252@mail.gmail.com> References: <8964FD69-1DA5-4A1D-A32D-38C6F28B27A5@gmail.com> <68aed4c30908080555l5bb99b5erf60b1e45686f2252@mail.gmail.com> Message-ID: A2: Yes, this seem unfortunate, so perhaps a different definition for Complex is warranted. Or maybe the default implementation for (**) should be changed so that 0**x is 0, except if x is 0 (in which case I think it should be undefined). -- Lennart On Sat, Aug 8, 2009 at 2:55 PM, Paul Sargent wrote: > Hi, > > First post to the cafe, so "Hello everybody!". > Hope this is reasonable subject matter and not too long. > > I've been working on some algorithms that involved taking the n-th root of > complex numbers. In my code I've implemented this as raising the complex > number ('z') to 1/n using the (**) operator. Obviously, there are n roots, > but I only need one of them so this is fine. > > Q1) Have I missed a method that's a little less general than 'raising to a > Complex'? We have integer powers, but not integer roots? > > All seems to work fine, except I have a little wrapper function to prefer > real roots of real numbers, until I started seeing NaNs appearing. This > happened when I tried to take the root of 0+0i. In fact raising 0+0i to any > power with (**) causes NaNs to appear. (^) and (^^) have no problem, > assuming the calculation is one that can be represented with those > operators. Neither is there a problem when the values being raised are not > in complex form. > > Prelude Data.Complex> let xs = [0.0 :+ 0.0, 1.0 :+ 0.0, 2.0 :+ 0.0, 3.0 :+ > 0.0] > > Prelude Data.Complex> [x ^ 2 | x <- xs] > [0.0 :+ 0.0,1.0 :+ 0.0,4.0 :+ 0.0,9.0 :+ 0.0] > > Prelude Data.Complex> [x ^^ 2 | x <- xs] > [0.0 :+ 0.0,1.0 :+ 0.0,4.0 :+ 0.0,9.0 :+ 0.0] > > Prelude Data.Complex> [x ** 2 | x <- xs] > [NaN :+ NaN,1.0 :+ 0.0,4.0 :+ 0.0,9.000000000000002 :+ 0.0] > > Prelude Data.Complex> let xs = [0.0,1.0,2.0,3.0] > Prelude Data.Complex> [x ** 2 | x <- xs] > [0.0,1.0,4.0,9.0] > > Digging deeper I've discovered this is because Complex inherits it's > definition of (**) as "x ** y = exp (log x * y)". Well... the log of 0+0i is > -Inf+0i. Multiply this by a real number in complex form and you end up with > -Infinity * 0.0 as one of the terms. According to the IEEE floating point > spec, this is NaN. That NaN propagates through exp, and you end up with NaN > :+ NaN ?as the result. > > Q2) Do people agree this is a bug in the definition of Data.Complex? > > Seems like the thing to do to fix this is have an instance of (**) for > Data.Complex that special cases (0 :+ 0) ** _ to always return (0 :+ 0). An > alternative would be to use the underlying non-complex (**) operator for > arguments with no imaginary parts. One downside is that this would change > the output of Complex (**) so that raising a real argument to a real power > always produced a real result (which is actually what I want, but may not be > what others expect / have got used to) > > Q3) Do people agree with these options? Any opinions? How would I submit a > patch? > > I did send a mail to the glasgow-haskell-bugs list, but it doesn't appear to > shown up in the archives, so I assume it didn't make it. It also didn't seem > quite the right place as this is in the libraries. Apologies if anybody > reading this is getting deja-vu. > > Paul > > > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > From byorgey at seas.upenn.edu Sat Aug 8 12:00:31 2009 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Sat Aug 8 11:41:08 2009 Subject: [Haskell-cafe] Haskell Weekly News: Issue 127 - August 8, 2009 Message-ID: <20090808160031.GA23392@seas.upenn.edu> --------------------------------------------------------------------------- Haskell Weekly News http://sequence.complete.org/hwn/20090808 Issue 127 - August 08, 2009 --------------------------------------------------------------------------- Welcome to issue 127 of HWN, a newsletter covering developments in the [1]Haskell community. Apologies for the long hiatus, mostly due to organizing Hac phi (which was a [2]great success!). And I'm now going on vacation for a couple weeks and may have limited Internet access, so don't hold your breath for an issue of the HWN next week either... anyway, a ton of interesting stuff has happened over the past three weeks (of course), including a bunch of [3]discussion on the Haskell-prime mailing list, a number of package releases, Haskell Platform discussion, and more. Announcements bindings-posix 0.0.2. Mauricio [4]announced [5]bindings-posix, a low level binding to Posix. It makes use of facilities and design from the [6]bindings-common package to map the [7]standard Posix library. bindings-common 0.2.1. Mauricio [8]announced a new release of [9]bindings-common, which offers basic code that provides a common design standard and common utilities for writing modules providing low-level foreign library bindings. The major new feature of this release is the availability of hsc2hs custom macros, and a corresponding reduction in code size. Dyre - Dynamic Program Recompilation (Xmonad-style configuration). Will Donnelly [10]announced the release of [11]dyre, a library for xmonad-style program recompilation. It is based in spirit after the HConf library written by the Yi project, but with a focus on simple integration, state persistence as an optional feature, and Windows support. nntp 0.0.2. Maciej Piechotka [12]announced the release of [13]nntp, a library to connect to nntp (i.e. mainly USENET) servers. This version represents a complete rewrite from version 0.0.1, including a new NntpT monad and basic support for XHDR. GLUT 2.2.0.0. Sven Panne [14]announced a new version of the [15]GLUT package, which depends on the new OpenGL, StateVar and Tensor packages, but is otherwise unchanged except for a new demo. OpenGL 2.3.0.0. Sven Panne [16]announced a new version of the [17]OpenGL package, which is now only a convenience layer upon the [18]OpenGLRaw and [19]GLURaw packages, written in in pure Haskell without the FFI. The latter two packages load the native libraries dynamically and do not rely on any C headers, making it possible to build all OpenGL-related packages even on machines without any installed native OpenGL support. yices 0.0.0.1. Ki Yung Ahn [20]announced [21]yices, a Haskell interface to the [22]Yices SMT solver. ALUT 2.2.0.0. Sven Panne [23]announced a new version of the ALUT package, which now depends on the highly portable [24]StateVar package instead of [25]OpenGL. OpenAL 1.4.0.0. Sven Panne [26]announced a new version of the [27]OpenAL package, which now depends on the highly portable [28]StateVar, [29]ObjectName and [30]Tensor packages, instead of [31]OpenGL. Tensor 1.0.0.1. Sven Panne [32]announced the [33]Tensor package, yet another spin-off of the OpenGL package, containing a few tensor data types and their instances for some basic type classes. darcs 2.3.0. Petr Rockai [34]announced a new stable release of [35]darcs, version 2.3.0. This version includes a number of improvements and bugfixes over the previous stable release, 2.2. Moreover, work has been done to improve performance of "darcs whatsnew" for large repositories. uacpid-0.0.4. Dino Morelli [36]announced the release of [37]uacpid, a daemon designed to be run in userspace that will monitor the local system's acpid socket for hardware events. These events can then be acted upon by handlers with access to the user's environment. Korean translation of "Programming in Haskell". Ki Yung Ahn [38]announced a new [39]non-English book on Haskell, published on July 24. TABI 0.1: a typeful tagged cross-language calling convention. Bulat Ziganshin [40]announced a preliminary release of [41]TABI, a library providing a typeful, tagged cross-language calling convention. Typeful/Text/HTMLs (for AngloHaskell/for scrap?). Jon Fairbairn [42]announced an [43]HTML library which guarantees standards compliance via types, even down to the nesting restrictions. yst 0.2.1. John MacFarlane [44]announced the release of [45]yst, which generates static websites from YAML or CSV data files and StringTemplates. This approach combines the speed, security, and ease of deployment of a static website with the flexibility and maintainability of a dynamic site that separates presentation and data. The Haskell Platform 2009.2.0.2. Don Stewart [46]announced the third release (2009.2.0.2) of the [47]Haskell Platform, a single, standard Haskell distribution for everyone. atom 0.1.0. Tom Hawkins [48]announced the 0.1.0 release of [49]Atom, a Haskell DSL for hard realtime applications. This release includes support for assertions and functional coverage to aid simulation and testing. tkhs-0.1.* Presentation Utility. Yusaku Hashimoto [50]announced the release of [51]tkhs-0.1.*, a simple presentation utility. If you are thinking PowerPoint is overkill for your presentation, Tkhs may fit the purpose. RFC: Unicode support in Alex. Jean-Philippe Bernardy [52]requested feedback on his modifications to the [53]Alex lexer generator to support Unicode. The prototype is [54]available on github. The Monad.Reader - Issue 14. Wouter Swierstra [55]announced Issue 14 of [56]The Monad.Reader. This issue contains three articles "Fun with Morse Code" by Heinrich Apfelmus, "Hieroglyph 2: Purely Functional Information Graphics Revisited" by Jefferson Heard, and "Lloyd Allison's Corecursive Queues: Why Continuations Matter" by Leon P Smith. TBC: Testing By Convention. Peter Gammie [57]announced the release of [58]TBC, a test harness which has features complementary to existing harnesses: it attempts to compile and run all tests, even if some do not compile or run; and tests following conventions require a lot less boilerplate. Elerea version 1.x.x. Patai Gergely [59]announced an update of his FRP library, [60]Elerea, along with some updates to the accompanying [61]example programs. The interface was changed into a monadic-applicative hybrid that distinguishes stateful and stateless combinators for safety reasons: most importantly, the latcher was removed due to various practical issues, and it is replaced by much better behaved stateless higher-order constructs. The library is now capable of handling arbitrary higher-order signals. haskell-src-exts-1.1.0. Niklas Broberg [62]announced the release of [63]haskell-src-exts-1.1.0, bringing you tuple sections, comments, and a few bug fixes. graphviz-2999.1.0.2. Ivan Lazar Miljenovic [64]announced a bug fix release of the [65]graphviz package, which fixes a bug spotted by Srihari Ramanathan where the Dot representation of Color values were double-quoted when they shouldn't have been. Leksah 0.6. Hamish Mackenzie [66]announced the 0.6 release of [67]Leksah, a Haskell IDE. New features include integrated GHCi based debugging, multi-window support, improved layout control, regular expression find and replace, ability to grep files in the current package, and improved Mac OS X integration. Semantic Web. Vasili I. Galchin [68]announced the [69]cabalisation of [70]Swish-0.2.1 (Semantic Web Inference uSing Haskell), a semantic web toolkit designed and implemented by Graham Klyne. The package now builds on GHC 6.8.2, with more improvements planned. graphviz-2999.1.0.1. Ivan Lazar Miljenovic [71]announced a bug-fix release to fix the problems with Either-based Attributes in the previous release (2999.0.0.0), spotted mainly by Zsolt Dollenstein. cautious-file 0.1.1: Ways to write a file cautiously, to avoid data loss. Robin Green [72]announced the first public release of [73]cautious-file, which provides a writeFile function that has several advantages over Prelude.writeFile: it uses the recommended way of writing a file on POSIX, so as not to expose the user to the risk of data loss after a crash or power failure; and it uses a temporary, randomly-named file for writing and only overwrites an existing file once the write is complete. Google Summer of Code Progress updates from participants in the 2008 [74]Google Summer of Code. Haddock improvements! Isaac Dupree has [75]cleaned up most of the loose edges on cross-package documentation, and has [76]begun moving comment parsing from GHC to Haddock. EclipseFP. Thomas Ten Cate is [77]finally happy with his refactorings of the Scion client, and has done [78]quite a bit of cleanup of compilation warnings and unit tests. Improving the Haskell space profiling experience. Gergely Patai posted about [79]segfaults with gtk2hs, and using Cairo instead of OpenGL for rendering, and has some [80]nice screenshots of the profiling client. haskell-src-exts -> haskell-src. Niklas Broberg has [81]started working on comment support. Fast darcs. Petr Rockai has made [82]much [83]progress, released [84]darcs 2.3.0, and posted a [85]discussion on patch formats. Discussion Adding binary to the Haskell Platform. Don Stewart began a [86]discussion thread on the possibility of adding the [87]binary package to the [88]Haskell Platform. Thinking about what's missing in our library coverage. Don Stewart [89]asked how to identify packages that ought to be added to the [90]Haskell Platform, and areas of functionality that are missing. Proposal: TypeDirectedNameResolution. Johannes Waldmann began a [91]discussion on a proposed language extension, [92]type-directed name resolution. Implicit concatenation in list comprehensions. Max Bolingbroke started a [93]discussion on a proposed syntax extension to allow multiple expressions on the left-hand side of a list comprehension, resulting in implicit concatenation. Jobs Postdoc and Ph.D. position on 3gERP-project at DIKU. Fritz Henglein [94]announced the availability of a postdoc position and a Ph.D. scholarship at the Department of Computer Science, University of Copenhagen (DIKU) within 3d generation enterprise resource planning systems (3gERP), a collaborative strategic research project with partners at DIKU (computer science), Copenhagen Business School (CBS, information systems) and Microsoft Development Center Copenhagen (MDCC, enterprise systems). Blog noise [95]Haskell news from the [96]blogosphere. Blog posts from people new to the Haskell community are marked with >>>, be sure to welcome them! * >>> Joel Ray King: [97]Starting out with Haskell. * JP Moresmau: [98]Yoohoo: mazes of monad is kind of popular!. * Don Stewart (dons): [99]Haskell Package Popularity Rankings : August 2009. * David Amos: [100]Where we've been, and where we're going. * >>> Michael Feathers: [101]Functional Refactoring and "You Can't Get There From Here". * Magnus Therning: [102]Updating GHC on Arch. * Tom Schrijvers: [103]Monadic Constraint Programming with Gecode. * Luke Plant: [104]Haskell string support. * Don Stewart (dons): [105]The Haskell Platform 2009.2.0.2. * Gergely Patai: [106]More profiling goodies. * Don Stewart (dons): [107]Heuristics for Blessing Software Packages. * David Amos: [108]How to count the number of positions of Rubik's cube. * Edward Kmett: [109]Slides from Hac Phi: "All About Monoids". * Brent Yorgey: [110]Primitive species and species operations, part II. * Magnus Therning: [111]Making a choice from a list in Haskell, Vty (part 4). * Brent Yorgey: [112]Primitive species and species operations. * Thomas ten Cate: [113]The Green Bar. * Petr Rockai: [114]soc progress 10. * Brent Yorgey: [115]Hac phi roundup. * Brent Yorgey: [116]More from Hac phi. * Roman Cheplyaka: [117]CCC #5: Trial. * Eric Kow: [118]some ideas for practical QuickCheck. * Nathan Sanders: [119]Profiling in Haskell, part 2. * >>> Bj?rn Winckler: [120]Inverse functions in Haskell. * >>> Alex Handy: [121]Everyone's talking about Haskell. * Niklas Broberg: [122]Starting on the comment support . * Gergely Patai: [123]Pango font rendering on an OpenGL canvas . * Brent Yorgey: [124]Hac phi day 2. * Petr Rockai: [125]Patch Formats. * Brent Yorgey: [126]Introducing Math.Combinatorics.Species!. * Magnus Therning: [127]Making a choice from a list in Haskell, Vty (part 3). * Michael Snoyman: [128]Embedding files in a binary. * Darcs: [129]darcs 2.3.0 is released!. * Petr Rockai: [130]Darcs 2.3.0. * >>> Ionu?: [131]Haskell's prefix and infix notations. * >>> Ionu?: [132]The minus operator in Haskell. * >>> Ken Jenkins: [133]Learning Haskell (Part 2). * James Iry: [134]Void vs Unit. * Justin Grant: [135]Generating pi in Haskell. * Petr Rockai: [136]soc progress 9. * >>> Ken Jenkins: [137]Learning Haskell (Part 1). * Isaac Dupree: [138]Next Project, Move doc-parsing to from GHC to Haddock. * Roman Cheplyaka: [139]Schr??dinger's cat. * Magnus Therning: [140]Ping server in Haskell (not that kind of ping, and rather silly). * >>> hydo: [141]Haskell and Hack fanboyism.. * Chris Smith: [142]Calculating Multiplicative Inverses in Modular Arithmetic. * David Amos: [143]Faster graph symmetries using distance partitions. * Isaac Dupree: [144]more cross-package docs details. * Nick Cameron: [145]ECOOP Day 3 - Day 1 of the main conference . * Ryan Lothian: [146]Haskell Graph Plotter - Part 1. * >>> Matias Giovannini: [147]Monadic Golf. * >>> Stephan Mann: [148]Cool Haskell Function. * >>> n0ne: [149]How do you use Haskell at work?. * Adam Blinkinsop: [150]Mastermind Solver in Haskell. * Ivan Uemlianin: [151]decorate-sort-undecorate in Haskell -- Advanced!. * Don Stewart: [152]Interview for SDTimes: "Everyone's talking about Haskell". * Don Stewart: [153]Haskell Platform Progress Report. * David Amos: [154]Strong generating sets for graph symmetries. * Chris Smith: [155]The Magic of Type Classes. * Twan van Laarhoven: [156]CPS based functional references . * Thomas ten Cate: [157]More robust Scion client code. * Paul Butler: [158]N-Queens in a Tweet. Quotes of the Week * dons: i heard there were webservers written in languages other than haskell * yrlnry2: #haskell is the most functional channel I've ever seen. * JonFairbairn: And one of the tests failed because Bolivia is now the Plurinational State of Bolivia, so I've add a patch for that. I've seen politics get in the way of programming, but I've never had a bug caused by /international/ politics before. * Adamant: ah, monads. the pons asinorum of Haskell. * QP: i drink i'm two thunk for this... i'm seeing (Double, Double) * benmachine: wait why am I giving advice I don't know anything * jfredett: @yow ! YOW! I seem to SEE a SHAPR asking for FUNNY ZIPPY QUOTES, TOO bad I left them in my OTHER PANTS * Berengal: Anyone doubting the immutable value philosophy needs to try vacuum * badsheepy: [in response to a spammer] my word, i feel immediately compelled to medicate myself. * monochrom: Haskell has solved programming. All that can be said programming is already said in tutorials and the haskell wiki. That is why we drift to meta topics. * kalven: i thought there were like 10 haskell jobs in the world, all in the "let's replace excel sheets with something else" industry there are at least 20. * BMeph: okmij.net, conal.net, comonad.reader, and sigfpe.blogspot.com; the four horsemen of the Haskell Apocalypse. * jaredj: [on parsec] i thought i got it but i need to 'try' again * gwern: *ponders Haskell nerdcore: 'I'm all about exact math, yo; I eat CReal for breakfast'* * Baughn: remember that comments take up space in compiled Haskell programs, and furthermore they take up processing time if execution passes through them. For these reasons, keep comments to a minimum, and never put comments inside of optimized Haskell code. Ideally all of your comments will lie outside of the path of execution. * gbacon: okay, I just tried to type Monday, but it came out Monady. Assimilation complete. * BenLippmeier: Are Haskell and OCaml destined to be The Velvet Underground of programming languages, where hardly anyone has heard them, but everyone who does forms a band? About the Haskell Weekly News New editions are posted to [159]the Haskell mailing list as well as to [160]the Haskell Sequence and [161]Planet Haskell. [162]RSS is also available, and headlines appear on [163]haskell.org. To help create new editions of this newsletter, please see the information on [164]how to contribute. Send stories to byorgey at cis dot upenn dot edu. The darcs repository is available at darcs get [165]http://code.haskell.org/~byorgey/code/hwn/ . References 1. http://haskell.org/ 2. http://byorgey.wordpress.com/2009/07/29/hac-phi-roundup/ 3. http://news.gmane.org/gmane.comp.lang.haskell.prime 4. http://article.gmane.org/gmane.comp.lang.haskell.libraries/11611 5. http://hackage.haskell.org/package/bindings-posix 6. http://hackage.haskell.org/package/bindings%2Dcommon 7. http://hackage.haskell.org/package/bindings%2Dcommon 8. http://article.gmane.org/gmane.comp.lang.haskell.libraries/11610 9. http://hackage.haskell.org/package/bindings%2Dcommon 10. http://article.gmane.org/gmane.comp.lang.haskell.general/17425 11. http://hackage.haskell.org/package/dyre 12. http://article.gmane.org/gmane.comp.lang.haskell.general/17407 13. http://hackage.haskell.org/package/nntp 14. http://article.gmane.org/gmane.comp.lang.haskell.general/17406 15. http://hackage.haskell.org/package/GLUT 16. http://article.gmane.org/gmane.comp.lang.haskell.general/17405 17. http://hackage.haskell.org/package/OpenGL 18. http://hackage.haskell.org/package/OpenGLRaw 19. http://hackage.haskell.org/package/GLURaw 20. http://article.gmane.org/gmane.comp.lang.haskell.general/17397 21. http://hackage.haskell.org/package/yices 22. http://yices.csl.sri.com/ 23. http://article.gmane.org/gmane.comp.lang.haskell.general/17395 24. http://hackage.haskell.org/package/StateVar 25. http://hackage.haskell.org/package/OpenGL 26. http://article.gmane.org/gmane.comp.lang.haskell.general/17394 27. http://hackage.haskell.org/package/OpenAL 28. http://hackage.haskell.org/package/StateVar 29. http://hackage.haskell.org/package/ObjectName 30. http://hackage.haskell.org/package/Tensor 31. http://hackage.haskell.org/package/OpenGL 32. http://article.gmane.org/gmane.comp.lang.haskell.general/17393 33. http://hackage.haskell.org/package/Tensor 34. http://article.gmane.org/gmane.comp.lang.haskell.general/17391 35. http://darcs.net/ 36. http://article.gmane.org/gmane.comp.lang.haskell.general/17388 37. http://hackage.haskell.org/package/uacpid 38. http://article.gmane.org/gmane.comp.lang.haskell.general/17386 39. http://hackage.haskell.org/package/uacpid 40. http://article.gmane.org/gmane.comp.lang.haskell.general/17384 41. http://tabi.googlecode.com/ 42. http://article.gmane.org/gmane.comp.lang.haskell.cafe/61980 43. http://homepage.ntlworld.com/jon.fairbairn/Typeful/Text/HTMLs/ 44. http://article.gmane.org/gmane.comp.lang.haskell.cafe/61915 45. http://hackage.haskell.org/package/yst 46. http://article.gmane.org/gmane.comp.lang.haskell.cafe/61874 47. http://hackage.haskell.org/platform/ 48. http://article.gmane.org/gmane.comp.lang.haskell.cafe/61849 49. http://hackage.haskell.org/package/atom 50. http://article.gmane.org/gmane.comp.lang.haskell.cafe/61845 51. http://hackage.haskell.org/package/tkhs 52. http://article.gmane.org/gmane.comp.lang.haskell.cafe/61809 53. http://hackage.haskell.org/package/alex 54. git://github.com/jyp/Alex.git 55. http://article.gmane.org/gmane.comp.lang.haskell.cafe/61800 56. http://themonadreader.wordpress.com/ 57. http://article.gmane.org/gmane.comp.lang.haskell.cafe/61707 58. http://hackage.haskell.org/package/TBC 59. http://article.gmane.org/gmane.comp.lang.haskell.cafe/61706 60. http://hackage.haskell.org/package/elerea 61. http://hackage.haskell.org/package/elerea-examples 62. http://article.gmane.org/gmane.comp.lang.haskell.cafe/61703 63. http://hackage.haskell.org/package/haskell%2Dsrc%2Dexts 64. http://article.gmane.org/gmane.comp.lang.haskell.cafe/61690 65. http://hackage.haskell.org/package/graphviz 66. http://article.gmane.org/gmane.comp.lang.haskell.cafe/61663 67. http://leksah.org/ 68. http://article.gmane.org/gmane.comp.lang.haskell.cafe/61613 69. http://hackage.haskell.org/package/swish 70. http://www.ninebynine.org/Software/swish-0.2.1.html 71. http://article.gmane.org/gmane.comp.lang.haskell.cafe/61545 72. http://article.gmane.org/gmane.comp.lang.haskell.cafe/61523 73. http://hackage.haskell.org/package/cautious-file 74. http://hackage.haskell.org/trac/summer-of-code/wiki/SoC2008 75. http://haddock2009.wordpress.com/2009/07/20/more-cross-package-docs-details/ 76. http://haddock2009.wordpress.com/2009/07/21/next-project-move-doc-parsing-to-from-ghc-to-haddock/ 77. http://eclipsefp.wordpress.com/2009/07/19/more-robust-scion-client-code/ 78. http://eclipsefp.wordpress.com/2009/07/30/the-green-bar/ 79. http://just-bottom.blogspot.com/2009/07/using-pango-fonts-on-opengl-canvas.html 80. http://just-bottom.blogspot.com/2009/08/more-profiling-goodies.html 81. http://nibrofun.blogspot.com/2009/07/starting-on-comment-support.html 82. http://web.mornfall.net/blog/soc_progress_9.html 83. http://web.mornfall.net/blog/soc_progress_10.html 84. http://web.mornfall.net/blog/darcs_2.3.0.html 85. http://web.mornfall.net/blog/patch_formats.html 86. http://thread.gmane.org/gmane.comp.lang.haskell.libraries/11658 87. http://hackage.haskell.org/package/binary 88. http://www.haskell.org/haskellwiki/Haskell_Platform 89. http://thread.gmane.org/gmane.comp.lang.haskell.libraries/11625 90. http://www.haskell.org/haskellwiki/Haskell_Platform 91. http://thread.gmane.org/gmane.comp.lang.haskell.cafe/61723 92. http://hackage.haskell.org/trac/haskell-prime/wiki/TypeDirectedNameResolution 93. http://thread.gmane.org/gmane.comp.lang.haskell.cafe/61514 94. http://article.gmane.org/gmane.comp.lang.haskell.general/17431 95. http://planet.haskell.org/ 96. http://haskell.org/haskellwiki/Blog_articles 97. http://joelrayking.wordpress.com/2009/08/08/starting-out-with-haskell/ 98. http://jpmoresmau.blogspot.com/2009/08/yoohoo-mazes-of-monad-is-kind-of.html 99. http://donsbot.wordpress.com/2009/08/06/haskell-package-popularity-rankings-august-2009/ 100. http://haskellformaths.blogspot.com/2009/08/where-weve-been-and-where-were-going.html 101. http://blog.objectmentor.com/articles/2009/08/05/functional-refactoring-and-you-cant-get-there-from-here 102. http://therning.org/magnus/archives/713 103. http://tomschrijvers.blogspot.com/2009/08/monadic-constraint-programming-with.html 104. http://lukeplant.me.uk/blog.php?id=1107301701 105. http://donsbot.wordpress.com/2009/08/03/the-haskell-platform-2009-2-0-2/ 106. http://just-bottom.blogspot.com/2009/08/more-profiling-goodies.html 107. http://donsbot.wordpress.com/2009/08/01/heuristics-for-blessing-software-packages/ 108. http://haskellformaths.blogspot.com/2009/08/how-to-count-number-of-positions-of.html 109. http://comonad.com/reader/2009/hac-phi-slides/ 110. http://byorgey.wordpress.com/2009/07/31/primitive-species-and-species-operations-part-ii/ 111. http://therning.org/magnus/archives/710 112. http://byorgey.wordpress.com/2009/07/30/primitive-species-and-species-operations/ 113. http://eclipsefp.wordpress.com/2009/07/30/the-green-bar/ 114. http://web.mornfall.net/blog/soc_progress_10.html 115. http://byorgey.wordpress.com/2009/07/29/hac-phi-roundup/ 116. http://byorgey.wordpress.com/2009/07/25/more-from-hac-%cf%86/ 117. http://ro-che.blogspot.com/2009/07/ccc-5.html 118. http://koweycode.blogspot.com/2009/07/some-ideas-for-practical-quickcheck.html 119. http://sandersn.com/blog/index.php?title=profiling_in_haskell_part_2 120. http://b4winckler.wordpress.com/2009/07/28/inverse-functions-in-haskell/ 121. http://www.sdtimes.com/blog/post/2009/07/27/Everyonee28099s-talking-about-Haskell.aspx 122. http://nibrofun.blogspot.com/2009/07/starting-on-comment-support.html 123. http://just-bottom.blogspot.com/2009/07/using-pango-fonts-on-opengl-canvas.html 124. http://byorgey.wordpress.com/2009/07/25/hac-%cf%86-day-2/ 125. http://web.mornfall.net/blog/patch_formats.html 126. http://byorgey.wordpress.com/2009/07/24/introducing-math-combinatorics-species/ 127. http://therning.org/magnus/archives/702 128. http://blog.snoyman.com/2009/07/23/embedding-files-in-a-binary/ 129. http://blog.darcs.net/2009/07/darcs-230-is-released.html 130. http://web.mornfall.net/blog/darcs_2.3.0.html 131. http://learninghaskell.wordpress.com/2009/07/23/haskell-prefix-and-infix-notations-for-functions/ 132. http://learninghaskell.wordpress.com/2009/07/23/the-minus-operator-in-haskell/ 133. http://webscript.princeton.edu/~kjenkins/wordpress/2009/07/learning-haskell-part-2/ 134. http://james-iry.blogspot.com/2009/07/void-vs-unit.html 135. http://jng.imagine27.com/articles/2009-07-23-094212_generating_pi_in_haskell.html 136. http://web.mornfall.net/blog/soc_progress_9.html 137. http://webscript.princeton.edu/~kjenkins/wordpress/2009/07/learning-haskell/ 138. http://haddock2009.wordpress.com/2009/07/21/next-project-move-doc-parsing-to-from-ghc-to-haddock/ 139. http://ro-che.blogspot.com/2009/07/schrodingers-cat.html 140. http://therning.org/magnus/archives/698 141. http://www.l2mlogistics.com/2009/07/haskell-and-hack-fanboyism.html 142. http://cdsmith.wordpress.com/2009/07/20/calculating-multiplicative-inverses-in-modular-arithmetic/ 143. http://haskellformaths.blogspot.com/2009/07/faster-graph-symmetries-using-distance.html 144. http://haddock2009.wordpress.com/2009/07/20/more-cross-package-docs-details/ 145. http://featherweightmusings.blogspot.com/2009/07/ecoop-day-3-day-1-of-main-conference.html 146. http://www.ryanlothian.com/articles/haskell-graphplotter 147. http://alaska-kamtchatka.blogspot.com/2009/07/monadic-golf.html 148. http://stephenmann.net/2009/07/17/cool-haskell-function/ 149. http://actuarialprog.wordpress.com/2009/07/13/how-do-you-use-haskell-at-work/ 150. http://adam.blinkinblogs.net/mastermind-solver-in-haskell 151. http://llaisdy.wordpress.com/2009/07/11/decorate-sort-undecorate-in-haskell-advanced/ 152. http://donsbot.wordpress.com/2009/07/27/interview-for-sdtimes-everyone%e2%80%99s-talking-about-haskell/ 153. http://donsbot.wordpress.com/2009/07/26/haskell-platform-progress-report/ 154. http://haskellformaths.blogspot.com/2009/07/strong-generating-sets-for-graph.html 155. http://cdsmith.wordpress.com/2009/07/23/the-magic-of-type-classes/ 156. http://twan.home.fmf.nl/blog/haskell/cps-functional-references.details 157. http://eclipsefp.wordpress.com/2009/07/19/more-robust-scion-client-code/ 158. http://paulbutler.org/archives/n-queens-in-a-tweet/ 159. http://www.haskell.org/mailman/listinfo/haskell 160. http://sequence.complete.org/ 161. http://planet.haskell.org/ 162. http://sequence.complete.org/node/feed 163. http://haskell.org/ 164. http://haskell.org/haskellwiki/HWN 165. http://code.haskell.org/~byorgey/code/hwn/ From lemming at henning-thielemann.de Sat Aug 8 12:23:59 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Sat Aug 8 12:04:38 2009 Subject: [Haskell-cafe] Examples In-Reply-To: <4A7D617E.9010103@btinternet.com> References: <4A7D617E.9010103@btinternet.com> Message-ID: On Sat, 8 Aug 2009, Andrew Coppin wrote: > As some of you may remember, I recently released a couple of packages on > Hackage. I'd like to also release some example programs using these packages, > but I'm not sure of the best way to do this. > > Do I make the example programs part of the package itself? Do I release a > seperate package which just contains the example code? Something else > entirely? What's the recommendation here? Usually I include the example program in the package, but make its compilation conditional using a Cabal flag like buildExamples. This way, you can build the examples explicitly by cabal install package -fbuildExamples but they won't be build when the package is build as dependent package. See for instance: http://code.haskell.org/gnuplot/gnuplot.cabal From lemming at henning-thielemann.de Sat Aug 8 13:17:05 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Sat Aug 8 12:57:45 2009 Subject: [Haskell-cafe] Complex numbers and (**) In-Reply-To: <68aed4c30908080555l5bb99b5erf60b1e45686f2252@mail.gmail.com> References: <8964FD69-1DA5-4A1D-A32D-38C6F28B27A5@gmail.com> <68aed4c30908080555l5bb99b5erf60b1e45686f2252@mail.gmail.com> Message-ID: On Sat, 8 Aug 2009, Paul Sargent wrote: > First post to the cafe, so "Hello everybody!". > Hope this is reasonable subject matter and not too long. > > I've been working on some algorithms that involved taking the n-th root of complex numbers. > In my code I've implemented this as raising the complex number ('z') to 1/n using the (**) > operator. Obviously, there are n roots, but I only need one of them so this is fine. I have written something on that topic: http://haskell.org/haskellwiki/Power_function I think the problem cannot be fully solved, especially not within the Haskell 98 numeric type classes. There is no satisfying implementation of (**) even for Float and Double. From lemming at henning-thielemann.de Sat Aug 8 13:33:20 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Sat Aug 8 13:14:00 2009 Subject: [Haskell-cafe] Hugs faster and more reliable than GHC for large list monad 'do' block In-Reply-To: <20090807023456.GB2894@whirlpool.galois.com> References: <4A7B4441.4040100@imageworks.com> <404396ef0908061426o4a0e2929kfa8bcd9f58313902@mail.gmail.com> <4A7B6653.7090104@imageworks.com> <20090807020250.GA7349@kira.casa> <20090807023456.GB2894@whirlpool.galois.com> Message-ID: On Thu, 6 Aug 2009, Don Stewart wrote: > Someone please file a bug report, > > http://hackage.haskell.org/trac/ghc/newticket?type=bug Done, Don! http://hackage.haskell.org/trac/ghc/ticket/3424 From vanenkj at gmail.com Sat Aug 8 15:03:35 2009 From: vanenkj at gmail.com (John Van Enk) Date: Sat Aug 8 14:44:12 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 Message-ID: Hi List, I've uploaded a first version of EnumMap to hackage. EnumMap is a generalization of IntMap that constrains the key to Enum rather than forcing it to be Int. I have no idea what impact this has on performance, but it still passes all the tests that ship with IntMap. (My guess is that performance will be similar/identical unless I've missed something.) If this package competes in speed (especially with an Int key) with IntMap, I'd expect this could be merged into the containers package as an IntMap replacement. The source comments/copyright/license hasn't been changed since this is a derivative work of the original IntMap package. http://hackage.haskell.org/package/EnumMap Comments/benchmarks/criticism is appreciated. Merging this in with containers eventually would be more appreciated. :) John Van Enk From lemming at henning-thielemann.de Sat Aug 8 16:41:01 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Sat Aug 8 16:21:40 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: References: Message-ID: On Sat, 8 Aug 2009, John Van Enk wrote: > Hi List, > > I've uploaded a first version of EnumMap to hackage. > > EnumMap is a generalization of IntMap that constrains the key to Enum > rather than forcing it to be Int. I have no idea what impact this has > on performance, but it still passes all the tests that ship with > IntMap. (My guess is that performance will be similar/identical unless > I've missed something.) Could that be implemented as wrapper around IntMap? From mwassell at bigpond.net.au Sat Aug 8 17:47:36 2009 From: mwassell at bigpond.net.au (Mark Wassell) Date: Sat Aug 8 17:28:17 2009 Subject: [Haskell-cafe] Using -Nx Option with GHC Message-ID: <4A7DF278.8070703@bigpond.net.au> Hi, I am trying to compile and run my program so that it utilises more than one core on my machine. I have looked at http://haskell.org/haskellwiki/Shootout/Parallel/BinaryTrees and am using parMap at a point in my code. I compile with ghc --make -O2 -threaded and run with the options +RTS -N5 The runtime complains that it doesn't understand the N option. I am running 6.10.4 on Windows XP. Cheers Mark From ndmitchell at gmail.com Sat Aug 8 17:55:01 2009 From: ndmitchell at gmail.com (Neil Mitchell) Date: Sat Aug 8 17:35:38 2009 Subject: [Haskell-cafe] Using -Nx Option with GHC In-Reply-To: <4A7DF278.8070703@bigpond.net.au> References: <4A7DF278.8070703@bigpond.net.au> Message-ID: <404396ef0908081455t62445e7fp46026f5b1f47011d@mail.gmail.com> Hi Mark, > I compile with > > ghc --make -O2 -threaded That should work - try deleting all .o/.obj files and the executable and trying to compile again. Thanks Neil From vanenkj at gmail.com Sat Aug 8 17:58:29 2009 From: vanenkj at gmail.com (John Van Enk) Date: Sat Aug 8 17:39:05 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: References: Message-ID: That's originally how I was thinking about doing it, but I think that requires one to re-implement all the functions available in Data.IntMap as simple wrappers that do the toEnum/fromEnum conversion. I think making it into its own module is a little cleaner. The conversion from EnumMap to IntMap is substantially cleaner than from IntMap to EnumMap: > type IntMap v = EnumMap Int v /jve On Sat, Aug 8, 2009 at 4:41 PM, Henning Thielemann wrote: > > On Sat, 8 Aug 2009, John Van Enk wrote: > >> Hi List, >> >> I've uploaded a first version of EnumMap to hackage. >> >> EnumMap is a generalization of IntMap that constrains the key to Enum >> rather than forcing it to be Int. I have no idea what impact this has >> on performance, but it still passes all the tests that ship with >> IntMap. (My guess is that performance will be similar/identical unless >> I've missed something.) > > Could that be implemented as wrapper around IntMap? > From mwassell at bigpond.net.au Sat Aug 8 18:10:31 2009 From: mwassell at bigpond.net.au (Mark Wassell) Date: Sat Aug 8 17:51:11 2009 Subject: [Haskell-cafe] Using -Nx Option with GHC In-Reply-To: <404396ef0908081455t62445e7fp46026f5b1f47011d@mail.gmail.com> References: <4A7DF278.8070703@bigpond.net.au> <404396ef0908081455t62445e7fp46026f5b1f47011d@mail.gmail.com> Message-ID: <4A7DF7D7.20501@bigpond.net.au> That did it, thanks. Neil Mitchell wrote: > Hi Mark, > > >> I compile with >> >> ghc --make -O2 -threaded >> > > That should work - try deleting all .o/.obj files and the executable > and trying to compile again. > > Thanks > > Neil > > From lemming at henning-thielemann.de Sat Aug 8 18:11:44 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Sat Aug 8 17:53:07 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: References: Message-ID: On Sat, 8 Aug 2009, John Van Enk wrote: > That's originally how I was thinking about doing it, but I think that > requires one to re-implement all the functions available in > Data.IntMap as simple wrappers that do the toEnum/fromEnum conversion. > I think making it into its own module is a little cleaner. The > conversion from EnumMap to IntMap is substantially cleaner than from > IntMap to EnumMap: > >> type IntMap v = EnumMap Int v Can you implement EnumMap in terms of the Enum methods, without many conversions to Int? I mean, if you often convert to Int and back then you could achieve the same on top of IntMap. Generally I prefer the strategy "from simple to complex". I consider Enum to be a "wrapper" around Int. http://haskell.org/haskellwiki/Simple_to_complex From vanenkj at gmail.com Sat Aug 8 19:02:54 2009 From: vanenkj at gmail.com (John Van Enk) Date: Sat Aug 8 18:43:30 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: References: Message-ID: What if we say that Enum a generalization, rather than a wrapper, of Int? If the benchmarks are even, is there a reason to use the more specific structure rather than the general one? I don't know if Enum being "more complex" outweighs the benefits of it being "more general" (if the EnumMap matches IntMap for speed). Thoughts? On Sat, Aug 8, 2009 at 6:11 PM, Henning Thielemann wrote: > > On Sat, 8 Aug 2009, John Van Enk wrote: > >> That's originally how I was thinking about doing it, but I think that >> requires one to re-implement all the functions available in >> Data.IntMap as simple wrappers that do the toEnum/fromEnum conversion. >> I think making it into its own module is a little cleaner. The >> conversion from EnumMap to IntMap is substantially cleaner than from >> IntMap to EnumMap: >> >>> type IntMap v = EnumMap Int v > > Can you implement EnumMap in terms of the Enum methods, without many > conversions to Int? I mean, if you often convert to Int and back then you > could achieve the same on top of IntMap. Generally I prefer the strategy > "from simple to complex". I consider Enum to be a "wrapper" around Int. > ?http://haskell.org/haskellwiki/Simple_to_complex > From thomas.dubuisson at gmail.com Sat Aug 8 19:14:15 2009 From: thomas.dubuisson at gmail.com (Thomas DuBuisson) Date: Sat Aug 8 18:54:51 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: References: Message-ID: <4c44d90b0908081614q5bd6325peeefe2d9319fe6fd@mail.gmail.com> There exists a small but measurable performance hit for at least one test case (using Int as keys, obviously). Perhaps the bias would be the other way if we were comparing EnumMap to an IntMap wrapped with to/from Enum. Thomas -- Using Data.IntMap [tommd@Mavlo Test]$ ghc --make -O2 im.hs [1 of 1] Compiling Main ( im.hs, im.o ) Linking im ... [tommd@Mavlo Test]$ ./im buildMap: 0.625563s lookupMap: 0.176478s [tommd@Mavlo Test]$ ./im buildMap: 0.613668s lookupMap: 0.174151s [tommd@Mavlo Test]$ ./im buildMap: 0.607961s lookupMap: 0.175584s -- Using Data.EnumMap [tommd@Mavlo Test]$ vi im.hs [tommd@Mavlo Test]$ ghc --make -O2 im.hs [1 of 1] Compiling Main ( im.hs, im.o ) Linking im ... [tommd@Mavlo Test]$ ./im buildMap: 0.705458s lookupMap: 0.229307s [tommd@Mavlo Test]$ ./im buildMap: 0.71757s lookupMap: 0.231273s [tommd@Mavlo Test]$ ./im buildMap: 0.685333s lookupMap: 0.23883s Code (sorry, its ugly I know) {-# LANGUAGE BangPatterns #-} module Main where import Data.Time import qualified Data.EnumMap as E type IntMap = E.EnumMap Int -- import qualified Data.IntMap as E -- type IntMap = E.IntMap main = do bench "buildMap" buildMap !e <- buildMap bench "lookupMap" (lookupMap e) bench str func = do start <- getCurrentTime !x <- func finish <- getCurrentTime let diff = diffUTCTime finish start putStrLn $ str ++ ":\t" ++ (show diff) keys = [0..1000000] buildMap :: IO (IntMap Int) buildMap = do return $ go keys keys E.empty where go [] _ !m = m go _ [] !m = m go (k:ks) (e:es) m = go ks es (E.insert k e m) lookupMap m = do check keys m where check [] _ = return () check (k:ks) m = if (E.lookup k m /= Just k) then error "blah" else check ks m On Sat, Aug 8, 2009 at 4:02 PM, John Van Enk wrote: > What if we say that Enum a generalization, rather than a wrapper, of Int? > > If the benchmarks are even, is there a reason to use the more specific > structure rather than the general one? I don't know if Enum being > "more complex" outweighs the benefits of it being "more general" (if > the EnumMap matches IntMap for speed). > > Thoughts? > > On Sat, Aug 8, 2009 at 6:11 PM, Henning > Thielemann wrote: >> >> On Sat, 8 Aug 2009, John Van Enk wrote: >> >>> That's originally how I was thinking about doing it, but I think that >>> requires one to re-implement all the functions available in >>> Data.IntMap as simple wrappers that do the toEnum/fromEnum conversion. >>> I think making it into its own module is a little cleaner. The >>> conversion from EnumMap to IntMap is substantially cleaner than from >>> IntMap to EnumMap: >>> >>>> type IntMap v = EnumMap Int v >> >> Can you implement EnumMap in terms of the Enum methods, without many >> conversions to Int? I mean, if you often convert to Int and back then you >> could achieve the same on top of IntMap. Generally I prefer the strategy >> "from simple to complex". I consider Enum to be a "wrapper" around Int. >> ?http://haskell.org/haskellwiki/Simple_to_complex >> > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From felipe.lessa at gmail.com Sat Aug 8 20:30:14 2009 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Sat Aug 8 20:10:54 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: <4c44d90b0908081614q5bd6325peeefe2d9319fe6fd@mail.gmail.com> References: <4c44d90b0908081614q5bd6325peeefe2d9319fe6fd@mail.gmail.com> Message-ID: <20090809003014.GB21821@kira.casa> On Sat, Aug 08, 2009 at 04:14:15PM -0700, Thomas DuBuisson wrote: > There exists a small but measurable performance hit for at least one > test case (using Int as keys, obviously). Perhaps the bias would be > the other way if we were comparing EnumMap to an IntMap wrapped with > to/from Enum. Perhaps some SPECIALIZE pragmas would help here. -- Felipe. From thomas.dubuisson at gmail.com Sat Aug 8 21:02:39 2009 From: thomas.dubuisson at gmail.com (Thomas DuBuisson) Date: Sat Aug 8 20:43:15 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: <20090809003014.GB21821@kira.casa> References: <4c44d90b0908081614q5bd6325peeefe2d9319fe6fd@mail.gmail.com> <20090809003014.GB21821@kira.casa> Message-ID: <4c44d90b0908081802y3bb6a9dbi75a8a8ef8b045ef5@mail.gmail.com> On Sat, Aug 8, 2009 at 5:30 PM, Felipe Lessa wrote: > On Sat, Aug 08, 2009 at 04:14:15PM -0700, Thomas DuBuisson wrote: >> There exists a small but measurable performance hit for at least one >> test case (using Int as keys, obviously). ?Perhaps the bias would be >> the other way if we were comparing EnumMap to an IntMap wrapped with >> to/from Enum. > > Perhaps some SPECIALIZE pragmas would help here. > Actually I tried that by adding SPECIALIZE to insert, insertN and lookup. it seemed to make the insert benchmark competitive but not lookup. Thomas From k2msmith at gmail.com Sat Aug 8 21:24:02 2009 From: k2msmith at gmail.com (Kevin Smith) Date: Sat Aug 8 21:04:37 2009 Subject: [Haskell-cafe] haskell embedded Message-ID: <49dd14e0908081824s3de6fbbal877eab75a0792ed5@mail.gmail.com> Hello, Could someone point me in the the direction of any references for using Haskell as an embedded language in an application. Xmonad seems to come to mind because the configuration files are written using Haskell. Any other information ? Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090808/c04fac60/attachment.html From mwotton at gmail.com Sat Aug 8 21:36:20 2009 From: mwotton at gmail.com (Mark Wotton) Date: Sat Aug 8 21:17:05 2009 Subject: [Haskell-cafe] haskell embedded In-Reply-To: <49dd14e0908081824s3de6fbbal877eab75a0792ed5@mail.gmail.com> References: <49dd14e0908081824s3de6fbbal877eab75a0792ed5@mail.gmail.com> Message-ID: <7D684771-7BF5-4E16-8640-A2668AE33F17@gmail.com> On 09/08/2009, at 11:24 AM, Kevin Smith wrote: > Hello, Could someone point me in the the direction of any > references for using Haskell as an embedded language in an > application. Xmonad seems to come to mind because the configuration > files are written using Haskell. Any other information ? Thanks in > advance. In a Haskell application or a foreign one? Xmonad and lambdbabot are probably not bad places to start looking at methods to load new Haskell at runtime into a Haskell process. If you're looking at embedding it in a C program, http://www.haskell.org/haskellwiki/Calling_Haskell_from_C is helpful, although it does require that you compile everything together at one time. I've been looking into ways to load haskell code into Ruby programs at run-time lately, which you can check out at shimweasel.com if you like. Briefly: dynamic library support doesn't work in ghc 6.10.1 at the moment, although it has at some point worked in GHC HEAD. I'm unable to get HEAD to build with --enable-shared on either Mac or Linux currently, you might have better luck. mark From vanenkj at gmail.com Sat Aug 8 23:29:02 2009 From: vanenkj at gmail.com (John Van Enk) Date: Sat Aug 8 23:09:38 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: <4c44d90b0908081802y3bb6a9dbi75a8a8ef8b045ef5@mail.gmail.com> References: <4c44d90b0908081614q5bd6325peeefe2d9319fe6fd@mail.gmail.com> <20090809003014.GB21821@kira.casa> <4c44d90b0908081802y3bb6a9dbi75a8a8ef8b045ef5@mail.gmail.com> Message-ID: How bad is the lookup compared to normal? On Sat, Aug 8, 2009 at 9:02 PM, Thomas DuBuisson wrote: > On Sat, Aug 8, 2009 at 5:30 PM, Felipe Lessa wrote: >> On Sat, Aug 08, 2009 at 04:14:15PM -0700, Thomas DuBuisson wrote: >>> There exists a small but measurable performance hit for at least one >>> test case (using Int as keys, obviously). ?Perhaps the bias would be >>> the other way if we were comparing EnumMap to an IntMap wrapped with >>> to/from Enum. >> >> Perhaps some SPECIALIZE pragmas would help here. >> > > Actually I tried that by adding SPECIALIZE to insert, insertN and > lookup. ?it seemed to make the insert benchmark competitive but not > lookup. > > Thomas > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From thomas.dubuisson at gmail.com Sun Aug 9 00:08:20 2009 From: thomas.dubuisson at gmail.com (Thomas DuBuisson) Date: Sat Aug 8 23:48:55 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: References: <4c44d90b0908081614q5bd6325peeefe2d9319fe6fd@mail.gmail.com> <20090809003014.GB21821@kira.casa> <4c44d90b0908081802y3bb6a9dbi75a8a8ef8b045ef5@mail.gmail.com> Message-ID: <4c44d90b0908082108t241a8d89u9b0465b78de1df57@mail.gmail.com> Inflating the number of elements in the test, I see: IntMap inserts: 5.3 seconds lookups: 2.0 seconds EnumMap inserts: 6.1 sec (15% slower) lookups: 2.5 sec (25% slower) EnumMap with SPECIALIZE of: {-# SPECIALIZE join :: Prefix -> EnumMap Int a -> Prefix -> EnumMap Int a -> EnumMap Int a #-} {-# SPECIALIZE lookup :: Int -> EnumMap Int a -> Maybe a #-} {-# SPECIALIZE lookupN :: Nat -> EnumMap Int a -> Maybe a #-} {-# SPECIALIZE insert :: Int -> a -> EnumMap Int a -> EnumMap Int a #-} inserts: 5.3 seconds (dead on) lookups: 2.6 seconds (owch!) Additionally specializing the functions used in lookup{,N} doesn't help. I tried inlining (via INLINE) a couple things but that only made performance notably worse. Thomas On Sat, Aug 8, 2009 at 8:29 PM, John Van Enk wrote: > How bad is the lookup compared to normal? > > On Sat, Aug 8, 2009 at 9:02 PM, Thomas > DuBuisson wrote: >> On Sat, Aug 8, 2009 at 5:30 PM, Felipe Lessa wrote: >>> On Sat, Aug 08, 2009 at 04:14:15PM -0700, Thomas DuBuisson wrote: >>>> There exists a small but measurable performance hit for at least one >>>> test case (using Int as keys, obviously). ?Perhaps the bias would be >>>> the other way if we were comparing EnumMap to an IntMap wrapped with >>>> to/from Enum. >>> >>> Perhaps some SPECIALIZE pragmas would help here. >>> >> >> Actually I tried that by adding SPECIALIZE to insert, insertN and >> lookup. ?it seemed to make the insert benchmark competitive but not >> lookup. >> >> Thomas >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> > From bulat.ziganshin at gmail.com Sun Aug 9 00:37:12 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sun Aug 9 00:18:32 2009 Subject: [Haskell-cafe] haskell embedded In-Reply-To: <49dd14e0908081824s3de6fbbal877eab75a0792ed5@mail.gmail.com> References: <49dd14e0908081824s3de6fbbal877eab75a0792ed5@mail.gmail.com> Message-ID: <89603931.20090809083712@gmail.com> Hello Kevin, Sunday, August 9, 2009, 5:24:02 AM, you wrote: > Hello, ?Could someone point me in the the direction of any > references for using Haskell as an embedded language in an hugs documentation notes how to embed Hugs into application -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From psarge+haskell at gmail.com Sun Aug 9 06:33:05 2009 From: psarge+haskell at gmail.com (Paul Sargent) Date: Sun Aug 9 06:13:40 2009 Subject: [Haskell-cafe] Complex numbers and (**) In-Reply-To: References: <8964FD69-1DA5-4A1D-A32D-38C6F28B27A5@gmail.com> <68aed4c30908080555l5bb99b5erf60b1e45686f2252@mail.gmail.com> Message-ID: <68aed4c30908090333w284c0aafj904b282e38e665d0@mail.gmail.com> On Sat, Aug 8, 2009 at 18:17, Henning Thielemann < lemming@henning-thielemann.de> wrote: > > On Sat, 8 Aug 2009, Paul Sargent wrote: > > First post to the cafe, so "Hello everybody!". >> Hope this is reasonable subject matter and not too long. >> >> I've been working on some algorithms that involved taking the n-th root of >> complex numbers. >> In my code I've implemented this as raising the complex number ('z') to >> 1/n using the (**) >> operator. Obviously, there are n roots, but I only need one of them so >> this is fine. >> > > I have written something on that topic: > http://haskell.org/haskellwiki/Power_function > > I think the problem cannot be fully solved, especially not within the > Haskell 98 numeric type classes. There is no satisfying implementation of > (**) even for Float and Double. > Well, I'm an engineer rather than a mathematician, so I'm not 100% sure I followed everything on that page, but you seem to be saying that nth-root can't be done because we're using floating point, and floating point isn't accurate enough to represent 1/n. I basically agree with this, which was why I asked about nth-root functions, but for my uses (**) is good enough as long as complex zero works. (To be honest I'd expect any complex nth-root function to work with the polar form, there-by getting around some of the issues I think you're referring to.) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090809/7c6e1462/attachment.html From lemming at henning-thielemann.de Sun Aug 9 08:10:15 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Sun Aug 9 07:50:52 2009 Subject: [Haskell-cafe] Complex numbers and (**) In-Reply-To: <68aed4c30908090333w284c0aafj904b282e38e665d0@mail.gmail.com> References: <8964FD69-1DA5-4A1D-A32D-38C6F28B27A5@gmail.com> <68aed4c30908080555l5bb99b5erf60b1e45686f2252@mail.gmail.com> <68aed4c30908090333w284c0aafj904b282e38e665d0@mail.gmail.com> Message-ID: On Sun, 9 Aug 2009, Paul Sargent wrote: > Well, I'm an engineer rather than a mathematician, so I'm not 100% sure I followed everything > on that page, but you seem to be saying that nth-root can't be done because we're using > floating point, and floating point isn't accurate enough to represent 1/n. Yes that's one problem. > I basically agree with this, which was why I asked about nth-root functions, but for my uses > (**) is good enough as long as complex zero works. In NumericPrelude we have the 'root' function for that purpose. From vanenkj at gmail.com Sun Aug 9 10:21:40 2009 From: vanenkj at gmail.com (John Van Enk) Date: Sun Aug 9 10:02:14 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: <4c44d90b0908082108t241a8d89u9b0465b78de1df57@mail.gmail.com> References: <4c44d90b0908081614q5bd6325peeefe2d9319fe6fd@mail.gmail.com> <20090809003014.GB21821@kira.casa> <4c44d90b0908081802y3bb6a9dbi75a8a8ef8b045ef5@mail.gmail.com> <4c44d90b0908082108t241a8d89u9b0465b78de1df57@mail.gmail.com> Message-ID: http://github.com/sw17ch/EnumMap/tree/master Perhaps you could patch what I have? :) On Sun, Aug 9, 2009 at 12:08 AM, Thomas DuBuisson wrote: > Inflating the number of elements in the test, I see: > > IntMap > inserts: 5.3 seconds > lookups: 2.0 seconds > > EnumMap > inserts: 6.1 sec (15% slower) > lookups: 2.5 sec (25% slower) > > EnumMap with SPECIALIZE of: > {-# SPECIALIZE join :: Prefix -> EnumMap Int a -> Prefix -> EnumMap > Int a -> EnumMap Int a #-} > {-# SPECIALIZE lookup :: Int -> EnumMap Int a -> Maybe a #-} > {-# SPECIALIZE lookupN :: Nat -> EnumMap Int a -> Maybe a #-} > {-# SPECIALIZE insert :: Int -> a -> EnumMap Int a -> EnumMap Int a #-} > inserts: 5.3 seconds (dead on) > lookups: 2.6 seconds (owch!) > > Additionally specializing the functions used in lookup{,N} doesn't > help. ?I tried inlining (via INLINE) a couple things but that only > made performance notably worse. > > > Thomas > > On Sat, Aug 8, 2009 at 8:29 PM, John Van Enk wrote: >> How bad is the lookup compared to normal? >> >> On Sat, Aug 8, 2009 at 9:02 PM, Thomas >> DuBuisson wrote: >>> On Sat, Aug 8, 2009 at 5:30 PM, Felipe Lessa wrote: >>>> On Sat, Aug 08, 2009 at 04:14:15PM -0700, Thomas DuBuisson wrote: >>>>> There exists a small but measurable performance hit for at least one >>>>> test case (using Int as keys, obviously). ?Perhaps the bias would be >>>>> the other way if we were comparing EnumMap to an IntMap wrapped with >>>>> to/from Enum. >>>> >>>> Perhaps some SPECIALIZE pragmas would help here. >>>> >>> >>> Actually I tried that by adding SPECIALIZE to insert, insertN and >>> lookup. ?it seemed to make the insert benchmark competitive but not >>> lookup. >>> >>> Thomas >>> _______________________________________________ >>> Haskell-Cafe mailing list >>> Haskell-Cafe@haskell.org >>> http://www.haskell.org/mailman/listinfo/haskell-cafe >>> >> > From doaitse at swierstra.net Sun Aug 9 12:23:17 2009 From: doaitse at swierstra.net (S. Doaitse Swierstra) Date: Sun Aug 9 12:03:52 2009 Subject: [Haskell-cafe] Parsec: using two different parser for the same string In-Reply-To: <4A7B28FD.9090603@imageworks.com> References: <9760562b0908051042p97be03tb5f49a0905ef44d5@mail.gmail.com> <4A79FABD.3080000@imageworks.com> <4A7A16CE.4070209@imageworks.com> <9760562b0908060859m5c49d9f0te659c5c75086753e@mail.gmail.com> <4A7B28FD.9090603@imageworks.com> Message-ID: The uu-parsinglib: http://hackage.haskell.org/packages/archive/uu-parsinglib/2.2.0/doc/html/Text-ParserCombinators-UU-Core.html contains a combinator to achieve just this: -- parsing two alternatives and returning both rsults pAscii = pSym ('\000', '\254') pIntList = pParens ((pSym ';') `pListSep` (read <$> pList (pSym ('0', '9')))) parseIntString = pList (pAscii) parseBoth = pPair pIntList parseIntString pPair p q = amb (Left <$> p <|> Right <$> q) The amb combinator tells you that it's parser parameter is ambiguous, and returns you all the possible results. Amazingly it still maintains its online behaviour. The only problem is that if either one of the parsers fails then you will get only a single result. I have added the code above to the Examples.hs contained in the uu- parsinglib (so it will show up in due time when I release a new version) which I am attaching. Just load this file, and call the function main to see what are the results of the different parsers and correction strategies. The only problem is that if either one of the parsers fails you will only get one of the results. If both fail you will get the result which fails latest and if both fail at the same place, the one which fails with the least repair costs. If you really want both results, even if the input is erroneaous, things become more complicated, especially if you want to embed this parser in a larger one, since then we have to check whether both parse the same prefix. If needed I could put some work into this, by making a slightly different version of the amb combinator. Doaitse On 6 aug 2009, at 21:03, Dan Weston wrote: > Paul, > > Arrows (and category theory in general) are interesting, but you > certainly don't need to understand them for this. > The only arrow in this code is the lowly function arrow (->). (&&&) > and (|||) are duals of each other and mean, respectively, "both" and > "either" (though for some bizarre reason, "both" is usually called > "fanout"!) > > This style of pointfree (or "pointless") code is clearer to me > because I don't have a bunch of variable names to invent and have > lying around. > > Anyway, if you prefer, don't import Control.Arrow at all, and just > use: > > -- |Both: Apply two functions to same argument and tuple the results > infixr 3 &&& > (&&&) :: (a -> b) -> (a -> c) -> a -> (b,c) > (f &&& g) x = (f x, g x) > > -- |Either: If argument is Left, apply Left function, else apply > Right function > infixr 2 ||| > (|||) :: (a -> c) -> (b -> c) -> Either a b -> c > (|||) = either > > either is implicitly imported from the Prelude and is defined as: > > -- | Case analysis for the 'Either' type. > -- If the value is @'Left' a@, apply the first function to @a@; > -- if it is @'Right' b@, apply the second function to @b@. > either :: (a -> c) -> (b -> c) -> Either a b -> c > either f _ (Left x) = f x > either _ g (Right y) = g y > > Dan > > Paul Sujkov wrote: >> Hi Dan, >> thank you for the solution. It looks pretty interesting and usable, >> however I'll have to spend some time understanding arrows: I never >> had an opportunity to use them before. Anyway, it looks very close >> to what I actually need, and in any case much less ugly than >> breaking the GenParser encapsulation >> 2009/8/6 Dan Weston > >> >> Of course, since ParsecT s u m is a functor, feel free to use fmap >> instead of parsecMap. Then you don't need to import from >> Text.Parsec.Prim. >> And in hindsight, I might prefer the name (<:>) or cons to (<>) >> for >> the first function, but now I'm just obsessing. :) >> Dan >> Dan Weston wrote: >> I think parsecMap does the job here: >> ----------------------- >> import Text.ParserCombinators.Parsec hiding ((<|>)) >> import Text.Parsec.Prim(parsecMap) >> import Control.Applicative((<|>)) >> import Control.Arrow((|||),(&&&)) >> -- Tagged (:) >> (<>) :: Either Char Char -> Either String String -> Either >> String String >> Left a <> Left b = Left (a:b) >> Left a <> Right b = Left (a:b) >> Right a <> Left b = Left (a:b) >> Right a <> Right b = Right (a:b) >> -- Tagged concat >> stringParser :: [Either Char Char] -> Either String String >> stringParser = foldr (<>) (Right "") >> -- Parse Integer if properly tagged, keeping unparsed string >> maybeToInteger :: Either String String -> (Maybe Integer, >> String) >> maybeToInteger = (const Nothing ||| Just . read) &&& (id ||| >> id) >> -- Tagged-choice parser >> intOrStringParser = parsecMap (maybeToInteger . stringParser) >> $ many1 (parsecMap Right digit <|> parsecMap Left (noneOf >> ";)")) >> -- Parse between parentheses >> intOrStringListParser = between (char '(') >> (char ')') >> (sepBy1 intOrStringParser >> (char >> ';')) >> ----------------------- >> Then you get a tagged version of each string, along with the >> string itself: >> *P> parseTest intOrStringListParser $ "(1;2w4;8;85)" >> [(Just 1,"1"),(Nothing,"2w4"),(Just 8,"8"),(Just 85,"85")] >> There may be some parsecMap-fold fusion optimization possible, >> though I haven't looked into that. >> Dan >> Paul Sujkov wrote: >> Hi everybody, >> suppose I have two different parsers: one just reads the >> string, and another one parses some values from it. E.g.: >> parseIntList :: Parser [Integer] >> parseIntList = do >> char '(' >> res <- liftM (map read) (sepBy1 (many1 digit) (char ';')) >> char ')' >> return res >> parseIntString :: Parser String >> parseIntString = manyTill anyChar eof >> so for some input like this - "(1;2;3;4)" - I will have >> two >> different result: >> *Parlog> parseTest parseIntList "(1;2;3;4)" >> [1,2,3,4] >> *Parlog> parseTest parseIntString "(1;2;3;4)" >> "(1;2;3;4)" >> but the thing that I actually want is something like >> Parser >> ([Integer], String) - results from both parsers at a time, >> no matter whether one of them fails or not: >> *Parlog> parseTest parseIntListAndString "(1;2;3;4)" >> ([1,2,3,4], "(1;2;3;4)") >> it is impossible at first sight, because first parser to >> use >> will consume all the input, and there will be nothing to >> parse for the second one >> Parsec contains "choice" function, but it is implemented >> via >> <|> and that is mplus - so it tries second alternative >> only >> if the first one fails. Is it possible to use two parsers >> for the same string (with try-like backtracking, no input >> actually consumed till the second parser finishes)? I can >> assume only dirty hacks with the GenParser internals - >> manual position storing and backtracking - but that is >> obviously not good >> however, my first attempt to solve the problem was kind a >> like that: to parse string to String, and then to use it >> as >> an input for the next level parse call: >> parseIntListAndString :: Parser ([Integer], String) >> parseIntListAndString = do >> str <- parseIntString >> return (res str, str) >> where res str = case (parse parseIntList "" str) of >> Left err -> [] >> Right val -> val >> but the problems with such a method began when I switched >> from Parser to GenParser with user state: function >> parseIntList have to update the state, but it can't have >> the >> same state as the parseIntListAndString any more: it has >> it's own. I can explicitly pass the state from >> parseIntListAndString to parseIntList, but I see no >> suitable >> way for the parseIntList to update it. I can return the >> updated state value from the parseIntList function, and >> call >> setState on a result - but it seems rather ugly to mee. >> However, if nothing else will do, that is an alternative >> it is of course possible to use two different parsers >> sequentially, but it is also very ineffective: I need to >> use >> such multiple parsing on a relatively small substring of >> the >> actual input, so little backtracking would be a much >> nicier >> approach. Any suggestions? >> -- Regards, Paul Sujkov >> -- >> Regards, Paul Sujkov > > _______________________________________________ > 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: Examples.hs Type: application/octet-stream Size: 3228 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090809/3984ac48/Examples.obj From explicitcall at googlemail.com Sun Aug 9 12:34:05 2009 From: explicitcall at googlemail.com (Max Desyatov) Date: Sun Aug 9 12:14:30 2009 Subject: [Haskell-cafe] ANNOUNCE: cabal-query 0.1 Message-ID: <877hxdkkua.fsf@zagan.made.you> This package was written to assist you at finding a set of packages, which satisfy your needs. At the moment it doesn't have a standalone executable, but you can do the queries from your Haskell code. It uses Data.Generics.PlateData, so * when Cabal package format changes, we don't have to rewrite anything * all queries are statically typed * as a disadvantage, we may suffer some performance loss when doing very complex queries, anyway most of processing goes while we read package descriptions, not querying them Example of enduser querying code: > module Main where > import qualified Data.ByteString.Lazy as B > import System.Environment > import Distribution.Query > import Distribution.Compiler > import Distribution.License > import Distribution.ModuleName hiding (main) > import Distribution.Package > import Distribution.PackageDescription > import Distribution.Version > import Distribution.Text > import Language.Haskell.Extension > main = (head `fmap` getArgs) >>= > B.readFile >>= > mapM_ (putStrLn . show . (x -> (display $ package x, display $ license x))) . > queryIndex (Not (Id (== GPL)) :& Not (Id (== BSD3))) This queries an index file, which is commonly located at ~/.cabal/packages/hackage.haskell.org/00-index.tar in POSIX systems. You can query any field of PackageDescription no matter how deep it is. You don't need to provide any type signature for comparison functions, which are wrapped in Id, as long as you use data constructors for which type can be inferred. In the future versions I want to add some query expressions parser, for invoking cabal-query from command-line. I suppose this will look like: cabal-query -q 'license == BSD3 & stability == stable & testedWith == GHC & repoType == (git | darcs)' From jvranish at gmail.com Sun Aug 9 14:44:41 2009 From: jvranish at gmail.com (Job Vranish) Date: Sun Aug 9 14:25:14 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: <4c44d90b0908082108t241a8d89u9b0465b78de1df57@mail.gmail.com> References: <4c44d90b0908081614q5bd6325peeefe2d9319fe6fd@mail.gmail.com> <20090809003014.GB21821@kira.casa> <4c44d90b0908081802y3bb6a9dbi75a8a8ef8b045ef5@mail.gmail.com> <4c44d90b0908082108t241a8d89u9b0465b78de1df57@mail.gmail.com> Message-ID: Inlining natFromInt and intFromNat improves things considerably. Using Thomas DuBuisson's benchmarking code (with a larger number of keys): IntMap: buildMap: 12.2 lookupMap: 2.7 Original EnumMap: buildMap: 13.0s lookupMap: 3.6s EnumMap built with -O2 (not sure the implications of building libraries with -O2) buildMap: 12.9s lookupMap: 2.7s effectively the same time for inserts compared with the original EnumMap improved performance for lookups (effectivly the same as IntMap) EnumMap built with -O2, inline on natFromInt and intFromNat and specialize for insert, and join: (doesn't appear to get a speedup with specialize on lookup and lookupN if EnumMap is built with -O2) buildMap: 12.2s lookupMap: 2.7s The same performance as IntMap! I'm kinda dissapointed ghc can't figure this out automatically, fromEnum/toEnum for Ints is just id. Oh well, a few more annotations in the library and wouldn't see any reason why EnumMap would be slower that IntMap. I'll submit a patch I also tried EnumMap but with a newtyped Int for the keys. I get the same performance for lookups as Int, but the inserts are slower. buildMap: 12.8s lookupMap: 2.7s My guess is that the specialize pragma on insert isn't getting triggered on the newtype (which I think it should) So I have a suggestion for a ghc optimization: Unwrap newtypes before specialization so that the specializer can take advantage of the underlying type. - Job On Sun, Aug 9, 2009 at 12:08 AM, Thomas DuBuisson < thomas.dubuisson@gmail.com> wrote: > Inflating the number of elements in the test, I see: > > IntMap > inserts: 5.3 seconds > lookups: 2.0 seconds > > EnumMap > inserts: 6.1 sec (15% slower) > lookups: 2.5 sec (25% slower) > > EnumMap with SPECIALIZE of: > {-# SPECIALIZE join :: Prefix -> EnumMap Int a -> Prefix -> EnumMap > Int a -> EnumMap Int a #-} > {-# SPECIALIZE lookup :: Int -> EnumMap Int a -> Maybe a #-} > {-# SPECIALIZE lookupN :: Nat -> EnumMap Int a -> Maybe a #-} > {-# SPECIALIZE insert :: Int -> a -> EnumMap Int a -> EnumMap Int a #-} > inserts: 5.3 seconds (dead on) > lookups: 2.6 seconds (owch!) > > Additionally specializing the functions used in lookup{,N} doesn't > help. I tried inlining (via INLINE) a couple things but that only > made performance notably worse. > > > Thomas > > On Sat, Aug 8, 2009 at 8:29 PM, John Van Enk wrote: > > How bad is the lookup compared to normal? > > > > On Sat, Aug 8, 2009 at 9:02 PM, Thomas > > DuBuisson wrote: > >> On Sat, Aug 8, 2009 at 5:30 PM, Felipe Lessa > wrote: > >>> On Sat, Aug 08, 2009 at 04:14:15PM -0700, Thomas DuBuisson wrote: > >>>> There exists a small but measurable performance hit for at least one > >>>> test case (using Int as keys, obviously). Perhaps the bias would be > >>>> the other way if we were comparing EnumMap to an IntMap wrapped with > >>>> to/from Enum. > >>> > >>> Perhaps some SPECIALIZE pragmas would help here. > >>> > >> > >> Actually I tried that by adding SPECIALIZE to insert, insertN and > >> lookup. it seemed to make the insert benchmark competitive but not > >> lookup. > >> > >> Thomas > >> _______________________________________________ > >> 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090809/13ac48ae/attachment.html From thomas.dubuisson at gmail.com Sun Aug 9 15:04:54 2009 From: thomas.dubuisson at gmail.com (Thomas DuBuisson) Date: Sun Aug 9 14:45:27 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: References: <4c44d90b0908081614q5bd6325peeefe2d9319fe6fd@mail.gmail.com> <20090809003014.GB21821@kira.casa> <4c44d90b0908081802y3bb6a9dbi75a8a8ef8b045ef5@mail.gmail.com> <4c44d90b0908082108t241a8d89u9b0465b78de1df57@mail.gmail.com> Message-ID: <4c44d90b0908091204n27a291cfia9c0a5a0f2ff70e1@mail.gmail.com> On Sun, Aug 9, 2009 at 11:44 AM, Job Vranish wrote: > Inlining natFromInt and intFromNat improves things considerably. > EnumMap built with -O2 (not sure the implications of building libraries with > -O2) Nice work Job, for some reason it didn't occur to me that the .cabal omitted -O2. The remaining question I have about the specialize pragma is where does this end? Should it only be specialized for Int? Perhaps there are other common instance of Enum that people will end up using for which we should add a SPECIALIZE. With N types and M functions we are talking about N x M rules, which could get ugly fast. Thomas From simonpj at microsoft.com Sun Aug 9 15:42:37 2009 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Sun Aug 9 15:23:15 2009 Subject: [Haskell-cafe] generalize RecordPuns and RecordWildCards to work with qualified names? In-Reply-To: <5ab17e790907241648x77999baft925cac5d9af116d7@mail.gmail.com> References: <2518b95d0907171556l3745912na56481698094b2dd@mail.gmail.com> <638ABD0A29C8884A91BC5FB5C349B1C34B7FA6CABB@EA-EXMSG-C334.europe.corp.microsoft.com> <5ab17e790907241648x77999baft925cac5d9af116d7@mail.gmail.com> Message-ID: <638ABD0A29C8884A91BC5FB5C349B1C35B30DEED90@EA-EXMSG-C334.europe.corp.microsoft.com> Oh, now I get it, thanks. This message concerns design choices for record-syntax-related GHC extensions. Lennart, pls tune in. You don?t need to have read the thread to understand this message. | I think that Even refers to an example like this: | | module A where | data A = A { a :: Int } | | The following works: | | {-# LANGUAGE NamedFieldPuns #-} | module B where | import A | f (A { a }) = a | | However, if we import "A" qualified, then punning does not seem to work: | | {-# LANGUAGE NamedFieldPuns #-} | module B where | import qualified A | f (A.A { a }) = a | | This results in: Not in scope: `a' Right. What is happening is that GHC looks up the first 'a' (the one on the LHS) and finds it not in scope. If you add -XDisambiguateRecordFields, it works fine. But admittedly, the error message is unhelpful. I could improve that. Now on to the suggested change: | {-# LANGUAGE NamedFieldPuns #-} | module B where | import qualified A | | f (A.A { A.a }) = a | | This results in: Qualified variable in pattern: A.a | | Even is suggesting that instead of reporting an error, in the second | case we could use the translation: | | f (A.A { A.a }) = a --> f (A.A { A.a = a }) | | (i.e., when punning occurs with a qualified name, use just the | unqualified part of the name in the pattern) Yes, that'd be possible. But it seems debatable -- it doesn't *look* as if the pattern (A.A { A.a }) binds 'a' -- and it seems even less desirable in record construction and update. To be concrete, would you expect these to work too? g a = A.A { A.a } --> g a = A.A { A.a = a } h x a = x { A.a } --> h x a = a { A.a = a } In these cases, I think the abbreviated code looks too confusing. With -XDisambiguateRecordFields you could say g a = A.A { a } which seems better. (But there's no help for record update, since we don?t know which data constructor is involved.) So my current conclusion is: improve the error message, perhaps suggesting the flag -XDismabiguateRecordFields, but don't add the change you suggest. Comments? Simon From jgm at berkeley.edu Sun Aug 9 16:27:45 2009 From: jgm at berkeley.edu (John MacFarlane) Date: Sun Aug 9 16:08:35 2009 Subject: [Haskell-cafe] Re: Request for Changelogs In-Reply-To: <1249568876.10202.65.camel@localhost> References: <1249568876.10202.65.camel@localhost> Message-ID: <20090809202745.GB7339@protagoras.phil.berkeley.edu> Agreed! I put in a request for this about a year ago: http://hackage.haskell.org/trac/hackage/ticket/299 There is a bit of follow-up discussion there. John +++ Joachim Breitner [Aug 06 09 16:27 ]: > Hi, > > (this is mostly a rant, but hopefully a constructive one) > > the Haskell/cabal/hackage eco system is pretty great, as we all know. > But there is one huge gaping omission there: Changelogs! > > I?m involved in packaging Haskell stuff for Debian. Now, the Debian > tools we have for that tell me ?Hlint has a new version, 1.6.5, which is > newer than the one you packages, 1.6.4. > > Huh, nice. What has changed? Is it relevant for Debian? Is it worth a > new upload? There is no easy way to find out: > > http://hackage.haskell.org/package/hlint lists no changes > http://community.haskell.org/~ndm/hlint/ lists no changes > (and not every package has a homepage) > http://community.haskell.org/~ndm/darcs/hlint/ contains on Changes file > (and not every package has a (linked) darcs repository) > http://community.haskell.org/~ndm/darcs/hlint/ also has no web frontend. > > Which leaves me with the option of getting the darcs repo and looking > through "darcs changes". If I know of a repository for the package. > > So please, package authors, put Changes files in your packages and keep > the current for now. > > And cabal/hackage guys: Llease introduce a standard Changes format for > cabal packages so that http://hackage.haskell.org/package/hlint readily > lists (or links to) changes. > > Thanks, > Joachim > > -- > Joachim "nomeata" Breitner > Debian Developer > nomeata@debian.org | ICQ# 74513189 | GPG-Keyid: 4743206C > JID: nomeata@joachim-breitner.de | http://people.debian.org/~nomeata > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From lennart at augustsson.net Sun Aug 9 16:39:53 2009 From: lennart at augustsson.net (Lennart Augustsson) Date: Sun Aug 9 16:20:28 2009 Subject: [Haskell-cafe] generalize RecordPuns and RecordWildCards to work with qualified names? In-Reply-To: <638ABD0A29C8884A91BC5FB5C349B1C35B30DEED90@EA-EXMSG-C334.europe.corp.microsoft.com> References: <2518b95d0907171556l3745912na56481698094b2dd@mail.gmail.com> <638ABD0A29C8884A91BC5FB5C349B1C34B7FA6CABB@EA-EXMSG-C334.europe.corp.microsoft.com> <5ab17e790907241648x77999baft925cac5d9af116d7@mail.gmail.com> <638ABD0A29C8884A91BC5FB5C349B1C35B30DEED90@EA-EXMSG-C334.europe.corp.microsoft.com> Message-ID: At a minimum I think the error message should be better. I also think it would be natural to use the DisambiguateRecordFields for the places where RecordWildcards are used. I mean, if I change from unqualified import to a qualified one, and then change all visible names to be qualified I would expect things to still work. For RecordPuns I don't have an opinion on what to do. -- Lennart On Sun, Aug 9, 2009 at 9:42 PM, Simon Peyton-Jones wrote: > Oh, now I get it, thanks. ?This message concerns design choices for record-syntax-related GHC extensions. ?Lennart, pls tune in. ?You don?t need to have read the thread to understand this message. > > | I think that Even refers to an example like this: > | > | module A where > | ? data A = A { a :: Int } > | > | The following works: > | > | {-# LANGUAGE NamedFieldPuns #-} > | module B where > | ? import A > | ? f (A { a }) = a > | > | However, if we import "A" qualified, then punning does not seem to work: > | > | {-# LANGUAGE NamedFieldPuns #-} > | module B where > | ? import qualified A > | ? f (A.A { a }) = a > | > | This results in: Not in scope: `a' > > Right. ?What is happening is that GHC looks up the first 'a' (the one on the LHS) and finds it not in scope. ?If you add -XDisambiguateRecordFields, it works fine. ?But admittedly, the error message is unhelpful. ?I could improve that. > > Now on to the suggested change: > > | {-# LANGUAGE NamedFieldPuns #-} > | module B where > | ? import qualified A > | > | ? f (A.A { A.a }) = a > | > | This results in: Qualified variable in pattern: A.a > | > | Even is suggesting that instead of reporting an error, in the second > | case we could use the translation: > | > | ? f (A.A { A.a }) = a ? --> ? f (A.A { A.a = a }) > | > | (i.e., when punning occurs with a qualified name, use just the > | unqualified part of the name in the pattern) > > Yes, that'd be possible. ? But it seems debatable -- it doesn't *look* as if the pattern (A.A { A.a }) binds 'a' -- and it seems even less desirable in record construction and update. ?To be concrete, would you expect these to work too? > > ?g a = A.A { A.a } ? ? --> ? ?g a = A.A { A.a = a } > ?h x a = x { A.a } ? ? --> ? ?h x a = a { A.a = a } > > In these cases, I think the abbreviated code looks too confusing. > > With -XDisambiguateRecordFields you could say > > ?g a = A.A { a } > > which seems better. ?(But there's no help for record update, since we don?t know which data constructor is involved.) > > > So my current conclusion is: improve the error message, perhaps suggesting the flag -XDismabiguateRecordFields, but don't add the change you suggest. > > Comments? > > Simon > > > _______________________________________________ > Glasgow-haskell-users mailing list > Glasgow-haskell-users@haskell.org > http://www.haskell.org/mailman/listinfo/glasgow-haskell-users > > From jvranish at gmail.com Sun Aug 9 17:44:05 2009 From: jvranish at gmail.com (Job Vranish) Date: Sun Aug 9 17:24:38 2009 Subject: [Haskell-cafe] Quickcheck for common typeclass laws Message-ID: Is there a hackage package that contains quickcheck properties for the laws of common typeclasses? (Functor, Monad, Num, Ord, Eq, Applicative, etc...) so that one could quickly check (har har) that their new instances satisfy the appropriate laws? It would be very nice to have a isValidMonad (undefined :: MyNewMonadType) function. If one does not exist, I may just have to make one. - Job -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090809/91528670/attachment.html From jeremy at n-heptane.com Sun Aug 9 18:19:55 2009 From: jeremy at n-heptane.com (Jeremy Shaw) Date: Sun Aug 9 18:00:32 2009 Subject: [Haskell-cafe] Quickcheck for common typeclass laws In-Reply-To: References: Message-ID: <878whshbp0.wl%jeremy@n-heptane.com> This perhaps? http://hackage.haskell.org/package/checkers - jeremy At Sun, 9 Aug 2009 17:44:05 -0400, Job Vranish wrote: > > [1 ] > [1.1 ] > Is there a hackage package that contains quickcheck properties for the laws > of common typeclasses? > (Functor, Monad, Num, Ord, Eq, Applicative, etc...) > so that one could quickly check (har har) that their new instances satisfy > the appropriate laws? > > It would be very nice to have a > isValidMonad (undefined :: MyNewMonadType) > function. > > If one does not exist, I may just have to make one. > > - Job > [1.2 ] > > [2 ] > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From psujkov at gmail.com Sun Aug 9 18:30:56 2009 From: psujkov at gmail.com (Paul Sujkov) Date: Sun Aug 9 18:11:30 2009 Subject: [Haskell-cafe] Parsec: using two different parser for the same string In-Reply-To: References: <9760562b0908051042p97be03tb5f49a0905ef44d5@mail.gmail.com> <4A79FABD.3080000@imageworks.com> <4A7A16CE.4070209@imageworks.com> <9760562b0908060859m5c49d9f0te659c5c75086753e@mail.gmail.com> <4A7B28FD.9090603@imageworks.com> Message-ID: <9760562b0908091530y4d385d97q1ceed7fc50949c5@mail.gmail.com> Hi Doaitse, that is very interesting, and I'll take a precise look at the uu-parsinglib. Regarding my original question there exist (I believe) one serious problem: existing code is written exclusively using Parsec and it's already quite complex. At first glimpse I don't see an obvious way to use both libraries in one parsing module simulatiously. However, these are a very good news indeed, thank you 2009/8/9 S. Doaitse Swierstra > The uu-parsinglib: > > > http://hackage.haskell.org/packages/archive/uu-parsinglib/2.2.0/doc/html/Text-ParserCombinators-UU-Core.html > > contains a combinator to achieve just this: > > -- parsing two alternatives and returning both rsults > pAscii = pSym ('\000', '\254') > pIntList = pParens ((pSym ';') `pListSep` (read <$> pList (pSym > ('0', '9')))) > parseIntString = pList (pAscii) > > parseBoth = pPair pIntList parseIntString > > pPair p q = amb (Left <$> p <|> Right <$> q) > > > The amb combinator tells you that it's parser parameter is ambiguous, and > returns you all the possible results. Amazingly it still maintains its > online behaviour. The only problem is that if either one of the parsers > fails then you will get only a single result. > > I have added the code above to the Examples.hs contained in the > uu-parsinglib (so it will show up in due time when I release a new version) > which I am attaching. Just load this file, and call the function main to see > what are the results of the different parsers and correction strategies. The > only problem is that if either one of the parsers fails you will only get > one of the results. If both fail you will get the result which fails latest > and if both fail at the same place, the one which fails with the least > repair costs. > > If you really want both results, even if the input is erroneaous, things > become more complicated, especially if you want to embed this parser in a > larger one, since then we have to check whether both parse the same prefix. > If needed I could put some work into this, by making a slightly different > version of the amb combinator. > > Doaitse > > > > > On 6 aug 2009, at 21:03, Dan Weston wrote: > > Paul, >> >> Arrows (and category theory in general) are interesting, but you certainly >> don't need to understand them for this. >> The only arrow in this code is the lowly function arrow (->). (&&&) and >> (|||) are duals of each other and mean, respectively, "both" and "either" >> (though for some bizarre reason, "both" is usually called "fanout"!) >> >> This style of pointfree (or "pointless") code is clearer to me because I >> don't have a bunch of variable names to invent and have lying around. >> >> Anyway, if you prefer, don't import Control.Arrow at all, and just use: >> >> -- |Both: Apply two functions to same argument and tuple the results >> infixr 3 &&& >> (&&&) :: (a -> b) -> (a -> c) -> a -> (b,c) >> (f &&& g) x = (f x, g x) >> >> -- |Either: If argument is Left, apply Left function, else apply Right >> function >> infixr 2 ||| >> (|||) :: (a -> c) -> (b -> c) -> Either a b -> c >> (|||) = either >> >> either is implicitly imported from the Prelude and is defined as: >> >> -- | Case analysis for the 'Either' type. >> -- If the value is @'Left' a@, apply the first function to @a@; >> -- if it is @'Right' b@, apply the second function to @b@. >> either :: (a -> c) -> (b -> c) -> Either a b -> c >> either f _ (Left x) = f x >> either _ g (Right y) = g y >> >> Dan >> >> Paul Sujkov wrote: >> >>> Hi Dan, >>> thank you for the solution. It looks pretty interesting and usable, >>> however I'll have to spend some time understanding arrows: I never had an >>> opportunity to use them before. Anyway, it looks very close to what I >>> actually need, and in any case much less ugly than breaking the GenParser >>> encapsulation >>> 2009/8/6 Dan Weston >> westondan@imageworks.com>> >>> Of course, since ParsecT s u m is a functor, feel free to use fmap >>> instead of parsecMap. Then you don't need to import from >>> Text.Parsec.Prim. >>> And in hindsight, I might prefer the name (<:>) or cons to (<>) for >>> the first function, but now I'm just obsessing. :) >>> Dan >>> Dan Weston wrote: >>> I think parsecMap does the job here: >>> ----------------------- >>> import Text.ParserCombinators.Parsec hiding ((<|>)) >>> import Text.Parsec.Prim(parsecMap) >>> import Control.Applicative((<|>)) >>> import Control.Arrow((|||),(&&&)) >>> -- Tagged (:) >>> (<>) :: Either Char Char -> Either String String -> Either >>> String String >>> Left a <> Left b = Left (a:b) >>> Left a <> Right b = Left (a:b) >>> Right a <> Left b = Left (a:b) >>> Right a <> Right b = Right (a:b) >>> -- Tagged concat >>> stringParser :: [Either Char Char] -> Either String String >>> stringParser = foldr (<>) (Right "") >>> -- Parse Integer if properly tagged, keeping unparsed string >>> maybeToInteger :: Either String String -> (Maybe Integer, String) >>> maybeToInteger = (const Nothing ||| Just . read) &&& (id ||| id) >>> -- Tagged-choice parser >>> intOrStringParser = parsecMap (maybeToInteger . stringParser) >>> $ many1 (parsecMap Right digit <|> parsecMap Left (noneOf ";)")) >>> -- Parse between parentheses >>> intOrStringListParser = between (char '(') >>> (char ')') >>> (sepBy1 intOrStringParser (char >>> ';')) >>> ----------------------- >>> Then you get a tagged version of each string, along with the >>> string itself: >>> *P> parseTest intOrStringListParser $ "(1;2w4;8;85)" >>> [(Just 1,"1"),(Nothing,"2w4"),(Just 8,"8"),(Just 85,"85")] >>> There may be some parsecMap-fold fusion optimization possible, >>> though I haven't looked into that. >>> Dan >>> Paul Sujkov wrote: >>> Hi everybody, >>> suppose I have two different parsers: one just reads the >>> string, and another one parses some values from it. E.g.: >>> parseIntList :: Parser [Integer] >>> parseIntList = do >>> char '(' >>> res <- liftM (map read) (sepBy1 (many1 digit) (char ';')) >>> char ')' >>> return res >>> parseIntString :: Parser String >>> parseIntString = manyTill anyChar eof >>> so for some input like this - "(1;2;3;4)" - I will have two >>> different result: >>> *Parlog> parseTest parseIntList "(1;2;3;4)" >>> [1,2,3,4] >>> *Parlog> parseTest parseIntString "(1;2;3;4)" >>> "(1;2;3;4)" >>> but the thing that I actually want is something like Parser >>> ([Integer], String) - results from both parsers at a time, >>> no matter whether one of them fails or not: >>> *Parlog> parseTest parseIntListAndString "(1;2;3;4)" >>> ([1,2,3,4], "(1;2;3;4)") >>> it is impossible at first sight, because first parser to use >>> will consume all the input, and there will be nothing to >>> parse for the second one >>> Parsec contains "choice" function, but it is implemented via >>> <|> and that is mplus - so it tries second alternative only >>> if the first one fails. Is it possible to use two parsers >>> for the same string (with try-like backtracking, no input >>> actually consumed till the second parser finishes)? I can >>> assume only dirty hacks with the GenParser internals - >>> manual position storing and backtracking - but that is >>> obviously not good >>> however, my first attempt to solve the problem was kind a >>> like that: to parse string to String, and then to use it as >>> an input for the next level parse call: >>> parseIntListAndString :: Parser ([Integer], String) >>> parseIntListAndString = do >>> str <- parseIntString >>> return (res str, str) >>> where res str = case (parse parseIntList "" str) of >>> Left err -> [] >>> Right val -> val >>> but the problems with such a method began when I switched >>> from Parser to GenParser with user state: function >>> parseIntList have to update the state, but it can't have the >>> same state as the parseIntListAndString any more: it has >>> it's own. I can explicitly pass the state from >>> parseIntListAndString to parseIntList, but I see no suitable >>> way for the parseIntList to update it. I can return the >>> updated state value from the parseIntList function, and call >>> setState on a result - but it seems rather ugly to mee. >>> However, if nothing else will do, that is an alternative >>> it is of course possible to use two different parsers >>> sequentially, but it is also very ineffective: I need to use >>> such multiple parsing on a relatively small substring of the >>> actual input, so little backtracking would be a much nicier >>> approach. Any suggestions? >>> -- Regards, Paul Sujkov >>> -- >>> Regards, Paul Sujkov >>> >> >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> > -- Regards, Paul Sujkov -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090809/47e9a392/attachment-0001.html From ramsdell0 at gmail.com Sun Aug 9 19:29:28 2009 From: ramsdell0 at gmail.com (John D. Ramsdell) Date: Sun Aug 9 19:10:05 2009 Subject: [Haskell-cafe] Examples In-Reply-To: References: <4A7D617E.9010103@btinternet.com> Message-ID: <7687290b0908091629l69722760s62df26fd7b3361ff@mail.gmail.com> > Usually I include the example program in the package, but make its compilation conditional using a Cabal flag like buildExamples. But then the binaries generated from the example program get installed. I think the poster wants to share the source code, not install a demo. I haven't figure out a way to specify test programs that don't get installed, but are only intended to be built and run within the context of a source distribution. John From thomas.dubuisson at gmail.com Sun Aug 9 20:15:43 2009 From: thomas.dubuisson at gmail.com (Thomas DuBuisson) Date: Sun Aug 9 19:56:15 2009 Subject: [Haskell-cafe] Examples In-Reply-To: <7687290b0908091629l69722760s62df26fd7b3361ff@mail.gmail.com> References: <4A7D617E.9010103@btinternet.com> <7687290b0908091629l69722760s62df26fd7b3361ff@mail.gmail.com> Message-ID: <4c44d90b0908091715gf3e41c1r6e95c19859542a05@mail.gmail.com> John D. Ramsdell wrote: >> Usually I include the example program in the package, but make its compilation conditional using a Cabal flag like buildExamples. > > But then the binaries generated from the example program get > installed. ?I think the poster wants to share the source code, not > install a demo. But only if the flag is set. The user can simply look at the source code example without installing the program. Another option: test code (or any other source) can easily be included in the source dist by adding them to the "extra-source-files:" line in the .cabal file. I include tests in the pureMD5 package in this manner. Thomas From ramsdell0 at gmail.com Sun Aug 9 20:50:54 2009 From: ramsdell0 at gmail.com (John D. Ramsdell) Date: Sun Aug 9 20:31:26 2009 Subject: [Haskell-cafe] Examples In-Reply-To: <4c44d90b0908091715gf3e41c1r6e95c19859542a05@mail.gmail.com> References: <4A7D617E.9010103@btinternet.com> <7687290b0908091629l69722760s62df26fd7b3361ff@mail.gmail.com> <4c44d90b0908091715gf3e41c1r6e95c19859542a05@mail.gmail.com> Message-ID: <7687290b0908091750v1b7d7435mc92f6e4b562968a2@mail.gmail.com> On Sun, Aug 9, 2009 at 8:15 PM, Thomas DuBuisson wrote: >...?Another option: test > code (or any other source) can easily be included in the source dist > by adding them to the "extra-source-files:" line in the .cabal file. But then cabal doesn't know how to build binaries from the source files with that option. John From ramsdell0 at gmail.com Sun Aug 9 21:07:53 2009 From: ramsdell0 at gmail.com (John D. Ramsdell) Date: Sun Aug 9 20:48:25 2009 Subject: [Haskell-cafe] Examples In-Reply-To: <7687290b0908091750v1b7d7435mc92f6e4b562968a2@mail.gmail.com> References: <4A7D617E.9010103@btinternet.com> <7687290b0908091629l69722760s62df26fd7b3361ff@mail.gmail.com> <4c44d90b0908091715gf3e41c1r6e95c19859542a05@mail.gmail.com> <7687290b0908091750v1b7d7435mc92f6e4b562968a2@mail.gmail.com> Message-ID: <7687290b0908091807y1d4a5329w6b452c6a3af5e044@mail.gmail.com> Maybe in addition to having a buildable boolean in a library or executable section, there should be an installable boolean. It would default to true, but when false, the library or executable section is ignored during package installation. John From mwotton at gmail.com Sun Aug 9 21:11:04 2009 From: mwotton at gmail.com (Mark Wotton) Date: Sun Aug 9 20:51:47 2009 Subject: [Haskell-cafe] Examples In-Reply-To: <7687290b0908091629l69722760s62df26fd7b3361ff@mail.gmail.com> References: <4A7D617E.9010103@btinternet.com> <7687290b0908091629l69722760s62df26fd7b3361ff@mail.gmail.com> Message-ID: <849309C2-1E02-4ECF-ADB6-F17D75727764@gmail.com> On 10/08/2009, at 9:29 AM, John D. Ramsdell wrote: >> Usually I include the example program in the package, but make its >> compilation conditional using a Cabal flag like buildExamples. > > But then the binaries generated from the example program get > installed. I think the poster wants to share the source code, not > install a demo. > > I haven't figure out a way to specify test programs that don't get > installed, but are only intended to be built and run within the > context of a source distribution. Couldn't resist a chance to spruik TBC (Testing By Convention) - it's a framework Pete Gammie and I are developing to run tests in Haskell. In addition to a few other neat features like not having to write boilerplate main functions by way of some conventions about how to run tests, it knows enough about Cabal to use the package information etc to link your tests together, and provides a command line tool (tbc) to run your tests and provide a report. If you use it and it's helpful to you, or you have any suggestions for how it could be improved, please let me or Pete know. Cheers Mark From k2msmith at gmail.com Sun Aug 9 22:07:10 2009 From: k2msmith at gmail.com (Kevin Smith) Date: Sun Aug 9 21:47:42 2009 Subject: [Haskell-cafe] haskell embedded In-Reply-To: <89603931.20090809083712@gmail.com> References: <49dd14e0908081824s3de6fbbal877eab75a0792ed5@mail.gmail.com> <89603931.20090809083712@gmail.com> Message-ID: <49dd14e0908091907r747a0423wa40b2f3979f78c95@mail.gmail.com> Hello, I checked the Hugs User Manual and I didn't find any notes on this in section 4. "Other Ways of Running Hugs". can you point me to this section or reference ? thanks On Sat, Aug 8, 2009 at 9:37 PM, Bulat Ziganshin wrote: > Hello Kevin, > > Sunday, August 9, 2009, 5:24:02 AM, you wrote: > > > Hello, Could someone point me in the the direction of any > > references for using Haskell as an embedded language in an > > hugs documentation notes how to embed Hugs into application > > > -- > Best regards, > Bulat mailto:Bulat.Ziganshin@gmail.com > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090809/7bdd246e/attachment.html From doaitse at swierstra.net Mon Aug 10 04:15:46 2009 From: doaitse at swierstra.net (S. Doaitse Swierstra) Date: Mon Aug 10 03:56:19 2009 Subject: [Haskell-cafe] Parsec: using two different parser for the same string In-Reply-To: <9760562b0908091530y4d385d97q1ceed7fc50949c5@mail.gmail.com> References: <9760562b0908051042p97be03tb5f49a0905ef44d5@mail.gmail.com> <4A79FABD.3080000@imageworks.com> <4A7A16CE.4070209@imageworks.com> <9760562b0908060859m5c49d9f0te659c5c75086753e@mail.gmail.com> <4A7B28FD.9090603@imageworks.com> <9760562b0908091530y4d385d97q1ceed7fc50949c5@mail.gmail.com> Message-ID: <5CC4C6E5-544E-4E20-973A-27A692430BC9@swierstra.net> Since the uu-parsinglib also provides a monadic interface it should not be too difficult to provide a Parsec interface on top of the uu- parsinglib combinators. so you can re-use large parts of your code. I expect that your parsers eventually will become simpler, since you do not have to add explicit control to the parsing process with try-like constructs. This being said I still think that the applicative interface is to be preferred over the monadic interface, since it does not prohibit all kind of static analases of your parser (as is done in the older parsing library which is part of the uulib package); using the monadic interface for building new parsers based on results recognised thus far is fine, but using it just to construct a parsing result is overkill. If you have any questions please let me know. Doaitse On 10 aug 2009, at 00:30, Paul Sujkov wrote: > Hi Doaitse, > > that is very interesting, and I'll take a precise look at the uu- > parsinglib. Regarding my original question there exist (I believe) > one serious problem: existing code is written exclusively using > Parsec and it's already quite complex. At first glimpse I don't see > an obvious way to use both libraries in one parsing module > simulatiously. However, these are a very good news indeed, thank you > > 2009/8/9 S. Doaitse Swierstra > The uu-parsinglib: > > http://hackage.haskell.org/packages/archive/uu-parsinglib/2.2.0/doc/html/Text-ParserCombinators-UU-Core.html > > contains a combinator to achieve just this: > > -- parsing two alternatives and returning both rsults > pAscii = pSym ('\000', '\254') > pIntList = pParens ((pSym ';') `pListSep` (read <$> pList > (pSym ('0', '9')))) > parseIntString = pList (pAscii) > > parseBoth = pPair pIntList parseIntString > > pPair p q = amb (Left <$> p <|> Right <$> q) > > > The amb combinator tells you that it's parser parameter is > ambiguous, and returns you all the possible results. Amazingly it > still maintains its online behaviour. The only problem is that if > either one of the parsers fails then you will get only a single > result. > > I have added the code above to the Examples.hs contained in the uu- > parsinglib (so it will show up in due time when I release a new > version) which I am attaching. Just load this file, and call the > function main to see what are the results of the different parsers > and correction strategies. The only problem is that if either one of > the parsers fails you will only get one of the results. If both > fail you will get the result which fails latest and if both fail at > the same place, the one which fails with the least repair costs. > > If you really want both results, even if the input is erroneaous, > things become more complicated, especially if you want to embed this > parser in a larger one, since then we have to check whether both > parse the same prefix. If needed I could put some work into this, by > making a slightly different version of the amb combinator. > > Doaitse > > > > > On 6 aug 2009, at 21:03, Dan Weston wrote: > > Paul, > > Arrows (and category theory in general) are interesting, but you > certainly don't need to understand them for this. > The only arrow in this code is the lowly function arrow (->). (&&&) > and (|||) are duals of each other and mean, respectively, "both" and > "either" (though for some bizarre reason, "both" is usually called > "fanout"!) > > This style of pointfree (or "pointless") code is clearer to me > because I don't have a bunch of variable names to invent and have > lying around. > > Anyway, if you prefer, don't import Control.Arrow at all, and just > use: > > -- |Both: Apply two functions to same argument and tuple the results > infixr 3 &&& > (&&&) :: (a -> b) -> (a -> c) -> a -> (b,c) > (f &&& g) x = (f x, g x) > > -- |Either: If argument is Left, apply Left function, else apply > Right function > infixr 2 ||| > (|||) :: (a -> c) -> (b -> c) -> Either a b -> c > (|||) = either > > either is implicitly imported from the Prelude and is defined as: > > -- | Case analysis for the 'Either' type. > -- If the value is @'Left' a@, apply the first function to @a@; > -- if it is @'Right' b@, apply the second function to @b@. > either :: (a -> c) -> (b -> c) -> Either a b -> c > either f _ (Left x) = f x > either _ g (Right y) = g y > > Dan > > Paul Sujkov wrote: > Hi Dan, > thank you for the solution. It looks pretty interesting and usable, > however I'll have to spend some time understanding arrows: I never > had an opportunity to use them before. Anyway, it looks very close > to what I actually need, and in any case much less ugly than > breaking the GenParser encapsulation > 2009/8/6 Dan Weston >> > Of course, since ParsecT s u m is a functor, feel free to use fmap > instead of parsecMap. Then you don't need to import from > Text.Parsec.Prim. > And in hindsight, I might prefer the name (<:>) or cons to (<>) for > the first function, but now I'm just obsessing. :) > Dan > Dan Weston wrote: > I think parsecMap does the job here: > ----------------------- > import Text.ParserCombinators.Parsec hiding ((<|>)) > import Text.Parsec.Prim(parsecMap) > import Control.Applicative((<|>)) > import Control.Arrow((|||),(&&&)) > -- Tagged (:) > (<>) :: Either Char Char -> Either String String -> Either > String String > Left a <> Left b = Left (a:b) > Left a <> Right b = Left (a:b) > Right a <> Left b = Left (a:b) > Right a <> Right b = Right (a:b) > -- Tagged concat > stringParser :: [Either Char Char] -> Either String String > stringParser = foldr (<>) (Right "") > -- Parse Integer if properly tagged, keeping unparsed string > maybeToInteger :: Either String String -> (Maybe Integer, > String) > maybeToInteger = (const Nothing ||| Just . read) &&& (id ||| id) > -- Tagged-choice parser > intOrStringParser = parsecMap (maybeToInteger . stringParser) > $ many1 (parsecMap Right digit <|> parsecMap Left (noneOf > ";)")) > -- Parse between parentheses > intOrStringListParser = between (char '(') > (char ')') > (sepBy1 intOrStringParser (char > ';')) > ----------------------- > Then you get a tagged version of each string, along with the > string itself: > *P> parseTest intOrStringListParser $ "(1;2w4;8;85)" > [(Just 1,"1"),(Nothing,"2w4"),(Just 8,"8"),(Just 85,"85")] > There may be some parsecMap-fold fusion optimization possible, > though I haven't looked into that. > Dan > Paul Sujkov wrote: > Hi everybody, > suppose I have two different parsers: one just reads the > string, and another one parses some values from it. E.g.: > parseIntList :: Parser [Integer] > parseIntList = do > char '(' > res <- liftM (map read) (sepBy1 (many1 digit) (char ';')) > char ')' > return res > parseIntString :: Parser String > parseIntString = manyTill anyChar eof > so for some input like this - "(1;2;3;4)" - I will have two > different result: > *Parlog> parseTest parseIntList "(1;2;3;4)" > [1,2,3,4] > *Parlog> parseTest parseIntString "(1;2;3;4)" > "(1;2;3;4)" > but the thing that I actually want is something like Parser > ([Integer], String) - results from both parsers at a time, > no matter whether one of them fails or not: > *Parlog> parseTest parseIntListAndString "(1;2;3;4)" > ([1,2,3,4], "(1;2;3;4)") > it is impossible at first sight, because first parser to use > will consume all the input, and there will be nothing to > parse for the second one > Parsec contains "choice" function, but it is implemented via > <|> and that is mplus - so it tries second alternative only > if the first one fails. Is it possible to use two parsers > for the same string (with try-like backtracking, no input > actually consumed till the second parser finishes)? I can > assume only dirty hacks with the GenParser internals - > manual position storing and backtracking - but that is > obviously not good > however, my first attempt to solve the problem was kind a > like that: to parse string to String, and then to use it as > an input for the next level parse call: > parseIntListAndString :: Parser ([Integer], String) > parseIntListAndString = do > str <- parseIntString > return (res str, str) > where res str = case (parse parseIntList "" str) of > Left err -> [] > Right val -> val > but the problems with such a method began when I switched > from Parser to GenParser with user state: function > parseIntList have to update the state, but it can't have the > same state as the parseIntListAndString any more: it has > it's own. I can explicitly pass the state from > parseIntListAndString to parseIntList, but I see no suitable > way for the parseIntList to update it. I can return the > updated state value from the parseIntList function, and call > setState on a result - but it seems rather ugly to mee. > However, if nothing else will do, that is an alternative > it is of course possible to use two different parsers > sequentially, but it is also very ineffective: I need to use > such multiple parsing on a relatively small substring of the > actual input, so little backtracking would be a much nicier > approach. Any suggestions? > -- Regards, Paul Sujkov > -- > Regards, Paul Sujkov > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > > -- > Regards, Paul Sujkov -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090810/619a429f/attachment.html From tretriluxana.s at gmail.com Mon Aug 10 04:34:14 2009 From: tretriluxana.s at gmail.com (Sukit Tretriluxana) Date: Mon Aug 10 04:14:48 2009 Subject: [Haskell-cafe] Any comments about Clojure language? Message-ID: <8252533f0908100134t552d6500x910949e1cc57160c@mail.gmail.com> Hi all, I start reading about Closure language (http://clojure.org) and it seems an interesting language. I don't know much about this language especially in comparison to Haskell feature by feature. Could it perhaps be what Haskell on JVM would have been with the dressing of Lisp syntax? Any one would like to chime in your comments about the language, in comparison to Haskell? Thanks, Ed -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090810/dff4a242/attachment.html From gour at gour-nitai.com Mon Aug 10 05:45:51 2009 From: gour at gour-nitai.com (Gour) Date: Mon Aug 10 05:30:34 2009 Subject: [Haskell-cafe] Re: [ANNOUNCE] hgettext 0.1.10 - last major release References: <8feb08f70904141418k3be64346xa0ddf52a33a5b816@mail.gmail.com> Message-ID: <87my689f3k.fsf@gaura-nitai.no-ip.org> >>>>> "Vasyl" == Vasyl Pasternak writes: Vasyl> I don't see any strong reasons to write any combinators over this Vasyl> basic bindings. Haskell needs more powerful internationalization Vasyl> library, and I am plan to design it, but it will be completely Vasyl> different from gettext principles, so this library will be Vasyl> released with another name. Any work done on the above mentioned library? Sincerely, Gour -- Gour | Hlapi?ina, Croatia | GPG key: F96FF5F6 --------------------------------------------------------------------------- -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090810/7f2dafea/attachment.bin From ketil at malde.org Mon Aug 10 09:24:36 2009 From: ketil at malde.org (Ketil Malde) Date: Mon Aug 10 09:05:13 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: (John Van Enk's message of "Sat\, 8 Aug 2009 15\:03\:35 -0400") References: Message-ID: <87zla73ip7.fsf@malde.org> John Van Enk writes: > EnumMap is a generalization of IntMap that constrains the key to Enum > rather than forcing it to be Int. I have no idea what impact this has > on performance, Will it have an impact on correctness? There are some funky Enum instances around: Prelude> map fromEnum [1,1.5,2] [1,1,2] Prelude Data.Int> fromEnum (10000000000 :: Int64) *** Exception: Enum.fromEnum{Int64}: value (10000000000) is outside of Int's bounds (-2147483648,2147483647) -k -- If I haven't seen further, it is by standing in the footprints of giants From g9ks157k at acme.softbase.org Mon Aug 10 10:04:08 2009 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Mon Aug 10 09:45:04 2009 Subject: [Haskell-cafe] Examples In-Reply-To: <4A7D617E.9010103@btinternet.com> References: <4A7D617E.9010103@btinternet.com> Message-ID: <200908101604.08196.g9ks157k@acme.softbase.org> Am Samstag, 8. August 2009 13:29 schrieb Andrew Coppin: > As some of you may remember, I recently released a couple of packages on > Hackage. I'd like to also release some example programs using these > packages, but I'm not sure of the best way to do this. > > Do I make the example programs part of the package itself? Do I release > a seperate package which just contains the example code? Something else > entirely? What's the recommendation here? I had to make this decision for Grapefruit, and I decided to put the examples into a separate package named grapefruit-examples. Note that the rest of Grapefruit was already split into several packages with names of the form grapefruit-*. Best wishes, Wolfgang From felipe.lessa at gmail.com Mon Aug 10 10:09:18 2009 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Mon Aug 10 09:49:54 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: <87zla73ip7.fsf@malde.org> References: <87zla73ip7.fsf@malde.org> Message-ID: <20090810140918.GA26102@kira.casa> On Mon, Aug 10, 2009 at 03:24:36PM +0200, Ketil Malde wrote: > John Van Enk writes: > > EnumMap is a generalization of IntMap that constrains the key to Enum > > rather than forcing it to be Int. I have no idea what impact this has > > on performance, > > Will it have an impact on correctness? There are some funky Enum > instances around: IMO it's implicit that keys overwrite eachother whenever their 'fromEnum' is equal, however that may be spoken in the docs. Depending on what you want you may or may not desire to have this behaviour, but this is how this data structure works. So, yes, it's correct, just different. :) -- Felipe. From dons at galois.com Mon Aug 10 12:35:48 2009 From: dons at galois.com (Don Stewart) Date: Mon Aug 10 12:18:23 2009 Subject: [Haskell-cafe] Any comments about Clojure language? In-Reply-To: <8252533f0908100134t552d6500x910949e1cc57160c@mail.gmail.com> References: <8252533f0908100134t552d6500x910949e1cc57160c@mail.gmail.com> Message-ID: <20090810163548.GE20093@whirlpool.galois.com> tretriluxana.s: > Hi all, > > I start reading about Closure language (http://clojure.org) and it seems an > interesting language. I don't know much about this language especially in > comparison to Haskell feature by feature. Could it perhaps be what Haskell on > JVM would have been with the dressing of Lisp syntax? > > Any one would like to chime in your comments about the language, in comparison > to Haskell? It's a Scheme-like language that targets the JVM. Most of the comparisons between Scheme-like languages and Haskell hold. It provides some form of built-in STM, and libraries for some persistant data structures, which is an interesting development. -- Don From wasserman.louis at gmail.com Mon Aug 10 13:37:47 2009 From: wasserman.louis at gmail.com (Louis Wasserman) Date: Mon Aug 10 13:18:37 2009 Subject: [Haskell-cafe] Re: Announce: EnumMap-0.0.1 Message-ID: Pardon my asking, but are fromEnum and toEnum guaranteed to preserve order on types like Double? I'd like to see a Double-backed Patricia tree map, but are we certain that EnumMap as presented will behave properly on such types? Louis Wasserman wasserman.louis@gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090810/592484b1/attachment.html From thomas.dubuisson at gmail.com Mon Aug 10 13:57:24 2009 From: thomas.dubuisson at gmail.com (Thomas DuBuisson) Date: Mon Aug 10 13:37:54 2009 Subject: [Haskell-cafe] Re: Announce: EnumMap-0.0.1 In-Reply-To: References: Message-ID: <4c44d90b0908101057i3bd71431sb711b44caad758a6@mail.gmail.com> Double seems to truncate to Int while values outside of the bounds go to zero. Obviously there would be no way to have a one to one mapping as Double is often in excess of 64 bits while Int is often 32 bits. These recent questions are really more about knowing the tool (library) you are using. Double can't be used as a key in IntMat, but it can now be used as a key in EnumMap - if it works for your needs then great! Thomas On Mon, Aug 10, 2009 at 10:37 AM, Louis Wasserman wrote: > Pardon my asking, but are fromEnum and toEnum guaranteed to preserve order > on types like Double?? I'd like to see a Double-backed Patricia tree map, > but are we certain that EnumMap as presented will behave properly on such > types? > > Louis Wasserman > wasserman.louis@gmail.com > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > From jvranish at gmail.com Mon Aug 10 14:11:16 2009 From: jvranish at gmail.com (Job Vranish) Date: Mon Aug 10 13:51:47 2009 Subject: [Haskell-cafe] Re: Announce: EnumMap-0.0.1 In-Reply-To: References: Message-ID: I'm not exactly sure what you mean by preserve order, but no, Doubles would not behave as expected in an EnumMap because fromEnum for Doubles just truncates: fromEnum (2.0 :: Double) == 2 fromEnum (2.5 :: Double) == 2 However I think that is more an issue with the Enum instances than with EnumMap. I really don't think Double should be an instance of Enum. (or if it is, it should actually _enumerate_ the values) It's basically just there for the list comprehension syntax. take 5 [1.0 ..] :: [Double] == [1.0,2.0,3.0,4.0,5.0] But I feel like that would be better handled with Num instances or something, or with a separate typeclass. - Job On Mon, Aug 10, 2009 at 1:37 PM, Louis Wasserman wrote: > Pardon my asking, but are fromEnum and toEnum guaranteed to preserve order > on types like Double? I'd like to see a Double-backed Patricia tree map, > but are we certain that EnumMap as presented will behave properly on such > types? > > Louis Wasserman > wasserman.louis@gmail.com > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090810/55c9463b/attachment.html From vanenkj at gmail.com Mon Aug 10 14:32:34 2009 From: vanenkj at gmail.com (John Van Enk) Date: Mon Aug 10 14:13:07 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: References: Message-ID: I've been trying to implement EnumMap as a wrapper for IntMap. Here's the first problem I ran into: > IntMap.insertWithKey :: (Key -> a -> a -> a) -> Key -> a -> IntMap a -> IntMap a I'd like to translate this to something like: > EnumMap.insertWithKey :: Enum k => (Key k -> a -> a -> a) -> Key k -> a -> EnumMap k a -> EnumMap k a My initial thought was just to make it a normal wrapper: > EnumMap.insertWithKey f k v m = IntMap.insertWithKey f (unKey k) v (unEnumMap m) The obvious problem here is the type of `f' expected by the wrapper function and the internal function. Either we force the wrapper to take a function that takes an Int as the first parameter, or we rewrite the logic of insertWithKey to allow us to use the proper (Key k) type. I don't see an obvious way around this--am I missing something? On Sat, Aug 8, 2009 at 4:41 PM, Henning Thielemann wrote: > > On Sat, 8 Aug 2009, John Van Enk wrote: > >> Hi List, >> >> I've uploaded a first version of EnumMap to hackage. >> >> EnumMap is a generalization of IntMap that constrains the key to Enum >> rather than forcing it to be Int. I have no idea what impact this has >> on performance, but it still passes all the tests that ship with >> IntMap. (My guess is that performance will be similar/identical unless >> I've missed something.) > > Could that be implemented as wrapper around IntMap? > From vanenkj at gmail.com Mon Aug 10 14:50:21 2009 From: vanenkj at gmail.com (John Van Enk) Date: Mon Aug 10 14:30:52 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: References: Message-ID: Allow me to answer my own question: > EnumMap.insertWithKey f k v m = IntMap.insertWithKey (f . Key . toEnum) (unKey k) v (unEnumMap m) On Mon, Aug 10, 2009 at 2:32 PM, John Van Enk wrote: > I've been trying to implement EnumMap as a wrapper for IntMap. Here's > the first problem I ran into: > >> IntMap.insertWithKey :: (Key -> a -> a -> a) -> Key -> a -> IntMap a -> IntMap a > > I'd like to translate this to something like: > >> EnumMap.insertWithKey :: Enum k => (Key k -> a -> a -> a) -> Key k -> a -> EnumMap k a -> EnumMap k a > > My initial thought was just to make it a normal wrapper: > >> EnumMap.insertWithKey f k v m = IntMap.insertWithKey f (unKey k) v (unEnumMap m) > > The obvious problem here is the type of `f' expected by the wrapper > function and the internal function. Either we force the wrapper to > take a function that takes an Int as the first parameter, or we > rewrite the logic of insertWithKey to allow us to use the proper (Key > k) type. > > I don't see an obvious way around this--am I missing something? > > On Sat, Aug 8, 2009 at 4:41 PM, Henning > Thielemann wrote: >> >> On Sat, 8 Aug 2009, John Van Enk wrote: >> >>> Hi List, >>> >>> I've uploaded a first version of EnumMap to hackage. >>> >>> EnumMap is a generalization of IntMap that constrains the key to Enum >>> rather than forcing it to be Int. I have no idea what impact this has >>> on performance, but it still passes all the tests that ship with >>> IntMap. (My guess is that performance will be similar/identical unless >>> I've missed something.) >> >> Could that be implemented as wrapper around IntMap? >> > From keithshep at gmail.com Mon Aug 10 19:31:18 2009 From: keithshep at gmail.com (Keith Sheppard) Date: Mon Aug 10 19:11:49 2009 Subject: [Haskell-cafe] Examples In-Reply-To: <200908101604.08196.g9ks157k@acme.softbase.org> References: <4A7D617E.9010103@btinternet.com> <200908101604.08196.g9ks157k@acme.softbase.org> Message-ID: <92e42b740908101631pe8de895q6da8c62df592a32b@mail.gmail.com> This seems to me like the kind of thing hackage maintainers should be giving guidance on (maybe they do already?) so that there is consistency. Sorry if this seems too off base, but here I go anyway... I have used apache IVY for packaging/dependency management in java and I really like the way it works. They have spent a lot of effort figuring out how to deal with complex project dependencies. For example they have organization (eg. "com.sun") and project (eg "javaSDK") concepts that help to keep the namespace clean. They also have different "profiles" like "test" or "dist" that you can depend on. Maybe it would be worthwhile to poke around ivy's docs and see if we want to pull any of these concepts into cabal/hackage On Mon, Aug 10, 2009 at 10:04 AM, Wolfgang Jeltsch wrote: > Am Samstag, 8. August 2009 13:29 schrieb Andrew Coppin: >> As some of you may remember, I recently released a couple of packages on >> Hackage. I'd like to also release some example programs using these >> packages, but I'm not sure of the best way to do this. >> >> Do I make the example programs part of the package itself? Do I release >> a seperate package which just contains the example code? Something else >> entirely? What's the recommendation here? > > I had to make this decision for Grapefruit, and I decided to put the examples > into a separate package named grapefruit-examples. Note that the rest of > Grapefruit was already split into several packages with names of the form > grapefruit-*. > > Best wishes, > Wolfgang > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- keithsheppard.name From tgdavies at gmail.com Mon Aug 10 19:46:51 2009 From: tgdavies at gmail.com (Tom Davies) Date: Mon Aug 10 19:27:27 2009 Subject: [Haskell-cafe] Any comments about Clojure language? In-Reply-To: <8252533f0908100134t552d6500x910949e1cc57160c@mail.gmail.com> References: <8252533f0908100134t552d6500x910949e1cc57160c@mail.gmail.com> Message-ID: <96B8EAB2-92DB-4482-AA6F-525EAE91E862@gmail.com> On 10/08/2009, at 6:34 PM, Sukit Tretriluxana wrote: > Hi all, > > I start reading about Closure language (http://clojure.org) and it > seems an interesting language. I don't know much about this language > especially in comparison to Haskell feature by feature. Could it > perhaps be what Haskell on JVM would have been with the dressing of > Lisp syntax? > > Any one would like to chime in your comments about the language, in > comparison to Haskell? As far as I know, the closest thing to Haskell on the JVM is CAL http://openquark.org Clojure differs from Haskell in being impure (although it does provide some immutable data structures) and in not being statically typed -- the lack of static typing is the most important difference IMHO. Tom From duncan.coutts at worc.ox.ac.uk Mon Aug 10 18:19:31 2009 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Mon Aug 10 20:30:34 2009 Subject: [Haskell-cafe] C2HS issues on Hackage In-Reply-To: <29bf512f0908032107j37fbfa02x6239ac1d242c7cfb@mail.gmail.com> References: <29bf512f0908032107j37fbfa02x6239ac1d242c7cfb@mail.gmail.com> Message-ID: <1249942771.20327.10136.camel@localhost> On Tue, 2009-08-04 at 07:07 +0300, Michael Snoyman wrote: > Hi all, > > I've written a Yaml library built on top of libyaml (the same C > library at the core of Python's yaml library). All is well on my local > system and my server; I'm currently using it in production. However, > the build is failing on Hackage with the following build log: > http://hackage.haskell.org/packages/archive/yaml/0.0.1/logs/failure/ghc-6.10. > > It seems that whichever version of C2HS is installed on the server > does not allow "type" (or perhaps other keywords?) to be used as C > identifiers. Unfortunately, "type" is the name of a field in a C > struct I need to integrate with. It's obviously not vital that I get > it to compile on hackage, but 1) I'm worried this is a sign of a > bigger problem, and 2) it's always nice to have the API documentation > available online. > > Any suggestions? I recommend that you specify in the .cabal file the minimum version of c2hs that you require. It's probably 0.16 that you need. Then of course you'll probably find that the version of c2hs on the single build machine is indeed older than that. This shows us again the problem with using a single build machine rather than allowing any client to upload build reports. As an interim measure before we get the new hackage server, you could email Ross and ask him nicely to update c2hs on the build machine. Duncan From DekuDekuplex at Yahoo.com Tue Aug 11 01:24:00 2009 From: DekuDekuplex at Yahoo.com (Benjamin L.Russell) Date: Tue Aug 11 01:04:46 2009 Subject: [Haskell-cafe] Re: Any comments about Clojure language? References: <8252533f0908100134t552d6500x910949e1cc57160c@mail.gmail.com> <20090810163548.GE20093@whirlpool.galois.com> Message-ID: On Mon, 10 Aug 2009 09:35:48 -0700, Don Stewart wrote: >tretriluxana.s: >> Hi all, >> >> I start reading about Closure language (http://clojure.org) and it seems an >> interesting language. I don't know much about this language especially in >> comparison to Haskell feature by feature. Could it perhaps be what Haskell on >> JVM would have been with the dressing of Lisp syntax? >> >> Any one would like to chime in your comments about the language, in comparison >> to Haskell? > >It's a Scheme-like language that targets the JVM. Most of the >comparisons between Scheme-like languages and Haskell hold. > >It provides some form of built-in STM, and libraries for some persistant >data structures, which is an interesting development. One advantage to Clojure over implementations of Scheme is that there is a packaged SLIME-based [1] editing environment available for Clojure, called "Clojure Box" [2] (inspired by Lispbox [3]). Although there are a number of Scheme-modes available for Emacs, most notably Quack [4], currently, there are no SLIME-based IDE's for any implementation of Scheme, the most similar packaged Emacs-based tool available being Gauchebox [5], which is not SLIME-based. Another advantage is the ability to use Java libraries. On the other hand, two disadvantages with Clojure compared to most implementations of Scheme are the lack of first-class continuations and tail-call optimization (TCO). Another possible disadvantage of Clojure (depending on one's perspective) is its emphasis on practical over theoretical aspects. Once, I visited the #clojure IRC channel on Freenode to ask a question about getting Clojure Box to work together with Lispbox, and when I happened to mention the relevance of the field of "PLT" (Programming Language Theory), one of the other users online didn't know what "PLT" stood for; I had to explain the definition of the acronym, and then explain what the field concerned. Apparently, the other users online at that time were more interested in industrial programming than in research or hobby-related study. Another possible disadvantage of Clojure is the lack of high-quality free online tutorials. When I asked about this issue on #clojure, the other users there suggested that I look at code, rather than at a tutorial, and when I persisted in asking about a tutorial, they then recommended that I purchase a for-fee book [6]. Haskell, by contrast, has many freely available online tutorials, and even some freely available online books, including RWH [7]. -- Benjamin L. Russell [1] Gorrie, Luke and Helmut Eller. "SLIME: The Superior Lisp Interaction Mode for Emacs." Based on SLIM, by Eric Marsden, mid-2003. 15 Feb. 2008. 11 Aug. 2009. . [2] Hoover, Shawn. "Clojure Box." 9 May 2009. 11 Aug. 2009. . [3] Seibel, Peter. "Lispbox." 2005. 11 Aug. 2009. . [4] Van Dyke, Neil. "neilvandyke.org - Quack: Enhanced Emacs Support for Editing and Running Scheme Code." 29 June 2006. 11 Aug. 2009. . [5] Kawai, Shiro. "Gauchebox." 2 Aug. 2009. 11 Aug. 2009. . [6] Halloway, Stuart. _Programming Clojure._ Raleigh, NC: Pragmatic Bookshelf, 2009. . [7] O'Sullivan, Brian, Don Stewart, and John Goerzen. _Real World Haskell._ Sebastopol, CA: O'Reilly Media, Inc., 2008. . -- Benjamin L. Russell / DekuDekuplex at Yahoo dot com http://dekudekuplex.wordpress.com/ Translator/Interpreter / Mobile: +011 81 80-3603-6725 "Furuike ya, kawazu tobikomu mizu no oto." -- Matsuo Basho^ From michael at snoyman.com Tue Aug 11 02:03:12 2009 From: michael at snoyman.com (Michael Snoyman) Date: Tue Aug 11 01:43:42 2009 Subject: [Haskell-cafe] C2HS issues on Hackage In-Reply-To: <1249942771.20327.10136.camel@localhost> References: <29bf512f0908032107j37fbfa02x6239ac1d242c7cfb@mail.gmail.com> <1249942771.20327.10136.camel@localhost> Message-ID: <29bf512f0908102303ob0cb896ye711acdbb02ae6af@mail.gmail.com> On Tue, Aug 11, 2009 at 1:19 AM, Duncan Coutts wrote: > On Tue, 2009-08-04 at 07:07 +0300, Michael Snoyman wrote: > > Hi all, > > > > I've written a Yaml library built on top of libyaml (the same C > > library at the core of Python's yaml library). All is well on my local > > system and my server; I'm currently using it in production. However, > > the build is failing on Hackage with the following build log: > > > http://hackage.haskell.org/packages/archive/yaml/0.0.1/logs/failure/ghc-6.10 > . > > > > It seems that whichever version of C2HS is installed on the server > > does not allow "type" (or perhaps other keywords?) to be used as C > > identifiers. Unfortunately, "type" is the name of a field in a C > > struct I need to integrate with. It's obviously not vital that I get > > it to compile on hackage, but 1) I'm worried this is a sign of a > > bigger problem, and 2) it's always nice to have the API documentation > > available online. > > > > Any suggestions? > > I recommend that you specify in the .cabal file the minimum version of > c2hs that you require. It's probably 0.16 that you need. > > Then of course you'll probably find that the version of c2hs on the > single build machine is indeed older than that. This shows us again the > problem with using a single build machine rather than allowing any > client to upload build reports. As an interim measure before we get the > new hackage server, you could email Ross and ask him nicely to update > c2hs on the build machine. > > Duncan Thanks for getting back to me Duncan. I was in fact using 0.16 on my system. However, to simplify things, I went ahead and rewrote to use the FFI directly. Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090811/dd19329f/attachment.html From olshanskydr at gmail.com Tue Aug 11 06:50:45 2009 From: olshanskydr at gmail.com (Dmitry Olshansky) Date: Tue Aug 11 06:31:14 2009 Subject: [Haskell-cafe] Haskell2Xml - Suggest looking at HXT In-Reply-To: <14ABF7EC-CD5B-49E6-A5CB-110D4404DF0B@gmail.com> References: <741612210908051249ya47b732ne8f06010204b5090@mail.gmail.com> <92e42b740908051710t1765909cg6e38f665bf221449@mail.gmail.com> <741612210908070231j409cb0ecwaf1cb694d860a8f9@mail.gmail.com> <3c6288ab0908070329v9aaeec8h74c8da9b5bd72fd7@mail.gmail.com> <741612210908070404m397a9f70u94504adb8cb1ce39@mail.gmail.com> <14ABF7EC-CD5B-49E6-A5CB-110D4404DF0B@gmail.com> Message-ID: <741612210908110350o3a69d846w4c6be319456d4a9c@mail.gmail.com> Hi Max, thanks for your suggestion. I also have a "not pretty" code which used Text.XML.Light and TH. I am going to rewrite it. HXT by my opinion is too big. The question is a "requirements". Which correlations exist between Haskell types and XML-Schema possibilities? How to prepare XML for different Haskell types? How to generate Haskell types from XML-Schema, which restrictions in schema could be authomatically modeled in Haskell? And so on... 2009/8/8 Max Cantor > Hi Dmitry, > > I've been using HXT and its XmlPickler class for encoding and decoding > between XML <-> Haskell types. It takes a while to wrap your brain around > the arrows based API for HXT (something I'm still working on) but it seems > to be quite powerful and well maintained. > > Also, I've written some Template Haskell code to derive instances for the > XmlPickler class (so that types can automatically be encoded and decoded as > XML. Its not pretty, has bugs, and is far from perfect but I can send that > to you if you'd like a way to get stared. > > Max > > On Aug 7, 2009, at 7:04 PM, Dmitry Olshansky wrote: > > Well, great thanks for interesting links. >> >> But definitely at first I need a time to try to understand what Generic >> Haskell and EMGM are. >> >> Does it stronger than Template Haskell? Could it be explained briefly and >> simplistic for first impression? Could it be compared with SYB or TH? >> >> Would it be applied to realisation of translation or to target Haskell >> code? >> >> Regards, >> Dmitry >> >> >> 2009/8/7 Sean Leather >> >> On Fri, Aug 7, 2009 at 12:05, John Lask wrote: >> the paper: >> >> Scripting XML with Generic Haskell >> Frank Atanassow, Dave Clarke and Johan Jeuring >> October 14, 2003 >> >> describes a translation from XML Schema to Haskell data types (like >> dtd2haskell) in generic haskell, I believe that the code for the tool >> described may also be available, how hard it would be to migrate over to >> vanilla haskell+generics is another question.... >> >> It looks like this almost might work in EMGM. They use a Label in addition >> to all the other representation structure elements. EMGM doesn't have a >> Label, but it might be useful to add it... >> >> With any needed changes such as the Label done, migrating this Generic >> Haskell code to EMGM would not be difficult. >> >> Sean >> >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090811/152cbb92/attachment.html From jwlato at gmail.com Tue Aug 11 07:51:19 2009 From: jwlato at gmail.com (John Lato) Date: Tue Aug 11 07:31:47 2009 Subject: [Haskell-cafe] Re: Examples Message-ID: <9979e72e0908110451v50e14fa6rb8e31257d7ea4024@mail.gmail.com> Hello, Looking at just examples, there are a few separate issues here. 1. Installation of example source for review 2. Building/installation of example programs For the second issue, the buildExamples flag suggested by Henning works well to actually build the examples with cabal, but the install location is still a problem. Most users wouldn't want example executables to go into their bin directory, especially not in the case of global installs. To the best of my knowledge, Cabal currently doesn't support separate installation locations for multiple executables, nor does it support building but not installing executables. With the first issue, the problem is simpler. There's no location for source code to be installed to. Users can download the package and unpack it themselves, or the developer can include demo source as a "data file" and install it to the datadir (IMO a poor choice). One option is to add support for different installation locations for each executable. Perhaps the --installdir flag could be extended to support a syntax like the following: --installdir=executableName:/path/to/install where if executableName matches one of the executables known to cabal, it will install just that executable to the specified location. This puts a larger burden on users, however, since they would need to know the name(s) of all the demo executables. It also doesn't address the issue of source location. Another way is to add a special type of executable for tests and demo programs to cabal. A user would specify a directory in the .cabal file (or command-line) to which tests would be installed. Cabal would then build the identified tests/demos for the package and put them into that specific directory, as well as the source code. This also answers the question of where to put executables that are Buildable but not Installable. Thoughts? Cheers, John Lato > Date: Sun, 9 Aug 2009 21:07:53 -0400 > From: "John D. Ramsdell" > Subject: Re: [Haskell-cafe] Examples > To: Haskell Cafe > Message-ID: > <7687290b0908091807y1d4a5329w6b452c6a3af5e044@mail.gmail.com> > Content-Type: text/plain; charset=UTF-8 > > Maybe in addition to having a buildable boolean in a library or > executable section, there should be an installable boolean. It would > default to true, but when false, the library or executable section is > ignored during package installation. > > John > From spoon at killersmurf.com Tue Aug 11 09:57:28 2009 From: spoon at killersmurf.com (spoon) Date: Tue Aug 11 09:37:58 2009 Subject: [Haskell-cafe] Hack on the Delve core, with Delve and Haskell Message-ID: <1249999048.4183.46.camel@utensil> Delve is a new programming language intended to bring the benefits of static type checking and functional programming to object-oriented design and development. It is an impure, eager language (Yes I can hear the groans of woe and cries for sanity already!) Currently Delve supports: Higher-order functions/first class functions Anonymous functions Lexical closures First class continuations Tail-call optimization A meta-object model (classes are objects) S-Expression based syntax. Embedded Haskell expressions within Delve. What it doesn't have: Lots and lots! Basically what I have is an de-sugared, untyped core language. An analogy could be made with Haskell core files. I'm going to be working on the type system for next little while (I have a stack of paper and a pen right here!). Once that is implemented we'll see where to go. Please see the TUTORIAL file included in the source for a brief outlook on Delve's syntax, semantics and planned type system. However! If you're looking for a new project, and especially if you are an undergraduate, then I think Delve would be a good choice for these reasons: It's written in a hybrid of Haskell and itself. It's currently undergoing active development (by me and some pals). You're not going to be lonely! It's quite powerful already, without too many lines of code (it's now just about 5.5KLOC - it's no goliath! ) It's a programming language: name a compiler which isn't a cool piece of tech! Ok, maybe you can but still, it's a chance to work on something non-trivial and interesting. Quite honestly, I'm a bit of a fool - I am a math undergrad! So don't you feel foolish about getting involved if you're not a professorial chap! If you feel like it, get involved in the design, and push me the patches :) It does require lots of love though! It was all hacked out rather quickly :) Executables which Delve provides: edc -- The Elgin Delve Compiler The Elgin Delve Compiler currently supports two backends - the first to a bytecode format for execution on edvm, and the second is to a Haskell source code representation of Delve bytecode. This allows Haskell to be embedded within Delve, for the express purpose of extending and building edvm. edc is written in Haskell (GHC). edvm -- The Elgin Delve Virtual Machine The Elgin Delve Virtual Machine executes Delve bytecode files (.dcode format). Since part of the VM is actually driven by Delve bytecode, edvm can be considered a hybrid of Delve and Haskell (again GHC). Delve continues the grand tradition of naming compilers after Scottish Cities (no, Elgin does not have a university). Delve is released under the terms of the GNU GPLv3. For more information on Delve, check my blog at http://killersmurf.blogspot.com/ and the Delve repository at http://github.com/elginer/Delve/ -- John From dagit at codersbase.com Tue Aug 11 10:31:38 2009 From: dagit at codersbase.com (Jason Dagit) Date: Tue Aug 11 10:12:07 2009 Subject: [Haskell-cafe] Hack on the Delve core, with Delve and Haskell In-Reply-To: <1249999048.4183.46.camel@utensil> References: <1249999048.4183.46.camel@utensil> Message-ID: On Tue, Aug 11, 2009 at 6:57 AM, spoon wrote: > Delve is a new programming language intended to bring the benefits of > static type checking and functional programming to object-oriented > design and development. It is an impure, eager language (Yes I can > hear the groans of woe and cries for sanity already!) Nice. Sounds like a fun project. If I had more spare cycles I would try to help. > > > Currently Delve supports: > > Higher-order functions/first class functions > Anonymous functions > Lexical closures > First class continuations > Tail-call optimization > A meta-object model (classes are objects) > S-Expression based syntax. > Embedded Haskell expressions within Delve. Could you create a comparison of Delve to other (potentially) similar languages? For example, how is Delve similar/dissimilar to Clojure and Scala? > > > Delve is released under the terms of the GNU GPLv3. Note intended as a criticism of the GPL or your decision to use it, but does this impact people's ability to use the Delve standard libraries in their own non-GPL projects? Good luck! Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090811/03b4f883/attachment.html From jvranish at gmail.com Tue Aug 11 11:48:45 2009 From: jvranish at gmail.com (Job Vranish) Date: Tue Aug 11 11:29:13 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? Message-ID: Does anybody know if there is some unsafe IO function that would let me do destructive assignment? Something like: a = 5 main = do veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign a 8 print a > 8 and yes I am in fact insane... I'm also looking for a way to make actual copies of data. so I could do something like this: a = Node 5 [Node 2 [], Node 5 [a]] main = do b <- makeCopy a veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign b (Node 0 []) -- 'a' is unchanged It would be even more fantastic, if the copy function was lazy. I think the traverse function might actually make a copy, but I would be happier with something more general (doesn't require membership in traversable), and more explicit (was actually designed for making real copies). Any ideas? Thanks, - Job -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090811/1ce69922/attachment.html From pumpkingod at gmail.com Tue Aug 11 12:08:08 2009 From: pumpkingod at gmail.com (Daniel Peebles) Date: Tue Aug 11 11:48:36 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? In-Reply-To: References: Message-ID: In both of your examples, a simple let would allow you to rebind the name (not the same as assigning, but it didn't look like you need that in those examples at least). Note that you're already in IO, so you can use an IORef if you want a true mutable variable, or an STRef in another function if you want to maintain a pure interface. But I'd strongly encourage you to look for alternate options here. Just because it's possible to use mutable variables in Haskell doesn't mean it's always a good idea to do so. Especially if you're new to the language, I'd suggest doing your best to avoid approaches from other languages. But in general, if something "looks" pure (like your "variables" in your email), you may be able to secretly mutate it behind the scenes, but the compiler may not even notice. One advantage of purity is that the compiler knows for sure that something won't change if you read it multiple times. If you go changing its value (assuming you find some hack that even allows it), you'll break many fundamental assumptions. Hope this helps! Dan On Tue, Aug 11, 2009 at 11:48 AM, Job Vranish wrote: > Does anybody know if there is some unsafe IO function that would let me do > destructive assignment? > Something like: > > a = 5 > main = do > ? veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign a 8 > ? print a >> 8 > > and yes I am in fact insane... > > I'm also looking for a way to make actual copies of data. > so I could do something like this: > > a = Node 5 [Node 2 [], Node 5 [a]] > main = do > ? b <- makeCopy a > ? veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign b (Node > 0 []) > ? -- 'a' is unchanged > > It would be even more fantastic, if the copy function was lazy. > I think the traverse function might actually make a copy, but I would be > happier with something more general (doesn't require membership in > traversable), and more explicit (was actually designed for making real > copies). > > Any ideas? > > Thanks, > > - Job > > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > From explicitcall at googlemail.com Tue Aug 11 12:14:20 2009 From: explicitcall at googlemail.com (Max Desyatov) Date: Tue Aug 11 11:53:53 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? In-Reply-To: (Job Vranish's message of "Tue, 11 Aug 2009 11:48:45 -0400") References: Message-ID: <87r5viz5sz.fsf@zagan.made.you> Job Vranish writes: > Does anybody know if there is some unsafe IO function that would let me do destructive assignment? > Something like: > > a = 5 > main = do > ? veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign a 8 > ? print a >> 8 Aren't StateT or IORefs the exact thing you are looking for? > I'm also looking for a way to make actual copies of data. > so I could do something like this: > > a = Node 5 [Node 2 [], Node 5 [a]] > main = do > ? b <- makeCopy a > ? veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign b (Node 0 []) > ? -- 'a' is unchanged > > It would be even more fantastic, if the copy function was lazy. > I think the traverse function might actually make a copy, but I would be happier with something more general (doesn't > require membership in traversable), and more explicit (was actually designed for making real copies). Same thing, IORefs could help you. Anyway, I can't imagine any case where veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign could be useful with its imperative semantics as you've described. The point is that Haskell is pure language and I use it because of this feature (not only because of this, to be exact). I don't want to use any library code that brokes pure semantics and launches nuclear bombs behind the IO monad. GHC is smart enough these days to do all optimised destructive assignments, copies and all that imperative stuff and there are plenty of other ways to get a performance boost without unsafeHorribleThings. From vanenkj at gmail.com Tue Aug 11 12:23:26 2009 From: vanenkj at gmail.com (John Van Enk) Date: Tue Aug 11 12:03:54 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? In-Reply-To: <87r5viz5sz.fsf@zagan.made.you> References: <87r5viz5sz.fsf@zagan.made.you> Message-ID: > unsafeHorribleThings I think we have a name for this new feature. I can see how something like this would be useful to some areas. There are many cases (graphs!) where it's just easier to build up structures destructively, seal them, and return them to happyPureFunTimesLand. Even if GHC does do just as good of a job as performing the unsafe button pushing our selves, it would be an interesting exercise. On Tue, Aug 11, 2009 at 12:14 PM, Max Desyatov wrote: > Job Vranish writes: > >> Does anybody know if there is some unsafe IO function that would let me do destructive assignment? >> Something like: >> >> a = 5 >> main = do >> ? veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign a 8 >> ? print a >>> 8 > > Aren't StateT or IORefs the exact thing you are looking for? > >> I'm also looking for a way to make actual copies of data. >> so I could do something like this: >> >> a = Node 5 [Node 2 [], Node 5 [a]] >> main = do >> ? b <- makeCopy a >> ? veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign b (Node 0 []) >> ? -- 'a' is unchanged >> >> It would be even more fantastic, if the copy function was lazy. >> I think the traverse function might actually make a copy, but I would be happier with something more general (doesn't >> require membership in traversable), and more explicit (was actually designed for making real copies). > > Same thing, IORefs could help you. ?Anyway, I can't imagine any case > where veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign > could be useful with its imperative semantics as you've described. ?The > point is that Haskell is pure language and I use it because of this > feature (not only because of this, to be exact). ?I don't want to use > any library code that brokes pure semantics and launches nuclear bombs > behind the IO monad. ?GHC is smart enough these days to do all optimised > destructive assignments, copies and all that imperative stuff and there > are plenty of other ways to get a performance boost without > unsafeHorribleThings. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From bulat.ziganshin at gmail.com Tue Aug 11 12:23:53 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Aug 11 12:04:32 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? In-Reply-To: References: Message-ID: <575565270.20090811202353@gmail.com> Hello Job, Tuesday, August 11, 2009, 7:48:45 PM, you wrote: > I'm also looking for a way to make actual copies of data. > so I could do something like this: i think you are just going non-FP way. haskell is great for declaring algorithms in pure mathematical way - as a function projecting input values into results. "updating" is just word from another world just for example - little function that joins two ordered lists returning list-in-order. note that it doesn't describe any updates, it describes how to build result from input values: merge xs [] = xs merge [] ys = ys merge (x:xs) (y:ys) | x References: <87r5viz5sz.fsf@zagan.made.you> Message-ID: <428838206.20090811202528@gmail.com> Hello John, Tuesday, August 11, 2009, 8:23:26 PM, you wrote: > I can see how something like this would be useful to some areas. There > are many cases (graphs!) where it's just easier to build up structures > destructively, seal them, and return them to happyPureFunTimesLand. it's ST monad. btw, many array algos from std library (histogram, for example) are written this way -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From jvranish at gmail.com Tue Aug 11 12:45:29 2009 From: jvranish at gmail.com (Job Vranish) Date: Tue Aug 11 12:25:57 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? In-Reply-To: <87r5viz5sz.fsf@zagan.made.you> References: <87r5viz5sz.fsf@zagan.made.you> Message-ID: Ga! Before to many people start flooding me responses of "This is really dumb idea don't do it!" I would like to clarify that for the most part IKnowWhatI'mDoing(TM) I am well aware of the usual ST/IORefs as the usual solutions to data mutability in haskell. I very very much understand purity, and why it is a good thing, and why we should try to stay away from IO and ST as much as possible. I am very much away that even if I had such a function that it will probably break everything. I am not just trying to make things run faster. What I am trying to do is hyper unusual and I really do need an unsafeHorribleThings to do it. - Job On Tue, Aug 11, 2009 at 12:14 PM, Max Desyatov wrote: > Job Vranish writes: > > > Does anybody know if there is some unsafe IO function that would let me > do destructive assignment? > > Something like: > > > > a = 5 > > main = do > > veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign a 8 > > print a > >> 8 > > Aren't StateT or IORefs the exact thing you are looking for? > > > I'm also looking for a way to make actual copies of data. > > so I could do something like this: > > > > a = Node 5 [Node 2 [], Node 5 [a]] > > main = do > > b <- makeCopy a > > veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign b > (Node 0 []) > > -- 'a' is unchanged > > > > It would be even more fantastic, if the copy function was lazy. > > I think the traverse function might actually make a copy, but I would be > happier with something more general (doesn't > > require membership in traversable), and more explicit (was actually > designed for making real copies). > > Same thing, IORefs could help you. Anyway, I can't imagine any case > where veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign > could be useful with its imperative semantics as you've described. The > point is that Haskell is pure language and I use it because of this > feature (not only because of this, to be exact). I don't want to use > any library code that brokes pure semantics and launches nuclear bombs > behind the IO monad. GHC is smart enough these days to do all optimised > destructive assignments, copies and all that imperative stuff and there > are plenty of other ways to get a performance boost without > unsafeHorribleThings. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090811/f06df495/attachment.html From felipe.lessa at gmail.com Tue Aug 11 12:57:48 2009 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Tue Aug 11 12:38:26 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? In-Reply-To: References: <87r5viz5sz.fsf@zagan.made.you> Message-ID: <20090811165748.GA21002@kira.casa> On Tue, Aug 11, 2009 at 12:45:29PM -0400, Job Vranish wrote: > What I am trying to do is hyper unusual and I really do need an > unsafeHorribleThings to do it. I guess these unsafeHorribleThings are impossible, you're trying to subvert the very core of the language. The only thing that comes close to that probably is IORefs + unsafePerformIO, but it seems this isn't what you want. -- Felipe. From explicitcall at googlemail.com Tue Aug 11 13:10:54 2009 From: explicitcall at googlemail.com (Max Desyatov) Date: Tue Aug 11 12:50:23 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? In-Reply-To: (Job Vranish's message of "Tue, 11 Aug 2009 12:45:29 -0400") References: <87r5viz5sz.fsf@zagan.made.you> Message-ID: <87hbwez36p.fsf@zagan.made.you> Job Vranish writes: > I am well aware of the usual ST/IORefs as the usual solutions to data mutability in haskell. > I very very much understand purity, and why it is a good thing, and why we should try to stay away from IO and ST as much > as possible. > I am very much away that even if I had such a function that it will probably break everything. > I am not just trying to make things run faster. > What I am trying to do is hyper unusual and I really do need an unsafeHorribleThings to do it. Well, is purpose of this a big secret? Maybe if you describe the whole direction of such efforts, somebody could propose better solution that satisfies your needs. I recommend you to describe semantics of unsafeHorribleThings in details, and in what exact cases this could be useful. From jake.mcarthur at gmail.com Tue Aug 11 13:11:21 2009 From: jake.mcarthur at gmail.com (Jake McArthur) Date: Tue Aug 11 12:51:52 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? In-Reply-To: References: <87r5viz5sz.fsf@zagan.made.you> Message-ID: <4A81A639.6010204@gmail.com> Job Vranish wrote: > What I am trying to do is hyper unusual and I really do need an > unsafeHorribleThings to do it. Normally when I really, honestly think this, I'm wrong anyway. - Jake From jvranish at gmail.com Tue Aug 11 13:28:19 2009 From: jvranish at gmail.com (Job Vranish) Date: Tue Aug 11 13:08:48 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? In-Reply-To: References: <87r5viz5sz.fsf@zagan.made.you> <1310268607.20090811205034@gmail.com> Message-ID: Opps, didn't "reply to all" I hate it when that happens... On Tue, Aug 11, 2009 at 1:00 PM, Job Vranish wrote: > haha, yeah. > > What I'm actually trying to do is make a way to manipulate arbitrary > recursive algebraic data structures as if they were graphs (not for > performance reasons but because it makes manipulating them much easier) > > It's similar to the data-reify package, but I need it to work on any > algebraic datatype. > > I'm not planning on using it for actually production code. I'm mostly just > experimenting with as a potentially interesting language feature. > > - Job > > > On Tue, Aug 11, 2009 at 12:50 PM, Bulat Ziganshin < > bulat.ziganshin@gmail.com> wrote: > >> Hello Job, >> >> Tuesday, August 11, 2009, 8:45:29 PM, you wrote: >> > What I am trying to do is hyper unusual and I really do need an >> unsafeHorribleThings to do it. >> >> yes, assigning 5 to 8 is really unusual in math :) >> >> >> -- >> Best regards, >> Bulat mailto:Bulat.Ziganshin@gmail.com >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090811/8c1b184a/attachment.html From vanenkj at gmail.com Tue Aug 11 14:19:05 2009 From: vanenkj at gmail.com (John Van Enk) Date: Tue Aug 11 13:59:33 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: References: Message-ID: For the sake of testing both options, here's a branch with the wrapper code instead of the replacement/integrated code: http://github.com/sw17ch/EnumMap/tree/wrapper On Sat, Aug 8, 2009 at 4:41 PM, Henning Thielemann wrote: > > On Sat, 8 Aug 2009, John Van Enk wrote: > >> Hi List, >> >> I've uploaded a first version of EnumMap to hackage. >> >> EnumMap is a generalization of IntMap that constrains the key to Enum >> rather than forcing it to be Int. I have no idea what impact this has >> on performance, but it still passes all the tests that ship with >> IntMap. (My guess is that performance will be similar/identical unless >> I've missed something.) > > Could that be implemented as wrapper around IntMap? > From r.mark.volkmann at gmail.com Tue Aug 11 15:13:54 2009 From: r.mark.volkmann at gmail.com (Mark Volkmann) Date: Tue Aug 11 14:54:21 2009 Subject: [Haskell-cafe] Re: Any comments about Clojure language? Message-ID: > On Mon, 10 Aug 2009 09:35:48 -0700, Don Stewart > wrote: > > Another possible disadvantage of Clojure is the lack of high-quality > free online tutorials. I wrote an extensive intro. to Clojure at http://ociweb.com/mark/clojure/article.html. -- R. Mark Volkmann Object Computing, Inc. From patai_gergely at fastmail.fm Tue Aug 11 15:46:39 2009 From: patai_gergely at fastmail.fm (Patai Gergely) Date: Tue Aug 11 15:27:06 2009 Subject: [Haskell-cafe] GSoC profiling project to be wrapped up Message-ID: <1250019999.30414.1329375813@webmail.messagingengine.com> Hi everyone, I finally uploaded the profiling tools to Hackage. The package names are hp2any-{core,graph,manager}. The first two should be possible to install right away, while the manager needs Gtk2Hs. A bit more on the project and this update at . Gergely -- http://www.fastmail.fm - IMAP accessible web-mail From bugfact at gmail.com Tue Aug 11 17:10:49 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Tue Aug 11 16:51:21 2009 Subject: [Haskell-cafe] GTK2HS OpenGL demo doesn't work on Vista when compiled? Message-ID: GTK2HS 0.10.1 comes with an OpenGL demo (share/demo/opengl/RotatingCube.hs) On my machine (Vista 32-bit) it runs fine under GHCi, but not when compiling using GHC (no rendering happens, unless I resize the window, then rendering happens from time to time) I'm using GHC 6.10.3 (installed Haskell Platform 2009.2.0.1). Do other people using Windows experience this problem? Cheers, Peter Verswyvelen From ott at mirix.org Tue Aug 11 17:57:40 2009 From: ott at mirix.org (Matthias-Christian Ott) Date: Tue Aug 11 17:38:13 2009 Subject: [Haskell-cafe] Haskell's type system compared to CLOS Message-ID: <20090811215740.GA23605@marix> Hi, usually I'm sceptical of programming languages which are not based on the von Neumann architecture, but recently I got interested in functional programming languages. The arrogance of lots of Haskell users, who made me feel that using a programming language other than Haskell is a waste of time, combined with vanguard mathematical notation has been very attractive to me and I have decided to get at least an idea of Haskell and its concepts. Some weeks ago I learned programming in Dylan and was impressed by its object system which is basically a stripped version of CLOS. Multiple dispatch together with a well-thought-out object system is quite powerful, because it removes the burden of including methods in the class definition. At the moment I'm reading the "Functional Programming using Standard ML" and I'm in the chapter on data types. This afternoon it occurred to me that classes and data types are symmetric. In a class hierarchy you start an abstract super class (the most abstract is the class object in some languages) and further specialise them via inheritance; with data types you can start with specialized versions and abstract them via constructors (I'm not sure how message sending to a superclass looks like in this analogy). Anyhow, I also came across an interesting presentation. Andreas L?h and Ralf Hinze state in their presentation "Open data types and open functions" [1]: * OO languages support extension of data, but not of functionality. * FP languages support extension of functionality, but not of data. Their first point refers to the fact that in most object-oriented languages don't allow the separate definition of classes and their respective methods. So to add new functions, you have edit the class definitions. However, in functional programming languages you can easily add new functionality via pattern matching, but have to either introduce new types or new constructors, which again means to modify existing code. In Dylan (and in Common Lisp) you define methods separate from classes and have pattern matching based on types. This solves all mentioned problems. So my question is, how are algebraic data types in Haskell superior to CLOS (despite the fact that CLOS is impure)? How do both compare? What has Haskell to provide what Common Lisp and Dylan haven't? Thanks! Regards, Matthias-Christian [1] http://people.cs.uu.nl/andres/open-japan.pdf From dons at galois.com Tue Aug 11 17:59:55 2009 From: dons at galois.com (Don Stewart) Date: Tue Aug 11 17:42:26 2009 Subject: [Haskell-cafe] Galois is Hiring Message-ID: <20090811215955.GK25224@whirlpool.galois.com> Galois is continuing to hire. We will also be at ICFP and related events, so come and see Lee Pike or me. We have multiple positions for talented functional programmers (with both junior and senior positions). A strong functional programming ability is an advantage (you will be programming in Haskell), and a good computer science background is required. Experience with compilers, operating systems, networking, security, and formal methods is of particular interest. Galois is based in Portland, Oregon. Our engineers work with functional languages, designing and developing advanced technologies for safety and security-critical systems, networks, and applications. Galois technical staff members play a pivotal role in developing advanced software technology. Enginners work in small team settings, and must successfully interact with clients, partners, and other employees in a highly cooperative, collaborative, and intellectually challenging environment. Technical staff may be called upon to write proposals, gather requirements, and work in all stages of the software development process, from requirements gathering to testing and validation. Additional duties may include project management, technology research and development, and technical infrastructure development. We?re looking for people who can invent, learn, think, and inspire. We reward creativity and thrive on collaboration. We offer great benefits and perks, including a 401K plan, stock options, paid vacation, family health plan, flexible work schedule, a casual work environment, snacks, espresso and foosball. A Masters or Ph.D. degree in Computer Science is desirable. Additionally, a strong programming background and experience with Haskell or other functional programming languages is preferred. You must work well with customers, including building rapport, identifying needs, and communicating with strong written, verbal and presentation skills. Must be highly motivated and able to self-manage to deadlines and quality goals. To learn more about us, visit http://www.galois.com and http://www.galois.com/company/careers The types of technology we use are covered in our blog: http://www.galois.com/blog/ We?d like to hear from you! Send your cover letter and resume to us at jobs2009 at galois.com. From mvanier42 at gmail.com Tue Aug 11 18:04:15 2009 From: mvanier42 at gmail.com (Michael Vanier) Date: Tue Aug 11 17:44:44 2009 Subject: [Haskell-cafe] Haskell's type system compared to CLOS In-Reply-To: <20090811215740.GA23605@marix> References: <20090811215740.GA23605@marix> Message-ID: <4A81EADF.4070706@cs.caltech.edu> Matthias-Christian Ott wrote: > Hi, > usually I'm sceptical of programming languages which are not based > on the von Neumann architecture, but recently I got interested in > functional programming languages. > > The arrogance of lots of Haskell users, who made me feel that using a > programming language other than Haskell is a waste of time, combined > with vanguard mathematical notation has been very attractive to me > and I have decided to get at least an idea of Haskell and its concepts. > > Some weeks ago I learned programming in Dylan and was impressed by its > object system which is basically a stripped version of CLOS. Multiple > dispatch together with a well-thought-out object system is quite > powerful, because it removes the burden of including methods in the > class definition. > > At the moment I'm reading the "Functional Programming using Standard > ML" and I'm in the chapter on data types. > > This afternoon it occurred to me that classes and data types are > symmetric. In a class hierarchy you start an abstract super class > (the most abstract is the class object in some languages) and further > specialise them via inheritance; with data types you can start with > specialized versions and abstract them via constructors (I'm not sure > how message sending to a superclass looks like in this analogy). > > Anyhow, I also came across an interesting presentation. Andreas L?h > and Ralf Hinze state in their presentation "Open data types and open > functions" [1]: > > * OO languages support extension of data, but not of functionality. > * FP languages support extension of functionality, but not of data. > > Their first point refers to the fact that in most object-oriented > languages don't allow the separate definition of classes and their > respective methods. So to add new functions, you have edit the class > definitions. > > However, in functional programming languages you can easily add new > functionality via pattern matching, but have to either introduce new > types or new constructors, which again means to modify existing code. > > In Dylan (and in Common Lisp) you define methods separate from classes > and have pattern matching based on types. This solves all mentioned > problems. > > So my question is, how are algebraic data types in Haskell superior to > CLOS (despite the fact that CLOS is impure)? How do both compare? > > What has Haskell to provide what Common Lisp and Dylan haven't? > > Thanks! > > Regards, > Matthias-Christian > > > Type classes. Mike From lennart at augustsson.net Tue Aug 11 18:08:01 2009 From: lennart at augustsson.net (Lennart Augustsson) Date: Tue Aug 11 17:48:29 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? In-Reply-To: References: Message-ID: No, there's no way you can change the value of 'a' after the fact. Since 'a' is a constant the compiler has most likely inlined it wherever it has been used, the done constant folding etc. If you need an updateable variable, you need to tell the compiler, otherwise it will assume your code is pure. -- Lennart On Tue, Aug 11, 2009 at 5:48 PM, Job Vranish wrote: > Does anybody know if there is some unsafe IO function that would let me do > destructive assignment? > Something like: > > a = 5 > main = do > ? veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign a 8 > ? print a >> 8 > > and yes I am in fact insane... > > I'm also looking for a way to make actual copies of data. > so I could do something like this: > > a = Node 5 [Node 2 [], Node 5 [a]] > main = do > ? b <- makeCopy a > ? veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign b (Node > 0 []) > ? -- 'a' is unchanged > > It would be even more fantastic, if the copy function was lazy. > I think the traverse function might actually make a copy, but I would be > happier with something more general (doesn't require membership in > traversable), and more explicit (was actually designed for making real > copies). > > Any ideas? > > Thanks, > > - Job > > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > From ott at mirix.org Tue Aug 11 18:45:44 2009 From: ott at mirix.org (Matthias-Christian Ott) Date: Tue Aug 11 18:26:18 2009 Subject: [Haskell-cafe] Haskell's type system compared to CLOS In-Reply-To: <4A81EE92.7090906@flippac.org> References: <20090811215740.GA23605@marix> <4A81EE92.7090906@flippac.org> Message-ID: <20090811224543.GA24154@marix> On Tue, Aug 11, 2009 at 11:20:02PM +0100, Philippa Cowderoy wrote: > Matthias-Christian Ott wrote: >> What has Haskell to provide what Common Lisp and Dylan haven't? > Static typing (with inference). Very large difference, that. That's true. This is a big advantage when compiling programmes. But as far as I know type inference is not always decidable in Haskell. Am I right? Dylan does type inference too and Hannes Mehnert is currently working on better type inference for the dylan compiler [1]. Regards, Matthias-Christian [1] https://berlin.ccc.de/wiki/Dem_Compiler_beim_Optimieren_zuschauen From thomas.dubuisson at gmail.com Tue Aug 11 18:46:14 2009 From: thomas.dubuisson at gmail.com (Thomas DuBuisson) Date: Tue Aug 11 18:26:41 2009 Subject: [Haskell-cafe] ANNOUNCE: HacPDX, A Hackathon in Portland Message-ID: <4c44d90b0908111546g5950ace0yc66b6c5d088d6e57@mail.gmail.com> HacPDX is an opportunity for Portland Haskell hackers to join together in building and improving libraries and tools. If you've never been, hackathons are typically not only a good opportunity for experienced devs to work together but also a great way for newcomers to get involved in the community. WHEN Friday Sept 25 3:30PM to 6:00 PM Saturday Sept 26 10:00AM to 6:00 PM Sunday Sept 27 10:00AM to 6:00 PM We can work however late, but tentatively let's plan on eating and sleeping. The Friday times give an opportunity to meet and test your network connectivity, should you so desire. Afterwards we can head out to grab a pint! WHERE We will be in rooom 86-01 (downstairs) of the fourth avenue building (1900 SW 4th Ave), which is part of Portland State University. As the building is locked during the weekends, I'll be letting attendees in via the Harrison Street entrance. EQUIPMENT You should bring a laptop with wireless (802.11). The room has whiteboards and a projector for any discussions or should anyone wish to give a talk. Further Information is available on the wiki [1]. Suggestions, wiki edits, organization and coordination help are all welcome. Thomas DuBuisson [1] http://haskell.org/haskellwiki/HacPDX From cmoore at wamboli.com Tue Aug 11 19:02:32 2009 From: cmoore at wamboli.com (Clint Moore) Date: Tue Aug 11 18:42:58 2009 Subject: [Haskell-cafe] ANNOUNCE: HacPDX, A Hackathon in Portland In-Reply-To: <4c44d90b0908111546g5950ace0yc66b6c5d088d6e57@mail.gmail.com> References: <4c44d90b0908111546g5950ace0yc66b6c5d088d6e57@mail.gmail.com> Message-ID: <157577bd0908111602x46a4edfdyc8c2bf14710daefd@mail.gmail.com> On Tue, Aug 11, 2009 at 3:46 PM, Thomas DuBuisson wrote: > HacPDX is an opportunity for Portland Haskell hackers to join together > in building and improving libraries and tools. ?If you've never been, > hackathons are typically not only a good opportunity for experienced > devs to work together but also a great way for newcomers to get > involved in the community. If anyone in the Seattle area is interested in going and doesn't have a ride, the Bonney Lake Nerd Wagon will be heading down for the event if you want to catch a ride. Get in touch with me for more info. From thomas.dubuisson at gmail.com Tue Aug 11 19:20:56 2009 From: thomas.dubuisson at gmail.com (Thomas DuBuisson) Date: Tue Aug 11 19:01:22 2009 Subject: [Haskell-cafe] Re: ANNOUNCE: HacPDX, A Hackathon in Portland In-Reply-To: <4c44d90b0908111546g5950ace0yc66b6c5d088d6e57@mail.gmail.com> References: <4c44d90b0908111546g5950ace0yc66b6c5d088d6e57@mail.gmail.com> Message-ID: <4c44d90b0908111620h6f55f3bav21e9d28e038b6388@mail.gmail.com> I should have added that I would like to get RSVPs via e-mail so I know to seek a larger room should it be needed. This is stated on the wiki but deserves inclusion with the e-mail. TomMD On Tue, Aug 11, 2009 at 3:46 PM, Thomas DuBuisson wrote: > HacPDX is an opportunity for Portland Haskell hackers to join together > in building and improving libraries and tools. ?If you've never been, > hackathons are typically not only a good opportunity for experienced > devs to work together but also a great way for newcomers to get > involved in the community. > > WHEN > Friday Sept 25 3:30PM to 6:00 PM Saturday Sept 26 10:00AM to 6:00 PM > Sunday Sept 27 10:00AM to 6:00 PM > > We can work however late, but tentatively let's plan on eating and > sleeping. ?The Friday times give an opportunity to meet and test your > network connectivity, should you so desire. Afterwards we can head out > to grab a pint! > > WHERE > We will be in rooom 86-01 (downstairs) of the fourth avenue building > (1900 SW 4th Ave), which is part of Portland State University. ?As the > building is locked during the weekends, I'll be letting attendees in > via the Harrison Street entrance. > > EQUIPMENT > You should bring a laptop with wireless (802.11). The room has > whiteboards and a projector for any discussions or should anyone wish > to give a talk. > > Further Information is available on the wiki [1]. ?Suggestions, wiki > edits, organization and coordination help are all welcome. > > > Thomas DuBuisson > > [1] http://haskell.org/haskellwiki/HacPDX > From explicitcall at googlemail.com Tue Aug 11 19:26:58 2009 From: explicitcall at googlemail.com (Max Desyatov) Date: Tue Aug 11 19:07:29 2009 Subject: [Haskell-cafe] Haskell's type system compared to CLOS In-Reply-To: <20090811224543.GA24154@marix> (Matthias-Christian Ott's message of "Wed, 12 Aug 2009 00:45:44 +0200") References: <20090811215740.GA23605@marix> <4A81EE92.7090906@flippac.org> <20090811224543.GA24154@marix> Message-ID: <87ocqmextp.fsf@zagan.made.you> Matthias-Christian Ott writes: > That's true. This is a big advantage when compiling programmes. But as > far as I know type inference is not always decidable in Haskell. Am I > right? Decidability of type inference depends on features you use (GADTs, type classes etc). Type inference in Haskell doesn't mean you avoid providing type signatures at all costs. It is good programming practice to provide type signatures, as elaborate design of ADTs, type classes you use in your program gives you possibility to encode specification of how program behaves in static, that is type signatures help you to document your code. From mle+hs at mega-nerd.com Tue Aug 11 22:55:33 2009 From: mle+hs at mega-nerd.com (Erik de Castro Lopo) Date: Tue Aug 11 22:36:09 2009 Subject: [Haskell-cafe] Network.Curl and posting XML data Message-ID: <20090812125533.25c29e24.mle+hs@mega-nerd.com> Hi all, I need to do a HTTP post of XML data (Content-type == "text/xml") to a HTTP (eventually HTTPS) server and to retrieve both the response code and some returned XML data. I have had an extensive read of the haskell-curl docs: http://hackage.haskell.org/packages/archive/curl/1.3.5/doc/html/Network-Curl.html as well as playing around with some code, but haskell-curl doesn't seem to support this. I've tried curlPost which along with not returning a response also insists on encoding my XML data as application/x-www-form-urlencoded which simply doesn't work. Anyone ben able to get something like this to work? Are there any alternatives to haskell-curl which will work for my application? Cheers, Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/ From olshanskydr at gmail.com Tue Aug 11 23:39:03 2009 From: olshanskydr at gmail.com (Dmitry Olshansky) Date: Tue Aug 11 23:19:29 2009 Subject: [Haskell-cafe] Network.Curl and posting XML data In-Reply-To: <20090812125533.25c29e24.mle+hs@mega-nerd.com> References: <20090812125533.25c29e24.mle+hs@mega-nerd.com> Message-ID: <741612210908112039n79cad549w200fd522530d2304@mail.gmail.com> Hi, Erik, Did you try Network.HTTP? Is it not enough? 2009/8/12 Erik de Castro Lopo > > Hi all, > > I need to do a HTTP post of XML data (Content-type == "text/xml") to > a HTTP (eventually HTTPS) server and to retrieve both the response > code and some returned XML data. > > I have had an extensive read of the haskell-curl docs: > > > http://hackage.haskell.org/packages/archive/curl/1.3.5/doc/html/Network-Curl.html > > as well as playing around with some code, but haskell-curl doesn't > seem to support this. I've tried curlPost which along with not > returning a response also insists on encoding my XML data as > application/x-www-form-urlencoded which simply doesn't work. > > Anyone ben able to get something like this to work? Are there any > alternatives to haskell-curl which will work for my application? > > Cheers, > Erik > -- > ---------------------------------------------------------------------- > Erik de Castro Lopo > http://www.mega-nerd.com/ > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090811/4708717d/attachment.html From mle+hs at mega-nerd.com Wed Aug 12 00:00:31 2009 From: mle+hs at mega-nerd.com (Erik de Castro Lopo) Date: Tue Aug 11 23:41:13 2009 Subject: [Haskell-cafe] Network.Curl and posting XML data In-Reply-To: <741612210908112039n79cad549w200fd522530d2304@mail.gmail.com> References: <20090812125533.25c29e24.mle+hs@mega-nerd.com> <741612210908112039n79cad549w200fd522530d2304@mail.gmail.com> Message-ID: <20090812140031.a4aa41d1.mle+hs@mega-nerd.com> Dmitry Olshansky wrote: > Did you try Network.HTTP? Is it not enough? I thought Network.HTTP was being deprecated and that Network.Curl was supposed to replace it. Network.HTTP certainly looks like it can do it. Thanks, Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/ From florbitous at gmail.com Wed Aug 12 00:46:18 2009 From: florbitous at gmail.com (Bernie Pope) Date: Wed Aug 12 00:26:44 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? In-Reply-To: References: Message-ID: <4d8ad03a0908112146t4f59900dkf57594e9f274e396@mail.gmail.com> 2009/8/12 Job Vranish : > Does anybody know if there is some unsafe IO function that would let me do > destructive assignment? > Something like: > > a = 5 > main = do > ? veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign a 8 > ? print a >> 8 I doubt you will be able to achieve that in Haskell, but there is another language which does support what you want which is very close to Haskell. It is called Disciple, and there is a compiler for it called DDC: http://www.haskell.org/haskellwiki/DDC DDC is rather young, so it depends on what you are doing as to whether it will fulfil all your needs. Cheers, Bernie. From mle+hs at mega-nerd.com Wed Aug 12 01:18:53 2009 From: mle+hs at mega-nerd.com (Erik de Castro Lopo) Date: Wed Aug 12 00:59:29 2009 Subject: [Haskell-cafe] Network.Curl and posting XML data In-Reply-To: <20090812140031.a4aa41d1.mle+hs@mega-nerd.com> References: <20090812125533.25c29e24.mle+hs@mega-nerd.com> <741612210908112039n79cad549w200fd522530d2304@mail.gmail.com> <20090812140031.a4aa41d1.mle+hs@mega-nerd.com> Message-ID: <20090812151853.a72fc202.mle+hs@mega-nerd.com> Erik de Castro Lopo wrote: > I thought Network.HTTP was being deprecated and that Network.Curl was > supposed to replace it. Cale on IRC pointed out that Network.Curl does more than just HTTP and that Network.HTTP allows more control than Network.Curl. Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/ From ketil at malde.org Wed Aug 12 02:09:54 2009 From: ketil at malde.org (Ketil Malde) Date: Wed Aug 12 01:50:24 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: <20090810140918.GA26102@kira.casa> (Felipe Lessa's message of "Mon\, 10 Aug 2009 11\:09\:18 -0300") References: <87zla73ip7.fsf@malde.org> <20090810140918.GA26102@kira.casa> Message-ID: <87ocqlzhot.fsf@malde.org> Felipe Lessa writes: >> There are some funky Enum instances around: > IMO it's implicit that keys overwrite eachother whenever their > 'fromEnum' is equal, however that may be spoken in the docs. I couldn't find anything explicit in the documentation. I'd suggest a clear note at the top, dismissing the (IMO natural) notion that "EnumMap k v" behaves like "Map k v" (which was true for IntMap and Map Int, I believe). And perhaps also note that you will get exceptions for values outside the Enum range. It strikes me that using Bits instead of Enum might be more likely to be what people want in many cases - but perhaps that would be too slow? Also that Enum really should map to Integer, but again, that's a speed issue.? One could also question the sanity of using e.g. floating point values as keys, but Map supports this, so who am I to judge. (Also, a minor documentation niggle is that Haskell only guarantees 30 bits for an Int, it's GHC that uses Ints of 32 and 64 bits. One could argue that it is the report that should be fixed here, unless one can imagine a program that depends on correct modulo arithmetic with an unknown quotient.) -k ? This of course migth give the careless reader of the Report the impression that the Haskell community values speed over correctness, and thus that we actually are aiming for popularity and mainstream recognition after all. -- If I haven't seen further, it is by standing in the footprints of giants From bugfact at gmail.com Wed Aug 12 05:00:07 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 12 04:40:34 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) Message-ID: I knew about DDC for a while but never bothered to look at it deeply since it was so young, and at first sight it just did what ML did (silently allowing side effects). But when looking again at it, it seems it actually does some very clever things to allow side effects and still be safe, a bit what one does explicitly with Haskell's ST and IO monads, but in DDC, the compiler seems to analyze where side effects happen and automatically annotates/enrich the types (with things like region, closure and effect information) to indicate this. The example given by DDC is that in Haskell, you need two versions of each higher order function if you really want your library to be reuseable, e.g. you need map and mapM, but in DDC you just need one function, map, which also is written in a pure style. See e.g. http://www.haskell.org/haskellwiki/DDC/EffectSystem I kind of agree with the DDC authors here; in Haskell as soon as a function has a side effect, and you want to pass that function to a pure higher order function, you're stuck, you need to pick the monadic version of the higher order function, if it exists. So Haskell doesn't really solve the modularity problem, you need two versions of each higher order function really, and you need to carefully plan ahead of time if you want to write in a monadic or pure style, and it also splits my brain mentally ("side effects are ***evil***. But hang on, how can I e.g. do a depth first search efficiently purely functional? Damn, it seems I can't! Let's switch back to C#/C++!!! Nooooo ;-) This seems to make Haskell not a good language for doing things like extreme programming where code evolves, unless you have some insanely clever refactoring tool ready that can convert pure into monadic functions and vice versa. Is it true that - as in DDC - side effects can be analyzed by the compiler (in the same sense that say, strictness is analyzed), freeing the library and user from writing/picking monadic versions??? If so, would this indeed solve the modularity/reusablity issue? I feel you can't have your cake and eat it here, so there must be catch? :-) Thanks for sharing any thoughts on this, Peter Verswyvelen From perikov at gmail.com Wed Aug 12 05:13:31 2009 From: perikov at gmail.com (Pavel Perikov) Date: Wed Aug 12 04:54:15 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: References: Message-ID: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> > unless you have some insanely > clever refactoring tool ready that can convert pure into monadic > functions and vice versa. Not trying to attack the idea, just some thoughts: I don't see much problem converting pure function into an "effectfull" form :) Having pure function myPureFunction::a1->a2->a3->res .... myPureFunction a1 a2 a3 -- pure call myPureFunction <$> a1 <*> a2 <*> a3 -- call using Applicative Probably, introducing some conventions and using some language extensions you can write a function taking pure function and converting it into monadic version (a-la SPJ' work on polyvariadic composition etc [1]) Have monadic function but needs to call it from pure code? use Control.Monad.Identity. Not a big deal to me but maybe I'm missing the point ----- [1] http://okmij.org/ftp/Haskell/types.html#polyvar-comp From Alistair.Bayley at invesco.com Wed Aug 12 05:26:02 2009 From: Alistair.Bayley at invesco.com (Bayley, Alistair) Date: Wed Aug 12 05:06:40 2009 Subject: [Haskell-cafe] RE: DDC compiler and effects;better than Haskell? In-Reply-To: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> References: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> Message-ID: <125EACD0CAE4D24ABDB4D148C4593DA9110261E5@GBLONXMB02.corp.amvescap.net> > From: haskell-cafe-bounces@haskell.org > [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Pavel Perikov > > > unless you have some insanely > > clever refactoring tool ready that can convert pure into monadic > > functions and vice versa. > > Not trying to attack the idea, just some thoughts: > > I don't see much problem converting pure function into an > "effectfull" > form :) Having pure function > myPureFunction::a1->a2->a3->res > .... > myPureFunction a1 a2 a3 -- pure call > myPureFunction <$> a1 <*> a2 <*> a3 -- call using Applicative > > Probably, introducing some conventions and using some language > extensions you can write a function taking pure function and > converting it into monadic version (a-la SPJ' work on polyvariadic > composition etc [1]) > > Have monadic function but needs to call it from pure code? use > Control.Monad.Identity. > > Not a big deal to me but maybe I'm missing the point In the HaRe catalogue ( http://www.cs.kent.ac.uk/projects/refactor-fp/catalogue/ ) there exists a "Monadification" refactoring: http://www.cs.kent.ac.uk/projects/refactor-fp/catalogue/Monadification1. html 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 bugfact at gmail.com Wed Aug 12 05:27:25 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 12 05:07:51 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> References: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> Message-ID: Well, the point is that you still have monadic and pure programming styles. It's true that applicative style programming can help here, but then you have these <$> and <*> operators everywhere, which also feels like boilerplate code (as you mention, some extensions could help here) Monadic style even has the do syntax, which really looks imperative, while of course, it isn't. I know that for e.g. doing a DFS I can use the ST monad and still be pure, however, my code *looks* imperative when I use the do syntax, which mentally feels weird (maybe it's just me being mentally ill ;-) It's even worse with the arrows syntax: without it I wouldn't be able to write complex Yampa stuff, but the syntax makes me feels that I'm drawing boxes and links using ASCII, and suddenly it *feels* different than when doing "nice" pure / applicative style programming. Again, maybe it's just my brain that is fucked up by 25 years of imperative programming :) So to me, keeping the syntax in a pure style (a bit like ML and F#) plays nicer with my brain. On Wed, Aug 12, 2009 at 11:13 AM, Pavel Perikov wrote: >> unless you have some insanely >> clever refactoring tool ready that can convert pure into monadic >> functions and vice versa. > > Not trying to attack the idea, just some thoughts: > > I don't see much problem converting pure function into an "effectfull" form > :) Having pure function > myPureFunction::a1->a2->a3->res > .... > myPureFunction a1 a2 a3 -- pure call > myPureFunction <$> a1 <*> a2 <*> a3 -- call using Applicative > > Probably, introducing some conventions and using some language extensions > you can write a function taking pure function and converting it into monadic > version (a-la SPJ' work on polyvariadic composition etc [1]) > > Have monadic function but needs to call it from pure code? use > Control.Monad.Identity. > > Not a big deal to me but maybe I'm missing the point > > ----- > [1] http://okmij.org/ftp/Haskell/types.html#polyvar-comp > > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From perikov at gmail.com Wed Aug 12 05:30:46 2009 From: perikov at gmail.com (Pavel Perikov) Date: Wed Aug 12 05:11:14 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: References: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> Message-ID: <5DEC0F62-2944-402C-A62D-84EBACF94690@gmail.com> On 12.08.2009, at 13:27, Peter Verswyvelen wrote: > Well, the point is that you still have monadic and pure programming > styles. It's true that applicative style programming can help here, > but then you have these <$> and <*> operators everywhere, which also > feels like boilerplate code (as you mention, some extensions could > help here) And you have higher-order functions, you're right. My reply was a bit rushed ;) P. > > Monadic style even has the do syntax, which really looks imperative, > while of course, it isn't. > > I know that for e.g. doing a DFS I can use the ST monad and still be > pure, however, my code *looks* imperative when I use the do syntax, > which mentally feels weird (maybe it's just me being mentally ill ;-) > > It's even worse with the arrows syntax: without it I wouldn't be able > to write complex Yampa stuff, but the syntax makes me feels that I'm > drawing boxes and links using ASCII, and suddenly it *feels* different > than when doing "nice" pure / applicative style programming. Again, > maybe it's just my brain that is fucked up by 25 years of imperative > programming :) > > So to me, keeping the syntax in a pure style (a bit like ML and F#) > plays nicer with my brain. > > On Wed, Aug 12, 2009 at 11:13 AM, Pavel Perikov > wrote: >>> unless you have some insanely >>> clever refactoring tool ready that can convert pure into monadic >>> functions and vice versa. >> >> Not trying to attack the idea, just some thoughts: >> >> I don't see much problem converting pure function into an >> "effectfull" form >> :) Having pure function >> myPureFunction::a1->a2->a3->res >> .... >> myPureFunction a1 a2 a3 -- pure call >> myPureFunction <$> a1 <*> a2 <*> a3 -- call using Applicative >> >> Probably, introducing some conventions and using some language >> extensions >> you can write a function taking pure function and converting it >> into monadic >> version (a-la SPJ' work on polyvariadic composition etc [1]) >> >> Have monadic function but needs to call it from pure code? use >> Control.Monad.Identity. >> >> Not a big deal to me but maybe I'm missing the point >> >> ----- >> [1] http://okmij.org/ftp/Haskell/types.html#polyvar-comp >> >> >> >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> From bugfact at gmail.com Wed Aug 12 05:32:29 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 12 05:12:55 2009 Subject: [Haskell-cafe] RE: DDC compiler and effects;better than Haskell? In-Reply-To: <125EACD0CAE4D24ABDB4D148C4593DA9110261E5@GBLONXMB02.corp.amvescap.net> References: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> <125EACD0CAE4D24ABDB4D148C4593DA9110261E5@GBLONXMB02.corp.amvescap.net> Message-ID: Yes, but HaRe *is* extremely clever :-) I just wish I could use it, but since it doesn't support many GHC extensions, I haven't. On Wed, Aug 12, 2009 at 11:26 AM, Bayley, Alistair wrote: >> From: haskell-cafe-bounces@haskell.org >> [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Pavel Perikov >> >> > unless you have some insanely >> > clever refactoring tool ready that can convert pure into monadic >> > functions and vice versa. >> >> Not trying to attack the idea, just some thoughts: >> >> I don't see much problem converting pure function into an >> "effectfull" >> form :) Having pure function >> myPureFunction::a1->a2->a3->res >> .... >> myPureFunction a1 a2 a3 -- pure call >> myPureFunction <$> a1 <*> a2 <*> a3 -- call using Applicative >> >> Probably, introducing some conventions and using some language >> extensions you can write a function taking pure function and >> converting it into monadic version (a-la SPJ' work on polyvariadic >> composition etc [1]) >> >> Have monadic function but needs to call it from pure code? use >> Control.Monad.Identity. >> >> Not a big deal to me but maybe I'm missing the point > > > In the HaRe catalogue ( > http://www.cs.kent.ac.uk/projects/refactor-fp/catalogue/ ) there exists > a "Monadification" refactoring: > > http://www.cs.kent.ac.uk/projects/refactor-fp/catalogue/Monadification1. > html > > 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 bulat.ziganshin at gmail.com Wed Aug 12 05:28:48 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Wed Aug 12 05:14:17 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> References: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> Message-ID: <547910850.20090812132848@gmail.com> Hello Pavel, Wednesday, August 12, 2009, 1:13:31 PM, you wrote: > Have monadic function but needs to call it from pure code? use > Control.Monad.Identity. by monadic function he probably meant ST or IO one, not polymorphic by any monad -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From bugfact at gmail.com Wed Aug 12 05:37:02 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 12 05:17:28 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <547910850.20090812132848@gmail.com> References: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> <547910850.20090812132848@gmail.com> Message-ID: Yes, sorry. But I think I already found the answer to my own question. DDC functions that are lazy don't allow side effects: http://www.haskell.org/haskellwiki/DDC/EvaluationOrder Anyway it would be cool if the DDC EffectSystem would also work on lazy functions :) On Wed, Aug 12, 2009 at 11:28 AM, Bulat Ziganshin wrote: > Hello Pavel, > > Wednesday, August 12, 2009, 1:13:31 PM, you wrote: > >> Have monadic function but needs to call it from pure code? use >> Control.Monad.Identity. > > by monadic function he probably meant ST or IO one, not polymorphic by > any monad > > -- > 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 jwlato at gmail.com Wed Aug 12 05:41:24 2009 From: jwlato at gmail.com (John Lato) Date: Wed Aug 12 05:21:50 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? Message-ID: <9979e72e0908120241s5a0a204s56dd7b11fd8d8afa@mail.gmail.com> Hi Job, I don't think this hypothetical function could exist; you may as well call it "notEverSafeOhTheHumanity" and be done with it. Since Haskell provides no guarantees about when (if ever) any given function/data will be evaluated, you would need some mechanism to tell the compiler that a data chunk has a certain value at one time and a different value at another. The language provides this in the IO (and ST) monads. So the function would need to live within IO, and you don't gain anything. If you try to take it outside of IO, with e.g. unsafePerformIO, then the compiler will no longer treat it like IO and the result is free to be evaluated whenever, so you're back where you started. Also, keep in mind that purity is a language requirement in Haskell and such a function really would "break everything". Specifically, you would get differing output depending on the exact transformations performed by the compiler, which in general would be difficult to predict in advance, probably not the same between different compiler versions, changed by compiler flags and phases of the moon, etc. I have an example in a darcs repo somewhere... Cheers, John > From: Job Vranish > Subject: Re: [Haskell-cafe] unsafeDestructiveAssign? > > Ga! Before to many people start flooding me responses of "This is really > dumb idea don't do it!" I would like to clarify that for the most part > IKnowWhatI'mDoing(TM) > > I am well aware of the usual ST/IORefs as the usual solutions to data > mutability in haskell. > I very very much understand purity, and why it is a good thing, and why we > should try to stay away from IO and ST as much as possible. > I am very much away that even if I had such a function that it will probably > break everything. > I am not just trying to make things run faster. > > What I am trying to do is hyper unusual and I really do need an > unsafeHorribleThings to do it. > > - Job From agocorona at gmail.com Wed Aug 12 06:06:20 2009 From: agocorona at gmail.com (Alberto G. Corona ) Date: Wed Aug 12 05:46:46 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? In-Reply-To: <9979e72e0908120241s5a0a204s56dd7b11fd8d8afa@mail.gmail.com> References: <9979e72e0908120241s5a0a204s56dd7b11fd8d8afa@mail.gmail.com> Message-ID: IMHO (and only IMHO) In a pure context, a copy operation does not make any sense. Why duplicate a chunck of memory whose content is inmutable?. Just create another pointer to it !. If you need to simulate the mutation of a variable in a imperative context, create a new closure and define a new variable with the same name. That is what monads do. In a impure context, use IORefs. 2009/8/12 John Lato > Hi Job, > > I don't think this hypothetical function could exist; you may as well > call it "notEverSafeOhTheHumanity" and be done with it. > > Since Haskell provides no guarantees about when (if ever) any given > function/data will be evaluated, you would need some mechanism to tell > the compiler that a data chunk has a certain value at one time and a > different value at another. The language provides this in the IO (and > ST) monads. So the function would need to live within IO, and you > don't gain anything. If you try to take it outside of IO, with e.g. > unsafePerformIO, then the compiler will no longer treat it like IO and > the result is free to be evaluated whenever, so you're back where you > started. > > Also, keep in mind that purity is a language requirement in Haskell > and such a function really would "break everything". Specifically, > you would get differing output depending on the exact transformations > performed by the compiler, which in general would be difficult to > predict in advance, probably not the same between different compiler > versions, changed by compiler flags and phases of the moon, etc. I > have an example in a darcs repo somewhere... > > Cheers, > John > > > From: Job Vranish > > Subject: Re: [Haskell-cafe] unsafeDestructiveAssign? > > > > Ga! Before to many people start flooding me responses of "This is really > > dumb idea don't do it!" I would like to clarify that for the most part > > IKnowWhatI'mDoing(TM) > > > > I am well aware of the usual ST/IORefs as the usual solutions to data > > mutability in haskell. > > I very very much understand purity, and why it is a good thing, and why > we > > should try to stay away from IO and ST as much as possible. > > I am very much away that even if I had such a function that it will > probably > > break everything. > > I am not just trying to make things run faster. > > > > What I am trying to do is hyper unusual and I really do need an > > unsafeHorribleThings to do it. > > > > - Job > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090812/4cf2c6ac/attachment.html From jules at jellybean.co.uk Wed Aug 12 06:37:31 2009 From: jules at jellybean.co.uk (Jules Bean) Date: Wed Aug 12 06:17:59 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: References: Message-ID: <4A829B6B.90806@jellybean.co.uk> Peter Verswyvelen wrote: > I kind of agree with the DDC authors here; in Haskell as soon as a > function has a side effect, and you want to pass that function to a > pure higher order function, you're stuck, you need to pick the monadic > version of the higher order function, if it exists. I just want to point out that you could *always* use the monadic version. That is, mapM subsumes map. Just use the Identity monad if you don't have anything really monadic going on. The reason we don't is that that looks + feels ugly. Jules From greenrd at greenrd.org Tue Aug 11 16:51:30 2009 From: greenrd at greenrd.org (Robin Green) Date: Wed Aug 12 06:41:02 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: References: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> <547910850.20090812132848@gmail.com> Message-ID: <20090811215130.08602eec@fedora> On Wed, 12 Aug 2009 11:37:02 +0200 Peter Verswyvelen wrote: > Yes, sorry. > > But I think I already found the answer to my own question. > > DDC functions that are lazy don't allow side effects: > http://www.haskell.org/haskellwiki/DDC/EvaluationOrder > > Anyway it would be cool if the DDC EffectSystem would also work on > lazy functions :) As was just pointed out in the unsafeDestructiveAssign thread from which this thread was forked, effects are incompatible with non-strict evaluation. The compiler is supposed to be able to reorder non-strict evaluation to do optimisations, but that can't be done if effects could happen. Also, effects would destroy modular reasoning. -- Robin From bugfact at gmail.com Wed Aug 12 07:09:50 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 12 06:50:16 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <20090811215130.08602eec@fedora> References: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> <547910850.20090812132848@gmail.com> <20090811215130.08602eec@fedora> Message-ID: Is this really the case? Or is just hard to implement? I mean, if...then...else is always kind of lazy in it's 2nd and 3rd argument, but I think DDC handles this correctly even with the presence of side effects (not sure, but it has a little presentation about it: http://cs.anu.edu.au/people/Ben.Lippmeier/talks/poisoning-20090618.pdf) And it's still possible to reason about a function with side effects in DDC since the side effects are visible in the type signature (you might need a good editor that shows you the inferred signatures, as done with F#). I mean it's possible to reason about monadic ST or IO no? I agree it's hard to reason about code that is not honest about side effects in its type signature. So couldn't this be generalized? If might completely miss the point here since I'm not at all academic, I'm an old school imperative hacker. On Tue, Aug 11, 2009 at 10:51 PM, Robin Green wrote: > As was just pointed out in the unsafeDestructiveAssign thread from which > this thread was forked, effects are incompatible with non-strict > evaluation. The compiler is supposed to be able to reorder non-strict > evaluation to do optimisations, but that can't be done if effects > could happen. Also, effects would destroy modular reasoning. > -- > Robin > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From tgdavies at gmail.com Wed Aug 12 07:44:12 2009 From: tgdavies at gmail.com (Tom Davies) Date: Wed Aug 12 07:24:42 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: References: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> <547910850.20090812132848@gmail.com> <20090811215130.08602eec@fedora> Message-ID: On 12/08/2009, at 9:09 PM, Peter Verswyvelen wrote: > Is this really the case? Or is just hard to implement? > > I mean, if...then...else is always kind of lazy in it's 2nd and 3rd > argument, but I think DDC handles this correctly even with the > presence of side effects (not sure, but it has a little presentation > about it: http://cs.anu.edu.au/people/Ben.Lippmeier/talks/poisoning-20090618.pdf) > As I haven't seen it mentioned on this thread: Ben Lippmeier's PhD thesis is available: http://cs.anu.edu.au/~Ben.Lippmeier/project/thesis/thesis-lippmeier-sub.pdf From vanenkj at gmail.com Wed Aug 12 09:16:24 2009 From: vanenkj at gmail.com (John Van Enk) Date: Wed Aug 12 08:56:51 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: <87ocqlzhot.fsf@malde.org> References: <87zla73ip7.fsf@malde.org> <20090810140918.GA26102@kira.casa> <87ocqlzhot.fsf@malde.org> Message-ID: On Wed, Aug 12, 2009 at 2:09 AM, Ketil Malde wrote: > Felipe Lessa writes: > >>> There are some funky Enum instances around: > >> IMO it's implicit that keys overwrite eachother whenever their >> 'fromEnum' is equal, however that may be spoken in the docs. > > I couldn't find anything explicit in the documentation. ?I'd suggest a > clear note at the top, dismissing the (IMO natural) notion that > "EnumMap k v" behaves like "Map k v" (which was true for IntMap and > Map Int, I believe). I haven't updated any of the documentation from IntMap over s/IntMap/EnumMap/g. > > And perhaps also note that you will get exceptions for values outside > the Enum range. > I'd think that part is obvious. > It strikes me that using Bits instead of Enum might be more likely to > be what people want in many cases - but perhaps that would be too slow? > Also that Enum really should map to Integer, but again, that's a speed > issue.? > I think Enum is a little more natural--perhaps I'm wrong. From derek.a.elkins at gmail.com Wed Aug 12 09:34:28 2009 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Wed Aug 12 09:14:53 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <20090811215130.08602eec@fedora> References: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> <547910850.20090812132848@gmail.com> <20090811215130.08602eec@fedora> Message-ID: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> On Tue, Aug 11, 2009 at 3:51 PM, Robin Green wrote: > On Wed, 12 Aug 2009 11:37:02 +0200 > Peter Verswyvelen wrote: > >> Yes, sorry. >> >> But I think I already found the answer to my own question. >> >> DDC functions that are lazy don't allow side effects: >> http://www.haskell.org/haskellwiki/DDC/EvaluationOrder >> >> Anyway it would be cool if the DDC EffectSystem would also work on >> lazy functions :) > > As was just pointed out in the unsafeDestructiveAssign thread from which > this thread was forked, effects are incompatible with non-strict > evaluation. No, they aren't. At least, they aren't in any technical way. There have been more than a few languages supporting both laziness and mutation starting with Algol. > The compiler is supposed to be able to reorder non-strict > evaluation to do optimisations, but that can't be done if effects > could happen. There's nothing special about non-strict evaluation that makes the antecedent true. Replacing "non-strict" with "strict" gives just as much of a valid statement. It is purity that allows (some) reordering of evaluation. > Also, effects would destroy modular reasoning. Again, it is purity, not laziness, that allows compositional reasoning. Effects destroy compositional reasoning in a strict language just as much. From derek.a.elkins at gmail.com Wed Aug 12 09:39:56 2009 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Wed Aug 12 09:20:21 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? In-Reply-To: <9979e72e0908120241s5a0a204s56dd7b11fd8d8afa@mail.gmail.com> References: <9979e72e0908120241s5a0a204s56dd7b11fd8d8afa@mail.gmail.com> Message-ID: <61f84eff0908120639t52e54ae1xf6d3235c60c8d938@mail.gmail.com> On Wed, Aug 12, 2009 at 4:41 AM, John Lato wrote: > Hi Job, > > I don't think this hypothetical function could exist; you may as well > call it ?"notEverSafeOhTheHumanity" and be done with it. > > Since Haskell provides no guarantees about when (if ever) any given > function/data will be evaluated, you would need some mechanism to tell > the compiler that a data chunk has a certain value at one time and a > different value at another. ?The language provides this in the IO (and > ST) monads. ?So the function would need to live within IO, and you > don't gain anything. ?If you try to take it outside of IO, with e.g. > unsafePerformIO, then the compiler will no longer treat it like IO and > the result is free to be evaluated whenever, so you're back where you > started. > > Also, keep in mind that purity is a language requirement in Haskell > and such a function really would "break everything". ?Specifically, > you would get differing output depending on the exact transformations > performed by the compiler, which in general would be difficult to > predict in advance, probably not the same between different compiler > versions, changed by compiler flags and phases of the moon, etc. ?I > have an example in a darcs repo somewhere... > > Cheers, > John > >> From: Job Vranish >> Subject: Re: [Haskell-cafe] unsafeDestructiveAssign? >> >> Ga! Before to many people start flooding me responses of "This is really >> dumb idea don't do it!" I would like to clarify that for the most part >> IKnowWhatI'mDoing(TM) >> >> I am well aware of the usual ST/IORefs as the usual solutions to data >> mutability in haskell. >> I very very much understand purity, and why it is a good thing, and why we >> should try to stay away from IO and ST as much as possible. >> I am very much away that even if I had such a function that it will probably >> break everything. >> I am not just trying to make things run faster. >> >> What I am trying to do is hyper unusual and I really do need an >> unsafeHorribleThings to do it. >> >> - Job (To Alberto as well.) Unsurprisingly, Lennart stated the real issue, but I'll re-emphasize it. As much trouble as such a profound violation of purity would cause, it's not the biggest problem. If that were all, you could easily write a C/assembly function that would do what was desired. The real problem is that there isn't necessarily any "data chunk" at all, i.e. there may not be anything to mutate. From mauricio.antunes at gmail.com Wed Aug 12 10:11:00 2009 From: mauricio.antunes at gmail.com (=?ISO-8859-1?Q?Maur=ED=ADcio_CA?=) Date: Wed Aug 12 09:51:37 2009 Subject: [Haskell-cafe] Finalizers on FunPtrs Message-ID: I see in Foreign.Ptr documentation that it is good practice to call freeHaskellFunPtr when a pointer to a Haskell function (obtained using 'dynamic' stubs) is not going to be used anymore. Is it possible to do that in a way that is similar to ForeignPtr behavior, where pointers are finalized when GC knows they're not going to be used anymore? See this attempt: In an IO monad: a <- giveMeFunPtr b <- castFunPtrToPtr a :: IO (Ptr something) foreignFunPtr <- newForeignPtr funPtrFinalizer b :: IO (ForeignPtr something) With funPtrFinalizer a FunPtr to: baseFunPtrFinalizer p = freeHaskellFunPtr . castPtrToFunPtr p Is something like that expected to work, i.e., would I get a ForeignPtr that I could cast and give to foreign functions, and still expect that my function pointer would be freed when not needed anymore? Thanks, Maur?cio From john at n-brain.net Wed Aug 12 10:12:14 2009 From: john at n-brain.net (John A. De Goes) Date: Wed Aug 12 09:52:44 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> References: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> <547910850.20090812132848@gmail.com> <20090811215130.08602eec@fedora> <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> Message-ID: On Aug 12, 2009, at 7:34 AM, Derek Elkins wrote: > Again, it is purity, not laziness, that allows compositional > reasoning. Effects destroy compositional reasoning in a strict > language just as much. Yes, but that's just as much true in the IO monad as in effectful code in DDC. I think the point is that a functional language with a built- in effect system that captures the nature of effects is pretty damn cool and eliminates a lot of boilerplate. Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 From dagit at codersbase.com Wed Aug 12 10:20:21 2009 From: dagit at codersbase.com (Jason Dagit) Date: Wed Aug 12 10:00:50 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> References: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> <547910850.20090812132848@gmail.com> <20090811215130.08602eec@fedora> <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> Message-ID: On Wed, Aug 12, 2009 at 6:34 AM, Derek Elkins wrote: > > Again, it is purity, not laziness, that allows compositional > reasoning. Effects destroy compositional reasoning in a strict > language just as much. Totality also matters, but for some reason we take that for granted :) Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090812/00df767f/attachment.html From greenrd at greenrd.org Tue Aug 11 20:16:56 2009 From: greenrd at greenrd.org (Robin Green) Date: Wed Aug 12 10:13:12 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> References: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> <547910850.20090812132848@gmail.com> <20090811215130.08602eec@fedora> <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> Message-ID: <20090812011656.200a0dc6@fedora> On Wed, 12 Aug 2009 08:34:28 -0500 Derek Elkins wrote: > On Tue, Aug 11, 2009 at 3:51 PM, Robin Green > wrote: > > On Wed, 12 Aug 2009 11:37:02 +0200 > > Peter Verswyvelen wrote: > > > >> Yes, sorry. > >> > >> But I think I already found the answer to my own question. > >> > >> DDC functions that are lazy don't allow side effects: > >> http://www.haskell.org/haskellwiki/DDC/EvaluationOrder > >> > >> Anyway it would be cool if the DDC EffectSystem would also work on > >> lazy functions :) > > > > As was just pointed out in the unsafeDestructiveAssign thread from > > which this thread was forked, effects are incompatible with > > non-strict evaluation. > > No, they aren't. At least, they aren't in any technical way. There > have been more than a few languages supporting both laziness and > mutation starting with Algol. OK, explicitly creating thunks, like in Algol, LISP and CAL, can work, because you can either prevent the programmer from using mutation inside a thunk (as in the CAL approach), or rely on the programmer to ensure that mutations are only done in a safe order (as in the "callback as thunk" approach, which can be done in almost any impure language). But if almost *every* expression is a thunk, as in a non-strict language like Haskell, and if moreover evaluation order can differ depending on the compiler/interpreter, or compiler version, or compiler flags, it becomes impractical to combine them. So yes, I agree, it's not an absolute technical incompatibility, it's a practical one. > > Also, effects would destroy modular reasoning. > > Again, it is purity, not laziness, that allows compositional > reasoning. Effects destroy compositional reasoning in a strict > language just as much. Not really - in a strict language, if in method M action A always happens before action B, then that fact will remain true in whichever context M is called (ignoring threading issues). In a non-strict, impure language, assuming monads are not used, if you have a function f which performs actions A and B, and two other functions g and h which both call f, the actions could happen in one order in g, and in the opposite order - or not at all - in h, because of a difference in data demanded by each function. Indeed, unless g and h are "top-level" functions (in the sense that they are main functions or invoked from some ghci-equivalent) the notion of "the" order the actions are performed in is ill-defined, because it could vary depending on which function g or h is being called from. Now, you could say, the strict order of evaluation can be simulated in a non-strict language on a case-by-case basis by using monads or whatever. Well, yes, but that would be missing the point, because the original point of this discussion was to avoid having to use monads. -- Robin From jvranish at gmail.com Wed Aug 12 10:36:36 2009 From: jvranish at gmail.com (Job Vranish) Date: Wed Aug 12 10:17:02 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? In-Reply-To: <4d8ad03a0908112146t4f59900dkf57594e9f274e396@mail.gmail.com> References: <4d8ad03a0908112146t4f59900dkf57594e9f274e396@mail.gmail.com> Message-ID: Yeah I'm thinking that even if I had such a function, it might be impossible to make it play nicely. I think I can do a restricted form of what I want with STRefs and StableNames (still dangerous) so I think I'll stick with that at least while experimenting in haskell. DCC looks extremely interesting! In fact it looks like I can do what I'm wanting out of the box! I will definitely have to experiment with it :) Thanks, On Wed, Aug 12, 2009 at 12:46 AM, Bernie Pope wrote: > 2009/8/12 Job Vranish : > > Does anybody know if there is some unsafe IO function that would let me > do > > destructive assignment? > > Something like: > > > > a = 5 > > main = do > > veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign a 8 > > print a > >> 8 > > I doubt you will be able to achieve that in Haskell, but there is > another language which does support what you want which is very close > to Haskell. It is called Disciple, and there is a compiler for it > called DDC: > > http://www.haskell.org/haskellwiki/DDC > > DDC is rather young, so it depends on what you are doing as to whether > it will fulfil all your needs. > > Cheers, > Bernie. > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090812/bc0a48db/attachment.html From dave at zednenem.com Wed Aug 12 11:15:36 2009 From: dave at zednenem.com (David Menendez) Date: Wed Aug 12 10:56:02 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> References: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> <547910850.20090812132848@gmail.com> <20090811215130.08602eec@fedora> <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> Message-ID: <49a77b7a0908120815h71e97b60w9ad6f3e9232865f@mail.gmail.com> On Wed, Aug 12, 2009 at 9:34 AM, Derek Elkins wrote: > On Tue, Aug 11, 2009 at 3:51 PM, Robin Green wrote: >> On Wed, 12 Aug 2009 11:37:02 +0200 >> Peter Verswyvelen wrote: >> >>> Yes, sorry. >>> >>> But I think I already found the answer to my own question. >>> >>> DDC functions that are lazy don't allow side effects: >>> http://www.haskell.org/haskellwiki/DDC/EvaluationOrder >>> >>> Anyway it would be cool if the DDC EffectSystem would also work on >>> lazy functions :) >> >> As was just pointed out in the unsafeDestructiveAssign thread from which >> this thread was forked, effects are incompatible with non-strict >> evaluation. > > No, they aren't. ?At least, they aren't in any technical way. ?There > have been more than a few languages supporting both laziness and > mutation starting with Algol. As far as I know, Algol had call-by-name, not call-by-need. -- Dave Menendez From dave at zednenem.com Wed Aug 12 11:34:06 2009 From: dave at zednenem.com (David Menendez) Date: Wed Aug 12 11:14:31 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: References: <87zla73ip7.fsf@malde.org> <20090810140918.GA26102@kira.casa> <87ocqlzhot.fsf@malde.org> Message-ID: <49a77b7a0908120834g3369a8e2l4082a45ca5c15e89@mail.gmail.com> On Wed, Aug 12, 2009 at 9:16 AM, John Van Enk wrote: > On Wed, Aug 12, 2009 at 2:09 AM, Ketil Malde wrote: >> >> And perhaps also note that you will get exceptions for values outside >> the Enum range. >> > > I'd think that part is obvious. That depends on what "outside the Enum range" means. You'll get an exception if you somehow get an Int key in the map which doesn't correspond to any value in the enum, but you don't get an exception if you try to pass in, say, a large Integer. Prelude> fromEnum (2^32) 0 In essence, you're using Enum as a hash function, but not making any provision for hash collisions. -- Dave Menendez From vanenkj at gmail.com Wed Aug 12 12:07:28 2009 From: vanenkj at gmail.com (John Van Enk) Date: Wed Aug 12 11:47:55 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: <49a77b7a0908120834g3369a8e2l4082a45ca5c15e89@mail.gmail.com> References: <87zla73ip7.fsf@malde.org> <20090810140918.GA26102@kira.casa> <87ocqlzhot.fsf@malde.org> <49a77b7a0908120834g3369a8e2l4082a45ca5c15e89@mail.gmail.com> Message-ID: On Wed, Aug 12, 2009 at 11:34 AM, David Menendez wrote: > On Wed, Aug 12, 2009 at 9:16 AM, John Van Enk wrote: >> On Wed, Aug 12, 2009 at 2:09 AM, Ketil Malde wrote: >>> >>> And perhaps also note that you will get exceptions for values outside >>> the Enum range. >>> >> >> I'd think that part is obvious. > > That depends on what "outside the Enum range" means. You'll get an > exception if you somehow get an Int key in the map which doesn't > correspond to any value in the enum... We should be protected by the type system against unmatched Int's in the map as long as you have sane Enum instances. > ... but you don't get an exception if > you try to pass in, say, a large Integer. > Prelude> fromEnum (2^32) > 0 > > In essence, you're using Enum as a hash function, but not making any > provision for hash collisions. > Unless I'm mistaken, the Enum typeclass _is_ a hash function who's keyspace is the range of Int that doesn't make any provisions for collisions. From dave at zednenem.com Wed Aug 12 12:58:40 2009 From: dave at zednenem.com (David Menendez) Date: Wed Aug 12 12:39:05 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: References: <87zla73ip7.fsf@malde.org> <20090810140918.GA26102@kira.casa> <87ocqlzhot.fsf@malde.org> <49a77b7a0908120834g3369a8e2l4082a45ca5c15e89@mail.gmail.com> Message-ID: <49a77b7a0908120958t6e3f8a34u88e45a3ab43537fe@mail.gmail.com> On Wed, Aug 12, 2009 at 12:07 PM, John Van Enk wrote: > On Wed, Aug 12, 2009 at 11:34 AM, David Menendez wrote: >> On Wed, Aug 12, 2009 at 9:16 AM, John Van Enk wrote: >>> On Wed, Aug 12, 2009 at 2:09 AM, Ketil Malde wrote: >>>> >>>> And perhaps also note that you will get exceptions for values outside >>>> the Enum range. >>>> >>> >>> I'd think that part is obvious. >> >> That depends on what "outside the Enum range" means. You'll get an >> exception if you somehow get an Int key in the map which doesn't >> correspond to any value in the enum... > > We should be protected by the type system against unmatched Int's in > the map as long as you have sane Enum instances. One would hope so. >> ... but you don't get an exception if >> you try to pass in, say, a large Integer. >> Prelude> fromEnum (2^32) >> 0 >> >> In essence, you're using Enum as a hash function, but not making any >> provision for hash collisions. >> > > Unless I'm mistaken, the Enum typeclass _is_ a hash function who's > keyspace is the range of Int that doesn't make any provisions for > collisions. Hash functions traditionally map integers to integers, so I would describe fromEnum as "like" a hash function, but that's not important. And yes, hash functions collide, which is why hash tables employ various methods for distinguishing keys that hash to the same values. EnumMap silently passes this responsibility to the user, without even a note in the documentation. -- Dave Menendez From vanenkj at gmail.com Wed Aug 12 13:03:55 2009 From: vanenkj at gmail.com (John Van Enk) Date: Wed Aug 12 12:44:20 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: <49a77b7a0908120958t6e3f8a34u88e45a3ab43537fe@mail.gmail.com> References: <87zla73ip7.fsf@malde.org> <20090810140918.GA26102@kira.casa> <87ocqlzhot.fsf@malde.org> <49a77b7a0908120834g3369a8e2l4082a45ca5c15e89@mail.gmail.com> <49a77b7a0908120958t6e3f8a34u88e45a3ab43537fe@mail.gmail.com> Message-ID: > EnumMap silently passes this responsibility to the user, without even a note in the documentation. Like I've said, I made no modifications to the documentation other than replacing IntMap with EnumMap. Should the community show more interest in the EnumMap, such a change will show up in the docs. On Wed, Aug 12, 2009 at 12:58 PM, David Menendez wrote: > On Wed, Aug 12, 2009 at 12:07 PM, John Van Enk wrote: >> On Wed, Aug 12, 2009 at 11:34 AM, David Menendez wrote: >>> On Wed, Aug 12, 2009 at 9:16 AM, John Van Enk wrote: >>>> On Wed, Aug 12, 2009 at 2:09 AM, Ketil Malde wrote: >>>>> >>>>> And perhaps also note that you will get exceptions for values outside >>>>> the Enum range. >>>>> >>>> >>>> I'd think that part is obvious. >>> >>> That depends on what "outside the Enum range" means. You'll get an >>> exception if you somehow get an Int key in the map which doesn't >>> correspond to any value in the enum... >> >> We should be protected by the type system against unmatched Int's in >> the map as long as you have sane Enum instances. > > One would hope so. > >>> ... but you don't get an exception if >>> you try to pass in, say, a large Integer. >>> Prelude> fromEnum (2^32) >>> 0 >>> >>> In essence, you're using Enum as a hash function, but not making any >>> provision for hash collisions. >>> >> >> Unless I'm mistaken, the Enum typeclass _is_ a hash function who's >> keyspace is the range of Int that doesn't make any provisions for >> collisions. > > Hash functions traditionally map integers to integers, so I would > describe fromEnum as "like" a hash function, but that's not important. > > And yes, hash functions collide, which is why hash tables employ > various methods for distinguishing keys that hash to the same values. > EnumMap silently passes this responsibility to the user, without even > a note in the documentation. > > -- > Dave Menendez > > From vanenkj at gmail.com Wed Aug 12 13:05:08 2009 From: vanenkj at gmail.com (John Van Enk) Date: Wed Aug 12 12:45:32 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: <87ocqlzhot.fsf@malde.org> References: <87zla73ip7.fsf@malde.org> <20090810140918.GA26102@kira.casa> <87ocqlzhot.fsf@malde.org> Message-ID: > It strikes me that using Bits instead of Enum might be more likely to be what people want in many cases It wouldn't hurt for you (or someone) to implement this. I'm sure it would be useful. On Wed, Aug 12, 2009 at 2:09 AM, Ketil Malde wrote: > Felipe Lessa writes: > >>> There are some funky Enum instances around: > >> IMO it's implicit that keys overwrite eachother whenever their >> 'fromEnum' is equal, however that may be spoken in the docs. > > I couldn't find anything explicit in the documentation. ?I'd suggest a > clear note at the top, dismissing the (IMO natural) notion that > "EnumMap k v" behaves like "Map k v" (which was true for IntMap and > Map Int, I believe). > > And perhaps also note that you will get exceptions for values outside > the Enum range. > > It strikes me that using Bits instead of Enum might be more likely to > be what people want in many cases - but perhaps that would be too slow? > Also that Enum really should map to Integer, but again, that's a speed > issue.? > > One could also question the sanity of using e.g. floating point values > as keys, but Map supports this, so who am I to judge. > > (Also, a minor documentation niggle is that Haskell only guarantees 30 > bits for an Int, it's GHC that uses Ints of 32 and 64 bits. ?One could > argue that it is the report that should be fixed here, unless one can > imagine a program that depends on correct modulo arithmetic with an > unknown quotient.) > > -k > > ? This of course migth give the careless reader of the Report the > impression that the Haskell community values speed over correctness, > and thus that we actually are aiming for popularity and mainstream > recognition after all. > -- > 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 > From felipe.lessa at gmail.com Wed Aug 12 13:13:44 2009 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Wed Aug 12 12:54:14 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> References: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> <547910850.20090812132848@gmail.com> <20090811215130.08602eec@fedora> <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> Message-ID: <20090812171344.GA9018@kira.casa> On Wed, Aug 12, 2009 at 08:34:28AM -0500, Derek Elkins wrote: > > As was just pointed out in the unsafeDestructiveAssign thread from which > > this thread was forked, effects are incompatible with non-strict > > evaluation. > > No, they aren't. At least, they aren't in any technical way. There > have been more than a few languages supporting both laziness and > mutation starting with Algol. But laziness is just one way of implementing non-strictness, right? What about others methods? -- Felipe. From jwlato at gmail.com Wed Aug 12 13:48:33 2009 From: jwlato at gmail.com (John Lato) Date: Wed Aug 12 13:28:58 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? In-Reply-To: <61f84eff0908120639t52e54ae1xf6d3235c60c8d938@mail.gmail.com> References: <9979e72e0908120241s5a0a204s56dd7b11fd8d8afa@mail.gmail.com> <61f84eff0908120639t52e54ae1xf6d3235c60c8d938@mail.gmail.com> Message-ID: <9979e72e0908121048i40f19c0aw3012b00ee177da01@mail.gmail.com> On Wed, Aug 12, 2009 at 2:39 PM, Derek Elkins wrote: > > (To Alberto as well.) > > Unsurprisingly, Lennart stated the real issue, but I'll re-emphasize > it. ?As much trouble as such a profound violation of purity would > cause, it's not the biggest problem. ?If that were all, you could > easily write a C/assembly function that would do what was desired. > The real problem is that there isn't necessarily any "data chunk" at > all, i.e. there may not be anything to mutate. > Lennart is right of course, but wouldn't his example just be a specific case of my argument? That is, the compiler decided to evaluate the data at compile time by replacing it with the primitive value and inlining it? It seems to me that in the absence of putting some scope or sequencing upon the mutating function, there's no way for such an unsafeMutate* to have any defined meaning in Haskell. And once you have provided either scope or evaluation order, it would be equivalent to just using a monad (although not necessarily IO). Which leads to the point I really want to make. Would a monad other than IO be acceptable? You could provide this functionality with a Reader's 'local' function for example, or with State. Cheers, John From ravi_n at alum.mit.edu Wed Aug 12 14:08:26 2009 From: ravi_n at alum.mit.edu (Ravi Nanavati) Date: Wed Aug 12 13:48:50 2009 Subject: [Haskell-cafe] Next BostonHaskell meeting: August 18th at MIT Message-ID: <161d443c0908121108y4f69ac4aq9c30f13a58c9690@mail.gmail.com> I'm pleased to announce the August meeting of the Boston Area Haskell Users' Group. Based on the feedback from the July meeting and the constraints of our speakers, the August meeting has been scheduled for Tuesday, August 18th from 6:30pm - 8:30pm. Like the past two meetings, it will be held in the MIT CSAIL Reading Room (32-G882, i.e. a room on the 8th floor of the Gates Tower of the MIT's Stata Center at 32 Vassar St in Cambridge, MA). We're making a slight departure from our meeting format this month. Our featured speaker will be Edward Kmett, who will be sharing a two-part presentation focusing on monoids and parsing. The first part of Edward's presentation is titled "Introduction to Monoids". After the first part of Edward's presentation, Shae Erisson will be presenting short overview of Haskell and emacs integration. Following Shae, Paul Chiusano will be talking briefly about functional programming opportunities at ClariFI (the job advertisement he recently posted to the BostonHaskell list). Paul is planning to be available to talk to anyone interested during our customary break. As you might guess, there isn't really room for Lightning Talks or other advertisements in August, but please feel free to contact me if you have something you'd like to talk about at a future meeting (since we're still very hungry for content for future meetings). After the break, Edward will be picking up with the second part of his presentation: "A Parallel Parsing Trifecta: Iteratees, Parsec, and Monoids". We're trying a new attendance poll this month: http://doodle.com/participation.html?pollId=x8rbbbprtezdtaan As before, responding to this poll will help with two things: 1. Getting an idea of what fraction of the Boston-area Haskell community can and can't attend this meeting (to help with future scheduling). 2. Giving me an estimated count of attendees, since I have talked my wife into baking some more goodies and bringing drinks again. Sponsorship of or other assistance with refreshments is still being eagerly solicited. I'm also still having trouble embedding this poll in a page on our Google Group, so if anyone has any ideas about that, please feel free to try (any group member can edit pages) and/or offer other assistance or suggestions. If you have any questions about the meeting please send them to the BostonHaskell mailing list: bostonhaskell@googlegroups.com or contact me directly. I look forward to seeing many Boston-area Haskellers at the August meeting! Thank you, - Ravi Nanavati From andrewcoppin at btinternet.com Wed Aug 12 14:24:00 2009 From: andrewcoppin at btinternet.com (Andrew Coppin) Date: Wed Aug 12 14:04:19 2009 Subject: [Haskell-cafe] Examples In-Reply-To: <7687290b0908091629l69722760s62df26fd7b3361ff@mail.gmail.com> References: <4A7D617E.9010103@btinternet.com> <7687290b0908091629l69722760s62df26fd7b3361ff@mail.gmail.com> Message-ID: <4A8308C0.9080207@btinternet.com> John D. Ramsdell wrote: >> Usually I include the example program in the package, but make its compilation conditional using a Cabal flag like buildExamples. >> > > But then the binaries generated from the example program get > installed. I think the poster wants to share the source code, not > install a demo. > Indeed yes. Example programs that don't really "do" anything exciting, but show you what kind of program structure you need to use and which functions to read up on to get your bearings. Since nobody else seems to have mentioned it yet: Another possibility is to embed [short!] examples into the Haddock documentation. For example, Control.Monad.Reader has several pages of example code at the bottom of the Haddock page. I am ambivilent as to whether this is a good or bad idea... > I haven't figure out a way to specify test programs that don't get > installed, but are only intended to be built and run within the > context of a source distribution. > Yes, I was going to ask about that too - but that's a seperate question. ;-) From korpios at korpios.com Wed Aug 12 15:13:37 2009 From: korpios at korpios.com (Tom Tobin) Date: Wed Aug 12 14:54:01 2009 Subject: [Haskell-cafe] Chicago Haskell User Group? Message-ID: There isn't a Chicago-area Haskell group, is there? If not, would anyone be interested in forming one? I used to run Chicago's Django (a Python web framework) group, but lost interest (and since I lived in the suburbs back then, got sick of the commute). Unlike Python, I'm still very much a beginner with Haskell, so I feel I'd be able to benefit quite a bit from picking the brains of more skilled users and cooperating with other beginners. My particular interests are web development (as that's my professional field) and multimedia organization (I'm working on a Haskell audio tagging library to help teach myself the language), but I'm open to learning just about anything. :-) From dons at galois.com Wed Aug 12 15:40:36 2009 From: dons at galois.com (Don Stewart) Date: Wed Aug 12 15:23:06 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: References: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> Message-ID: <20090812194036.GF29909@whirlpool.galois.com> bugfact: > Well, the point is that you still have monadic and pure programming > styles. It's true that applicative style programming can help here, > but then you have these <$> and <*> operators everywhere, which also > feels like boilerplate code (as you mention, some extensions could > help here) Overloading whitespace as application in the Identity idiom! :) -- Do From patai_gergely at fastmail.fm Wed Aug 12 16:01:12 2009 From: patai_gergely at fastmail.fm (Patai Gergely) Date: Wed Aug 12 15:41:40 2009 Subject: [Haskell-cafe] Working around file locking in Windows Message-ID: <1250107272.14592.1329564085@webmail.messagingengine.com> Hello all, I'm trying to make the hp2any suite to be fully functional under Windows, but I'm running into permission errors when I try to read the heap profile that's still being written by its producer. Is there a way to solve this problem without turning to the Win32 interface and having to write platform specific code? Gergely -- http://www.fastmail.fm - One of many happy users: http://www.fastmail.fm/docs/quotes.html From conor at strictlypositive.org Wed Aug 12 16:16:49 2009 From: conor at strictlypositive.org (Conor McBride) Date: Wed Aug 12 15:57:25 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <20090812194036.GF29909@whirlpool.galois.com> References: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> <20090812194036.GF29909@whirlpool.galois.com> Message-ID: On 12 Aug 2009, at 20:40, Don Stewart wrote: > bugfact: >> Well, the point is that you still have monadic and pure programming >> styles. It's true that applicative style programming can help here, >> but then you have these <$> and <*> operators everywhere, which also >> feels like boilerplate code (as you mention, some extensions could >> help here) > > Overloading whitespace as application in the Identity idiom! :) [cough!] Conor psst: http://personal.cis.strath.ac.uk/~conor/pub/she/idiom.html From dons at galois.com Wed Aug 12 16:16:56 2009 From: dons at galois.com (Don Stewart) Date: Wed Aug 12 15:59:27 2009 Subject: [Haskell-cafe] Database written in Haskell? In-Reply-To: <4A7CBC32.7090201@alexjacobson.com> References: <4A7CBC32.7090201@alexjacobson.com> Message-ID: <20090812201656.GM29909@whirlpool.galois.com> Give it a cool name like SlothDB or something :) -- Don alex: > HAppS' IxSet library gives relational operations but does not have a SQL > interface. Am thinking of changing the name to RelSet to make the > functionality clear. You can use HAppS.State to give ACID properties > to operations on this data structure. > > -Alex- > > On 8/1/09 12:15 AM, G?nther Schmidt wrote: >> Hi, >> >> is there an SQL database written in Haskell like HSQLDB which is >> written in Java? >> >> G?nther >> >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From dons at galois.com Wed Aug 12 17:03:18 2009 From: dons at galois.com (Don Stewart) Date: Wed Aug 12 16:45:48 2009 Subject: [Haskell-cafe] GSoC profiling project to be wrapped up In-Reply-To: <1250019999.30414.1329375813@webmail.messagingengine.com> References: <1250019999.30414.1329375813@webmail.messagingengine.com> Message-ID: <20090812210318.GY29909@whirlpool.galois.com> patai_gergely: > Hi everyone, > > I finally uploaded the profiling tools to Hackage. The package names are > hp2any-{core,graph,manager}. The first two should be possible to install > right away, while the manager needs Gtk2Hs. A bit more on the project > and this update at . > Do you have an overview somewhere of the tools and how to use them? -- Don From patai_gergely at fastmail.fm Wed Aug 12 17:27:05 2009 From: patai_gergely at fastmail.fm (Patai Gergely) Date: Wed Aug 12 17:07:29 2009 Subject: [Haskell-cafe] GSoC profiling project to be wrapped up In-Reply-To: <20090812210318.GY29909@whirlpool.galois.com> References: <1250019999.30414.1329375813@webmail.messagingengine.com> <20090812210318.GY29909@whirlpool.galois.com> Message-ID: <1250112425.1334.1329578005@webmail.messagingengine.com> > Do you have an overview somewhere of the tools and how to use them? Well, not really. While there is some basic information on the project wiki at Google Code, it is rather outdated. So probably the blog comes closest to that, but it also concentrates on the details. I intend to extract the bits of documentation found in the individual packages and unite them in one piece for online reading. Gergely -- http://www.fastmail.fm - Faster than the air-speed velocity of an unladen european swallow From dan.doel at gmail.com Wed Aug 12 17:28:41 2009 From: dan.doel at gmail.com (Dan Doel) Date: Wed Aug 12 17:09:09 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> Message-ID: <200908121728.41807.dan.doel@gmail.com> On Wednesday 12 August 2009 10:12:14 am John A. De Goes wrote: > I think the point is that a functional language with a built- > in effect system that captures the nature of effects is pretty damn > cool and eliminates a lot of boilerplate. It's definitely an interesting direction (possibly even the right one in the long run), but it's not without its faults currently (unless things have changed since I looked at it). For instance: what effects does disciple support? Mutation and IO? What if I want non-determinism, or continuations, etc.? How do I as a user add those effects to the effect system, and specify how they should interact with the other effects? As far as I know, there aren't yet any provisions for this, so presumably you'll end up with effect system for effects supported by the compiler, and monads for effects you're writing yourself. By contrast, monad transformers (for one) let you do the above defining of new effects, and specifying how they interact (although they're certainly neither perfect, nor completely satisfying theoretically). Someone will probably eventually create (or already has, and I don't know about it) an extensible effect system that would put this objection to rest. Until then, you're dealing in trade offs. -- Dan From jeremy at n-heptane.com Wed Aug 12 17:45:43 2009 From: jeremy at n-heptane.com (Jeremy Shaw) Date: Wed Aug 12 17:26:06 2009 Subject: [Haskell-cafe] Chicago Haskell User Group? In-Reply-To: References: Message-ID: <877hx8hfjs.wl%jeremy@n-heptane.com> Hello, Sounds good to me. I am in the Chicago area and do Haskell-based web development all day, every day, using the Happstack platform. I don't have much time to organize, but I would be able to attend meetings and give some presentations. Personally, I would recommend using a facebook page as a means of communicating within the group. Facebook offers the following features: 1. a proven track record of allowing users to control their levels of privacy, and not spamming them. More information regarding privacy here: http://www.google.com/search?q=privacy&query=site%3Awww.insidefacebook.com 2. many people already have accounts, and, if not, creating one is super easy 3. event calendar, invitations 4. free photo and video hosting 5. discussion boards 6. can be extended (free) via the Facebook API (in Haskell, I have a library I will be announcing soon). 7. Super easy to setup (less than 2 minutes). (Applications -> Ads and Pages -> Pages -> Create Page). I would recommend a facebook page over a facebook group. I would - jeremy At Wed, 12 Aug 2009 14:13:37 -0500, Tom Tobin wrote: > > There isn't a Chicago-area Haskell group, is there? If not, would > anyone be interested in forming one? I used to run Chicago's Django > (a Python web framework) group, but lost interest (and since I lived > in the suburbs back then, got sick of the commute). Unlike Python, > I'm still very much a beginner with Haskell, so I feel I'd be able to > benefit quite a bit from picking the brains of more skilled users and > cooperating with other beginners. My particular interests are web > development (as that's my professional field) and multimedia > organization (I'm working on a Haskell audio tagging library to help > teach myself the language), but I'm open to learning just about > anything. :-) > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From jeremy at n-heptane.com Wed Aug 12 17:49:44 2009 From: jeremy at n-heptane.com (Jeremy Shaw) Date: Wed Aug 12 17:30:09 2009 Subject: [Haskell-cafe] Chicago Haskell User Group? In-Reply-To: <877hx8hfjs.wl%jeremy@n-heptane.com> References: <877hx8hfjs.wl%jeremy@n-heptane.com> Message-ID: <8763cshfd3.wl%jeremy@n-heptane.com> Also, With a acronym like C.H.U.G, we better have beer... ;) - jeremy From dons at galois.com Wed Aug 12 17:47:44 2009 From: dons at galois.com (Don Stewart) Date: Wed Aug 12 17:30:20 2009 Subject: [Haskell-cafe] Chicago Haskell User Group? In-Reply-To: <877hx8hfjs.wl%jeremy@n-heptane.com> References: <877hx8hfjs.wl%jeremy@n-heptane.com> Message-ID: <20090812214744.GF29909@whirlpool.galois.com> Excellent. BTW, more documented "Haskell for the Web" summaries/state of the art etc would be good. Some centralized community resource. -- Don jeremy: > Hello, > > Sounds good to me. I am in the Chicago area and do Haskell-based web > development all day, every day, using the Happstack platform. > > I don't have much time to organize, but I would be able to attend > meetings and give some presentations. > > Personally, I would recommend using a facebook page as a means of > communicating within the group. Facebook offers the following features: > > 1. a proven track record of allowing users to control their levels of > privacy, and not spamming them. More information regarding privacy > here: > > http://www.google.com/search?q=privacy&query=site%3Awww.insidefacebook.com > > 2. many people already have accounts, and, if not, creating one is super easy > > 3. event calendar, invitations > > 4. free photo and video hosting > > 5. discussion boards > > 6. can be extended (free) via the Facebook API (in Haskell, I have a > library I will be announcing soon). > > 7. Super easy to setup (less than 2 minutes). (Applications -> Ads and Pages -> Pages -> Create Page). > > I would recommend a facebook page over a facebook group. I would > > - jeremy > > At Wed, 12 Aug 2009 14:13:37 -0500, > Tom Tobin wrote: > > > > There isn't a Chicago-area Haskell group, is there? If not, would > > anyone be interested in forming one? I used to run Chicago's Django > > (a Python web framework) group, but lost interest (and since I lived > > in the suburbs back then, got sick of the commute). Unlike Python, > > I'm still very much a beginner with Haskell, so I feel I'd be able to > > benefit quite a bit from picking the brains of more skilled users and > > cooperating with other beginners. My particular interests are web > > development (as that's my professional field) and multimedia > > organization (I'm working on a Haskell audio tagging library to help > > teach myself the language), but I'm open to learning just about > > anything. :-) > > _______________________________________________ > > 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 thestonetable at gmail.com Wed Aug 12 17:54:01 2009 From: thestonetable at gmail.com (Cory Knapp) Date: Wed Aug 12 17:34:34 2009 Subject: [Haskell-cafe] Chicago Haskell User Group? In-Reply-To: <877hx8hfjs.wl%jeremy@n-heptane.com> References: <877hx8hfjs.wl%jeremy@n-heptane.com> Message-ID: <4A8339F9.6080106@gmail.com> I and certainly some of my professors would be extremely interested in a Chicago HUG. Facebook sounds like a good idea, but I tend not to actually check facebook groups. They just aren't quite intrusive enough. :) Unfortunately (actually, quite fortunately), I'm in Budapest for the semester, so I can't participate in a very real way. I don't believe the professors who would be interested subscribe to Haskell Cafe, so I will pass any relevant info on. Cheers, Cory Jeremy Shaw wrote: > Hello, > > Sounds good to me. I am in the Chicago area and do Haskell-based web > development all day, every day, using the Happstack platform. > > I don't have much time to organize, but I would be able to attend > meetings and give some presentations. > > Personally, I would recommend using a facebook page as a means of > communicating within the group. Facebook offers the following features: > > 1. a proven track record of allowing users to control their levels of > privacy, and not spamming them. More information regarding privacy > here: > > http://www.google.com/search?q=privacy&query=site%3Awww.insidefacebook.com > > 2. many people already have accounts, and, if not, creating one is super easy > > 3. event calendar, invitations > > 4. free photo and video hosting > > 5. discussion boards > > 6. can be extended (free) via the Facebook API (in Haskell, I have a > library I will be announcing soon). > > 7. Super easy to setup (less than 2 minutes). (Applications -> Ads and Pages -> Pages -> Create Page). > > I would recommend a facebook page over a facebook group. I would > > - jeremy > > At Wed, 12 Aug 2009 14:13:37 -0500, > Tom Tobin wrote: > >> There isn't a Chicago-area Haskell group, is there? If not, would >> anyone be interested in forming one? I used to run Chicago's Django >> (a Python web framework) group, but lost interest (and since I lived >> in the suburbs back then, got sick of the commute). Unlike Python, >> I'm still very much a beginner with Haskell, so I feel I'd be able to >> benefit quite a bit from picking the brains of more skilled users and >> cooperating with other beginners. My particular interests are web >> development (as that's my professional field) and multimedia >> organization (I'm working on a Haskell audio tagging library to help >> teach myself the language), but I'm open to learning just about >> anything. :-) >> _______________________________________________ >> 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 wasserman.louis at gmail.com Wed Aug 12 18:13:25 2009 From: wasserman.louis at gmail.com (Louis Wasserman) Date: Wed Aug 12 17:54:09 2009 Subject: [Haskell-cafe] Chicago Haskell User Group? Message-ID: Count me in. I'm a student at UChicago. Louis Wasserman wasserman.louis@gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090812/0286639b/attachment.html From korpios at korpios.com Wed Aug 12 18:49:04 2009 From: korpios at korpios.com (Tom Tobin) Date: Wed Aug 12 18:29:29 2009 Subject: [Haskell-cafe] Chicago Haskell User Group? In-Reply-To: <877hx8hfjs.wl%jeremy@n-heptane.com> References: <877hx8hfjs.wl%jeremy@n-heptane.com> Message-ID: On Wed, Aug 12, 2009 at 4:45 PM, Jeremy Shaw wrote: > Personally, I would recommend using a facebook page as a means of > communicating within the group. Okay: http://www.facebook.com/pages/Chicago-IL/Chicago-Haskell-User-Group/115989593098 I hope that's the correct public-facing link, since Facebook's administration interfaces are a bit confusing. From qdunkan at gmail.com Wed Aug 12 18:58:32 2009 From: qdunkan at gmail.com (Evan Laforge) Date: Wed Aug 12 18:38:56 2009 Subject: [Haskell-cafe] generalize RecordPuns and RecordWildCards to work with qualified names? In-Reply-To: <638ABD0A29C8884A91BC5FB5C349B1C35B30DEED90@EA-EXMSG-C334.europe.corp.microsoft.com> References: <2518b95d0907171556l3745912na56481698094b2dd@mail.gmail.com> <638ABD0A29C8884A91BC5FB5C349B1C34B7FA6CABB@EA-EXMSG-C334.europe.corp.microsoft.com> <5ab17e790907241648x77999baft925cac5d9af116d7@mail.gmail.com> <638ABD0A29C8884A91BC5FB5C349B1C35B30DEED90@EA-EXMSG-C334.europe.corp.microsoft.com> Message-ID: <2518b95d0908121558j477f061o591a4267efc40f4@mail.gmail.com> > | Even is suggesting that instead of reporting an error, in the second > | case we could use the translation: > | > | ? f (A.A { A.a }) = a ? --> ? f (A.A { A.a = a }) > | > | (i.e., when punning occurs with a qualified name, use just the > | unqualified part of the name in the pattern) > > Yes, that'd be possible. ? But it seems debatable -- it doesn't *look* as if the pattern (A.A { A.a }) binds 'a' -- and it seems even less desirable in record construction and update. ?To be concrete, would you expect these to work too? > > ?g a = A.A { A.a } ? ? --> ? ?g a = A.A { A.a = a } > ?h x a = x { A.a } ? ? --> ? ?h x a = a { A.a = a } Oh, I didn't realize that record punning included construction as well. Yeah, that's a little funky looking. I don't mind seeing the binding form and I think a new reader could figure it out without too much trouble but I would be a little confused by the construction form and think a new reader would also be confused. > With -XDisambiguateRecordFields you could say > > ?g a = A.A { a } > > which seems better. ?(But there's no help for record update, since we don?t know which data constructor is involved.) I didn't know about DisambiguateRecordFields! Looks like that also makes the wildcard work like I want it to. The ghc docs for DisambiguateRecordFields don't make this very clear to me... it talks about disambiguating names in scope, but if I say "R.R { a = val}" I wouldn't expect it to "disambiguate" 'a', which is not in scope at all, to 'R.a' which looks like a completely different name. Rereading the paragraph at 7.3.11 I'm still surprised this works. Maybe add something like: ... preceeding docs ... This also means that if you use qualified imports you can still use unqualified field names. E.g. in the pattern @(R.R { a = a_val })@, @a@ will be disambiguated to @R.a@, even if @R@ is imported qualified. I gather we're not supposed to call them "records" anymore, they're supposed to be something I forget now, but the rest of the ghc docs says records, so... > So my current conclusion is: improve the error message, perhaps suggesting the flag -XDismabiguateRecordFields, but don't add the change you suggest. > > Comments? Sounds good to me. I'll try adding DisambiguateRecordFields and try out the new punning, thanks! From jeremy at n-heptane.com Wed Aug 12 19:19:23 2009 From: jeremy at n-heptane.com (Jeremy Shaw) Date: Wed Aug 12 18:59:47 2009 Subject: [Haskell-cafe] Chicago Haskell User Group? In-Reply-To: <4A8339F9.6080106@gmail.com> References: <877hx8hfjs.wl%jeremy@n-heptane.com> <4A8339F9.6080106@gmail.com> Message-ID: <874oschb7o.wl%jeremy@n-heptane.com> At Wed, 12 Aug 2009 23:54:01 +0200, Cory Knapp wrote: > > I and certainly some of my professors would be extremely interested in a > Chicago HUG. Facebook sounds like a good idea, but I tend not to > actually check facebook groups. They just aren't quite intrusive enough. :) With facebook pages (as opposed to groups), you can send slightly more instrusive messages. By default, you should receive an email to your email address when you are invited to an event. Facebook pages also allow you to publish stories that show up in your story feed, or show up in your facebook inbox as an unread message. This is one reason why I recommended a page over a group. If they add RSS feeds, that would make things even nicer. - jeremy From jeremy at n-heptane.com Wed Aug 12 19:21:49 2009 From: jeremy at n-heptane.com (Jeremy Shaw) Date: Wed Aug 12 19:02:12 2009 Subject: [Haskell-cafe] Chicago Haskell User Group? In-Reply-To: References: <877hx8hfjs.wl%jeremy@n-heptane.com> Message-ID: <873a7whb3m.wl%jeremy@n-heptane.com> At Wed, 12 Aug 2009 17:49:04 -0500, Tom Tobin wrote: > > On Wed, Aug 12, 2009 at 4:45 PM, Jeremy Shaw wrote: > > Personally, I would recommend using a facebook page as a means of > > communicating within the group. > > Okay: > > http://www.facebook.com/pages/Chicago-IL/Chicago-Haskell-User-Group/115989593098 > > I hope that's the correct public-facing link, since Facebook's > administration interfaces are a bit confusing. Sweet! I joined. You might add a logo from this page: http://www.haskell.org/haskellwiki/Haskell_logos/New_logo_ideas Or you can make me an admin, and I'll do it. To make someone an admin: 1. go to the page 2. click on 'See All' under Fans 3. click on the 'Make Admin' button - jeremy From jason.dusek at gmail.com Wed Aug 12 19:42:18 2009 From: jason.dusek at gmail.com (Jason Dusek) Date: Wed Aug 12 19:22:42 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <200908121728.41807.dan.doel@gmail.com> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> Message-ID: <42784f260908121642x6c722092p8eac084e3a69716@mail.gmail.com> 2009/08/12 Dan Doel : > On Wednesday 12 August 2009 10:12:14 am John A. De Goes wrote: > > I think the point is that a functional language with a > > built- in effect system that captures the nature of effects > > is pretty damn cool and eliminates a lot of boilerplate. > > It's definitely an interesting direction (possibly even the > right one in the long run), but it's not without its faults > currently (unless things have changed since I looked at it). > > For instance: what effects does disciple support? Mutation and > IO? What if I want non-determinism, or continuations, etc.? > How do I as a user add those effects to the effect system, and > specify how they should interact with the other effects? As > far as I know, there aren't yet any provisions for this, so > presumably you'll end up with effect system for effects > supported by the compiler, and monads for effects you're > writing yourself. +1 -- Jason Dusek From jwlato at gmail.com Wed Aug 12 20:18:41 2009 From: jwlato at gmail.com (John Lato) Date: Wed Aug 12 19:59:04 2009 Subject: [Haskell-cafe] containers and maps Message-ID: <9979e72e0908121718m3f132b7fn6ce6189090c33617@mail.gmail.com> Hello, The recent discussion regarding One Container Class To Rule Them All got me to thinking about container classes and map functions. ListLike (which is really a pretty nice package, and I would like to see more people use it) provides two map functions, a regular map with type > map :: (item -> item') -> full -> full' and also rigidMap: > rigidMap :: (item -> item) -> full -> full I think the utility of rigidMap is clear for anyone who's tried to solve the container class problem. Anyway, I had the idea of taking both maps out of ListLike entirely, and replace them with this: > class (ListLike full item, ListLike full' item') => Map full item full' item' where > map :: (item -> item') -> full -> full' Wouldn't this be better? I see the following benefits: -instances for polymorphic types like List are trivial -instances for monomorphic types (e.g. ByteString) can use the native map implementation. -Instances for types with class restrictions on the elements (e.g. UVector) can also be written. On the downside, the class context is much longer, but you'd only need to write the whole thing when you're actually using map, and then it'll include the ListLike instance automatically. Obviously this isn't so much one container class to rule them all as it is a set of classes that all work together, but as long as it's sensible that's fine with me. Thoughts? John Lato From korpios at korpios.com Wed Aug 12 20:24:46 2009 From: korpios at korpios.com (Tom Tobin) Date: Wed Aug 12 20:05:09 2009 Subject: [Haskell-cafe] Chicago Haskell User Group? In-Reply-To: <873a7whb3m.wl%jeremy@n-heptane.com> References: <877hx8hfjs.wl%jeremy@n-heptane.com> <873a7whb3m.wl%jeremy@n-heptane.com> Message-ID: On Wed, Aug 12, 2009 at 6:21 PM, Jeremy Shaw wrote: > Or you can make me an admin, and I'll do it. I did that; feel free to go ahead and dress up the page. ^_^ A logo somehow incorporating elements of the skyline into the new Haskell logo would be cute, if you (or anyone else) is artistically inclined. From john at n-brain.net Wed Aug 12 21:27:30 2009 From: john at n-brain.net (John A. De Goes) Date: Wed Aug 12 21:07:57 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <200908121728.41807.dan.doel@gmail.com> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> Message-ID: <58697AAD-4C90-4BF1-8118-35522DF1F895@n-brain.net> So what, because effect systems might not eliminate *all* boilerplate, you'd rather use boilerplate 100% of the time? :-) Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 On Aug 12, 2009, at 3:28 PM, Dan Doel wrote: > On Wednesday 12 August 2009 10:12:14 am John A. De Goes wrote: >> I think the point is that a functional language with a built- >> in effect system that captures the nature of effects is pretty damn >> cool and eliminates a lot of boilerplate. > > It's definitely an interesting direction (possibly even the right > one in the > long run), but it's not without its faults currently (unless things > have > changed since I looked at it). > > For instance: what effects does disciple support? Mutation and IO? > What if I > want non-determinism, or continuations, etc.? How do I as a user add > those > effects to the effect system, and specify how they should interact > with the > other effects? As far as I know, there aren't yet any provisions for > this, so > presumably you'll end up with effect system for effects supported by > the > compiler, and monads for effects you're writing yourself. > > By contrast, monad transformers (for one) let you do the above > defining of new > effects, and specifying how they interact (although they're > certainly neither > perfect, nor completely satisfying theoretically). > > Someone will probably eventually create (or already has, and I don't > know > about it) an extensible effect system that would put this objection > to rest. > Until then, you're dealing in trade offs. > > -- Dan From ninegua at gmail.com Wed Aug 12 22:02:51 2009 From: ninegua at gmail.com (Paul L) Date: Wed Aug 12 21:43:15 2009 Subject: [Haskell-cafe] ANNOUNCE: GLFW-0.4.1 Message-ID: <856033f20908121902o6932893cub8d62bfc07123eb@mail.gmail.com> I'm glad to announce a new version of GLFW, 0.4.1, has been uploaded to HackageDB. Notable changes include: * workaround for a FFI bug that affects GHC < 6.10 on 64-bit machines. * fix for the compilation problem on OS X for GHC > 6.10.1 * compatibility fix to work with both OpenGL 2.3.0.0 and older versions. * choice of a "dynamic" flag to link with dynamic GLFW C library instead. * a number of other fixes, cleanups and improvements. Many thanks goes to Brian Lewis, S?nke Hahn, and other people who sent in bug reports, patches, and suggestions. If you have any problem with this new version, you can either reply this email, or send to my other account (paul at thev.net). -- Regards, Paul Liu Yale Haskell Group http://www.haskell.org/yale From dan.doel at gmail.com Wed Aug 12 22:13:08 2009 From: dan.doel at gmail.com (Dan Doel) Date: Wed Aug 12 21:53:36 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <58697AAD-4C90-4BF1-8118-35522DF1F895@n-brain.net> References: <200908121728.41807.dan.doel@gmail.com> <58697AAD-4C90-4BF1-8118-35522DF1F895@n-brain.net> Message-ID: <200908122213.08912.dan.doel@gmail.com> On Wednesday 12 August 2009 9:27:30 pm John A. De Goes wrote: > So what, because effect systems might not eliminate *all* boilerplate, > you'd rather use boilerplate 100% of the time? :-) For most of my Haskell programs, the majority of the program is not made up of straight IO or ST functions, so how much boilerplate is it really eliminating? And since all the fooM functions have to exist for all the other monads, how much more boilerplate is it really to use them for IO and ST as well? Off hand, I'd say I don't write foo and fooM versions of functions much in actual programs, either. Such duplication goes into libraries, and that would be the case for Disciple as well (until there's a way to extend the effect system outside the compiler). So it's more of "effect systems eliminate 2% of my boilerplate; who (currently) cares? And is it worth having situations like 'you use monads for these effects, and the effect system for these other effects' in the language to do so?" But, as I said, it's not that I don't think it's a fruitful area of research, I just don't think it's going to yield significantly nicer code than Haskell _yet_. -- Dan From Ben.Lippmeier at anu.edu.au Wed Aug 12 23:11:09 2009 From: Ben.Lippmeier at anu.edu.au (Ben Lippmeier) Date: Wed Aug 12 22:51:36 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> References: <1E056B5A-0C7D-4605-9B3D-4F4A1F0C03C2@gmail.com> <547910850.20090812132848@gmail.com> <20090811215130.08602eec@fedora> <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> Message-ID: <4A83844D.5000400@anu.edu.au> Derek Elkins wrote: >> The compiler is supposed to be able to reorder non-strict >> evaluation to do optimisations, but that can't be done if effects >> could happen. >> > > There's nothing special about non-strict evaluation that makes the > antecedent true. Replacing "non-strict" with "strict" gives just as > much of a valid statement. It is purity that allows (some) reordering > of evaluation. > Here are two effectful statements that can safely be reordered. print "foo" x := 5 here are two more y := 2 z := 3 (provided y and z don't alias) Purity allows some reordering of evaluation, so does knowing that two effectful computations won't interfere. Ben. From kkwweett at yahoo.fr Wed Aug 12 23:23:21 2009 From: kkwweett at yahoo.fr (jean legrand) Date: Wed Aug 12 23:03:44 2009 Subject: [Haskell-cafe] Improving event management in elerea Message-ID: <429528.76725.qm@web24507.mail.ird.yahoo.com> Hi Haskellers, I've written a new version of the breakout elerea-example where mouse is replaced by LEFT and RIGHT keys http://hpaste.org:80/fastcgi/hpaste.fcgi/view?id=8159 and I have two questions. 1) my event function (line 79) returns a new signal and takes 3 arguments : an initial signal and a Bool signal which triggers when to apply the transform function given as a third argument. The body of the event function uses two calls to the sampler function. Is it possible to write this body with a unique call to sampler ? 2) this event function is used to link a keypress with a transformation of the position of the player. It is thus called two times (lines 91 and 94), one for each one of the two keys LEFT and RIGHT. Thanks to the ability to compose a new Bool signal from other ones, it is possible to define a guard for the transform function during the calls to event (lines 92 and 95 : the incrementation (decrementation) is only doable when the player abscissa is less than 0.6 (more than -0.8)). Nevertheless, during the game, I noticed some discrepancy with this ideal description : try to go to an extreme side (several hits of the LEFT key for instance until the player hits the left side) then go back in the opposite direction before hitting the opposite side (three hits of the RIGHT key for instance) then the first key pressing corresponding to the opposite of the opposite direction (i.e the initial LEFT direction) has no effect. Do you understand why ? Thanks From jake.mcarthur at gmail.com Wed Aug 12 23:40:38 2009 From: jake.mcarthur at gmail.com (Jake McArthur) Date: Wed Aug 12 23:21:06 2009 Subject: [Haskell-cafe] containers and maps In-Reply-To: <9979e72e0908121718m3f132b7fn6ce6189090c33617@mail.gmail.com> References: <9979e72e0908121718m3f132b7fn6ce6189090c33617@mail.gmail.com> Message-ID: <4A838B36.6000702@gmail.com> The monoids package offers something similar to this: mapReduce :: (Generator c, Reducer e m) => (Elem c -> e) -> c -> m If we take (Elem c) to be (item), (e) to be (item'), (c) to be (full), and (m) to be (full'), it's basically the same thing, and offers the same advantages as the ones you listed, as far as I can tell. - Jake From Ben.Lippmeier at anu.edu.au Wed Aug 12 23:41:54 2009 From: Ben.Lippmeier at anu.edu.au (Ben Lippmeier) Date: Wed Aug 12 23:22:22 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <200908121728.41807.dan.doel@gmail.com> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> Message-ID: <4A838B82.9020606@anu.edu.au> Dan Doel wrote: > For instance: what effects does disciple support? Mutation and IO? You can create your own top-level effects which interfere will all others, for example: effect !Network; effect !File; readFile :: String -(!e)> String :- !e = !File Now any function that calls readFile will also have a !File effect. > What if I > want non-determinism, or continuations, etc.? How do I as a user add those > effects to the effect system, and specify how they should interact with the > other effects? As far as I know, there aren't yet any provisions for this, so > presumably you'll end up with effect system for effects supported by the > compiler, and monads for effects you're writing yourself. > Yep. In Disciple, a computation has an effect if its evaluation cannot safely be reordered with others having the same effect. That is, computations have effects if they might "interfere" with others. One of the goals of the work has been to perform compiler optimisations without having to use IO-monad style state threading. "IO" is very coarse grained, and using the IO monad for everything tends to introduce more data-dependencies than strictly needed, which limits what optimisations you can do. Non-determinism and continuations are tricker things than the simple notion of "effects-as-interference", which I haven't got a good solution for. Ben. From Ben.Lippmeier at anu.edu.au Wed Aug 12 23:46:29 2009 From: Ben.Lippmeier at anu.edu.au (Ben Lippmeier) Date: Wed Aug 12 23:26:55 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <200908122213.08912.dan.doel@gmail.com> References: <200908121728.41807.dan.doel@gmail.com> <58697AAD-4C90-4BF1-8118-35522DF1F895@n-brain.net> <200908122213.08912.dan.doel@gmail.com> Message-ID: <4A838C95.2040902@anu.edu.au> Dan Doel wrote: > Off hand, I'd say I don't write foo and fooM versions of functions much in > actual programs, either. Such duplication goes into libraries... It would be ok if the duplication /was/ actually in the libraries, but often it's not. Note the lack of Data.Map.mapM and Data.Map.foldM. Want to apply a monadic computation to all the elements of a Data.Map? Convert it to a list and back.. Ben. From john at n-brain.net Wed Aug 12 23:50:58 2009 From: john at n-brain.net (John A. De Goes) Date: Wed Aug 12 23:31:25 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <200908122213.08912.dan.doel@gmail.com> References: <200908121728.41807.dan.doel@gmail.com> <58697AAD-4C90-4BF1-8118-35522DF1F895@n-brain.net> <200908122213.08912.dan.doel@gmail.com> Message-ID: Fair enough, but keep in mind an effect system does more than just eliminate boilerplate: it provides richer information on the precise nature of the interaction of a function with the real world. With the right insight, you can reorder and parallelize all kinds of effectful computations. Something that "dumb" monads can't provide. I haven't played with DDC, but I do believe some new FPL with a powerful effect system is going to take off in the next 5 years. Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 On Aug 12, 2009, at 8:13 PM, Dan Doel wrote: > On Wednesday 12 August 2009 9:27:30 pm John A. De Goes wrote: >> So what, because effect systems might not eliminate *all* >> boilerplate, >> you'd rather use boilerplate 100% of the time? :-) > > For most of my Haskell programs, the majority of the program is not > made up of > straight IO or ST functions, so how much boilerplate is it really > eliminating? > And since all the fooM functions have to exist for all the other > monads, how > much more boilerplate is it really to use them for IO and ST as well? > > Off hand, I'd say I don't write foo and fooM versions of functions > much in > actual programs, either. Such duplication goes into libraries, and > that would > be the case for Disciple as well (until there's a way to extend the > effect > system outside the compiler). > > So it's more of "effect systems eliminate 2% of my boilerplate; who > (currently) cares? And is it worth having situations like 'you use > monads for > these effects, and the effect system for these other effects' in the > language > to do so?" > > But, as I said, it's not that I don't think it's a fruitful area of > research, > I just don't think it's going to yield significantly nicer code than > Haskell > _yet_. > > -- Dan From john at n-brain.net Wed Aug 12 23:56:18 2009 From: john at n-brain.net (John A. De Goes) Date: Wed Aug 12 23:36:45 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <4A838B82.9020606@anu.edu.au> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> Message-ID: <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> The next step is to distinguish between reading file A and reading file B, between reading file A and writing file A, between reading one part of file A and writing another part of file A, etc. When the effect system can carry that kind of information, and not just for files, but network, memory, etc., then you'll be able to do some extremely powerful parallelization & optimization. But for now providing course grained information on the class to which an effect belongs is pretty interesting in its own right. Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 On Aug 12, 2009, at 9:41 PM, Ben Lippmeier wrote: > Dan Doel wrote: >> For instance: what effects does disciple support? Mutation and IO? > You can create your own top-level effects which interfere > will all others, for example: > > effect !Network; > effect !File; > > readFile :: String -(!e)> String > :- !e = !File > > Now any function that calls readFile will also have a !File effect. > >> What if I want non-determinism, or continuations, etc.? How do I as >> a user add those effects to the effect system, and specify how they >> should interact with the other effects? As far as I know, there >> aren't yet any provisions for this, so presumably you'll end up >> with effect system for effects supported by the compiler, and >> monads for effects you're writing yourself. >> > Yep. > > In Disciple, a computation has an effect if its evaluation cannot > safely be reordered with others having the same effect. That is, > computations have effects if they might "interfere" with others. > > One of the goals of the work has been to perform compiler > optimisations without having to use IO-monad style state threading. > "IO" is very coarse grained, and using the IO monad for everything > tends to introduce more data-dependencies than strictly needed, which > limits what optimisations you can do. > > Non-determinism and continuations are tricker things than the simple > notion of "effects-as-interference", which I haven't got a good > solution for. > > Ben. > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From dan.doel at gmail.com Wed Aug 12 23:56:21 2009 From: dan.doel at gmail.com (Dan Doel) Date: Wed Aug 12 23:36:50 2009 Subject: DDC compiler and =?iso-8859-1?q?effects=3B=09better_than_Haskell=3F?= (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <4A838C95.2040902@anu.edu.au> References: <200908122213.08912.dan.doel@gmail.com> <4A838C95.2040902@anu.edu.au> Message-ID: <200908122356.22042.dan.doel@gmail.com> On Wednesday 12 August 2009 11:46:29 pm Ben Lippmeier wrote: > Dan Doel wrote: > > Off hand, I'd say I don't write foo and fooM versions of functions much > > in actual programs, either. Such duplication goes into libraries... > > It would be ok if the duplication /was/ actually in the libraries, > but often it's not. > > Note the lack of Data.Map.mapM and Data.Map.foldM. Want to apply a monadic > computation to all the elements of a Data.Map? Convert it to a list and > back.. Or use Data.Traversable.mapM and Data.Foldable.foldM. From Ben.Lippmeier at anu.edu.au Thu Aug 13 00:10:01 2009 From: Ben.Lippmeier at anu.edu.au (Ben Lippmeier) Date: Wed Aug 12 23:50:29 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <200908122356.22042.dan.doel@gmail.com> References: <200908122213.08912.dan.doel@gmail.com> <4A838C95.2040902@anu.edu.au> <200908122356.22042.dan.doel@gmail.com> Message-ID: <4A839219.8060106@anu.edu.au> Dan Doel wrote: > On Wednesday 12 August 2009 11:46:29 pm Ben Lippmeier wrote: > >> Dan Doel wrote: >> >>> Off hand, I'd say I don't write foo and fooM versions of functions much >>> in actual programs, either. Such duplication goes into libraries... >>> >> It would be ok if the duplication /was/ actually in the libraries, >> but often it's not. >> >> Note the lack of Data.Map.mapM and Data.Map.foldM. Want to apply a monadic >> computation to all the elements of a Data.Map? Convert it to a list and >> back.. >> > > Or use Data.Traversable.mapM and Data.Foldable.foldM. > > Ah thanks, I didn't notice the Traversable instance. There are other higher-order functions in Data.Map that don't seem to have monadic counterparts though, like insertWith, unionsWith, updateAt ... Ben. From jake.mcarthur at gmail.com Thu Aug 13 00:12:27 2009 From: jake.mcarthur at gmail.com (Jake McArthur) Date: Wed Aug 12 23:52:52 2009 Subject: [Haskell-cafe] containers and maps In-Reply-To: <4A838B36.6000702@gmail.com> References: <9979e72e0908121718m3f132b7fn6ce6189090c33617@mail.gmail.com> <4A838B36.6000702@gmail.com> Message-ID: <4A8392AB.5090305@gmail.com> Jake McArthur wrote: > The monoids package offers something similar to this: > > mapReduce :: (Generator c, Reducer e m) => (Elem c -> e) -> c -> m > > If we take (Elem c) to be (item), (e) to be (item'), (c) to be (full), > and (m) to be (full'), it's basically the same thing, and offers the > same advantages as the ones you listed, as far as I can tell. Your example about uvector inspired me to try writing out the necessary instances for uvector: instance UA a => Monoid (UArr a) where mempty = emptyU mappend = appendU instance UA a => Reducer a (UArr a) where unit = singletonU snoc = snocU cons = consU instance UA a => Generator (UArr a) where type Elem (UArr a) = a mapTo f = foldlU (\a -> snoc a . f) - Jake From allbery at ece.cmu.edu Thu Aug 13 00:12:55 2009 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Wed Aug 12 23:53:31 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <4A838C95.2040902@anu.edu.au> References: <200908121728.41807.dan.doel@gmail.com> <58697AAD-4C90-4BF1-8118-35522DF1F895@n-brain.net> <200908122213.08912.dan.doel@gmail.com> <4A838C95.2040902@anu.edu.au> Message-ID: <57253B04-6466-4B36-A49A-17032FFE330B@ece.cmu.edu> On Aug 12, 2009, at 23:46 , Ben Lippmeier wrote: > Dan Doel wrote: >> Off hand, I'd say I don't write foo and fooM versions of functions >> much in actual programs, either. Such duplication goes into >> libraries... > > Note the lack of Data.Map.mapM and Data.Map.foldM. Want to apply a > monadic > computation to all the elements of a Data.Map? Convert it to a list > and back.. If Data.Map were a Monad, then the Monad mapM and foldM would work. It's not (can't represent Ord constraint on keys), so you have to translate into a monad to use monad functions. I don't know if Oleg's restricted monads, which *can* represent Data.Map, provide something similar. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 195 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090812/16fba715/PGP.bin From john at repetae.net Thu Aug 13 00:46:09 2009 From: john at repetae.net (John Meacham) Date: Thu Aug 13 00:26:34 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? In-Reply-To: <9979e72e0908121048i40f19c0aw3012b00ee177da01@mail.gmail.com> References: <9979e72e0908120241s5a0a204s56dd7b11fd8d8afa@mail.gmail.com> <61f84eff0908120639t52e54ae1xf6d3235c60c8d938@mail.gmail.com> <9979e72e0908121048i40f19c0aw3012b00ee177da01@mail.gmail.com> Message-ID: <20090813044609.GF26470@sliver.repetae.net> On Wed, Aug 12, 2009 at 06:48:33PM +0100, John Lato wrote: > On Wed, Aug 12, 2009 at 2:39 PM, Derek Elkins wrote: > > > > (To Alberto as well.) > > > > Unsurprisingly, Lennart stated the real issue, but I'll re-emphasize > > it. ?As much trouble as such a profound violation of purity would > > cause, it's not the biggest problem. ?If that were all, you could > > easily write a C/assembly function that would do what was desired. > > The real problem is that there isn't necessarily any "data chunk" at > > all, i.e. there may not be anything to mutate. > > > > Lennart is right of course, but wouldn't his example just be a > specific case of my argument? That is, the compiler decided to > evaluate the data at compile time by replacing it with the primitive > value and inlining it? It seems to me that in the absence of putting > some scope or sequencing upon the mutating function, there's no way > for such an unsafeMutate* to have any defined meaning in Haskell. And > once you have provided either scope or evaluation order, it would be > equivalent to just using a monad (although not necessarily IO). The inherent problem is that 'heap locations' are not first class values in haskell. There is no way to refer to 'the location holding a variable', not so much because they don't exist, but because it is just inexpressible in haskell. for instance, let b = a in unsafeUpdate b 3 what exactly does this update? Is there any meaningful interpretation of it? b and a are the same value, but that says nothing about the heap location. or > f x = unsafeUpdate x 10 are you updating the argument to f or what was passed into f? the above will likely be translated internally by the compiler to something like: > void f(int x) { x = 10; } which is obviously a nop. the inherent problem is that variables don't refer to heap locations, they refer to values and pretty much all compiler transforms depend on that. This has nothing to do with monads, there is no monad that will change that feature of haskell: I don't think it would be a rare thing for 'unsafeupdate' to not work, I would expect it to pretty much never do what you want with a modern compiler, it would break eta reduction and beta reduction for instance, which are the bread and butter of compiler transforms. John -- John Meacham - ?repetae.net?john? - http://notanumber.net/ From roconnor at theorem.ca Thu Aug 13 00:54:29 2009 From: roconnor at theorem.ca (roconnor@theorem.ca) Date: Thu Aug 13 00:34:52 2009 Subject: [Haskell-cafe] Re: DDC compiler and effects; better than Haskell? In-Reply-To: References: Message-ID: On Wed, 12 Aug 2009, Peter Verswyvelen wrote: > I kind of agree with the DDC authors here; in Haskell as soon as a > function has a side effect, and you want to pass that function to a > pure higher order function, you're stuck, you need to pick the monadic > version of the higher order function, if it exists. So Haskell doesn't > really solve the modularity problem, you need two versions of each > higher order function really, Actually you need five versions: The pure version, the pre-order traversal, the post-order traversal, the in-order traversal, and the reverse in-order traversal. And that is just looking at syntax. If you care about your semantics you could potentially have more (or less). -- Russell O'Connor ``All talk about `theft,''' the general counsel of the American Graphophone Company wrote, ``is the merest claptrap, for there exists no property in ideas musical, literary or artistic, except as defined by statute.'' From bulat.ziganshin at gmail.com Thu Aug 13 01:40:45 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Aug 13 01:28:17 2009 Subject: [Haskell-cafe] Working around file locking in Windows In-Reply-To: <1250107272.14592.1329564085@webmail.messagingengine.com> References: <1250107272.14592.1329564085@webmail.messagingengine.com> Message-ID: <1506767502.20090813094045@gmail.com> Hello Patai, Thursday, August 13, 2009, 12:01:12 AM, you wrote: > I'm trying to make the hp2any suite to be fully functional under > Windows, but I'm running into permission errors when I try to read the > heap profile that's still being written by its producer. Is there a way > to solve this problem without turning to the Win32 interface and having > to write platform specific code? this probably need to open file in shared mode, that isn't supported by Haskell libraries. i think the best you can do is to open FD in shared mode and then convert it to System.IO.Handle -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From ketil at malde.org Thu Aug 13 02:34:33 2009 From: ketil at malde.org (Ketil Malde) Date: Thu Aug 13 02:14:58 2009 Subject: [Haskell-cafe] Announce: EnumMap-0.0.1 In-Reply-To: <49a77b7a0908120834g3369a8e2l4082a45ca5c15e89@mail.gmail.com> (David Menendez's message of "Wed\, 12 Aug 2009 11\:34\:06 -0400") References: <87zla73ip7.fsf@malde.org> <20090810140918.GA26102@kira.casa> <87ocqlzhot.fsf@malde.org> <49a77b7a0908120834g3369a8e2l4082a45ca5c15e89@mail.gmail.com> Message-ID: <87ljloql1i.fsf@malde.org> David Menendez writes: > That depends on what "outside the Enum range" means. You'll get an > exception if you somehow get an Int key in the map which doesn't > correspond to any value in the enum, but you don't get an exception if > you try to pass in, say, a large Integer. > Prelude> fromEnum (2^32) > 0 Yes, but: Prelude Data.Int> fromEnum (2^32 :: Int64) *** Exception: Enum.fromEnum{Int64}: value (4294967296) is outside of Int's bounds (-2147483648,2147483647) so apparently, different Enum instances deal with this differently. >From GHC.Num: instance Enum Integer where [...] fromEnum n = I# (toInt# n) >From GHC.Int: instance Enum Int64 where [...] fromEnum x@(I64# x#) | x >= fromIntegral (minBound::Int) && x <= fromIntegral (maxBound::Int) = I# (int64ToInt# x#) | otherwise = fromEnumError "Int64" x -k -- If I haven't seen further, it is by standing in the footprints of giants From oleg at okmij.org Thu Aug 13 03:54:06 2009 From: oleg at okmij.org (oleg@okmij.org) Date: Thu Aug 13 03:37:04 2009 Subject: [Haskell-cafe] DDC compiler and effects Message-ID: <20090813075406.F353B1769A@Adric.metnet.navy.mil> Combining non-strict evaluation and even laziness (non-strictness plus sharing) with effects is of course possible. That is the topic of the ICFP09 paper of Sebastian Fischer et al., which describes the combination of laziness with non-determinism. The ideas of the paper have been implemented in a Hackage package and in the embedded probabilistic DSL Hansei. In the presence of effects, call-by-name is no longer observationally equivalent to call-by-need: one has to be explicit what is shared. Curry's call-time-choice seems a good choice: variables always denote values rather than computations and can be shared at will (of the run-time system). The language is still non-strict, and computations whose results are not demanded are not evaluated and none of their effects are performed. Since any computable effect can be modeled by delimited control, call-by-name shift/reset calculi provide general treatment of effects and non-strictness. Call-by-name delimited control calculi have been developed by Herbelin (POPL08). A different call-by-name shift/reset calculus (containing call-by-value calculus as a proper subset) is described in http://okmij.org/ftp/Computation/Continuations.html#cbn-shift The latter, cbn-xi, calculus includes effect sub-typing, which is common in effect calculi. A call-by-name function whose argument type is effectful can always be applied to a pure term. A pure term can be regarded as potentially having any effect. On the other hand, a function whose argument type is pure can only be applied to a pure term. The cbn-xi calculus also supports strict functions. Their argument type is always a pure type and they can be applied to terms regardless of their effect, because the effect will occur before the application. Pure functions thus provide a measure of effect-polymorphism. The cbn-xi and the other CBN calculi with delimited control are deterministic. The best application for the cbn-xi calculus I could find was in linguistics. The calculus was used to represent various effects in natural language: quantification, binding, raised and in-situ wh-questions. Importantly, several effects -- several question words, anaphora with quantification, superiority -- could be represented. One may view ML and Haskell as occupying two ends of the extreme. ML assumes any computation to be effectful and every function to have side effects. Therefore, an ML compiler cannot do optimizations like reordering (even apply commutative laws where exists), unless it can examine the source code and prove that computations to reorder are effect-free. That obviously all but precludes separate compilation; the only aggressive optimizing ML compiler, MLton, is a whole-program compiler. Haskell, on the other hand, assumes every expression pure. Lots algebraic properties become available and can be exploited, by compilers and people. Alas, that precludes any effects. Hence monads were introduced, bringing back control dependencies disguised as a data dependency. Monadic language forms a restrictive subset of Haskell (for example, we can't use monadic expressions in guards, `if' and `case' statements). In the monadic sublanguage, Haskell swings to another extreme and assumes, like ML, that everything is impure. Thus in an expression, do x <- e1 y <- e2 ... the two binding cannot be commuted, even if e1 and e2 are both 'return'. If the compiler sees the source code of e1 and e2 and is sufficiently smart to apply monadic laws, the compiler can determine the two bindings can be reordered. However, if e1 and e2 are defined in a separate module, I don't think that any existing compiler would even think about reordering. Hopefully a system like DDC will find the middle ground. From taruti at taruti.net Thu Aug 13 04:14:31 2009 From: taruti at taruti.net (Taru Karttunen) Date: Thu Aug 13 03:54:54 2009 Subject: [Haskell-cafe] Cleaner networking API - network-fancy Message-ID: <1250151030-sup-4812@oz.taruti.net> Hello network-fancy offers a cleaner API to networking facilities in Haskell. It supports high-level operations on tcp, udp and unix sockets. I would like some feedback on the API http://hackage.haskell.org/packages/archive/network-fancy/0.1.4/doc/html/Network-Fancy.html In particular: * Does the type of the server function in dgramServer make sense? or would (packet -> Address -> (packet -> IO ()) -> IO ()) be better? * Does the StringLike class make sense? * Any other suggestions? - Taru Karttunen From sebastian.sylvan at gmail.com Thu Aug 13 04:42:57 2009 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Thu Aug 13 04:30:56 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> Message-ID: <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> On Thu, Aug 13, 2009 at 4:56 AM, John A. De Goes wrote: > > The next step is to distinguish between reading file A and reading file B, between reading file A and writing file A, between reading one part of file > A and writing another part of file A, etc. When the effect system can carry > that kind of information, and not just for files, but network, memory, etc., > then you'll be able to do some extremely powerful parallelization & > optimization. > What if you have another program, written in C or something, that monitors a file for changes, and if so changes the contents of another file? Surely to catch that you must mark *all* file system access as "interefering"? Even worse, another program could monitor the state of a file and conditionally disable thet network driver, now file access interferes with network access. -- Sebastian Sylvan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090813/0ae27655/attachment-0001.html From apfelmus at quantentunnel.de Thu Aug 13 04:52:45 2009 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Thu Aug 13 04:33:21 2009 Subject: [Haskell-cafe] Re: DDC compiler and effects; better than Haskell? (was Re: unsafeDestructiveAssign?) In-Reply-To: <58697AAD-4C90-4BF1-8118-35522DF1F895@n-brain.net> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <58697AAD-4C90-4BF1-8118-35522DF1F895@n-brain.net> Message-ID: John A. De Goes wrote: > So what, because effect systems might not eliminate *all* boilerplate, > you'd rather use boilerplate 100% of the time? :-) The thing is that you still need mapM and friends for all those effects (like non-determinism) that are not baked into the language. Regards, apfelmus -- http://apfelmus.nfshost.com From jwlato at gmail.com Thu Aug 13 05:01:34 2009 From: jwlato at gmail.com (John Lato) Date: Thu Aug 13 04:41:57 2009 Subject: [Haskell-cafe] containers and maps In-Reply-To: <4A8392AB.5090305@gmail.com> References: <9979e72e0908121718m3f132b7fn6ce6189090c33617@mail.gmail.com> <4A838B36.6000702@gmail.com> <4A8392AB.5090305@gmail.com> Message-ID: <9979e72e0908130201u68a04f39tffd02fce3c6e35b2@mail.gmail.com> On 8/13/09, Jake McArthur wrote: > Jake McArthur wrote: > > > The monoids package offers something similar to this: > > > > ? ?mapReduce :: (Generator c, Reducer e m) => (Elem c -> e) -> c -> m > > > > If we take (Elem c) to be (item), (e) to be (item'), (c) to be (full), and > (m) to be (full'), it's basically the same thing, and offers the same > advantages as the ones you listed, as far as I can tell. > > > > Your example about uvector inspired me to try writing out the necessary > instances for uvector: > > ? ?instance UA a => Monoid (UArr a) where > ? ? ? ?mempty ?= emptyU > ? ? ? ?mappend = appendU > > ? ?instance UA a => Reducer a (UArr a) where > ? ? ? ?unit = singletonU > ? ? ? ?snoc = snocU > ? ? ? ?cons = consU > > ? ?instance UA a => Generator (UArr a) where > ? ? ? ?type Elem (UArr a) = a > ? ? ? ?mapTo f = foldlU (\a -> snoc a . f) > This looks to be essentially the same as the 'map' function in ListLike, and suffers from the same problem. It won't have the performance characteristics of the native map functions. Using e.g. ByteStrings, you're recreating a ByteString by snoc'ing elements. This might work with UVector (I intend to try it this evening); I don't know how well the fusion framework will hold up in class dictionaries. Still, the monoids package is very powerful (and I'd completely forgotten it). Perhaps there's another approach that would work? John From apfelmus at quantentunnel.de Thu Aug 13 05:06:51 2009 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Thu Aug 13 04:47:30 2009 Subject: [Haskell-cafe] Re: DDC compiler and effects; better than Haskell? In-Reply-To: References: Message-ID: Russell O'Connor wrote: > Peter Verswyvelen wrote: > >> I kind of agree with the DDC authors here; in Haskell as soon as a >> function has a side effect, and you want to pass that function to a >> pure higher order function, you're stuck, you need to pick the monadic >> version of the higher order function, if it exists. So Haskell doesn't >> really solve the modularity problem, you need two versions of each >> higher order function really, > > Actually you need five versions: The pure version, the pre-order > traversal, the post-order traversal, the in-order traversal, and the > reverse in-order traversal. And that is just looking at syntax. If you > care about your semantics you could potentially have more (or less). Exactly! There is no unique choice for the order of effects when lifting a pure function to an effectful one. For instance, here two different versions of an effectful map : mapM f [] = return [] mapM f (x:xs) = do y <- f x ys <- mapM f xs return (y:ys) mapM2 f [] = return [] mapM2 f (x:xs) = do ys <- mapM2 f xs y <- f x return (y:ys) Which one will the DCC compiler chose, given map f [] = [] map f (x:xs) = f x : map f xs ? Whenever I write a pure higher order function, I'd also have to document the order of effects. Regards, apfelmus -- http://apfelmus.nfshost.com From jwlato at gmail.com Thu Aug 13 05:30:08 2009 From: jwlato at gmail.com (John Lato) Date: Thu Aug 13 05:10:30 2009 Subject: [Haskell-cafe] Re: unsafeDestructiveAssign? Message-ID: <9979e72e0908130230u31684c12r52a4400a8b88388b@mail.gmail.com> > From: John Meacham > Subject: Re: [Haskell-cafe] unsafeDestructiveAssign? > On Wed, Aug 12, 2009 at 06:48:33PM +0100, John Lato wrote: > > On Wed, Aug 12, 2009 at 2:39 PM, Derek Elkins wrote: > > > > > > (To Alberto as well.) > > > > > > Unsurprisingly, Lennart stated the real issue, but I'll re-emphasize > > > it. ??As much trouble as such a profound violation of purity would > > > cause, it's not the biggest problem. ??If that were all, you could > > > easily write a C/assembly function that would do what was desired. > > > The real problem is that there isn't necessarily any "data chunk" at > > > all, i.e. there may not be anything to mutate. > > > > > > > Lennart is right of course, but wouldn't his example just be a > > specific case of my argument? ?That is, the compiler decided to > > evaluate the data at compile time by replacing it with the primitive > > value and inlining it? ?It seems to me that in the absence of putting > > some scope or sequencing upon the mutating function, there's no way > > for such an unsafeMutate* to have any defined meaning in Haskell. ?And > > once you have provided either scope or evaluation order, it would be > > equivalent to just using a monad (although not necessarily IO). > > > The inherent problem is that 'heap locations' are not first class values in > haskell. There is no way to refer to 'the location holding a variable', > not so much because they don't exist, but because it is just > inexpressible in haskell. for instance, Thanks for this clear explanation. The concept of an unsafeDestructiveAssign function really caught my attention because it seemed inexpressible. This makes perfect sense, including an explanation for mutable data in IO (because IORef, Ptr, and the like make a "data location" a first class value). I like to have a solid foundation for my nonsense. Cheers, John From bugfact at gmail.com Thu Aug 13 05:30:40 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Thu Aug 13 05:11:04 2009 Subject: [Haskell-cafe] Re: DDC compiler and effects; better than Haskell? In-Reply-To: References: Message-ID: Well, in DDC I believe the order is left to right. But you guys are right, many orders exist. On the other hand, a language might offer primitives to convert pure-to-effectfull functions no, in which you indicate the order you want. e.g. preOrder map No? (anyway Oleg's reply seems to give a definite answer to this thread no? :-) On Thu, Aug 13, 2009 at 11:06 AM, Heinrich Apfelmus wrote: > Russell O'Connor wrote: >> Peter Verswyvelen wrote: >> >>> I kind of agree with the DDC authors here; in Haskell as soon as a >>> function has a side effect, and you want to pass that function to a >>> pure higher order function, you're stuck, you need to pick the monadic >>> version of the higher order function, if it exists. So Haskell doesn't >>> really solve the modularity problem, you need two versions of each >>> higher order function really, >> >> Actually you need five versions: The pure version, the pre-order >> traversal, the post-order traversal, the in-order traversal, and the >> reverse in-order traversal. ?And that is just looking at syntax. ?If you >> care about your semantics you could potentially have more (or less). > > Exactly! There is no unique choice for the order of effects when lifting > a pure function to an effectful one. > > For instance, here two different versions of an effectful ?map : > > ? mapM f [] ? ? = return [] > ? mapM f (x:xs) = do > ? ? ? y ?<- f x > ? ? ? ys <- mapM f xs > ? ? ? return (y:ys) > > ? mapM2 f [] ? ? = return [] > ? mapM2 f (x:xs) = do > ? ? ? ys <- mapM2 f xs > ? ? ? y ?<- f x > ? ? ? return (y:ys) > > Which one will the DCC compiler chose, given > > ? map f [] ? ? = [] > ? map f (x:xs) = f x : map f xs > > ? Whenever I write a pure higher order function, I'd also have to > document the order of effects. > > > Regards, > apfelmus > > -- > http://apfelmus.nfshost.com > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From Ben.Lippmeier at anu.edu.au Thu Aug 13 05:32:30 2009 From: Ben.Lippmeier at anu.edu.au (Ben Lippmeier) Date: Thu Aug 13 05:12:58 2009 Subject: [Haskell-cafe] Re: DDC compiler and effects; better than Haskell? In-Reply-To: References: Message-ID: <4A83DDAE.9030404@anu.edu.au> Heinrich Apfelmus wrote: >> Actually you need five versions: The pure version, the pre-order >> traversal, the post-order traversal, the in-order traversal, and the >> reverse in-order traversal. And that is just looking at syntax. If you >> care about your semantics you could potentially have more (or less). >> > > Exactly! There is no unique choice for the order of effects when lifting > a pure function to an effectful one. > > For instance, here two different versions of an effectful map : > > mapM f [] = return [] > mapM f (x:xs) = do > y <- f x > ys <- mapM f xs > return (y:ys) > > mapM2 f [] = return [] > mapM2 f (x:xs) = do > ys <- mapM2 f xs > y <- f x > return (y:ys) > > Which one will the DCC compiler chose, given > > map f [] = [] > map f (x:xs) = f x : map f xs > Disciple uses default strict, left to right evaluation order. For the above map function, if "f" has any effects they will be executed in the same order as the list elements. > ? Whenever I write a pure higher order function, I'd also have to > document the order of effects. > If you write a straight-up higher-order function like map above, then it's neither pure or impure. Rather, it's polymorphic in the effect of its argument function. When effect information is added to the type of map it becomes: map :: forall a b %r1 %r2 !e1 . (a -(!e1)> b) -> List %r1 a -(!e2)> List %r2 b :- !e2 = !{ !Read %r1; !e1 } Which says the effect of evaluating map is to read the list and do whatever the argument function does. If the argument function is pure, and the input list is constant, then the application of map is pure, otherwise not. If you want to define an "always-pure" version of map, which only accepts pure argument functions then you can give it the signature: pureMap :: (a -(!e1)> b) -> List %r1 a -> List %r2 b :- Pure !e1, Const %r1 .. and use the same definition as before. Note that you don't have to specify the complete type in the source language, only the bits you care about - the rest is inferred. Now if you try to pass pureMap an impure function, you get an effect typing error. Adding purity constraints allows you to write H.O functions without committing to an evaluation order, so you can change it later if desired. Ben. From conor at strictlypositive.org Thu Aug 13 05:37:32 2009 From: conor at strictlypositive.org (Conor McBride) Date: Thu Aug 13 05:17:57 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <200908121728.41807.dan.doel@gmail.com> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> Message-ID: Hi Dan On 12 Aug 2009, at 22:28, Dan Doel wrote: > On Wednesday 12 August 2009 10:12:14 am John A. De Goes wrote: >> I think the point is that a functional language with a built- >> in effect system that captures the nature of effects is pretty damn >> cool and eliminates a lot of boilerplate. > > It's definitely an interesting direction (possibly even the right > one in the > long run), but it's not without its faults currently (unless things > have > changed since I looked at it). From what I've seen, I think we should applaud Ben for kicking the open here. Is Haskell over-committed to monads? Does Haskell make a sufficient distinction between notions of value and notions of computation in its type system? > For instance: what effects does disciple support? Mutation and IO? > What if I > want non-determinism, or continuations, etc.? How do I as a user add > those > effects to the effect system, and specify how they should interact > with the > other effects? As far as I know, there aren't yet any provisions for > this, so > presumably you'll end up with effect system for effects supported by > the > compiler, and monads for effects you're writing yourself. > > By contrast, monad transformers (for one) let you do the above > defining of new > effects, and specifying how they interact (although they're > certainly neither > perfect, nor completely satisfying theoretically). > > Someone will probably eventually create (or already has, and I don't > know > about it) an extensible effect system that would put this objection > to rest. > Until then, you're dealing in trade offs. It's still very much on the drawing board, but I once flew a kite called "Frank" which tried to do something of the sort (http://cs.ioc.ee/efftt/mcbride-slides.pdf). Frank distinguishes "value types" from "computation types" very much in the manner of Paul Blain Levy's call-by-push-value. You make a computation type from a value type v by attaching a capabilty to it (a possibly empty set of interfaces which must be enabled) [i_1,..i_n]v. You make a value type from a computation type c by suspending it {c}. Expressions are typed with value components matched up in the usual way and capabilities checked for inclusion in the ambient capability. That is, you don't need idiom-brackets because you're always in them: it's just a question of which idiom, as tracked by type. There's a construct to extend the ambient idiom by providing a "listener" for an interface (subtly disguised, a homomorphism from the free monad on the interface to the outer notion of computation). Listeners can transform the value type of the computations they interpret: a listener might offer the "throw" capability to a computation of type t, and deliver a pure computation of type Maybe t. But "[Throw]t" and "[]Maybe t" are distinguished, unlike in Haskell. Moreover {[]t} and t are distinct: the former is lazy, the latter strict, but there is no reason why we should ever evaluate a pure thunk more than once, even if it is forced repeatedly. I agree with Oleg's remarks, elsewhere in this thread: there is a middle ground to be found between ML and Haskell. We should search with open minds. All the best Conor From jason.dusek at gmail.com Thu Aug 13 05:45:29 2009 From: jason.dusek at gmail.com (Jason Dusek) Date: Thu Aug 13 05:25:52 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> Message-ID: <42784f260908130245l20d63468qa655095c95d7cbc3@mail.gmail.com> 2009/08/12 John A. De Goes : > The next step is to distinguish between reading file A and > reading file B, between reading file A and writing file A, > between reading one part of file A and writing another part of > file A, etc. When the effect system can carry that kind of > information, and not just for files, but network, memory, > etc., then you'll be able to do some extremely powerful > parallelization & optimization. I am challenged to imagine optimizations that would be safe in the case of File I/O. -- Jason Dusek From P.W.Trinder at hw.ac.uk Thu Aug 13 05:36:30 2009 From: P.W.Trinder at hw.ac.uk (Trinder, Philip W) Date: Thu Aug 13 05:28:11 2009 Subject: [Haskell-cafe] Parallel Symbolic Computing Research Post Message-ID: <976F9C1B58DCB84EA7021B8BFB483B8E0CC36EA8@ex6.mail.win.hw.ac.uk> The next generation of HPC platform will provide teraflop performance from 10^5 or more cores. A major challenge is to develop the programming models and software infrastructures to effectively exploit these architectures. In the HPC-GAP project (High Performance Computational Algebra and Discrete Mathematics EPSRC EP/G055181) we aim to address this challenge for the GAP Group Algebra package. You will join a team of four researchers in an ambitious programme to adapt the GAP computational algebra system to take advantage of modern high performance computers. You will collaborate with other HPC-GAP members at Aberdeen and St Andrews and Edinburgh Universities. You will take part in and publish research using the software you develop. You will have excellent parallel system engineering expertise, a degree in computer science, an appropriate PhD or equivalent, and good teamwork skills. Desirable criteria include functional language experience e.g. Haskell, a track record of academic publications, experience preparing research grant applications, and experience with a range of software technologies. You will start on 1 September 2009 and continue until the end of the grant in August 2013. Full details at www.jobs.ac.uk/jobs/SP072/Research_Associate_-_Parallel_Symbolic_Computi ng/ -------------------------------------------- Phil Trinder School of Mathematical and Computer Sciences Heriot-Watt University Edinburgh, EH14 4AS E: P.W.Trinder@hw.ac.uk T: +44 (0)131 451 3435 F: +44 (0)131 451 3327 I: www.macs.hw.ac.uk/~trinder -- Heriot-Watt University is a Scottish charity registered under charity number SC000278. From agocorona at gmail.com Thu Aug 13 06:09:08 2009 From: agocorona at gmail.com (Alberto G. Corona ) Date: Thu Aug 13 05:49:31 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <42784f260908130245l20d63468qa655095c95d7cbc3@mail.gmail.com> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <42784f260908130245l20d63468qa655095c95d7cbc3@mail.gmail.com> Message-ID: Another issue in DCC is in the course of writing a procedure, is that either the programmer has too much information (the list of effects of all the called procedures if they are explicit), or too little, if they are generated and managed by the compiler. How he knows for sure that a variable to be used in the next statement is pure or it would be updated by the previous function call?. if the list of effects of a procedure is hidden or worse, contains a lot of information, Isn`t this a problem?. In contrast, the division of the world in pure/impure operations is relaxing. Ok , after the @ operator I?m sure that everithing is pure, but things are not clear outside. At least in Haskell, trough monads, we have a clear signature about the effects we are dealiing with. If IO can be considered an effect. Maybe, in Haskell, the coarse IO monad can be divided in smaller monads as well, in the same but reverse way than DCC can handle the whole IO as a single effect (I guess)? 2009/8/13 Jason Dusek > 2009/08/12 John A. De Goes : > > The next step is to distinguish between reading file A and > > reading file B, between reading file A and writing file A, > > between reading one part of file A and writing another part of > > file A, etc. When the effect system can carry that kind of > > information, and not just for files, but network, memory, > > etc., then you'll be able to do some extremely powerful > > parallelization & optimization. > > I am challenged to imagine optimizations that would be safe in > the case of File I/O. > > -- > Jason Dusek > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090813/f52f6918/attachment.html From magnus at therning.org Thu Aug 13 06:32:15 2009 From: magnus at therning.org (Magnus Therning) Date: Thu Aug 13 06:12:39 2009 Subject: [Haskell-cafe] Cleaner networking API - network-fancy In-Reply-To: <1250151030-sup-4812@oz.taruti.net> References: <1250151030-sup-4812@oz.taruti.net> Message-ID: On Thu, Aug 13, 2009 at 9:14 AM, Taru Karttunen wrote: > Hello > > network-fancy offers a cleaner API to networking facilities in > Haskell. It supports high-level operations on tcp, udp and unix > sockets. > > I would like some feedback on the API > http://hackage.haskell.org/packages/archive/network-fancy/0.1.4/doc/html/Network-Fancy.html > > In particular: > * Does the type of the server function in dgramServer make sense? > ?or would (packet -> Address -> (packet -> IO ()) -> IO ()) be > ?better? > * Does the StringLike class make sense? > * Any other suggestions? There is already a getHostName in Network.BSD, any reason for not using it? /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?org http://therning.org/magnus identi.ca|twitter: magthe From jake.mcarthur at gmail.com Thu Aug 13 08:51:45 2009 From: jake.mcarthur at gmail.com (Jake McArthur) Date: Thu Aug 13 08:32:11 2009 Subject: [Haskell-cafe] containers and maps In-Reply-To: <9979e72e0908130201u68a04f39tffd02fce3c6e35b2@mail.gmail.com> References: <9979e72e0908121718m3f132b7fn6ce6189090c33617@mail.gmail.com> <4A838B36.6000702@gmail.com> <4A8392AB.5090305@gmail.com> <9979e72e0908130201u68a04f39tffd02fce3c6e35b2@mail.gmail.com> Message-ID: <4A840C61.2030403@gmail.com> John Lato wrote: > This looks to be essentially the same as the 'map' function in > ListLike, and suffers from the same problem. It won't have the > performance characteristics of the native map functions. Using e.g. > ByteStrings, you're recreating a ByteString by snoc'ing elements. Oh, I see now what you are after. You're right. This wouldn't play nice when creating ByteStrings (which is probably why there is no instance for Reducer Char ByteString). > This might work with UVector (I intend to try it this evening); I > don't know how well the fusion framework will hold up in class > dictionaries. Do report back, as I am curious as well. > Still, the monoids package is very powerful (and I'd completely > forgotten it). Perhaps there's another approach that would work? Yay, something to mull over! :) - Jake From zunino at di.unipi.it Thu Aug 13 09:02:44 2009 From: zunino at di.unipi.it (Roberto Zunino) Date: Thu Aug 13 08:43:08 2009 Subject: [Haskell-cafe] unsafeDestructiveAssign? In-Reply-To: References: Message-ID: <4A840EF4.8050802@di.unipi.it> Job Vranish wrote: > Does anybody know if there is some unsafe IO function that would let me do > destructive assignment? > Something like: > > a = 5 > main = do > veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign a 8 > print a >> 8 Untested, just guessing: {-# NOILINE aRef , a #-} aRef = unsafePerformIO (newRef 0) a = unsafePerformIO aRef main = do use a -- 0 if you are lucky writeRef aRef 5 use a -- 5 if you are lucky However, I would not in the least be surprised if your program stops working whenever your cat purrs. And yes, I find the above "code" quite disgusting. Zun. From john at n-brain.net Thu Aug 13 09:14:09 2009 From: john at n-brain.net (John A. De Goes) Date: Thu Aug 13 08:54:36 2009 Subject: [Haskell-cafe] Cleaner networking API - network-fancy In-Reply-To: <1250151030-sup-4812@oz.taruti.net> References: <1250151030-sup-4812@oz.taruti.net> Message-ID: <94D075F5-3DA7-416E-8010-AA80FF2B16A0@n-brain.net> Thank goodness for a cleaner networking API. I almost chose Haskell's socket API as an example of what _not_ to do in my series on Good API Design (http://jdegoes.squarespace.com/journal/2009/5/11/good-api-design-part-3.html ). Ended up going with Java though. :-) Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 On Aug 13, 2009, at 2:14 AM, Taru Karttunen wrote: > Hello > > network-fancy offers a cleaner API to networking facilities in > Haskell. It supports high-level operations on tcp, udp and unix > sockets. > > I would like some feedback on the API > http://hackage.haskell.org/packages/archive/network-fancy/0.1.4/doc/html/Network-Fancy.html > > In particular: > * Does the type of the server function in dgramServer make sense? > or would (packet -> Address -> (packet -> IO ()) -> IO ()) be > better? > * Does the StringLike class make sense? > * Any other suggestions? > > - Taru Karttunen > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From john at n-brain.net Thu Aug 13 09:19:54 2009 From: john at n-brain.net (John A. De Goes) Date: Thu Aug 13 09:00:21 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> Message-ID: <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> > What if you have another program, written in C or something, that > monitors a file for changes, and if so changes the contents of > another file? Surely to catch that you must mark *all* file system > access as "interefering"? Even worse, another program could monitor > the state of a file and conditionally disable thet network driver, > now file access interferes with network access. A compiler or runtime system can't know about these kinds of things -- unless perhaps you push the effect system into the operating system (interesting idea). The best you can do is ensure the program itself is correct in the absence of interference from other programs, but there's no way to obtain a guarantee in the presence of interference. Either with an effect system, or without (think of all the sequential imperative code that gets broken when other programs concurrently tamper with the file system or networking, etc.). Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 On Aug 13, 2009, at 2:42 AM, Sebastian Sylvan wrote: > > > On Thu, Aug 13, 2009 at 4:56 AM, John A. De Goes > wrote: > > The next step is to distinguish between reading file A and reading > file B, > between reading file A and writing file A, between reading one part > of file A and writing another part of file A, etc. When the effect > system can carry that kind of information, and not just for files, > but network, memory, etc., then you'll be able to do some extremely > powerful parallelization & optimization. > > What if you have another program, written in C or something, that > monitors a file for changes, and if so changes the contents of > another file? Surely to catch that you must mark *all* file system > access as "interefering"? Even worse, another program could monitor > the state of a file and conditionally disable thet network driver, > now file access interferes with network access. > > > -- > Sebastian Sylvan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090813/769e36e6/attachment.html From john at n-brain.net Thu Aug 13 09:25:12 2009 From: john at n-brain.net (John A. De Goes) Date: Thu Aug 13 09:05:37 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <42784f260908130245l20d63468qa655095c95d7cbc3@mail.gmail.com> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <42784f260908130245l20d63468qa655095c95d7cbc3@mail.gmail.com> Message-ID: Hmmm, bad example. Assume memory instead. That said, reordering/ parallelization of *certain combinations of* writes/reads to independent files under whole program analysis is no less safe than sequential writes/reads. It just "feels" less safe, but the one thing that will screw both up is interference from outside programs. Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 On Aug 13, 2009, at 3:45 AM, Jason Dusek wrote: > 2009/08/12 John A. De Goes : >> The next step is to distinguish between reading file A and >> reading file B, between reading file A and writing file A, >> between reading one part of file A and writing another part of >> file A, etc. When the effect system can carry that kind of >> information, and not just for files, but network, memory, >> etc., then you'll be able to do some extremely powerful >> parallelization & optimization. > > I am challenged to imagine optimizations that would be safe in > the case of File I/O. > > -- > Jason Dusek From john at n-brain.net Thu Aug 13 09:31:57 2009 From: john at n-brain.net (John A. De Goes) Date: Thu Aug 13 09:12:24 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <42784f260908130245l20d63468qa655095c95d7cbc3@mail.gmail.com> Message-ID: <59D62AC6-441F-41FE-92C3-D0811E8AB7DD@n-brain.net> On Aug 13, 2009, at 4:09 AM, Alberto G. Corona wrote: > Maybe, in Haskell, the coarse IO monad can be divided in smaller > monads as well I don't even want to imagine how that would obfuscate otherwise "straightforward" looking monadic code. The root problem is that monads don't capture enough information on the nature of effects, which limits composability. What's needed is something richer, which gives the compiler enough information to do all those things that make life easy for the developer, whilst maximizing the performance of the application. DDC is an interesting experiment in that direction. Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 From ifl2009 at shu.edu Thu Aug 13 10:13:38 2009 From: ifl2009 at shu.edu (IFL 2009) Date: Thu Aug 13 09:54:04 2009 Subject: [Haskell-cafe] IFL 2009: Final Call for Papers and Participation Message-ID: An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090813/ae3c1864/attachment.html From ganesh.sittampalam at credit-suisse.com Thu Aug 13 10:15:14 2009 From: ganesh.sittampalam at credit-suisse.com (Sittampalam, Ganesh) Date: Thu Aug 13 09:56:19 2009 Subject: [Haskell-cafe] Re: DDC compiler and effects; better than Haskell? In-Reply-To: References: Message-ID: <16442B752A06A74AB4D9F9A5FF076E4B03B9F8F2@ELON17P32001A.csfb.cs-group.com> What would preOrder foldr/foldl mean? What about preOrder (reverse . map) and preOrder (map . reverse) ? Another option would be for map to take a "strategy" as a parameter, sort of like Control.Parallel.Strategies. Peter Verswyvelen wrote: > Well, in DDC I believe the order is left to right. > > But you guys are right, many orders exist. > > On the other hand, a language might offer primitives to convert > pure-to-effectfull functions no, in which you indicate the order you > want. > > e.g. preOrder map > > No? > > (anyway Oleg's reply seems to give a definite answer to this thread > no? :-) > > On Thu, Aug 13, 2009 at 11:06 AM, Heinrich > Apfelmus wrote: >> Russell O'Connor wrote: >>> Peter Verswyvelen wrote: >>> >>>> I kind of agree with the DDC authors here; in Haskell as soon as a >>>> function has a side effect, and you want to pass that function to a >>>> pure higher order function, you're stuck, you need to pick the >>>> monadic version of the higher order function, if it exists. So >>>> Haskell doesn't really solve the modularity problem, you need two >>>> versions of each higher order function really, >>> >>> Actually you need five versions: The pure version, the pre-order >>> traversal, the post-order traversal, the in-order traversal, and the >>> reverse in-order traversal. ?And that is just looking at syntax. ?If >>> you care about your semantics you could potentially have more (or >>> less). >> >> Exactly! There is no unique choice for the order of effects when >> lifting a pure function to an effectful one. >> >> For instance, here two different versions of an effectful ?map : >> >> ? mapM f [] ? ? = return [] >> ? mapM f (x:xs) = do >> ? ? ? y ?<- f x >> ? ? ? ys <- mapM f xs >> ? ? ? return (y:ys) >> >> ? mapM2 f [] ? ? = return [] >> ? mapM2 f (x:xs) = do >> ? ? ? ys <- mapM2 f xs >> ? ? ? y ?<- f x >> ? ? ? return (y:ys) >> >> Which one will the DCC compiler chose, given >> >> ? map f [] ? ? = [] >> ? map f (x:xs) = f x : map f xs >> >> ? Whenever I write a pure higher order function, I'd also have to >> document the order of effects. >> >> >> Regards, >> apfelmus >> >> -- >> http://apfelmus.nfshost.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 =============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html =============================================================================== From dagit at codersbase.com Thu Aug 13 10:52:38 2009 From: dagit at codersbase.com (Jason Dagit) Date: Thu Aug 13 10:33:01 2009 Subject: [Haskell-cafe] Re: Thinking about what's missing in our library coverage In-Reply-To: <20090804055319.GA20525@whirlpool.galois.com> References: <20090803234432.GK17991@whirlpool.galois.com> <57526e770908032240s20a0e9d5t168bae4d8622432c@mail.gmail.com> <20090804055319.GA20525@whirlpool.galois.com> Message-ID: On Mon, Aug 3, 2009 at 10:53 PM, Don Stewart wrote: > alexander.dunlap: > > > o pandoc ? markdown, reStructuredText, HTML, LaTeX, ConTeXt, > Docbook, OpenDocument, ODT, RTF, MediaWiki, groff > > > > No. Pandoc is too actively developed to go into the HP. It's also much > > more of an end-user application than a "standard library" - it's > > applications are not general enough to be included in the standard > > distribution. > > > > One comment on your thoughtful post. > > What role does having unique capabilities for the Haskell Platform play? > > Our base library is already notable for having OpenGL support out of the > box. Maybe markup/markdown formats (for example) would also help Haskell > stand out from the crowd. A similar case would be gtk2hs out of the box > (Python supplied Tcl guis). I just thought of something I wanted to use Haskell for at work. It would be a tool used internally on windows and osx. I was thinking to myself, "Well, it would be nice if it had a GUI and the deps for building it were easy to satisfy." Naturally I looked at what packages the HP provides and I was disappointed to find out that other than OpenGL/GLUT and Win32 there are no GUI libraries provided. So a cross platfrom GUI library would be much appreciated. Whether that's wxHaskell, gtk2hs, or something else is not terribly important to me. On a side note, SDL support would be a nice addition to the OpenGL support. I think the other dependencies for what I have in mind are easily satisfied by the HP as it is. It would also be nice if we had some sort of web development platform as part of the HP. Those .NET folks have all these neat add-on libraries that just come bundled. Makes me jealous. Cabal-install makes things much easier overall so maybe I shouldn't complain... Thanks for the HP! Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090813/5074d4eb/attachment.html From roconnor at theorem.ca Thu Aug 13 11:06:46 2009 From: roconnor at theorem.ca (roconnor@theorem.ca) Date: Thu Aug 13 10:47:08 2009 Subject: [Haskell-cafe] Re: DDC compiler and effects; better than Haskell? In-Reply-To: References: Message-ID: On Thu, 13 Aug 2009, roconnor@theorem.ca wrote: > Actually you need five versions: The pure version, the pre-order traversal, > the post-order traversal, the in-order traversal, and the reverse in-order > traversal. And that is just looking at syntax. If you care about your > semantics you could potentially have more (or less). Minor technical correction. The four syntactic traversals are: pre-order, post-order, reverse pre-order, and reverse-post order. The in-order and reverse in-order are examples of other semantic traversals specific to binary tree like structures. -- Russell O'Connor ``All talk about `theft,''' the general counsel of the American Graphophone Company wrote, ``is the merest claptrap, for there exists no property in ideas musical, literary or artistic, except as defined by statute.'' From kkwweett at yahoo.fr Thu Aug 13 11:20:40 2009 From: kkwweett at yahoo.fr (jean legrand) Date: Thu Aug 13 11:01:02 2009 Subject: [Haskell-cafe] Improving event management in elerea In-Reply-To: <429528.76725.qm@web24507.mail.ird.yahoo.com> Message-ID: <572981.30322.qm@web24508.mail.ird.yahoo.com> > > http://hpaste.org:80/fastcgi/hpaste.fcgi/view?id=8159 > > and I have two questions. > > 1) my event function (line 79) returns a new signal and > takes 3 arguments : an initial signal and a Bool signal > which triggers when to apply the transform function given as > a third argument. The body of the event function uses two > calls to the sampler function. Is it possible to write this > body with a unique call to sampler ? > Second question solved with event ini b f = mdo let gs = generator eb $ (flat.f) <$> s' eb <- edge b s' <- sampler <$> storeJust ini gs s <- sampler <$> storeJust s' gs return s but I still can't answer my first one (couldn't this function -or its improvement- be part of the library ?) From mito at panix.com Thu Aug 13 12:03:54 2009 From: mito at panix.com (Gregory Michael Travis) Date: Thu Aug 13 11:44:17 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) Message-ID: <20090813160354.C33C614B99@panix1.panix.com> "John A. De Goes" sed: > Hmmm, bad example. Assume memory instead. That said, reordering/ > parallelization of *certain combinations of* writes/reads to > independent files under whole program analysis is no less safe than > sequential writes/reads. It just "feels" less safe, but the one thing > that will screw both up is interference from outside programs. This reminds me of something I've heard of: the commutative monad. I might have seen the phrase in some presentation by Simon Peyton-Jones. I took it to mean some sort of monad that sequenced computations, but was also capable of reordering them according to rules specified by the implementer of the monad. Thus, you could re-order operations on separate files, because they can't possible interfere with each other. This strikes me as an important idea, something that would allow you to incrementally optimize while keeping safety. For example, let's say you implement a complex distributed system, using a single distributed state monad to manage global state. This would be very slow, since you would no doubt have to have a central node controlling the order of all side-effects. But this node could re-group and re-distributed the side-effects. This would be done by using the type system to carefully separate effects that couldn't interfere. I'm not expressing this as well as I'd like. From the programmer's perspective, though, it could have a nice property: you start with a slow, but trivial state monad. Then you add rules and clauses that indicate when two effects can have their order switched; all the while, the meaning of the program is unchanged. This is not unlike nodes distributed database that have to receive updates from other nodes and figure out how to apply all the updates in a coherent order, or throw an exception if it cannot. From Patrick.Browne at comp.dit.ie Thu Aug 13 12:24:37 2009 From: Patrick.Browne at comp.dit.ie (pat browne) Date: Thu Aug 13 12:06:26 2009 Subject: [Haskell-cafe] matching types in Haskell Message-ID: <4A843E45.7040107@comp.dit.ie> Hi, I wish to align or match some Haskell types in order to represent a set of ontologies and their embedded concpts [1]. I am not sure wheather modules or classes could be used. I have done this task in a language called Maude[2]. The code is below. I appreciate that Maude is not very popular so there is a brief description below. This diagram below represents the semantics of what I am trying to achive. I want to construct MERGEDONTOLOGY from ONTOLOGY1 and ONTOLOGY2 both of which are based on COMMON. MERGEDONTOLOGY { Woman, RiverBank, FinancialBank, HumanBeing} /\ /\ / \ / \ / \ / \ / \ / \ ONTOLOGY1 ONTOLOGY2 {Woman, Bank, Person} {Woman, Bank, Human} /\ /\ \ / \ / \ / \ / \ / \ / \ / {Woman , Person} COMMMON Each Maude module represents (below) a distinct ontology, each sort (or type in Haskell) represents a concept. This example includes both synonyms and homonyms. I want to align ONTOLOGY1 and ONTOLOGY2 w.r.t COMMON to produce MERGEDONTOLOGY. The details of the concepts are as follows. The Woman concept should be the same in all ontologies, there is only one Woman concept and it is named as such in each ontology. Hence there should be only one Woman.MERGEDONTOLOGY There is only one concept HumanBeing.MERGEDONTOLOGY, but there are 3 synonyms Human.ONTOLOGY2, Person.ONTOLOGY1, and Person.COMMON It would seem that Person.COMMON should be mapped (or renamed?) to Human.ONTOLOGY2 which in turn is renamed (or mapped) to HumanBeing.MERGEDONTOLOGY. The homonyms are Bank.ONTOLOGY1 and Bank.ONTOLOGY2 which should become distinct entities in RiverBank.MERGEDONTOLOGY and FinancialBank.MERGEDONTOLOGY My question is how should this be done in Haskell. Is there a classes only solution? Is ther a module only solution? Or do I need both? Regards, Pat ============================================= Brief description of Maude code In the Maude Language the module is the basic conceptual unit. Sorts are declared in modules Every line ends with a space dot. In this case each module is bracketed by fth .. endfth There are various types of mappings between modules. In this case I used renamings where the syntax is *( name_in_source_module to name_in_target_module....) The keyword protecting is a type of inport. The + symbol between the modules forms a new module that includes all the information in each of its arguments ============================== fth COMMON is sorts Woman Person . endfth fth ONTOLOGY1 is protecting COMMON . sorts Bank . endfth fth ONTOLOGY2 is protecting COMMON *( sort Person to Human) . sorts Bank . endfth fth MERGEDONTOLOGY is including (ONTOLOGY1 * (sort Bank to RiverBank,sort Person to HumanBeing)) + (ONTOLOGY2 * (sort Human to HumanBeing, sort Bank to FinancialBank)) . endfth with the command show all MERGEDONTOLOGY the system will produce the following module fth MERGEDONTOLOGY0 is sorts Woman HumanBeing FinancialBank RiverBank . endfth ================================ Reference [1]Shapes of Alignments Construction, Combination, and Computation by Oliver Kutz, Till Mossakowsk, and Mihai Codescu http://www.informatik.uni-bremen.de/~okutz/shapes.pdf [2] Informa tiom on Maude at: http://maude.cs.uiuc.edu/ From spam at scientician.net Thu Aug 13 13:45:49 2009 From: spam at scientician.net (Bardur Arantsson) Date: Thu Aug 13 13:26:24 2009 Subject: [Haskell-cafe] Re: Cleaner networking API - network-fancy In-Reply-To: <1250151030-sup-4812@oz.taruti.net> References: <1250151030-sup-4812@oz.taruti.net> Message-ID: Taru Karttunen wrote: > Hello > > network-fancy offers a cleaner API to networking facilities in > Haskell. It supports high-level operations on tcp, udp and unix > sockets. > > I would like some feedback on the API > http://hackage.haskell.org/packages/archive/network-fancy/0.1.4/doc/html/Network-Fancy.html > > In particular: > * Does the type of the server function in dgramServer make sense? > or would (packet -> Address -> (packet -> IO ()) -> IO ()) be > better? > * Does the StringLike class make sense? > * Any other suggestions? > > - Taru Karttunen One thing that seems to be missing (and also seems to be missing from the GHC standard libraries AFAICT) is listening for multicast UDP. This requires some extra socket gymnastics to handle group membership. The details can be found in the network-multicast package. Cheers, -- /me who wonders where his signature went. From thomas.dubuisson at gmail.com Thu Aug 13 14:09:38 2009 From: thomas.dubuisson at gmail.com (Thomas DuBuisson) Date: Thu Aug 13 13:49:59 2009 Subject: [Haskell-cafe] Re: Cleaner networking API - network-fancy In-Reply-To: References: <1250151030-sup-4812@oz.taruti.net> Message-ID: <4c44d90b0908131109t6b753de1n84a1ac42b5e0d2fd@mail.gmail.com> I'm considering putting not insignificant effort into reworking the Network API during HacPDX. Assuming Johan agrees with the changes (and I don't know exactly what those are yet), I'd like to leave Network.Socket for general use and rework the Network module to allow easier TCP/UDP sending and receiving, binding to particular IP addresses, using bytestrings, receiving data with IP Headers, and sending with IP headers. Multicast is another good idea that should be in there. In general, the community would probably benefit if all these small packages (network, network-data, network-fancy, network-bytestring, network-multicast, network-server) gave way to fewer, more complete packages. Right now the thought has came to me that the cleanest, most uniform method might be to have a Config data type with all these ideas as options and use a single 'connect', 'listen' or 'receive' function for all the different protocols and their various options. I'll think on it. Thomas On Thu, Aug 13, 2009 at 10:45 AM, Bardur Arantsson wrote: > Taru Karttunen wrote: >> >> Hello >> >> network-fancy offers a cleaner API to networking facilities in >> Haskell. It supports high-level operations on tcp, udp and unix >> sockets. >> I would like some feedback on the API >> >> http://hackage.haskell.org/packages/archive/network-fancy/0.1.4/doc/html/Network-Fancy.html >> >> In particular: >> * Does the type of the server function in dgramServer make sense? >> ?or would (packet -> Address -> (packet -> IO ()) -> IO ()) be >> ?better? >> * Does the StringLike class make sense? >> * Any other suggestions? >> >> - Taru Karttunen > > One thing that seems to be missing (and also seems to be missing from the > GHC standard libraries AFAICT) is listening for multicast UDP. This requires > some extra socket gymnastics to handle group membership. The details can be > found in the network-multicast package. > > Cheers, > > -- > /me who wonders where his signature went. > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From sebastian.sylvan at gmail.com Thu Aug 13 14:24:21 2009 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Thu Aug 13 14:04:43 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> Message-ID: <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> On Thu, Aug 13, 2009 at 2:19 PM, John A. De Goes wrote: > What if you have another program, written in C or something, that > monitors a file for changes, and if so changes the contents of another file? > Surely to catch that you must mark *all* file system access as > "interefering"? Even worse, another program could monitor the state of a > file and conditionally disable thet network driver, now file access > interferes with network access. > > > A compiler or runtime system can't know about these kinds of things -- > unless perhaps you push the effect system into the operating system > (interesting idea). The best you can do is ensure the program itself is > correct in the absence of interference from other programs > I think the best you can do is make sure any code which is vulnerable to such interference won't be subject to unsafe transformations (like changing the order of evaluation). So I do think pretty much anything that relies on the outside world needs to go into one big effects "category" so the compiler/runtime will "stay out" and let the programmer explicitly define the ordering of those operations, precisely because the compiler has no way of knowing anything about what kind of assumptions are in effect. -- Sebastian Sylvan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090813/137a53de/attachment.html From johan.tibell at gmail.com Thu Aug 13 14:41:51 2009 From: johan.tibell at gmail.com (Johan Tibell) Date: Thu Aug 13 14:22:35 2009 Subject: [Haskell-cafe] Re: Cleaner networking API - network-fancy In-Reply-To: <4c44d90b0908131109t6b753de1n84a1ac42b5e0d2fd@mail.gmail.com> References: <1250151030-sup-4812@oz.taruti.net> <4c44d90b0908131109t6b753de1n84a1ac42b5e0d2fd@mail.gmail.com> Message-ID: <90889fe70908131141q566300calb0ad0fac431dae0d@mail.gmail.com> On Thu, Aug 13, 2009 at 8:09 PM, Thomas DuBuisson wrote: > I'm considering putting not insignificant effort into reworking the > Network API during HacPDX. ?Assuming Johan agrees with the changes > (and I don't know exactly what those are yet), I'd like to leave > Network.Socket for general use and rework the Network module to allow > easier TCP/UDP sending and receiving, binding to particular IP > addresses, using bytestrings, receiving data with IP Headers, and > sending with IP headers. ?Multicast is another good idea that should > be in there. Designing a correct and usable socket API is difficult. There are lots of corner cases that are easy to get wrong. For example, the current socket API always throws an EOF exception if recv returns a zero length string even though a zero length return value only indicates EOF when using TCP! Furthermore, the current API uses Strings which makes no sense. The library is poorly documented and lacks test (compare it to e.g. Python's socket module). There are other pitfalls as well. If you only cover parts of the BSD API you will alienate a fraction of your users who are forced to write their own bindings, not an easy task, especially if you want the binding to be cross platform. This applied to any OS binding. My best advice would be to form an special interest group (SIG) and iron out the details. This doesn't have to be anything terribly formal. Just a bunch of people who are interested in improving things. The SIG could keep a wiki with the current design. This makes it easier for both the members and other interested developer to review the design and find flaws. >> In general, the community would probably benefit if all these small > packages (network, network-data, network-fancy, network-bytestring, > network-multicast, network-server) gave way to fewer, more complete > packages. I absolutely agree. Hackage has increased the number of libraries a lot, which is great. However, great libraries often come out of peer reviews and attention to detail. As for network-bytestring, it is slated to be merged back into network under Network.Socket.ByteString if it passes community review. > Right now the thought has came to me that the cleanest, most uniform > method might be to have a Config data type with all these ideas as > options and use a single 'connect', 'listen' or 'receive' function for > all the different protocols and their various options. ?I'll think on > it. Write a wiki and explain how nicely this idea solves some of the current issues. That would be a good start. Just my 2 cents, Johan From taruti at taruti.net Thu Aug 13 15:07:45 2009 From: taruti at taruti.net (Taru Karttunen) Date: Thu Aug 13 14:48:07 2009 Subject: [Haskell-cafe] Re: Cleaner networking API - network-fancy In-Reply-To: <4c44d90b0908131109t6b753de1n84a1ac42b5e0d2fd@mail.gmail.com> References: <1250151030-sup-4812@oz.taruti.net> <4c44d90b0908131109t6b753de1n84a1ac42b5e0d2fd@mail.gmail.com> Message-ID: <1250190342-sup-1663@oz.taruti.net> Excerpts from Thomas DuBuisson's message of Thu Aug 13 21:09:38 +0300 2009: > Right now the thought has came to me that the cleanest, most uniform > method might be to have a Config data type with all these ideas as > options and use a single 'connect', 'listen' or 'receive' function for > all the different protocols and their various options. I'll think on > it. UDP does not play nicely with Handles. TCP wants Handles. Thus using an unified API does not make much sense. The semantics are just too different. - Taru Karttunen From john at repetae.net Thu Aug 13 15:57:58 2009 From: john at repetae.net (John Meacham) Date: Thu Aug 13 15:38:19 2009 Subject: [Haskell-cafe] Proposal: TypeDirectedNameResolution In-Reply-To: <20090727204137.GE14826@colquitt.org> References: <4A6DCE93.5020700@imn.htwk-leipzig.de> <89ca3d1f0907270929u53c3ae8ey14758557bf07e29b@mail.gmail.com> <89ca3d1f0907271010r359baf22q6a1e66a4d91fd8a2@mail.gmail.com> <20090727204137.GE14826@colquitt.org> Message-ID: <20090813195758.GL26470@sliver.repetae.net> On Mon, Jul 27, 2009 at 04:41:37PM -0400, John Dorsey wrote: > I'm assuming that name resolution is currently independent of type > inference, and will happen before type inference. With the proposal this is > no longer true, and in general some partial type inference will have to > happen before conflicting unqualified names are resolved. > > My worry is that the proposal will require a compliant compiler to > interweave name resolution and type inference iteratively. Indeed. This is my concern too. I can't see any way to do implement it in jhc at least without some major hassle. Name Resolution occurs several stages before typechecking, even before desugaring, having to intertwine it with type checking would be a complicated affair to say the least. John -- John Meacham - ?repetae.net?john? - http://notanumber.net/ From john at repetae.net Thu Aug 13 16:06:37 2009 From: john at repetae.net (John Meacham) Date: Thu Aug 13 15:46:58 2009 Subject: [Haskell-cafe] Re: Proposal: TypeDirectedNameResolution In-Reply-To: <2f9b2d30907281005u5bff3db4h19c59290b166a9ef@mail.gmail.com> References: <4A6DCE93.5020700@imn.htwk-leipzig.de> <89ca3d1f0907270929u53c3ae8ey14758557bf07e29b@mail.gmail.com> <2f9b2d30907281005u5bff3db4h19c59290b166a9ef@mail.gmail.com> Message-ID: <20090813200637.GM26470@sliver.repetae.net> On Tue, Jul 28, 2009 at 10:05:29AM -0700, Ryan Ingram wrote: > On Tue, Jul 28, 2009 at 1:41 AM, Heinrich > Apfelmus wrote: > > While I do agree that qualified names are annoying at times, I think > > that type directed name disambiguation is a Pandora's box. > > I see where you are going, but I'm not sure I agree. Let me give an > example from another language with this kind of resolution: C++. From > a purely practical point of view, function overloading in C++ does > what I want almost all the time. And when it doesn't do what I want, > it's always been immediately obvious, and it's a sign that my design > is flawed. I would be careful about assuming aspects of C++ will translate to haskell at the type system level, The reason is that in C++, all type information flows in one direction, for instance. int foo(...) { ... int x = bar(z,y); ... } all of the types of everything passed to bar and what it returns (x,y, and z) are fully specified at every call site, so 'name overloading' is a simple matter of finding the best match. however in haskell this isn't the case. 'bar' may affect the types used in 'foo'. there is two way type information passing in haskell. This radically changes the landscape for what is possible in the two type systems. John -- John Meacham - ?repetae.net?john? - http://notanumber.net/ From jwlato at gmail.com Thu Aug 13 16:43:43 2009 From: jwlato at gmail.com (John Lato) Date: Thu Aug 13 16:24:05 2009 Subject: [Haskell-cafe] containers and maps In-Reply-To: <4A840C61.2030403@gmail.com> References: <9979e72e0908121718m3f132b7fn6ce6189090c33617@mail.gmail.com> <4A838B36.6000702@gmail.com> <4A8392AB.5090305@gmail.com> <9979e72e0908130201u68a04f39tffd02fce3c6e35b2@mail.gmail.com> <4A840C61.2030403@gmail.com> Message-ID: <9979e72e0908131343x6d0a00cey3bcdc297887da27b@mail.gmail.com> On Thu, Aug 13, 2009 at 1:51 PM, Jake McArthur wrote: > John Lato wrote: >> > >> This might work with UVector (I intend to try it this evening); I >> don't know how well the fusion framework will hold up in class >> dictionaries. > > Do report back, as I am curious as well. I have just recently hacked together a small test. The code is at http://inmachina.net/~jwlato/haskell/testUVector.hs The task is to generate a list of 1 million Ints (really 1e6-1), map a multiply by 2, and check to see if any values equal 0. The uvector code is (essentially): > let res = anyU (== ( 0:: Int)) . mapU (* 2) . enumFromToU 1 $ 1000000 and by itself runs in a small fraction of a second. Technically the start and stop values are specified on the command line, but these are the values I predominantly used. Here are results for some other modes: ListLike.map: significantly slower, and runs out of memory (memory request failed) ListLike.rigidMap: appears to be the same as using mapU directly mapReduce: significantly slower (the 1e6 element test completed after about an hour), but ran in a very small amount of memory. It looks like GHC was able to see through the rigidMap function at least, but I don't know if this would still work with the instance defined in another file. Cheers, John From lemming at henning-thielemann.de Thu Aug 13 16:47:48 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Thu Aug 13 16:28:12 2009 Subject: [Haskell-cafe] Space for commentaries on hackage In-Reply-To: References: Message-ID: On Wed, 5 Aug 2009, Maur??cio CA wrote: > It would be nice to have a place for anonimous > comments below each page of a hackage package, maybe > with a cabal option to enable/disable that for a > particular package. Authors of packages with few > users may want that as a way to get first impressions > on their work they would otherwise not get. (At least, > I am, so I thought maybe others probably would.) I used to use Haskell-Wiki for project homepages, so people can leave comments in the according talk pages. From patai_gergely at fastmail.fm Thu Aug 13 17:31:07 2009 From: patai_gergely at fastmail.fm (Patai Gergely) Date: Thu Aug 13 17:11:29 2009 Subject: [Haskell-cafe] Improving event management in elerea Message-ID: <1250199067.18527.1329753449@webmail.messagingengine.com> Hello Jean, If I got you right, you basically want to have a signal that changes its value by a predetermined transform function whenever there is an edge detected on a bool signal. In that case, it would be easier to define it in terms of transfer: accumIf :: a -> (a -> a) -> Signal Bool -> SignalMonad (Signal a) accumIf v0 f b = transfer v0 g b where g _dt c x0 = if c then f x0 else x0 event :: a -> Signal Bool -> (a -> a) -> SignalMonad (Signal a) event v0 b f = accumIf v0 f =<< edge b I even factored out the edge functionality. Of course you also have to pass playerX0 to this function as is, without the pure wrapping. Also, your flat function is practically equivalent to (return . pure), why did you define it using transfer? Another thing to note is that you might want to define playerX as an integral of a velocity derived from lpress and rpress, so you wouldn't need to press and release the buttons repeatedly, and the speed would be the same regardless of sampling rate, since integral takes the time step into account. > but I still can't answer my first one (couldn't this function > -or its improvement- be part of the library ?) Sure, anything is possible. Elerea is a new library, and it deliberately exposes only some low-level constructs. In particular transfer, which basically lets you fall back on pure state transformer functions. My idea was that as more and more code is written in it, we can extract recurring patterns and add them to the library. But at the moment it is not clear what the useful patterns are, and I'd rather not start guessing and littering the library with useless combinators in advance. For instance, the accumIf function is a conditional version of stateful, and it might be generally useful. Whether it's the best name, that's another question. Gergely -- http://www.fastmail.fm - The professional email service From bertram.felgenhauer at googlemail.com Thu Aug 13 18:32:05 2009 From: bertram.felgenhauer at googlemail.com (Bertram Felgenhauer) Date: Thu Aug 13 18:12:30 2009 Subject: [Haskell-cafe] Improving MPTC usability when fundeps aren't appropriate? In-Reply-To: References: Message-ID: <4a849467.1818d00a.2721.67f8@mx.google.com> Daniel Peebles wrote: > I've been playing with multiparameter typeclasses recently and have > written a few "uncallable methods" in the process. For example, in > > class Moo a b where > moo :: a -> a > > Another solution would be to artificially force moo to take > a "dummy" b so that the compiler can figure out which instance you > meant. That's what I've been doing in the mean time, but wouldn't it > be simpler and less hackish to add a some form of "instance > annotation", like a type annotation, that would make it possible to > specify what instance you wanted when it's ambiguous? Syntax aside, dummy arguments have a disadvantage when it comes to optimizing code, because the compiler doesn't know that the dummy argument is unused in the function; indeed you could define instances where the dummy argument is used. For this reason it's technically better to use a newtype instead: newtype Lambda t a = Lambda { unLambda :: a } and, say, class Moo a b where moo :: Lambda b (a -> a) Note that we can convert between functions taking dummy arguments and such "lambda" types easily: lambdaToDummy :: Lambda t a -> t -> a lambdaToDummy a _ = unLambda a dummyToLambda :: (t -> a) -> Lambda t a dummyToLambda f = Lambda (f undefined) In fact, lambdaToDummy makes a great infix operator: (@@) :: Lambda t a -> t -> a (@@) = lambdaToDummy infixl 1 @@ Now we can write moo @@ (undefined :: x) where with dummy arguments we would write moo (undefined :: x) . The compiler will inline (@@) and lambdaToDummy (they're both small) and produce unLambda moo , that is, the plain value of type a -> a that we wanted to use in the first place. All this happens after type checking and fixing the instance of Moo to use. Bertram From twanvl at gmail.com Thu Aug 13 18:49:20 2009 From: twanvl at gmail.com (Twan van Laarhoven) Date: Thu Aug 13 18:29:37 2009 Subject: [Haskell-cafe] Proposal: TypeDirectedNameResolution In-Reply-To: <20090813195758.GL26470@sliver.repetae.net> References: <4A6DCE93.5020700@imn.htwk-leipzig.de> <89ca3d1f0907270929u53c3ae8ey14758557bf07e29b@mail.gmail.com> <89ca3d1f0907271010r359baf22q6a1e66a4d91fd8a2@mail.gmail.com> <20090727204137.GE14826@colquitt.org> <20090813195758.GL26470@sliver.repetae.net> Message-ID: <4A849870.6000806@gmail.com> John Meacham wrote: > On Mon, Jul 27, 2009 at 04:41:37PM -0400, John Dorsey wrote: > >>I'm assuming that name resolution is currently independent of type >>inference, and will happen before type inference. With the proposal this is >>no longer true, and in general some partial type inference will have to >>happen before conflicting unqualified names are resolved. >> >>My worry is that the proposal will require a compliant compiler to >>interweave name resolution and type inference iteratively. > > > Indeed. This is my concern too. I can't see any way to do implement it > in jhc at least without some major hassle. Name Resolution occurs > several stages before typechecking, even before desugaring, having to > intertwine it with type checking would be a complicated affair to say > the least. You can still resolve the names first, while keeping the ambiguity: data Expr = ... | OverloadedVar [UniqueId] -- after name resolution Then the type checker checks all possible overloads, and in the end only one variable reference is left. TDNR would still complicate the typechecker, since it suddenly needs to do backtracking. Twan From spoon at killersmurf.com Thu Aug 13 20:39:57 2009 From: spoon at killersmurf.com (spoon) Date: Thu Aug 13 20:20:19 2009 Subject: [Haskell-cafe] Hack on the Delve core, with Delve and Haskell In-Reply-To: References: <1249999048.4183.46.camel@utensil> Message-ID: <1250210397.4063.69.camel@utensil> > Could you create a comparison of Delve to other (potentially) similar > languages? For example, how is Delve similar/dissimilar to Clojure > and Scala? > I don't have any experience with Clojure at all, but looking at the page, it would appear that Clojure does not support first-class continuations, while Delve does. Delve is closer to scheme in this respect. Delve differs from Scala in that Delve is a much more imperative language. Classes are not static - they are created at run-time. In this way, Delve is akin to a well-typed ruby. Delve aims to support the open classes and objects of Smalltalk and Ruby. Since it is typed, breaking the encapsulation of an object could be tracked by the type system - I'd venture to say would be useful for a situation like a classbox, which modifies classes after they are defined. > Delve is released under the terms of the GNU GPLv3. > > Note intended as a criticism of the GPL or your decision to use it, > but does this impact people's ability to use the Delve standard > libraries in their own non-GPL projects? Don't worry! The GPL will be used to protect only the source of the virtual machine and the compiler - since Delve bytecode is just input for the VM, it doesn't constitute a modification of the software so it can be proprietary. In the same way, it's still GPL to allow proprietary extensions to be linked into the VM or compiler through specific interfaces. - John From ekmett at gmail.com Thu Aug 13 22:15:42 2009 From: ekmett at gmail.com (Edward Kmett) Date: Thu Aug 13 21:56:03 2009 Subject: [Haskell-cafe] containers and maps In-Reply-To: <9979e72e0908131343x6d0a00cey3bcdc297887da27b@mail.gmail.com> References: <9979e72e0908121718m3f132b7fn6ce6189090c33617@mail.gmail.com> <4A838B36.6000702@gmail.com> <4A8392AB.5090305@gmail.com> <9979e72e0908130201u68a04f39tffd02fce3c6e35b2@mail.gmail.com> <4A840C61.2030403@gmail.com> <9979e72e0908131343x6d0a00cey3bcdc297887da27b@mail.gmail.com> Message-ID: <7fb8f82f0908131915m212dbaa5q9939ca646bc6905@mail.gmail.com> Yeah, my answer on the ByteString front is to make a bunch of Reducers for a Builder data type that works like the one in Data.Binary.Builder. It generates a much more suitable Reducer and can reduce Chars, Strings, Strict and Lazy UTF8-encoded Bytestrings, etc. I'm using that inside of my toy compiler right now when I need to generate output, like a Lazy ByteString of source. (My variant Builder -- ok, my mostly cut and pasted Builder, has been made slightly smarter and is now tuned to work with UTF8 encoded data, which is what I've been feeding it lately.) I may migrate it into the monoids library from my current project if there is interest, but I'm trying to avoid ballooning that up too far in size again and re-entering dependency hell. The monoids library drew a pretty hard distinction between things that build up nicely (Monoids/Reducers) and things that tear down easily (Generators) but only works with a few things that do both efficiently (i.e. Seq/FingerTree) For my purposes this has worked rather well, but raw strict (and to a lesser degree, lazy) ByteStrings make abysmal Reducers. ;) In the end, bolting a list-like interface on something that can be _made_ to implement all of the operations but can't be made to implement them remotely efficiently, seems like it is asking for trouble, bug reports about performance, and pain. On the other hand, FingerTrees of wrapped strict ByteStrings work nicely as a monoidal lazy bytestring-like structure that provides an efficient snoc, indexing operation, and very efficient slicing for extracting token values with maximal sharing. I'll be giving a talk at the next Boston Haskell User Group in a few days about my abuse of those in a terrible hodge-podge solution of Iteratees, Parsec 3 and monoids, which yields an efficient parallel/incremental lexer. I'll see about posting the slides afterwards. -Edward Kmett On Thu, Aug 13, 2009 at 4:43 PM, John Lato wrote: > On Thu, Aug 13, 2009 at 1:51 PM, Jake McArthur > wrote: > > John Lato wrote: > >> > > > >> This might work with UVector (I intend to try it this evening); I > >> don't know how well the fusion framework will hold up in class > >> dictionaries. > > > > Do report back, as I am curious as well. > > I have just recently hacked together a small test. The code is at > http://inmachina.net/~jwlato/haskell/testUVector.hs > > The task is to generate a list of 1 million Ints (really 1e6-1), map a > multiply by 2, and check to see if any values equal 0. The uvector > code is (essentially): > > > let res = anyU (== ( 0:: Int)) . mapU (* 2) . enumFromToU 1 $ 1000000 > > and by itself runs in a small fraction of a second. Technically the > start and stop values are specified on the command line, but these are > the values I predominantly used. > > Here are results for some other modes: > > ListLike.map: significantly slower, and runs out of memory (memory > request failed) > ListLike.rigidMap: appears to be the same as using mapU directly > mapReduce: significantly slower (the 1e6 element test completed after > about an hour), but ran in a very small amount of memory. > > It looks like GHC was able to see through the rigidMap function at > least, but I don't know if this would still work with the instance > defined in another file. > > Cheers, > John > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090813/42aa336c/attachment.html From kkwweett at yahoo.fr Thu Aug 13 23:07:20 2009 From: kkwweett at yahoo.fr (jean legrand) Date: Thu Aug 13 22:47:42 2009 Subject: [Haskell-cafe] Improving event management in elerea In-Reply-To: <1250199067.18527.1329753449@webmail.messagingengine.com> Message-ID: <532544.58061.qm@web24501.mail.ird.yahoo.com> > detected on a bool signal. In that case, it would be easier > to define it > in terms of transfer: > > accumIf :: a -> (a -> a) -> Signal Bool -> > SignalMonad (Signal a) > accumIf v0 f b = transfer v0 g b > where g _dt c x0 = if c then f x0 else x0 > > event :: a -> Signal Bool -> (a -> a) -> > SignalMonad (Signal a) > event v0 b f = accumIf v0 f =<< edge b nice > Also, your flat function is practically equivalent to > (return . pure), > why did you define it using transfer? lack of reflex (and reflexion !) > Another thing to note is that you might want to define > playerX as an > integral of a velocity derived from lpress and rpress, so > you wouldn't > need to press and release the buttons repeatedly, and the > speed would be > the same regardless of sampling rate, since integral takes > the time step > into account. > or event :: a -> Signal Bool -> (a -> a) -> SignalMonad (Signal a) event v0 b f = accumIf v0 f =<< return b ? > For instance, the accumIf function is a conditional version > of stateful, > and it might be generally useful. Whether it's the best > name, that's > another question. > > Gergely thank you for your very helpful post From taruti at taruti.net Fri Aug 14 02:24:15 2009 From: taruti at taruti.net (Taru Karttunen) Date: Fri Aug 14 02:04:35 2009 Subject: [Haskell-cafe] Re: Cleaner networking API - network-fancy In-Reply-To: <90889fe70908131141q566300calb0ad0fac431dae0d@mail.gmail.com> References: <1250151030-sup-4812@oz.taruti.net> <4c44d90b0908131109t6b753de1n84a1ac42b5e0d2fd@mail.gmail.com> <90889fe70908131141q566300calb0ad0fac431dae0d@mail.gmail.com> Message-ID: <1250230995-sup-8661@oz.taruti.net> Excerpts from Johan Tibell's message of Thu Aug 13 21:41:51 +0300 2009: > My best advice would be to form an special interest group (SIG) and > iron out the details. This doesn't have to be anything terribly > formal. Just a bunch of people who are interested in improving things. > > The SIG could keep a wiki with the current design. This makes it > easier for both the members and other interested developer to review > the design and find flaws. +1 I would be interested in participating in this. - Taru Karttunen From patai_gergely at fastmail.fm Fri Aug 14 04:51:18 2009 From: patai_gergely at fastmail.fm (Patai Gergely) Date: Fri Aug 14 04:31:39 2009 Subject: [Haskell-cafe] Improving event management in elerea Message-ID: <1250239878.21359.1329821339@webmail.messagingengine.com> > or > > event :: a -> Signal Bool -> (a -> a) -> SignalMonad (Signal a) > event v0 b f = accumIf v0 f =<< return b > > ? That's not a good idea, because it doesn't take time into consideration, so you'd jump a huge amount in every frame. What I had in mind is something like this: ifte :: Signal Bool -> Signal a -> Signal a -> Signal a ifte sc st sf = (\c t f -> if c then t else f) <$> sc <*> st <*> sf And then: playerX <- integral playerX0 ( ifte (lpress &&@ (playerX >@ pure (-fieldW))) (-1) 0 + ifte (rpress &&@ (playerX <@ pure (fieldW-playerW))) (1) 0 ) This won't be perfect, since the paddle can get a bit beyond the edge of the field. This can be prevented by using some kind of clamped integral, for instance, which you can again define in terms of transfer, just like the plain integral. Also, note that mixing bind and return is redundant, since "f =<< return b" is equivalent to "f b". Gergely -- http://www.fastmail.fm - Choose from over 50 domains or use your own From kkwweett at yahoo.fr Fri Aug 14 05:37:10 2009 From: kkwweett at yahoo.fr (jean legrand) Date: Fri Aug 14 05:17:30 2009 Subject: [Haskell-cafe] Improving event management in elerea In-Reply-To: <1250239878.21359.1329821339@webmail.messagingengine.com> Message-ID: <160698.4991.qm@web24507.mail.ird.yahoo.com> > so you'd jump a huge amount in every frame. What I had in can you explain, please ? I can't feel it when I play. > something like this: > > ifte :: Signal Bool -> Signal a -> Signal a -> > Signal a > ifte sc st sf = (\c t f -> if c then t else f) <$> > sc <*> st <*> sf > > And then: > > playerX <- integral playerX0 > ( ifte > (lpress &&@ (playerX >@ pure (-fieldW))) (-1) 0 > + ifte > (rpress &&@ (playerX <@ pure (fieldW-playerW))) > (1) > 0 > ) > looks better indeed since there isn't a double signal anymore > This won't be perfect, since the paddle can get a bit > beyond the edge of > the field. This can be prevented by using some kind of > clamped integral, or using some rounding as I did in my first implementation ? > > Also, note that mixing bind and return is redundant, since > "f =<< return > b" is equivalent to "f b". > yes, of course ! one of The laws, thanks ! From patai_gergely at fastmail.fm Fri Aug 14 07:38:16 2009 From: patai_gergely at fastmail.fm (Patai Gergely) Date: Fri Aug 14 07:18:36 2009 Subject: [Haskell-cafe] Improving event management in elerea Message-ID: <1250249896.20227.1329832749@webmail.messagingengine.com> > can you explain, please ? I can't feel it when I play. Well, the paddle moves very fast that way, and its speed depends on the refresh rate. While the refresh rate is set in this program, it's not a good idea to depend on it in any way. Transfer functions provide access to the frame time, so you can adjust the speed to be independent of it. > or using some rounding as I did in my first implementation ? It's good if that works. However, I wouldn't depend on that either, since you might have to struggle with edge cases, and you also rely on the sizes being related to each other in various ways instead of choosing them freely. In my opinion, the best solution in this case would be a clamped integral, which would also make it unnecessary to check for the edge of the field in the condition (note that I make use of the Num instances of signals to take care of the lifting): integralClamped v0 vmin vmax s = transfer v0 accum s where accum dt v v0 = max vmin $ min vmax $ v0+v*realToFrac dt playerX <- integralClamped playerX0 (-fieldW) (fieldW-playerW) (ifte lpress (-1) 0 + ifte rpress 1 0) >From these, integralClamped and ifte might also be good candidates for inclusion in the library. Gergely -- http://www.fastmail.fm - Choose from over 50 domains or use your own From thomas at cs.ru.nl Fri Aug 14 11:06:39 2009 From: thomas at cs.ru.nl (Thomas van Noort) Date: Fri Aug 14 10:46:40 2009 Subject: [Haskell-cafe] Type family signatures Message-ID: <4A857D7F.7040000@cs.ru.nl> Hello, I have a question regarding type family signatures. Consider the following type family: type family Fam a :: * Then I define a GADT that takes such a value and wraps it: data GADT :: * -> * where GADT :: a -> Fam a -> GADT (Fam a) and an accompanying unwrapper: unwrap :: GADT (Fam a) -> (a, Fam a) unwrap (GADT x y) = (x, y) When Fam is declared using the first notation, type family Fam a :: * GHC HEAD gives the following error message: Main.hs:9:21: Couldn't match expected type `a' against inferred type `a1' `a' is a rigid type variable bound by the type signature for `unwrap' at Main.hs:8:20 `a1' is a rigid type variable bound by the constructor `GADT' at Main.hs:9:8 In the expression: x In the expression: (x, y) In the definition of `unwrap': unwrap (GADT x y) = (x, y) However, when Fam is declared as (moving the a to the other side of the :: and changing it into *), type family Fam :: * -> * everything is ok. So, it seems to me that GHC HEAD considers both signatures to be really different. However, I do not quite understand the semantic difference in my example, other than that Fam needs to be fully satisfied in its named type arguments. Note that GHC 6.10.3 does not accept the latter signature for Fam since it requires at least one index for some reason, that's why I'm using GHC HEAD. Regards, Thomas From dave at zednenem.com Fri Aug 14 11:32:56 2009 From: dave at zednenem.com (David Menendez) Date: Fri Aug 14 11:13:15 2009 Subject: [Haskell-cafe] Type family signatures In-Reply-To: <4A857D7F.7040000@cs.ru.nl> References: <4A857D7F.7040000@cs.ru.nl> Message-ID: <49a77b7a0908140832h7033b368nabc73f513de070d3@mail.gmail.com> On Fri, Aug 14, 2009 at 11:06 AM, Thomas van Noort wrote: > Hello, > > I have a question regarding type family signatures. Consider the following > type family: > > ?type family Fam a :: * > > Then I define a GADT that takes such a value and wraps it: > > ?data GADT :: * -> * where > ? ?GADT :: a -> Fam a -> GADT (Fam a) > > and an accompanying unwrapper: > > ?unwrap :: GADT (Fam a) -> (a, Fam a) > ?unwrap (GADT x y) = (x, y) > > When Fam is declared using the first notation, > > ?type family Fam a :: * > > GHC HEAD gives the following error message: > > ?Main.hs:9:21: > ? ?Couldn't match expected type `a' against inferred type `a1' > ? ? ?`a' is a rigid type variable bound by > ? ? ? ? ?the type signature for `unwrap' at Main.hs:8:20 > ? ? ?`a1' is a rigid type variable bound by > ? ? ? ? ? the constructor `GADT' at Main.hs:9:8 > ? ?In the expression: x > ? ?In the expression: (x, y) > ? ?In the definition of `unwrap': unwrap (GADT x y) = (x, y) This is because type families are not injective. Nothing stops you from defining two instances such as, type instance Fam Int = Bool type instance Fam Char = Bool in which case a value of type GADT Bool is ambiguous. Does it contain an Int or a Char? > However, when Fam is declared as (moving the a to the other side of the :: > and changing it into *), > > ?type family Fam :: * -> * > > everything is ok. So, it seems to me that GHC HEAD considers both signatures > to be really different. However, I do not quite understand the semantic > difference in my example, other than that Fam needs to be fully satisfied in > its named type arguments. Note that GHC 6.10.3 does not accept the latter > signature for Fam since it requires at least one index for some reason, > that's why I'm using GHC HEAD. A type family with no index is equivalent to a type synonym. But in answer to your question, these signatures are very different. Consider these families. type family Foo a b :: * type family Bar a :: * -> * Foo is indexed by two parameters, but Bar is only indexed by one. type instance Foo A B = X type instance Foo A C = X -- Foo a b ~ Foo a c does not imply b ~ c type instance Bar A = [] -- Bar a b ~ Bar a c does imply b ~ c Bar returns a type constructor, so it can be used anywhere a type constructor of kind * -> * can be used. foo :: (Functor (Foo a)) => ... -- invalid bar :: (Functor (Bar a)) => ... -- valid -- Dave Menendez From kowey at darcs.net Fri Aug 14 12:04:00 2009 From: kowey at darcs.net (Eric Kow) Date: Fri Aug 14 11:44:19 2009 Subject: [Haskell-cafe] Edinburgh Meetup (Sat 29 Aug) and Hack Day (Sun 30 Aug) Message-ID: <20090814160359.GG26689@brighton.ac.uk> Dear Haskellers, Just a quick reminder that we will be having a Hack Day in Edinburgh on Sunday 30 August (ICFP venue). That's in two weeks! For the interested, we will also be meeting up the day before 09:30 Saturday 29 August just outside the RCPE (ie. the ICFP venue again). We'll have a quick wander and hopefully find some nice places to sit and chat, whip out the occasional laptop and fling a lambda or not being careful not to injure the passers-by. For more details, see http://www.haskell.org/haskellwiki/Hac7 And do send me an email if you're interested in attending. It'll help us to get an idea how many people will be there. See you soon! :-) -- Eric Kow PGP Key ID: 08AC04F9 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090814/b0b3d93f/attachment.bin From lemming at henning-thielemann.de Fri Aug 14 12:06:25 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Fri Aug 14 11:47:02 2009 Subject: [Haskell-cafe] Quickcheck for common typeclass laws In-Reply-To: <878whshbp0.wl%jeremy@n-heptane.com> References: <878whshbp0.wl%jeremy@n-heptane.com> Message-ID: On Sun, 9 Aug 2009, Jeremy Shaw wrote: > This perhaps? > > http://hackage.haskell.org/package/checkers It seems dangerous to me to supply orphan instances in a package which is not obviously related to QuickCheck. I propose to get approval from the QuickCheck authors, that the instances can be considered "official" and use a package name which reflects that. The package name should start with QuickCheck in order to get the 'checkers' package close to QuickCheck in a lexicographic list. Then people cannot miss it so easily. From lemming at henning-thielemann.de Fri Aug 14 12:39:29 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Fri Aug 14 12:19:50 2009 Subject: [Haskell-cafe] Re: DDC compiler and effects; better than Haskell? In-Reply-To: References: Message-ID: On Thu, 13 Aug 2009, Heinrich Apfelmus wrote: > Russell O'Connor wrote: >> Peter Verswyvelen wrote: >> >>> I kind of agree with the DDC authors here; in Haskell as soon as a >>> function has a side effect, and you want to pass that function to a >>> pure higher order function, you're stuck, you need to pick the monadic >>> version of the higher order function, if it exists. So Haskell doesn't >>> really solve the modularity problem, you need two versions of each >>> higher order function really, >> >> Actually you need five versions: The pure version, the pre-order >> traversal, the post-order traversal, the in-order traversal, and the >> reverse in-order traversal. And that is just looking at syntax. If you >> care about your semantics you could potentially have more (or less). > > Exactly! There is no unique choice for the order of effects when lifting > a pure function to an effectful one. Which proves the proposition (courtesy of Johannes Waldmann), again: If a problem is more difficult to solve in Haskell than in another language, this is not Haskell's fault, but it is because the tackled problem is difficult and the other language only hides the problem. :-) From lemming at henning-thielemann.de Fri Aug 14 13:43:54 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Fri Aug 14 13:24:14 2009 Subject: [Haskell-cafe] Re: Adding an ignore function to Control.Monad In-Reply-To: <4A599AD1.1080403@therning.org> References: <4A4C2572.60006@isaac.cedarswampstudios.org> <404396ef0907012326j6ca93absa27d01bcf04eafe1@mail.gmail.com> <7fb8f82f0907020100n4a8bc570q60e9550ec57aef0a@mail.gmail.com> <20090702172217.GE27889@whirlpool.galois.com> <5ab17e790907021501o9676fe8yc296c62407976d5c@mail.gmail.com> <20090711031032.GA3717@whirlpool.galois.com> <50c1e0910907110035k4253661cnf8119018737e3a0f@mail.gmail.com> <90889fe70907110105v52a72cc1ga45a5cb1fd000216@mail.gmail.com> <4A584C83.8020300@web.de> <4A599AD1.1080403@therning.org> Message-ID: On Sun, 12 Jul 2009, Magnus Therning wrote: > Stephan Friedrichs wrote: >> Johan Tibell wrote: >>> [...] >>> >>> I also think void is clearer than ignore. >> >> So do I. Another point is, that it's familiar from other languages; a >> function "void f(...)" doesn't return anything but may have an effect >> on the environment. > > That depends on what languages you are familiar with, of course. To me void > is a type (C/C++) while ignore is a function (OCaml) ;-) In the Modula-II derivative Cluster it is named FORGET, in Modula-3 it is named EVAL. http://www.henning-thielemann.de/Cluster/Handbuch.pdf http://www.cs.tut.fi/lintula/manual/modula3/m3defn/html/eval.html From kkwweett at yahoo.fr Fri Aug 14 14:26:41 2009 From: kkwweett at yahoo.fr (jean legrand) Date: Fri Aug 14 14:07:01 2009 Subject: [Haskell-cafe] Improving event management in elerea In-Reply-To: <1250249896.20227.1329832749@webmail.messagingengine.com> Message-ID: <779077.35186.qm@web24508.mail.ird.yahoo.com> > to the frame time, so you can adjust the speed to be > independent of it. ok, thanks > integralClamped v0 vmin vmax s = transfer v0 accum s > where accum dt v v0 = max vmin $ min vmax $ > v0+v*realToFrac dt > > playerX <- integralClamped playerX0 (-fieldW) > (fieldW-playerW) > (ifte lpress > (-1) 0 + ifte rpress 1 0) > I haven't quite understood yet so I'll see later but I already have another question : what if the functions are some signal functions . For instance, instead of being (subtract 1) :: a -> a, it is a signal func :: Signal (a ->a) ? Is there also a simple way to compose func with an (x :: Signal a) in order to produce a new signal ? I naively tried y=func <*> x but the influence of func doesn't seem to exceed a frame. From westondan at imageworks.com Fri Aug 14 15:03:48 2009 From: westondan at imageworks.com (Dan Weston) Date: Fri Aug 14 14:45:03 2009 Subject: [Haskell-cafe] Type family signatures In-Reply-To: <49a77b7a0908140832h7033b368nabc73f513de070d3@mail.gmail.com> References: <4A857D7F.7040000@cs.ru.nl> <49a77b7a0908140832h7033b368nabc73f513de070d3@mail.gmail.com> Message-ID: <4A85B514.4050306@imageworks.com> But presumably he can use a data family instead of a type family to restore injectivity, at the cost of adding an extra wrapped bottom value and one more layer of value constructor? David Menendez wrote: > On Fri, Aug 14, 2009 at 11:06 AM, Thomas van Noort wrote: >> Hello, >> >> I have a question regarding type family signatures. Consider the following >> type family: >> >> type family Fam a :: * >> >> Then I define a GADT that takes such a value and wraps it: >> >> data GADT :: * -> * where >> GADT :: a -> Fam a -> GADT (Fam a) >> >> and an accompanying unwrapper: >> >> unwrap :: GADT (Fam a) -> (a, Fam a) >> unwrap (GADT x y) = (x, y) >> >> When Fam is declared using the first notation, >> >> type family Fam a :: * >> >> GHC HEAD gives the following error message: >> >> Main.hs:9:21: >> Couldn't match expected type `a' against inferred type `a1' >> `a' is a rigid type variable bound by >> the type signature for `unwrap' at Main.hs:8:20 >> `a1' is a rigid type variable bound by >> the constructor `GADT' at Main.hs:9:8 >> In the expression: x >> In the expression: (x, y) >> In the definition of `unwrap': unwrap (GADT x y) = (x, y) > > This is because type families are not injective. Nothing stops you > from defining two instances such as, > > type instance Fam Int = Bool > type instance Fam Char = Bool > > in which case a value of type GADT Bool is ambiguous. Does it contain > an Int or a Char? > >> However, when Fam is declared as (moving the a to the other side of the :: >> and changing it into *), >> >> type family Fam :: * -> * >> >> everything is ok. So, it seems to me that GHC HEAD considers both signatures >> to be really different. However, I do not quite understand the semantic >> difference in my example, other than that Fam needs to be fully satisfied in >> its named type arguments. Note that GHC 6.10.3 does not accept the latter >> signature for Fam since it requires at least one index for some reason, >> that's why I'm using GHC HEAD. > > A type family with no index is equivalent to a type synonym. > > But in answer to your question, these signatures are very different. > Consider these families. > > type family Foo a b :: * > type family Bar a :: * -> * > > Foo is indexed by two parameters, but Bar is only indexed by one. > > type instance Foo A B = X > type instance Foo A C = X > -- Foo a b ~ Foo a c does not imply b ~ c > > type instance Bar A = [] > -- Bar a b ~ Bar a c does imply b ~ c > > Bar returns a type constructor, so it can be used anywhere a type > constructor of kind * -> * can be used. > > foo :: (Functor (Foo a)) => ... -- invalid > bar :: (Functor (Bar a)) => ... -- valid > From patai_gergely at fastmail.fm Fri Aug 14 16:08:05 2009 From: patai_gergely at fastmail.fm (Patai Gergely) Date: Fri Aug 14 15:48:23 2009 Subject: [Haskell-cafe] GSoC profiling project to be wrapped up In-Reply-To: <20090812210318.GY29909@whirlpool.galois.com> References: <1250019999.30414.1329375813@webmail.messagingengine.com> <20090812210318.GY29909@whirlpool.galois.com> Message-ID: <1250280485.3119.1329912103@webmail.messagingengine.com> > > I finally uploaded the profiling tools to Hackage. The package names are > > hp2any-{core,graph,manager}. The first two should be possible to install > > right away, while the manager needs Gtk2Hs. A bit more on the project > > and this update at . > > Do you have an overview somewhere of the tools and how to use them? I just added an entry to HaskellWiki: http://www.haskell.org/haskellwiki/Hp2any Gergely -- http://www.fastmail.fm - The professional email service From john at n-brain.net Fri Aug 14 16:41:45 2009 From: john at n-brain.net (John A. De Goes) Date: Fri Aug 14 16:22:06 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> Message-ID: <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> Hmmm, my point (perhaps I wasn't clear), is that different effects have different commutability properties. In the case of a file system, you can commute two sequential reads from two different files. This has no effect on the result of the computation, assuming no interference from other programs -- and if there _is_ interference from other programs, then guarantees go out the window, _with or without_ commuting. Monads are an insufficient structure to capture the fine semantics of effects. Something more powerful is needed. And in general, the way effects combine and commute is quite complicated and needs to be baked into the effect system, rather than being the responsibility of a lowly developer. Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 On Aug 13, 2009, at 12:24 PM, Sebastian Sylvan wrote: > > > On Thu, Aug 13, 2009 at 2:19 PM, John A. De Goes > wrote: >> What if you have another program, written in C or something, that >> monitors a file for changes, and if so changes the contents of >> another file? Surely to catch that you must mark *all* file system >> access as "interefering"? Even worse, another program could monitor >> the state of a file and conditionally disable thet network driver, >> now file access interferes with network access. > > > A compiler or runtime system can't know about these kinds of things > -- unless perhaps you push the effect system into the operating > system (interesting idea). The best you can do is ensure the program > itself is correct in the absence of interference from other programs > > I think the best you can do is make sure any code which is > vulnerable to such interference won't be subject to unsafe > transformations (like changing the order of evaluation). > So I do think pretty much anything that relies on the outside world > needs to go into one big effects "category" so the compiler/runtime > will "stay out" and let the programmer explicitly define the > ordering of those operations, precisely because the compiler has no > way of knowing anything about what kind of assumptions are in effect. > > > -- > Sebastian Sylvan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090814/e1be189e/attachment.html From ryani.spam at gmail.com Fri Aug 14 16:49:15 2009 From: ryani.spam at gmail.com (Ryan Ingram) Date: Fri Aug 14 16:29:33 2009 Subject: [Haskell-cafe] Type family signatures In-Reply-To: <4A85B514.4050306@imageworks.com> References: <4A857D7F.7040000@cs.ru.nl> <49a77b7a0908140832h7033b368nabc73f513de070d3@mail.gmail.com> <4A85B514.4050306@imageworks.com> Message-ID: <2f9b2d30908141349v581d05f9lfb6fa98aa4fe2a4@mail.gmail.com> On Fri, Aug 14, 2009 at 12:03 PM, Dan Weston wrote: > But presumably he can use a data family instead of a type family to restore > injectivity, at the cost of adding an extra wrapped bottom value and one > more layer of value constructor? Actually, you don't even necessarily pay this penalty, since you can put newtypes into data families. > data family Foo a > newtype instance Foo () = UnitFoo Int You do need to add the constructor wrap/unwrapping in code, but they all get erased after typechecking. -- ryan From dagit at codersbase.com Fri Aug 14 17:38:19 2009 From: dagit at codersbase.com (Jason Dagit) Date: Fri Aug 14 17:18:38 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> Message-ID: On Fri, Aug 14, 2009 at 1:41 PM, John A. De Goes wrote: > > Hmmm, my point (perhaps I wasn't clear), is that different effects have > different commutability properties. In the case of a file system, you can > commute two sequential reads from two different files. This has no effect on > the result of the computation, assuming no interference from other programs > -- and if there _is_ interference from other programs, then guarantees go > out the window, _with or without_ commuting. > > Monads are an insufficient structure to capture the fine semantics of > effects. Something more powerful is needed. And in general, the way effects > combine and commute is quite complicated and needs to be baked into the > effect system, rather than being the responsibility of a lowly developer. > It's really interesting. This is related to the reasoning darcs does with patches (aka patch theory). Patches tend to have effects on your repository. Sometimes those effects can be reordered without changing the final state of the repository. Other times, it is not possible to reorder them without either having a non-sensible final state or different final states. I've never thought about reading research about effect systems for the sake of version control. I'll have to look into this. Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090814/662ef624/attachment.html From bugfact at gmail.com Fri Aug 14 18:28:22 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Fri Aug 14 18:08:41 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: References: <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> Message-ID: I think version is control is really just a subset of a larger effect theory. E.g. I've been experimenting with a parallel undo/redo system in C#, where some actions can commute and be undone separately, and for detecting this, the actions need to explicitly expose what they will change; so this also seems in the same line of research (and has been reported earlier in the thread "darcs as undo/redo system"). And if I recall correctly, imperative compilers can reorder and parallelize instructions based on what they read/write; again this feels the same. Like John said, it will be interesting when the operating system itself exposes all dependencies (what it reads/writes), so that if e.g. content of file A is used to generate content of file B, that this is not some spooky action at a distance. Now the OS is treated like a big black IO box (realworld in -> realworld out), just because we're still stuck with dumb hierarchical file systems and other opaque IO. Another example might be FRP / Yampa, and the recent work of Hai (Paul) Liu, Paul Hudak and co, where causal commutative arrows are invented. AFRP computations really commute, while standard arrows are just a generalization of monads, so not really suitable for capturing the parallel nature of AFRP. The way I discovered this myself, is that when you have e.g. a large tree of user interface widgets, represented by a big arrow circuit, and the user edits just the one widget in one branch (which happens when e.g. the mouse is captured), then with the current arrows system all branches will be visited depth first. But of course only the path towards the widget that will change needs to be visited, all the other remain constant. Since I don't have any academic backgrounds - only intuition - I'm not sure if these topics are related, but they sure feel like it :-) On Fri, Aug 14, 2009 at 11:38 PM, Jason Dagit wrote: > > > On Fri, Aug 14, 2009 at 1:41 PM, John A. De Goes wrote: >> >> Hmmm, my point (perhaps I wasn't clear), is that different effects have >> different commutability properties. In the case of a file system, you can >> commute two sequential reads from two different files. This has no effect on >> the result of the computation, assuming no interference from other programs >> -- and if there _is_ interference from other programs, then guarantees go >> out the window, _with or without_ commuting. >> Monads are an insufficient structure to capture the fine semantics of >> effects. Something more powerful is needed. And in general, the way effects >> combine and commute is quite complicated and needs to be baked into the >> effect system, rather than being the responsibility of a lowly developer. > > It's really interesting.? This is related to the reasoning darcs does with > patches (aka patch theory).? Patches tend to have effects on your > repository.? Sometimes those effects can be reordered without changing the > final state of the repository.? Other times, it is not possible to reorder > them without either having a non-sensible final state or different final > states.? I've never thought about reading research about effect systems for > the sake of version control.? I'll have to look into this. > > Jason > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > From westondan at imageworks.com Fri Aug 14 19:32:44 2009 From: westondan at imageworks.com (Dan Weston) Date: Fri Aug 14 19:13:37 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: References: <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> Message-ID: <4A85F41C.8040600@imageworks.com> My intuition says the proper formalism is that undo is left adjoint to redo. They together form a monad in the category of redoable actions. return lifts doable actions to undoable ones by attaching an empty undo stack. join lowers (reflects) a first-class undoable action out of the undo stack and makes it doable. The reason that the adjunction view is more fundamental here is that the monad is in some sense the equivalence class of all observationally equivalent undo/redo pairs. That is, undo need not actually restore the previous state: it is sufficient to restore any action that, when redone, gives the same state as the one before undo. There may be justification for this idea in Rossiter et al, "Process as a World Transaction" (http://computing.unn.ac.uk/staff/CGNR1/anpa064.pdf), though I haven't had time to read it yet. Dan Peter Verswyvelen wrote: > I think version is control is really just a subset of a larger effect > theory. E.g. I've been experimenting with a parallel undo/redo system > in C#, where some actions can commute and be undone separately, and > for detecting this, the actions need to explicitly expose what they > will change; so this also seems in the same line of research (and has > been reported earlier in the thread "darcs as undo/redo system"). > > And if I recall correctly, imperative compilers can reorder and > parallelize instructions based on what they read/write; again this > feels the same. > > Like John said, it will be interesting when the operating system > itself exposes all dependencies (what it reads/writes), so that if > e.g. content of file A is used to generate content of file B, that > this is not some spooky action at a distance. Now the OS is treated > like a big black IO box (realworld in -> realworld out), just because > we're still stuck with dumb hierarchical file systems and other opaque > IO. > > Another example might be FRP / Yampa, and the recent work of Hai > (Paul) Liu, Paul Hudak and co, where causal commutative arrows are > invented. AFRP computations really commute, while standard arrows are > just a generalization of monads, so not really suitable for capturing > the parallel nature of AFRP. The way I discovered this myself, is that > when you have e.g. a large tree of user interface widgets, represented > by a big arrow circuit, and the user edits just the one widget in one > branch (which happens when e.g. the mouse is captured), then with the > current arrows system all branches will be visited depth first. But of > course only the path towards the widget that will change needs to be > visited, all the other remain constant. > > Since I don't have any academic backgrounds - only intuition - I'm not > sure if these topics are related, but they sure feel like it :-) > > On Fri, Aug 14, 2009 at 11:38 PM, Jason Dagit wrote: >> >> On Fri, Aug 14, 2009 at 1:41 PM, John A. De Goes wrote: >>> Hmmm, my point (perhaps I wasn't clear), is that different effects have >>> different commutability properties. In the case of a file system, you can >>> commute two sequential reads from two different files. This has no effect on >>> the result of the computation, assuming no interference from other programs >>> -- and if there _is_ interference from other programs, then guarantees go >>> out the window, _with or without_ commuting. >>> Monads are an insufficient structure to capture the fine semantics of >>> effects. Something more powerful is needed. And in general, the way effects >>> combine and commute is quite complicated and needs to be baked into the >>> effect system, rather than being the responsibility of a lowly developer. >> It's really interesting. This is related to the reasoning darcs does with >> patches (aka patch theory). Patches tend to have effects on your >> repository. Sometimes those effects can be reordered without changing the >> final state of the repository. Other times, it is not possible to reorder >> them without either having a non-sensible final state or different final >> states. I've never thought about reading research about effect systems for >> the sake of version control. I'll have to look into this. >> >> Jason >> >> _______________________________________________ >> 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 sebastian.sylvan at gmail.com Fri Aug 14 22:21:54 2009 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Fri Aug 14 22:02:11 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> Message-ID: <3d96ac180908141921n37bfbcf8n2a0aab4144304004@mail.gmail.com> On Fri, Aug 14, 2009 at 9:41 PM, John A. De Goes wrote: > > Hmmm, my point (perhaps I wasn't clear), is that different effects have > different commutability properties. In the case of a file system, you can > commute two sequential reads from two different files. > But you can't! I can easily envisage a scenario where there's a link between two pieces of data in two different files, where it's okay if the data in file A is "newer" (in a versioning sense, not a timestamp sense) than the corresponding data in file B, but the opposite doesn't hold. So if you have another program writing that data it will write first to A, and then to B. The program reading this *must* then read the files in the correct order (B then A, to ensure the data from A is always newer or at the same "version" as the data in B). Anytime you talk to the outside world, there may be implicit ordering that you need to respect, so I really think that needs to be serialized. Of course, there may be things in the IO monad that doesn't talk to the outside world that could be commutative. -- Sebastian Sylvan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090814/22d6f479/attachment.html From john at n-brain.net Fri Aug 14 22:55:01 2009 From: john at n-brain.net (John A. De Goes) Date: Fri Aug 14 22:35:22 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <3d96ac180908141921n37bfbcf8n2a0aab4144304004@mail.gmail.com> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> <3d96ac180908141921n37bfbcf8n2a0aab4144304004@mail.gmail.com> Message-ID: On Aug 14, 2009, at 8:21 PM, Sebastian Sylvan wrote: > But you can't! I can easily envisage a scenario where there's a link > between two pieces of data in two different files, where it's okay > if the data in file A is "newer" (in a versioning sense, not a > timestamp sense) than the corresponding data in file B, but the > opposite doesn't hold. So if you have another program writing that > data it will write first to A, and then to B. The program reading > this *must* then read the files in the correct order (B then A, to > ensure the data from A is always newer or at the same "version" as > the data in B). That's nonsense. Because what happens if your program reads A while the other program is writing to A, or reads B just after the other program has written to A, but before it has written to B? As I said before, you cannot make any guarantees in the presence of interference, _with or without_ commuting. So any sensible effects system will assume no interference (perhaps with unsafeXXX functions for when you're OK with shooting yourself in the foot). > Anytime you talk to the outside world, there may be implicit > ordering that you need to respect, so I really think that needs to > be serialized. > Of course, there may be things in the IO monad that doesn't talk to > the outside world that could be commutative. If you don't like the file system, consider mutable memory. An effect system will tell me I can safely update two pieces of non-overlapping, contiguous memory concurrently, even in different threads if the complexity so justifies it. The IO monad is a poor man's solution to the problem of effects. Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 From sebastian.sylvan at gmail.com Fri Aug 14 23:07:10 2009 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Fri Aug 14 22:47:27 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: References: <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> <3d96ac180908141921n37bfbcf8n2a0aab4144304004@mail.gmail.com> Message-ID: <3d96ac180908142007y2905f39cgec566c61951b4488@mail.gmail.com> On Sat, Aug 15, 2009 at 3:55 AM, John A. De Goes wrote: > On Aug 14, 2009, at 8:21 PM, Sebastian Sylvan wrote: > > But you can't! I can easily envisage a scenario where there's a link >> between two pieces of data in two different files, where it's okay if the >> data in file A is "newer" (in a versioning sense, not a timestamp sense) >> than the corresponding data in file B, but the opposite doesn't hold. So if >> you have another program writing that data it will write first to A, and >> then to B. The program reading this *must* then read the files in the >> correct order (B then A, to ensure the data from A is always newer or at the >> same "version" as the data in B). >> > > That's nonsense. Because what happens if your program reads A while the > other program is writing to A Depends on the file system. For example, the file could be locked so you would just block. Or the file system might be transactional. I used files as an example, the point wasn't to get bogged down in exact semantics of concurrent access - assume all reads/writes are atomic (or can be viewed as such from the apps POV) for the purposes of discussion. > , or reads B just after the other program has written to A, but before it > has written to B? This is precisely the scenario that would be legal in that case. You'd end up with data from A that's newer than B, which we said was okay, but for some app-specific reason the opposite is *not* okay. In order for you not to crash you *have* to make sure you read from B first, because otherwise you could read from A right before it's updated, and then read B right after both A and B have been updated which means B is now newer than A and your program goes boom. The point is that the ordering of reads are not arbitrary. > As I said before, you cannot make any guarantees in the presence of > interference, _with or without_ commuting. That's a separate issue. The problem is that if you *do* depend on outside "interference", then the sequence of operations matters. -- Sebastian Sylvan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090814/72148116/attachment.html From sebastian.sylvan at gmail.com Fri Aug 14 23:34:33 2009 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Fri Aug 14 23:14:50 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: References: <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> <3d96ac180908141921n37bfbcf8n2a0aab4144304004@mail.gmail.com> Message-ID: <3d96ac180908142034y36176485q69f49a466f539de1@mail.gmail.com> On Sat, Aug 15, 2009 at 3:55 AM, John A. De Goes wrote: > > If you don't like the file system, consider mutable memory. An effect > system will tell me I can safely update two pieces of non-overlapping, > contiguous memory concurrently, even in different threads if the complexity > so justifies it. I'd like to point out that this relaxation of sequencing for memory operations is already in effect in C on many CPUs. Even though you write things sequentially, it doesn't actually happen sequentially unless you explicitly say so with memory barriers. This causes massive head-aches and horrible bugs that are almost impossible to track down whenever you actually do depend on the order (usually in multi-threading scenarios, e.g. lockless data structures). The point is, the safer option is to enforce a sequential model (like Haskell does), since that way you can always rely on ordering even if you don't even realise you need to, and there's plenty of practical experience indicating that the other option (explicit barriers to indicate when something isn't commutative) is sheer madness. -- Sebastian Sylvan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090814/94dddbac/attachment.html From bugfact at gmail.com Sat Aug 15 04:09:28 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Sat Aug 15 03:49:45 2009 Subject: [Haskell-cafe] qsort Message-ID: I was reading the introduction at http://www.haskell.org/haskellwiki/Introduction where the typical Haskell version of qsort is given qsort [] = [] qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++qsort (filter (>=x ) xs which is then compared to the inplace C version, showing off how much shorter the Haskell version is. However, the page also has a link to a "semi-direct" translation of the C version, which then brings the user to all kinds of confusing threads and texts, like *"**Unfortunately none of the above "real" quicksorts seems to compile as given, when copy/pasted into ghci. Can someone fix? The "parallel" quicksort gave error "unknown package concurrent" when I ran make in quicksort/gransim. Has anyone got a functioning "real" quicksort that works on copy/paste? The program below is working very very slowly. It's probably slowsort... :o)"* * * Furthermore the inplace versions of qsort in Haskell are IMO less readable than the C version. I'm not sure but if I would be a beginner I might get confused by this. It is often claimed that compiler technology will make it possible to compile high level code into efficient low level code that is almost as efficient as the C or asm routines. How does this apply to qsort today? Cheers, Peter Verswyvelen -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090815/a53b661c/attachment.html From david.waern at gmail.com Sat Aug 15 06:04:41 2009 From: david.waern at gmail.com (David Waern) Date: Sat Aug 15 05:44:56 2009 Subject: [Haskell-cafe] ANN: Haddock version 2.5.0 Message-ID: -------------------------------------------- -- Haddock 2.5.0 -------------------------------------------- A new version of Haddock, the Haskell documentation tool, is out! If you're using GHC 6.10.2 and Haddock 2.4.2, you should be able to upgrade to this version without any problem. If you're using something else, you should re-install any documentation that you want to link to after upgrading. Please use the bug tracker to submit bug reports or feature requests. -------------------------------------------- -- Changes in version 2.5.0 -------------------------------------------- * Drop support for GHC 6.8.* * Add support for GHC 6.10.3 and 6.10.4 * Revert to the old multi-page index for large packages (#106) * Show GADT records in the generated documentation * Create the output directory if it doesn't exist (#104) * Use the native codegen instead of compiling via C for TH modules * Add --use-unicode flag for displaying prettier versions of common symbols * Mutiple verbosity levels: remove --verbose and add --verbosity=n * Simpler versioning of .haddock files To avoid slow search, Haddock switches from the searchable index to the old multi-page index for large packages (containing over 150 items). This, and support for GADT records in the generated documentation was implemented by Isaac Dupree as part of his Summer of Code project. The --use-unicode flag was contributed by George Porges. -------------------------------------------- -- Links -------------------------------------------- Homepage: http://www.haskell.org/haddock Hackage page: http://hackage.haskell.org/package/haddock-2.5.0 Bugtracker and wiki: http://trac.haskell.org/haddock Mailing list: haddock@projects.haskell.org Code repository: http://code.haskell.org/haddock -------------------------------------------- -- Contributors -------------------------------------------- The following people contributed patches to this release: Isaac Dupree Ian Lynagh Simon Marlow Simon Peyton-Jones George Porges David Waern -------------------------------------------- -- Future Plans -------------------------------------------- Here are the top priority tickets right now: * Cross-package documentation (#24) * Good warning messages when encountering unexpected Haddock comments (#94) * Comments on instance declarations (#29) Isaac Dupree has been working on the first item as part of his SoC project and it is near completion. If you have any input on what we should prioritize, add yourself to the CC list of the ticket(s) that you are interested in. -------------------------------------------- -- Get Involved -------------------------------------------- We would be very happy to get more contributors. To get involved, start by grabbing the code: http://code.haskell.org/haddock Then take a look at the bug and feature tracker for things to work on: http://trac.haskell.org/haddock From mxcantor at gmail.com Sat Aug 15 08:15:17 2009 From: mxcantor at gmail.com (Max Cantor) Date: Sat Aug 15 07:55:38 2009 Subject: [Haskell-cafe] Request for Comments - hscurrency 0.0.1 Message-ID: Hi all, I'm putting together some simple tools to do safe calculations on different currencies. For instance, making sure that you dont add something like 5 USD + 10 JPY without doing a proper conversion. I've put up some code on google code which probably explains what I'm trying to do more succinctly than this email. I'm curious what poeple think about the library, its the first haskell code I've written for the purpose of sharing and I intend to add it to hackage once I finalize the interface a bit more. The code is at: http://bit.ly/1Cjjlj I'm very open to suggestions on improving the interface. RIght now its very simple and straightforward but potentially limited. I originally wrote it so that the Prc type would be an instance of several numerical classes but eventually stripped that out as it required returning undefined in several cases (such as calling toIntegral on a Prc which was a composite of several currencies). I felt it was better to avoid having partial functions.. Max From jason.dusek at gmail.com Sat Aug 15 08:36:54 2009 From: jason.dusek at gmail.com (Jason Dusek) Date: Sat Aug 15 08:17:10 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> Message-ID: <42784f260908150536t5201b6c5i40541b2fda084fc@mail.gmail.com> 2009/08/14 John A. De Goes : > Hmmm, my point (perhaps I wasn't clear), is that different > effects have different commutability properties. In the case > of a file system, you can commute two sequential reads from > two different files. I think this is a bad example -- it's not something that's safe in general and discredits your idea. How would the compiler even know that two files are not actually the same file? However, the idea that a programmer can specify safely commuting effects is worthwhile. One could operate in a "different files are different" IO monad where the compiler assumes that reads on files with different names are commutable. > This has no effect on the result of the computation, assuming > no interference from other programs -- and if there _is_ > interference from other programs, then guarantees go out the > window, _with or without_ commuting. Well, yes -- which sounds like, there are no guarantees in general. Something that works half the time leaves you with two responsibilities -- the old responsibility of the work you did when you didn't have it and the new responsibility of knowing when it applies and when it doesn't. -- Jason Dusek From kkwweett at yahoo.fr Sat Aug 15 09:51:21 2009 From: kkwweett at yahoo.fr (jean legrand) Date: Sat Aug 15 09:31:38 2009 Subject: [Haskell-cafe] Elerea/GLFW Tetris Message-ID: <517638.63900.qm@web24508.mail.ird.yahoo.com> Hi Haskellers, Here is my first real program in Haskell. http://hpaste.org:80/fastcgi/hpaste.fcgi/view?id=8211 In fact, I'm not fully responsible because it's just an adapted version of a Tetris Creighton Hogg had written for Reactive/GLUT. As the first version, it's a very simple game (no levels, no points ...) but it's playable ! The major problem is when the board is full, the program sadly stops for an empty list : indeed, I wasn't interested in that part and I prefered dealing with the signals. As the frame is the same as the breakout frame, it is also possible to launch the game with ./Tetris --dump-dot | dot -Tsvg -o tetris.svg in order to get an svg showing a graph of the signals. Any help is welcome to understand this graph ! Every comment is welcome (especially about the first 170 lines). Enjoy! From daniel.is.fischer at web.de Sat Aug 15 12:09:38 2009 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Sat Aug 15 11:51:30 2009 Subject: [Haskell-cafe] qsort In-Reply-To: References: Message-ID: <200908151809.38739.daniel.is.fischer@web.de> Am Samstag 15 August 2009 10:09:28 schrieb Peter Verswyvelen: > I was reading the introduction at > http://www.haskell.org/haskellwiki/Introduction > where the typical Haskell version of qsort is given > > qsort [] = [] > qsort (x:xs) = qsort > (filter#v:filter> (< x) xs) > ++ > [x] > ++ >qsort > (filter#v:filter> > (>=gt;=>x ) xs > > which is then compared to the inplace C version, showing off how much > shorter the Haskell version is. > > However, the page also has a link to a "semi-direct" translation of the C > version, which then brings the user to all kinds of confusing threads and > texts, like > > *"**Unfortunately none of the above "real" quicksorts seems to compile as > given, when copy/pasted into ghci. Can someone fix? The "parallel" > quicksort gave error "unknown package concurrent" when I ran make in > quicksort/gransim. Has anyone got a functioning "real" quicksort that works > on copy/paste? The program below is working very very slowly. It's probably > slowsort... :o)"* > * > * > Furthermore the inplace versions of qsort in Haskell are IMO less readable > than the C version. > > I'm not sure but if I would be a beginner I might get confused by this. Okay, the more direct translation of the C code ---------------------------------------------------------- import Data.Array.Base (unsafeRead, unsafeWrite) import Data.Array.ST import Control.Monad.ST myqsort :: STUArray s Int Int -> Int -> Int -> ST s () myqsort a lo hi | lo < hi = do let lscan p h i | i < h = do v <- unsafeRead a i if p < v then return i else lscan p h (i+1) | otherwise = return i rscan p l i | l < i = do v <- unsafeRead a i if v < p then return i else rscan p l (i-1) | otherwise = return i swap i j = do v <- unsafeRead a i unsafeRead a j >>= unsafeWrite a i unsafeWrite a j v sloop p l h | l < h = do l1 <- lscan p h l h1 <- rscan p l1 h if (l1 < h1) then (swap l1 h1 >> sloop p l1 h1) else return l1 | otherwise = return l piv <- unsafeRead a hi i <- sloop piv lo hi swap i hi myqsort a lo (i-1) myqsort a (i+1) hi | otherwise = return () ---------------------------------------------------------------------------------------- doesn't sacrifice performance for polymorphism (the C code isn't polymorphic either) - in my tests, it took less than twice the time the C code took to sort the same array, not too bad. It compiles as is, and if it satisfies readability requirements, somebody can put it on the wiki. > > It is often claimed that compiler technology will make it possible to > compile high level code into efficient low level code that is almost as > efficient as the C or asm routines. How does this apply to qsort today? If you give it a chance to optimise, it isn't too bad. The code from the wiki takes about three times as long as the code above, ** if it's compiled a) with -O2 and b) in a setting where it specialises to the appropriate unboxed array type, be it by giving {-# SPECIALISE #-} pragmas or by having the code in the same module as the use (with a good type, e.g. STUArray s Int Int) **. If you disable optimisations by requiring fully polymorphic code and only that, the factor is about 80. > > Cheers, > Peter Verswyvelen From magnus at therning.org Sat Aug 15 13:06:07 2009 From: magnus at therning.org (Magnus Therning) Date: Sat Aug 15 12:46:25 2009 Subject: [Haskell-cafe] ANN: Haddock version 2.5.0 In-Reply-To: References: Message-ID: <4A86EAFF.5010905@therning.org> David Waern wrote: > -------------------------------------------- > -- Haddock 2.5.0 > -------------------------------------------- > > A new version of Haddock, the Haskell documentation tool, is out! > > If you're using GHC 6.10.2 and Haddock 2.4.2, you should be able to upgrade to > this version without any problem. If you're using something else, you should > re-install any documentation that you want to link to after upgrading. > > Please use the bug tracker to submit bug reports or feature requests. > > -------------------------------------------- > -- Changes in version 2.5.0 > -------------------------------------------- > > * Drop support for GHC 6.8.* > > * Add support for GHC 6.10.3 and 6.10.4 Hmm, does this mean that GHC 6.10.4 ships with a version of Haddock that doesn't handle the compiler it ships with? /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?org http://therning.org/magnus identi.ca|twitter: magthe -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: OpenPGP digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090815/e64e3cc3/signature.bin From aslatter at gmail.com Sat Aug 15 13:23:55 2009 From: aslatter at gmail.com (Antoine Latter) Date: Sat Aug 15 13:04:11 2009 Subject: [Haskell-cafe] Request for Comments - hscurrency 0.0.1 In-Reply-To: References: Message-ID: <694519c50908151023x2282bb86u51a8e22c026a65be@mail.gmail.com> On Sat, Aug 15, 2009 at 7:15 AM, Max Cantor wrote: > Hi all, > > I'm putting together some simple tools to do safe calculations on different > currencies. ?For instance, making sure that you dont add something like 5 > USD + 10 JPY without doing a proper conversion. > > I've put up some code on google code which probably explains what I'm trying > to do more succinctly than this email. ?I'm curious what poeple think about > the library, its the first haskell code I've written for the purpose of > sharing and I intend to add it to hackage once I finalize the interface a > bit more. > > The code is at: http://bit.ly/1Cjjlj > > I'm very open to suggestions on improving the interface. ?RIght now its very > simple and straightforward but potentially limited. > > I originally wrote it so that the Prc type would be an instance of several > numerical classes but eventually stripped that out as it required returning > undefined in several cases (such as calling toIntegral on a Prc which was a > composite of several currencies). ?I felt it was better to avoid having > partial functions.. > The names aren't immediately clear to me, but maybe they make sense in the discipline of currency trading. Are these sorts of calculations commonly done with double precision floats? Doing any sort of currency math with binary floating point numbers feels odd to me, but again, I may not be the target for this sort of library. Antoine From dagit at codersbase.com Sat Aug 15 13:26:10 2009 From: dagit at codersbase.com (Jason Dagit) Date: Sat Aug 15 13:06:25 2009 Subject: [Haskell-cafe] Request for Comments - hscurrency 0.0.1 In-Reply-To: References: Message-ID: On Sat, Aug 15, 2009 at 5:15 AM, Max Cantor wrote: > Hi all, > > I'm putting together some simple tools to do safe calculations on different > currencies. For instance, making sure that you dont add something like 5 > USD + 10 JPY without doing a proper conversion. > > I've put up some code on google code which probably explains what I'm > trying to do more succinctly than this email. I'm curious what poeple think > about the library, its the first haskell code I've written for the purpose > of sharing and I intend to add it to hackage once I finalize the interface a > bit more. > > The code is at: http://bit.ly/1Cjjlj > > I'm very open to suggestions on improving the interface. RIght now its > very simple and straightforward but potentially limited. Right now it looks like you have taken the approach of embedded domain specific language. You have not exposed the currency units to the type system. Therefore you rely on the rules of your embedded language to do proper conversions. Have you considered exposing the type information to the type checker? A similar question came up recently on a Portland functional programming mailing list and my reply can be found here: http://groups.google.com/group/pdxfunc/tree/browse_frm/month/2009-08/5c565768ecf30c57?rnum=1&_done=%2Fgroup%2Fpdxfunc%2Fbrowse_frm%2Fmonth%2F2009-08%3F#doc_5c565768ecf30c57 The experimental code which resulted is here: http://gist.github.com/165691 You may also want to look at the dimensional package: http://code.google.com/p/dimensional/ Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090815/5da2865e/attachment.html From david.waern at gmail.com Sat Aug 15 14:05:58 2009 From: david.waern at gmail.com (David Waern) Date: Sat Aug 15 13:46:15 2009 Subject: [Haskell-cafe] ANN: Haddock version 2.5.0 In-Reply-To: <4A86EAFF.5010905@therning.org> References: <4A86EAFF.5010905@therning.org> Message-ID: 2009/8/15 Magnus Therning : > David Waern wrote: >> >> -------------------------------------------- >> -- Haddock 2.5.0 >> -------------------------------------------- >> >> A new version of Haddock, the Haskell documentation tool, is out! >> >> If you're using GHC 6.10.2 and Haddock 2.4.2, you should be able to >> upgrade to >> this version without any problem. If you're using something else, you >> should >> re-install any documentation that you want to link to after upgrading. >> >> Please use the bug tracker to submit bug reports or feature requests. >> >> -------------------------------------------- >> -- Changes in version 2.5.0 >> -------------------------------------------- >> >> ?* Drop support for GHC 6.8.* >> >> ?* Add support for GHC 6.10.3 and 6.10.4 > > Hmm, does this mean that GHC 6.10.4 ships with a version of Haddock that > doesn't handle the compiler it ships with? Doh. You are right, both 2.4.2 and 2.5.0 work with GHC 6.10.*. Should not have been added to CHANGES. Thanks, David From patai_gergely at fastmail.fm Sat Aug 15 17:12:05 2009 From: patai_gergely at fastmail.fm (Patai Gergely) Date: Sat Aug 15 16:52:19 2009 Subject: [Haskell-cafe] Elerea/GLFW Tetris Message-ID: <1250370725.18411.1330018649@webmail.messagingengine.com> > Here is my first real program in Haskell. How come you started out with playing around with FRP libraries right away? It's a rather peculiar choice, I'd say. > In fact, I'm not fully responsible because it's just an adapted > version of a Tetris Creighton Hogg had written for Reactive/GLUT. > As the first version, it's a very simple game (no levels, no > points ...) but it's playable ! It's an interesting exercise, and quite a nice job from someone who considers themselves a beginner. One thing I don't really understand is why you packed up those applicative combinators in a SignalMonad, i.e. the reason behind flat and sf_sa. You have much more freedom in using them as they are, since they can appear inside any expression. For instance, you could just say the following in the let declaration: sfall = (uncurry . fall) <$> randomBehavior seed sid = pure id Or even better, since both sfall and sid are created by pure combinators, you don't even need to name them if they are used only once anyway: autumn = ifte metronome ((uncurry . fall) <$> randomBehavior seed) (pure id) Another thing, which is really a matter of taste, is that you seem to like point-free style acrobatics. I don't think it's always the best choice, especially if you are to share code with others, since most people grok code with explicit parameters easier than magic involving flip and const and (un)curry and the like, except for the obvious cases of composing a chain of operations, where dropping arguments feels quite natural. For instance, the definition of f_a looks problematic to me because of these concerns. Gergely -- http://www.fastmail.fm - Same, same, but different... From kkwweett at yahoo.fr Sat Aug 15 18:10:34 2009 From: kkwweett at yahoo.fr (jean legrand) Date: Sat Aug 15 17:50:50 2009 Subject: [Haskell-cafe] Elerea/GLFW Tetris In-Reply-To: <1250370725.18411.1330018649@webmail.messagingengine.com> Message-ID: <579176.85999.qm@web24504.mail.ird.yahoo.com> > How come you started out with playing around with FRP > libraries right > away? It's a rather peculiar choice, I'd say. I'm always curious about how the languages I study interact with OpenGL because I'm in the numerical simulation. When I came to Haskell on December, it was quite a new sensation at the functional level first (I knew Scheme but I never tried to find out how Scheme could interact with OpenGL!) and also about IO. But I liked it (and running). Then I studied Reactive but I had some problems installing it on Linux GHC6.6 so I was looking another library and I saw your post on March I think. But my knowledge about Haskell was too light at this time. Then I studied more and here I am! > It's an interesting exercise, and quite a nice job from > someone who > considers themselves a beginner. thanks, it took me a few days but as I said it was floating in my head for a few months. > they can appear inside any expression. For instance, you > could just say > the following in the let declaration: > > sfall = (uncurry . fall) <$> randomBehavior seed > sid = pure id yes, I saw sfall too late (however I haven't thought about sid, thanks) > Another thing, which is really a matter of taste, is that > you seem to > like point-free style acrobatics. I don't think it's always > the best > choice, especially if you are to share code with others, > since most > people grok code with explicit parameters easier than magic > involving > flip and const and (un)curry and the like, except for the > obvious cases > of composing a chain of operations, where dropping > arguments feels quite > natural. For instance, the definition of f_a looks > problematic to me > because of these concerns. > I agree with you in general (point-free is unreadable), but in the case of f_a particularly, it took me a long time (not as long as for sf_a, however) to design it (not the point-free version but the raw one) and I think the point-free version is the best way to dissuade anyone to try to hack it and to persuade her to write a new function which fits her needs. It is actually the reason why I called f_a like this : because its two arguments are a function and a non-function argument (the first argument of sf_a is of course a signal of a function). This means I don't want to know how the machine works when I write my program. But it's a matter of taste as you said. From john at n-brain.net Sat Aug 15 18:45:54 2009 From: john at n-brain.net (John A. De Goes) Date: Sat Aug 15 18:26:11 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <3d96ac180908142007y2905f39cgec566c61951b4488@mail.gmail.com> References: <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> <3d96ac180908141921n37bfbcf8n2a0aab4144304004@mail.gmail.com> <3d96ac180908142007y2905f39cgec566c61951b4488@mail.gmail.com> Message-ID: On Aug 14, 2009, at 9:07 PM, Sebastian Sylvan wrote: > That's a separate issue. The problem is that if you *do* depend on > outside "interference", then the sequence of operations matters. You're example is highly contrived. Were I designing an effect system, I would not design for programs that require outside interference through a medium as uncontrolled as the file system, because (1) if there are applications requiring such measures, they are few and far between, and (2) you cannot make any guarantees about the correctness of programs depending on interference through an uncontrolled medium. Effect system optimizations are about taking programs that are correct, and transforming them to faster but equivalent programs that are still correct. That said, your reasoning precludes the use of file read buffering, and other similar operations that are routinely done. It's only an illusion that such programs are "safe", with or without transformation of sequential read operations. Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 From john at n-brain.net Sat Aug 15 18:54:42 2009 From: john at n-brain.net (John A. De Goes) Date: Sat Aug 15 18:35:01 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <3d96ac180908142034y36176485q69f49a466f539de1@mail.gmail.com> References: <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> <3d96ac180908141921n37bfbcf8n2a0aab4144304004@mail.gmail.com> <3d96ac180908142034y36176485q69f49a466f539de1@mail.gmail.com> Message-ID: <6A1A0FDE-E416-4FB5-BC62-95CB05D23C09@n-brain.net> On Aug 14, 2009, at 9:34 PM, Sebastian Sylvan wrote: > On Sat, Aug 15, 2009 at 3:55 AM, John A. De Goes > wrote: > If you don't like the file system, consider mutable memory. An > effect system will tell me I can safely update two pieces of non- > overlapping, contiguous memory concurrently, even in different > threads if the complexity so justifies it. > > I'd like to point out that this relaxation of sequencing for memory > operations is already in effect in C on many CPUs. Even though you > write things sequentially, it doesn't actually happen sequentially > unless you explicitly say so with memory barriers. This causes > massive head-aches and horrible bugs that are almost impossible to > track down whenever you actually do depend on the order (usually in > multi-threading scenarios, e.g. lockless data structures). That's because C has no effect system and is too low-level for an effect system. That's no argument against one in a high-level language similar in syntax to Haskell. > The point is, the safer option is to enforce a sequential model > (like Haskell does), since that way you can always rely on ordering > even if you don't even realise you need to, and there's plenty of > practical experience indicating that the other option (explicit > barriers to indicate when something isn't commutative) is sheer > madness. Your point about safety in C has no relation to safety in a functional language with a sophisticated effect system. Haskell enforces a sequential model not because it's safer (it's NOT), but because it's simpler and because it's the best Haskell monads can do. Unfortunately, it doesn't fly in a world with dozens of cores. Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090815/08df147f/attachment.html From sebastian.sylvan at gmail.com Sat Aug 15 18:59:45 2009 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Sat Aug 15 18:39:59 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <6A1A0FDE-E416-4FB5-BC62-95CB05D23C09@n-brain.net> References: <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> <3d96ac180908141921n37bfbcf8n2a0aab4144304004@mail.gmail.com> <3d96ac180908142034y36176485q69f49a466f539de1@mail.gmail.com> <6A1A0FDE-E416-4FB5-BC62-95CB05D23C09@n-brain.net> Message-ID: <3d96ac180908151559v348916cei28ca3f57f9125886@mail.gmail.com> On Sat, Aug 15, 2009 at 11:54 PM, John A. De Goes wrote: > On Aug 14, 2009, at 9:34 PM, Sebastian Sylvan wrote: > > On Sat, Aug 15, 2009 at 3:55 AM, John A. De Goes wrote: >> >> If you don't like the file system, consider mutable memory. An effect >> system will tell me I can safely update two pieces of non-overlapping, >> contiguous memory concurrently, even in different threads if the complexity >> so justifies it. > > > I'd like to point out that this relaxation of sequencing for memory > operations is already in effect in C on many CPUs. Even though you write > things sequentially, it doesn't actually happen sequentially unless you > explicitly say so with memory barriers. This causes massive head-aches and > horrible bugs that are almost impossible to track down whenever you actually > do depend on the order (usually in multi-threading scenarios, e.g. lockless > data structures). > > > That's because C has no effect system and is too low-level for an effect > system. That's no argument against one in a high-level language similar in > syntax to Haskell. > ... > > Your point about safety in C has no relation to safety in a functional > language with a sophisticated effect system. > I'm sorry, but I think it does. You're advocating that modifications to mutable state shouldn't have sequential semantics, I'm pointing out that this is the case today in C on many CPUs and it's a royal pain to work with in practice (causing many almost-impossible-to-debug crashes). I would not want functional languages to adopt something that's proven to be insanity-inducingly difficult to use. -- Sebastian Sylvan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090815/939fba25/attachment.html From john at n-brain.net Sat Aug 15 19:05:33 2009 From: john at n-brain.net (John A. De Goes) Date: Sat Aug 15 18:45:52 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <42784f260908150536t5201b6c5i40541b2fda084fc@mail.gmail.com> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> <42784f260908150536t5201b6c5i40541b2fda084fc@mail.gmail.com> Message-ID: On Aug 15, 2009, at 6:36 AM, Jason Dusek wrote: > 2009/08/14 John A. De Goes : >> Hmmm, my point (perhaps I wasn't clear), is that different >> effects have different commutability properties. In the case >> of a file system, you can commute two sequential reads from >> two different files. > > I think this is a bad example -- it's not something that's > safe in general and discredits your idea. How would the > compiler even know that two files are not actually the same > file? I don't think the file system is the best example. However, I do think it's a reasonable one. Let's say the type of the function getFilesInDir is annotated in such a way as to tell the effect system that every file in the returned array is unique. Further, let's say the type of the function makeNewTempFile is annotated in such a way as to tell the effect system that the function will succeed in creating a new temp file with a name unique from any other existing file. Then if you write a recursive function that loops through all files in a directory, and for each file, it parses and compiles the file into a new temp file, then a sufficiently sophisticated compiler should be able to safely transform the recursion into parallel parsing and compilation -- in a way that's provably correct, assuming the original program was correct. The promise of a language with a purely functional part and a powerful effect system for everything else is very great. And very important in the massively concurrent world we are entering. > Well, yes -- which sounds like, there are no guarantees > in general. Something that works half the time leaves you with > two responsibilities -- the old responsibility of the work you > did when you didn't have it and the new responsibility of > knowing when it applies and when it doesn't. In the other thread, I brought up the example of buffering reads. Library authors make the decision to buffer for one reason: because if some other program is messing with the data, you're screwed no matter what. And yeah, "they might be screwing with the data in just the way you need it to be screwed with," (Sebastian), in which case my advice is use C and hope for the best. :-) Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 From sebastian.sylvan at gmail.com Sat Aug 15 19:07:46 2009 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Sat Aug 15 18:48:00 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: References: <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> <3d96ac180908141921n37bfbcf8n2a0aab4144304004@mail.gmail.com> <3d96ac180908142007y2905f39cgec566c61951b4488@mail.gmail.com> Message-ID: <3d96ac180908151607x7e104601w468877c00a06488f@mail.gmail.com> On Sat, Aug 15, 2009 at 11:45 PM, John A. De Goes wrote: > > Effect system optimizations are about taking programs that are correct, and > transforming them to faster but equivalent programs that are still correct. And since reordering access to externally modifiable data (external includes memory if it's visible to other therads) is *not* safe, that shouldn't be done. You're arguing for doing unsafe (i.e. they can cause a functioning program to become non-functioning) transformations! That said, your reasoning precludes the use of file read buffering, and > other similar operations that are routinely done. It's only an illusion that > such programs are "safe", with or without transformation of sequential read > operations. Yes, you do have to be very careful about abstractions like that, but the fact that we have some of that now, which can cause very hard-to-catch bugs when you rely on ordering, is no good argument that we should add even more of it! -- Sebastian Sylvan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090815/29d51959/attachment.html From john at n-brain.net Sat Aug 15 19:18:05 2009 From: john at n-brain.net (John A. De Goes) Date: Sat Aug 15 18:58:22 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <3d96ac180908151559v348916cei28ca3f57f9125886@mail.gmail.com> References: <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> <3d96ac180908141921n37bfbcf8n2a0aab4144304004@mail.gmail.com> <3d96ac180908142034y36176485q69f49a466f539de1@mail.gmail.com> <6A1A0FDE-E416-4FB5-BC62-95CB05D23C09@n-brain.net> <3d96ac180908151559v348916cei28ca3f57f9125886@mail.gmail.com> Message-ID: On Aug 15, 2009, at 4:59 PM, Sebastian Sylvan wrote: > > Your point about safety in C has no relation to safety in a > functional language with a sophisticated effect system. > > I'm sorry, but I think it does. You're advocating that modifications > to mutable state shouldn't have sequential semantics, You must think I'm arguing for some kind of low-level analog of C, augmented with an effect system. I'm not. You can't do that. To maximize the potential for optimization, you need a high-level language, mostly functional, with a very sophisticated and carefully controlled effects system for expressing imperative actions. If you have threads and shared mutable state, then you might require that any access to shared state be done through an atomic block (STM). The type system would encode if mutable variables can be shared between threads, and if so, the compiler would mandate they be accessed from inside an atomic block. In such conditions, multiple sequential writes can be safely parallelized, in addition to a host of other optimizations. > I'm pointing out that this is the case today in C on many CPUs and > it's a royal pain to work with in practice (causing many almost- > impossible-to-debug crashes). I would not want functional languages > to adopt something that's proven to be insanity-inducingly difficult > to use. Please don't ever bring up C again. You can't do anything interesting in C. Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 From sebastian.sylvan at gmail.com Sat Aug 15 19:32:30 2009 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Sat Aug 15 19:12:43 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: References: <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> <3d96ac180908141921n37bfbcf8n2a0aab4144304004@mail.gmail.com> <3d96ac180908142034y36176485q69f49a466f539de1@mail.gmail.com> <6A1A0FDE-E416-4FB5-BC62-95CB05D23C09@n-brain.net> <3d96ac180908151559v348916cei28ca3f57f9125886@mail.gmail.com> Message-ID: <3d96ac180908151632l58ab531epbd08878c47f8ee09@mail.gmail.com> On Sun, Aug 16, 2009 at 12:18 AM, John A. De Goes wrote: > On Aug 15, 2009, at 4:59 PM, Sebastian Sylvan wrote: > > >> Your point about safety in C has no relation to safety in a functional >> language with a sophisticated effect system. >> >> I'm sorry, but I think it does. You're advocating that modifications to >> mutable state shouldn't have sequential semantics, >> > > You must think I'm arguing for some kind of low-level analog of C, > augmented with an effect system. I'm not. You can't do that. No, I don't. I think you're arguing for making access to mutable state commutative. Are you not? > In such conditions, multiple sequential writes can be safely parallelized, > in addition to a host of other optimizations. I'm not saying you shouldn't parallelise them in very specific circumstances *where it's safe*, I'm just saying that you shouldn't assume that it's safe unless you know it is. If you want to do a transformation that's unsafe in general, but safe in a specific circumstance, then of course, go ahead! To my reading it seems like you're arguing that memory/file access should *always* be considered commutative though, which is what I'm objecting too. > I'm pointing out that this is the case today in C on many CPUs and it's a >> royal pain to work with in practice (causing many almost-impossible-to-debug >> crashes). I would not want functional languages to adopt something that's >> proven to be insanity-inducingly difficult to use. >> > > Please don't ever bring up C again. You can't do anything interesting in C. I bring up C until you can explain how what you're suggesting is any different from the current state in C w.r.t. the ordering of memory access. >From what you've said so far I can't see how it is, and it would be instructive to look at the problems with the approach you're advocating since we're dealing with its pitfalls *today* in the real world. -- Sebastian Sylvan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090815/96cdb792/attachment.html From porges at porg.es Sat Aug 15 23:34:57 2009 From: porges at porg.es (porges@porg.es) Date: Sat Aug 15 23:15:21 2009 Subject: [Haskell-cafe] ANN: Haddock version 2.5.0 In-Reply-To: Message-ID: > George Porges s/Porges/Pollard/; Porges is just an alias :) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 908 bytes Desc: OpenPGP digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090815/197487fe/signature.bin From artem at AA5779.spb.edu Sun Aug 16 02:38:03 2009 From: artem at AA5779.spb.edu (Artem V. Andreev) Date: Sun Aug 16 02:18:25 2009 Subject: [Haskell-cafe] Re: DDC compiler and effects; better than Haskell? In-Reply-To: (John A. De Goes's message of "Sat\, 15 Aug 2009 17\:05\:33 -0600") References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> <42784f260908150536t5201b6c5i40541b2fda084fc@mail.gmail.com> Message-ID: <87ocqgxnzo.fsf@artemsmp.iling.nw.ru> "John A. De Goes" writes: > On Aug 15, 2009, at 6:36 AM, Jason Dusek wrote: >> 2009/08/14 John A. De Goes : >>> Hmmm, my point (perhaps I wasn't clear), is that different >>> effects have different commutability properties. In the case >>> of a file system, you can commute two sequential reads from >>> two different files. >> >> I think this is a bad example -- it's not something that's >> safe in general and discredits your idea. How would the >> compiler even know that two files are not actually the same >> file? > > I don't think the file system is the best example. However, I do think it's a reasonable one. > > Let's say the type of the function getFilesInDir is annotated in such a way as to tell the effect > system that every file in the returned array is unique. Further, let's say the type of the > function makeNewTempFile is annotated in such a way as to tell the effect system that the > function will succeed in creating a new temp file with a name unique from any other existing > file. Sorry, but this example is ridiculuous. While file *names* in this case might be reasonably assumed to be unique, the *files* themselves may not. Any modern filesystem does support file aliasing, and usually several forms thereof. And what does makeNewTempFile function do? Does it create a new file like POSIX mktemp() and return its name, or does it rather behave as POSIX mkstemp()? The first case is a well known security hole, and the second case does not, as it seems to me, fit well into the rest of your reasoning. However, let's consider further file system tree traversal. In some cases you might not care, whether some of the directories you descend into are actually the same directory, so your proposed optimization would be `safe'. However, in other cases sequential traversal would work, while a parallelized version would not, unless special additional measures are taken. E.g. consider a case of a build system. It traverses a source tree, finds sources files and if corresponding object files are non-existent or outdated, does something to regenerate them. Now if you have a directory that's actually a link to another directory, and you do sequential traversal, everything is fine: you descend into the directory the first time, build everything there and when you descend into it the second time, there's just nothing to do. If you do parallel traversal, you may well end up in the situation where two threads check simultaneously for an object file, discover it's outdated and run two build processes simultaneously, with the most likely effect of corrupted object file. > Then if you write a recursive function that loops through all files in a directory, and for each > file, it parses and compiles the file into a new temp file, then a sufficiently sophisticated > compiler should be able to safely transform the recursion into parallel parsing and compilation > -- in a way that's provably correct, assuming the original program was correct. > > The promise of a language with a purely functional part and a powerful effect system for > everything else is very great. And very important in the massively concurrent world we are > entering. > >> Well, yes -- which sounds like, there are no guarantees >> in general. Something that works half the time leaves you with >> two responsibilities -- the old responsibility of the work you >> did when you didn't have it and the new responsibility of >> knowing when it applies and when it doesn't. > > In the other thread, I brought up the example of buffering reads. Library authors make the > decision to buffer for one reason: because if some other program is messing with the data, you're > screwed no matter what. > > And yeah, "they might be screwing with the data in just the way you need it to be screwed with," > (Sebastian), in which case my advice is use C and hope for the best. :-) > > Regards, > > John A. De Goes > N-Brain, Inc. > The Evolution of Collaboration > > http://www.n-brain.net | 877-376-2724 x 101 > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- S. Y. A(R). A. From axman6 at gmail.com Sun Aug 16 03:26:43 2009 From: axman6 at gmail.com (Alex Mason) Date: Sun Aug 16 03:07:04 2009 Subject: [Haskell-cafe] why does the binary library require so much memory? In-Reply-To: <20090731212730.GX809@whirlpool.galois.com> References: <87prbg607u.wl%jeremy@n-heptane.com> <20090731212730.GX809@whirlpool.galois.com> Message-ID: <224729E9-8CC2-48FC-8AE3-9C061270C63F@gmail.com> Hi Don, I was wondering if perhaps this might be a slightly better instance for Binary [a], that might solve a) the problem of having to traverse the entire list first, and b) the list length limitation of using length and Ints. My version is hopefully a little more lazy (taking maxBound :: Word16 elements at a time), and should potentially allow infinite lists to be stored: import Data.Binary import Data.Binary.Get import Data.Binary.Put import Data.Word newtype List a = List [a] deriving (Show,Eq) instance Binary a => Binary (List a) where put (List xs) = do let (hd,num,tl) = btake maxBound xs putWord16be num if num == 0 then return () else do mapM_ put hd put (List tl) get = do num <- getWord16be if num > 0 then do xs <- sequence (replicate (fromIntegral num) get) List ys <- get return (List (xs ++ ys)) else return (List []) btake :: Word16 -> [a] -> ([a],Word16,[a]) btake n xs = btake' n n xs btake' :: Word16 -> Word16 -> [a] -> ([a],Word16,[a]) btake' 0 m xs = ([],m,xs) btake' n m [] = ([],m-n,[]) btake' !n m (x:xs) = (x:xs',n',ys) where (xs',n',ys) = btake' (n-1) m xs My testing of this version shows that it's terribly bad when it comes to memory usage, but I'm sure someone can find a more efficient way to do what I'm trying here. -- Axman On 01/08/2009, at 07:27, Don Stewart wrote: > bos: >> On Fri, Jul 31, 2009 at 1:56 PM, Jeremy Shaw >> wrote: >> >> >> Using encode/decode from Binary seems to permamently increase my >> memory consumption by 60x fold. I am wonder if I am doing >> something >> wrong, or if this is an issue with Binary. >> >> >> It's an issue with the Binary instance for lists, which forces the >> entire spine >> of the list too early. This gives you a gigantic structure to hold >> onto. > > This is the current instance > > instance Binary a => Binary [a] where > put l = put (length l) >> mapM_ put l > get = do n <- get :: Get Int > getMany n > > -- | 'getMany n' get 'n' elements in order, without blowing the > stack. > getMany :: Binary a => Int -> Get [a] > getMany n = go [] n > where > go xs 0 = return $! reverse xs > go xs i = do x <- get > -- we must seq x to avoid stack overflows due to > laziness in > -- (>>=) > x `seq` go (x:xs) (i-1) > > It used to be this, though, > > xs <- replicateM n get -- now the elems. > > > -- Don > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From johan.tibell at gmail.com Sun Aug 16 04:25:17 2009 From: johan.tibell at gmail.com (Johan Tibell) Date: Sun Aug 16 04:05:51 2009 Subject: [Haskell-cafe] GSoC profiling project to be wrapped up In-Reply-To: <1250280485.3119.1329912103@webmail.messagingengine.com> References: <1250019999.30414.1329375813@webmail.messagingengine.com> <20090812210318.GY29909@whirlpool.galois.com> <1250280485.3119.1329912103@webmail.messagingengine.com> Message-ID: <90889fe70908160125n66a13712i4525550ad6e38360@mail.gmail.com> 2009/8/14 Patai Gergely : >> > I finally uploaded the profiling tools to Hackage. The package names are >> > hp2any-{core,graph,manager}. The first two should be possible to install >> > right away, while the manager needs Gtk2Hs. A bit more on the project >> > and this update at . >> >> Do you have an overview somewhere of the tools and how to use them? > > I just added an entry to HaskellWiki: > > http://www.haskell.org/haskellwiki/Hp2any As his mentor, I would like to thank Gergely for all the hard work he did this summer. I'm very happy with the result. Please try the real time profiler next time you need to debug a memory issue and send Gergely your feedback (and bug reports). Cheers, Johan From gwern0 at gmail.com Sun Aug 16 04:29:35 2009 From: gwern0 at gmail.com (Gwern Branwen) Date: Sun Aug 16 04:09:48 2009 Subject: [Haskell-cafe] qsort In-Reply-To: <200908151809.38739.daniel.is.fischer@web.de> References: <200908151809.38739.daniel.is.fischer@web.de> Message-ID: On Sat, Aug 15, 2009 at 12:09 PM, Daniel Fischer wrote: > It compiles as is, and if it satisfies readability requirements, somebody can put it on > the wiki. > http://www.haskell.org/haskellwiki/?title=Introduction%2FDirect_Translation&diff=29575&oldid=21061 I've done so; it'd be nice if you could add some usage examples and timings (especially of the 80x performance of the original). -- gwern From david.waern at gmail.com Sun Aug 16 04:46:29 2009 From: david.waern at gmail.com (David Waern) Date: Sun Aug 16 04:26:43 2009 Subject: [Haskell-cafe] ANN: Haddock version 2.5.0 In-Reply-To: References: Message-ID: 2009/8/16 : >> George Porges > > s/Porges/Pollard/; Porges is just an alias :) Oh, sorry about that! I tried to google on your email address but didn't find anything, so I assumed Porges was your surname. I should start sending out my release notes for revivew ;-) David From marcin.kosiba at gmail.com Sun Aug 16 04:46:39 2009 From: marcin.kosiba at gmail.com (Marcin Kosiba) Date: Sun Aug 16 04:27:02 2009 Subject: [Haskell-cafe] Re: DDC compiler and effects; better than Haskell? In-Reply-To: <87ocqgxnzo.fsf@artemsmp.iling.nw.ru> References: <87ocqgxnzo.fsf@artemsmp.iling.nw.ru> Message-ID: <200908161046.42906.marcin.kosiba@gmail.com> On Sunday 16 August 2009, Artem V. Andreev wrote: > "John A. De Goes" writes: > > On Aug 15, 2009, at 6:36 AM, Jason Dusek wrote: > >> 2009/08/14 John A. De Goes : > >>> Hmmm, my point (perhaps I wasn't clear), is that different > >>> effects have different commutability properties. In the case > >>> of a file system, you can commute two sequential reads from > >>> two different files. > >> > >> I think this is a bad example -- it's not something that's > >> safe in general and discredits your idea. How would the > >> compiler even know that two files are not actually the same > >> file? > > > > I don't think the file system is the best example. However, I do think > > it's a reasonable one. > > > > Let's say the type of the function getFilesInDir is annotated in such a > > way as to tell the effect system that every file in the returned array > > is unique. Further, let's say the type of the function makeNewTempFile > > is annotated in such a way as to tell the effect system that the > > function will succeed in creating a new temp file with a name unique > > from any other existing file. > > Sorry, but this example is ridiculuous. While file *names* in this case > might be reasonably assumed to be unique, the *files* themselves may not. > Any modern filesystem does support file aliasing, and usually several forms > thereof. And what does makeNewTempFile function do? Does it create a new > file like POSIX mktemp() and return its name, or does it rather behave as > POSIX mkstemp()? The first case is a well known security hole, and the > second case does not, as it seems to me, fit well into the rest of your > reasoning. Hi, IMHO, provided with a flexible effect system, the decision on how to do read/write operations on files is a matter of libraries. But I'd like to ask another question: is the effects system you're discussing now really capable of providing significant performance improvements in case of file I/O? Even if we assume some consistency model and transform one correct program to another one -- how do you estimate efficiency without knowledge of physical media characteristics? I kinda see how this could be used to optimize different kinds of media access (reordering socket/file operations or even running some of those in parallel), but I don't see how can we benefit from reordering writes to the same media. Another thing is that not every kind of r/w operation requires the same consistency model -- like when I'm writing a backup for later use I only care about my writes being in the same order. I imagine that such an effect system could help write software for CC-NUMA architectures or shared-memory distributed systems. -- Thanks! Marcin Kosiba -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part. Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090816/8e2b0b45/attachment.bin From uzytkownik2 at gmail.com Sun Aug 16 06:45:42 2009 From: uzytkownik2 at gmail.com (Maciej Piechotka) Date: Sun Aug 16 06:26:18 2009 Subject: [Haskell-cafe] Calling function with unknown number and type arguments Message-ID: <1250419542.8044.67.camel@notebook> I have to write a function which calls a function with unknown (i.e. given in runtime) number and type of arguments. 1. Use closure implementation from Gtk2Hs. Pros: Written Cons: Not in haskell 2. Use unsafeCoerce. Something like: f a b = return (a + b) f' = unsafeCoerce (f :: Int -> Int -> IO Int) :: IO () unsafeCoerce (unsafeCoerce ((unsafeCoerce f' :: Int -> IO ()) 5) :: Int -> IO ()) 4 :: IO Int (of course it is an example in fact it will be not only Int etc.) Personally I'd prefere in-haskell solution as: - Rts API used by Gtk2Hs is 'semi-public' - It is GHC-specific (?) but I'm not sure if my solution is safe. Regards -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090816/0ee74bcb/attachment-0001.bin From mauricio.antunes at gmail.com Sun Aug 16 09:21:31 2009 From: mauricio.antunes at gmail.com (=?ISO-8859-1?Q?Maur=ED=ADcio_CA?=) Date: Sun Aug 16 09:02:05 2009 Subject: [Haskell-cafe] Blank definition list in haddock Message-ID: I read in haddock documentation that we write definition lists like this: -- [@something@] Definition of something. However, using that structure to document many itens, I get a blank list of definitions, like you can see in this section ('Macros') of the documentation for a package of mine: http://hackage.haskell.org/packages/archive/bindings-common/0.2.2/doc/html/Bindings.html#3 However, as can be seen in the source code, there are many definitions inside 'Macros' section. http://hackage.haskell.org/packages/archive/bindings-common/0.2.2/doc/html/src/Bindings.html Did I used those definitons the wrong way? Thanks, Maur?cio From john at n-brain.net Sun Aug 16 09:33:50 2009 From: john at n-brain.net (John A. De Goes) Date: Sun Aug 16 09:14:06 2009 Subject: [Haskell-cafe] Re: DDC compiler and effects; better than Haskell? In-Reply-To: <87ocqgxnzo.fsf@artemsmp.iling.nw.ru> References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> <42784f260908150536t5201b6c5i40541b2fda084fc@mail.gmail.com> <87ocqgxnzo.fsf@artemsmp.iling.nw.ru> Message-ID: <2DED3DCA-2678-455A-ACEF-23AD22A0A209@n-brain.net> I forgot about links. In that case, consider: getUniqueFilesInDirRecursive. Attacking irrelevant details in an argument is often called a "strawman attack". Such attacks are pointless because they do not address the real substance of the issue. My example is easily modified to avoid the issues you raise. Consider the fact that many file-based operations _can and are parallelized manually by developers_. The challenge for next generation language and effect system designers is to figure out _how_ such operations can be automatically parallelized, given sufficient constraints, high-level constructs, and a powerful effect system. Saying, "I don't know exactly how it will look," is quite a bit different from saying "It can't be done." I claim the former. Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 On Aug 16, 2009, at 12:38 AM, Artem V. Andreev wrote: > "John A. De Goes" writes: > >> On Aug 15, 2009, at 6:36 AM, Jason Dusek wrote: >>> 2009/08/14 John A. De Goes : >>>> Hmmm, my point (perhaps I wasn't clear), is that different >>>> effects have different commutability properties. In the case >>>> of a file system, you can commute two sequential reads from >>>> two different files. >>> >>> I think this is a bad example -- it's not something that's >>> safe in general and discredits your idea. How would the >>> compiler even know that two files are not actually the same >>> file? >> >> I don't think the file system is the best example. However, I do >> think it's a reasonable one. >> >> Let's say the type of the function getFilesInDir is annotated in >> such a way as to tell the effect >> system that every file in the returned array is unique. Further, >> let's say the type of the >> function makeNewTempFile is annotated in such a way as to tell the >> effect system that the >> function will succeed in creating a new temp file with a name >> unique from any other existing >> file. > Sorry, but this example is ridiculuous. While file *names* in this > case might be reasonably assumed > to be unique, the *files* themselves may not. Any modern filesystem > does support file aliasing, > and usually several forms thereof. And what does makeNewTempFile > function do? Does it create a new > file like POSIX mktemp() and return its name, or does it rather > behave as POSIX mkstemp()? > The first case is a well known security hole, and the second case > does not, as it seems to me, fit > well into the rest of your reasoning. > > However, let's consider further file system tree traversal. In some > cases you might not care, whether > some of the directories you descend into are actually the same > directory, so your proposed optimization > would be `safe'. However, in other cases sequential traversal would > work, while a parallelized version > would not, unless special additional measures are taken. E.g. > consider a case of a build system. It > traverses a source tree, finds sources files and if corresponding > object files are non-existent or > outdated, does something to regenerate them. Now if you have a > directory that's actually a link to > another directory, and you do sequential traversal, everything is > fine: you descend into the directory > the first time, build everything there and when you descend into it > the second time, there's just nothing > to do. If you do parallel traversal, you may well end up in the > situation where two threads check > simultaneously for an object file, discover it's outdated and run > two build processes simultaneously, > with the most likely effect of corrupted object file. > > >> Then if you write a recursive function that loops through all files >> in a directory, and for each >> file, it parses and compiles the file into a new temp file, then a >> sufficiently sophisticated >> compiler should be able to safely transform the recursion into >> parallel parsing and compilation >> -- in a way that's provably correct, assuming the original program >> was correct. >> >> The promise of a language with a purely functional part and a >> powerful effect system for >> everything else is very great. And very important in the massively >> concurrent world we are >> entering. >> >>> Well, yes -- which sounds like, there are no guarantees >>> in general. Something that works half the time leaves you with >>> two responsibilities -- the old responsibility of the work you >>> did when you didn't have it and the new responsibility of >>> knowing when it applies and when it doesn't. >> >> In the other thread, I brought up the example of buffering reads. >> Library authors make the >> decision to buffer for one reason: because if some other program >> is messing with the data, you're >> screwed no matter what. >> >> And yeah, "they might be screwing with the data in just the way >> you need it to be screwed with," >> (Sebastian), in which case my advice is use C and hope for the >> best. :-) >> >> Regards, >> >> John A. De Goes >> N-Brain, Inc. >> The Evolution of Collaboration >> >> http://www.n-brain.net | 877-376-2724 x 101 >> >> >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> > > -- > > S. Y. A(R). A. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From david.waern at gmail.com Sun Aug 16 09:34:05 2009 From: david.waern at gmail.com (David Waern) Date: Sun Aug 16 09:14:20 2009 Subject: [Haskell-cafe] Blank definition list in haddock In-Reply-To: References: Message-ID: 2009/8/16 Maur??cio CA : > I read in haddock documentation that we write > definition lists like this: > > -- ?[@something@] Definition of something. > > However, using that structure to document many > itens, I get a blank list of definitions, like > you can see in this section ('Macros') of the > documentation for a package of mine: > > http://hackage.haskell.org/packages/archive/bindings-common/0.2.2/doc/html/Bindings.html#3 > > However, as can be seen in the source code, there > are many definitions inside 'Macros' section. > > http://hackage.haskell.org/packages/archive/bindings-common/0.2.2/doc/html/src/Bindings.html > > > Did I used those definitons the wrong way? I think the problem is that you have written normal comments instead of Haddock comments. Try adding a | in front of the paragraphs, or just merge them all into one Haddock comment by inserting "--" in front of the blank lines in between your paragraphs. David From john at n-brain.net Sun Aug 16 09:38:36 2009 From: john at n-brain.net (John A. De Goes) Date: Sun Aug 16 09:18:52 2009 Subject: [Haskell-cafe] Re: DDC compiler and effects; better than Haskell? In-Reply-To: <200908161046.42906.marcin.kosiba@gmail.com> References: <87ocqgxnzo.fsf@artemsmp.iling.nw.ru> <200908161046.42906.marcin.kosiba@gmail.com> Message-ID: I chose this example specifically because parsing/compiling is not IO- bound. Many build systems today achieve multi-core scaling by parallelizing all the phases: parsing, semantic analysis, and compilation. Your question is a good one and one we face already in auto- parallelization of purely functional code: how do you know when the cost of doing something in another thread is overwhelmed by the benefit? I think JIT compilation provides the ultimate answer to these types of questions, because you can make guesses, and if you get them wrong, simply try again. Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 On Aug 16, 2009, at 2:46 AM, Marcin Kosiba wrote: >> Hi, > IMHO, provided with a flexible effect system, the decision on how > to do > read/write operations on files is a matter of libraries. > But I'd like to ask another question: is the effects system you're > discussing > now really capable of providing significant performance improvements > in case > of file I/O? Even if we assume some consistency model and transform > one > correct program to another one -- how do you estimate efficiency > without > knowledge of physical media characteristics? I kinda see how this > could be > used to optimize different kinds of media access (reordering socket/ > file > operations or even running some of those in parallel), but I don't > see how > can we benefit from reordering writes to the same media. > Another thing is that not every kind of r/w operation requires the > same > consistency model -- like when I'm writing a backup for later use I > only care > about my writes being in the same order. I imagine that such an > effect system > could help write software for CC-NUMA architectures or shared-memory > distributed systems. > -- > Thanks! > Marcin Kosiba > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From john at n-brain.net Sun Aug 16 09:50:43 2009 From: john at n-brain.net (John A. De Goes) Date: Sun Aug 16 09:31:00 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <3d96ac180908151632l58ab531epbd08878c47f8ee09@mail.gmail.com> References: <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> <3d96ac180908141921n37bfbcf8n2a0aab4144304004@mail.gmail.com> <3d96ac180908142034y36176485q69f49a466f539de1@mail.gmail.com> <6A1A0FDE-E416-4FB5-BC62-95CB05D23C09@n-brain.net> <3d96ac180908151559v348916cei28ca3f57f9125886@mail.gmail.com> <3d96ac180908151632l58ab531epbd08878c47f8ee09@mail.gmail.com> Message-ID: <4DD4AE93-8CBC-43B1-9995-A06D3D40582F@n-brain.net> On Aug 15, 2009, at 5:32 PM, Sebastian Sylvan wrote: > On Sun, Aug 16, 2009 at 12:18 AM, John A. De Goes > wrote: > You must think I'm arguing for some kind of low-level analog of C, > augmented with an effect system. I'm not. You can't do that. > > No, I don't. I think you're arguing for making access to mutable > state commutative. Are you not? There are many cases when mutation to state _is_ commutative. I can't argue that certain operations are _always_ commutative without talking about the language. Pretend I'm arguing for a mostly functional language and effect system that maximize the opportunities for parallelizing code. > I'm not saying you shouldn't parallelise them in very specific > circumstances *where it's safe*, I'm just saying that you shouldn't > assume that it's safe unless you know it is. If you want to do a > transformation that's unsafe in general, but safe in a specific > circumstance, then of course, go ahead! > To my reading it seems like you're arguing that memory/file access > should *always* be considered commutative though, which is what I'm > objecting too. In the right language, many times of memory (and possibly file) operations _always_ commute. In the wrong language, they _sometimes_ commute or _never_ provably commute. I'm not arguing for the assumption in any language where it is false. Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090816/36e5f40f/attachment.html From mxcantor at gmail.com Sun Aug 16 09:55:28 2009 From: mxcantor at gmail.com (Max Cantor) Date: Sun Aug 16 09:35:46 2009 Subject: [Haskell-cafe] Request for Comments - hscurrency 0.0.1 In-Reply-To: References: Message-ID: <7A6B927F-9DA4-439A-A661-8EFBB9809065@gmail.com> @Jason I'm not sure what you mean about exposing the type information. Unless you mean that each currency would be a separate type somehow. While this is a similar problem to the dimensional issue, the problem is that the FX rates are changing all the time. While the conversion between a meter and a foot is always constant, with FX rates thats not the case. So 2ft + 3m is always a well defined value but something like USD 1 + JPY 1 gives a function of the USDJPY exchange rate, not a constant value. @ Antoine I'll add some comments. you're right that doubles are not typically used nor would they be in a finished product. for the time being, however, I dont know if its better to use Ratio's, Fixed's or what, so just settled on the most straightforward for now. On Aug 16, 2009, at 1:26 AM, Jason Dagit wrote: > > > On Sat, Aug 15, 2009 at 5:15 AM, Max Cantor > wrote: > Hi all, > > I'm putting together some simple tools to do safe calculations on > different currencies. For instance, making sure that you dont add > something like 5 USD + 10 JPY without doing a proper conversion. > > I've put up some code on google code which probably explains what > I'm trying to do more succinctly than this email. I'm curious what > poeple think about the library, its the first haskell code I've > written for the purpose of sharing and I intend to add it to hackage > once I finalize the interface a bit more. > > The code is at: http://bit.ly/1Cjjlj > > I'm very open to suggestions on improving the interface. RIght now > its very simple and straightforward but potentially limited. > > Right now it looks like you have taken the approach of embedded > domain specific language. You have not exposed the currency units > to the type system. Therefore you rely on the rules of your > embedded language to do proper conversions. > > Have you considered exposing the type information to the type > checker? A similar question came up recently on a Portland > functional programming mailing list and my reply can be found here: > http://groups.google.com/group/pdxfunc/tree/browse_frm/month/2009-08/5c565768ecf30c57?rnum=1&_done=%2Fgroup%2Fpdxfunc%2Fbrowse_frm%2Fmonth%2F2009-08%3F#doc_5c565768ecf30c57 > > The experimental code which resulted is here: > http://gist.github.com/165691 > > You may also want to look at the dimensional package: > http://code.google.com/p/dimensional/ > > Jason From sebastian.sylvan at gmail.com Sun Aug 16 10:24:02 2009 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Sun Aug 16 10:04:19 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: <4DD4AE93-8CBC-43B1-9995-A06D3D40582F@n-brain.net> References: <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> <3d96ac180908141921n37bfbcf8n2a0aab4144304004@mail.gmail.com> <3d96ac180908142034y36176485q69f49a466f539de1@mail.gmail.com> <6A1A0FDE-E416-4FB5-BC62-95CB05D23C09@n-brain.net> <3d96ac180908151559v348916cei28ca3f57f9125886@mail.gmail.com> <3d96ac180908151632l58ab531epbd08878c47f8ee09@mail.gmail.com> <4DD4AE93-8CBC-43B1-9995-A06D3D40582F@n-brain.net> Message-ID: <3d96ac180908160724g7f87d532u6c545c1a330abe09@mail.gmail.com> On Sun, Aug 16, 2009 at 2:50 PM, John A. De Goes wrote: > On Aug 15, 2009, at 5:32 PM, Sebastian Sylvan wrote: > > On Sun, Aug 16, 2009 at 12:18 AM, John A. De Goes > wrote: > >> You must think I'm arguing for some kind of low-level analog of C, >> augmented with an effect system. I'm not. You can't do that. >> > > No, I don't. I think you're arguing for making access to mutable state > commutative. Are you not? > > > There are many cases when mutation to state _is_ commutative. I can't argue > that certain operations are _always_ commutative without talking about the > language. > > Pretend I'm arguing for a mostly functional language and effect system that > maximize the opportunities for parallelizing code. > > I'm not saying you shouldn't parallelise them in very specific > circumstances *where it's safe*, I'm just saying that you shouldn't assume > that it's safe unless you know it is. If you want to do a transformation > that's unsafe in general, but safe in a specific circumstance, then of > course, go ahead! > To my reading it seems like you're arguing that memory/file access should > *always* be considered commutative though, which is what I'm objecting too. > > > In the right language, many times of memory (and possibly file) operations > _always_ commute. In the wrong language, they _sometimes_ commute or _never_ > provably commute. I'm not arguing for the assumption in any language where > it is false. > Well now I'm confused. Earlier you said: "In the case of a file system, you can commute two sequential reads from two different files. This has no effect on the result of the computation, assuming no interference from other programs -- and if there _is_ interference from other programs, then guarantees go out the window, _with or without_ commuting." It's the "assuming no interference form other programs" that bugs me, because when you're reading outside data you kind of have to assume that there *is* outside interference because you can't really protect yourself against it. Furthermore, that "interference" is often more like cooperation/communication so you're actually *counting* on "outside interference". E.g. consider durable storage that have to survive random reboots etc., I'm sure there are quite a few very carefully considered sequential steps that need to happen in just the right order to get a consistent view of the data when you read it back in. That earlier quote seems to imply that you're arguing for just treating all file reads as commutative and just ignoring that this is an unsafe assumption. If you no longer think this then I guess we're in agreement. My point is that *if* there is any chance for outside access to anything you're reading, then ordering *does* matter. This is the case for file reads, and may be the case for memory reads. For the latter the compiler could *potentially* figure out when memory can't be touched by other threads and make them commute, but I still think the semantics for mutable code should be sequential (since it unifies the two scenarios), and then the compiler might make them commutative in scenarios where it's guaranteed to be safe. For file reads, I don't think there's a way of knowing that two file reads are independent, especially since this dependency might live *outside* the program (e.g. the dependency might only exist for the human reading the output of the program). So really, if there's any chance something else might touch your data, the only reasonably safe way to deal with it is to enforce sequentiality. -- Sebastian Sylvan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090816/fc9275bb/attachment.html From artem at AA5779.spb.edu Sun Aug 16 10:47:48 2009 From: artem at AA5779.spb.edu (Artem V. Andreev) Date: Sun Aug 16 10:28:04 2009 Subject: [Haskell-cafe] Re: DDC compiler and effects; better than Haskell? In-Reply-To: <2DED3DCA-2678-455A-ACEF-23AD22A0A209@n-brain.net> (John A. De Goes's message of "Sun\, 16 Aug 2009 07\:33\:50 -0600") References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> <42784f260908150536t5201b6c5i40541b2fda084fc@mail.gmail.com> <87ocqgxnzo.fsf@artemsmp.iling.nw.ru> <2DED3DCA-2678-455A-ACEF-23AD22A0A209@n-brain.net> Message-ID: <87hbw7yfvv.fsf@artemsmp.iling.nw.ru> "John A. De Goes" writes: > I forgot about links. In that case, consider: getUniqueFilesInDirRecursive. > > Attacking irrelevant details in an argument is often called a "strawman attack". Such attacks are > pointless because they do not address the real substance of the issue. My example is easily > modified to avoid the issues you raise. > > Consider the fact that many file-based operations _can and are parallelized manually by > developers_. The challenge for next generation language and effect system designers is to figure > out _how_ such operations can be automatically parallelized, given sufficient constraints, > high-level constructs, and a powerful effect system. > > Saying, "I don't know exactly how it will look," is quite a bit different from saying "It can't > be done." I claim the former. > > Regards, I am sorry, but it's not about details, but about the essence. My point was that there are a lot of subtle issues when we're dealing with (e.g.) a file system in a real-world manner. I have no doubt that it is possible to develop a sound logical system that would cover them and then encode it as a part of the type system of a language. That will probably lead to compile-time detection of a wider class of errors. But the problem is that one (IMHO) cannot deal with these subtleties in a generic manner. That is, there are things that may be done in parallel, and there are things that may not -- and it depends on the actual task you want to perform. So basically instead of manually parallelizing something, you'll (IMHO) end up writing complex type annotations so that a compiler could parallelize it on its own behalf. As somebody who have a certain experience with formal methods, I doubt that the latter will ever be simplier than the former. > John A. De Goes > N-Brain, Inc. > The Evolution of Collaboration > > http://www.n-brain.net | 877-376-2724 x 101 > > On Aug 16, 2009, at 12:38 AM, Artem V. Andreev wrote: > >> "John A. De Goes" writes: >> >>> On Aug 15, 2009, at 6:36 AM, Jason Dusek wrote: >>>> 2009/08/14 John A. De Goes : >>>>> Hmmm, my point (perhaps I wasn't clear), is that different >>>>> effects have different commutability properties. In the case >>>>> of a file system, you can commute two sequential reads from >>>>> two different files. >>>> >>>> I think this is a bad example -- it's not something that's >>>> safe in general and discredits your idea. How would the >>>> compiler even know that two files are not actually the same >>>> file? >>> >>> I don't think the file system is the best example. However, I do think it's a reasonable one. >>> >>> Let's say the type of the function getFilesInDir is annotated in such a way as to tell the >>> effect >>> system that every file in the returned array is unique. Further, let's say the type of the >>> function makeNewTempFile is annotated in such a way as to tell the effect system that the >>> function will succeed in creating a new temp file with a name unique from any other existing >>> file. >> Sorry, but this example is ridiculuous. While file *names* in this case might be reasonably >> assumed >> to be unique, the *files* themselves may not. Any modern filesystem does support file aliasing, >> and usually several forms thereof. And what does makeNewTempFile function do? Does it create a >> new >> file like POSIX mktemp() and return its name, or does it rather behave as POSIX mkstemp()? >> The first case is a well known security hole, and the second case does not, as it seems to me, >> fit >> well into the rest of your reasoning. >> >> However, let's consider further file system tree traversal. In some cases you might not care, >> whether >> some of the directories you descend into are actually the same directory, so your proposed >> optimization >> would be `safe'. However, in other cases sequential traversal would work, while a parallelized >> version >> would not, unless special additional measures are taken. E.g. consider a case of a build >> system. It >> traverses a source tree, finds sources files and if corresponding object files are non-existent >> or >> outdated, does something to regenerate them. Now if you have a directory that's actually a link >> to >> another directory, and you do sequential traversal, everything is fine: you descend into the >> directory >> the first time, build everything there and when you descend into it the second time, there's >> just nothing >> to do. If you do parallel traversal, you may well end up in the situation where two threads >> check >> simultaneously for an object file, discover it's outdated and run two build processes >> simultaneously, >> with the most likely effect of corrupted object file. >> >> >>> Then if you write a recursive function that loops through all files in a directory, and for >>> each >>> file, it parses and compiles the file into a new temp file, then a sufficiently sophisticated >>> compiler should be able to safely transform the recursion into parallel parsing and >>> compilation >>> -- in a way that's provably correct, assuming the original program was correct. >>> >>> The promise of a language with a purely functional part and a powerful effect system for >>> everything else is very great. And very important in the massively concurrent world we are >>> entering. >>> >>>> Well, yes -- which sounds like, there are no guarantees >>>> in general. Something that works half the time leaves you with >>>> two responsibilities -- the old responsibility of the work you >>>> did when you didn't have it and the new responsibility of >>>> knowing when it applies and when it doesn't. >>> >>> In the other thread, I brought up the example of buffering reads. Library authors make the >>> decision to buffer for one reason: because if some other program is messing with the data, >>> you're >>> screwed no matter what. >>> >>> And yeah, "they might be screwing with the data in just the way you need it to be screwed >>> with," >>> (Sebastian), in which case my advice is use C and hope for the best. :-) >>> >>> Regards, >>> >>> John A. De Goes >>> N-Brain, Inc. >>> The Evolution of Collaboration >>> >>> http://www.n-brain.net | 877-376-2724 x 101 >>> >>> >>> _______________________________________________ >>> Haskell-Cafe mailing list >>> Haskell-Cafe@haskell.org >>> http://www.haskell.org/mailman/listinfo/haskell-cafe >>> >> >> -- >> >> S. Y. A(R). A. >> _______________________________________________ >> 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 > -- S. Y. A(R). A. From sacha at myxomop.com Sun Aug 16 10:54:32 2009 From: sacha at myxomop.com (Alexander Kotelnikov) Date: Sun Aug 16 10:40:19 2009 Subject: [Haskell-cafe] simple hsql question Message-ID: <874os724if.fsf@benington.loc> Hi I wanted to see what access to databases HSQL provides and I stumbled in the very beginning. Assume I have a table map1 with attributes "i" and "s" interger and varchar() respectively. The following code fails (with segfault) for me. And I see no other way to tell compiler that I am expecting an interger to be found as 'i' in a fetched row. import Database.HSQL import Database.HSQL.MySQL main :: IO () main = do c <- connect "localhost" "tx_test" "sacha" "" s <- query c "SELECT i FROM map1" print $ getFieldsTypes s i <- (getFieldValue s "i")::IO Int print i disconnect c -- Alexander Kotelnikov Saint-Petersburg, Russia From allbery at ece.cmu.edu Sun Aug 16 11:00:20 2009 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Sun Aug 16 10:41:08 2009 Subject: [Haskell-cafe] Calling function with unknown number and type arguments In-Reply-To: <1250419542.8044.67.camel@notebook> References: <1250419542.8044.67.camel@notebook> Message-ID: <7B18664B-E2B6-4241-8FFE-89224DC3148F@ece.cmu.edu> On Aug 16, 2009, at 06:45 , Maciej Piechotka wrote: > I have to write a function which calls a function with unknown (i.e. > given in runtime) number and type of arguments. Take a look at the implementation of Text.Printf. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 195 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090816/a4defa5b/PGP.bin From mauricio.antunes at gmail.com Sun Aug 16 12:16:02 2009 From: mauricio.antunes at gmail.com (=?ISO-8859-1?Q?Maur=ED=ADcio_CA?=) Date: Sun Aug 16 11:58:29 2009 Subject: [Haskell-cafe] Re: Blank definition list in haddock In-Reply-To: References: Message-ID: >> I read in haddock documentation that we write >> definition lists like this: >> [...] >> Did I used those definitons the wrong way? > I think the problem is that you have written normal comments instead > of Haddock comments. Try adding a | in front of the paragraphs, or > just merge them all into one Haddock comment by inserting "--" in > front of the blank lines in between your paragraphs. OK. Sent the patch below to haddock maintainer. Thanks, Maur?cio %%% Paragraphs - One or more blank lines separates two paragraphs in a - documentation comment. + One or more blank lines separate two paragraphs in a + documentation comment. Such blank lines, though, should + still be commented, or they would interrupt Haddock + documentation. %%% From leather at cs.uu.nl Sun Aug 16 16:07:06 2009 From: leather at cs.uu.nl (Sean Leather) Date: Sun Aug 16 15:47:40 2009 Subject: [Haskell-cafe] Calling function with unknown number and type arguments In-Reply-To: <7B18664B-E2B6-4241-8FFE-89224DC3148F@ece.cmu.edu> References: <1250419542.8044.67.camel@notebook> <7B18664B-E2B6-4241-8FFE-89224DC3148F@ece.cmu.edu> Message-ID: <3c6288ab0908161307u6f8ebf09wf3c42d094930167b@mail.gmail.com> On Sun, Aug 16, 2009 at 17:00, Brandon S. Allbery wrote: > On Aug 16, 2009, at 06:45 , Maciej Piechotka wrote: > >> I have to write a function which calls a function with unknown (i.e. >> given in runtime) number and type of arguments. >> > > Take a look at the implementation of Text.Printf. > Or Text.XFormat.Show in xformat while you're at it. (Warning: blatant self-promoting.) http://hackage.haskell.org/package/xformat >From the tests in the package: showf (Show % Int % String) 4.05 20 " blah" == "4.0520 blah" showf (Wrap '(' Int ')') 24 == "(24)" Sean -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090816/d5e62c39/attachment.html From RafaelGCPP.Linux at gmail.com Sun Aug 16 16:10:23 2009 From: RafaelGCPP.Linux at gmail.com (Rafael Gustavo da Cunha Pereira Pinto) Date: Sun Aug 16 15:50:35 2009 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: GLUT 2.2.1.0 In-Reply-To: <200908161812.02982.Sven.Panne@aedion.de> References: <200908161812.02982.Sven.Panne@aedion.de> Message-ID: <351ff25e0908161310w3d2330c9v94424cc39d335eda@mail.gmail.com> Thanks Sven! BTW, as an enhancement for 2.2.2.0, you could treat unnamed mouse buttons. Mouses with more axis and more buttons are becoming increasingly common, and "unmarshalMouseButton" is not prepared to accept them!! Here are exceptions I caught, playing with my Genius Traveler 515 mouse: unmarshalMouseButton: illegal value 5 unmarshalMouseButton: illegal value 6 unmarshalMouseButton: illegal value 7 unmarshalMouseButton: illegal value 8 Anyway, keep the good work! Best Regards, Rafael On Sun, Aug 16, 2009 at 13:12, Sven Panne wrote: > A new version of the GLUT package has been uploaded to Hackage. > > * The package is now autoconf-free. API entries are resolved dynamically > at > runtime, just like the OpenGLRaw and GLURaw packages. > > * Support for sRGB framebuffers has been added, just use SRGBMode with > initialDisplayMode. To use this functionality, you need the upcoming > freeglut > 2.6.0 library, older versions and "classic" GLUT do not support this > feature. > > * Support for context profiles has been added via initialContextProfile. > Again, this works with the upcoming freeglut 2.6.0 library only. > > Cheers, > S. > _______________________________________________ > Haskell mailing list > Haskell@haskell.org > http://www.haskell.org/mailman/listinfo/haskell > -- Rafael Gustavo da Cunha Pereira Pinto -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090816/6468c810/attachment.html From jesusalbertosanchez at gmail.com Sun Aug 16 16:28:51 2009 From: jesusalbertosanchez at gmail.com (=?ISO-8859-1?Q?Jes=FAs_Alberto_S=E1nchez_Pimienta?=) Date: Sun Aug 16 16:09:22 2009 Subject: [Haskell-cafe] Request for comments - hdnsomatic Message-ID: <30b6b2420908161328w1b4f1b8fo78a0c4be8cc11496@mail.gmail.com> Hello haskellers, I just finished my first useful haskell program and I'd be glad if you make me some comments http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8244#a8244 Thank you, and sorry for my english. "Piensa y trabaja" Jes?s Alberto S?nchez Pimienta Estudiante de la Lic. en Estudios Pol?ticos y Gobierno Universidad de Guadalajara -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090816/bdffea96/attachment.html From ndmitchell at gmail.com Sun Aug 16 17:43:12 2009 From: ndmitchell at gmail.com (Neil Mitchell) Date: Sun Aug 16 17:23:30 2009 Subject: [Haskell-cafe] Request for comments - hdnsomatic In-Reply-To: <30b6b2420908161328w1b4f1b8fo78a0c4be8cc11496@mail.gmail.com> References: <30b6b2420908161328w1b4f1b8fo78a0c4be8cc11496@mail.gmail.com> Message-ID: <404396ef0908161443w7b52fac3wda6bd51ddec3cfab@mail.gmail.com> Hi An easy way to get some instant feedback is to run HLint on it: http://community.haskell.org/~ndm/hlint The results are: C:\Neil\hlint>hlint Example.hs Example.hs:42:1: Warning: Use liftM Found: readFile p >>= return . lines >>= return . map (second tail . break (== '=') . filter (/= ' ')) Why not: liftM (map (second tail . break (== '=') . filter (/= ' '))) (readFile p >>= return . lines) Example.hs:42:1: Warning: Use liftM Found: readFile p >>= return . lines Why not: liftM lines (readFile p) Found 2 suggestions So using liftM instead of >>= return might be better style. You can also make minor tweaks like: if null args then readConfig defaultConfig else readConfig (head args) ==> readConfig $ if null args then defaultConfig else head args currentIP <- catch (getIPAddress webIP) (\e -> syslog Error (show e) >> return "0") oldIP <- catch (S.readFile ipCache) (\e -> syslog Error (show e) >> return "0") ==> let catch_ x = catch x (\e -> syslog Error (show e) >> return "0") currentIP <- catch_ $ getIPAddress webIP oldIP <- catch_ (S.readFile ipCache) And there's no need to exitSuccess at the end of main, exitSuccess is the default. Thanks Neil 2009/8/16 Jes?s Alberto S?nchez Pimienta : > Hello haskellers, > > I just finished my first useful haskell program and? I'd be glad if you make > me some comments > > http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8244#a8244 > > Thank you, and sorry for my english. > > > "Piensa y trabaja" > > Jes?s Alberto S?nchez Pimienta > Estudiante de la Lic. en Estudios Pol?ticos y Gobierno > Universidad de Guadalajara > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > From jesusalbertosanchez at gmail.com Sun Aug 16 19:26:49 2009 From: jesusalbertosanchez at gmail.com (=?ISO-8859-1?Q?Jes=FAs_Alberto_S=E1nchez_Pimienta?=) Date: Sun Aug 16 19:07:20 2009 Subject: [Haskell-cafe] Request for comments - hdnsomatic In-Reply-To: <404396ef0908161443w7b52fac3wda6bd51ddec3cfab@mail.gmail.com> References: <30b6b2420908161328w1b4f1b8fo78a0c4be8cc11496@mail.gmail.com> <404396ef0908161443w7b52fac3wda6bd51ddec3cfab@mail.gmail.com> Message-ID: <30b6b2420908161626g12ce04e5y6eb5d21d27c85827@mail.gmail.com> Many Thanks Neil, I tried to build hlint before submitting to the mail list but i couldn't because my haskell-src-exts is version 1.1.1 and the cabal file of hlint requires a version < 1.1. Now i modified the cabal depends and successfully installed hlint, it's a great tool. "Piensa y trabaja" Jes?s Alberto S?nchez Pimienta Estudiante de la Lic. en Estudios Pol?ticos y Gobierno Universidad de Guadalajara 2009/8/16 Neil Mitchell > Hi > > An easy way to get some instant feedback is to run HLint on it: > http://community.haskell.org/~ndm/hlint > > The results are: > > C:\Neil\hlint>hlint Example.hs > Example.hs:42:1: Warning: Use liftM > Found: > readFile p >>= return . lines >>= > return . map (second tail . break (== '=') . filter (/= ' ')) > Why not: > liftM (map (second tail . break (== '=') . filter (/= ' '))) > (readFile p >>= return . lines) > > Example.hs:42:1: Warning: Use liftM > Found: > readFile p >>= return . lines > Why not: > liftM lines (readFile p) > > Found 2 suggestions > > So using liftM instead of >>= return might be better style. > > You can also make minor tweaks like: > > if null args then readConfig defaultConfig else readConfig (head args) > ==> > readConfig $ if null args then defaultConfig else head args > > currentIP <- catch (getIPAddress webIP) (\e -> syslog Error (show e) > >> return "0") > oldIP <- catch (S.readFile ipCache) (\e -> syslog Error (show e) >> > return "0") > ==> > let catch_ x = catch x (\e -> syslog Error (show e) >> return "0") > currentIP <- catch_ $ getIPAddress webIP > oldIP <- catch_ (S.readFile ipCache) > > And there's no need to exitSuccess at the end of main, exitSuccess is > the default. > > Thanks > > Neil > > > > > > 2009/8/16 Jes?s Alberto S?nchez Pimienta : > > Hello haskellers, > > > > I just finished my first useful haskell program and I'd be glad if you > make > > me some comments > > > > http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8244#a8244 > > > > Thank you, and sorry for my english. > > > > > > "Piensa y trabaja" > > > > Jes?s Alberto S?nchez Pimienta > > Estudiante de la Lic. en Estudios Pol?ticos y Gobierno > > Universidad de Guadalajara > > > > > > _______________________________________________ > > Haskell-Cafe mailing list > > Haskell-Cafe@haskell.org > > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090816/9ab59ed9/attachment.html From ok at cs.otago.ac.nz Sun Aug 16 19:32:13 2009 From: ok at cs.otago.ac.nz (Richard O'Keefe) Date: Sun Aug 16 19:12:28 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> <3d96ac180908141921n37bfbcf8n2a0aab4144304004@mail.gmail.com> Message-ID: On Aug 15, 2009, at 2:55 PM, John A. De Goes wrote: >> If you don't like the file system, consider mutable memory. An >> effect system will tell me I can safely update two pieces of non- >> overlapping, contiguous memory concurrently, even in different >> threads if the complexity so justifies it. The IO monad is a poor >> man's solution to the problem of effects. In the presence of out-of-order memory writes, write buffers, caches, &c, I'm not going to contradict you, but it certainly isn't as _obvious_ as it used to be. I've come across an experimental microprocessor where I _think_ it isn't safe if you have --------+--------- data 1 | data 2 ----+--------+---- cache line whether that's so on any other processor is beyond my expertise. From aslatter at gmail.com Sun Aug 16 20:35:19 2009 From: aslatter at gmail.com (Antoine Latter) Date: Sun Aug 16 20:15:31 2009 Subject: [Haskell-cafe] Calling function with unknown number and type arguments In-Reply-To: <3c6288ab0908161307u6f8ebf09wf3c42d094930167b@mail.gmail.com> References: <1250419542.8044.67.camel@notebook> <7B18664B-E2B6-4241-8FFE-89224DC3148F@ece.cmu.edu> <3c6288ab0908161307u6f8ebf09wf3c42d094930167b@mail.gmail.com> Message-ID: <694519c50908161735l2319f58aq1d68d77d5ad142b2@mail.gmail.com> On Sun, Aug 16, 2009 at 3:07 PM, Sean Leather wrote: > > On Sun, Aug 16, 2009 at 17:00, Brandon S. Allbery wrote: >> >> On Aug 16, 2009, at 06:45 , Maciej Piechotka wrote: >>> >>> I have to write a function which calls a function with unknown (i.e. >>> given in runtime) number and type of arguments. >> >> Take a look at the implementation of Text.Printf. > > > Or Text.XFormat.Show in xformat while you're at it. (Warning: blatant > self-promoting.) > > ? http://hackage.haskell.org/package/xformat > > From the tests in the package: > > ? showf (Show % Int % String) 4.05 20 " blah" == "4.0520 blah" > ? showf (Wrap '(' Int ')') 24 == "(24)" > But with those, the number of arguments is still known at compile time, correct? Antoine From john at n-brain.net Sun Aug 16 20:48:46 2009 From: john at n-brain.net (John A. De Goes) Date: Sun Aug 16 20:29:01 2009 Subject: DDC compiler and effects; better than Haskell? (was Re: [Haskell-cafe] unsafeDestructiveAssign?) In-Reply-To: References: <61f84eff0908120634v620b0b57hcc7b36251553b2a3@mail.gmail.com> <200908121728.41807.dan.doel@gmail.com> <4A838B82.9020606@anu.edu.au> <2D8EC0D8-343D-41D2-BCFF-72F574460D45@n-brain.net> <3d96ac180908130142v50bd65fcp24942279e18b24f1@mail.gmail.com> <118D926F-1CD6-446F-ABB4-204210F4AC2D@n-brain.net> <3d96ac180908131124p5fa946k22a88ab4dc099754@mail.gmail.com> <7DD28636-A8D6-4E1C-8EF3-30936B85540D@n-brain.net> <3d96ac180908141921n37bfbcf8n2a0aab4144304004@mail.gmail.com> Message-ID: <2D163C32-D9CA-4E5E-8B7C-5232DEE33FE3@n-brain.net> In the presence of _uncontrolled concurrency_, you are correct, but uncontrolled concurrency is a failed paradigm littered with defective software. Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 On Aug 16, 2009, at 5:32 PM, Richard O'Keefe wrote: > On Aug 15, 2009, at 2:55 PM, John A. De Goes wrote: >>> If you don't like the file system, consider mutable memory. An >>> effect system will tell me I can safely update two pieces of non- >>> overlapping, contiguous memory concurrently, even in different >>> threads if the complexity so justifies it. The IO monad is a poor >>> man's solution to the problem of effects. > > In the presence of out-of-order memory writes, write buffers, > caches, &c, I'm not going to contradict you, but it certainly > isn't as _obvious_ as it used to be. > > I've come across an experimental microprocessor where I _think_ > it isn't safe if you have > > --------+--------- > data 1 | data 2 > ----+--------+---- > cache > line > > whether that's so on any other processor is beyond my expertise. > From mutjida at gmail.com Sun Aug 16 21:08:37 2009 From: mutjida at gmail.com (jeff p) Date: Sun Aug 16 20:48:48 2009 Subject: [Haskell-cafe] Request for Comments - hscurrency 0.0.1 In-Reply-To: <7A6B927F-9DA4-439A-A661-8EFBB9809065@gmail.com> References: <7A6B927F-9DA4-439A-A661-8EFBB9809065@gmail.com> Message-ID: Hello, To let the type checker do some work for you, without getting all the way into the territory of the dimensional package, you can use newtypes and a Units class with methods for wrapping and unwrapping Doubles; we use this approach at work and find it strikes a nice balance between useful (static typechecking) and usable (unobtrusive to introduce to existing codebase). Just as in your code, conversions are written explicitly by us and can change when needed (with a recompile), or can require an IO action to make use of changing data. -Jeff On Sun, Aug 16, 2009 at 9:55 AM, Max Cantor wrote: > @Jason I'm not sure what you mean about exposing the type information. > ?Unless you mean that each currency would be a separate type somehow. While > this is a similar problem to the dimensional issue, the problem is that the > FX rates are changing all the time. ?While the conversion between a meter > and a foot is always constant, with FX rates thats not the case. ?So 2ft + > 3m is always a well defined value but something like USD 1 + JPY 1 gives a > function of the USDJPY exchange rate, not a constant value. > > @ Antoine I'll add some comments. ?you're right that doubles are not > typically used nor would they be in a finished product. ?for the time being, > however, I dont know if its better to use Ratio's, Fixed's or what, so just > settled on the most straightforward for now. > > > On Aug 16, 2009, at 1:26 AM, Jason Dagit wrote: > >> >> >> On Sat, Aug 15, 2009 at 5:15 AM, Max Cantor wrote: >> Hi all, >> >> I'm putting together some simple tools to do safe calculations on >> different currencies. ?For instance, making sure that you dont add something >> like 5 USD + 10 JPY without doing a proper conversion. >> >> I've put up some code on google code which probably explains what I'm >> trying to do more succinctly than this email. ?I'm curious what poeple think >> about the library, its the first haskell code I've written for the purpose >> of sharing and I intend to add it to hackage once I finalize the interface a >> bit more. >> >> The code is at: http://bit.ly/1Cjjlj >> >> I'm very open to suggestions on improving the interface. ?RIght now its >> very simple and straightforward but potentially limited. >> >> Right now it looks like you have taken the approach of embedded domain >> specific language. ?You have not exposed the currency units to the type >> system. ?Therefore you rely on the rules of your embedded language to do >> proper conversions. >> >> Have you considered exposing the type information to the type checker? ?A >> similar question came up recently on a Portland functional programming >> mailing list and my reply can be found here: >> >> http://groups.google.com/group/pdxfunc/tree/browse_frm/month/2009-08/5c565768ecf30c57?rnum=1&_done=%2Fgroup%2Fpdxfunc%2Fbrowse_frm%2Fmonth%2F2009-08%3F#doc_5c565768ecf30c57 >> >> The experimental code which resulted is here: >> http://gist.github.com/165691 >> >> You may also want to look at the dimensional package: >> http://code.google.com/p/dimensional/ >> >> Jason > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From caseyh at istar.ca Sun Aug 16 21:29:56 2009 From: caseyh at istar.ca (Casey Hawthorne) Date: Sun Aug 16 21:10:15 2009 Subject: [Haskell-cafe] Uncontrolled Concurrency, isn't that concept now thread-bare? Message-ID: <7jch85l7tgm17etrkgab8uscdtrfrful51@4ax.com> -- Regards, Casey From dan.doel at gmail.com Sun Aug 16 21:50:01 2009 From: dan.doel at gmail.com (Dan Doel) Date: Sun Aug 16 21:30:17 2009 Subject: [Haskell-cafe] Calling function with unknown number and type arguments In-Reply-To: <694519c50908161735l2319f58aq1d68d77d5ad142b2@mail.gmail.com> References: <1250419542.8044.67.camel@notebook> <3c6288ab0908161307u6f8ebf09wf3c42d094930167b@mail.gmail.com> <694519c50908161735l2319f58aq1d68d77d5ad142b2@mail.gmail.com> Message-ID: <200908162150.02084.dan.doel@gmail.com> On Sunday 16 August 2009 8:35:19 pm Antoine Latter wrote: > But with those, the number of arguments is still known at compile time, > correct? {-# LANGUAGE Rank2Types #-} import Text.Printf import System.Environment nprintf :: PrintfType t => Int -> Int -> t nprintf n e = aux (printf str) n where str = concat $ replicate n "%d" aux :: PrintfType t' => (forall t. PrintfType t => t) -> Int -> t' aux pf 0 = pf aux pf n = aux (pf e) (n-1) main = do (n:e:_) <- map read `fmap` getArgs nprintf n e :: IO () ------------------------------------------------------------------------ % ./Var 2 5 55 % ./Var 6 5 555555 Voila. -- Dan From aslatter at gmail.com Sun Aug 16 22:39:52 2009 From: aslatter at gmail.com (Antoine Latter) Date: Sun Aug 16 22:20:03 2009 Subject: [Haskell-cafe] Calling function with unknown number and type arguments In-Reply-To: <200908162150.02084.dan.doel@gmail.com> References: <1250419542.8044.67.camel@notebook> <3c6288ab0908161307u6f8ebf09wf3c42d094930167b@mail.gmail.com> <694519c50908161735l2319f58aq1d68d77d5ad142b2@mail.gmail.com> <200908162150.02084.dan.doel@gmail.com> Message-ID: <694519c50908161939l35c03162h65bc4bbf48957b3d@mail.gmail.com> On Sun, Aug 16, 2009 at 8:50 PM, Dan Doel wrote: > On Sunday 16 August 2009 8:35:19 pm Antoine Latter wrote: >> But with those, the number of arguments is still known at compile time, >> correct? > > > % ./Var 2 5 > 55 > % ./Var 6 5 > 555555 > > Voila. Ah! Very nice. Antoine From miguelimo38 at yandex.ru Mon Aug 17 01:06:24 2009 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Mon Aug 17 00:46:38 2009 Subject: [Haskell-cafe] ANNOUNCE: compose-trans-0.0 Message-ID: <081E2E74-EC6C-458A-A232-47BCF1935CC5@yandex.ru> Just uploaded compose-trans-0.0 to Hackage. 'compose-trans' is a small library intended to make monad transformers composable. It provides a class TransM, derived from MonadTrans, which is closed under composition - that is, if t1 and t2 are instances of TransM, then (t2 :. t1) is also an instance of TransM (and, therefore, an instance of MonadTrans), and the type ((t2 :. t1) m x) is isomorphic to (t2 (t1 m) x). It's fairly easy to make a new transformer an instance of TransM; it only takes one short line of code. There are also TransP and TransF classes, that help dealing with MonadPlus and MonadFix instances. From explicitcall at googlemail.com Mon Aug 17 02:05:14 2009 From: explicitcall at googlemail.com (Max Desyatov) Date: Mon Aug 17 01:45:25 2009 Subject: [Haskell-cafe] Re: [Haskell-beginners] Ambigous Types with Haskell Functional Graph Library In-Reply-To: (Joe's message of "Mon, 17 Aug 2009 01:23:03 -0400") References: <87iqgnkznd.fsf@gmail.com> <871vnbt73k.fsf@zagan.made.you> Message-ID: <87ws53rn51.fsf@zagan.made.you> Joe writes: > I tried using ucycle directly from Data.Graph.Inductive.Example by > itself. > > I didn't realize there were two instances of Graph. How would you use the > PatriciaTree Graph instance in the ucycle type signature? > > ucycle :: Graph gr => Int -> gr () () You must have that Graph instance in scope. I can't give any more suggestions as I don't see the code in which you use `ucycle`. From Sven.Panne at aedion.de Mon Aug 17 02:17:28 2009 From: Sven.Panne at aedion.de (Sven Panne) Date: Mon Aug 17 01:57:46 2009 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: GLUT 2.2.1.0 In-Reply-To: <351ff25e0908161310w3d2330c9v94424cc39d335eda@mail.gmail.com> References: <200908161812.02982.Sven.Panne@aedion.de> <351ff25e0908161310w3d2330c9v94424cc39d335eda@mail.gmail.com> Message-ID: <200908170817.29227.Sven.Panne@aedion.de> Am Sonntag, 16. August 2009 22:10:23 schrieb Rafael Gustavo da Cunha Pereira Pinto: > BTW, as an enhancement for 2.2.2.0, you could treat unnamed mouse buttons. > Mouses with more axis and more buttons are becoming increasingly common, > and "unmarshalMouseButton" is not prepared to accept them!! > > Here are exceptions I caught, playing with my Genius Traveler 515 mouse: > > unmarshalMouseButton: illegal value 5 > unmarshalMouseButton: illegal value 6 > unmarshalMouseButton: illegal value 7 > unmarshalMouseButton: illegal value 8 Good point, I had similar reports already, but I simply forgot to handle this in yesterday's release. The right way to handle this would probably be extending the MouseButton data type with an 'AdditionalButton Int' constructor and simply pass the unknown button numbers via this case. I am not so sure about a nice name for this constructor: AdditionalButton? GenericButton? Or simply MouseButton, just like the type itself? Cheers, S. From sargrigory at ya.ru Mon Aug 17 02:35:33 2009 From: sargrigory at ya.ru (Grigory Sarnitskiy) Date: Mon Aug 17 02:15:46 2009 Subject: [Haskell-cafe] Got problems with classes Message-ID: <161821250490933@webmail51.yandex.ru> Hello! I can't understand why the following dummy example doesn't work. {-# OPTIONS -XTypeSynonymInstances #-} {-# OPTIONS -XFlexibleInstances #-} module Main where import Data.Array.Unboxed class Particle p type ParticleC = (Double, Double, Double) instance Particle ParticleC class Configuration c where getParticleI :: (Particle p) => c -> Int -> p type Collection p = UArray (Int,Int) Double instance Configuration (Collection p) where getParticleI config i = (1,1,1) :: ParticleC From bulat.ziganshin at gmail.com Mon Aug 17 02:52:58 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Mon Aug 17 02:34:50 2009 Subject: [Haskell-cafe] Got problems with classes In-Reply-To: <161821250490933@webmail51.yandex.ru> References: <161821250490933@webmail51.yandex.ru> Message-ID: <568962609.20090817105258@gmail.com> Hello Grigory, Monday, August 17, 2009, 10:35:33 AM, you wrote: > Hello! I can't understand why the following dummy example doesn't work. http://haskell.org/haskellwiki/OOP_vs_type_classes shortly speaking, throw away your OOP experience and learn new paradigm from scratch. also, http://rsdn.ru/forum/decl/2517181.1.aspx -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From thomas at cs.ru.nl Mon Aug 17 03:12:21 2009 From: thomas at cs.ru.nl (Thomas van Noort) Date: Mon Aug 17 02:52:13 2009 Subject: [Haskell-cafe] Type family signatures In-Reply-To: <2f9b2d30908141349v581d05f9lfb6fa98aa4fe2a4@mail.gmail.com> References: <4A857D7F.7040000@cs.ru.nl> <49a77b7a0908140832h7033b368nabc73f513de070d3@mail.gmail.com> <4A85B514.4050306@imageworks.com> <2f9b2d30908141349v581d05f9lfb6fa98aa4fe2a4@mail.gmail.com> Message-ID: <4A8902D5.50106@cs.ru.nl> Somehow I didn't receive David's mail, but his explanation makes a lot of sense. I'm still wondering how this results in a type error involving rigid type variables. Ryan Ingram wrote: > On Fri, Aug 14, 2009 at 12:03 PM, Dan Weston wrote: >> But presumably he can use a data family instead of a type family to restore >> injectivity, at the cost of adding an extra wrapped bottom value and one >> more layer of value constructor? > > Actually, you don't even necessarily pay this penalty, since you can > put newtypes into data families. > >> data family Foo a >> newtype instance Foo () = UnitFoo Int > > You do need to add the constructor wrap/unwrapping in code, but they > all get erased after typechecking. > > -- ryan > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From ndmitchell at gmail.com Mon Aug 17 05:57:11 2009 From: ndmitchell at gmail.com (Neil Mitchell) Date: Mon Aug 17 05:37:22 2009 Subject: [Haskell-cafe] Request for comments - hdnsomatic In-Reply-To: <30b6b2420908161626g12ce04e5y6eb5d21d27c85827@mail.gmail.com> References: <30b6b2420908161328w1b4f1b8fo78a0c4be8cc11496@mail.gmail.com> <404396ef0908161443w7b52fac3wda6bd51ddec3cfab@mail.gmail.com> <30b6b2420908161626g12ce04e5y6eb5d21d27c85827@mail.gmail.com> Message-ID: <404396ef0908170257u2a938694s74aa5f67ddaab7d6@mail.gmail.com> Hi I should release a new version - the darcs version requires haskell-src-exts 1.1.*. I'll do that tonight. Thanks, Neil 2009/8/17 Jes?s Alberto S?nchez Pimienta : > Many Thanks Neil, > > I tried to build hlint before submitting to the mail list but i couldn't > because my haskell-src-exts is version 1.1.1 and the cabal file of hlint > requires a version < 1.1. Now i modified the cabal depends and successfully > installed hlint, it's a great tool. > > "Piensa y trabaja" > > Jes?s Alberto S?nchez Pimienta > Estudiante de la Lic. en Estudios Pol?ticos y Gobierno > Universidad de Guadalajara > > > > 2009/8/16 Neil Mitchell >> >> Hi >> >> An easy way to get some instant feedback is to run HLint on it: >> http://community.haskell.org/~ndm/hlint >> >> The results are: >> >> C:\Neil\hlint>hlint Example.hs >> Example.hs:42:1: Warning: Use liftM >> Found: >> ?readFile p >>= return . lines >>= >> ? ?return . map (second tail . break (== '=') . filter (/= ' ')) >> Why not: >> ?liftM (map (second tail . break (== '=') . filter (/= ' '))) >> ? ?(readFile p >>= return . lines) >> >> Example.hs:42:1: Warning: Use liftM >> Found: >> ?readFile p >>= return . lines >> Why not: >> ?liftM lines (readFile p) >> >> Found 2 suggestions >> >> So using liftM instead of >>= return might be better style. >> >> You can also make minor tweaks like: >> >> if null args then readConfig defaultConfig else readConfig (head args) >> ==> >> readConfig $ if null args then defaultConfig else head args >> >> ?currentIP <- catch (getIPAddress webIP) (\e -> syslog Error (show e) >> >> ?return "0") >> ?oldIP <- catch (S.readFile ipCache) (\e -> ?syslog Error (show e) >> >> return "0") >> ==> >> let catch_ x = catch x (\e -> syslog Error (show e) >> ?return "0") >> currentIP <- catch_ $ getIPAddress webIP >> oldIP <- catch_ (S.readFile ipCache) >> >> And there's no need to exitSuccess at the end of main, exitSuccess is >> the default. >> >> Thanks >> >> Neil >> >> >> >> >> >> 2009/8/16 Jes?s Alberto S?nchez Pimienta : >> > Hello haskellers, >> > >> > I just finished my first useful haskell program and? I'd be glad if you >> > make >> > me some comments >> > >> > http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8244#a8244 >> > >> > Thank you, and sorry for my english. >> > >> > >> > "Piensa y trabaja" >> > >> > Jes?s Alberto S?nchez Pimienta >> > Estudiante de la Lic. en Estudios Pol?ticos y Gobierno >> > Universidad de Guadalajara >> > >> > >> > _______________________________________________ >> > Haskell-Cafe mailing list >> > Haskell-Cafe@haskell.org >> > http://www.haskell.org/mailman/listinfo/haskell-cafe >> > >> > > > From dav.vire+haskell at gmail.com Mon Aug 17 06:02:28 2009 From: dav.vire+haskell at gmail.com (david48) Date: Mon Aug 17 05:42:38 2009 Subject: [Haskell-cafe] Getting highest sum of list elements with Map In-Reply-To: References: Message-ID: <4c88418c0908170302q30594688v49569c00ace5a698@mail.gmail.com> On Wed, Aug 5, 2009 at 10:51 AM, wrote: > (Full source attached; or alternately, grab it: darcs get > http://community.haskell.org/~gwern/hcorpus ) > > So I have this little program which hopefully will help me learn French by Probably off-topic, but also, I'm willing to help anyone learning French, for example by answering questions in French, or about French, or just writing about anything in French, or translating texts for you. Bon courage, David. From kkwweett at yahoo.fr Mon Aug 17 08:01:47 2009 From: kkwweett at yahoo.fr (jean legrand) Date: Mon Aug 17 07:41:58 2009 Subject: [Haskell-cafe] Elerea/GLFW Tetris In-Reply-To: <517638.63900.qm@web24508.mail.ird.yahoo.com> Message-ID: <19375.19875.qm@web24506.mail.ird.yahoo.com> As I've been warned, two dependencies (Common.Utils and Common.Vector) are to be resolved in order to use this Tetris code. They're part of the elerea-examples package (from hackage) but their access is not public so a solution is to modify the cabal file during installation. Another solution is to create a Common directory in the current directory, then decompress the source located in http://hackage.haskell.org/package/elerea-examples and copy the two files Vector.lhs and Utils.lhs in Common. > Hi Haskellers, > Here is my first real program in Haskell. > > http://hpaste.org:80/fastcgi/hpaste.fcgi/view?id=8211 > > In fact, I'm not fully responsible because it's just an > adapted version of a Tetris Creighton Hogg had written for > Reactive/GLUT. > As the first version, it's a very simple game (no levels, > no points ...) but it's playable ! > > The major problem is when the board is full, the program > sadly stops for an empty list : indeed, I wasn't interested > in that part and I prefered dealing with the signals. > > As the frame is the same as the breakout frame, it is also > possible to launch the game with > > ./Tetris --dump-dot | dot -Tsvg -o tetris.svg > > in order to get an svg showing a graph of the signals. Any > help is welcome to understand this graph ! > > Every comment is welcome (especially about the first 170 > lines). > Enjoy! From RafaelGCPP.Linux at gmail.com Mon Aug 17 08:24:58 2009 From: RafaelGCPP.Linux at gmail.com (Rafael Gustavo da Cunha Pereira Pinto) Date: Mon Aug 17 08:05:09 2009 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: GLUT 2.2.1.0 In-Reply-To: <200908170817.29227.Sven.Panne@aedion.de> References: <200908161812.02982.Sven.Panne@aedion.de> <351ff25e0908161310w3d2330c9v94424cc39d335eda@mail.gmail.com> <200908170817.29227.Sven.Panne@aedion.de> Message-ID: <351ff25e0908170524y2bc04e9fs4fa8707bbbbe329b@mail.gmail.com> On Mon, Aug 17, 2009 at 03:17, Sven Panne wrote: > Am Sonntag, 16. August 2009 22:10:23 schrieb Rafael Gustavo da Cunha > Pereira > Pinto: > > BTW, as an enhancement for 2.2.2.0, you could treat unnamed mouse > buttons. > > Mouses with more axis and more buttons are becoming increasingly common, > > and "unmarshalMouseButton" is not prepared to accept them!! > > > > Here are exceptions I caught, playing with my Genius Traveler 515 mouse: > > > > unmarshalMouseButton: illegal value 5 > > unmarshalMouseButton: illegal value 6 > > unmarshalMouseButton: illegal value 7 > > unmarshalMouseButton: illegal value 8 > > Good point, I had similar reports already, but I simply forgot to handle > this > in yesterday's release. The right way to handle this would probably be > extending the MouseButton data type with an 'AdditionalButton Int' > constructor > and simply pass the unknown button numbers via this case. I am not so sure > about a nice name for this constructor: AdditionalButton? GenericButton? Or > simply MouseButton, just like the type itself? > > Cheers, > S. > > AdditionalButton seems good. My second choice would be to use MouseButton. -- Rafael Gustavo da Cunha Pereira Pinto -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090817/c13b1fad/attachment.html From bugfact at gmail.com Mon Aug 17 08:50:53 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Mon Aug 17 08:31:04 2009 Subject: [Haskell-cafe] Elerea/GLFW Tetris In-Reply-To: <19375.19875.qm@web24506.mail.ird.yahoo.com> References: <517638.63900.qm@web24508.mail.ird.yahoo.com> <19375.19875.qm@web24506.mail.ird.yahoo.com> Message-ID: As a side-note, it might be interesting to use the Vec package on Hackage, since it seems to offer fast, unboxed linear algebra. On Mon, Aug 17, 2009 at 2:01 PM, jean legrand wrote: > As I've been warned, two dependencies (Common.Utils and Common.Vector) are > to be resolved in order to use this Tetris code. > They're part of the elerea-examples package (from hackage) but their access > is not public so a solution is to modify the cabal file during installation. > > Another solution is to create a Common directory in the current directory, > then decompress the source located in > > http://hackage.haskell.org/package/elerea-examples > > and copy the two files Vector.lhs and Utils.lhs in Common. > > > > Hi Haskellers, > > Here is my first real program in Haskell. > > > > http://hpaste.org:80/fastcgi/hpaste.fcgi/view?id=8211 > > > > In fact, I'm not fully responsible because it's just an > > adapted version of a Tetris Creighton Hogg had written for > > Reactive/GLUT. > > As the first version, it's a very simple game (no levels, > > no points ...) but it's playable ! > > > > The major problem is when the board is full, the program > > sadly stops for an empty list : indeed, I wasn't interested > > in that part and I prefered dealing with the signals. > > > > As the frame is the same as the breakout frame, it is also > > possible to launch the game with > > > > ./Tetris --dump-dot | dot -Tsvg -o tetris.svg > > > > in order to get an svg showing a graph of the signals. Any > > help is welcome to understand this graph ! > > > > Every comment is welcome (especially about the first 170 > > lines). > > Enjoy! > > > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090817/417b0118/attachment.html From kkwweett at yahoo.fr Mon Aug 17 10:00:57 2009 From: kkwweett at yahoo.fr (jean legrand) Date: Mon Aug 17 09:41:08 2009 Subject: [Haskell-cafe] Elerea/GLFW Tetris In-Reply-To: <19375.19875.qm@web24506.mail.ird.yahoo.com> Message-ID: <987444.87326.qm@web24507.mail.ird.yahoo.com> > As I've been warned, two dependencies > (Common.Utils and Common.Vector) are to be resolved in order > to use this Tetris code. > They're part of the elerea-examples package (from hackage) > but their access is not public so a solution is to modify > the cabal file during installation. > > Another solution is to create a Common directory in the > current directory, then decompress the source located in > > http://hackage.haskell.org/package/elerea-examples > > and copy the two files Vector.lhs and Utils.lhs in Common. > but the simplest soltution is to get rid of these dependancies as long as they are of very little importance actually : http://hpaste.org:80/fastcgi/hpaste.fcgi/view?id=8261 I added (line 291 to 309) the code needed to play Pentis but at this time the random generator bugs with 18 elements and only p12 is selected. Those who want to try can easily comment l.274 and decomment l.275 (then removing p17,p18 from the list because of the bug) and replace straight by p1 on l.80 Harder ! From martijn at van.steenbergen.nl Mon Aug 17 10:09:22 2009 From: martijn at van.steenbergen.nl (Martijn van Steenbergen) Date: Mon Aug 17 09:49:36 2009 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: GLUT 2.2.1.0 In-Reply-To: <200908170817.29227.Sven.Panne@aedion.de> References: <200908161812.02982.Sven.Panne@aedion.de> <351ff25e0908161310w3d2330c9v94424cc39d335eda@mail.gmail.com> <200908170817.29227.Sven.Panne@aedion.de> Message-ID: <4A896492.6010201@van.steenbergen.nl> Sven Panne wrote: > and simply pass the unknown button numbers via this case. I am not so sure > about a nice name for this constructor: AdditionalButton? GenericButton? Or > simply MouseButton, just like the type itself? How about OtherButton? Martijn. From zefirov at prosoft.ru Mon Aug 17 10:38:58 2009 From: zefirov at prosoft.ru (Zefirov Sergey) Date: Mon Aug 17 10:19:10 2009 Subject: [Haskell-cafe] Grouping and SIMD in parallel Haskell (using Nested Data Parallel Haskell ideas in legacy code) Message-ID: <431353321B0D214CBD767E22931DD477E52317522C@msk-mail-2.prosoft.ru> I haven't had enough time to polish a paper about the subject, so I decided to post my results here, in Haskell Caf?. When Simon Peyton-Jones was in Moscow about a month ago I made a bold statement that Parallel Haskell programs, expressed with the help of par and pseq, can be transformed into Nested Data Parallel Haskell. I wrote a simple model of what will be if we group arguments of par and pseq into queues based on parallel arrays from NDPH. We could then evaluate all thunks from that queues in parallel using SIMD (or just getting higher ILP). We also do not have to lock out main spark queue, we lock only queue we should put argument in. The latter turned out to be beneficial in itself, at least in my simple model. Let us look at famous parallel fib function: Fib n | N <= 1 = 1 | otherwise = a `par` b `pseq` a+b where a = fib (n-1) b = fib (n-2) When we evaluate fib we put a spark of a into spark queue and proceed to evaluate b and, then, a+b. When we put a into spark queue, we lock queue out, modify and release. There is a big probability that threads on different cores will compete for queue lock and some of them (most of them) will waste time waiting for lock release. If we group a's into different queue and put to main spark queue a spark to evaluate a complete group of a's at once, we will get less wasted time. This will work even for single CPU. Below is a run of (fib 15) on my model with cpuCount 1, 4 and 16 and a's or b's group length 0 (no grouping) and 16: cpuCount groupLength=0 groupLength=16 modelTicks modelTicks 1 34535 27189 4 12178 7472 16 7568 3157 speedup 2.19 times 3.11 times ticks1/ticks16 I think results speak for itself. I think the idea of `par` argument grouping could be viable. I should note that I made several digressions when I wrote model. One of digressions is that all evaluations are put into queue. In (a `par` b `pseq` a+b) a put into a_queue, b put into b_queue and (a+b) put into main queue. Each evaluated spark update it's "parent" - a spark that wait for it. Also, main loop of single CPU changed from simple (reading main spark queue + execute when get something) into a series of attepmts with fall back on failure: - first read main queue and execute spark if succeed, - else read current a_queue and execute all sparks there if succeed, - else read current b_queue and execute all sparks there if succeed, - else go to main loop. The new (transformed) code for our fib below: -- |Create a new queue based on parallel array. It holds a parallel array with current arguments and a function that performs -- computation in RTS monad (evaluation function). newQueueParArray :: (x -> RTS ()) -> RTSRef ([: x :],x -> RTS ()) a_queue = unsafePerformIO $ newQueueParArray (\x -> fib (x-1)) -- RTSRef (Int,Int -> Int) b_queue = unsafePerformIO $ newQueueParArray (\x -> fib (x-2)) -- RTSRef (Int,Int -> Int) fib n caller | n <= 1 = 1 | otherwise = unsafePerformIO $ do Ab <- addToMainQueue (defer (+) caller) A' <- addToParArrQueue a_queue x ab B' <- addToParArrQueue b_queue x ab addToMainQueue ab -- add a spark to check a' and b' evaluation status, compute a+b and update the caller. That transfomation cannot be done at the source level using usual type (class/families) hackery. It could be done, though, using core-to-core transformations. It is clear that several values of same type (Int for fib) and a function to perform operations over them leads to SIMD execution. I made some provisions to exploit SIMD and ILP in my model. It can load more than single task information and add several values per cycle. This also speeds execution up, but not so radically (about 3%). The source code for model is here: http://82.146.47.211/attachment/wiki/ndpph/ndp-ph.hs (it's a MskHUG.ru domain, we have temporary problems with DNS). It short of comments, but I tried to make understandable function names. Compile it with 'ghc -o ndp-ph --make -O2 ndp-ph' and run with a command line like the following: ndp-ph.exe cpuCount 1 usePrivateGroups 0 maxABTaskLength 64 taskFetchsPerCycle 1 thunksPerAddition 8 cyclesPerAddition 1 I decided to create a model of exexcution instead of modifying an existing implementation because I have not enough time. I wrote it over evenings and a weekend, so it is simple, it's rude and it does the job pretty fine. From nccb2 at kent.ac.uk Mon Aug 17 10:49:51 2009 From: nccb2 at kent.ac.uk (Neil Brown) Date: Mon Aug 17 10:30:01 2009 Subject: [Haskell-cafe] Got problems with classes In-Reply-To: <161821250490933@webmail51.yandex.ru> References: <161821250490933@webmail51.yandex.ru> Message-ID: <4A896E0F.5010504@kent.ac.uk> Hi, One reason (there may be more) is as follows: Grigory Sarnitskiy wrote: > class Configuration c where > getParticleI :: (Particle p) => c -> Int -> p > This type signature declares that for any type c that has a Configuration instance (and an Int), you can give me back something that is of *any type* p, provided I have a Particle instance for p. So if I was to declare: instance Particle Int Then I should be able to do: x :: Int x = getParticleI someConfigurationItem 6 But... > type Collection p = UArray (Int,Int) Double > instance Configuration (Collection p) where > getParticleI config i = (1,1,1) :: ParticleC > What you are doing in your instance, however, is always returning a ParticleC, which is a specific type rather than any type that belongs to Particle. There are several ways to solve this. A few examples: 1. Make getParticleI specifically return a ParticleC, rather than the type p. 2. Add a makeParticle function to the particle type-class. If you had: class Particle p where makeParticle :: (Double, Double, Double) -> p Then you could rewrite that last line as: getParticleI config i = makeParticle (1, 1, 1) And then the return would be of any type p that has a Particle instance. 3. Parameterise the collection over the particle, e.g. class Configuration c where getParticleI :: Particle p => c p -> Int -> p But currently Collection is not actually parameterised using the p parameter (the UArray has Double, not Particle), so I can't properly adjust your example for that. Hope that helps, Neil. From jvranish at gmail.com Mon Aug 17 11:05:01 2009 From: jvranish at gmail.com (Job Vranish) Date: Mon Aug 17 10:45:11 2009 Subject: [Haskell-cafe] Got problems with classes In-Reply-To: <161821250490933@webmail51.yandex.ru> References: <161821250490933@webmail51.yandex.ru> Message-ID: I'm not exactly sure what you're trying to do, but the problem is that you're trying to return a specific value where the type signature is polymorphic. getParticleI returns a p, (with the constraint that p is a type in the class Particle) This means that getParticleI can be called in any context that needs a Particle p, but your getParticleI returns (Double, Double, Double) so it would only work in a context that needed a (Double, Double, Double), and the type signature doesn't reflect that, so you get an error. To emphasize the problem, say I make a ParticleD type ParticleD = (Int, Int) instance Particle ParticleD let (a, b) = getParticleI myConfig 5 -- this is perfectly valid since ParticleD is a Particle, but doesn't work with your getParticleI definition because it returns a specific type (Double, Double, Double). Do you see what I mean? You can fix it by either fixing the type of getParticleI: getParticleI :: c -> Int -> ParticleC or by using multiparameter type classes class Configuration c p where getParticleI :: (Particle p) => c -> Int -> p depending on what you're actually trying to do. - Job On Mon, Aug 17, 2009 at 2:35 AM, Grigory Sarnitskiy wrote: > Hello! I can't understand why the following dummy example doesn't work. > > {-# OPTIONS -XTypeSynonymInstances #-} > {-# OPTIONS -XFlexibleInstances #-} > module Main where > import Data.Array.Unboxed > > class Particle p > > type ParticleC = (Double, Double, Double) > instance Particle ParticleC > > class Configuration c where > getParticleI :: (Particle p) => c -> Int -> p > > type Collection p = UArray (Int,Int) Double > instance Configuration (Collection p) where > getParticleI config i = (1,1,1) :: ParticleC > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090817/b7c80cab/attachment.html From ganesh.sittampalam at credit-suisse.com Mon Aug 17 12:39:19 2009 From: ganesh.sittampalam at credit-suisse.com (Sittampalam, Ganesh) Date: Mon Aug 17 12:19:39 2009 Subject: [Haskell-cafe] Credit Suisse is hiring Message-ID: <16442B752A06A74AB4D9F9A5FF076E4B03B9F906@ELON17P32001A.csfb.cs-group.com> Hi, Just to chime in with the spate of job advertisements, the Global Modelling and Analytics Group (GMAG) at Credit Suisse is once again looking to hire functional programmers. The group consists of about 130 people worldwide. The majority of the group are mathematicians engaged in developing mathematical models for financial products traded by the division. Approximately 20 people are primarily computing experts, based in the Architecture and Delivery (AD) subgroup within GMAG, and successful candidates will also be based in this group. We are already making heavy use of functional programming within the group, and we expect to increase this in the future. Some information about our Haskell projects can be found here: http://www.haskell.org/communities/05-2009/html/report.html#creditsuisse ; more recently we have adopted F# for implementing and deploying models on the .NET platform and we are currently ramping up our F# usage. Our team works closely with the modellers to help them leverage functional programming to improve the design of their code. Key requirements: At least one of: - An academic track record in functional programming. - Significant experience of "real-world" computing environments, preferably using functional programming. Excellent communication skills in order to convey new ideas to our modelling team. Location: London or New York Contact: Howard Mansell Myself (Ganesh Sittampalam ) and Tobias Gedell will be attending ICFP 2009 and associated workshops in Edinburgh - if you'd like to discuss this in person, get in touch with us by email, or just grab one of us there. Background information: As one of the world's leading banks, Credit Suisse provides its clients with investment banking, private banking and asset management services worldwide. Founded in 1856, Credit Suisse has a long tradition of meeting the complex financial needs of a wide range of clients, offering advisory services, comprehensive solutions and innovative products to companies, institutional clients and high-net-worth private clients globally. Credit Suisse is active in over 50 countries and employs approximately 46,000 people. Further information can be found at www.credit-suisse.com. Cultural diversity is essential to our success. As such, we employ people from more than 100 countries. Credit Suisse empowers employees to work openly and respectfully with each other and with clients, ultimately striving to deliver superior results while offering initiatives and programs to assist employees achieve a healthy work-life balance. The Global Modelling and Analytics Group (GMAG) is responsible for producing state-of-the-art pricing, trading and risk management models for Credit Suisse. These models are used across a range of businesses in the Fixed Income and Equity departments. The group performs the full spectrum of quantitative work, from mathematical modelling through software implementation and delivery, to risk analysis of trades and existing portfolios. The group's mandate covers all major asset classes, including Credit Derivatives, Commodities, Emerging Markets, Equity Derivatives and Convertibles, Exotics, Foreign Exchange, Fund Linked Products, Interest Rate Products and Mortgage Derivatives. GMAG operates globally with members located in London, New York, Hong Kong, Tokyo, Zurich and S?o Paolo. Established in 1990, GMAG stands out as a unified quant group that has been covering all major product areas since its inception. The group has always enjoyed a strong relationship with Trading, Structuring and Sales, assisting them with trade pricing and risk management. As the group is based on the trading floor, it is ideally placed to respond to the financial modelling needs of the businesses it supports. The breadth of GMAG's mandate makes it uniquely positioned to leverage the skills and experience of its members, and to provide a consistent modelling approach across all areas. Over time, the group has developed an extensive suite of pricing models on a common platform with complete integration across all asset classes. Quantitative Analysts in GMAG carry out a range of activities which include the creation of sophisticated mathematical models for the valuation of complex derivatives, development of the technology platform used to deliver models and driving the use of these models throughout the bank. Our Quantitative Analysts typically hold an advanced quantitative degree, have excellent analytical and problem-solving skills, demonstrate creative thinking, have strong programming skills, and are confident communicators. =============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html =============================================================================== -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090817/d54c2ff8/attachment.html From explicitcall at googlemail.com Mon Aug 17 13:17:41 2009 From: explicitcall at googlemail.com (Max Desyatov) Date: Mon Aug 17 12:57:52 2009 Subject: [Haskell-cafe] Re: Changelogs and "available since" In-Reply-To: <431fb4c10908170918n13df5a61x54dad34d82ff0d49@mail.gmail.com> (Laszlo Nagy's message of "Mon, 17 Aug 2009 18:18:46 +0200") References: <431fb4c10908170918n13df5a61x54dad34d82ff0d49@mail.gmail.com> Message-ID: <874os6gy16.fsf@zagan.made.you> Laszlo Nagy writes: > Hi All, > > I was volunteer to solve this problem: > > In a conversation on the libraries@haskell.org I was suggested to > scratch my idea here. > > > I would use hoogle for this. Currently it stores the package name and > the symbols of the modules about a package. What do you think about hayoo? I prefer this to hoogle, as hayoo has more complete database across hackage packages, AFAIK > I would extend it to store > the version of the package as well. Extend the query methods to use > all the available package description at search. And make a > VersionRange from the matched Versions. I wrote some code for doing this a while ago. Take a look and make some comments, I can extend this library to satisfy your needs http://hackage.haskell.org/package/cabal-query From sargrigory at ya.ru Mon Aug 17 14:01:03 2009 From: sargrigory at ya.ru (Grigory Sarnitskiy) Date: Mon Aug 17 13:41:14 2009 Subject: [Haskell-cafe] Got problems with classes In-Reply-To: References: <161821250490933@webmail51.yandex.ru> Message-ID: <94421250532063@webmail57.yandex.ru> An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090817/1c916737/attachment.html From sacha at myxomop.com Mon Aug 17 16:14:48 2009 From: sacha at myxomop.com (Alexander Kotelnikov) Date: Mon Aug 17 15:55:24 2009 Subject: [Haskell-cafe] Re: simple hsql question References: <874os724if.fsf@benington.loc> Message-ID: <87my5yyz7r.fsf@benington.loc> Ok, let me ask it in another way. Is there a good way to access databases, mysql in particular, from haskell program? >>>>> On Sun, 16 Aug 2009 18:54:32 +0400 >>>>> "AK" == Alexander Kotelnikov wrote: AK> AK> Hi AK> I wanted to see what access to databases HSQL provides and I stumbled in AK> the very beginning. Assume I have a table map1 with attributes "i" and "s" AK> interger and varchar() respectively. The following code fails (with AK> segfault) for me. And I see no other way to tell compiler that I am AK> expecting an interger to be found as 'i' in a fetched row. AK> AK> import Database.HSQL AK> import Database.HSQL.MySQL AK> AK> main :: IO () AK> main = do AK> c <- connect "localhost" "tx_test" "sacha" "" AK> s <- query c "SELECT i FROM map1" AK> print $ getFieldsTypes s AK> i <- (getFieldValue s "i")::IO Int AK> print i AK> disconnect c AK> AK> -- AK> Alexander Kotelnikov AK> Saint-Petersburg, Russia AK> -- Alexander Kotelnikov Saint-Petersburg, Russia From ndmitchell at gmail.com Mon Aug 17 16:16:28 2009 From: ndmitchell at gmail.com (Neil Mitchell) Date: Mon Aug 17 15:56:40 2009 Subject: [Haskell-cafe] Re: Changelogs and "available since" In-Reply-To: <874os6gy16.fsf@zagan.made.you> References: <431fb4c10908170918n13df5a61x54dad34d82ff0d49@mail.gmail.com> <874os6gy16.fsf@zagan.made.you> Message-ID: <404396ef0908171316s50d9d541uea5fc6d8ac2009a5@mail.gmail.com> Hi >> I would use hoogle for this. Currently it stores the package name and >> the symbols of the modules about a package. > > What do you think about hayoo? ?I prefer this to hoogle, as hayoo has > more complete database across hackage packages, AFAIK Hayoo gets it package database out of haddock with text hackery - try things like data Foo = Bar {a, b :: Foo}, it's not nearly complete. Hoogle on the other hand directly examines bits and produces an accurate index. That's also one of the reasons Hoogle is a bit behind Hayoo, it has to do more to get the full package information out. One day Hoogle will match Hayoo and index all packages. Thanks Neil From jvranish at gmail.com Mon Aug 17 17:07:12 2009 From: jvranish at gmail.com (Job Vranish) Date: Mon Aug 17 16:47:24 2009 Subject: [Haskell-cafe] Re: Changelogs and "available since" In-Reply-To: <404396ef0908171316s50d9d541uea5fc6d8ac2009a5@mail.gmail.com> References: <431fb4c10908170918n13df5a61x54dad34d82ff0d49@mail.gmail.com> <874os6gy16.fsf@zagan.made.you> <404396ef0908171316s50d9d541uea5fc6d8ac2009a5@mail.gmail.com> Message-ID: What would it take to increase the hoogle index to most of the packages on hackage? I have been wanting to use hoogle to search hackage for a while and I would be interesting in helping make it happen. - Job On Mon, Aug 17, 2009 at 4:16 PM, Neil Mitchell wrote: > Hi > > >> I would use hoogle for this. Currently it stores the package name and > >> the symbols of the modules about a package. > > > > What do you think about hayoo? I prefer this to hoogle, as hayoo has > > more complete database across hackage packages, AFAIK > > Hayoo gets it package database out of haddock with text hackery - try > things like data Foo = Bar {a, b :: Foo}, it's not nearly complete. > Hoogle on the other hand directly examines bits and produces an > accurate index. That's also one of the reasons Hoogle is a bit behind > Hayoo, it has to do more to get the full package information out. One > day Hoogle will match Hayoo and index all packages. > > Thanks > > Neil > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090817/655a5aa4/attachment.html From explicitcall at googlemail.com Mon Aug 17 18:07:51 2009 From: explicitcall at googlemail.com (Max Desyatov) Date: Mon Aug 17 17:47:58 2009 Subject: [Haskell-cafe] Re: simple hsql question In-Reply-To: <87my5yyz7r.fsf@benington.loc> (Alexander Kotelnikov's message of "Tue, 18 Aug 2009 00:14:48 +0400") References: <874os724if.fsf@benington.loc> <87my5yyz7r.fsf@benington.loc> Message-ID: <87ljli3xhk.fsf@zagan.made.you> Alexander Kotelnikov writes: > Ok, let me ask it in another way. Is there a good way to access > databases, mysql in particular, from haskell program? Use HDBC or Takusen. You can find them on hackage. HDBC is fairly usable, but you must write SQL queries by yourself or use some simple machinery to construct queries. I've written a bunch of helper functions to construct queries as strings, e.g.: > insert :: String -> [String] -> String -> String > insert t = (++) . > (" INSERT " ++) . > (" INTO " ++) . > (t ++) . > (" (" ++) . (++ ") ") . > join ", " > select :: [String] -> String -> String > select = (++) . (" SELECT " ++) . join ", " > from :: [String] -> String -> String > from = (++) . (" FROM " ++) . join ", " In the end your query looks like: > query' (select ["max(cheque)"] . from ["history"] $ ";" In this way you avoid typical errors which emerge when you write simple SQL query strings. Though you don't get true static typing. There are haskelldb and Takusen, which provide more elaborate way of connecting to RDBMS, they demand more investigation though. From simon at joyful.com Mon Aug 17 18:20:49 2009 From: simon at joyful.com (Simon Michael) Date: Mon Aug 17 18:01:21 2009 Subject: [Haskell-cafe] Re: Request for Comments - hscurrency 0.0.1 In-Reply-To: References: Message-ID: Thanks for sharing this. If you haven't already, also check out http://hledger.org/api-doc -> Amount and Commodity modules for possibly related work. From jefferson.r.heard at gmail.com Mon Aug 17 19:49:57 2009 From: jefferson.r.heard at gmail.com (Jeff Heard) Date: Mon Aug 17 19:30:26 2009 Subject: [Haskell-cafe] ANN: OpenCLRaw 1.0.1000 Message-ID: <4165d3a70908171649o374aa995y26cfb570219cc351@mail.gmail.com> All, I've released a raw binding to the OpenCL platform on Hackage. The main differences between it and the C bindings are that constants have been replaced by newtypes for type safety reasons, void-essential functions that return a token errorcode return a Maybe ErrorCode, and functions that return a handle/ptr and return an error-code through an out-parameter return instead an Either ErrorCode a. Modules are grouped roughly by the section in which they appear in the standard. I'm working on an OpenCL binding that is a little more "cooked" as well as a high-level OpenCL binding. OpenCL is a platform for single-host heterogenous, data-parallel computing that follows roughly the OpenGL and OpenAL conventions for how the library is architected. It will be available by default in the next version of Apple's OS-X, and there are drivers for AMD Opteron/Athlons and nVidia CUDA-based graphics cards. The basic procedure behind running an OpenCL program is: 1. get a list of platforms 2. choose a device on the platform that fits your needs 3. create a context for the platform and the device 4. compile a program and "kernels" written in OpenCL/C 5. create memory buffer objects. 6. execute kernels on the memory buffer objects. 7. rinse hands, repeat. Obviously this is not very functional, but we can't get there without a raw binding. Data Parallel computing is somewhere Haskell is excelling; hopefully this will generate some interest in creating a DPH binding to OpenCL's C99-based language, OpenCL/C. From mauricio.antunes at gmail.com Mon Aug 17 20:26:50 2009 From: mauricio.antunes at gmail.com (=?ISO-8859-1?Q?Maur=ED=ADcio_CA?=) Date: Mon Aug 17 20:07:24 2009 Subject: [Haskell-cafe] Re: ANN: OpenCLRaw 1.0.1000 In-Reply-To: <4165d3a70908171649o374aa995y26cfb570219cc351@mail.gmail.com> References: <4165d3a70908171649o374aa995y26cfb570219cc351@mail.gmail.com> Message-ID: > I've released a raw binding to the OpenCL platform on > Hackage. The main differences between it and the C bindings are > that constants have been replaced by newtypes for type safety > reasons, (...) If you think there's something I could change in the package below to make it usefull for this kind of work in the future, please let me know: http://hackage.haskell.org/packages/archive/bindings-common/0.2.5/doc/html/Bindings.html Although, design decisions are pretty different, so may be it would not help, but I thought it worth sugesting. Best, Maur?cio From ekirpichov at gmail.com Tue Aug 18 03:28:17 2009 From: ekirpichov at gmail.com (Eugene Kirpichov) Date: Tue Aug 18 03:08:25 2009 Subject: [Haskell-cafe] Grouping and SIMD in parallel Haskell (using Nested Data Parallel Haskell ideas in legacy code) In-Reply-To: <431353321B0D214CBD767E22931DD477E52317522C@msk-mail-2.prosoft.ru> References: <431353321B0D214CBD767E22931DD477E52317522C@msk-mail-2.prosoft.ru> Message-ID: <5e0214850908180028l78293a84l3afbabb9d5ac140e@mail.gmail.com> Now I finally understood the idea that you were talking about :) I didn't quite get it during the MskHUG meeting. The idea is brilliant to my mind; I am surprised that none of the gurus are answering. So, if I understood it correctly, you are suggesting to: - make a separate spark queue (implemented by a linked list of groupSize-sized arrays) for every thunk type in the program that can possibly be the argument of a `par` or `pseq` (which, however, may turn out to be almost all thunk types present in the program) - automagically create vectorized versions of these thunks' code - spawn sparks by appending them to the corresponding queue (to a non-locked array node?) - evaluate sparks in a vectorized fashion by invoking the vectorized code over groups The problems I see here are: - not all thunks code can be vectorized automatically - how should we represent the sparks in the queue for a certain thunk type? It's clear that it is no longer needed to put the whole closure into the spark queue, since the closure code is already known and fixed for each queue. For efficient vectorization, the queue probably should consist of closure data arrays. - I do not immediately see an efficient (lockless) way of picking a nonempty spark queue; however, I am sure there must be such a way, and even if there isn't, the inefficiency may well be overweighted by the efficiency gain from vectorization 2009/8/17 Zefirov Sergey : > I haven't had enough time to polish a paper about the subject, so I decided to post my results here, in Haskell Caf?. > > When Simon Peyton-Jones was in Moscow about a month ago I made a bold statement that Parallel Haskell programs, expressed with the help of par and pseq, can be transformed into Nested Data Parallel Haskell. > > I wrote a simple model of what will be if we group arguments of par and pseq into queues based on parallel arrays from NDPH. We could then evaluate all thunks from that queues in parallel using SIMD (or just getting higher ILP). We also do not have to lock out main spark queue, we lock only queue we should put argument in. The latter turned out to be beneficial in itself, at least in my simple model. > > Let us look at famous parallel fib function: > ? ?Fib n > ? ? ? ?| N <= 1 = 1 > ? ? ? ?| otherwise = a `par` b `pseq` a+b > ? ? ? ?where > ? ? ? ? ? ?a = fib (n-1) > ? ? ? ? ? ?b = fib (n-2) > > When we evaluate fib we put a spark of a into spark queue and proceed to evaluate b and, then, a+b. When we put a into spark queue, we lock queue out, modify and release. There is a big probability that threads on different cores will compete for queue lock and some of them (most of them) will waste time waiting for lock release. > > If we group a's into different queue and put to main spark queue a spark to evaluate a complete group of a's at once, we will get less wasted time. > > This will work even for single CPU. Below is a run of (fib 15) on my model with cpuCount 1, 4 and 16 and a's or b's group length 0 (no grouping) and 16: > > ? ?cpuCount ?groupLength=0 ?groupLength=16 > ? ? ? ? ? ? ?modelTicks ? ? modelTicks > ? ?1 ? ? ? ? 34535 ? ? ? ? ?27189 > ? ?4 ? ? ? ? 12178 ? ? ? ? ?7472 > ? ?16 ? ? ? ?7568 ? ? ? ? ? 3157 > ? ?speedup ? 2.19 times ? ? 3.11 times > ? ?ticks1/ticks16 > > I think results speak for itself. I think the idea of `par` argument grouping could be viable. > > I should note that I made several digressions when I wrote model. One of digressions is that all evaluations are put into queue. In (a `par` b `pseq` a+b) a put into a_queue, b put into b_queue and (a+b) put into main queue. Each evaluated spark update it's "parent" - a spark that wait for it. > > Also, main loop of single CPU changed from simple (reading main spark queue + execute when get something) into a series of attepmts with fall back on failure: > - first read main queue and execute spark if succeed, > - else read current a_queue and execute all sparks there if succeed, > - else read current b_queue and execute all sparks there if succeed, > - else go to main loop. > > The new (transformed) code for our fib below: > > ? ?-- |Create a new queue based on parallel array. It holds a parallel array with current arguments and a function that performs > ? ?-- computation in RTS monad (evaluation function). > ? ?newQueueParArray :: (x -> RTS ()) -> RTSRef ([: x :],x -> RTS ()) > ? ?a_queue = unsafePerformIO $ newQueueParArray (\x -> fib (x-1)) -- RTSRef (Int,Int -> Int) > ? ?b_queue = unsafePerformIO $ newQueueParArray (\x -> fib (x-2)) -- RTSRef (Int,Int -> Int) > > ? ?fib n caller > ? ? ? ?| n <= 1 = 1 > ? ? ? ?| otherwise = unsafePerformIO $ do > ? ? ? ? ? ?Ab <- addToMainQueue (defer (+) caller) > ? ? ? ? ? ?A' <- addToParArrQueue a_queue x ab > ? ? ? ? ? ?B' <- addToParArrQueue b_queue x ab > ? ? ? ? ? ?addToMainQueue ab -- add a spark to check a' and b' evaluation status, compute a+b and update the caller. > > That transfomation cannot be done at the source level using usual type (class/families) hackery. It could be done, though, using core-to-core transformations. > > It is clear that several values of same type (Int for fib) and a function to perform operations over them leads to SIMD execution. > > I made some provisions to exploit SIMD and ILP in my model. It can load more than single task information and add several values per cycle. > > This also speeds execution up, but not so radically (about 3%). > > The source code for model is here: http://82.146.47.211/attachment/wiki/ndpph/ndp-ph.hs (it's a MskHUG.ru domain, we have temporary problems with DNS). It short of comments, but I tried to make understandable function names. > > Compile it with 'ghc -o ndp-ph --make -O2 ndp-ph' and run with a command line like the following: > > ? ? ndp-ph.exe cpuCount 1 usePrivateGroups 0 maxABTaskLength 64 taskFetchsPerCycle 1 thunksPerAddition 8 cyclesPerAddition 1 > > I decided to create a model of exexcution instead of modifying an existing implementation because I have not enough time. I wrote it over evenings and a weekend, so it is simple, it's rude and it does the job pretty fine. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Eugene Kirpichov Web IR developer, market.yandex.ru From ravi_n at alum.mit.edu Mon Aug 17 14:17:47 2009 From: ravi_n at alum.mit.edu (Ravi Nanavati) Date: Tue Aug 18 03:20:55 2009 Subject: [Haskell-cafe] REMINDER: Next BostonHaskell meeting TOMORROW (August 18th) at MIT Message-ID: <161d443c0908171117j3b4f780en57434d97b4b0cc29@mail.gmail.com> The full details of the event are here: http://groups.google.com/group/bostonhaskell/browse_thread/thread/71243e7d2ec57300 I'm just sending out this reminder to make sure more people hear about the event (especially as, with Brent on vacation, there wasn't a Haskell Weekly News this week). If you're planning to come please respond to our scheduling poll at: http://doodle.com/participation.html?pollId=x8rbbbprtezdtaan This will help us get a better count of attendees for refreshments (since my wife has volunteered to make more baked goodies). Please also respond to the poll if you're interested in BostonHaskell, but couldn't come this month because of scheduling or location constraints. That will help us improve planning for future meetings. I look forward to seeing many Boston-area Haskellers tomorrow! Thanks, - Ravi Nanavati From colin at colina.demon.co.uk Tue Aug 18 05:25:34 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Tue Aug 18 05:05:51 2009 Subject: [Haskell-cafe] Can't install Haskell Platform on 64-bit Linux Message-ID: I installed GHC 6.10.4 (as ./configure said it was required) from a .bz2 file on the GHC downloads page. I then tried ./configure for the platform again, and got: checking ghc actually works... no configure: error: Your installation of ghc does not appear to work. It cannot compile a simple program (see config.log for the details). If you installed ghc from a generic binary tarball then it is worth checking that you have the 'gmp' C library and header files installed. (On debian-based systems this package is called libgmp3-dev.) Looking in config.log, I see: configure:2287: checking ghc actually works configure:2296: /usr/local/bin/ghc -o conftest conftest.hs /tmp/ghc22651_0/ghc22651_0.s: Assembler messages: /tmp/ghc22651_0/ghc22651_0.s:43:0: Error: suffix or operands invalid for `push' /tmp/ghc22651_0/ghc22651_0.s:89:0: Error: suffix or operands invalid for `push' /tmp/ghc22651_0/ghc22651_0.s:135:0: Error: suffix or operands invalid for `push' configure:2299: $? = 1 configure: failed program was: main = putStr "Hello world!\n" -- this file generated by TRY-COMPILE-GHC end of failed program. configure:2308: result: no configure:2314: error: Your installation of ghc does not appear to work. It cannot compile a simple program (see config.log for the details). If you installed ghc from a generic binary tarball then it is worth checking that you have the 'gmp' C library and header files installed. (On debian-based systems this package is called libgmp3-dev.) Libgmp is installed. I don't know the significance of the assembler error messages. If I type from the command line: ghci I get the Prelude> prompt, so it looks like the installation is OK at first glance. What should I check next? -- Colin Adams Preston Lancashire From magnus at therning.org Tue Aug 18 05:54:45 2009 From: magnus at therning.org (Magnus Therning) Date: Tue Aug 18 05:34:56 2009 Subject: [Haskell-cafe] Can't install Haskell Platform on 64-bit Linux In-Reply-To: References: Message-ID: On Tue, Aug 18, 2009 at 10:25 AM, Colin Paul Adams wrote: > I installed GHC 6.10.4 (as ./configure said it was required) from a > .bz2 file on the GHC downloads page. I then tried ./configure for the > platform again, and got: What distribution of Linux do you use? I'd strongly suggest getting it from your distro's repo rather than downloading the tar-ball. That way you avoid satisfying dependencies manually. /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?org http://therning.org/magnus identi.ca|twitter: magthe From colin at colina.demon.co.uk Tue Aug 18 05:58:44 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Tue Aug 18 05:39:03 2009 Subject: [Haskell-cafe] Can't install Haskell Platform on 64-bit Linux In-Reply-To: (Magnus Therning's message of "Tue\, 18 Aug 2009 10\:54\:45 +0100") References: Message-ID: >>>>> "Magnus" == Magnus Therning writes: Magnus> On Tue, Aug 18, 2009 at 10:25 AM, Colin Paul Magnus> Adams wrote: >> I installed GHC 6.10.4 (as ./configure said it was required) >> from a .bz2 file on the GHC downloads page. I then tried >> ./configure for the platform again, and got: Magnus> What distribution of Linux do you use? Fedora. Magnus> I'd strongly suggest getting it from your distro's repo Magnus> rather than downloading the tar-ball. That way you avoid Magnus> satisfying dependencies manually. It's not available. -- Colin Adams Preston Lancashire From zefirov at prosoft.ru Tue Aug 18 06:06:21 2009 From: zefirov at prosoft.ru (Zefirov Sergey) Date: Tue Aug 18 05:46:30 2009 Subject: [Haskell-cafe] Grouping and SIMD in parallel Haskell (using Nested Data Parallel Haskell ideas in legacy code) In-Reply-To: <5e0214850908180028l78293a84l3afbabb9d5ac140e@mail.gmail.com> References: <431353321B0D214CBD767E22931DD477E52317522C@msk-mail-2.prosoft.ru> <5e0214850908180028l78293a84l3afbabb9d5ac140e@mail.gmail.com> Message-ID: <431353321B0D214CBD767E22931DD477E52317522D@msk-mail-2.prosoft.ru> > -----Original Message----- > From: Eugene Kirpichov [mailto:ekirpichov@gmail.com] > Sent: Tuesday, August 18, 2009 11:28 AM > To: Zefirov Sergey > Cc: haskell-cafe@haskell.org > Subject: Re: [Haskell-cafe] Grouping and SIMD in parallel Haskell > (using Nested Data Parallel Haskell ideas in legacy code) > > Now I finally understood the idea that you were talking about :) I > didn't quite get it during the MskHUG meeting. > The idea is brilliant to my mind; I am surprised that none of the > gurus are answering. > > So, if I understood it correctly, you are suggesting to: > - make a separate spark queue (implemented by a linked list of > groupSize-sized arrays) for every thunk type in the program that can > possibly be the argument of a `par` or `pseq` (which, however, may > turn out to be almost all thunk types present in the program) Yep. And it could be beneficiary by itself. > - automagically create vectorized versions of these thunks' code If we can. Looks like we can. ;) > - spawn sparks by appending them to the corresponding queue (to a > non-locked array node?) Sparks queues can be non-locked if they belong to threads. Or, in other words, each thread has it's own spark's queue and all threads share main queue. If sparks queues are shared between threads, they should be locked. My model suggests that private spark queues slows down execution speed, but I haven't paid enough attention to the subject so my code could be wrong. Look yourself: usePrivateGroups maxABTaskLength ticks (fib 15) 0 0 7568 0 16 3157 0 32 2977 1 0 7753 1 16 3772 1 32 4242 All other parameters are: cpuCount 16 taskFetchsPerCycle 1 thunksPerAddition 1 cyclesPerAddition 1. Anyway, let's say we have several processors and they all share all queues. When one processor encounter that some queue is locked it immediately proceed to another queue, which could be locked with less probability. > - evaluate sparks in a vectorized fashion by invoking the vectorized > code over groups Again, if we can. > The problems I see here are: > - not all thunks code can be vectorized automatically I tried to find a contradictory example and failed. But I haven't tried very hard. ;) I noticed that first argument for par should be considered strict. So we can demand that fib will receive Int# instead of boxed (and delayed) Int. Operations on [:Int#:] ([:Float#:], [:Char#:]) should be very efficient. An argument could be delayed (lazy) or of an algebraic type (like Maybe). Here we will have forcing of computation or pattern matching and, therefore, conditional execution. Conditional execution could be expressed in parallel SIMD operations, an example is given at Tim Sweeney presentation (near the end). (http://graphics.cs.williams.edu/archive/SweeneyHPG2009/TimHPG2009.pdf) The version there isn't best possible, but it works. > - how should we represent the sparks in the queue for a certain thunk > type? It's clear that it is no longer needed to put the whole closure > into the spark queue, since the closure code is already known and > fixed for each queue. For efficient vectorization, the queue probably > should consist of closure data arrays. I think we would borrow closure representation from NDP Haskell. ;) > - I do not immediately see an efficient (lockless) way of picking a > nonempty spark queue; however, I am sure there must be such a way, and > even if there isn't, the inefficiency may well be overweighted by the > efficiency gain from vectorization With different sparks queues we prevent frequent locking of main spark queue. CPUs get more work per single lock. I think it's good in itself, vectorization could only add to it. Look at the table: maxABTaskLength ticks (fib 15) 0 7568 1 5651 2 4656 4 3663 8 3263 16 3157 32 2977 64 2931 (other model parameters: cpuCount 16 usePrivateGroups 0 maxABTaskLength taskFetchsPerCycle 1 thunksPerAddition 1 cyclesPerAddition 1) The effect on vectorization according to my model is negligible: thunksPerAddition 2 results in 2894 ticks and then time stop lowering. Increase in taskFetchsPerCycle also does not provide any noticeable speed up. I cannot promise because, but I will try to implement my idea because I already see it as a good idea. ;) PS I always fascinated how Haskell is amenable for RTS changes. Add a complication underneath once and free yourself from complication on the surface for ever. ;) From kolar at fit.vutbr.cz Tue Aug 18 06:50:38 2009 From: kolar at fit.vutbr.cz (Dusan Kolar) Date: Tue Aug 18 06:30:45 2009 Subject: [Haskell-cafe] Library function for map+append Message-ID: <4A8A877E.9030805@fit.vutbr.cz> Hello all, During a small project I'm trying to develop a small application. It becomes quite often that I need a function mapapp: mapapp _ [] ap = ap mapapp f (a:as) ap = f a : map f as ap I tried hoogle to find such a function with no success. Is there any function/functions built-in "standard" libraries that could easily satisfy the functionality with the same or even better (?) efficiency? Of course, (map f list) ++ append would do the same as mapapp f list append but with less efficiency. Or am I wrong? Thanks Dusan From ekirpichov at gmail.com Tue Aug 18 07:00:20 2009 From: ekirpichov at gmail.com (Eugene Kirpichov) Date: Tue Aug 18 06:40:27 2009 Subject: [Haskell-cafe] Library function for map+append In-Reply-To: <4A8A877E.9030805@fit.vutbr.cz> References: <4A8A877E.9030805@fit.vutbr.cz> Message-ID: <5e0214850908180400n543d215avc8bbe4323a8c85ee@mail.gmail.com> Hi. Have you done any measurements that prove that such a function would indeed increase performance noticeably? 2009/8/18 Dusan Kolar : > Hello all, > > ?During a small project I'm trying to develop a small application. It > becomes quite often that I need a function mapapp: > > mapapp _ [] ap = ap > mapapp f (a:as) ap = f a : map f as ap > > ?I tried hoogle to find such a function with no success. Is there any > function/functions built-in "standard" libraries that could easily satisfy > the functionality with the same or even better (?) efficiency? > > ?Of course, > (map f list) ++ append > ?would do the same as > > mapapp f list append > > ?but with less efficiency. Or am I wrong? > > ?Thanks > > ? Dusan > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Eugene Kirpichov Web IR developer, market.yandex.ru From Alistair.Bayley at invesco.com Tue Aug 18 07:03:12 2009 From: Alistair.Bayley at invesco.com (Bayley, Alistair) Date: Tue Aug 18 06:43:20 2009 Subject: [Haskell-cafe] Library function for map+append In-Reply-To: <4A8A877E.9030805@fit.vutbr.cz> References: <4A8A877E.9030805@fit.vutbr.cz> Message-ID: <125EACD0CAE4D24ABDB4D148C4593DA911026205@GBLONXMB02.corp.amvescap.net> > From: haskell-cafe-bounces@haskell.org > [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Dusan Kolar > > During a small project I'm trying to develop a small > application. It > becomes quite often that I need a function mapapp: > > mapapp _ [] ap = ap > mapapp f (a:as) ap = f a : map f as ap > > I tried hoogle to find such a function with no success. Is > there any > function/functions built-in "standard" libraries that could easily > satisfy the functionality with the same or even better (?) efficiency? What does mapapp do? What is its type? At first I thought maybe you were rewriting concatMap, but now I can't tell what you're doing. http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-List.htm l#v%3AconcatMap 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 tonymorris at gmail.com Tue Aug 18 07:28:25 2009 From: tonymorris at gmail.com (Tony Morris) Date: Tue Aug 18 07:08:45 2009 Subject: [Haskell-cafe] Library function for map+append In-Reply-To: <4A8A877E.9030805@fit.vutbr.cz> References: <4A8A877E.9030805@fit.vutbr.cz> Message-ID: <4A8A9059.50304@gmail.com> Dusan Kolar wrote: > Hello all, > > During a small project I'm trying to develop a small application. It > becomes quite often that I need a function mapapp: > > mapapp _ [] ap = ap > mapapp f (a:as) ap = f a : map f as ap > > I tried hoogle to find such a function with no success. Is there any > function/functions built-in "standard" libraries that could easily > satisfy the functionality with the same or even better (?) efficiency? > > Of course, > (map f list) ++ append > would do the same as > > mapapp f list append > > but with less efficiency. Or am I wrong? > > Thanks > > Dusan > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > mapapp = ((++) .) . map Reasoning about efficiency in a pure lazy language is different. -- Tony Morris http://tmorris.net/ From bulat.ziganshin at gmail.com Tue Aug 18 07:23:54 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Aug 18 07:09:22 2009 Subject: [Haskell-cafe] Library function for map+append In-Reply-To: <4A8A877E.9030805@fit.vutbr.cz> References: <4A8A877E.9030805@fit.vutbr.cz> Message-ID: <13410248282.20090818152354@gmail.com> Hello Dusan, Tuesday, August 18, 2009, 2:50:38 PM, you wrote: > but with less efficiency. Or am I wrong? probably wrong. haskell is lazy language also there is differential lists (dlist) implementation on hackage -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From Alistair.Bayley at invesco.com Tue Aug 18 07:36:50 2009 From: Alistair.Bayley at invesco.com (Bayley, Alistair) Date: Tue Aug 18 07:16:58 2009 Subject: [Haskell-cafe] Library function for map+append In-Reply-To: <125EACD0CAE4D24ABDB4D148C4593DA911026205@GBLONXMB02.corp.amvescap.net> References: <4A8A877E.9030805@fit.vutbr.cz> <125EACD0CAE4D24ABDB4D148C4593DA911026205@GBLONXMB02.corp.amvescap.net> Message-ID: <125EACD0CAE4D24ABDB4D148C4593DA911026206@GBLONXMB02.corp.amvescap.net> > > mapapp _ [] ap = ap > > mapapp f (a:as) ap = f a : map f as ap > > What does mapapp do? What is its type? Never mind, I've got it now. 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 kolar at fit.vutbr.cz Tue Aug 18 07:40:33 2009 From: kolar at fit.vutbr.cz (Dusan Kolar) Date: Tue Aug 18 07:20:41 2009 Subject: [Haskell-cafe] Library function for map+append In-Reply-To: <13410248282.20090818152354@gmail.com> References: <4A8A877E.9030805@fit.vutbr.cz> <13410248282.20090818152354@gmail.com> Message-ID: <4A8A9331.7030909@fit.vutbr.cz> Dlists maybe good it all the app is written using them. Probably not good idea to switch to them in the middle of project... I know it is lazy, but I don't think it is able to eliminate operations, is it? At least intuitively, the map f list takes n*C ticks (C is for application of f and list "creation", n is the list length, f is of no importance, it is always the same, but list probably must be created due to ++). Then, (++) take n*K ticks (K for list creation - I want to write out the list at the end, so that it is created). In my case (mapapp), it is n*CK, where CK stands for f and list creation... the CK is very similar to C... Thus, I should save the n*K, or at least its large portion... shouldn't I? If not, how the compiler can eliminate the operations? Dusan Bulat Ziganshin wrote: > Hello Dusan, > > Tuesday, August 18, 2009, 2:50:38 PM, you wrote: > > >> but with less efficiency. Or am I wrong? >> > > probably wrong. haskell is lazy language > > also there is differential lists (dlist) implementation on hackage > > > From clemens at endorphin.org Tue Aug 18 07:58:31 2009 From: clemens at endorphin.org (Clemens Fruhwirth) Date: Tue Aug 18 07:38:41 2009 Subject: [Haskell-cafe] Library function for map+append In-Reply-To: <4A8A877E.9030805@fit.vutbr.cz> References: <4A8A877E.9030805@fit.vutbr.cz> Message-ID: <2f83750a0908180458t13c89036w3375c9f7d3781c71@mail.gmail.com> 2009/8/18 Dusan Kolar : > Hello all, > > ?During a small project I'm trying to develop a small application. It > becomes quite often that I need a function mapapp: > > mapapp _ [] ap = ap > mapapp f (a:as) ap = f a : map f as ap > > ?I tried hoogle to find such a function with no success. Is there any > function/functions built-in "standard" libraries that could easily satisfy > the functionality with the same or even better (?) efficiency? Can't think of something like that either but at least we can make it shorter and less readable ;) mapapp f xs tail = foldr ((:) . f) tail xs > ?Of course, > (map f list) ++ append > ?would do the same as > > mapapp f list append > > ?but with less efficiency. Or am I wrong? Yes, that is less efficient because ++ has to create N new cons cells if "list" has length N. -- Fruhwirth Clemens http://clemens.endorphin.org From wsysdu at gmail.com Tue Aug 18 08:42:18 2009 From: wsysdu at gmail.com (Eric Wong) Date: Tue Aug 18 08:29:58 2009 Subject: [Haskell-cafe] simulation in the haskell way Message-ID: <200908182042.19093.wsysdu@gmail.com> Hello, Haskellers! I'm relatively new to haskell and due to my strong imperative background, it's really a pain to learn haskell. But I'm really indulged in it. :) Now I think I understand the basics of Haskell very well, such as the type system and monad. And for those data-flow kind of applications, I can easily structure the problem in a functional way and sketch out an intuitive picture of the computation. But for simulation kind-of problems, in which I think OO really fits the best, what's the haskell way to structure such problems? I once thought maybe I can use the State monad to simulate objects. But it's really hard for me to implement, because I think State monad is used to simulate a global shared state, is it right? Then what's the best way to simulate private states or just instead how to solve simulation problems such as a physical engine using the haskell way? Best regards. Eric From artem at AA5779.spb.edu Tue Aug 18 08:55:10 2009 From: artem at AA5779.spb.edu (Artem V. Andreev) Date: Tue Aug 18 08:35:21 2009 Subject: [Haskell-cafe] Library function for map+append In-Reply-To: <4A8A9331.7030909@fit.vutbr.cz> (Dusan Kolar's message of "Tue\, 18 Aug 2009 13\:40\:33 +0200") References: <4A8A877E.9030805@fit.vutbr.cz> <13410248282.20090818152354@gmail.com> <4A8A9331.7030909@fit.vutbr.cz> Message-ID: <878whhxowh.fsf@artemsmp.iling.nw.ru> Dusan Kolar writes: > Dlists maybe good it all the app is written using them. Probably not good idea to switch to them > in the middle of project... > > I know it is lazy, but I don't think it is able to eliminate operations, is it? > > At least intuitively, the map f list takes n*C ticks (C is for application of f and list > "creation", n is the list length, f is of no importance, it is always the same, but list probably > must be created due to ++). > > Then, (++) take n*K ticks (K for list creation - I want to write out the list at the end, so that > it is created). > > In my case (mapapp), it is n*CK, where CK stands for f and list creation... the CK is very similar > to C... Thus, I should save the n*K, or at least its large portion... shouldn't I? If not, how > the compiler can eliminate the operations? IMHO, the best way to reason about functional programs is via equational reasoning. So let's consider straightforward definitions for map and (++): map f [] = [] map f (x:xs) = f x : map f xs (++) [] l = l (++) (x:xs) l = x : (xs ++ l) Now let's see what happens with (map f x) ++ y doing case analysis and simplification with the above equations: (map f []) ++ y = [] ++ y = y (map f (x:xs)) ++ y = (f x : map f xs) ++ y = f x : (map f xs ++ y) So: (map f []) ++ y = y (map f (x : xs)) ++ y = f x : (map f xs ++ y) Now consider trivial definition for mapapp: mapapp f x y = (map f x) ++ y. Substituting this backwards into the above equations, we get: mapapp f [] y = y mapapp f (x : xs) y = f x : (mapapp f x xs) which is exactly the definition you've listed. Of course, a Haskell implementation is not *required* to do such transformations, but unless you really observe the difference in performance, it's more or less safe to assume there would be no intermediate list creation/destruction. -- S. Y. A(R). A. From artem at AA5779.spb.edu Tue Aug 18 09:12:37 2009 From: artem at AA5779.spb.edu (Artem V. Andreev) Date: Tue Aug 18 08:52:51 2009 Subject: [Haskell-cafe] Library function for map+append In-Reply-To: <2f83750a0908180458t13c89036w3375c9f7d3781c71@mail.gmail.com> (Clemens Fruhwirth's message of "Tue\, 18 Aug 2009 13\:58\:31 +0200") References: <4A8A877E.9030805@fit.vutbr.cz> <2f83750a0908180458t13c89036w3375c9f7d3781c71@mail.gmail.com> Message-ID: <874os5xo3e.fsf@artemsmp.iling.nw.ru> Clemens Fruhwirth writes: > 2009/8/18 Dusan Kolar : >> Hello all, >> >> ?During a small project I'm trying to develop a small application. It >> becomes quite often that I need a function mapapp: >> >> mapapp _ [] ap = ap >> mapapp f (a:as) ap = f a : map f as ap >> >> ?I tried hoogle to find such a function with no success. Is there any >> function/functions built-in "standard" libraries that could easily satisfy >> the functionality with the same or even better (?) efficiency? > > Can't think of something like that either but at least we can make it > shorter and less readable ;) > > mapapp f xs tail = foldr ((:) . f) tail xs > >> ?Of course, >> (map f list) ++ append >> ?would do the same as >> >> mapapp f list append >> >> ?but with less efficiency. Or am I wrong? > > Yes, that is less efficient because ++ has to create N new cons cells > if "list" has length N. No, it does not *have to*. > Fruhwirth Clemens http://clemens.endorphin.org > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -- S. Y. A(R). A. From colin at colina.demon.co.uk Tue Aug 18 09:17:22 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Tue Aug 18 08:57:32 2009 Subject: [Haskell-cafe] Can't install Haskell Platform on 64-bit Linux In-Reply-To: (Magnus Therning's message of "Tue\, 18 Aug 2009 11\:27\:21 +0100") References: Message-ID: >>>>> "Magnus" == Magnus Therning writes: Magnus> Ouch, there only seems to be a version of 6.10.3 in Fedora Magnus> 11, if I read this correctly: Magnus> https://admin.fedoraproject.org/pkgdb/packages/name/ghc Magnus> (I'm not a Fedora user so I might be completely confused Magnus> here :-) Magnus> It looks like the pre-built ghc can't find the installed Magnus> libgmp. I don't think it's a problem with libgmp. I think that's just a cautionary message, based on experience that this is a common error. -- Colin Adams Preston Lancashire From ekirpichov at gmail.com Tue Aug 18 09:30:54 2009 From: ekirpichov at gmail.com (Eugene Kirpichov) Date: Tue Aug 18 09:11:01 2009 Subject: [Haskell-cafe] Library function for map+append In-Reply-To: <874os5xo3e.fsf@artemsmp.iling.nw.ru> References: <4A8A877E.9030805@fit.vutbr.cz> <2f83750a0908180458t13c89036w3375c9f7d3781c71@mail.gmail.com> <874os5xo3e.fsf@artemsmp.iling.nw.ru> Message-ID: <5e0214850908180630j7d2843b4m9f43fe37bb0db0f9@mail.gmail.com> module Main where mymap f xs = m xs where m [] = [] m (x:xs) = f x:m xs mymapp1 f xs ys = m xs where m [] = ys m (x:xs) = f x:m xs mymapp2 f [] ys = ys mymapp2 f (x:xs) ys = f x:mymapp2 f xs ys mapp1 f xs ys = (f`map`xs) ++ ys mapp2 f xs ys = (f`mymap`xs) ++ ys mapp3 f xs ys = mymapp1 f xs ys mapp4 f xs ys = mymapp2 f xs ys mapp = mapp1 main = putStrLn . show . length $ mapp (+1) [1..100000000] [1,2,3] mapp1: 3.764s mapp2: 5.753s mapp3: 4.302s mapp4: 4.767s So, the fastest way is the simplest one. 18 ??????? 2009 ?. 17:12 ???????????? Artem V. Andreev (artem@aa5779.spb.edu) ???????: > Clemens Fruhwirth writes: > >> 2009/8/18 Dusan Kolar : >>> Hello all, >>> >>> ?During a small project I'm trying to develop a small application. It >>> becomes quite often that I need a function mapapp: >>> >>> mapapp _ [] ap = ap >>> mapapp f (a:as) ap = f a : map f as ap >>> >>> ?I tried hoogle to find such a function with no success. Is there any >>> function/functions built-in "standard" libraries that could easily satisfy >>> the functionality with the same or even better (?) efficiency? >> >> Can't think of something like that either but at least we can make it >> shorter and less readable ;) >> >> mapapp f xs tail = foldr ((:) . f) tail xs >> >>> ?Of course, >>> (map f list) ++ append >>> ?would do the same as >>> >>> mapapp f list append >>> >>> ?but with less efficiency. Or am I wrong? >> >> Yes, that is less efficient because ++ has to create N new cons cells >> if "list" has length N. > No, it does not *have to*. > > > >> Fruhwirth Clemens http://clemens.endorphin.org >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> >> > > -- > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?S. Y. A(R). A. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Eugene Kirpichov Web IR developer, market.yandex.ru From es at ertes.de Tue Aug 18 09:47:55 2009 From: es at ertes.de (Ertugrul Soeylemez) Date: Tue Aug 18 09:28:26 2009 Subject: [Haskell-cafe] Re: simulation in the haskell way References: <200908182042.19093.wsysdu@gmail.com> Message-ID: <20090818154755.759b7c15@tritium.xx> Eric Wong wrote: > I'm relatively new to haskell and due to my strong imperative > background, it's really a pain to learn haskell. But I'm really > indulged in it. :) > > Now I think I understand the basics of Haskell very well, such as the > type system and monad. And for those data-flow kind of applications, I > can easily structure the problem in a functional way and sketch out an > intuitive picture of the computation. But for simulation kind-of > problems, in which I think OO really fits the best, what's the haskell > way to structure such problems? I once thought maybe I can use the > State monad to simulate objects. But it's really hard for me to > implement, because I think State monad is used to simulate a global > shared state, is it right? > > Then what's the best way to simulate private states or just instead > how to solve simulation problems such as a physical engine using the > haskell way? A state monad is used to encode a stateful computation. Whether its state is global or not really only depends on how long the computation lives. Here is how you can use one to maintain a list of objects: computation :: State [Object] Result computation = do objs0 <- get (result, objs1) <- doSomethingWith objs0 put objs1 return result This is really just a convenient encoding of: computation :: [Object] -> (Result, [Object]) Whether that [Object] state is global really only depends on where you use evalState, execState or runState and how long the computation takes. I often do something like this, which you can regard as global 'state' (or rather a global environment): type AppIO = ReaderT AppConfig IO myApp :: AppIO () myApp = ... main :: IO () main = getAppConfig >>= evalStateT myApp Greets, Ertugrul. -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://blog.ertes.de/ From es at ertes.de Tue Aug 18 09:49:50 2009 From: es at ertes.de (Ertugrul Soeylemez) Date: Tue Aug 18 09:35:11 2009 Subject: [Haskell-cafe] Re: simulation in the haskell way References: <200908182042.19093.wsysdu@gmail.com> <20090818154755.759b7c15@tritium.xx> Message-ID: <20090818154950.79260d73@tritium.xx> Ertugrul Soeylemez wrote: > computation :: State [Object] Result > computation = do > objs0 <- get > (result, objs1) <- doSomethingWith objs0 > put objs1 > return result Misindented, sorry. Again: computation :: State [Object] Result computation = do objs0 <- get (result, objs1) <- doSomethingWith objs0 put objs1 return result Greets, Ertugrul. -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://blog.ertes.de/ From zefirov at prosoft.ru Tue Aug 18 09:55:19 2009 From: zefirov at prosoft.ru (Zefirov Sergey) Date: Tue Aug 18 09:35:28 2009 Subject: [Haskell-cafe] Looking up functions inQ monad (Template Haskell). Message-ID: <431353321B0D214CBD767E22931DD477E523175230@msk-mail-2.prosoft.ru> Why isn't possible to lookup and call user-defined functions while performing Template Haskell actions? Just like the way Template Haskell looks up and calls 'f' in $(f ...). 'f' gets looked up and called. And user of Q monad cannot do that. A colleague of mine, a Lisp user, says that almost everything is in place. It's just not enabled. Is there any problem we do not understand? From bugfact at gmail.com Tue Aug 18 09:55:53 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Tue Aug 18 09:36:08 2009 Subject: [Haskell-cafe] simulation in the haskell way In-Reply-To: <200908182042.19093.wsysdu@gmail.com> References: <200908182042.19093.wsysdu@gmail.com> Message-ID: You need to look into functional reactive programming, but be warned, this is active research :-) Two libraries I know of in which you can currently make working simulations are Yampa and Elerea. But the former doesn't scale really well, and the latter might not really be functional (I think it's not referentially transparent) Other libraries such as Reactive and Grapefruit are very promising, but I don't know their current status. Good luck. For me (I'm also an experienced imperative programmer in the simulation field), Haskell is very addictive, but also insanely frustrating because I never have the feeling I know the language well enough and I don't see the big picture yet. So I can't yet achieve in Haskell what I can in other languages, but purity and laziness are drugs, so you're doomed :-) On Tue, Aug 18, 2009 at 2:42 PM, Eric Wong wrote: > Hello, Haskellers! > > I'm relatively new to haskell and due to my strong imperative background, > it's > really a pain to learn haskell. But I'm really indulged in it. :) > > Now I think I understand the basics of Haskell very well, such as the type > system and monad. And for those data-flow kind of applications, I can > easily > structure the problem in a functional way and sketch out an intuitive > picture > of the computation. But for simulation kind-of problems, in which I think > OO > really fits the best, what's the haskell way to structure such problems? > I once thought maybe I can use the State monad to simulate objects. But > it's > really hard for me to implement, because I think State monad is used to > simulate a global shared state, is it right? > > Then what's the best way to simulate private states or just instead how to > solve simulation problems such as a physical engine using the haskell way? > > Best regards. > Eric > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090818/7b21d3e8/attachment-0001.html From jefferson.r.heard at gmail.com Tue Aug 18 09:57:49 2009 From: jefferson.r.heard at gmail.com (Jeff Heard) Date: Tue Aug 18 09:38:14 2009 Subject: [Haskell-cafe] Re: ANN: OpenCLRaw 1.0.1000 In-Reply-To: <4165d3a70908171649o374aa995y26cfb570219cc351@mail.gmail.com> References: <4165d3a70908171649o374aa995y26cfb570219cc351@mail.gmail.com> Message-ID: <4165d3a70908180657r2eab42w3de91851f4529857@mail.gmail.com> There was a missing include in the cabal file. fixed... On Mon, Aug 17, 2009 at 7:49 PM, Jeff Heard wrote: > All, I've released a raw binding to the OpenCL platform on Hackage. > The main differences between it and the C bindings are that constants > have been replaced by newtypes for type safety reasons, void-essential > functions that return a token errorcode return a Maybe ErrorCode, and > functions that return a handle/ptr and return an error-code through an > out-parameter return instead an Either ErrorCode a. ?Modules are > grouped roughly by the section in which they appear in the standard. > > I'm working on an OpenCL binding that is a little more "cooked" as > well as a high-level OpenCL binding. > > OpenCL is a platform for single-host heterogenous, data-parallel > computing that follows roughly the OpenGL and OpenAL conventions for > how the library is architected. ?It will be available by default in > the next version of Apple's OS-X, and there are drivers for AMD > Opteron/Athlons and nVidia CUDA-based graphics cards. > > The basic procedure behind running an OpenCL program is: > > 1. get a list of platforms > 2. choose a device on the platform that fits ?your needs > 3. create a context for the platform and the device > 4. compile a program and "kernels" written in OpenCL/C > 5. create memory buffer objects. > 6. execute kernels on the memory buffer objects. > 7. rinse hands, repeat. > > Obviously this is not very functional, but we can't get there without > a raw binding. ? Data Parallel computing is somewhere Haskell is > excelling; hopefully this will generate some interest in creating a > DPH binding to OpenCL's C99-based language, OpenCL/C. > From colin at colina.demon.co.uk Tue Aug 18 10:02:25 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Tue Aug 18 09:43:04 2009 Subject: [Haskell-cafe] Text.Html introduction Message-ID: http://www.haskell.org/ghc/docs/latest/html/libraries/xhtml/Text-XHtml.html says: "Based on the original Text.Html library by Andy Gill. See http://www.cse.ogi.edu/~andy/html/intro.htm for an introduction to that library. " But that link gives a not-found page. Anyone know where it is know? -- Colin Adams Preston Lancashire From bulat.ziganshin at gmail.com Tue Aug 18 10:03:53 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Aug 18 09:44:10 2009 Subject: [Haskell-cafe] Looking up functions inQ monad (Template Haskell). In-Reply-To: <431353321B0D214CBD767E22931DD477E523175230@msk-mail-2.prosoft.ru> References: <431353321B0D214CBD767E22931DD477E523175230@msk-mail-2.prosoft.ru> Message-ID: <1299952350.20090818180353@gmail.com> Hello Zefirov, Tuesday, August 18, 2009, 5:55:19 PM, you wrote: > Why isn't possible to lookup and call user-defined functions while > performing Template Haskell actions? if i understood correctly what you mean - it's possible. the function just need to be defined in module imported by current one. defining and using function in the same module isn't supported since it may be tricky for language with global module analysis. Lisp just executes lists as it reads them, so it doesn't have such problem -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From colin at colina.demon.co.uk Tue Aug 18 10:14:25 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Tue Aug 18 09:54:36 2009 Subject: [Haskell-cafe] Planning for a website Message-ID: I'm intending to replace my current website - which uses Drupal, with a hand-written-in-Haskell version this autumn, for a number of reasons (a principal one is the lack of an upgrade path in Drupal). So I'm currently looking into the libraries available to see how much I'll have to write myself. One problem will be to get GHC ported to DragonFly BSD, but that can wait until I have a test version of the site working on Linux. The next major challange is to implement something like Drupal's Image and Image Gallery modules. That doesn't seem to be a great problem, as the exif and GD libraries seem to cover everything I'll need. So my major decision is what framework and html-generating libraries to use. There is such a wide choice on the Haskell Wiki. But I guess some are more maintained than others. For instance, WASH attracts me, with it's guarantee of valid generated pages, but it isn't clear to me that it's actively maintained (last date I can see on the web pages is 2006). HappStack is obviously currently maintained, and since it seems to have a blogging module in development, that is attractive. HASP is maintained too, I think. Has anyone written a comparison of the various libraries, or gone through the same decision process recently? -- Colin Adams Preston Lancashire From johan.tibell at gmail.com Tue Aug 18 10:18:06 2009 From: johan.tibell at gmail.com (Johan Tibell) Date: Tue Aug 18 09:58:36 2009 Subject: [Haskell-cafe] Text.Html introduction In-Reply-To: References: Message-ID: <90889fe70908180718i4d701ee3qa0fb554d804bb0cc@mail.gmail.com> On Tue, Aug 18, 2009 at 4:02 PM, Colin Paul Adams wrote: > http://www.haskell.org/ghc/docs/latest/html/libraries/xhtml/Text-XHtml.html > says: > > "Based on the original Text.Html library by Andy Gill. See > http://www.cse.ogi.edu/~andy/html/intro.htm for an introduction to > that library. " > > But that link gives a not-found page. > > Anyone know where it is know? I was looking for this page this morning and couldn't find it. Google does have it in its cache either. -- Johan From jake.mcarthur at gmail.com Tue Aug 18 10:52:15 2009 From: jake.mcarthur at gmail.com (Jake McArthur) Date: Tue Aug 18 10:32:23 2009 Subject: [Haskell-cafe] Planning for a website In-Reply-To: References: Message-ID: <4A8AC01F.1080205@gmail.com> Colin Paul Adams wrote: > One problem will be to get GHC ported to DragonFly BSD, but that can > wait until I have a test version of the site working on Linux. I would love to see this. It's the biggest thing blocking me from trying Dragonfly more seriously. > WASH attracts me, with it's guarantee of valid generated pages, > but it isn't clear to me that it's actively maintained (last date I > can see on the web pages is 2006). You should look into HSP. It also provides those guarantees, is maintained, and provides a nice template-style syntax which you can use inline with your Haskell code. Also check out the Formlets library. > HappStack is obviously currently maintained, and since it seems to > have a blogging module in development, that is attractive. I recommend this. - Jake From jake.mcarthur at gmail.com Tue Aug 18 10:56:12 2009 From: jake.mcarthur at gmail.com (Jake McArthur) Date: Tue Aug 18 10:36:24 2009 Subject: [Haskell-cafe] Planning for a website In-Reply-To: References: Message-ID: <4A8AC10C.2070701@gmail.com> I forgot to also mention this somewhat recent announcement for a pedantically type safe HTML library: http://www.haskell.org/pipermail/haskell-cafe/2009-August/064907.html - Jake From colin at colina.demon.co.uk Tue Aug 18 10:56:29 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Tue Aug 18 10:36:52 2009 Subject: [Haskell-cafe] Planning for a website In-Reply-To: <4A8AC01F.1080205@gmail.com> (Jake McArthur's message of "Tue\, 18 Aug 2009 09\:52\:15 -0500") References: <4A8AC01F.1080205@gmail.com> Message-ID: >>>>> "Jake" == Jake McArthur writes: Jake> Colin Paul Adams wrote: >> One problem will be to get GHC ported to DragonFly BSD, but >> that can wait until I have a test version of the site working >> on Linux. Jake> I would love to see this. It's the biggest thing blocking me Jake> from trying Dragonfly more seriously. Well it will happen, as I have to use DragonFly, as my website is all about dragonflies :-) Someone has already got it working sufficiently to compile xmonad, so it should just be a matter of digging around the low-level issues. Jake> You should look into HSP. It also provides those guarantees, Jake> is maintained, and provides a nice template-style syntax Jake> which you can use inline with your Haskell code. Jake> Also check out the Formlets library. >> HappStack is obviously currently maintained, and since it seems >> to have a blogging module in development, that is attractive. Jake> I recommend this. Thanks. -- Colin Adams Preston Lancashire From leather at cs.uu.nl Tue Aug 18 11:49:21 2009 From: leather at cs.uu.nl (Sean Leather) Date: Tue Aug 18 11:29:47 2009 Subject: [Haskell-cafe] Library function for map+append In-Reply-To: <5e0214850908180630j7d2843b4m9f43fe37bb0db0f9@mail.gmail.com> References: <4A8A877E.9030805@fit.vutbr.cz> <2f83750a0908180458t13c89036w3375c9f7d3781c71@mail.gmail.com> <874os5xo3e.fsf@artemsmp.iling.nw.ru> <5e0214850908180630j7d2843b4m9f43fe37bb0db0f9@mail.gmail.com> Message-ID: <3c6288ab0908180849q75facbdm84a2ad69b663ac38@mail.gmail.com> > >>> During a small project I'm trying to develop a small application. It > >>> becomes quite often that I need a function mapapp: > >>> > >>> mapapp _ [] ap = ap > >>> mapapp f (a:as) ap = f a : map f as ap > > >> Of course, > >>> (map f list) ++ append > >>> would do the same as > >>> > >>> mapapp f list append > >>> > >>> but with less efficiency. Or am I wrong? > I timed each of the following five operations with ... > ghc -O2 --make MapApp.hs > time ./MapApp ... and they produced no statistically significant differences. Each ran for about 3.8 seconds. Perhaps you can try it to convince yourself? Sean -- module Main where mapapp0 :: (a -> b) -> [b] -> [a] -> [b] mapapp0 f tail xs = map f xs ++ tail mapapp1 :: (a -> b) -> [b] -> [a] -> [b] mapapp1 _ tail [] = tail mapapp1 f tail (a:as) = f a : mapapp1 f tail as mapapp2 :: (a -> b) -> [b] -> [a] -> [b] mapapp2 f tail = go where go [] = tail go (x:xs) = f x : go xs mapapp3 :: (a -> b) -> [b] -> [a] -> [b] mapapp3 f tail = foldr ((:) . f) tail main = do writeFile "/dev/null" $ show $ [1 .. 10001000] -- writeFile "/dev/null" $ show $ mapapp0 (+3) [1 .. 10000000] [1 .. 1000] -- writeFile "/dev/null" $ show $ mapapp1 (+3) [1 .. 10000000] [1 .. 1000] -- writeFile "/dev/null" $ show $ mapapp2 (+3) [1 .. 10000000] [1 .. 1000] -- writeFile "/dev/null" $ show $ mapapp3 (+3) [1 .. 10000000] [1 .. 1000] return () -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090818/c6bf24f0/attachment.html From bulat.ziganshin at gmail.com Tue Aug 18 12:23:07 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Aug 18 12:03:26 2009 Subject: [Haskell-cafe] Library function for map+append In-Reply-To: <3c6288ab0908180849q75facbdm84a2ad69b663ac38@mail.gmail.com> References: <4A8A877E.9030805@fit.vutbr.cz> <2f83750a0908180458t13c89036w3375c9f7d3781c71@mail.gmail.com> <874os5xo3e.fsf@artemsmp.iling.nw.ru> <5e0214850908180630j7d2843b4m9f43fe37bb0db0f9@mail.gmail.com> <3c6288ab0908180849q75facbdm84a2ad69b663ac38@mail.gmail.com> Message-ID: <1666982942.20090818202307@gmail.com> Hello Sean, Tuesday, August 18, 2009, 7:49:21 PM, you wrote: > ? writeFile "/dev/null" $ show $ [1 .. 10001000] it may be dominated by show+writeFile. i suggest you to compute, say, sum of all elements instead -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From leather at cs.uu.nl Tue Aug 18 12:38:26 2009 From: leather at cs.uu.nl (Sean Leather) Date: Tue Aug 18 12:18:52 2009 Subject: [Haskell-cafe] Library function for map+append In-Reply-To: <1666982942.20090818202307@gmail.com> References: <4A8A877E.9030805@fit.vutbr.cz> <2f83750a0908180458t13c89036w3375c9f7d3781c71@mail.gmail.com> <874os5xo3e.fsf@artemsmp.iling.nw.ru> <5e0214850908180630j7d2843b4m9f43fe37bb0db0f9@mail.gmail.com> <3c6288ab0908180849q75facbdm84a2ad69b663ac38@mail.gmail.com> <1666982942.20090818202307@gmail.com> Message-ID: <3c6288ab0908180938v652ea048o6d4976344283a399@mail.gmail.com> On Tue, Aug 18, 2009 at 18:23, Bulat Ziganshin wrote: > Hello Sean, > > Tuesday, August 18, 2009, 7:49:21 PM, you wrote: > > > writeFile "/dev/null" $ show $ [1 .. 10001000] > > it may be dominated by show+writeFile. i suggest you to compute, say, > sum of all elements instead > Thank you, Bulat. The results now show some variation. Sean -- writeFile "/dev/null" $ show $ sum $ [1 .. 10001000] 0m1.652s 0m1.634s 0m1.658s writeFile "/dev/null" $ show $ sum $ mapapp0 (+3) [1 .. 10000000] [1 .. 1000] 0m1.601s 0m1.613s 0m1.615s writeFile "/dev/null" $ show $ sum $ mapapp1 (+3) [1 .. 10000000] [1 .. 1000] 0m1.647s 0m1.656s 0m1.654s writeFile "/dev/null" $ show $ sum $ mapapp2 (+3) [1 .. 10000000] [1 .. 1000] 0m1.640s 0m1.645s 0m1.664s writeFile "/dev/null" $ show $ sum $ mapapp3 (+3) [1 .. 10000000] [1 .. 1000] 0m1.541s 0m1.531s 0m1.561s -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090818/e5e7deaa/attachment.html From lrpalmer at gmail.com Tue Aug 18 12:51:44 2009 From: lrpalmer at gmail.com (Luke Palmer) Date: Tue Aug 18 12:31:50 2009 Subject: [Haskell-cafe] Library function for map+append In-Reply-To: <4A8A9331.7030909@fit.vutbr.cz> References: <4A8A877E.9030805@fit.vutbr.cz> <13410248282.20090818152354@gmail.com> <4A8A9331.7030909@fit.vutbr.cz> Message-ID: <7ca3f0160908180951o1e0fe188q7340f308539c9c6a@mail.gmail.com> 2009/8/18 Dusan Kolar : > Dlists maybe good it all the app is written using them. Probably not good > idea to switch to them in the middle of project... I have a different criterion for DLists. I think they are best to use in small scopes (I think the same of monads), as opposed to interfacing between different parts of a project. A DList is well-suited when you are *outputting* a list using appends; i.e. just concatenating stuff together, but not looking at the heads or iterating over the lists. The DList Quicksort is a perfect example. It also makes a good monoid for Writer. toList it after you're done generating; this is an efficient operation. Luke From mauricio.antunes at gmail.com Tue Aug 18 13:53:26 2009 From: mauricio.antunes at gmail.com (=?ISO-8859-1?Q?Maur=ED=ADcio_CA?=) Date: Tue Aug 18 13:34:00 2009 Subject: [Haskell-cafe] Re: simulation in the haskell way In-Reply-To: <200908182042.19093.wsysdu@gmail.com> References: <200908182042.19093.wsysdu@gmail.com> Message-ID: > ...) But for simulation kind-of problems, in which I think OO > really fits the best, what's the haskell way to structure such problems? > I once thought maybe I can use the State monad to simulate objects. But it's > really hard for me to implement, because I think State monad is used to > simulate a global shared state, is it right? > > Then what's the best way to simulate private states or just instead how to > solve simulation problems such as a physical engine using the haskell way? A physical engine can be simulated using pure code, with a function from timestep to state. (Of course, that doesn't hold when you want to deal with user interaction.) I think there is no general answer to your question. My sugestion is to describe an example you would like to work with. Maur?cio From simon at joyful.com Tue Aug 18 14:02:15 2009 From: simon at joyful.com (Simon Michael) Date: Tue Aug 18 13:42:50 2009 Subject: [Haskell-cafe] Re: Planning for a website In-Reply-To: References: Message-ID: I can give a +1 vote for the Hack api and related libs. (Jinjing Wang is a one-man army.) Below hack you'll run happstack or another web-serving lib. Above hack you might run some combination of loli, maid, the hack middleware modules, hsp. The advantage is that changing the low-level server in future is a matter of changing one or two lines; and the upper-level utilities seem more usable to me than current happstack's. From explicitcall at googlemail.com Tue Aug 18 14:09:26 2009 From: explicitcall at googlemail.com (Max Desyatov) Date: Tue Aug 18 13:49:26 2009 Subject: [Haskell-cafe] Re: [Haskell-beginners] Start file with associated prog (windows only?) In-Reply-To: <1250618215.3888.21.camel@sol> (Bernhard Lehnert's message of "Tue, 18 Aug 2009 19:56:55 +0200") References: <1250604770.3888.17.camel@sol> <1250618215.3888.21.camel@sol> Message-ID: <87ws51c7u1.fsf@zagan.made.you> Bernhard Lehnert writes: >> Windows has a command "start" which you can use e.g. via System.Process.proc. > > Thank you, Magnus - this is exactly what I was looking for. (By the way, > someone should implement something like this for GNOME and KDE, > too ;-) ) You can do that using MIME, look at /etc/mailcap, it already contains all what you need to run appropriate process for exact MIME-type. As long as it's supported in your distribution. From inforichland at gmail.com Tue Aug 18 14:36:40 2009 From: inforichland at gmail.com (Tim Wawrzynczak) Date: Tue Aug 18 14:16:48 2009 Subject: [Haskell-cafe] Planning for a website In-Reply-To: References: <4A8AC01F.1080205@gmail.com> Message-ID: <4335a3260908181136t44109a4fn44fda763e9b2df16@mail.gmail.com> I'd also give a read to this website: http://jekor.com/article/is-haskell-a-good-choice-for-web-applications Interesting read about a guy who actually used Haskell to create his website from the ground up. On Tue, Aug 18, 2009 at 9:56 AM, Colin Paul Adams wrote: > >>>>> "Jake" == Jake McArthur writes: > > Jake> Colin Paul Adams wrote: > >> One problem will be to get GHC ported to DragonFly BSD, but > >> that can wait until I have a test version of the site working > >> on Linux. > > Jake> I would love to see this. It's the biggest thing blocking me > Jake> from trying Dragonfly more seriously. > > Well it will happen, as I have to use DragonFly, as my website is all > about dragonflies :-) > > Someone has already got it working sufficiently to compile xmonad, so > it should just be a matter of digging around the low-level issues. > > Jake> You should look into HSP. It also provides those guarantees, > Jake> is maintained, and provides a nice template-style syntax > Jake> which you can use inline with your Haskell code. > > Jake> Also check out the Formlets library. > > >> HappStack is obviously currently maintained, and since it seems > >> to have a blogging module in development, that is attractive. > > Jake> I recommend this. > > Thanks. > -- > Colin Adams > Preston Lancashire > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090818/ea6ac220/attachment.html From jvranish at gmail.com Tue Aug 18 15:19:32 2009 From: jvranish at gmail.com (Job Vranish) Date: Tue Aug 18 14:59:39 2009 Subject: [Haskell-cafe] Keeping an indexed collection of values? Message-ID: I've been in a situation a lot lately where I need to keep a collection of values, and keep track of them by a persistent index. IO and ST refs can do this, but for various reasons I can't/don't want to use them. My first hacked up attempt is as follows: data IndexedCollection a = IndexedCollection { nextKey :: Int, availableKeys :: [Int], items :: (IntMap Int a) } deriving (Show) emptyIndexedCollection :: IndexedCollection a emptyIndexedCollection = IndexedCollection 0 [] empty addItem :: a -> IndexedCollection a -> (Int, IndexedCollection a) addItem a (IndexedCollection nextKey' [] t) = (nextKey', IndexedCollection (nextKey' + 1) [] (insert nextKey' a t)) addItem a (IndexedCollection nextKey' (k:ks) t) = (k, IndexedCollection nextKey' ks (insert k a t)) removeItem :: Int -> IndexedCollection a -> IndexedCollection a removeItem k (IndexedCollection nextKey' ks t) = IndexedCollection nextKey' (k:ks) (delete k t) lookupItem :: Int -> IndexedCollection a -> Maybe a lookupItem k (IndexedCollection _ _ t) = lookup k t Basically: when you add an item, use the first index in availableKeys (if there is one), otherwise use "nextKey" for the index, and then increment it for the next item. When and Item is removed, add it's index to availableKeys This keeps the code for keeping track of/generating indexes hidden away from the rest of the program which is nice, and it remains fairly efficient. Items will be added and removed on very regular basis. Often enough that I'm slightly concerned about overflow of nextKey for very long run times, and hence the availableKeys list. Does anyone know of a better/already existent data structure for handling this problem? Or perhaps a better way of keeping a "key pool" than my availableKeys solution? - Job -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090818/50d8dd8e/attachment.html From explicitcall at googlemail.com Tue Aug 18 15:22:54 2009 From: explicitcall at googlemail.com (Max Desyatov) Date: Tue Aug 18 15:02:54 2009 Subject: [Haskell-cafe] Re: Planning for a website In-Reply-To: (Simon Michael's message of "Tue, 18 Aug 2009 11:02:15 -0700") References: Message-ID: <87skfpc4fl.fsf@zagan.made.you> Simon Michael writes: > I can give a +1 vote for the Hack api and related libs. (Jinjing Wang > is a one-man army.) Below hack you'll run happstack or another > web-serving lib. Above hack you might run some combination of loli, > maid, the hack middleware modules, hsp. > > The advantage is that changing the low-level server in future is a > matter of changing one or two lines; and the upper-level utilities > seem more usable to me than current happstack's. The problem is that `hack` isn't documented at all and that prevents it from being in wide use. At least, when I started my web app, I preferred happstack, as low-level and documented API is better than high-level API without a little bit of documentation, examples and tutorials. From marcin.kosiba at gmail.com Tue Aug 18 16:24:02 2009 From: marcin.kosiba at gmail.com (Marcin Kosiba) Date: Tue Aug 18 16:04:19 2009 Subject: [Haskell-cafe] Re: simulation in the haskell way In-Reply-To: References: <200908182042.19093.wsysdu@gmail.com> Message-ID: <200908182224.06321.marcin.kosiba@gmail.com> On Tuesday 18 August 2009, Maur??cio CA wrote: > > ...) But for simulation kind-of problems, in which I think OO > > really fits the best, what's the haskell way to structure such problems? > > I once thought maybe I can use the State monad to simulate objects. But > > it's really hard for me to implement, because I think State monad is used > > to simulate a global shared state, is it right? > > > > Then what's the best way to simulate private states or just instead how > > to solve simulation problems such as a physical engine using the haskell > > way? > > A physical engine can be simulated using pure code, with a > function from timestep to state. (Of course, that doesn't hold > when you want to deal with user interaction.) I think there is no > general answer to your question. My sugestion is to describe an > example you would like to work with. Hi, I did a medium sized mobility models simulator this way. The simulation is represented as an infinite list of states, where the next state is created by applying a state transformation ("next") function to the previous state. This has the advantage that you can calculate values based on more than one state. The downside is that if you need to look back 100 stesp, you need to remember 100 states (though if enough of it is unchanged and shared then it's not really that much of a problem). As far as the details go -- different parts of the simulator are executed in different monads. "god-mode" code, like the "next" function has the type nextStep :: World -> World but the mobility model implementation (which tells a node how to move) is a stateful computation run by nextStep: mobilityModel :: StateT NodeState (Reader World) () But as Maur??cio said -- please describe what you want to achieve. At least what kind of simulation you'd like to write. -- Thanks! Marcin Kosiba -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part. Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090818/f9aa4b00/attachment.bin From uzytkownik2 at gmail.com Tue Aug 18 16:29:42 2009 From: uzytkownik2 at gmail.com (Maciej Piechotka) Date: Tue Aug 18 16:10:00 2009 Subject: [Haskell-cafe] Installing documentation with cabal Message-ID: <1250627382.27060.68.camel@notebook> Is it possible to automatically (or non-automatically) install documentation when installing package with cabal-install? Regards -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090818/2c7d2754/attachment.bin From gtener at gmail.com Tue Aug 18 16:37:18 2009 From: gtener at gmail.com (=?UTF-8?Q?Krzysztof_Skrz=C4=99tnicki?=) Date: Tue Aug 18 16:17:25 2009 Subject: [Haskell-cafe] Installing documentation with cabal In-Reply-To: <1250627382.27060.68.camel@notebook> References: <1250627382.27060.68.camel@notebook> Message-ID: <220e47b40908181337p555d70afm6c8a0bfb429ba846@mail.gmail.com> It is. From command line: cabal install package --enable-documentation or add line "documentation: True" to .cabal/config or equivalent. Best regards Krzysztof Skrz?tnicki On Tue, Aug 18, 2009 at 22:29, Maciej Piechotka wrote: > Is it possible to automatically (or non-automatically) install > documentation when installing package with cabal-install? > > Regards > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090818/c4c0d8ce/attachment.html From uzytkownik2 at gmail.com Tue Aug 18 16:52:54 2009 From: uzytkownik2 at gmail.com (Maciej Piechotka) Date: Tue Aug 18 16:33:04 2009 Subject: [Haskell-cafe] Installing documentation with cabal In-Reply-To: <220e47b40908181337p555d70afm6c8a0bfb429ba846@mail.gmail.com> References: <1250627382.27060.68.camel@notebook> <220e47b40908181337p555d70afm6c8a0bfb429ba846@mail.gmail.com> Message-ID: <1250628774.27060.69.camel@notebook> On Tue, 2009-08-18 at 22:37 +0200, Krzysztof Skrz?tnicki wrote: > It is. From command line: > > cabal install package --enable-documentation > > or add line > "documentation: True" > to .cabal/config or equivalent. > > Best regards > > Krzysztof Skrz?tnicki > Thanks a lot. Regards -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090818/87c7b5f0/attachment.bin From ryani.spam at gmail.com Tue Aug 18 16:56:19 2009 From: ryani.spam at gmail.com (Ryan Ingram) Date: Tue Aug 18 16:36:25 2009 Subject: [Haskell-cafe] Type family signatures In-Reply-To: <4A8902D5.50106@cs.ru.nl> References: <4A857D7F.7040000@cs.ru.nl> <49a77b7a0908140832h7033b368nabc73f513de070d3@mail.gmail.com> <4A85B514.4050306@imageworks.com> <2f9b2d30908141349v581d05f9lfb6fa98aa4fe2a4@mail.gmail.com> <4A8902D5.50106@cs.ru.nl> Message-ID: <2f9b2d30908181356r74295c6es3f2431967de34409@mail.gmail.com> On Mon, Aug 17, 2009 at 12:12 AM, Thomas van Noort wrote: > Somehow I didn't receive David's mail, but his explanation makes a lot of > sense. I'm still wondering how this results in a type error involving rigid > type variables. "rigid" type means the type has been specified by the programmer somehow. Desugaring your code a bit, we get: GADT :: forall a b. (b ~ Fam a) => a -> b -> GADT b Notice that this is an existential type that partially hides "a"; all we know about "a" after unwrapping this type is that (Fam a ~ b). unwrap :: forall a b. (b ~ Fam a) => GADT b -> (a,b) unwrap (GADT x y) = (x,y) So, the type signature of unwrap fixes "a" and "b" to be supplied by the caller. Then the pattern match on GADT needs a type variable for the existential, so a new "a1" is invented. These are rigid because they cannot be further refined by the typechecker; the typechecker cannot unify them with other types, like "a1 ~ Int", or "a1 ~ a". An example of a non-rigid variable occurs type-checking this expression: foo x = x + (1 :: Int) During type-checking/inference, there is a point where the type environment is: (+) :: forall a. Num a => a -> a -> a b :: *, non-rigid x :: b c :: *, non-rigid foo :: b -> c Then (+) gets instantiated at Int and forces "b" and "c" to be Int. In your case, during the typechecking of unwrap, we have: unwrap :: forall a b. (b ~ Fam a) => GADT b -> (a,b) a :: *, rigid b :: *, rigid (b ~ Fam a) -- From the pattern match on GADT: a1 :: *, rigid x :: a1 y :: b (b ~ Fam a1) Now the typechecker wants to unify "a" and "a1", and it cannot, because they are rigid. If one of them was still open, we could unify it with the other. The type equalities give us (Fam a ~ Fam a1), but that does not give us (a ~ a1). If Fam was a data type or data family, we would know it is injective and be able to derive (a ~ a1), but it is a type family, so we are stuck. -- ryan From magnus at therning.org Tue Aug 18 16:59:48 2009 From: magnus at therning.org (Magnus Therning) Date: Tue Aug 18 16:39:56 2009 Subject: [Haskell-cafe] Re: [Haskell-beginners] Start file with associated prog (windows only?) In-Reply-To: <87ws51c7u1.fsf@zagan.made.you> References: <1250604770.3888.17.camel@sol> <1250618215.3888.21.camel@sol> <87ws51c7u1.fsf@zagan.made.you> Message-ID: <4A8B1644.7020000@therning.org> Max Desyatov wrote: > Bernhard Lehnert writes: >>> Windows has a command "start" which you can use e.g. via System.Process.proc. >> Thank you, Magnus - this is exactly what I was looking for. (By the way, >> someone should implement something like this for GNOME and KDE, >> too ;-) ) > > You can do that using MIME, look at /etc/mailcap, it already contains > all what you need to run appropriate process for exact MIME-type. As > long as it's supported in your distribution. Is there a command line interface for that? Or maybe a lib that's easy to wrap? If you want to query the Gnome MIME database (which is separate from /etc/mailcap) you can use 'xdg-mime'. /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?org http://therning.org/magnus identi.ca|twitter: magthe -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: OpenPGP digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090818/49763390/signature.bin From kkwweett at yahoo.fr Tue Aug 18 17:00:13 2009 From: kkwweett at yahoo.fr (jean legrand) Date: Tue Aug 18 16:40:20 2009 Subject: [Haskell-cafe] simulation in the haskell way In-Reply-To: <200908182042.19093.wsysdu@gmail.com> Message-ID: <796377.27437.qm@web24506.mail.ird.yahoo.com> > Then what's the best way to simulate private states or just > instead how to > solve simulation problems such as a physical engine using > the haskell way? perhaps Hipmunk ? http://hackage.haskell.org/package/Hipmunk From wsysdu at gmail.com Tue Aug 18 18:40:45 2009 From: wsysdu at gmail.com (Eric Wong) Date: Tue Aug 18 18:23:39 2009 Subject: [Haskell-cafe] Re: simulation in the haskell way In-Reply-To: <200908182224.06321.marcin.kosiba@gmail.com> References: <200908182042.19093.wsysdu@gmail.com> <200908182224.06321.marcin.kosiba@gmail.com> Message-ID: <200908190640.45683.wsysdu@gmail.com> I used to think about a physical engine in a similar way, and I think it can work. But in some simulations that objects have lots of dependencies on others can be tricky. For instance, object o1 depends on o2, if we represent them in pure values, when we update o2, then o1 must be updated with a new o2 value, isn't it? Recently I want to implement the digital circuit simulation in SICP using Haskell as an exercise. In the Scheme version, each Wire is represented as a function with local states. It records the signal on the wire and actions it will take when the signal changes to activate other wires. How to represent the Wire in haskell purely? If I use State Monad (yes, it's pure :) to repsent a wire with local state, the interaction between connected wires is really tricky to implement. any ideas? thanks. Eric From sjoerd at w3future.com Tue Aug 18 18:47:50 2009 From: sjoerd at w3future.com (Sjoerd Visscher) Date: Tue Aug 18 18:28:02 2009 Subject: [Haskell-cafe] Text.Html introduction In-Reply-To: <90889fe70908180718i4d701ee3qa0fb554d804bb0cc@mail.gmail.com> References: <90889fe70908180718i4d701ee3qa0fb554d804bb0cc@mail.gmail.com> Message-ID: <0D00C34C-F68B-4389-ABE9-79DAB681DF74@w3future.com> Here is something: http://cpansearch.perl.org/src/AUTRIJUS/Language-Haskell-0.01/hugs98-Nov2003/fptools/hslibs/text/html/doc/doc.htm (Link found in an old haskell-cafe message) Sjoerd On Aug 18, 2009, at 4:18 PM, Johan Tibell wrote: > On Tue, Aug 18, 2009 at 4:02 PM, Colin Paul > Adams wrote: >> http://www.haskell.org/ghc/docs/latest/html/libraries/xhtml/Text-XHtml.html >> says: >> >> "Based on the original Text.Html library by Andy Gill. See >> http://www.cse.ogi.edu/~andy/html/intro.htm for an introduction to >> that library. " >> >> But that link gives a not-found page. >> >> Anyone know where it is know? > > I was looking for this page this morning and couldn't find it. Google > does have it in its cache either. > > -- Johan > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe -- Sjoerd Visscher sjoerd@w3future.com From bugfact at gmail.com Tue Aug 18 18:57:08 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Tue Aug 18 18:37:15 2009 Subject: [Haskell-cafe] Re: simulation in the haskell way In-Reply-To: <200908190640.45683.wsysdu@gmail.com> References: <200908182042.19093.wsysdu@gmail.com> <200908182224.06321.marcin.kosiba@gmail.com> <200908190640.45683.wsysdu@gmail.com> Message-ID: You could read: http://www.cs.nott.ac.uk/~nhn/FoPAD2007/Talks/nhn-FoPAD2007.pdf http://haskell.cs.yale.edu/yale/papers/haskell-workshop03/yampa-arcade.pdf http://www.cs.nott.ac.uk/~nhn/Talks/HW2002-FRPContinued.pdf http://www.haskell.org/yale/papers/haskellworkshop02/index.html http://www.haskell.org/haskellwiki/Frag Basically, even in an imperative solution, if you have complex dependencies between objects at the same time T, then my experience tells me your into trouble, it's better to make all objects at time T depend on the state of other objects at time T-dT. If you absolutely need to know at time T what the state of another object is at time T, the network of dependencies needs to be rearranged dynamically, and you might get different results (or endless loops if you do it badly) in the case of mutual dependencies. This is what Elerea does. On Wed, Aug 19, 2009 at 12:40 AM, Eric Wong wrote: > I used to think about a physical engine in a similar way, and I think it > can work. But in some simulations that objects have lots of dependencies > on others can be tricky. For instance, object o1 depends on o2, if we > represent them in pure values, when we update o2, then o1 must be > updated with a new o2 value, isn't it? > > Recently I want to implement the digital circuit simulation in SICP using > Haskell as an exercise. In the Scheme version, each Wire is represented > as a function with local states. It records the signal on the wire and > actions it will take when the signal changes to activate other wires. > How to represent the Wire in haskell purely? > > If I use State Monad (yes, it's pure :) to repsent a wire with local state, > the interaction between connected wires is really tricky to implement. > any ideas? > > thanks. > Eric > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090818/3c55b042/attachment.html From es at ertes.de Tue Aug 18 19:29:06 2009 From: es at ertes.de (Ertugrul Soeylemez) Date: Tue Aug 18 19:09:37 2009 Subject: [Haskell-cafe] Re: simulation in the haskell way References: <200908182042.19093.wsysdu@gmail.com> <200908182224.06321.marcin.kosiba@gmail.com> <200908190640.45683.wsysdu@gmail.com> Message-ID: <20090819012906.198e4e0d@tritium.xx> Eric Wong wrote: > I used to think about a physical engine in a similar way, and I think > it can work. But in some simulations that objects have lots of > dependencies on others can be tricky. For instance, object o1 depends > on o2, if we represent them in pure values, when we update o2, then o1 > must be updated with a new o2 value, isn't it? This is something handled best by functional reactive programming. See Peter Verswyvelen's post. It allows you to encode this purely in an excitingly elegant way. > Recently I want to implement the digital circuit simulation in SICP > using Haskell as an exercise. In the Scheme version, each Wire is > represented as a function with local states. It records the signal on > the wire and actions it will take when the signal changes to activate > other wires. How to represent the Wire in haskell purely? > > If I use State Monad (yes, it's pure :) to repsent a wire with local > state, the interaction between connected wires is really tricky to > implement. any ideas? You don't. Either you use a state monad to hold _all_ wires (objects) in, say, a Map, a Set or an Array, or you use a completely different approach (like FRP). In other words, your state monad should represent all wires, not just one, because all wires together make up the state you want to work with. Greets, Ertugrul. -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://blog.ertes.de/ From bugfact at gmail.com Tue Aug 18 19:41:10 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Tue Aug 18 19:21:17 2009 Subject: [Haskell-cafe] Re: simulation in the haskell way In-Reply-To: <20090819012906.198e4e0d@tritium.xx> References: <200908182042.19093.wsysdu@gmail.com> <200908182224.06321.marcin.kosiba@gmail.com> <200908190640.45683.wsysdu@gmail.com> <20090819012906.198e4e0d@tritium.xx> Message-ID: It is interesting to note that recent work on AFRP (arrow-based FRP) - namely "Causal Commutative Arrows" - optimizes a complete circuit of arrows ("interconnected objects" if you prefer to think that way) that all have local state and local feedback loops into one large state and feedback loop, essentially what optimized imperative simulations also do (e.g. thousands of moving particles that are treated as a single state block of position/velocity pairs). Together with stream fusion the researchers working on this were able to generate optimized code that runs hundreds (!!!) times faster than the best GHC could do. Impressive isn't it. Unfortunately it will only work on static networks, not those with dynamic switches in it, but I'm pretty sure that within say 5 years, this will all be settled and it will become exiting times for simulation developers, we will finally be pure, lazy *and* fast; it just needs a little push (since it's now mostly pulling, okay I'll stop the nonsense, couldn't resist the nerd talk ;-) On Wed, Aug 19, 2009 at 1:29 AM, Ertugrul Soeylemez wrote: > Eric Wong wrote: > > > I used to think about a physical engine in a similar way, and I think > > it can work. But in some simulations that objects have lots of > > dependencies on others can be tricky. For instance, object o1 depends > > on o2, if we represent them in pure values, when we update o2, then o1 > > must be updated with a new o2 value, isn't it? > > This is something handled best by functional reactive programming. See > Peter Verswyvelen's post. It allows you to encode this purely in an > excitingly elegant way. > > > > Recently I want to implement the digital circuit simulation in SICP > > using Haskell as an exercise. In the Scheme version, each Wire is > > represented as a function with local states. It records the signal on > > the wire and actions it will take when the signal changes to activate > > other wires. How to represent the Wire in haskell purely? > > > > If I use State Monad (yes, it's pure :) to repsent a wire with local > > state, the interaction between connected wires is really tricky to > > implement. any ideas? > > You don't. Either you use a state monad to hold _all_ wires (objects) > in, say, a Map, a Set or an Array, or you use a completely different > approach (like FRP). In other words, your state monad should represent > all wires, not just one, because all wires together make up the state > you want to work with. > > > Greets, > Ertugrul. > > > -- > nightmare = unsafePerformIO (getWrongWife >>= sex) > http://blog.ertes.de/ > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090818/cf6f412c/attachment.html From wsysdu at gmail.com Tue Aug 18 20:19:39 2009 From: wsysdu at gmail.com (Eric Wong) Date: Tue Aug 18 20:02:35 2009 Subject: [Haskell-cafe] Re: simulation in the haskell way In-Reply-To: References: <200908182042.19093.wsysdu@gmail.com> <20090819012906.198e4e0d@tritium.xx> Message-ID: <200908190819.39990.wsysdu@gmail.com> Thanks for all your post. When I was using C and Python, I used to think of most applications in an simulation way. I think it's right to say that programs are simulations. But now I have to change my mind in Haskell, I have to think in a data-flow way, that is: data in, processing using function composition, data out. Even true simulation should be seen in such a perspective, right? And of course, I have to learn about FRP. Thanks, Eric From jason.dusek at gmail.com Tue Aug 18 21:18:47 2009 From: jason.dusek at gmail.com (Jason Dusek) Date: Tue Aug 18 20:58:51 2009 Subject: [Haskell-cafe] Re: simulation in the haskell way In-Reply-To: <200908190819.39990.wsysdu@gmail.com> References: <200908182042.19093.wsysdu@gmail.com> <20090819012906.198e4e0d@tritium.xx> <200908190819.39990.wsysdu@gmail.com> Message-ID: <42784f260908181818l2ccdf0d1y9a59da0df2efd618@mail.gmail.com> 2009/08/18 Eric Wong : > When I was using C and Python, I used to think of most > applications in an simulation way. By "simulation way", do you mean "object-oriented way"? -- Jason Dusek From dagit at codersbase.com Tue Aug 18 21:20:33 2009 From: dagit at codersbase.com (Jason Dagit) Date: Tue Aug 18 21:00:38 2009 Subject: [Haskell-cafe] Re: simulation in the haskell way In-Reply-To: <200908190819.39990.wsysdu@gmail.com> References: <200908182042.19093.wsysdu@gmail.com> <20090819012906.198e4e0d@tritium.xx> <200908190819.39990.wsysdu@gmail.com> Message-ID: On Tue, Aug 18, 2009 at 5:19 PM, Eric Wong wrote: > Thanks for all your post. > > When I was using C and Python, I used to think of most applications in an > simulation way. ?I think it's right to say that programs are simulations. On a philosophical note, this is a sign of expertise. Humans tend to think of the world, and things in, in the way that they understand things in their area of expertise. If you develop expertise in Haskell (or FP in general) you will like begin to see things in functional ways. Jason From mauricio.antunes at gmail.com Tue Aug 18 21:55:41 2009 From: mauricio.antunes at gmail.com (=?ISO-8859-1?Q?Maur=ED=ADcio_CA?=) Date: Tue Aug 18 21:36:16 2009 Subject: [Haskell-cafe] Re: simulation in the haskell way In-Reply-To: <200908190819.39990.wsysdu@gmail.com> References: <200908182042.19093.wsysdu@gmail.com> <20090819012906.198e4e0d@tritium.xx> <200908190819.39990.wsysdu@gmail.com> Message-ID: > When I was using C and Python, I used to think of most applications in an > simulation way. I think it's right to say that programs are simulations. > But now I have to change my mind in Haskell, I have to think in a data-flow > way, that is: data in, processing using function composition, data out. You have to think there's no in and out, since there's no state and so no before and after. And no flow, since time is just an ilusion of users. In Haskell, a program just "is". Sorry, could not resist the Jedi talk... Hope you like the language. Best, Maur?cio From wsysdu at gmail.com Tue Aug 18 21:56:40 2009 From: wsysdu at gmail.com (Shiyou Wang) Date: Tue Aug 18 21:39:36 2009 Subject: [Haskell-cafe] Re: simulation in the haskell way In-Reply-To: <42784f260908181818l2ccdf0d1y9a59da0df2efd618@mail.gmail.com> References: <200908182042.19093.wsysdu@gmail.com> <200908190819.39990.wsysdu@gmail.com> <42784f260908181818l2ccdf0d1y9a59da0df2efd618@mail.gmail.com> Message-ID: <200908190956.40261.wsysdu@gmail.com> > By "simulation way", do you mean "object-oriented way"? they are similar, but not equal, I think. OO is great for simulation, but simulation does not necessarily use OO. Virtual machine simulates real machines, you can use OO language to do it, but most use C in the real world I think. So, simulation way is more like an imperative way. But it also relates to what do you mean by "simulation". If we are simulating things in the physics world, then it's most likely imperative, and most of the time an OO way. Because the physics world are more natrual in such a perspective. But if we are simulating the way people doing things, it may not necessarily be imperative. For instance Mathematics, It's more natural to simulate in a functional way. From wsysdu at gmail.com Tue Aug 18 22:24:24 2009 From: wsysdu at gmail.com (Eric Wong) Date: Tue Aug 18 22:07:20 2009 Subject: [Haskell-cafe] Re: simulation in the haskell way In-Reply-To: <200908190956.40261.wsysdu@gmail.com> References: <200908182042.19093.wsysdu@gmail.com> <42784f260908181818l2ccdf0d1y9a59da0df2efd618@mail.gmail.com> <200908190956.40261.wsysdu@gmail.com> Message-ID: <200908191024.24273.wsysdu@gmail.com> Sorry for a mistake. "Shiyou Wang" is my identity in a private chinese group. Sorry for the confusing. :-( Eric From k2msmith at gmail.com Tue Aug 18 23:15:49 2009 From: k2msmith at gmail.com (Kevin Smith) Date: Tue Aug 18 22:55:57 2009 Subject: [Haskell-cafe] Control.Parallel on 6.10.4 - Mac OS X version Message-ID: <49dd14e0908182015q10e80597n325658072ea74266@mail.gmail.com> I'm using the Control.Parallel package on ghc version 6.10.4 and I don't seem to be getting any parallel threads or sparks created at all with the "-threaded" compilation option using runtime flags "+RTS -N2". I'm using simple examples from the paper "A Tutorial on Parallel and Concurrent Programming in Haskell" by Jones and Singh. I'm running on an Intel Mac core 2 duo. Does anyone know how I can check if the parallel functionality in ghc is working on my 6.10.4 ghc package installed on this platform ? I installed it from the "supported" runtime pkg for OS X from the ghc website. thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090818/6dd30111/attachment.html From dons at galois.com Tue Aug 18 23:17:18 2009 From: dons at galois.com (Don Stewart) Date: Tue Aug 18 22:59:29 2009 Subject: [Haskell-cafe] Control.Parallel on 6.10.4 - Mac OS X version In-Reply-To: <49dd14e0908182015q10e80597n325658072ea74266@mail.gmail.com> References: <49dd14e0908182015q10e80597n325658072ea74266@mail.gmail.com> Message-ID: <20090819031718.GA1623@whirlpool.galois.com> k2msmith: > I'm using the Control.Parallel package on ghc version 6.10.4 and I don't seem > to be getting any parallel threads or sparks created at all with the > "-threaded" compilation option using runtime flags "+RTS -N2". I'm using > simple examples from the paper "A Tutorial on Parallel and Concurrent > Programming in Haskell" by Jones and Singh. > > I'm running on an Intel Mac core 2 duo. Does anyone know how I can check if > the parallel functionality in ghc is working on my 6.10.4 ghc package installed > on this platform ? I installed it from the "supported" runtime pkg for OS X > from the ghc website. > A simple parallel 'hello world' http://haskell.org/haskellwiki/Haskell_in_5_steps#Write_your_first_parallel_Haskell_program From jmccarty at sent.com Wed Aug 19 00:14:24 2009 From: jmccarty at sent.com (Jason McCarty) Date: Tue Aug 18 23:54:30 2009 Subject: [Haskell-cafe] Observations about foldM Message-ID: <20090819041424.GC1103@quaternion> [This message is literate Haskell] Hi -cafe, I was trying to use Monad.foldM in the State monad recently and ran into some performance issues. They were eventually fixed with seq, but along the way I made some discoveries, which I thought I would share. The Report defines foldM as foldM :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m a foldM f z [] = return z foldM f z (x:xs) = f z x >>= \z' -> foldM f z' xs It turns out that foldM is essentially a right fold. Define f' = \h t -> flip f h >=> t. The operator (>=>) is (reverse) Kleisli composition, defined in Control.Monad as f >=> g = \x -> f x >>= g. Now foldM f z xs = foldr f' return xs z. Proof. On the empty list, foldM f z [] = return z [definition of foldM] = foldr f' return [] z [definition of foldr] Now fix a list xs and inductively assume that foldM f z xs = foldr f' return xs z for all z. Then for any z and x, foldM f z (x:xs) = f z x >>= \z' -> foldM f z' xs [definition of foldM] = f z x >>= \z' -> foldr f' return xs z' [inductive hypothesis] = f z x >>= foldr f' return xs [eta-conversion(*)] = flip f x z >>= foldr f' return xs [definition of flip] = (\z' -> flip f x z' >>= foldr f' return xs) z [beta-reduction] = (flip f x >=> foldr f' return xs) z [definition of >=>] = (f' x (foldr f' return xs)) z [definition of f'] = foldr f' return (x:xs) z [definition of foldr] (*) The eta-conversion preserves strictness as long as return /= _|_, since f >=> g is in WHNF. Interestingly, foldM can also be written as a left fold. To see this, note that it is a theorem that foldr f z xs = foldl f z xs as long as f is associative and z is a unit for f. Since (>=>) is associative with unit return, we have foldr (\h t -> flip f h >=> t) return = foldr (>=>) return . map (flip f) [foldr/map fusion] = foldl (>=>) return . map (flip f) [by the theorem] = foldl (\t h -> t >=> flip f h) return [foldl/map fusion] Therefore foldM f z xs = foldr f' return xs z = foldl f'' return xs z, where f'' = \t h -> t >=> flip f h. But this doesn't mean these all have the same performance characteristics. Exercise for the reader: find examples where the foldr version performs better than the foldl version and vice-versa. I've noticed this distinction between State and [] in particular. They both may require use of seq in the function f to prevent stack overflow. Here is a module implementing these versions of foldM. It seems reasonable to have versions with <=< and with f unflipped as well, but those could be derived from the functions below. > module FoldM (foldrM, foldr1M, foldlM, foldl1M) where > import Control.Monad((>=>)) > -- foldrM nests to the right: > -- foldrM f z [x1, ..., xn] = (flip f x1 >=> (... >=> (flip f xn)...)) $ z > foldrM :: Monad m => (a -> b -> m a) -> a -> [b] -> m a > foldrM f z xs = foldr (\h t -> flip f h >=> t) return xs z Surprisingly, this may or may not be faster than the equivalent foldrM f z = return z >>= foldr (\h t -> flip f h >=> t) return xs depending on the monad. But they're both slower than foldM. > foldr1M f (x:xs) = foldrM f x xs > -- foldlM nests to the left: > -- foldlM f z [x1, ..., xn] = (...(flip f x1) >=> ...) >=> flip f xn) $ z > foldlM :: Monad m => (a -> b -> m a) -> a -> [b] -> m a > foldlM f z xs = foldl (\t h -> t >=> flip f h) return xs z Again, this is apparently faster or slower than either of foldlM f z xs = return z >>= foldl (\t h -> t >=> flip f h) return xs foldlM f = foldl (\t h -> t >>= flip f h) . return depending on the monad. > foldl1M f (x:xs) = foldlM f x xs -- Jason McCarty From michael at snoyman.com Wed Aug 19 03:36:33 2009 From: michael at snoyman.com (Michael Snoyman) Date: Wed Aug 19 03:16:39 2009 Subject: [Haskell-cafe] Re: Planning for a website In-Reply-To: <87skfpc4fl.fsf@zagan.made.you> References: <87skfpc4fl.fsf@zagan.made.you> Message-ID: <29bf512f0908190036x7aa018cqc721b65a9ac06efc@mail.gmail.com> On Tue, Aug 18, 2009 at 10:22 PM, Max Desyatov wrote: > Simon Michael writes: > > > I can give a +1 vote for the Hack api and related libs. (Jinjing Wang > > is a one-man army.) Below hack you'll run happstack or another > > web-serving lib. Above hack you might run some combination of loli, > > maid, the hack middleware modules, hsp. > > > > The advantage is that changing the low-level server in future is a > > matter of changing one or two lines; and the upper-level utilities > > seem more usable to me than current happstack's. > > The problem is that `hack` isn't documented at all and that prevents it > from being in wide use. At least, when I started my web app, I > preferred happstack, as low-level and documented API is better than > high-level API without a little bit of documentation, examples and > tutorials. > I don't see how you can call hack a "high-level API." It's about as low-level as it gets, kind of equivalent to the CGI protocol. I wrote up a little blog article with a hack introduction ( http://blog.snoyman.com/2009/06/28/hack-introduction/). I would also recommend checking out my hack-samples repo on github ( http://github.com/snoyberg/hack-samples/tree/master). Overall, hack is still developing, so the documentation is a little lacking. However, I at least am using it in production on a few sites ( http://eliezer.snoyman.com, http://wordify.snoyman.com). Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/7ab235e9/attachment.html From sebf at informatik.uni-kiel.de Wed Aug 19 03:47:45 2009 From: sebf at informatik.uni-kiel.de (Sebastian Fischer) Date: Wed Aug 19 03:27:54 2009 Subject: [Haskell-cafe] Keeping an indexed collection of values? In-Reply-To: References: Message-ID: On Aug 18, 2009, at 9:19 PM, Job Vranish wrote: > data IndexedCollection a = IndexedCollection { > nextKey :: Int, > availableKeys :: [Int], > items :: (IntMap Int a) > } deriving (Show) > > emptyIndexedCollection :: IndexedCollection a > emptyIndexedCollection = IndexedCollection 0 [] empty > [...] > Does anyone know of a better/already existent data structure for > handling this problem? > Or perhaps a better way of keeping a "key pool" than my > availableKeys solution? just a slight simplification: you could drop the nextKey field and initialise availableKeys with [0..] in emptyIndexCollection. The add function would consume the head of this list, the remove function add the deleted key as new head. -- Underestimating the novelty of the future is a time-honored tradition. (D.G.) From bugfact at gmail.com Wed Aug 19 04:23:21 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 19 04:03:28 2009 Subject: [Haskell-cafe] Re: simulation in the haskell way In-Reply-To: References: <200908182042.19093.wsysdu@gmail.com> <20090819012906.198e4e0d@tritium.xx> <200908190819.39990.wsysdu@gmail.com> Message-ID: I don't really agree that in Haskell when it comes to simulation a program "just is". That is the idealized story. At least when writing your own simulation engine, in practice you have to deal with operational details such as future unknown values that can block computations; to much laziness can cause hickups in the framerate since unobserved computations build up over time (a bit like sum does) which is why most Yampa simulations I've seen mark all the outputs deep strict (so even the end user needs to know about the operational details); binding to the head of signals and signal recursion causes space and time leaks, and that's why Yampa doesn't provide first signals, which in turn gives problems with inefficiency regarding too much redundant evaluation, etc... *Wolfgang *Jeltsch is working on a PhD thesis for Grapefruit in which I hope all problems with FRP will be nicely documented, since currently there doesn't seem to be clear literature that tells the whole story with pros/cons of each framework. I even believe Luke Palmer abandoned Haskell for doing FRP and started inventing his own language "Dana"; see http://lukepalmer.wordpress.com And of course Conal Elliot's blog outlines some of the problems and beauties of his latest FRP system (Reactive) So it's not all sunshine and roses, but that's also what makes it interesting :) 2009/8/19 Maur??cio CA > When I was using C and Python, I used to think of most applications in an >> simulation way. I think it's right to say that programs are simulations. >> But now I have to change my mind in Haskell, I have to think in a >> data-flow >> way, that is: data in, processing using function composition, data out. >> > > You have to think there's no in and out, since there's > no state and so no before and after. And no flow, since > time is just an ilusion of users. In Haskell, a program > just "is". > > Sorry, could not resist the Jedi talk... > > Hope you like the language. Best, > Maur?cio > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/6429e83e/attachment.html From malcolm.wallace at cs.york.ac.uk Wed Aug 19 05:01:05 2009 From: malcolm.wallace at cs.york.ac.uk (Malcolm Wallace) Date: Wed Aug 19 04:41:09 2009 Subject: [Haskell-cafe] Text.Html introduction In-Reply-To: <0D00C34C-F68B-4389-ABE9-79DAB681DF74@w3future.com> References: <90889fe70908180718i4d701ee3qa0fb554d804bb0cc@mail.gmail.com> <0D00C34C-F68B-4389-ABE9-79DAB681DF74@w3future.com> Message-ID: >>> "Based on the original Text.Html library by Andy Gill. See >>> http://www.cse.ogi.edu/~andy/html/intro.htm for an introduction to >>> that library. " Try the Internet Archive: http://web.archive.org/web/*/http://www.cse.ogi.edu/~andy/html/intro.htm Regards, Malcolm From thomas at cs.ru.nl Wed Aug 19 05:08:34 2009 From: thomas at cs.ru.nl (Thomas van Noort) Date: Wed Aug 19 04:48:26 2009 Subject: [Haskell-cafe] Type family signatures In-Reply-To: <2f9b2d30908181356r74295c6es3f2431967de34409@mail.gmail.com> References: <4A857D7F.7040000@cs.ru.nl> <49a77b7a0908140832h7033b368nabc73f513de070d3@mail.gmail.com> <4A85B514.4050306@imageworks.com> <2f9b2d30908141349v581d05f9lfb6fa98aa4fe2a4@mail.gmail.com> <4A8902D5.50106@cs.ru.nl> <2f9b2d30908181356r74295c6es3f2431967de34409@mail.gmail.com> Message-ID: <4A8BC112.3050904@cs.ru.nl> Thank your for this elaborate explanation, you made my day! Thomas Ryan Ingram wrote: > On Mon, Aug 17, 2009 at 12:12 AM, Thomas van Noort wrote: >> Somehow I didn't receive David's mail, but his explanation makes a lot of >> sense. I'm still wondering how this results in a type error involving rigid >> type variables. > > "rigid" type means the type has been specified by the programmer somehow. > > Desugaring your code a bit, we get: > > GADT :: forall a b. (b ~ Fam a) => a -> b -> GADT b > > Notice that this is an existential type that partially hides "a"; all > we know about "a" after unwrapping this type is that (Fam a ~ b). > > unwrap :: forall a b. (b ~ Fam a) => GADT b -> (a,b) > unwrap (GADT x y) = (x,y) > > So, the type signature of unwrap fixes "a" and "b" to be supplied by > the caller. Then the pattern match on GADT needs a type variable for > the existential, so a new "a1" is invented. These are rigid because > they cannot be further refined by the typechecker; the typechecker > cannot unify them with other types, like "a1 ~ Int", or "a1 ~ a". > > An example of a non-rigid variable occurs type-checking this expression: > > foo x = x + (1 :: Int) > > During type-checking/inference, there is a point where the type environment is: > > (+) :: forall a. Num a => a -> a -> a > > b :: *, non-rigid > x :: b > > c :: *, non-rigid > foo :: b -> c > > Then (+) gets instantiated at Int and forces "b" and "c" to be Int. > > In your case, during the typechecking of unwrap, we have: > > unwrap :: forall a b. (b ~ Fam a) => GADT b -> (a,b) > a :: *, rigid > b :: *, rigid > (b ~ Fam a) > > -- From the pattern match on GADT: > a1 :: *, rigid > x :: a1 > y :: b > (b ~ Fam a1) > > Now the typechecker wants to unify "a" and "a1", and it cannot, > because they are rigid. If one of them was still open, we could unify > it with the other. > > The type equalities give us (Fam a ~ Fam a1), but that does not give > us (a ~ a1). If Fam was a data type or data family, we would know it > is injective and be able to derive (a ~ a1), but it is a type family, > so we are stuck. > > -- ryan From simonpj at microsoft.com Wed Aug 19 05:19:27 2009 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Wed Aug 19 04:59:32 2009 Subject: [Haskell-cafe] Type family signatures In-Reply-To: <2f9b2d30908181356r74295c6es3f2431967de34409@mail.gmail.com> References: <4A857D7F.7040000@cs.ru.nl> <49a77b7a0908140832h7033b368nabc73f513de070d3@mail.gmail.com> <4A85B514.4050306@imageworks.com> <2f9b2d30908141349v581d05f9lfb6fa98aa4fe2a4@mail.gmail.com> <4A8902D5.50106@cs.ru.nl> <2f9b2d30908181356r74295c6es3f2431967de34409@mail.gmail.com> Message-ID: <638ABD0A29C8884A91BC5FB5C349B1C35CE710129A@EA-EXMSG-C334.europe.corp.microsoft.com> David is right that the program should be rejected. To be concrete, as he suggests, suppose type instance Fam Int = Bool type instance Fam Char = Bool Now suppose that 'unwrap' did typecheck. Then we could write: x :: Fam Int x = GADT 3 True y :: (Char, Bool) y = unwrap x Voila! We started with an Int (3), and managed to return it as the first component of a pair of type (Char,Bool). Ryan's explanation of the type checking process is accurate, but I agree that the error message is horrible. Dimitrios and I are working on a better version of the type checker that will say something more helpful, like Cannot deduce (a ~ a1) from (Fam a ~ Fam a1) which is a lot more useful. Nice example, thank you. Simon | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On | Behalf Of Ryan Ingram | Sent: 18 August 2009 21:56 | To: Thomas van Noort | Cc: Haskell Cafe | Subject: Re: [Haskell-cafe] Type family signatures | | On Mon, Aug 17, 2009 at 12:12 AM, Thomas van Noort wrote: | > Somehow I didn't receive David's mail, but his explanation makes a lot of | > sense. I'm still wondering how this results in a type error involving rigid | > type variables. | | "rigid" type means the type has been specified by the programmer somehow. | | Desugaring your code a bit, we get: | | GADT :: forall a b. (b ~ Fam a) => a -> b -> GADT b | | Notice that this is an existential type that partially hides "a"; all | we know about "a" after unwrapping this type is that (Fam a ~ b). | | unwrap :: forall a b. (b ~ Fam a) => GADT b -> (a,b) | unwrap (GADT x y) = (x,y) | | So, the type signature of unwrap fixes "a" and "b" to be supplied by | the caller. Then the pattern match on GADT needs a type variable for | the existential, so a new "a1" is invented. These are rigid because | they cannot be further refined by the typechecker; the typechecker | cannot unify them with other types, like "a1 ~ Int", or "a1 ~ a". | | An example of a non-rigid variable occurs type-checking this expression: | | foo x = x + (1 :: Int) | | During type-checking/inference, there is a point where the type environment is: | | (+) :: forall a. Num a => a -> a -> a | | b :: *, non-rigid | x :: b | | c :: *, non-rigid | foo :: b -> c | | Then (+) gets instantiated at Int and forces "b" and "c" to be Int. | | In your case, during the typechecking of unwrap, we have: | | unwrap :: forall a b. (b ~ Fam a) => GADT b -> (a,b) | a :: *, rigid | b :: *, rigid | (b ~ Fam a) | | -- From the pattern match on GADT: | a1 :: *, rigid | x :: a1 | y :: b | (b ~ Fam a1) | | Now the typechecker wants to unify "a" and "a1", and it cannot, | because they are rigid. If one of them was still open, we could unify | it with the other. | | The type equalities give us (Fam a ~ Fam a1), but that does not give | us (a ~ a1). If Fam was a data type or data family, we would know it | is injective and be able to derive (a ~ a1), but it is a type family, | so we are stuck. | | -- ryan | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe From jason.dusek at gmail.com Wed Aug 19 05:25:00 2009 From: jason.dusek at gmail.com (Jason Dusek) Date: Wed Aug 19 05:05:04 2009 Subject: [Haskell-cafe] Some trouble with AttoParsec. Message-ID: <42784f260908190225r289969f3ib51e39246b8a5370@mail.gmail.com> The linked to text demoes a seemingly impossible error when processing a lazy byte string with AttoParsec: I check to see if the ByteString is null, take the last character and get an exception. -- Jason Dusek http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8309#a8309 From jason.dusek at gmail.com Wed Aug 19 05:38:41 2009 From: jason.dusek at gmail.com (Jason Dusek) Date: Wed Aug 19 05:18:45 2009 Subject: [Haskell-cafe] Re: Some trouble with AttoParsec. In-Reply-To: <42784f260908190225r289969f3ib51e39246b8a5370@mail.gmail.com> References: <42784f260908190225r289969f3ib51e39246b8a5370@mail.gmail.com> Message-ID: <42784f260908190238u667df42ai3d3eb896e42e753a@mail.gmail.com> Aha. From `Data.ByteString.Lazy` we have: null :: ByteString -> Bool null Empty = True null _ = False So either users need to norm ByteStrings before testing them for emptiness or it needs to happen within the ByteString code... -- Jason Dusek From ramsdell0 at gmail.com Wed Aug 19 05:43:43 2009 From: ramsdell0 at gmail.com (John D. Ramsdell) Date: Wed Aug 19 05:23:47 2009 Subject: [Haskell-cafe] Unifcation and matching in Abelian groups Message-ID: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> I've been studying equational unification. I decided to test my understanding of it by implementing unification and matching in Abelian groups. I am quite surprised by how little code it takes. Let me share it with you. John Test cases: 2x+y=3z 2x=x+y 64x-41y=a Code: > -- Unification and matching in Abelian groups > -- John D. Ramsdell -- August 2009 > > module Main (main, test) where > > import Data.Char (isSpace, isAlpha, isAlphaNum, isDigit) > import Data.List (sort) > import System.IO (isEOF) > > -- Chapter 8, Section 5 of the Handbook of Automated Reasoning by > -- Franz Baader and Wayne Snyder describes unification and matching in > -- communtative/monoidal theories. This module refines the described > -- algorithms for the special case of Abelian groups. > > -- In this module, an Abelian group is a free algebra over a signature > -- with three function symbols, > -- > -- * the binary symbol +, the group operator, > -- * a constant 0, the identity element, and > -- * the unary symbol -, the inverse operator. > -- > -- The algebra is generated by a set of variables. Syntactically, a > -- variable is an identifer such as x and y. > > -- The axioms associated with the algebra are: > -- > -- * x + y = y + x Commutativity > -- * (x + y) + z = x + (y + z) Associativity > -- * x + 0 = x Group identity > -- * x + -x = 0 Cancellation > > -- A substitution maps variables to terms. A substitution s is > -- extended to a term as follows. > -- > -- s(0) = 0 > -- s(-t) = -s(t) > -- s(t + t') = s(t) + s(t') > > -- The unification problem is given the problem statement t =? t', > -- find a substitution s such that s(t) = s(t') modulo the axioms of > -- the algebra. The matching problem is to find substitution s such > -- that s(t) = t' modulo the axioms. > > -- A term is represented as the sum of factors, and a factor is the > -- product of an integer coeficient and a variable or the group > -- identity, zero. In this representation, every coeficient is > -- non-zero, and no variable occurs twice. > > -- A term can be represented by a finite map from variables to > -- non-negative integers. To make the code easier to understand, > -- association lists are used instead of Data.Map. > > newtype Lin = Lin [(String, Int)] > > -- Constructors > > -- Identity element (zero) > ide :: Lin > ide = Lin [] > > -- Factors > var :: Int -> String -> Lin > var 0 _ = Lin [] > var c x = Lin [(x, c)] > > -- Invert by negating coefficients. > neg :: Lin -> Lin > neg (Lin t) = > Lin $ map (\(x, c) -> (x, negate c)) t > > -- Join terms ensuring that coefficients are non-zero, and no variable > -- occurs twice. > add :: Lin -> Lin -> Lin > add (Lin t) (Lin t') = > Lin $ foldr f t' t > where > f (x, c) t = > case lookup x t of > Just c' | c + c' == 0 -> remove x t > | otherwise -> (x, c + c') : remove x t > Nothing -> (x, c) : t > > -- Remove the first pair in an association list that matches the key. > remove :: Eq a => a -> [(a, b)] -> [(a, b)] > remove _ [] = [] > remove x (y@(z, _) : ys) > | x == z = ys > | otherwise = y : remove x ys > > canonicalize :: Lin -> Lin > canonicalize (Lin t) = > Lin (sort t) > > -- Convert a linearized term into an association list. > assocs :: Lin -> [(String, Int)] > assocs (Lin t) = t > > term :: [(String, Int)] -> Lin > term assoc = > foldr f ide assoc > where > f (x, c) t = add t $ var c x > > -- Unification and Matching > > newtype Equation = Equation (Lin, Lin) > > newtype Maplet = Maplet (String, Lin) > > -- Unification is the same as matching when there are no constants > unify :: Monad m => Equation -> m [Maplet] > unify (Equation (t0, t1)) = > match $ Equation (add t0 (neg t1), ide) > > -- Matching in Abelian groups is performed by finding integer > -- solutions to linear equations, and then using the solutions to > -- construct a most general unifier. > match :: Monad m => Equation -> m [Maplet] > match (Equation (t0, t1)) = > case (assocs t0, assocs t1) of > ([], []) -> return [] > ([], _) -> fail "no solution" > (t0, t1) -> > do > subst <- intLinEq (map snd t0) (map snd t1) > return $ mgu (map fst t0) (map fst t1) subst > > -- Construct a most general unifier from a solution to a linear > -- equation. The function adds the variables back into terms, and > -- generates fresh variables as needed. > mgu :: [String] -> [String] -> Subst -> [Maplet] > mgu vars syms subst = > foldr f [] (zip vars [0..]) > where > f (x, n) maplets = > case lookup n subst of > Just (factors, consts) -> > Maplet (x, g factors consts) : maplets > Nothing -> > Maplet (x, var 1 $ genSym n) : maplets > g factors consts = > term (zip genSyms factors ++ zip syms consts) > genSyms = map genSym [0..] > > -- Generated variables start with this character. > genChar :: Char > genChar = 'g' > > genSym :: Int -> String > genSym i = genChar : show i > > -- So why solve linear equations? Consider the matching problem > -- > -- c[0]*x[0] + c[1]*x[1] + ... + c[n-1]*x[n-1] =? > -- d[0]*a[0] + d[1]*a[1] + ... + d[m-1]*a[m-1] > -- > -- with n variables and m constants. We seek a most general unifier s > -- such that > -- > -- s(c[0]*x[0] + c[1]*x[1] + ... + c[n-1]*x[n-1]) = > -- d[0]*a[0] + d[1]*a[1] + ... + d[m-1]*a[m-1] > -- > -- which is the same as > -- > -- c[0]*s(x[0]) + c[1]*s(x[1]) + ... + c[n-1]*s(x[n-1]) = > -- d[0]*a[0] + d[1]*a[1] + ... + d[m-1]*a[m-1] > -- > -- Notice that the number of occurrences of constant a[0] in s(x[0]) > -- plus s(x[1]) ... s(x[n-1]) must equal d[0]. Thus the mappings of > -- the unifier that involve constant a[0] respect integer solutions of > -- the following linear equation. > -- > -- c[0]*x[0] + c[1]*x[1] + ... + c[n-1]*x[n-1] = d[0] > -- > -- To compute a most general unifier, a most general integer solution > -- to a linear equation must be found. > > -- Integer Solutions of Linear Inhomogeneous Equations > > type LinEq = ([Int], [Int]) > > -- A linear equation with integer coefficients is represented as a > -- pair of lists of integers, the coefficients and the constants. If > -- there are no constants, the linear equation represented by (c, []) > -- is the homogeneous equation: > -- > -- c[0]*x[0] + c[1]*x[1] + ... + c[n-1]*x[n-1] = 0 > -- > -- where n is the length of c. Otherwise, (c, d) represents a > -- sequence of inhomogeneous linear equations with the same > -- left-hand-side: > -- > -- c[0]*x[0] + c[1]*x[1] + ... + c[n-1]*x[n-1] = d[0] > -- c[0]*x[0] + c[1]*x[1] + ... + c[n-1]*x[n-1] = d[1] > -- ... > -- c[0]*x[0] + c[1]*x[1] + ... + c[n-1]*x[n-1] = d[m-1] > -- > -- where m is the length of d. > > type Subst = [(Int, LinEq)] > > -- A solution is a partial map from variables to terms, and a term is > -- a pair of lists of integers, the variable part of the term followed > -- by the constant part. The variable part may specify variables not > -- in the input. For example, the solution of > -- > -- 64x = 41y + 1 > -- > -- is x = -41z - 16 and y = -64z - 25. The computed solution is read > -- off the list returned as an answer. > -- > -- intLinEq [64,-41] [1] = > -- [(0,([0,0,0,0,0,0,-41],[-16])), > -- (1,([0,0,0,0,0,0,-64],[-25]))] > > -- Find integer solutions to linear equations > intLinEq :: Monad m => [Int] -> [Int] -> m Subst > intLinEq coefficients constants = > intLinEqLoop (length coefficients) (coefficients, constants) [] > > -- The algorithm used to find solutions is described in Vol. 2 of The > -- Art of Computer Programming / Seminumerical Alorithms, 2nd Ed., > -- 1981, by Donald E. Knuth, pg. 327. > > -- On input, n is the number of variables in the original problem, c > -- is the coefficients, d is the constants, and subst is a list of > -- eliminated variables. > intLinEqLoop :: Monad m => Int -> LinEq -> Subst -> m Subst > intLinEqLoop n (c, d) subst = > -- Find the smallest coefficient in absolute value > let (i, ci) = smallest c in > case () of > _ | ci < 0 -> intLinEqLoop n (invert c, invert d) subst > -- Ensure the smallest coefficient is positive > | ci == 0 -> fail "bad problem" > -- Lack of non-zero coefficients is an error > | ci == 1 -> > -- A general solution of the following form has been found: > -- x[i] = sum[j] -c'[j]*x[j] + d[k] for all k > -- where c' is c with c'[i] = 0. > return $ eliminate n (i, (invert (zero i c), d)) subst > | divisible ci c -> > -- If all the coefficients are divisible by c[i], a solution is > -- immediate if all the constants are divisible by c[i], > -- otherwise there is no solution. > if divisible ci d then > let c' = divide ci c > d' = divide ci d in > return $ eliminate n (i, (invert (zero i c'), d')) subst > else > fail "no solution" > | otherwise -> > -- Eliminate x[i] in favor of freshly created variable x[n], > -- where n is the length of c. > -- x[n] = sum[j] (c[j] div c[i] * x[j]) > -- The new equation to be solved is: > -- c[i]*x[n] + sum[j] c'[j]*x[j] = d[k] for all k > -- where c'[j] = c[j] mod c[i] for j /= i and c'[i] = 0. > let c' = map (\x -> mod x ci) (zero i c) > c'' = divide ci (zero i c) > subst' = eliminate n (i, (invert c'' ++ [1], [])) subst in > intLinEqLoop n (c' ++ [ci], d) subst' > > -- Find the smallest coefficient in absolute value > smallest :: [Int] -> (Int, Int) > smallest xs = > foldl f (-1, 0) (zip [0..] xs) > where > f (i, n) (j, x) > | n == 0 = (j, x) > | x == 0 || abs n <= abs x = (i, n) > | otherwise = (j, x) > > invert :: [Int] -> [Int] > invert t = map negate t > > -- Zero the ith position in a list > zero :: Int -> [Int] -> [Int] > zero _ [] = [] > zero 0 (_:xs) = 0 : xs > zero i (x:xs) = x : zero (i - 1) xs > > -- Eliminate a variable from the existing substitution. If the > -- variable is in the original problem, add it to the substitution. > eliminate :: Int -> (Int, LinEq) -> Subst -> Subst > eliminate n m@(i, (c, d)) subst = > if i < n then > m : map f subst > else > map f subst > where > f m'@(i', (c', d')) = -- Eliminate i in c' if it occurs in c' > case get i c' of > 0 -> m' -- i is not in c' > ci -> (i', (addmul ci (zero i c') c, addmul ci d' d)) > -- Find ith coefficient > get _ [] = 0 > get 0 (x:_) = x > get i (_:xs) = get (i - 1) xs > -- addnum n xs ys sums xs and ys after multiplying ys by n > addmul 1 [] ys = ys > addmul n [] ys = map (* n) ys > addmul _ xs [] = xs > addmul n (x:xs) (y:ys) = (x + n * y) : addmul n xs ys > > divisible :: Int -> [Int] -> Bool > divisible small t = > all (\x -> mod x small == 0) t > > divide :: Int -> [Int] -> [Int] > divide small t = > map (\x -> div x small) t > > -- Input and Output > > instance Show Lin where > showsPrec _ (Lin []) = > showString "0" > showsPrec _ x = > showFactor t . showl ts > where > Lin (t:ts) = canonicalize x > showFactor (x, 1) = showString x > showFactor (x, -1) = showChar '-' . showString x > showFactor (x, c) = shows c . showString x > showl [] = id > showl ((s,n):ts) > | n < 0 = > showString " - " . showFactor (s, negate n) . showl ts > showl (t:ts) = showString " + " . showFactor t . showl ts > > instance Read Lin where > readsPrec _ s0 = > [ (t1, s2) | (t0, s1) <- readFactor s0, > (t1, s2) <- readRest t0 s1 ] > where > readPrimary s0 = > [ (t0, s1) | (x, s1) <- scan s0, isVar x, > let t0 = var 1 x ] ++ > [ (t0, s1) | ("0", s1) <- scan s0, > (s, _) <- scan s1, not (isVar s), > let t0 = ide ] ++ > [ (t0, s2) | (n, s1) <- scan s0, isNum n, > (x, s2) <- scan s1, isVar x, > let t0 = var (read n) x ] ++ > [ (t0, s3) | ("(", s1) <- scan s0, > (t0, s2) <- reads s1, > (")", s3) <- scan s2 ] > readFactor s0 = > [ (t1, s2) | ("-", s1) <- scan s0, > (t0, s2) <- readPrimary s1, > let t1 = neg t0 ] ++ > [ (t0, s1) | (s, _) <- scan s0, s /= "-", > (t0, s1) <- readPrimary s0 ] > readRest t0 s0 = > [ (t2, s3) | ("+", s1) <- scan s0, > (t1, s2) <- readFactor s1, > (t2, s3) <- readRest (add t0 t1) s2 ] ++ > [ (t2, s3) | ("-", s1) <- scan s0, > (t1, s2) <- readPrimary s1, > (t2, s3) <- readRest (add t0 (neg t1)) s2 ] ++ > [ (t0, s0) | (s, _) <- scan s0, s /= "+" && s /= "-" ] > > isNum :: String -> Bool > isNum (c:_) = isDigit c > isNum _ = False > > isVar :: String -> Bool > isVar (c:_) = isAlpha c && c /= genChar > isVar _ = False > > scan :: ReadS String > scan "" = [("", "")] > scan (c:s) > | isSpace c = scan s > | isAlpha c = [ (c:part, t) | (part,t) <- [span isAlphaNum s] ] > | isDigit c = [ (c:part, t) | (part,t) <- [span isDigit s] ] > | otherwise = [([c], s)] > > instance Show Equation where > showsPrec _ (Equation (t0, t1)) = > shows t0 . showString " = " . shows t1 > > instance Read Equation where > readsPrec _ s0 = > [ (Equation (t0, t1), s3) | (t0, s1) <- reads s0, > ("=", s2) <- scan s1, > (t1, s3) <- reads s2 ] > > instance Show Maplet where > showsPrec _ (Maplet (x, t)) = > showString x . showString " -> " . shows t > > -- Test Routine > > -- Given an equation, display a unifier and a matcher. > test :: String -> IO () > test prob = > case readM prob of > Err err -> putStrLn err > Ans (Equation (t0, t1)) -> > do > putStr "Problem: " > print $ Equation (canonicalize t0, canonicalize t1) > subst <- unify $ Equation (t0, t1) > putStr "Unifier: " > print subst > putStr "Matcher: " > case match $ Equation (t0, t1) of > Err err -> putStrLn err > Ans subst -> print subst > putStrLn "" > > readM :: (Read a, Monad m) => String -> m a > readM s = > case [ x | (x, t) <- reads s, ("", "") <- lex t ] of > [x] -> return x > [] -> fail "no parse" > _ -> fail "ambiguous parse" > > data AnsErr a > = Ans a > | Err String > > instance Monad AnsErr where > (Ans x) >>= k = k x > (Err s) >>= _ = Err s > return = Ans > fail = Err > > main :: IO () > main = > do > done <- isEOF > case done of > True -> return () > False -> > do > prob <- getLine > test prob > main From jason.dusek at gmail.com Wed Aug 19 06:07:39 2009 From: jason.dusek at gmail.com (Jason Dusek) Date: Wed Aug 19 05:47:44 2009 Subject: [Haskell-cafe] Re: Some trouble with AttoParsec. In-Reply-To: <42784f260908190238u667df42ai3d3eb896e42e753a@mail.gmail.com> References: <42784f260908190225r289969f3ib51e39246b8a5370@mail.gmail.com> <42784f260908190238u667df42ai3d3eb896e42e753a@mail.gmail.com> Message-ID: <42784f260908190307p432d7402r6ffd8584fbf19405@mail.gmail.com> 2009/08/19 Jason Dusek : > ?Aha. From `Data.ByteString.Lazy` we have: > > ? ?null :: ByteString -> Bool > ? ?null Empty = True > ? ?null _ ? ? = False > > ?So either users need to norm ByteStrings before testing > ?them for emptiness or it needs to happen within the ByteString > ?code... Well, no, actually -- the lazy `ByteString` constructors are all supposed to conform to the invariant that there are no empty chunks. So something is funny with AttoParsec: Prelude Data.ParserCombinators.Attoparsec.Char8 Data.ByteString.Lazy.Char8> parse (takeTill (== '"')) (pack "\"\"") (Chunk "\"" Empty,Right (Chunk "" Empty)) it :: (ByteString, Either ParseError ByteString) Sorry to hash this out on the list; I'm used to think of my troubles with Haskell libs as misunderstandings on my part. I'll have to look into what AttoParsec is doing and file a bug report. -- Jason Dusek From ndmitchell at gmail.com Wed Aug 19 06:16:06 2009 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Aug 19 05:56:10 2009 Subject: [Haskell-cafe] Unifcation and matching in Abelian groups In-Reply-To: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> Message-ID: <404396ef0908190316rc772614p9c660c8ab5095ed6@mail.gmail.com> Hi, I ran your code thought HLint (http://community.haskell.org/~ndm/hlint), and it suggested a couple of things (mainly eta reduce). The most interesting suggestions are on your main function: > main :: IO () > main = > do > done <- isEOF > case done of > True -> return () > False -> > do > prob <- getLine > test prob > main It suggests: Example.lhs:432:3: Warning: Use if Found: case done of True -> return () False -> do prob <- getLine test prob main Why not: if done then return () else do prob <- getLine test prob main Changing that and rerunning says: Example.lhs:432:3: Error: Use unless Found: if done then return () else do prob <- getLine test prob main Why not: unless done $ do prob <- getLine test prob main So I (or rather HLint) recommends you do: > main :: IO () > main = > do > done <- isEOF > unless done $ do > prob <- getLine > test prob > main Thanks, Neil From bulat.ziganshin at gmail.com Wed Aug 19 06:36:48 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Wed Aug 19 06:17:02 2009 Subject: [Haskell-cafe] Unifcation and matching in Abelian groups In-Reply-To: <404396ef0908190316rc772614p9c660c8ab5095ed6@mail.gmail.com> References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> <404396ef0908190316rc772614p9c660c8ab5095ed6@mail.gmail.com> Message-ID: <94182209.20090819143648@gmail.com> Hello Neil, Wednesday, August 19, 2009, 2:16:06 PM, you wrote: >> main = >> do >> done <- isEOF >> unless done $ do >> prob <- getLine >> test prob >> main main = untilM isEOF (getLine >>= test) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From ramsdell0 at gmail.com Wed Aug 19 06:45:20 2009 From: ramsdell0 at gmail.com (John D. Ramsdell) Date: Wed Aug 19 06:25:24 2009 Subject: [Haskell-cafe] Unifcation and matching in Abelian groups In-Reply-To: <404396ef0908190316rc772614p9c660c8ab5095ed6@mail.gmail.com> References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> <404396ef0908190316rc772614p9c660c8ab5095ed6@mail.gmail.com> Message-ID: <7687290b0908190345q23313f4bwf24b6868499ee704@mail.gmail.com> On Wed, Aug 19, 2009 at 6:16 AM, Neil Mitchell wrote: > Why not: > ?if done then return () else > ? ?do prob <- getLine > ? ? ? test prob > ? ? ? main I've given up on using if-then-else in do expressions. They confuse emacs. There is a proposal for Haskell' to fix the problem, but until then, I will not use them in do expressions. I'm so glad new languages do not use the offset rule. I get tired typing tab in emacs, especially since for most other languages, emacs does so well at picking a good indent. Requiring coders to spend so much time choosing indents reminds me of the days when I wrote C code with vi. I've been there, done that, and moved on to emacs. > ?unless done $ > ? ?do prob <- getLine > ? ? ? test prob > ? ? ? main I do like this suggestion. Thanks. John From ndmitchell at gmail.com Wed Aug 19 06:51:33 2009 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Aug 19 06:31:38 2009 Subject: [Haskell-cafe] Unifcation and matching in Abelian groups In-Reply-To: <7687290b0908190345q23313f4bwf24b6868499ee704@mail.gmail.com> References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> <404396ef0908190316rc772614p9c660c8ab5095ed6@mail.gmail.com> <7687290b0908190345q23313f4bwf24b6868499ee704@mail.gmail.com> Message-ID: <404396ef0908190351v3f206ae1y63e0152255dd4da2@mail.gmail.com> Hi > I've given up on using if-then-else in do expressions. ?They confuse > emacs. ?There is a proposal for Haskell' to fix the problem, but until > then, I will not use them in do expressions. It's a shame, there are ways of indenting them that work, but they're not as natural. It's a wart, but it will be fixed. > I'm so glad new languages do not use the offset rule. F# is new and has the offset rule. Haskell is old and has the optional offset rule: do { prob <- getLine ; test prob ; main} Now your indentation is your own :-) Some people prefer this style. Simon Peyton Jones uses it in the book beautiful code. I much prefer indentation only. Thanks Neil From ramsdell0 at gmail.com Wed Aug 19 07:05:51 2009 From: ramsdell0 at gmail.com (John D. Ramsdell) Date: Wed Aug 19 06:45:55 2009 Subject: [Haskell-cafe] Unifcation and matching in Abelian groups In-Reply-To: <404396ef0908190351v3f206ae1y63e0152255dd4da2@mail.gmail.com> References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> <404396ef0908190316rc772614p9c660c8ab5095ed6@mail.gmail.com> <7687290b0908190345q23313f4bwf24b6868499ee704@mail.gmail.com> <404396ef0908190351v3f206ae1y63e0152255dd4da2@mail.gmail.com> Message-ID: <7687290b0908190405h7936fd4i4436a35cddb17cd7@mail.gmail.com> On Wed, Aug 19, 2009 at 6:51 AM, Neil Mitchell wrote: > F# is new and has the offset rule. Haskell is old and has the optional > offset rule: I thought F# uses OCaml syntax. Emacs does well with OCaml syntax. Guy Steele told this story at a conference. As part of the Fortress design effort, he and other at Sun visited several sites that make use of high performance computing. They received a variety of suggestions on how to design a high productivity language for high performance computing, and uniformly were asked not to give programmers a language that uses the offset rule. John From bugfact at gmail.com Wed Aug 19 07:07:34 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 19 06:47:39 2009 Subject: [Haskell-cafe] Where do I put the seq? Message-ID: In an attempt to get a deeper understanding of several monads (State, ST, IO, ...) I skimmed over some of the research papers (but didn't understand all of it, I lack the required education) and decided to write a little program myself without using any prefab monad instances that should mimic the following: main = do putStrLn "Enter your name:" x <- getLine putStr "Welcome " putStrLn x putStrLn "Goodbye!" But instead of using IO, I wanted to make my own pure monad that gets evaluated with interact, and does the same. However, I get the following output: Enter your name: Welcome ...... So the Welcome is printed too soon. This is obvious since my monad is lazy, so I tried to put a seq at some strategic places to get the same behavior as IO. But I completely failed doing so, either the program doesn't print anything and asks input first, or it still prints too much output. Of course I could just use ST, State, transformers, etc, but this is purely an exercise I'm doing. So, I could re-read all papers and look in detail at all the code, but maybe someone could help me out where to put the seq or what to do :-) The code is at http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 Oh btw, the usage of DList here might not be needed; intuitively it felt like the correct thing to do, but when it comes to Haskell, my intuition is usually wrong ;-) Thanks a lot, Peter Verswyvelen -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/098fbb0f/attachment.html From gour at gour-nitai.com Wed Aug 19 07:14:25 2009 From: gour at gour-nitai.com (Gour) Date: Wed Aug 19 06:51:55 2009 Subject: [Haskell-cafe] Re: Planning for a website References: Message-ID: <87prasys1a.fsf@gaura-nitai.no-ip.org> >>>>> "Colin" == Colin Paul Adams writes: Colin> So my major decision is what framework and html-generating Colin> libraries to use. There is such a wide choice on the Haskell Colin> Wiki. But I guess some are more maintained than others. For Colin> instance, WASH attracts me, with it's guarantee of valid Colin> generated pages, but it isn't clear to me that it's actively Colin> maintained (last date I can see on the web pages is 2006). Have you thought about Turbinado (http://turbinado.org) ? Sincerely, Gour -- Gour | Hlapi?ina, Croatia | GPG key: F96FF5F6 --------------------------------------------------------------------------- -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/53ef6710/attachment.bin From jules at jellybean.co.uk Wed Aug 19 08:32:19 2009 From: jules at jellybean.co.uk (Jules Bean) Date: Wed Aug 19 08:12:23 2009 Subject: [Haskell-cafe] Unifcation and matching in Abelian groups In-Reply-To: <7687290b0908190345q23313f4bwf24b6868499ee704@mail.gmail.com> References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> <404396ef0908190316rc772614p9c660c8ab5095ed6@mail.gmail.com> <7687290b0908190345q23313f4bwf24b6868499ee704@mail.gmail.com> Message-ID: <4A8BF0D3.7050403@jellybean.co.uk> John D. Ramsdell wrote: > On Wed, Aug 19, 2009 at 6:16 AM, Neil Mitchell wrote: > >> Why not: >> if done then return () else >> do prob <- getLine >> test prob >> main > > I've given up on using if-then-else in do expressions. They confuse > emacs. There is a proposal for Haskell' to fix the problem, but until > then, I will not use them in do expressions. Do not blame haskell, blame emacs, if emacs is so stupid. Fortunately there is a better emacs mode which understands layout and if: http://kuribas.hcoop.net/haskell-indentation.el > I'm so glad new languages do not use the offset rule. I get tired > typing tab in emacs, especially since for most other languages, emacs > does so well at picking a good indent. Requiring coders to spend so > much time choosing indents reminds me of the days when I wrote C code > with vi. I've been there, done that, and moved on to emacs. Do not blame haskell, blame emacs. The layout rule is simple to understand and I think it makes attractive code. It's not haskell's fault that the emacs mode chooses a bad indent so often. There is a better emacs mode which gets the indentation right more often, I find ;) http://kuribas.hcoop.net/haskell-indentation.el Jules From dan.doel at gmail.com Wed Aug 19 09:04:33 2009 From: dan.doel at gmail.com (Dan Doel) Date: Wed Aug 19 08:44:42 2009 Subject: [Haskell-cafe] Observations about foldM In-Reply-To: <20090819041424.GC1103@quaternion> References: <20090819041424.GC1103@quaternion> Message-ID: <200908190904.34080.dan.doel@gmail.com> On Wednesday 19 August 2009 12:14:24 am Jason McCarty wrote: > Interestingly, foldM can also be written as a left fold. To see this, note > that it is a theorem that foldr f z xs = foldl f z xs as long as f is > associative and z is a unit for f. It must also be the case that xs is finite in length, because if it is infinite, then 'foldl f z xs' is bottom, while 'foldr f z xs' needn't be. This difference holds over into foldM implemented with each, where you can write something like: foldM (\f e -> if even e then Left (show e) else Right f) "no evens" [1..] and get an answer of 'Left "2"' with a foldr implementation, but bottom with a foldl implementation. This potentially translates into its own performance concerns, because in such monads, the computation can short-circuit upon finding a 'throw' when using the foldr implementation, but with the foldl implementation, you have to do at least a little shuffling of thunks for the entire list. -- Dan From ekirpichov at gmail.com Wed Aug 19 10:32:57 2009 From: ekirpichov at gmail.com (Eugene Kirpichov) Date: Wed Aug 19 10:13:00 2009 Subject: [Haskell-cafe] Observations about foldM In-Reply-To: <200908190904.34080.dan.doel@gmail.com> References: <20090819041424.GC1103@quaternion> <200908190904.34080.dan.doel@gmail.com> Message-ID: <5e0214850908190732k3226ea3csd0ab39cf88d4cbbe@mail.gmail.com> 2009/8/19 Dan Doel : > On Wednesday 19 August 2009 12:14:24 am Jason McCarty wrote: >> Interestingly, foldM can also be written as a left fold. To see this, note >> that it is a theorem that foldr f z xs = foldl f z xs as long as f is >> associative and z is a unit for f. > This is not true: f has to be commutative, not associative. Consider matrix multiplication. > It must also be the case that xs is finite in length, because if it is > infinite, then 'foldl f z xs' is bottom, while 'foldr f z xs' needn't be. This > difference holds over into foldM implemented with each, where you can write > something like: > > ?foldM (\f e -> if even e then Left (show e) else Right f) "no evens" [1..] > > and get an answer of 'Left "2"' with a foldr implementation, but bottom with a > foldl implementation. > > This potentially translates into its own performance concerns, because in such > monads, the computation can short-circuit upon finding a 'throw' when using > the foldr implementation, but with the foldl implementation, you have to do at > least a little shuffling of thunks for the entire list. > > -- Dan > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Eugene Kirpichov Web IR developer, market.yandex.ru From bugfact at gmail.com Wed Aug 19 10:35:58 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 19 10:16:03 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: Message-ID: Apparently this particular example happens to work on Mac and Linux because of different buffering (thanks Martijn for the help!) To make sure we have no buffering at all, the main function should be: main = do hSetBuffering stdout NoBuffering hSetBuffering stdin NoBuffering test Now I think it should also be *incorrect* on Unix systems. I guess the way I'm concatenating the strings is not correct, not sure. I would like to use a graphical tool to show the graph reduction step by step, to get a better understanding of the laziness & strictness. Does such a tool exist? I know people often say this is not usable because the amount of information is too much, but I used to be an assembly language programmer so I still would like to give it a try :-) On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen wrote: > In an attempt to get a deeper understanding of several monads (State, ST, > IO, ...) I skimmed over some of the research papers (but didn't understand > all of it, I lack the required education) and decided to write a little > program myself without using any prefab monad instances that should mimic > the following: > main = do > putStrLn "Enter your name:" > x <- getLine > putStr "Welcome " > putStrLn x > putStrLn "Goodbye!" > > But instead of using IO, I wanted to make my own pure monad that gets > evaluated with interact, and does the same. > > However, I get the following output: > > Enter your name: > Welcome ...... > > So the Welcome is printed too soon. > > This is obvious since my monad is lazy, so I tried to put a seq at some > strategic places to get the same behavior as IO. But I completely failed > doing so, either the program doesn't print anything and asks input first, or > it still prints too much output. > > Of course I could just use ST, State, transformers, etc, but this is purely > an exercise I'm doing. > > So, I could re-read all papers and look in detail at all the code, but > maybe someone could help me out where to put the seq or what to do :-) > > The code is at http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 > > Oh btw, the usage of DList here might not be needed; intuitively it felt > like the correct thing to do, but when it comes to Haskell, my intuition is > usually wrong ;-) > > Thanks a lot, > Peter Verswyvelen > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/a8760b35/attachment.html From fernanbolando at mailc.net Wed Aug 19 10:39:36 2009 From: fernanbolando at mailc.net (Fernan Bolando) Date: Wed Aug 19 10:19:40 2009 Subject: [Haskell-cafe] Hugs used in circuit simulations code In-Reply-To: <200907290454.45351.daniel.is.fischer@web.de> References: <1d5d51400907281832w32c96f99tb1d8ac2d73c01cc@mail.gmail.com> <200907290454.45351.daniel.is.fischer@web.de> Message-ID: <1d5d51400908190739w298ce203ua88c640e5de451d9@mail.gmail.com> On Wed, Jul 29, 2009 at 10:54 AM, Daniel Fischer wrote: > Am Mittwoch 29 Juli 2009 03:32:20 schrieb Fernan Bolando: >> What is everybodies expereience in speed difference between C and >> interpreted haskell? > > That depends on what you do, unsurprisingly. But usually it's huge. A factor of several > hundred is not uncommon, but 10-100 is the normal range (in my limited experience, I > almost always compile). > Hi Daniel and other thanks for the feedback the old simulation that took 13mins now only takes 2mins. I included a bunch of tweaking options. Someone needs to have a considerable knowledge in the circuit they are simulating and circuit simulator to be able tweak these. I am not that guy though all the tweak strategy are based on a bunch of papers I have been reading lately and blindly implements them. thanks again for the feedback. The new code is still not very haskelly but its a lot more useful now. http://plan9.bell-labs.com/sources/contrib/fernan/escomma/ -- http://www.fernski.com From daniel.is.fischer at web.de Wed Aug 19 10:44:52 2009 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Wed Aug 19 10:25:54 2009 Subject: [Haskell-cafe] Observations about foldM In-Reply-To: <5e0214850908190732k3226ea3csd0ab39cf88d4cbbe@mail.gmail.com> References: <20090819041424.GC1103@quaternion> <200908190904.34080.dan.doel@gmail.com> <5e0214850908190732k3226ea3csd0ab39cf88d4cbbe@mail.gmail.com> Message-ID: <200908191644.52887.daniel.is.fischer@web.de> Am Mittwoch 19 August 2009 16:32:57 schrieb Eugene Kirpichov: > 2009/8/19 Dan Doel : > > On Wednesday 19 August 2009 12:14:24 am Jason McCarty wrote: > >> Interestingly, foldM can also be written as a left fold. To see this, > >> note that it is a theorem that foldr f z xs = foldl f z xs as long as f > >> is associative and z is a unit for f. > > This is not true: f has to be commutative, not associative. > > Consider matrix multiplication. > It is true: foldr: A1*(A2*(... *AN*E)) foldl: (...((E*A1)*A2)*...*AN) Commutativity doesn't help, consider data Foo = Z | A | B (~) :: Foo -> Foo -> Foo Z ~ x = x x ~ Z = x B ~ B = A _ ~ _ = B (~) is commutative, but not associative, Z is a unit for (~). foldr (~) Z [A,A,B] = B foldl (~) Z [A,A,B] = A From leimy2k at gmail.com Wed Aug 19 11:00:48 2009 From: leimy2k at gmail.com (David Leimbach) Date: Wed Aug 19 10:40:53 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: Message-ID: <3e1162e60908190800j3888c2d9jf9f6f8342ba165ec@mail.gmail.com> Try LineBuffering. I do linewise stuff with interact a lot. You'll find stuff like unlines . lines may help too. In fact I just wrote a blog post about this. http://leimy9.blogspot.com I'm trying to write some interactive code to automate working with serial console controlled power strips, so I need to either use Expect (yuck) or do my own thing. Dave On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen wrote: > Apparently this particular example happens to work on Mac and Linux because > of different buffering (thanks Martijn for the help!) > To make sure we have no buffering at all, the main function should be: > > main = do hSetBuffering stdout NoBuffering hSetBuffering stdin NoBuffering test > > Now I think it should also be *incorrect* on Unix systems. > > I guess the way I'm concatenating the strings is not correct, not sure. > > I would like to use a graphical tool to show the graph reduction step by > step, to get a better understanding of the laziness & strictness. Does such > a tool exist? I know people often say this is not usable because the amount > of information is too much, but I used to be an assembly language programmer > so I still would like to give it a try :-) > > > > On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen wrote: > >> In an attempt to get a deeper understanding of several monads (State, ST, >> IO, ...) I skimmed over some of the research papers (but didn't understand >> all of it, I lack the required education) and decided to write a little >> program myself without using any prefab monad instances that should mimic >> the following: >> main = do >> putStrLn "Enter your name:" >> x <- getLine >> putStr "Welcome " >> putStrLn x >> putStrLn "Goodbye!" >> >> But instead of using IO, I wanted to make my own pure monad that gets >> evaluated with interact, and does the same. >> >> However, I get the following output: >> >> Enter your name: >> Welcome ...... >> >> So the Welcome is printed too soon. >> >> This is obvious since my monad is lazy, so I tried to put a seq at some >> strategic places to get the same behavior as IO. But I completely failed >> doing so, either the program doesn't print anything and asks input first, or >> it still prints too much output. >> >> Of course I could just use ST, State, transformers, etc, but this is >> purely an exercise I'm doing. >> >> So, I could re-read all papers and look in detail at all the code, but >> maybe someone could help me out where to put the seq or what to do :-) >> >> The code is at http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 >> >> Oh btw, the usage of DList here might not be needed; intuitively it felt >> like the correct thing to do, but when it comes to Haskell, my intuition is >> usually wrong ;-) >> >> Thanks a lot, >> Peter Verswyvelen >> >> > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/052c216c/attachment.html From bugfact at gmail.com Wed Aug 19 11:12:07 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 19 10:52:12 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <3e1162e60908190800j3888c2d9jf9f6f8342ba165ec@mail.gmail.com> References: <3e1162e60908190800j3888c2d9jf9f6f8342ba165ec@mail.gmail.com> Message-ID: Thanks, but that doesn't really matter in my example, my code is just buggy, and I'm not sure why. For example if I change my test function so that it outputs lines only, then it still prints Welcome first before asking for input. See e.g. http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328 On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach wrote: > Try LineBuffering. > I do linewise stuff with interact a lot. You'll find stuff like > > unlines . lines > > may help too. In fact I just wrote a blog post about this. > > http://leimy9.blogspot.com > > I'm trying to write some interactive code to automate working with serial > console controlled power strips, so I need to either use Expect (yuck) or do > my own thing. > > Dave > > On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen wrote: > >> Apparently this particular example happens to work on Mac and Linux >> because of different buffering (thanks Martijn for the help!) >> To make sure we have no buffering at all, the main function should be: >> >> main = do hSetBuffering stdout NoBuffering hSetBuffering stdin NoBuffering test >> >> Now I think it should also be *incorrect* on Unix systems. >> >> I guess the way I'm concatenating the strings is not correct, not sure. >> >> I would like to use a graphical tool to show the graph reduction step by >> step, to get a better understanding of the laziness & strictness. Does such >> a tool exist? I know people often say this is not usable because the amount >> of information is too much, but I used to be an assembly language programmer >> so I still would like to give it a try :-) >> >> >> >> On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen wrote: >> >>> In an attempt to get a deeper understanding of several monads (State, ST, >>> IO, ...) I skimmed over some of the research papers (but didn't understand >>> all of it, I lack the required education) and decided to write a little >>> program myself without using any prefab monad instances that should mimic >>> the following: >>> main = do >>> putStrLn "Enter your name:" >>> x <- getLine >>> putStr "Welcome " >>> putStrLn x >>> putStrLn "Goodbye!" >>> >>> But instead of using IO, I wanted to make my own pure monad that gets >>> evaluated with interact, and does the same. >>> >>> However, I get the following output: >>> >>> Enter your name: >>> Welcome ...... >>> >>> So the Welcome is printed too soon. >>> >>> This is obvious since my monad is lazy, so I tried to put a seq at some >>> strategic places to get the same behavior as IO. But I completely failed >>> doing so, either the program doesn't print anything and asks input first, or >>> it still prints too much output. >>> >>> Of course I could just use ST, State, transformers, etc, but this is >>> purely an exercise I'm doing. >>> >>> So, I could re-read all papers and look in detail at all the code, but >>> maybe someone could help me out where to put the seq or what to do :-) >>> >>> The code is at http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 >>> >>> Oh btw, the usage of DList here might not be needed; intuitively it felt >>> like the correct thing to do, but when it comes to Haskell, my intuition is >>> usually wrong ;-) >>> >>> Thanks a lot, >>> Peter Verswyvelen >>> >>> >> >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/6491ce22/attachment.html From colin at colina.demon.co.uk Wed Aug 19 11:13:14 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Wed Aug 19 10:53:23 2009 Subject: [Haskell-cafe] Re: Planning for a website In-Reply-To: <87prasys1a.fsf@gaura-nitai.no-ip.org> (gour@gour-nitai.com's message of "Wed\, 19 Aug 2009 13\:14\:25 +0200") References: <87prasys1a.fsf@gaura-nitai.no-ip.org> Message-ID: >>>>> "Gour" == Gour writes: >>>>> "Colin" == Colin Paul Adams writes: Colin> So my major decision is what framework and html-generating Colin> libraries to use. There is such a wide choice on the Colin> Haskell Wiki. But I guess some are more maintained than Colin> others. For instance, WASH attracts me, with it's guarantee Colin> of valid generated pages, but it isn't clear to me that Colin> it's actively maintained (last date I can see on the web Colin> pages is 2006). Gour> Have you thought about Turbinado (http://turbinado.org) ? I didn't like it when I clicked on the link that says: Learn about Turbinado here and got a this page doesn't exist response. Then I looked at the archticeture link, and didn't like the idea of having to generate Haskell data types from relational tables (if i understood it right). I'd much rather be using happstack's macid stuff, especially as I will have only very low usage, so i shouldn't have any scalability problems. -- Colin Adams Preston Lancashire From colin at colina.demon.co.uk Wed Aug 19 11:21:37 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Wed Aug 19 11:02:16 2009 Subject: [Haskell-cafe] Re: ANN: Typeful/Text/HTMLs (for AngloHaskell/for scrap?) In-Reply-To: (Jon Fairbairn's message of "Wed\, 05 Aug 2009 17\:30\:57 +0100") References: Message-ID: >>>>> "Jon" == Jon Fairbairn writes: Jon> I wrote: >> You can get the whole thing with >> >> darcs get --partial >> http://homepage.ntlworld.com/jon.fairbairn/Typeful/Text/nHTMLs Jon> but that was a temporary url that I copied and pasted. The Jon> correct one: Jon> darcs get --partial Jon> http://homepage.ntlworld.com/jon.fairbairn/Typeful/Text/HTMLs Did you make any progress on this at Anglo-Haskell? Will it be cabal-ized soon? -- Colin Adams Preston Lancashire From leimy2k at gmail.com Wed Aug 19 11:25:27 2009 From: leimy2k at gmail.com (David Leimbach) Date: Wed Aug 19 11:05:33 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908190800j3888c2d9jf9f6f8342ba165ec@mail.gmail.com> Message-ID: <3e1162e60908190825n133f9435gfbfc3110b87688f0@mail.gmail.com> On Wed, Aug 19, 2009 at 8:12 AM, Peter Verswyvelen wrote: > Thanks, but that doesn't really matter in my example, my code is just > buggy, and I'm not sure why. For example if I change my test function so > that it outputs lines only, then it still prints Welcome first before asking > for input. > Ah I see, I misunderstood. Sorry for the noise! ;-) I thought perhaps you'd hit something I ran into last night. Dave > > See e.g. http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328 > > On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach wrote: > >> Try LineBuffering. >> I do linewise stuff with interact a lot. You'll find stuff like >> >> unlines . lines >> >> may help too. In fact I just wrote a blog post about this. >> >> http://leimy9.blogspot.com >> >> I'm trying to write some interactive code to automate working with serial >> console controlled power strips, so I need to either use Expect (yuck) or do >> my own thing. >> >> Dave >> >> On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen wrote: >> >>> Apparently this particular example happens to work on Mac and Linux >>> because of different buffering (thanks Martijn for the help!) >>> To make sure we have no buffering at all, the main function should be: >>> >>> main = do hSetBuffering stdout NoBuffering hSetBuffering stdin NoBuffering test >>> >>> Now I think it should also be *incorrect* on Unix systems. >>> >>> I guess the way I'm concatenating the strings is not correct, not sure. >>> >>> I would like to use a graphical tool to show the graph reduction step by >>> step, to get a better understanding of the laziness & strictness. Does such >>> a tool exist? I know people often say this is not usable because the amount >>> of information is too much, but I used to be an assembly language programmer >>> so I still would like to give it a try :-) >>> >>> >>> >>> On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen wrote: >>> >>>> In an attempt to get a deeper understanding of several monads (State, >>>> ST, IO, ...) I skimmed over some of the research papers (but didn't >>>> understand all of it, I lack the required education) and decided to write a >>>> little program myself without using any prefab monad instances that should >>>> mimic the following: >>>> main = do >>>> putStrLn "Enter your name:" >>>> x <- getLine >>>> putStr "Welcome " >>>> putStrLn x >>>> putStrLn "Goodbye!" >>>> >>>> But instead of using IO, I wanted to make my own pure monad that gets >>>> evaluated with interact, and does the same. >>>> >>>> However, I get the following output: >>>> >>>> Enter your name: >>>> Welcome ...... >>>> >>>> So the Welcome is printed too soon. >>>> >>>> This is obvious since my monad is lazy, so I tried to put a seq at some >>>> strategic places to get the same behavior as IO. But I completely failed >>>> doing so, either the program doesn't print anything and asks input first, or >>>> it still prints too much output. >>>> >>>> Of course I could just use ST, State, transformers, etc, but this is >>>> purely an exercise I'm doing. >>>> >>>> So, I could re-read all papers and look in detail at all the code, but >>>> maybe someone could help me out where to put the seq or what to do :-) >>>> >>>> The code is at http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 >>>> >>>> Oh btw, the usage of DList here might not be needed; intuitively it felt >>>> like the correct thing to do, but when it comes to Haskell, my intuition is >>>> usually wrong ;-) >>>> >>>> Thanks a lot, >>>> Peter Verswyvelen >>>> >>>> >>> >>> _______________________________________________ >>> Haskell-Cafe mailing list >>> Haskell-Cafe@haskell.org >>> http://www.haskell.org/mailman/listinfo/haskell-cafe >>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/304cdcd5/attachment-0001.html From bugfact at gmail.com Wed Aug 19 11:25:43 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 19 11:05:48 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908190800j3888c2d9jf9f6f8342ba165ec@mail.gmail.com> Message-ID: I fixed it myself but it's really tricky :-) http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8330 The idea is, that when the input is requested, the output that is then generated must be in sync with the input. inp = S $ \s i -> let r = (*s** **`**D**.**append**`** **(**i** **`**seq**`** **D**.**empty**)*, head i) in (tail i, r) I first had inp = S $ \s i -> let r = (i `seq` *s*, head i) in (tail i, r) But that was too eager, since i syncs the input not with the output, but with the function that will generate the output. Okay, now I can sleep again :-) On Wed, Aug 19, 2009 at 5:12 PM, Peter Verswyvelen wrote: > Thanks, but that doesn't really matter in my example, my code is just > buggy, and I'm not sure why. For example if I change my test function so > that it outputs lines only, then it still prints Welcome first before asking > for input. > See e.g. http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328 > > On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach wrote: > >> Try LineBuffering. >> I do linewise stuff with interact a lot. You'll find stuff like >> >> unlines . lines >> >> may help too. In fact I just wrote a blog post about this. >> >> http://leimy9.blogspot.com >> >> I'm trying to write some interactive code to automate working with serial >> console controlled power strips, so I need to either use Expect (yuck) or do >> my own thing. >> >> Dave >> >> On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen wrote: >> >>> Apparently this particular example happens to work on Mac and Linux >>> because of different buffering (thanks Martijn for the help!) >>> To make sure we have no buffering at all, the main function should be: >>> >>> main = do hSetBuffering stdout NoBuffering hSetBuffering stdin NoBuffering test >>> >>> Now I think it should also be *incorrect* on Unix systems. >>> >>> I guess the way I'm concatenating the strings is not correct, not sure. >>> >>> I would like to use a graphical tool to show the graph reduction step by >>> step, to get a better understanding of the laziness & strictness. Does such >>> a tool exist? I know people often say this is not usable because the amount >>> of information is too much, but I used to be an assembly language programmer >>> so I still would like to give it a try :-) >>> >>> >>> >>> On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen wrote: >>> >>>> In an attempt to get a deeper understanding of several monads (State, >>>> ST, IO, ...) I skimmed over some of the research papers (but didn't >>>> understand all of it, I lack the required education) and decided to write a >>>> little program myself without using any prefab monad instances that should >>>> mimic the following: >>>> main = do >>>> putStrLn "Enter your name:" >>>> x <- getLine >>>> putStr "Welcome " >>>> putStrLn x >>>> putStrLn "Goodbye!" >>>> >>>> But instead of using IO, I wanted to make my own pure monad that gets >>>> evaluated with interact, and does the same. >>>> >>>> However, I get the following output: >>>> >>>> Enter your name: >>>> Welcome ...... >>>> >>>> So the Welcome is printed too soon. >>>> >>>> This is obvious since my monad is lazy, so I tried to put a seq at some >>>> strategic places to get the same behavior as IO. But I completely failed >>>> doing so, either the program doesn't print anything and asks input first, or >>>> it still prints too much output. >>>> >>>> Of course I could just use ST, State, transformers, etc, but this is >>>> purely an exercise I'm doing. >>>> >>>> So, I could re-read all papers and look in detail at all the code, but >>>> maybe someone could help me out where to put the seq or what to do :-) >>>> >>>> The code is at http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 >>>> >>>> Oh btw, the usage of DList here might not be needed; intuitively it felt >>>> like the correct thing to do, but when it comes to Haskell, my intuition is >>>> usually wrong ;-) >>>> >>>> Thanks a lot, >>>> Peter Verswyvelen >>>> >>>> >>> >>> _______________________________________________ >>> Haskell-Cafe mailing list >>> Haskell-Cafe@haskell.org >>> http://www.haskell.org/mailman/listinfo/haskell-cafe >>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/96008fb9/attachment.html From marco-oweber at gmx.de Wed Aug 19 11:27:55 2009 From: marco-oweber at gmx.de (Marc Weber) Date: Wed Aug 19 11:08:02 2009 Subject: [Haskell-cafe] Re: Planning for a website In-Reply-To: References: <87prasys1a.fsf@gaura-nitai.no-ip.org> Message-ID: <1250695595-sup-5861@nixos> Excerpts from Colin Paul Adams's message of Wed Aug 19 17:13:14 +0200 2009: > I'd much rather be using happstack's macid stuff, especially as I will > have only very low usage, so i shouldn't have any scalability problems. See also this current thread: http://groups.google.com/group/happs/browse_thread/thread/961ab7cc28f1f91f Marc Weber From jon.fairbairn at cl.cam.ac.uk Wed Aug 19 11:36:07 2009 From: jon.fairbairn at cl.cam.ac.uk (Jon Fairbairn) Date: Wed Aug 19 11:16:37 2009 Subject: [Haskell-cafe] Re: ANN: Typeful/Text/HTMLs (for AngloHaskell/for scrap?) References: Message-ID: Colin Paul Adams writes: >>>>>> "Jon" == Jon Fairbairn writes: > Jon> darcs get --partial > Jon> http://homepage.ntlworld.com/jon.fairbairn/Typeful/Text/HTMLs > > Did you make any progress on this at Anglo-Haskell? Not really, owing to Microsoft site security ;-) [not that they were being unreasonable, just that it cut me off rather abruptly]. I've started some notes connected with this at (which as implied is not quite finished), though they are not especially interesting to anyone who simply wants to use the library. > Will it be cabal-ized soon? That depends on whether anyone wants it done sufficiently strongly to do it... at the moment I'm not motivated to learning how to do it (if I get past all the non-programming stuff on my life to-do list, there are several things on the project's TODO list that come before "Caballise"). After all, if I'm the only person using the library, there's no reason to caballise... granted, that smacks of a self fulfilling prophecy, but I'm led to believe that if someone already knows cabal, it would be the work of moments to do the job, whereas learning it would take significant effort? The license would need attention too... in the absence of convincing arguments to the contrary, I would favour GPL myself. [1] And by the time I next wanted to do it, the chances are it would have changed so much (or I would have forgotten it anyway) that I'd have to learn it again. -- J?n Fairbairn Jon.Fairbairn@cl.cam.ac.uk From leimy2k at gmail.com Wed Aug 19 11:38:56 2009 From: leimy2k at gmail.com (David Leimbach) Date: Wed Aug 19 11:19:00 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908190800j3888c2d9jf9f6f8342ba165ec@mail.gmail.com> Message-ID: <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> This doesn't seem to be working for me interactively though on a Mac. I still get "Welcome" before I've entered text. On Wed, Aug 19, 2009 at 8:25 AM, Peter Verswyvelen wrote: > I fixed it myself but it's really tricky :-) > http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8330 > > The idea is, > that when the input is requested, the output that is then generated must be > in sync with the input. > > inp = S $ \s i -> let r = (*s** **`**D**.**append**`** **(**i** **`**seq**`** **D**.**empty**)*, head i) in (tail i, r) > > > > I first had > > inp = S $ \s i -> let r = (i `seq` *s*, head i) in (tail i, r) > > > But that was too eager, since i syncs the input not with the output, but > with the function that will generate the output. > > Okay, now I can sleep again :-) > > > > > On Wed, Aug 19, 2009 at 5:12 PM, Peter Verswyvelen wrote: > >> Thanks, but that doesn't really matter in my example, my code is just >> buggy, and I'm not sure why. For example if I change my test function so >> that it outputs lines only, then it still prints Welcome first before asking >> for input. >> See e.g. http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328 >> >> On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach wrote: >> >>> Try LineBuffering. >>> I do linewise stuff with interact a lot. You'll find stuff like >>> >>> unlines . lines >>> >>> may help too. In fact I just wrote a blog post about this. >>> >>> http://leimy9.blogspot.com >>> >>> I'm trying to write some interactive code to automate working with serial >>> console controlled power strips, so I need to either use Expect (yuck) or do >>> my own thing. >>> >>> Dave >>> >>> On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen wrote: >>> >>>> Apparently this particular example happens to work on Mac and Linux >>>> because of different buffering (thanks Martijn for the help!) >>>> To make sure we have no buffering at all, the main function should be: >>>> >>>> main = do hSetBuffering stdout NoBuffering hSetBuffering stdin NoBuffering test >>>> >>>> Now I think it should also be *incorrect* on Unix systems. >>>> >>>> I guess the way I'm concatenating the strings is not correct, not sure. >>>> >>>> I would like to use a graphical tool to show the graph reduction step by >>>> step, to get a better understanding of the laziness & strictness. Does such >>>> a tool exist? I know people often say this is not usable because the amount >>>> of information is too much, but I used to be an assembly language programmer >>>> so I still would like to give it a try :-) >>>> >>>> >>>> >>>> On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen wrote: >>>> >>>>> In an attempt to get a deeper understanding of several monads (State, >>>>> ST, IO, ...) I skimmed over some of the research papers (but didn't >>>>> understand all of it, I lack the required education) and decided to write a >>>>> little program myself without using any prefab monad instances that should >>>>> mimic the following: >>>>> main = do >>>>> putStrLn "Enter your name:" >>>>> x <- getLine >>>>> putStr "Welcome " >>>>> putStrLn x >>>>> putStrLn "Goodbye!" >>>>> >>>>> But instead of using IO, I wanted to make my own pure monad that gets >>>>> evaluated with interact, and does the same. >>>>> >>>>> However, I get the following output: >>>>> >>>>> Enter your name: >>>>> Welcome ...... >>>>> >>>>> So the Welcome is printed too soon. >>>>> >>>>> This is obvious since my monad is lazy, so I tried to put a seq at some >>>>> strategic places to get the same behavior as IO. But I completely failed >>>>> doing so, either the program doesn't print anything and asks input first, or >>>>> it still prints too much output. >>>>> >>>>> Of course I could just use ST, State, transformers, etc, but this is >>>>> purely an exercise I'm doing. >>>>> >>>>> So, I could re-read all papers and look in detail at all the code, but >>>>> maybe someone could help me out where to put the seq or what to do :-) >>>>> >>>>> The code is at http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 >>>>> >>>>> Oh btw, the usage of DList here might not be needed; intuitively it >>>>> felt like the correct thing to do, but when it comes to Haskell, my >>>>> intuition is usually wrong ;-) >>>>> >>>>> Thanks a lot, >>>>> Peter Verswyvelen >>>>> >>>>> >>>> >>>> _______________________________________________ >>>> Haskell-Cafe mailing list >>>> Haskell-Cafe@haskell.org >>>> http://www.haskell.org/mailman/listinfo/haskell-cafe >>>> >>>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/41b89cf7/attachment.html From leimy2k at gmail.com Wed Aug 19 11:39:54 2009 From: leimy2k at gmail.com (David Leimbach) Date: Wed Aug 19 11:19:57 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> References: <3e1162e60908190800j3888c2d9jf9f6f8342ba165ec@mail.gmail.com> <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> Message-ID: <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> Argh... I too have been up too late :-). I edited THE WRONG FILE! No wonder your change didn't take effect! :-/ Time for coffee I suppose. On Wed, Aug 19, 2009 at 8:38 AM, David Leimbach wrote: > This doesn't seem to be working for me interactively though on a Mac. I > still get "Welcome" before I've entered text. > > > On Wed, Aug 19, 2009 at 8:25 AM, Peter Verswyvelen wrote: > >> I fixed it myself but it's really tricky :-) >> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8330 >> >> The idea is, >> that when the input is requested, the output that is then generated must be >> in sync with the input. >> >> inp = S $ \s i -> let r = (*s** **`**D**.**append**`** **(**i** **`**seq**`** **D**.**empty**)*, head i) in (tail i, r) >> >> >> >> I first had >> >> inp = S $ \s i -> let r = (i `seq` *s*, head i) in (tail i, r) >> >> >> But that was too eager, since i syncs the input not with the output, but >> with the function that will generate the output. >> >> Okay, now I can sleep again :-) >> >> >> >> >> On Wed, Aug 19, 2009 at 5:12 PM, Peter Verswyvelen wrote: >> >>> Thanks, but that doesn't really matter in my example, my code is just >>> buggy, and I'm not sure why. For example if I change my test function so >>> that it outputs lines only, then it still prints Welcome first before asking >>> for input. >>> See e.g. http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328 >>> >>> On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach wrote: >>> >>>> Try LineBuffering. >>>> I do linewise stuff with interact a lot. You'll find stuff like >>>> >>>> unlines . lines >>>> >>>> may help too. In fact I just wrote a blog post about this. >>>> >>>> http://leimy9.blogspot.com >>>> >>>> I'm trying to write some interactive code to automate working with >>>> serial console controlled power strips, so I need to either use Expect >>>> (yuck) or do my own thing. >>>> >>>> Dave >>>> >>>> On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen wrote: >>>> >>>>> Apparently this particular example happens to work on Mac and Linux >>>>> because of different buffering (thanks Martijn for the help!) >>>>> To make sure we have no buffering at all, the main function should be: >>>>> >>>>> main = do hSetBuffering stdout NoBuffering hSetBuffering stdin NoBuffering test >>>>> >>>>> Now I think it should also be *incorrect* on Unix systems. >>>>> >>>>> I guess the way I'm concatenating the strings is not correct, not sure. >>>>> >>>>> I would like to use a graphical tool to show the graph reduction step >>>>> by step, to get a better understanding of the laziness & strictness. Does >>>>> such a tool exist? I know people often say this is not usable because the >>>>> amount of information is too much, but I used to be an assembly language >>>>> programmer so I still would like to give it a try :-) >>>>> >>>>> >>>>> >>>>> On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen wrote: >>>>> >>>>>> In an attempt to get a deeper understanding of several monads (State, >>>>>> ST, IO, ...) I skimmed over some of the research papers (but didn't >>>>>> understand all of it, I lack the required education) and decided to write a >>>>>> little program myself without using any prefab monad instances that should >>>>>> mimic the following: >>>>>> main = do >>>>>> putStrLn "Enter your name:" >>>>>> x <- getLine >>>>>> putStr "Welcome " >>>>>> putStrLn x >>>>>> putStrLn "Goodbye!" >>>>>> >>>>>> But instead of using IO, I wanted to make my own pure monad that gets >>>>>> evaluated with interact, and does the same. >>>>>> >>>>>> However, I get the following output: >>>>>> >>>>>> Enter your name: >>>>>> Welcome ...... >>>>>> >>>>>> So the Welcome is printed too soon. >>>>>> >>>>>> This is obvious since my monad is lazy, so I tried to put a seq at >>>>>> some strategic places to get the same behavior as IO. But I completely >>>>>> failed doing so, either the program doesn't print anything and asks input >>>>>> first, or it still prints too much output. >>>>>> >>>>>> Of course I could just use ST, State, transformers, etc, but this is >>>>>> purely an exercise I'm doing. >>>>>> >>>>>> So, I could re-read all papers and look in detail at all the code, but >>>>>> maybe someone could help me out where to put the seq or what to do :-) >>>>>> >>>>>> The code is at http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 >>>>>> >>>>>> Oh btw, the usage of DList here might not be needed; intuitively it >>>>>> felt like the correct thing to do, but when it comes to Haskell, my >>>>>> intuition is usually wrong ;-) >>>>>> >>>>>> Thanks a lot, >>>>>> Peter Verswyvelen >>>>>> >>>>>> >>>>> >>>>> _______________________________________________ >>>>> Haskell-Cafe mailing list >>>>> Haskell-Cafe@haskell.org >>>>> http://www.haskell.org/mailman/listinfo/haskell-cafe >>>>> >>>>> >>>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/d861cf36/attachment.html From bugfact at gmail.com Wed Aug 19 11:55:56 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 19 11:36:02 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> References: <3e1162e60908190800j3888c2d9jf9f6f8342ba165ec@mail.gmail.com> <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> Message-ID: Not at all, use it for whatever you want to :-) I'm writing this code because I'm preparing to write a bunch of tutorials on FRP, and I first wanted to start with simple console based FRP, e.g. making a little text adventure game, where the input/choices of the user might be parsed ala parsec, using monadic style, applicative style, and arrows, and then doing the same with FRP frameworks like Yampa, Elera, Reactive, etc... After that I would start writing tutorials that use OpenGL, making some very simple games, again with the above approaches, and ending with a conversion of a very old game of mine (Zarathrusta written in assembler from 1991, which was based on Thrust from 1986, converted by myself in C++ to PocketPC as G-Pod, and so I would like to make a version in Haskell that runs on the iPhone :-) This of course is a lot of work, and I would like to put this on the Haskell wiki or a blog or something, so others can contribute and comment. I would like to show real examples that explain the shortcomings of the FRP approaches, because now this is still a bit blurry to me. On Wed, Aug 19, 2009 at 5:43 PM, David Leimbach wrote: > This Monad you've created is quite excellent. I was trying to do something > like this about a year ago, to make the input and output handling of an > interactive bowling score card work nicely. I kept running into issues, and > did not believe that seq was going to do the trick. Nice work! > This is a very useful monad I think, it could be called "Prompter" or > something to that effect. > > Do you mind if I use it in some of my code? > > Dave > > > On Wed, Aug 19, 2009 at 8:42 AM, Peter Verswyvelen wrote: > >> LOL. Maybe we should have that coffee together ;-) at least virtually! >> >> On Wed, Aug 19, 2009 at 5:39 PM, David Leimbach wrote: >> >>> Argh... I too have been up too late :-). I edited THE WRONG FILE! No >>> wonder your change didn't take effect! :-/ >>> Time for coffee I suppose. >>> >>> >>> On Wed, Aug 19, 2009 at 8:38 AM, David Leimbach wrote: >>> >>>> This doesn't seem to be working for me interactively though on a Mac. I >>>> still get "Welcome" before I've entered text. >>>> >>>> >>>> On Wed, Aug 19, 2009 at 8:25 AM, Peter Verswyvelen wrote: >>>> >>>>> I fixed it myself but it's really tricky :-) >>>>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8330 >>>>> >>>>> The idea is, >>>>> that when the input is requested, the output that is then generated must be >>>>> in sync with the input. >>>>> >>>>> inp = S $ \s i -> let r = (*s** **`**D**.**append**`** **(**i** **`**seq**`** **D**.**empty**)*, head i) in (tail i, r) >>>>> >>>>> >>>>> >>>>> I first had >>>>> >>>>> inp = S $ \s i -> let r = (i `seq` *s*, head i) in (tail i, r) >>>>> >>>>> >>>>> But that was too eager, since i syncs the input not with the output, >>>>> but with the function that will generate the output. >>>>> >>>>> Okay, now I can sleep again :-) >>>>> >>>>> >>>>> >>>>> >>>>> On Wed, Aug 19, 2009 at 5:12 PM, Peter Verswyvelen wrote: >>>>> >>>>>> Thanks, but that doesn't really matter in my example, my code is just >>>>>> buggy, and I'm not sure why. For example if I change my test function so >>>>>> that it outputs lines only, then it still prints Welcome first before asking >>>>>> for input. >>>>>> See e.g. http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328 >>>>>> >>>>>> On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach wrote: >>>>>> >>>>>>> Try LineBuffering. >>>>>>> I do linewise stuff with interact a lot. You'll find stuff like >>>>>>> >>>>>>> unlines . lines >>>>>>> >>>>>>> may help too. In fact I just wrote a blog post about this. >>>>>>> >>>>>>> http://leimy9.blogspot.com >>>>>>> >>>>>>> I'm trying to write some interactive code to automate working with >>>>>>> serial console controlled power strips, so I need to either use Expect >>>>>>> (yuck) or do my own thing. >>>>>>> >>>>>>> Dave >>>>>>> >>>>>>> On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen < >>>>>>> bugfact@gmail.com> wrote: >>>>>>> >>>>>>>> Apparently this particular example happens to work on Mac and Linux >>>>>>>> because of different buffering (thanks Martijn for the help!) >>>>>>>> To make sure we have no buffering at all, the main function should >>>>>>>> be: >>>>>>>> >>>>>>>> main = do hSetBuffering stdout NoBuffering hSetBuffering stdin NoBuffering test >>>>>>>> >>>>>>>> Now I think it should also be *incorrect* on Unix systems. >>>>>>>> >>>>>>>> I guess the way I'm concatenating the strings is not correct, not >>>>>>>> sure. >>>>>>>> >>>>>>>> I would like to use a graphical tool to show the graph reduction >>>>>>>> step by step, to get a better understanding of the laziness & strictness. >>>>>>>> Does such a tool exist? I know people often say this is not usable because >>>>>>>> the amount of information is too much, but I used to be an assembly language >>>>>>>> programmer so I still would like to give it a try :-) >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen < >>>>>>>> bugfact@gmail.com> wrote: >>>>>>>> >>>>>>>>> In an attempt to get a deeper understanding of several monads >>>>>>>>> (State, ST, IO, ...) I skimmed over some of the research papers (but didn't >>>>>>>>> understand all of it, I lack the required education) and decided to write a >>>>>>>>> little program myself without using any prefab monad instances that should >>>>>>>>> mimic the following: >>>>>>>>> main = do >>>>>>>>> putStrLn "Enter your name:" >>>>>>>>> x <- getLine >>>>>>>>> putStr "Welcome " >>>>>>>>> putStrLn x >>>>>>>>> putStrLn "Goodbye!" >>>>>>>>> >>>>>>>>> But instead of using IO, I wanted to make my own pure monad that >>>>>>>>> gets evaluated with interact, and does the same. >>>>>>>>> >>>>>>>>> However, I get the following output: >>>>>>>>> >>>>>>>>> Enter your name: >>>>>>>>> Welcome ...... >>>>>>>>> >>>>>>>>> So the Welcome is printed too soon. >>>>>>>>> >>>>>>>>> This is obvious since my monad is lazy, so I tried to put a seq at >>>>>>>>> some strategic places to get the same behavior as IO. But I completely >>>>>>>>> failed doing so, either the program doesn't print anything and asks input >>>>>>>>> first, or it still prints too much output. >>>>>>>>> >>>>>>>>> Of course I could just use ST, State, transformers, etc, but this >>>>>>>>> is purely an exercise I'm doing. >>>>>>>>> >>>>>>>>> So, I could re-read all papers and look in detail at all the code, >>>>>>>>> but maybe someone could help me out where to put the seq or what to do :-) >>>>>>>>> >>>>>>>>> The code is at http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 >>>>>>>>> >>>>>>>>> Oh btw, the usage of DList here might not be needed; intuitively it >>>>>>>>> felt like the correct thing to do, but when it comes to Haskell, my >>>>>>>>> intuition is usually wrong ;-) >>>>>>>>> >>>>>>>>> Thanks a lot, >>>>>>>>> Peter Verswyvelen >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> Haskell-Cafe mailing list >>>>>>>> Haskell-Cafe@haskell.org >>>>>>>> http://www.haskell.org/mailman/listinfo/haskell-cafe >>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>> >>>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/cd823387/attachment.html From colin at colina.demon.co.uk Wed Aug 19 11:57:16 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Wed Aug 19 11:37:57 2009 Subject: [Haskell-cafe] Re: ANN: Typeful/Text/HTMLs (for AngloHaskell/for scrap?) In-Reply-To: (Jon Fairbairn's message of "Wed\, 19 Aug 2009 16\:36\:07 +0100") References: Message-ID: >>>>> "Jon" == Jon Fairbairn writes: >> Will it be cabal-ized soon? Jon> That depends on whether anyone wants it done sufficiently Jon> strongly to do it. Then I guess I will - some time in October. -- Colin Adams Preston Lancashire From bugfact at gmail.com Wed Aug 19 12:28:16 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 19 12:08:21 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908190800j3888c2d9jf9f6f8342ba165ec@mail.gmail.com> <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> Message-ID: Expect more bugs with this though :-) Just found out that looping does not work, it hangs, e.g. test = do out "Enter your first name:" fstName <- inp out "Enter your second name:" sndName <- inp out ("Welcome "++fstName++" "++sndName) out "Goodbye!"* **test* Doesn't seem to work :-) Back to the drawing board. On Wed, Aug 19, 2009 at 5:55 PM, Peter Verswyvelen wrote: > Not at all, use it for whatever you want to :-) > I'm writing this code because I'm preparing to write a bunch of tutorials > on FRP, and I first wanted to start with simple console based FRP, e.g. > making a little text adventure game, where the input/choices of the user > might be parsed ala parsec, using monadic style, applicative style, and > arrows, and then doing the same with FRP frameworks like Yampa, Elera, > Reactive, etc... > > After that I would start writing tutorials that use OpenGL, making some > very simple games, again with the above approaches, and ending with a > conversion of a very old game of mine (Zarathrusta written in assembler from > 1991, which was based on Thrustfrom 1986, converted by myself in C++ to PocketPC as > G-Pod, > and so I would like to make a version in Haskell that runs on the iPhone :-) > > This of course is a lot of work, and I would like to put this on the > Haskell wiki or a blog or something, so others can contribute and comment. I > would like to show real examples that explain the shortcomings of the FRP > approaches, because now this is still a bit blurry to me. > > > > On Wed, Aug 19, 2009 at 5:43 PM, David Leimbach wrote: > >> This Monad you've created is quite excellent. I was trying to do >> something like this about a year ago, to make the input and output handling >> of an interactive bowling score card work nicely. I kept running into >> issues, and did not believe that seq was going to do the trick. Nice work! >> This is a very useful monad I think, it could be called "Prompter" or >> something to that effect. >> >> Do you mind if I use it in some of my code? >> >> Dave >> >> >> On Wed, Aug 19, 2009 at 8:42 AM, Peter Verswyvelen wrote: >> >>> LOL. Maybe we should have that coffee together ;-) at least virtually! >>> >>> On Wed, Aug 19, 2009 at 5:39 PM, David Leimbach wrote: >>> >>>> Argh... I too have been up too late :-). I edited THE WRONG FILE! No >>>> wonder your change didn't take effect! :-/ >>>> Time for coffee I suppose. >>>> >>>> >>>> On Wed, Aug 19, 2009 at 8:38 AM, David Leimbach wrote: >>>> >>>>> This doesn't seem to be working for me interactively though on a Mac. >>>>> I still get "Welcome" before I've entered text. >>>>> >>>>> >>>>> On Wed, Aug 19, 2009 at 8:25 AM, Peter Verswyvelen wrote: >>>>> >>>>>> I fixed it myself but it's really tricky :-) >>>>>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8330 >>>>>> >>>>>> The idea >>>>>> is, that when the input is requested, the output that is then generated must >>>>>> be in sync with the input. >>>>>> >>>>>> inp = S $ \s i -> let r = (*s** **`**D**.**append**`** **(**i** **`**seq**`** **D**.**empty**)*, head i) in (tail i, r) >>>>>> >>>>>> >>>>>> >>>>>> I first had >>>>>> >>>>>> inp = S $ \s i -> let r = (i `seq` *s*, head i) in (tail i, r) >>>>>> >>>>>> >>>>>> But that was too eager, since i syncs the input not with the output, >>>>>> but with the function that will generate the output. >>>>>> >>>>>> Okay, now I can sleep again :-) >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> On Wed, Aug 19, 2009 at 5:12 PM, Peter Verswyvelen >>>>> > wrote: >>>>>> >>>>>>> Thanks, but that doesn't really matter in my example, my code is just >>>>>>> buggy, and I'm not sure why. For example if I change my test function so >>>>>>> that it outputs lines only, then it still prints Welcome first before asking >>>>>>> for input. >>>>>>> See e.g. http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328 >>>>>>> >>>>>>> On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach wrote: >>>>>>> >>>>>>>> Try LineBuffering. >>>>>>>> I do linewise stuff with interact a lot. You'll find stuff like >>>>>>>> >>>>>>>> unlines . lines >>>>>>>> >>>>>>>> may help too. In fact I just wrote a blog post about this. >>>>>>>> >>>>>>>> http://leimy9.blogspot.com >>>>>>>> >>>>>>>> I'm trying to write some interactive code to automate working with >>>>>>>> serial console controlled power strips, so I need to either use Expect >>>>>>>> (yuck) or do my own thing. >>>>>>>> >>>>>>>> Dave >>>>>>>> >>>>>>>> On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen < >>>>>>>> bugfact@gmail.com> wrote: >>>>>>>> >>>>>>>>> Apparently this particular example happens to work on Mac and Linux >>>>>>>>> because of different buffering (thanks Martijn for the help!) >>>>>>>>> To make sure we have no buffering at all, the main function should >>>>>>>>> be: >>>>>>>>> >>>>>>>>> main = do hSetBuffering stdout NoBuffering hSetBuffering stdin NoBuffering test >>>>>>>>> >>>>>>>>> Now I think it should also be *incorrect* on Unix systems. >>>>>>>>> >>>>>>>>> I guess the way I'm concatenating the strings is not correct, not >>>>>>>>> sure. >>>>>>>>> >>>>>>>>> I would like to use a graphical tool to show the graph reduction >>>>>>>>> step by step, to get a better understanding of the laziness & strictness. >>>>>>>>> Does such a tool exist? I know people often say this is not usable because >>>>>>>>> the amount of information is too much, but I used to be an assembly language >>>>>>>>> programmer so I still would like to give it a try :-) >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen < >>>>>>>>> bugfact@gmail.com> wrote: >>>>>>>>> >>>>>>>>>> In an attempt to get a deeper understanding of several monads >>>>>>>>>> (State, ST, IO, ...) I skimmed over some of the research papers (but didn't >>>>>>>>>> understand all of it, I lack the required education) and decided to write a >>>>>>>>>> little program myself without using any prefab monad instances that should >>>>>>>>>> mimic the following: >>>>>>>>>> main = do >>>>>>>>>> putStrLn "Enter your name:" >>>>>>>>>> x <- getLine >>>>>>>>>> putStr "Welcome " >>>>>>>>>> putStrLn x >>>>>>>>>> putStrLn "Goodbye!" >>>>>>>>>> >>>>>>>>>> But instead of using IO, I wanted to make my own pure monad that >>>>>>>>>> gets evaluated with interact, and does the same. >>>>>>>>>> >>>>>>>>>> However, I get the following output: >>>>>>>>>> >>>>>>>>>> Enter your name: >>>>>>>>>> Welcome ...... >>>>>>>>>> >>>>>>>>>> So the Welcome is printed too soon. >>>>>>>>>> >>>>>>>>>> This is obvious since my monad is lazy, so I tried to put a seq at >>>>>>>>>> some strategic places to get the same behavior as IO. But I completely >>>>>>>>>> failed doing so, either the program doesn't print anything and asks input >>>>>>>>>> first, or it still prints too much output. >>>>>>>>>> >>>>>>>>>> Of course I could just use ST, State, transformers, etc, but this >>>>>>>>>> is purely an exercise I'm doing. >>>>>>>>>> >>>>>>>>>> So, I could re-read all papers and look in detail at all the code, >>>>>>>>>> but maybe someone could help me out where to put the seq or what to do :-) >>>>>>>>>> >>>>>>>>>> The code is at http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 >>>>>>>>>> >>>>>>>>>> Oh btw, the usage of DList here might not be needed; intuitively >>>>>>>>>> it felt like the correct thing to do, but when it comes to Haskell, my >>>>>>>>>> intuition is usually wrong ;-) >>>>>>>>>> >>>>>>>>>> Thanks a lot, >>>>>>>>>> Peter Verswyvelen >>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>>> _______________________________________________ >>>>>>>>> Haskell-Cafe mailing list >>>>>>>>> Haskell-Cafe@haskell.org >>>>>>>>> http://www.haskell.org/mailman/listinfo/haskell-cafe >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>> >>>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/6a4c5841/attachment-0001.html From leimy2k at gmail.com Wed Aug 19 12:31:32 2009 From: leimy2k at gmail.com (David Leimbach) Date: Wed Aug 19 12:11:38 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908190800j3888c2d9jf9f6f8342ba165ec@mail.gmail.com> <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> Message-ID: <3e1162e60908190931q6e2a36eam22ec1bb78e6691a7@mail.gmail.com> Have you spoken to Conal Elliott about this stuff? He might be interested. He was looking for doing this sort of thing on iPhones for a bit. Also, I was wondering if you thought this Monad might be useful as a way to automate tasks in an Expect like fashion. I've been struggling with a good way to do this stuff in Haskell for a while. One challenge is that input is not always line oriented, for example the "Password: " token that we get when we use ssh interactively. My first thought was to try to avoid seq, and use "words" and "unwords". However, I'm thinking now that I'm going to need new Monad Operations like inp, but for different token sizes and possibly different matches of characters. Dave On Wed, Aug 19, 2009 at 8:55 AM, Peter Verswyvelen wrote: > Not at all, use it for whatever you want to :-) > I'm writing this code because I'm preparing to write a bunch of tutorials > on FRP, and I first wanted to start with simple console based FRP, e.g. > making a little text adventure game, where the input/choices of the user > might be parsed ala parsec, using monadic style, applicative style, and > arrows, and then doing the same with FRP frameworks like Yampa, Elera, > Reactive, etc... > > After that I would start writing tutorials that use OpenGL, making some > very simple games, again with the above approaches, and ending with a > conversion of a very old game of mine (Zarathrusta written in assembler from > 1991, which was based on Thrustfrom 1986, converted by myself in C++ to PocketPC as > G-Pod, > and so I would like to make a version in Haskell that runs on the iPhone :-) > > This of course is a lot of work, and I would like to put this on the > Haskell wiki or a blog or something, so others can contribute and comment. I > would like to show real examples that explain the shortcomings of the FRP > approaches, because now this is still a bit blurry to me. > > > > On Wed, Aug 19, 2009 at 5:43 PM, David Leimbach wrote: > >> This Monad you've created is quite excellent. I was trying to do >> something like this about a year ago, to make the input and output handling >> of an interactive bowling score card work nicely. I kept running into >> issues, and did not believe that seq was going to do the trick. Nice work! >> This is a very useful monad I think, it could be called "Prompter" or >> something to that effect. >> >> Do you mind if I use it in some of my code? >> >> Dave >> >> >> On Wed, Aug 19, 2009 at 8:42 AM, Peter Verswyvelen wrote: >> >>> LOL. Maybe we should have that coffee together ;-) at least virtually! >>> >>> On Wed, Aug 19, 2009 at 5:39 PM, David Leimbach wrote: >>> >>>> Argh... I too have been up too late :-). I edited THE WRONG FILE! No >>>> wonder your change didn't take effect! :-/ >>>> Time for coffee I suppose. >>>> >>>> >>>> On Wed, Aug 19, 2009 at 8:38 AM, David Leimbach wrote: >>>> >>>>> This doesn't seem to be working for me interactively though on a Mac. >>>>> I still get "Welcome" before I've entered text. >>>>> >>>>> >>>>> On Wed, Aug 19, 2009 at 8:25 AM, Peter Verswyvelen wrote: >>>>> >>>>>> I fixed it myself but it's really tricky :-) >>>>>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8330 >>>>>> >>>>>> The idea >>>>>> is, that when the input is requested, the output that is then generated must >>>>>> be in sync with the input. >>>>>> >>>>>> inp = S $ \s i -> let r = (*s** **`**D**.**append**`** **(**i** **`**seq**`** **D**.**empty**)*, head i) in (tail i, r) >>>>>> >>>>>> >>>>>> >>>>>> I first had >>>>>> >>>>>> inp = S $ \s i -> let r = (i `seq` *s*, head i) in (tail i, r) >>>>>> >>>>>> >>>>>> But that was too eager, since i syncs the input not with the output, >>>>>> but with the function that will generate the output. >>>>>> >>>>>> Okay, now I can sleep again :-) >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> On Wed, Aug 19, 2009 at 5:12 PM, Peter Verswyvelen >>>>> > wrote: >>>>>> >>>>>>> Thanks, but that doesn't really matter in my example, my code is just >>>>>>> buggy, and I'm not sure why. For example if I change my test function so >>>>>>> that it outputs lines only, then it still prints Welcome first before asking >>>>>>> for input. >>>>>>> See e.g. http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328 >>>>>>> >>>>>>> On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach wrote: >>>>>>> >>>>>>>> Try LineBuffering. >>>>>>>> I do linewise stuff with interact a lot. You'll find stuff like >>>>>>>> >>>>>>>> unlines . lines >>>>>>>> >>>>>>>> may help too. In fact I just wrote a blog post about this. >>>>>>>> >>>>>>>> http://leimy9.blogspot.com >>>>>>>> >>>>>>>> I'm trying to write some interactive code to automate working with >>>>>>>> serial console controlled power strips, so I need to either use Expect >>>>>>>> (yuck) or do my own thing. >>>>>>>> >>>>>>>> Dave >>>>>>>> >>>>>>>> On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen < >>>>>>>> bugfact@gmail.com> wrote: >>>>>>>> >>>>>>>>> Apparently this particular example happens to work on Mac and Linux >>>>>>>>> because of different buffering (thanks Martijn for the help!) >>>>>>>>> To make sure we have no buffering at all, the main function should >>>>>>>>> be: >>>>>>>>> >>>>>>>>> main = do hSetBuffering stdout NoBuffering hSetBuffering stdin NoBuffering test >>>>>>>>> >>>>>>>>> Now I think it should also be *incorrect* on Unix systems. >>>>>>>>> >>>>>>>>> I guess the way I'm concatenating the strings is not correct, not >>>>>>>>> sure. >>>>>>>>> >>>>>>>>> I would like to use a graphical tool to show the graph reduction >>>>>>>>> step by step, to get a better understanding of the laziness & strictness. >>>>>>>>> Does such a tool exist? I know people often say this is not usable because >>>>>>>>> the amount of information is too much, but I used to be an assembly language >>>>>>>>> programmer so I still would like to give it a try :-) >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen < >>>>>>>>> bugfact@gmail.com> wrote: >>>>>>>>> >>>>>>>>>> In an attempt to get a deeper understanding of several monads >>>>>>>>>> (State, ST, IO, ...) I skimmed over some of the research papers (but didn't >>>>>>>>>> understand all of it, I lack the required education) and decided to write a >>>>>>>>>> little program myself without using any prefab monad instances that should >>>>>>>>>> mimic the following: >>>>>>>>>> main = do >>>>>>>>>> putStrLn "Enter your name:" >>>>>>>>>> x <- getLine >>>>>>>>>> putStr "Welcome " >>>>>>>>>> putStrLn x >>>>>>>>>> putStrLn "Goodbye!" >>>>>>>>>> >>>>>>>>>> But instead of using IO, I wanted to make my own pure monad that >>>>>>>>>> gets evaluated with interact, and does the same. >>>>>>>>>> >>>>>>>>>> However, I get the following output: >>>>>>>>>> >>>>>>>>>> Enter your name: >>>>>>>>>> Welcome ...... >>>>>>>>>> >>>>>>>>>> So the Welcome is printed too soon. >>>>>>>>>> >>>>>>>>>> This is obvious since my monad is lazy, so I tried to put a seq at >>>>>>>>>> some strategic places to get the same behavior as IO. But I completely >>>>>>>>>> failed doing so, either the program doesn't print anything and asks input >>>>>>>>>> first, or it still prints too much output. >>>>>>>>>> >>>>>>>>>> Of course I could just use ST, State, transformers, etc, but this >>>>>>>>>> is purely an exercise I'm doing. >>>>>>>>>> >>>>>>>>>> So, I could re-read all papers and look in detail at all the code, >>>>>>>>>> but maybe someone could help me out where to put the seq or what to do :-) >>>>>>>>>> >>>>>>>>>> The code is at http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 >>>>>>>>>> >>>>>>>>>> Oh btw, the usage of DList here might not be needed; intuitively >>>>>>>>>> it felt like the correct thing to do, but when it comes to Haskell, my >>>>>>>>>> intuition is usually wrong ;-) >>>>>>>>>> >>>>>>>>>> Thanks a lot, >>>>>>>>>> Peter Verswyvelen >>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>>> _______________________________________________ >>>>>>>>> Haskell-Cafe mailing list >>>>>>>>> Haskell-Cafe@haskell.org >>>>>>>>> http://www.haskell.org/mailman/listinfo/haskell-cafe >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>> >>>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/b39f10db/attachment.html From leimy2k at gmail.com Wed Aug 19 12:40:39 2009 From: leimy2k at gmail.com (David Leimbach) Date: Wed Aug 19 12:20:42 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908190800j3888c2d9jf9f6f8342ba165ec@mail.gmail.com> <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> Message-ID: <3e1162e60908190940r3804490dgbc10032caaad792@mail.gmail.com> Yet this does work interact $ run test9 test9 = replicateM 9 test Will run test 9 times. I suppose if one constructed an infinite list you could loop as you wanted to. Yet, that might not be what you want. Dave On Wed, Aug 19, 2009 at 9:28 AM, Peter Verswyvelen wrote: > Expect more bugs with this though :-) Just found out that looping does not > work, it hangs, e.g. > > test = do out "Enter your first name:" fstName <- inp out "Enter your second name:" sndName <- inp out ("Welcome "++fstName++" "++sndName) out "Goodbye!"* **test* > > Doesn't seem to work :-) Back to the drawing board. > > > On Wed, Aug 19, 2009 at 5:55 PM, Peter Verswyvelen wrote: > >> Not at all, use it for whatever you want to :-) >> I'm writing this code because I'm preparing to write a bunch of tutorials >> on FRP, and I first wanted to start with simple console based FRP, e.g. >> making a little text adventure game, where the input/choices of the user >> might be parsed ala parsec, using monadic style, applicative style, and >> arrows, and then doing the same with FRP frameworks like Yampa, Elera, >> Reactive, etc... >> >> After that I would start writing tutorials that use OpenGL, making some >> very simple games, again with the above approaches, and ending with a >> conversion of a very old game of mine (Zarathrusta written in assembler from >> 1991, which was based on Thrustfrom 1986, converted by myself in C++ to PocketPC as >> G-Pod, >> and so I would like to make a version in Haskell that runs on the iPhone :-) >> >> This of course is a lot of work, and I would like to put this on the >> Haskell wiki or a blog or something, so others can contribute and comment. I >> would like to show real examples that explain the shortcomings of the FRP >> approaches, because now this is still a bit blurry to me. >> >> >> >> On Wed, Aug 19, 2009 at 5:43 PM, David Leimbach wrote: >> >>> This Monad you've created is quite excellent. I was trying to do >>> something like this about a year ago, to make the input and output handling >>> of an interactive bowling score card work nicely. I kept running into >>> issues, and did not believe that seq was going to do the trick. Nice work! >>> This is a very useful monad I think, it could be called "Prompter" or >>> something to that effect. >>> >>> Do you mind if I use it in some of my code? >>> >>> Dave >>> >>> >>> On Wed, Aug 19, 2009 at 8:42 AM, Peter Verswyvelen wrote: >>> >>>> LOL. Maybe we should have that coffee together ;-) at least virtually! >>>> >>>> On Wed, Aug 19, 2009 at 5:39 PM, David Leimbach wrote: >>>> >>>>> Argh... I too have been up too late :-). I edited THE WRONG FILE! No >>>>> wonder your change didn't take effect! :-/ >>>>> Time for coffee I suppose. >>>>> >>>>> >>>>> On Wed, Aug 19, 2009 at 8:38 AM, David Leimbach wrote: >>>>> >>>>>> This doesn't seem to be working for me interactively though on a Mac. >>>>>> I still get "Welcome" before I've entered text. >>>>>> >>>>>> >>>>>> On Wed, Aug 19, 2009 at 8:25 AM, Peter Verswyvelen >>>>> > wrote: >>>>>> >>>>>>> I fixed it myself but it's really tricky :-) >>>>>>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8330 >>>>>>> >>>>>>> The idea >>>>>>> is, that when the input is requested, the output that is then generated must >>>>>>> be in sync with the input. >>>>>>> >>>>>>> inp = S $ \s i -> let r = (*s** **`**D**.**append**`** **(**i** **`**seq**`** **D**.**empty**)*, head i) in (tail i, r) >>>>>>> >>>>>>> >>>>>>> >>>>>>> I first had >>>>>>> >>>>>>> inp = S $ \s i -> let r = (i `seq` *s*, head i) in (tail i, r) >>>>>>> >>>>>>> >>>>>>> But that was too eager, since i syncs the input not with the output, >>>>>>> but with the function that will generate the output. >>>>>>> >>>>>>> Okay, now I can sleep again :-) >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> On Wed, Aug 19, 2009 at 5:12 PM, Peter Verswyvelen < >>>>>>> bugfact@gmail.com> wrote: >>>>>>> >>>>>>>> Thanks, but that doesn't really matter in my example, my code is >>>>>>>> just buggy, and I'm not sure why. For example if I change my test function >>>>>>>> so that it outputs lines only, then it still prints Welcome first before >>>>>>>> asking for input. >>>>>>>> See e.g. http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328 >>>>>>>> >>>>>>>> On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach wrote: >>>>>>>> >>>>>>>>> Try LineBuffering. >>>>>>>>> I do linewise stuff with interact a lot. You'll find stuff like >>>>>>>>> >>>>>>>>> unlines . lines >>>>>>>>> >>>>>>>>> may help too. In fact I just wrote a blog post about this. >>>>>>>>> >>>>>>>>> http://leimy9.blogspot.com >>>>>>>>> >>>>>>>>> I'm trying to write some interactive code to automate working with >>>>>>>>> serial console controlled power strips, so I need to either use Expect >>>>>>>>> (yuck) or do my own thing. >>>>>>>>> >>>>>>>>> Dave >>>>>>>>> >>>>>>>>> On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen < >>>>>>>>> bugfact@gmail.com> wrote: >>>>>>>>> >>>>>>>>>> Apparently this particular example happens to work on Mac and >>>>>>>>>> Linux because of different buffering (thanks Martijn for the help!) >>>>>>>>>> To make sure we have no buffering at all, the main function should >>>>>>>>>> be: >>>>>>>>>> >>>>>>>>>> main = do hSetBuffering stdout NoBuffering hSetBuffering stdin NoBuffering test >>>>>>>>>> >>>>>>>>>> Now I think it should also be *incorrect* on Unix systems. >>>>>>>>>> >>>>>>>>>> I guess the way I'm concatenating the strings is not correct, not >>>>>>>>>> sure. >>>>>>>>>> >>>>>>>>>> I would like to use a graphical tool to show the graph reduction >>>>>>>>>> step by step, to get a better understanding of the laziness & strictness. >>>>>>>>>> Does such a tool exist? I know people often say this is not usable because >>>>>>>>>> the amount of information is too much, but I used to be an assembly language >>>>>>>>>> programmer so I still would like to give it a try :-) >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen < >>>>>>>>>> bugfact@gmail.com> wrote: >>>>>>>>>> >>>>>>>>>>> In an attempt to get a deeper understanding of several monads >>>>>>>>>>> (State, ST, IO, ...) I skimmed over some of the research papers (but didn't >>>>>>>>>>> understand all of it, I lack the required education) and decided to write a >>>>>>>>>>> little program myself without using any prefab monad instances that should >>>>>>>>>>> mimic the following: >>>>>>>>>>> main = do >>>>>>>>>>> putStrLn "Enter your name:" >>>>>>>>>>> x <- getLine >>>>>>>>>>> putStr "Welcome " >>>>>>>>>>> putStrLn x >>>>>>>>>>> putStrLn "Goodbye!" >>>>>>>>>>> >>>>>>>>>>> But instead of using IO, I wanted to make my own pure monad that >>>>>>>>>>> gets evaluated with interact, and does the same. >>>>>>>>>>> >>>>>>>>>>> However, I get the following output: >>>>>>>>>>> >>>>>>>>>>> Enter your name: >>>>>>>>>>> Welcome ...... >>>>>>>>>>> >>>>>>>>>>> So the Welcome is printed too soon. >>>>>>>>>>> >>>>>>>>>>> This is obvious since my monad is lazy, so I tried to put a seq >>>>>>>>>>> at some strategic places to get the same behavior as IO. But I completely >>>>>>>>>>> failed doing so, either the program doesn't print anything and asks input >>>>>>>>>>> first, or it still prints too much output. >>>>>>>>>>> >>>>>>>>>>> Of course I could just use ST, State, transformers, etc, but this >>>>>>>>>>> is purely an exercise I'm doing. >>>>>>>>>>> >>>>>>>>>>> So, I could re-read all papers and look in detail at all the >>>>>>>>>>> code, but maybe someone could help me out where to put the seq or what to do >>>>>>>>>>> :-) >>>>>>>>>>> >>>>>>>>>>> The code is at >>>>>>>>>>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 >>>>>>>>>>> >>>>>>>>>>> Oh btw, the usage of DList here might not be needed; intuitively >>>>>>>>>>> it felt like the correct thing to do, but when it comes to Haskell, my >>>>>>>>>>> intuition is usually wrong ;-) >>>>>>>>>>> >>>>>>>>>>> Thanks a lot, >>>>>>>>>>> Peter Verswyvelen >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> >>>>>>>>>> _______________________________________________ >>>>>>>>>> Haskell-Cafe mailing list >>>>>>>>>> Haskell-Cafe@haskell.org >>>>>>>>>> http://www.haskell.org/mailman/listinfo/haskell-cafe >>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>> >>>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/51d8709e/attachment.html From jupdike at gmail.com Wed Aug 19 12:45:28 2009 From: jupdike at gmail.com (Jared Updike) Date: Wed Aug 19 12:25:31 2009 Subject: [Haskell-cafe] Haddock: Failed to create dependency graph (when adding sections with * or a module heading) Message-ID: <8b108f950908190945m747b0df3m8bffdc81ed220a01@mail.gmail.com> I compiled and installed haddock-2.4.2 from the tarball source. Adding a few simple comments to the code here: https://dl.getdropbox.com/u/143480/doc/DualMap.hs and running haddock $ haddock -h -o doc Data/DualMap.hs Warning: Data.DualMap: could not find link destinations for: Data.Typeable.Typeable2 GHC.Base.Eq GHC.Show.Show GHC.Base.Ord GHC.Base.Bool Data.Set.Set yields: https://dl.getdropbox.com/u/143480/doc/Data-DualMap.html Things look good. (Note that this module only depends on libs that ship with GHC and no other source modules.) However, when I try to add sections (a la http://www.haskell.org/haddock/doc/html/ch03s04.html#id289234 ) in the comments with "-- * test" I get: $ haddock -h -o doc Data/DualMap.hs Data/DualMap.hs:20:0: parse error on input `-- * test' haddock: Failed to create dependency graph I have no idea where to begin getting this to work since this error message only tells me that Haddock.Interface.depanal returned Nothing (according to a grep of the haddock sources) but not how to stop the dependency analysis from failing. Perhaps I need some more command line arguments or references to missing link destinations in GHC/base/containers documentation or some haddock config file? Searching Google yielded plenty of cabal build errors of the same ilk for packages on hackage but nothing about how to fix them. Jared. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/4d65cb1f/attachment.html From ekmett at gmail.com Wed Aug 19 13:19:17 2009 From: ekmett at gmail.com (Edward Kmett) Date: Wed Aug 19 12:59:20 2009 Subject: [Haskell-cafe] Observations about foldM In-Reply-To: <5e0214850908190732k3226ea3csd0ab39cf88d4cbbe@mail.gmail.com> References: <20090819041424.GC1103@quaternion> <200908190904.34080.dan.doel@gmail.com> <5e0214850908190732k3226ea3csd0ab39cf88d4cbbe@mail.gmail.com> Message-ID: <7fb8f82f0908191019n2f0a8f52s369d36e8e870c04c@mail.gmail.com> It is associativity that is required, not commutativity (in addition to the fact that the list is finite). This is why Data.Foldable provides operations for monoids over containers. Monoids just provide you with associativity and a unit, which lets you reparenthesize the fold however you want. See the monoids library or my slides from hac-phi for lots of (ab)uses of a monoid's associativity. http://comonad.com/reader/2009/hac-phi-slides/ -Edward Kmett On Wed, Aug 19, 2009 at 10:32 AM, Eugene Kirpichov wrote: > 2009/8/19 Dan Doel : > > On Wednesday 19 August 2009 12:14:24 am Jason McCarty wrote: > >> Interestingly, foldM can also be written as a left fold. To see this, > note > >> that it is a theorem that foldr f z xs = foldl f z xs as long as f is > >> associative and z is a unit for f. > > > > This is not true: f has to be commutative, not associative. > > Consider matrix multiplication. > > > It must also be the case that xs is finite in length, because if it is > > infinite, then 'foldl f z xs' is bottom, while 'foldr f z xs' needn't be. > This > > difference holds over into foldM implemented with each, where you can > write > > something like: > > > > foldM (\f e -> if even e then Left (show e) else Right f) "no evens" > [1..] > > > > and get an answer of 'Left "2"' with a foldr implementation, but bottom > with a > > foldl implementation. > > > > This potentially translates into its own performance concerns, because in > such > > monads, the computation can short-circuit upon finding a 'throw' when > using > > the foldr implementation, but with the foldl implementation, you have to > do at > > least a little shuffling of thunks for the entire list. > > > > -- Dan > > _______________________________________________ > > Haskell-Cafe mailing list > > Haskell-Cafe@haskell.org > > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > > > > -- > Eugene Kirpichov > Web IR developer, market.yandex.ru > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/96e5c54a/attachment.html From ryani.spam at gmail.com Wed Aug 19 13:23:12 2009 From: ryani.spam at gmail.com (Ryan Ingram) Date: Wed Aug 19 13:03:15 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908190800j3888c2d9jf9f6f8342ba165ec@mail.gmail.com> <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> Message-ID: <2f9b2d30908191023s2c11aa72m47fa8729868f6f23@mail.gmail.com> I posted a reply to your paste with a stricter version of S and some cleanup. Untested, though I believe it should work without "seq". "case" provides all the strictness you need, I think! -- ryan On Wed, Aug 19, 2009 at 9:28 AM, Peter Verswyvelen wrote: > Expect more bugs with this though :-) Just found out that looping does not > work, it hangs, e.g. > > test = do > out "Enter your first name:" > fstName <- inp > out "Enter your second name:" > sndName <- inp > out ("Welcome "++fstName++" "++sndName) > out "Goodbye!" > test > > Doesn't seem to work :-) Back to the drawing board. > > On Wed, Aug 19, 2009 at 5:55 PM, Peter Verswyvelen > wrote: >> >> Not at all, use it for whatever you want to :-) >> I'm writing this code because I'm preparing to write a bunch of tutorials >> on FRP, and I first wanted to start with simple console based FRP, e.g. >> making a little text adventure game, where the input/choices of the user >> might be parsed ala parsec, using monadic style, applicative style, and >> arrows, and then doing the same with FRP frameworks like Yampa, Elera, >> Reactive, etc... >> After that I would start writing tutorials that use OpenGL, making some >> very simple games, again with the above approaches, and ending with a >> conversion of a very old game of mine (Zarathrusta written in assembler from >> 1991, which was based on Thrust from 1986, converted by myself in C++ to >> PocketPC as G-Pod, and so I would like to make a version in Haskell that >> runs on the iPhone :-) >> This of course is a lot of work, and I would like to put this on the >> Haskell wiki or a blog or something, so others can contribute and comment. I >> would like to show real examples that explain the shortcomings of the FRP >> approaches, because now this is still a bit blurry to me. >> >> On Wed, Aug 19, 2009 at 5:43 PM, David Leimbach wrote: >>> >>> This Monad you've created is quite excellent. ?I was trying to do >>> something like this about a year ago, to make the input and output handling >>> of an interactive bowling score card work nicely. ?I kept running into >>> issues, and did not believe that seq was going to do the trick. ?Nice work! >>> This is a very useful monad I think, it could be called "Prompter" or >>> something to that effect. >>> Do you mind if I use it in some of my code? >>> Dave >>> >>> On Wed, Aug 19, 2009 at 8:42 AM, Peter Verswyvelen >>> wrote: >>>> >>>> LOL. Maybe we should have that coffee together ;-) at least virtually! >>>> On Wed, Aug 19, 2009 at 5:39 PM, David Leimbach >>>> wrote: >>>>> >>>>> Argh... I too have been up too late :-). ?I edited THE WRONG FILE! ?No >>>>> wonder your change didn't take effect! ?:-/ >>>>> Time for coffee I suppose. >>>>> >>>>> On Wed, Aug 19, 2009 at 8:38 AM, David Leimbach >>>>> wrote: >>>>>> >>>>>> This doesn't seem to be working for me interactively though on a Mac. >>>>>> ?I still get "Welcome" before I've entered text. >>>>>> >>>>>> On Wed, Aug 19, 2009 at 8:25 AM, Peter Verswyvelen >>>>>> wrote: >>>>>>> >>>>>>> I fixed it myself but it's really tricky :-) >>>>>>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8330 >>>>>>> The idea is, that when the input is requested, the output that is >>>>>>> then generated must be in sync with the input. >>>>>>> >>>>>>> inp = S $ \s i -> let r = (s `D.append` (i `seq` D.empty), head i) in >>>>>>> (tail i, r) >>>>>>> >>>>>>> >>>>>>> I first had >>>>>>> >>>>>>> inp = S $ \s i -> let r = (i `seq` s, head i) in (tail i, r) >>>>>>> >>>>>>> But that was too eager, since i syncs the input not with the output, >>>>>>> but with the function that will generate the output. >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> Okay, now I can sleep again :-) >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> On Wed, Aug 19, 2009 at 5:12 PM, Peter Verswyvelen >>>>>>> wrote: >>>>>>>> >>>>>>>> Thanks, but that doesn't really matter in my example, my code is >>>>>>>> just buggy, and I'm not sure why. For example if I change my test function >>>>>>>> so that it outputs lines only, then it still prints Welcome first before >>>>>>>> asking for input. >>>>>>>> See e.g.?http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328 >>>>>>>> On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach >>>>>>>> wrote: >>>>>>>>> >>>>>>>>> Try LineBuffering. >>>>>>>>> I do linewise stuff with interact a lot. ?You'll find stuff like >>>>>>>>> unlines . lines >>>>>>>>> may help too. ?In fact I just wrote a blog post about this. >>>>>>>>> http://leimy9.blogspot.com >>>>>>>>> I'm trying to write some interactive code to automate working with >>>>>>>>> serial console controlled power strips, so I need to either use Expect >>>>>>>>> (yuck) or do my own thing. >>>>>>>>> Dave >>>>>>>>> >>>>>>>>> On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen >>>>>>>>> wrote: >>>>>>>>>> >>>>>>>>>> Apparently this particular example happens to work on Mac and >>>>>>>>>> Linux because of different buffering (thanks Martijn for the help!) >>>>>>>>>> To make sure we have no buffering at all, the main function should >>>>>>>>>> be: >>>>>>>>>> >>>>>>>>>> main = do >>>>>>>>>> hSetBuffering stdout NoBuffering >>>>>>>>>> hSetBuffering stdin NoBuffering >>>>>>>>>> test >>>>>>>>>> >>>>>>>>>> Now I think it should also be incorrect on Unix systems. >>>>>>>>>> I guess the way I'm concatenating the strings is not correct, not >>>>>>>>>> sure. >>>>>>>>>> I would like to use a graphical tool to show the graph reduction >>>>>>>>>> step by step, to get a better understanding of the laziness & strictness. >>>>>>>>>> Does such a tool exist? I know people often say this is not usable because >>>>>>>>>> the amount of information is too much, but I used to be an assembly language >>>>>>>>>> programmer so I still would like to give it a try :-) >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen >>>>>>>>>> wrote: >>>>>>>>>>> >>>>>>>>>>> In an attempt to get a deeper understanding of several monads >>>>>>>>>>> (State, ST, IO, ...) I skimmed over some of the research papers (but didn't >>>>>>>>>>> understand all of it, I lack the required education) and decided to write a >>>>>>>>>>> little program myself without using any prefab monad instances that should >>>>>>>>>>> mimic the following: >>>>>>>>>>> main = do >>>>>>>>>>> ??putStrLn "Enter your name:" >>>>>>>>>>> ??x <- getLine >>>>>>>>>>> ??putStr "Welcome " >>>>>>>>>>> ??putStrLn x >>>>>>>>>>> ??putStrLn "Goodbye!" >>>>>>>>>>> But instead of using IO, I wanted to make my own pure monad that >>>>>>>>>>> gets evaluated with interact, and does the same. >>>>>>>>>>> However, I get the following output: >>>>>>>>>>> Enter your name: >>>>>>>>>>> Welcome ...... >>>>>>>>>>> So the Welcome is printed too soon. >>>>>>>>>>> This is obvious since my monad is lazy, so I tried to put a seq >>>>>>>>>>> at some strategic places to get the same behavior as IO. But I completely >>>>>>>>>>> failed doing so, either the program doesn't print anything and asks input >>>>>>>>>>> first, or it still prints too much output. >>>>>>>>>>> Of course I could just use ST, State, transformers, etc, but this >>>>>>>>>>> is purely an exercise I'm doing. >>>>>>>>>>> So, I could re-read all papers and look in detail at all the >>>>>>>>>>> code, but maybe someone could help me out where to put the seq or what to do >>>>>>>>>>> :-) >>>>>>>>>>> The code is at?http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 >>>>>>>>>>> Oh btw, the usage of DList here might not be needed; intuitively >>>>>>>>>>> it felt like the correct thing to do, but when it comes to Haskell, my >>>>>>>>>>> intuition is usually wrong ;-) >>>>>>>>>>> Thanks a lot, >>>>>>>>>>> Peter Verswyvelen >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> _______________________________________________ >>>>>>>>>> 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 iainspeed at gmail.com Wed Aug 19 13:31:18 2009 From: iainspeed at gmail.com (Iain Barnett) Date: Wed Aug 19 13:11:22 2009 Subject: [Haskell-cafe] gbp sign showing as unknown character by GHC Message-ID: Quick question: I've tested this in a couple of different terminals (roxterm and xterm), so I'm fairly sure it's GHC that's the problem. Have I missed a setting? GHCi, version 6.10.4 Prelude> putStrLn "?" ? Hugs98 200609-3 Hugs> putStrLn "?" ? I get the same character output from a password generator I've writtern, after compilation with GHC [iainb]$ ./makepass2 50 2 >> testfile.txt [iainb]$ cat testfile.txt H(xW!:maNyxZ;h,IW=Uu4G$ztc>k@Q[g6?y:?TbG&5Nd")+"5+ Iain -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/009e8ed0/attachment.html From leimy2k at gmail.com Wed Aug 19 13:31:53 2009 From: leimy2k at gmail.com (David Leimbach) Date: Wed Aug 19 13:11:58 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <2f9b2d30908191023s2c11aa72m47fa8729868f6f23@mail.gmail.com> References: <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <2f9b2d30908191023s2c11aa72m47fa8729868f6f23@mail.gmail.com> Message-ID: <3e1162e60908191031t63795c4apfbd47820647016ab@mail.gmail.com> Doesn't seem to compile. I nearly never use case statements in my code, so I'm not really sure what's going on. neat2.hs:14:39: parse error on input `=' Dave On Wed, Aug 19, 2009 at 10:23 AM, Ryan Ingram wrote: > I posted a reply to your paste with a stricter version of S and some > cleanup. > > Untested, though I believe it should work without "seq". > > "case" provides all the strictness you need, I think! > > -- ryan > > On Wed, Aug 19, 2009 at 9:28 AM, Peter Verswyvelen > wrote: > > Expect more bugs with this though :-) Just found out that looping does > not > > work, it hangs, e.g. > > > > test = do > > out "Enter your first name:" > > fstName <- inp > > out "Enter your second name:" > > sndName <- inp > > out ("Welcome "++fstName++" "++sndName) > > out "Goodbye!" > > test > > > > Doesn't seem to work :-) Back to the drawing board. > > > > On Wed, Aug 19, 2009 at 5:55 PM, Peter Verswyvelen > > wrote: > >> > >> Not at all, use it for whatever you want to :-) > >> I'm writing this code because I'm preparing to write a bunch of > tutorials > >> on FRP, and I first wanted to start with simple console based FRP, e.g. > >> making a little text adventure game, where the input/choices of the user > >> might be parsed ala parsec, using monadic style, applicative style, and > >> arrows, and then doing the same with FRP frameworks like Yampa, Elera, > >> Reactive, etc... > >> After that I would start writing tutorials that use OpenGL, making some > >> very simple games, again with the above approaches, and ending with a > >> conversion of a very old game of mine (Zarathrusta written in assembler > from > >> 1991, which was based on Thrust from 1986, converted by myself in C++ to > >> PocketPC as G-Pod, and so I would like to make a version in Haskell that > >> runs on the iPhone :-) > >> This of course is a lot of work, and I would like to put this on the > >> Haskell wiki or a blog or something, so others can contribute and > comment. I > >> would like to show real examples that explain the shortcomings of the > FRP > >> approaches, because now this is still a bit blurry to me. > >> > >> On Wed, Aug 19, 2009 at 5:43 PM, David Leimbach > wrote: > >>> > >>> This Monad you've created is quite excellent. I was trying to do > >>> something like this about a year ago, to make the input and output > handling > >>> of an interactive bowling score card work nicely. I kept running into > >>> issues, and did not believe that seq was going to do the trick. Nice > work! > >>> This is a very useful monad I think, it could be called "Prompter" or > >>> something to that effect. > >>> Do you mind if I use it in some of my code? > >>> Dave > >>> > >>> On Wed, Aug 19, 2009 at 8:42 AM, Peter Verswyvelen > >>> wrote: > >>>> > >>>> LOL. Maybe we should have that coffee together ;-) at least virtually! > >>>> On Wed, Aug 19, 2009 at 5:39 PM, David Leimbach > >>>> wrote: > >>>>> > >>>>> Argh... I too have been up too late :-). I edited THE WRONG FILE! > No > >>>>> wonder your change didn't take effect! :-/ > >>>>> Time for coffee I suppose. > >>>>> > >>>>> On Wed, Aug 19, 2009 at 8:38 AM, David Leimbach > >>>>> wrote: > >>>>>> > >>>>>> This doesn't seem to be working for me interactively though on a > Mac. > >>>>>> I still get "Welcome" before I've entered text. > >>>>>> > >>>>>> On Wed, Aug 19, 2009 at 8:25 AM, Peter Verswyvelen < > bugfact@gmail.com> > >>>>>> wrote: > >>>>>>> > >>>>>>> I fixed it myself but it's really tricky :-) > >>>>>>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8330 > >>>>>>> The idea is, that when the input is requested, the output that is > >>>>>>> then generated must be in sync with the input. > >>>>>>> > >>>>>>> inp = S $ \s i -> let r = (s `D.append` (i `seq` D.empty), head i) > in > >>>>>>> (tail i, r) > >>>>>>> > >>>>>>> > >>>>>>> I first had > >>>>>>> > >>>>>>> inp = S $ \s i -> let r = (i `seq` s, head i) in (tail i, r) > >>>>>>> > >>>>>>> But that was too eager, since i syncs the input not with the > output, > >>>>>>> but with the function that will generate the output. > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> Okay, now I can sleep again :-) > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> On Wed, Aug 19, 2009 at 5:12 PM, Peter Verswyvelen > >>>>>>> wrote: > >>>>>>>> > >>>>>>>> Thanks, but that doesn't really matter in my example, my code is > >>>>>>>> just buggy, and I'm not sure why. For example if I change my test > function > >>>>>>>> so that it outputs lines only, then it still prints Welcome first > before > >>>>>>>> asking for input. > >>>>>>>> See e.g. http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328 > >>>>>>>> On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach < > leimy2k@gmail.com> > >>>>>>>> wrote: > >>>>>>>>> > >>>>>>>>> Try LineBuffering. > >>>>>>>>> I do linewise stuff with interact a lot. You'll find stuff like > >>>>>>>>> unlines . lines > >>>>>>>>> may help too. In fact I just wrote a blog post about this. > >>>>>>>>> http://leimy9.blogspot.com > >>>>>>>>> I'm trying to write some interactive code to automate working > with > >>>>>>>>> serial console controlled power strips, so I need to either use > Expect > >>>>>>>>> (yuck) or do my own thing. > >>>>>>>>> Dave > >>>>>>>>> > >>>>>>>>> On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen > >>>>>>>>> wrote: > >>>>>>>>>> > >>>>>>>>>> Apparently this particular example happens to work on Mac and > >>>>>>>>>> Linux because of different buffering (thanks Martijn for the > help!) > >>>>>>>>>> To make sure we have no buffering at all, the main function > should > >>>>>>>>>> be: > >>>>>>>>>> > >>>>>>>>>> main = do > >>>>>>>>>> hSetBuffering stdout NoBuffering > >>>>>>>>>> hSetBuffering stdin NoBuffering > >>>>>>>>>> test > >>>>>>>>>> > >>>>>>>>>> Now I think it should also be incorrect on Unix systems. > >>>>>>>>>> I guess the way I'm concatenating the strings is not correct, > not > >>>>>>>>>> sure. > >>>>>>>>>> I would like to use a graphical tool to show the graph reduction > >>>>>>>>>> step by step, to get a better understanding of the laziness & > strictness. > >>>>>>>>>> Does such a tool exist? I know people often say this is not > usable because > >>>>>>>>>> the amount of information is too much, but I used to be an > assembly language > >>>>>>>>>> programmer so I still would like to give it a try :-) > >>>>>>>>>> > >>>>>>>>>> > >>>>>>>>>> On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen > >>>>>>>>>> wrote: > >>>>>>>>>>> > >>>>>>>>>>> In an attempt to get a deeper understanding of several monads > >>>>>>>>>>> (State, ST, IO, ...) I skimmed over some of the research papers > (but didn't > >>>>>>>>>>> understand all of it, I lack the required education) and > decided to write a > >>>>>>>>>>> little program myself without using any prefab monad instances > that should > >>>>>>>>>>> mimic the following: > >>>>>>>>>>> main = do > >>>>>>>>>>> putStrLn "Enter your name:" > >>>>>>>>>>> x <- getLine > >>>>>>>>>>> putStr "Welcome " > >>>>>>>>>>> putStrLn x > >>>>>>>>>>> putStrLn "Goodbye!" > >>>>>>>>>>> But instead of using IO, I wanted to make my own pure monad > that > >>>>>>>>>>> gets evaluated with interact, and does the same. > >>>>>>>>>>> However, I get the following output: > >>>>>>>>>>> Enter your name: > >>>>>>>>>>> Welcome ...... > >>>>>>>>>>> So the Welcome is printed too soon. > >>>>>>>>>>> This is obvious since my monad is lazy, so I tried to put a seq > >>>>>>>>>>> at some strategic places to get the same behavior as IO. But I > completely > >>>>>>>>>>> failed doing so, either the program doesn't print anything and > asks input > >>>>>>>>>>> first, or it still prints too much output. > >>>>>>>>>>> Of course I could just use ST, State, transformers, etc, but > this > >>>>>>>>>>> is purely an exercise I'm doing. > >>>>>>>>>>> So, I could re-read all papers and look in detail at all the > >>>>>>>>>>> code, but maybe someone could help me out where to put the seq > or what to do > >>>>>>>>>>> :-) > >>>>>>>>>>> The code is at > http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 > >>>>>>>>>>> Oh btw, the usage of DList here might not be needed; > intuitively > >>>>>>>>>>> it felt like the correct thing to do, but when it comes to > Haskell, my > >>>>>>>>>>> intuition is usually wrong ;-) > >>>>>>>>>>> Thanks a lot, > >>>>>>>>>>> Peter Verswyvelen > >>>>>>>>>> > >>>>>>>>>> > >>>>>>>>>> _______________________________________________ > >>>>>>>>>> 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 > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/327abc95/attachment-0001.html From leimy2k at gmail.com Wed Aug 19 13:37:39 2009 From: leimy2k at gmail.com (David Leimbach) Date: Wed Aug 19 13:17:42 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <3e1162e60908191031t63795c4apfbd47820647016ab@mail.gmail.com> References: <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <2f9b2d30908191023s2c11aa72m47fa8729868f6f23@mail.gmail.com> <3e1162e60908191031t63795c4apfbd47820647016ab@mail.gmail.com> Message-ID: <3e1162e60908191037m5c79d589ia78db27dd1449ae8@mail.gmail.com> I've corrected it. It still doesn't suffer looping. :-) On Wed, Aug 19, 2009 at 10:31 AM, David Leimbach wrote: > Doesn't seem to compile. > I nearly never use case statements in my code, so I'm not really sure > what's going on. > > neat2.hs:14:39: parse error on input `=' > > Dave > > On Wed, Aug 19, 2009 at 10:23 AM, Ryan Ingram wrote: > >> I posted a reply to your paste with a stricter version of S and some >> cleanup. >> >> Untested, though I believe it should work without "seq". >> >> "case" provides all the strictness you need, I think! >> >> -- ryan >> >> On Wed, Aug 19, 2009 at 9:28 AM, Peter Verswyvelen >> wrote: >> > Expect more bugs with this though :-) Just found out that looping does >> not >> > work, it hangs, e.g. >> > >> > test = do >> > out "Enter your first name:" >> > fstName <- inp >> > out "Enter your second name:" >> > sndName <- inp >> > out ("Welcome "++fstName++" "++sndName) >> > out "Goodbye!" >> > test >> > >> > Doesn't seem to work :-) Back to the drawing board. >> > >> > On Wed, Aug 19, 2009 at 5:55 PM, Peter Verswyvelen >> > wrote: >> >> >> >> Not at all, use it for whatever you want to :-) >> >> I'm writing this code because I'm preparing to write a bunch of >> tutorials >> >> on FRP, and I first wanted to start with simple console based FRP, e.g. >> >> making a little text adventure game, where the input/choices of the >> user >> >> might be parsed ala parsec, using monadic style, applicative style, and >> >> arrows, and then doing the same with FRP frameworks like Yampa, Elera, >> >> Reactive, etc... >> >> After that I would start writing tutorials that use OpenGL, making some >> >> very simple games, again with the above approaches, and ending with a >> >> conversion of a very old game of mine (Zarathrusta written in assembler >> from >> >> 1991, which was based on Thrust from 1986, converted by myself in C++ >> to >> >> PocketPC as G-Pod, and so I would like to make a version in Haskell >> that >> >> runs on the iPhone :-) >> >> This of course is a lot of work, and I would like to put this on the >> >> Haskell wiki or a blog or something, so others can contribute and >> comment. I >> >> would like to show real examples that explain the shortcomings of the >> FRP >> >> approaches, because now this is still a bit blurry to me. >> >> >> >> On Wed, Aug 19, 2009 at 5:43 PM, David Leimbach >> wrote: >> >>> >> >>> This Monad you've created is quite excellent. I was trying to do >> >>> something like this about a year ago, to make the input and output >> handling >> >>> of an interactive bowling score card work nicely. I kept running into >> >>> issues, and did not believe that seq was going to do the trick. Nice >> work! >> >>> This is a very useful monad I think, it could be called "Prompter" or >> >>> something to that effect. >> >>> Do you mind if I use it in some of my code? >> >>> Dave >> >>> >> >>> On Wed, Aug 19, 2009 at 8:42 AM, Peter Verswyvelen > > >> >>> wrote: >> >>>> >> >>>> LOL. Maybe we should have that coffee together ;-) at least >> virtually! >> >>>> On Wed, Aug 19, 2009 at 5:39 PM, David Leimbach >> >>>> wrote: >> >>>>> >> >>>>> Argh... I too have been up too late :-). I edited THE WRONG FILE! >> No >> >>>>> wonder your change didn't take effect! :-/ >> >>>>> Time for coffee I suppose. >> >>>>> >> >>>>> On Wed, Aug 19, 2009 at 8:38 AM, David Leimbach >> >>>>> wrote: >> >>>>>> >> >>>>>> This doesn't seem to be working for me interactively though on a >> Mac. >> >>>>>> I still get "Welcome" before I've entered text. >> >>>>>> >> >>>>>> On Wed, Aug 19, 2009 at 8:25 AM, Peter Verswyvelen < >> bugfact@gmail.com> >> >>>>>> wrote: >> >>>>>>> >> >>>>>>> I fixed it myself but it's really tricky :-) >> >>>>>>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8330 >> >>>>>>> The idea is, that when the input is requested, the output that is >> >>>>>>> then generated must be in sync with the input. >> >>>>>>> >> >>>>>>> inp = S $ \s i -> let r = (s `D.append` (i `seq` D.empty), head i) >> in >> >>>>>>> (tail i, r) >> >>>>>>> >> >>>>>>> >> >>>>>>> I first had >> >>>>>>> >> >>>>>>> inp = S $ \s i -> let r = (i `seq` s, head i) in (tail i, r) >> >>>>>>> >> >>>>>>> But that was too eager, since i syncs the input not with the >> output, >> >>>>>>> but with the function that will generate the output. >> >>>>>>> >> >>>>>>> >> >>>>>>> >> >>>>>>> >> >>>>>>> >> >>>>>>> >> >>>>>>> >> >>>>>>> Okay, now I can sleep again :-) >> >>>>>>> >> >>>>>>> >> >>>>>>> >> >>>>>>> >> >>>>>>> >> >>>>>>> >> >>>>>>> >> >>>>>>> >> >>>>>>> >> >>>>>>> >> >>>>>>> On Wed, Aug 19, 2009 at 5:12 PM, Peter Verswyvelen >> >>>>>>> wrote: >> >>>>>>>> >> >>>>>>>> Thanks, but that doesn't really matter in my example, my code is >> >>>>>>>> just buggy, and I'm not sure why. For example if I change my test >> function >> >>>>>>>> so that it outputs lines only, then it still prints Welcome first >> before >> >>>>>>>> asking for input. >> >>>>>>>> See e.g. >> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328 >> >>>>>>>> On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach < >> leimy2k@gmail.com> >> >>>>>>>> wrote: >> >>>>>>>>> >> >>>>>>>>> Try LineBuffering. >> >>>>>>>>> I do linewise stuff with interact a lot. You'll find stuff like >> >>>>>>>>> unlines . lines >> >>>>>>>>> may help too. In fact I just wrote a blog post about this. >> >>>>>>>>> http://leimy9.blogspot.com >> >>>>>>>>> I'm trying to write some interactive code to automate working >> with >> >>>>>>>>> serial console controlled power strips, so I need to either use >> Expect >> >>>>>>>>> (yuck) or do my own thing. >> >>>>>>>>> Dave >> >>>>>>>>> >> >>>>>>>>> On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen >> >>>>>>>>> wrote: >> >>>>>>>>>> >> >>>>>>>>>> Apparently this particular example happens to work on Mac and >> >>>>>>>>>> Linux because of different buffering (thanks Martijn for the >> help!) >> >>>>>>>>>> To make sure we have no buffering at all, the main function >> should >> >>>>>>>>>> be: >> >>>>>>>>>> >> >>>>>>>>>> main = do >> >>>>>>>>>> hSetBuffering stdout NoBuffering >> >>>>>>>>>> hSetBuffering stdin NoBuffering >> >>>>>>>>>> test >> >>>>>>>>>> >> >>>>>>>>>> Now I think it should also be incorrect on Unix systems. >> >>>>>>>>>> I guess the way I'm concatenating the strings is not correct, >> not >> >>>>>>>>>> sure. >> >>>>>>>>>> I would like to use a graphical tool to show the graph >> reduction >> >>>>>>>>>> step by step, to get a better understanding of the laziness & >> strictness. >> >>>>>>>>>> Does such a tool exist? I know people often say this is not >> usable because >> >>>>>>>>>> the amount of information is too much, but I used to be an >> assembly language >> >>>>>>>>>> programmer so I still would like to give it a try :-) >> >>>>>>>>>> >> >>>>>>>>>> >> >>>>>>>>>> On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen >> >>>>>>>>>> wrote: >> >>>>>>>>>>> >> >>>>>>>>>>> In an attempt to get a deeper understanding of several monads >> >>>>>>>>>>> (State, ST, IO, ...) I skimmed over some of the research >> papers (but didn't >> >>>>>>>>>>> understand all of it, I lack the required education) and >> decided to write a >> >>>>>>>>>>> little program myself without using any prefab monad instances >> that should >> >>>>>>>>>>> mimic the following: >> >>>>>>>>>>> main = do >> >>>>>>>>>>> putStrLn "Enter your name:" >> >>>>>>>>>>> x <- getLine >> >>>>>>>>>>> putStr "Welcome " >> >>>>>>>>>>> putStrLn x >> >>>>>>>>>>> putStrLn "Goodbye!" >> >>>>>>>>>>> But instead of using IO, I wanted to make my own pure monad >> that >> >>>>>>>>>>> gets evaluated with interact, and does the same. >> >>>>>>>>>>> However, I get the following output: >> >>>>>>>>>>> Enter your name: >> >>>>>>>>>>> Welcome ...... >> >>>>>>>>>>> So the Welcome is printed too soon. >> >>>>>>>>>>> This is obvious since my monad is lazy, so I tried to put a >> seq >> >>>>>>>>>>> at some strategic places to get the same behavior as IO. But I >> completely >> >>>>>>>>>>> failed doing so, either the program doesn't print anything and >> asks input >> >>>>>>>>>>> first, or it still prints too much output. >> >>>>>>>>>>> Of course I could just use ST, State, transformers, etc, but >> this >> >>>>>>>>>>> is purely an exercise I'm doing. >> >>>>>>>>>>> So, I could re-read all papers and look in detail at all the >> >>>>>>>>>>> code, but maybe someone could help me out where to put the seq >> or what to do >> >>>>>>>>>>> :-) >> >>>>>>>>>>> The code is at >> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 >> >>>>>>>>>>> Oh btw, the usage of DList here might not be needed; >> intuitively >> >>>>>>>>>>> it felt like the correct thing to do, but when it comes to >> Haskell, my >> >>>>>>>>>>> intuition is usually wrong ;-) >> >>>>>>>>>>> Thanks a lot, >> >>>>>>>>>>> Peter Verswyvelen >> >>>>>>>>>> >> >>>>>>>>>> >> >>>>>>>>>> _______________________________________________ >> >>>>>>>>>> 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 >> > >> > >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/42bd5fa9/attachment.html From ekirpichov at gmail.com Wed Aug 19 13:46:09 2009 From: ekirpichov at gmail.com (Eugene Kirpichov) Date: Wed Aug 19 13:26:12 2009 Subject: [Haskell-cafe] Observations about foldM In-Reply-To: <200908191644.52887.daniel.is.fischer@web.de> References: <20090819041424.GC1103@quaternion> <200908190904.34080.dan.doel@gmail.com> <5e0214850908190732k3226ea3csd0ab39cf88d4cbbe@mail.gmail.com> <200908191644.52887.daniel.is.fischer@web.de> Message-ID: <5e0214850908191046h408ec48atcb8ab5974a7ae8ea@mail.gmail.com> You're right. My bad, indeed. 2009/8/19 Daniel Fischer : > Am Mittwoch 19 August 2009 16:32:57 schrieb Eugene Kirpichov: >> 2009/8/19 Dan Doel : >> > On Wednesday 19 August 2009 12:14:24 am Jason McCarty wrote: >> >> Interestingly, foldM can also be written as a left fold. To see this, >> >> note that it is a theorem that foldr f z xs = foldl f z xs as long as f >> >> is associative and z is a unit for f. >> >> This is not true: f has to be commutative, not associative. >> >> Consider matrix multiplication. >> > > It is true: > foldr: A1*(A2*(... *AN*E)) > foldl: (...((E*A1)*A2)*...*AN) > > Commutativity doesn't help, consider > > data Foo = Z | A | B > > (~) :: Foo -> Foo -> Foo > Z ~ x = x > x ~ Z = x > B ~ B = A > _ ~ _ = B > > (~) is commutative, but not associative, Z is a unit for (~). > > foldr (~) Z [A,A,B] = B > foldl (~) Z [A,A,B] = A > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Eugene Kirpichov Web IR developer, market.yandex.ru From iainspeed at gmail.com Wed Aug 19 14:08:04 2009 From: iainspeed at gmail.com (Iain Barnett) Date: Wed Aug 19 13:48:07 2009 Subject: [Haskell-cafe] gbp sign showing as unknown character by GHC In-Reply-To: <3e1162e60908191039w7daeca17p13d4c79c549c6244@mail.gmail.com> References: <3e1162e60908191039w7daeca17p13d4c79c549c6244@mail.gmail.com> Message-ID: 2009/8/19 David Leimbach > Interesting... GHCI bug? Didn't the readline dependency go away not too > long ago? Could it be related? > I just tried this Prelude> putStrLn "\?" ghc: panic! (the 'impossible' happened) (GHC version 6.10.4 for i386-unknown-linux): charType: '\163' Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug So perhaps I should put in a bug report, as that shouldn't happen (it doesn't with some other characters I tried), unless anyone has a different idea? I'm running Arch Linux with xmonad and using roxterm, so perhaps it's something to do with my setup? Iain -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/d46de6bc/attachment.html From alexander.dunlap at gmail.com Wed Aug 19 14:16:26 2009 From: alexander.dunlap at gmail.com (Alexander Dunlap) Date: Wed Aug 19 13:56:48 2009 Subject: [Haskell-cafe] gbp sign showing as unknown character by GHC In-Reply-To: References: <3e1162e60908191039w7daeca17p13d4c79c549c6244@mail.gmail.com> Message-ID: <57526e770908191116q420a2efdude077719189d57b0@mail.gmail.com> On Wed, Aug 19, 2009 at 11:08 AM, Iain Barnett wrote: > > > 2009/8/19 David Leimbach >> >> Interesting... GHCI bug? ?Didn't the readline dependency go away not too >> long ago? ?Could it be related? > > I just tried this > Prelude> putStrLn "\?" > ghc: panic! (the 'impossible' happened) > ??(GHC version 6.10.4 for i386-unknown-linux): > charType: '\163' > Please report this as a GHC bug: ?http://www.haskell.org/ghc/reportabug > > So perhaps I should put in a bug report, as that shouldn't happen (it > doesn't with some other characters I tried), unless anyone has a different > idea? I'm running Arch Linux with xmonad and using roxterm, so perhaps it's > something to do with my setup? > Iain > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > I can reproduce the panic on both urxvt and uxterm. On urxvt, GHCi works correctly with putStrLn "?". On uxterm, it just prints a blank space. I can type the GBP sign into both terminals. Could it be a terminfo problem of some sort? It seems suspicious that there is a difference between terminals. Alex From bugfact at gmail.com Wed Aug 19 14:28:52 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 19 14:08:57 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <3e1162e60908191037m5c79d589ia78db27dd1449ae8@mail.gmail.com> References: <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <2f9b2d30908191023s2c11aa72m47fa8729868f6f23@mail.gmail.com> <3e1162e60908191031t63795c4apfbd47820647016ab@mail.gmail.com> <3e1162e60908191037m5c79d589ia78db27dd1449ae8@mail.gmail.com> Message-ID: The cleaned up code didn't seem to work for me, it printed everything before asking input again. But I added a patch that looks like it supports looping, but I don't understand exactly what is going on :-) I added the "delay" function which makes appending to the output less strict. Note that in this version I add a delay to each right argument of >>=, but one could also do it manually On Wed, Aug 19, 2009 at 7:37 PM, David Leimbach wrote: > I've corrected it. It still doesn't suffer looping. :-) > > > On Wed, Aug 19, 2009 at 10:31 AM, David Leimbach wrote: > >> Doesn't seem to compile. >> I nearly never use case statements in my code, so I'm not really sure >> what's going on. >> >> neat2.hs:14:39: parse error on input `=' >> >> Dave >> >> On Wed, Aug 19, 2009 at 10:23 AM, Ryan Ingram wrote: >> >>> I posted a reply to your paste with a stricter version of S and some >>> cleanup. >>> >>> Untested, though I believe it should work without "seq". >>> >>> "case" provides all the strictness you need, I think! >>> >>> -- ryan >>> >>> On Wed, Aug 19, 2009 at 9:28 AM, Peter Verswyvelen >>> wrote: >>> > Expect more bugs with this though :-) Just found out that looping does >>> not >>> > work, it hangs, e.g. >>> > >>> > test = do >>> > out "Enter your first name:" >>> > fstName <- inp >>> > out "Enter your second name:" >>> > sndName <- inp >>> > out ("Welcome "++fstName++" "++sndName) >>> > out "Goodbye!" >>> > test >>> > >>> > Doesn't seem to work :-) Back to the drawing board. >>> > >>> > On Wed, Aug 19, 2009 at 5:55 PM, Peter Verswyvelen >>> > wrote: >>> >> >>> >> Not at all, use it for whatever you want to :-) >>> >> I'm writing this code because I'm preparing to write a bunch of >>> tutorials >>> >> on FRP, and I first wanted to start with simple console based FRP, >>> e.g. >>> >> making a little text adventure game, where the input/choices of the >>> user >>> >> might be parsed ala parsec, using monadic style, applicative style, >>> and >>> >> arrows, and then doing the same with FRP frameworks like Yampa, Elera, >>> >> Reactive, etc... >>> >> After that I would start writing tutorials that use OpenGL, making >>> some >>> >> very simple games, again with the above approaches, and ending with a >>> >> conversion of a very old game of mine (Zarathrusta written in >>> assembler from >>> >> 1991, which was based on Thrust from 1986, converted by myself in C++ >>> to >>> >> PocketPC as G-Pod, and so I would like to make a version in Haskell >>> that >>> >> runs on the iPhone :-) >>> >> This of course is a lot of work, and I would like to put this on the >>> >> Haskell wiki or a blog or something, so others can contribute and >>> comment. I >>> >> would like to show real examples that explain the shortcomings of the >>> FRP >>> >> approaches, because now this is still a bit blurry to me. >>> >> >>> >> On Wed, Aug 19, 2009 at 5:43 PM, David Leimbach >>> wrote: >>> >>> >>> >>> This Monad you've created is quite excellent. I was trying to do >>> >>> something like this about a year ago, to make the input and output >>> handling >>> >>> of an interactive bowling score card work nicely. I kept running >>> into >>> >>> issues, and did not believe that seq was going to do the trick. Nice >>> work! >>> >>> This is a very useful monad I think, it could be called "Prompter" or >>> >>> something to that effect. >>> >>> Do you mind if I use it in some of my code? >>> >>> Dave >>> >>> >>> >>> On Wed, Aug 19, 2009 at 8:42 AM, Peter Verswyvelen < >>> bugfact@gmail.com> >>> >>> wrote: >>> >>>> >>> >>>> LOL. Maybe we should have that coffee together ;-) at least >>> virtually! >>> >>>> On Wed, Aug 19, 2009 at 5:39 PM, David Leimbach >>> >>>> wrote: >>> >>>>> >>> >>>>> Argh... I too have been up too late :-). I edited THE WRONG FILE! >>> No >>> >>>>> wonder your change didn't take effect! :-/ >>> >>>>> Time for coffee I suppose. >>> >>>>> >>> >>>>> On Wed, Aug 19, 2009 at 8:38 AM, David Leimbach >> > >>> >>>>> wrote: >>> >>>>>> >>> >>>>>> This doesn't seem to be working for me interactively though on a >>> Mac. >>> >>>>>> I still get "Welcome" before I've entered text. >>> >>>>>> >>> >>>>>> On Wed, Aug 19, 2009 at 8:25 AM, Peter Verswyvelen < >>> bugfact@gmail.com> >>> >>>>>> wrote: >>> >>>>>>> >>> >>>>>>> I fixed it myself but it's really tricky :-) >>> >>>>>>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8330 >>> >>>>>>> The idea is, that when the input is requested, the output that is >>> >>>>>>> then generated must be in sync with the input. >>> >>>>>>> >>> >>>>>>> inp = S $ \s i -> let r = (s `D.append` (i `seq` D.empty), head >>> i) in >>> >>>>>>> (tail i, r) >>> >>>>>>> >>> >>>>>>> >>> >>>>>>> I first had >>> >>>>>>> >>> >>>>>>> inp = S $ \s i -> let r = (i `seq` s, head i) in (tail i, r) >>> >>>>>>> >>> >>>>>>> But that was too eager, since i syncs the input not with the >>> output, >>> >>>>>>> but with the function that will generate the output. >>> >>>>>>> >>> >>>>>>> >>> >>>>>>> >>> >>>>>>> >>> >>>>>>> >>> >>>>>>> >>> >>>>>>> >>> >>>>>>> Okay, now I can sleep again :-) >>> >>>>>>> >>> >>>>>>> >>> >>>>>>> >>> >>>>>>> >>> >>>>>>> >>> >>>>>>> >>> >>>>>>> >>> >>>>>>> >>> >>>>>>> >>> >>>>>>> >>> >>>>>>> On Wed, Aug 19, 2009 at 5:12 PM, Peter Verswyvelen >>> >>>>>>> wrote: >>> >>>>>>>> >>> >>>>>>>> Thanks, but that doesn't really matter in my example, my code is >>> >>>>>>>> just buggy, and I'm not sure why. For example if I change my >>> test function >>> >>>>>>>> so that it outputs lines only, then it still prints Welcome >>> first before >>> >>>>>>>> asking for input. >>> >>>>>>>> See e.g. >>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328 >>> >>>>>>>> On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach < >>> leimy2k@gmail.com> >>> >>>>>>>> wrote: >>> >>>>>>>>> >>> >>>>>>>>> Try LineBuffering. >>> >>>>>>>>> I do linewise stuff with interact a lot. You'll find stuff >>> like >>> >>>>>>>>> unlines . lines >>> >>>>>>>>> may help too. In fact I just wrote a blog post about this. >>> >>>>>>>>> http://leimy9.blogspot.com >>> >>>>>>>>> I'm trying to write some interactive code to automate working >>> with >>> >>>>>>>>> serial console controlled power strips, so I need to either use >>> Expect >>> >>>>>>>>> (yuck) or do my own thing. >>> >>>>>>>>> Dave >>> >>>>>>>>> >>> >>>>>>>>> On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen >>> >>>>>>>>> wrote: >>> >>>>>>>>>> >>> >>>>>>>>>> Apparently this particular example happens to work on Mac and >>> >>>>>>>>>> Linux because of different buffering (thanks Martijn for the >>> help!) >>> >>>>>>>>>> To make sure we have no buffering at all, the main function >>> should >>> >>>>>>>>>> be: >>> >>>>>>>>>> >>> >>>>>>>>>> main = do >>> >>>>>>>>>> hSetBuffering stdout NoBuffering >>> >>>>>>>>>> hSetBuffering stdin NoBuffering >>> >>>>>>>>>> test >>> >>>>>>>>>> >>> >>>>>>>>>> Now I think it should also be incorrect on Unix systems. >>> >>>>>>>>>> I guess the way I'm concatenating the strings is not correct, >>> not >>> >>>>>>>>>> sure. >>> >>>>>>>>>> I would like to use a graphical tool to show the graph >>> reduction >>> >>>>>>>>>> step by step, to get a better understanding of the laziness & >>> strictness. >>> >>>>>>>>>> Does such a tool exist? I know people often say this is not >>> usable because >>> >>>>>>>>>> the amount of information is too much, but I used to be an >>> assembly language >>> >>>>>>>>>> programmer so I still would like to give it a try :-) >>> >>>>>>>>>> >>> >>>>>>>>>> >>> >>>>>>>>>> On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen >>> >>>>>>>>>> wrote: >>> >>>>>>>>>>> >>> >>>>>>>>>>> In an attempt to get a deeper understanding of several monads >>> >>>>>>>>>>> (State, ST, IO, ...) I skimmed over some of the research >>> papers (but didn't >>> >>>>>>>>>>> understand all of it, I lack the required education) and >>> decided to write a >>> >>>>>>>>>>> little program myself without using any prefab monad >>> instances that should >>> >>>>>>>>>>> mimic the following: >>> >>>>>>>>>>> main = do >>> >>>>>>>>>>> putStrLn "Enter your name:" >>> >>>>>>>>>>> x <- getLine >>> >>>>>>>>>>> putStr "Welcome " >>> >>>>>>>>>>> putStrLn x >>> >>>>>>>>>>> putStrLn "Goodbye!" >>> >>>>>>>>>>> But instead of using IO, I wanted to make my own pure monad >>> that >>> >>>>>>>>>>> gets evaluated with interact, and does the same. >>> >>>>>>>>>>> However, I get the following output: >>> >>>>>>>>>>> Enter your name: >>> >>>>>>>>>>> Welcome ...... >>> >>>>>>>>>>> So the Welcome is printed too soon. >>> >>>>>>>>>>> This is obvious since my monad is lazy, so I tried to put a >>> seq >>> >>>>>>>>>>> at some strategic places to get the same behavior as IO. But >>> I completely >>> >>>>>>>>>>> failed doing so, either the program doesn't print anything >>> and asks input >>> >>>>>>>>>>> first, or it still prints too much output. >>> >>>>>>>>>>> Of course I could just use ST, State, transformers, etc, but >>> this >>> >>>>>>>>>>> is purely an exercise I'm doing. >>> >>>>>>>>>>> So, I could re-read all papers and look in detail at all the >>> >>>>>>>>>>> code, but maybe someone could help me out where to put the >>> seq or what to do >>> >>>>>>>>>>> :-) >>> >>>>>>>>>>> The code is at >>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 >>> >>>>>>>>>>> Oh btw, the usage of DList here might not be needed; >>> intuitively >>> >>>>>>>>>>> it felt like the correct thing to do, but when it comes to >>> Haskell, my >>> >>>>>>>>>>> intuition is usually wrong ;-) >>> >>>>>>>>>>> Thanks a lot, >>> >>>>>>>>>>> Peter Verswyvelen >>> >>>>>>>>>> >>> >>>>>>>>>> >>> >>>>>>>>>> _______________________________________________ >>> >>>>>>>>>> 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 >>> > >>> > >>> >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/2263e927/attachment.html From bulat.ziganshin at gmail.com Wed Aug 19 14:30:30 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Wed Aug 19 14:10:59 2009 Subject: [Haskell-cafe] gbp sign showing as unknown character by GHC In-Reply-To: <57526e770908191116q420a2efdude077719189d57b0@mail.gmail.com> References: <3e1162e60908191039w7daeca17p13d4c79c549c6244@mail.gmail.com> <57526e770908191116q420a2efdude077719189d57b0@mail.gmail.com> Message-ID: <1754123245.20090819223030@gmail.com> Hello Alexander, Wednesday, August 19, 2009, 10:16:26 PM, you wrote: > Could it be a terminfo problem of some sort? It seems suspicious that > there is a difference between terminals. probably, terminals reports some unusual symbols. but any panic should be reported to GHC Trac - anyway -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From ryani.spam at gmail.com Wed Aug 19 15:28:13 2009 From: ryani.spam at gmail.com (Ryan Ingram) Date: Wed Aug 19 15:08:15 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <2f9b2d30908191023s2c11aa72m47fa8729868f6f23@mail.gmail.com> <3e1162e60908191031t63795c4apfbd47820647016ab@mail.gmail.com> <3e1162e60908191037m5c79d589ia78db27dd1449ae8@mail.gmail.com> Message-ID: <2f9b2d30908191228m5b38ddf0ib56052a60ef817ba@mail.gmail.com> Added a new version (tested, works with infinite loops, no early output, etc.) http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8343 I'll put up a short write-up after lunch. -- ryan On Wed, Aug 19, 2009 at 11:28 AM, Peter Verswyvelen wrote: > The cleaned up code didn't seem to work for me, it printed everything before > asking input again. > But I added a patch that looks like it supports looping, but I don't > understand exactly what is going on :-) > I added the "delay" function which makes appending to the output less > strict. > Note that in this version I add a delay to each right argument of >>=, but > one could also do it manually > On Wed, Aug 19, 2009 at 7:37 PM, David Leimbach wrote: >> >> I've corrected it. ?It still doesn't suffer looping. ?:-) >> >> On Wed, Aug 19, 2009 at 10:31 AM, David Leimbach >> wrote: >>> >>> Doesn't seem to compile. >>> I nearly never use case statements in my code, so I'm not really sure >>> what's going on. >>> neat2.hs:14:39: parse error on input `=' >>> Dave >>> On Wed, Aug 19, 2009 at 10:23 AM, Ryan Ingram >>> wrote: >>>> >>>> I posted a reply to your paste with a stricter version of S and some >>>> cleanup. >>>> >>>> Untested, though I believe it should work without "seq". >>>> >>>> "case" provides all the strictness you need, I think! >>>> >>>> ?-- ryan >>>> >>>> On Wed, Aug 19, 2009 at 9:28 AM, Peter Verswyvelen >>>> wrote: >>>> > Expect more bugs with this though :-) Just found out that looping does >>>> > not >>>> > work, it hangs, e.g. >>>> > >>>> > test = do >>>> > ? out "Enter your first name:" >>>> > ? fstName <- inp >>>> > ? out "Enter your second name:" >>>> > ? sndName <- inp >>>> > ? out ("Welcome "++fstName++" "++sndName) >>>> > ? out "Goodbye!" >>>> > ? test >>>> > >>>> > Doesn't seem to work :-) Back to the drawing board. >>>> > >>>> > On Wed, Aug 19, 2009 at 5:55 PM, Peter Verswyvelen >>>> > wrote: >>>> >> >>>> >> Not at all, use it for whatever you want to :-) >>>> >> I'm writing this code because I'm preparing to write a bunch of >>>> >> tutorials >>>> >> on FRP, and I first wanted to start with simple console based FRP, >>>> >> e.g. >>>> >> making a little text adventure game, where the input/choices of the >>>> >> user >>>> >> might be parsed ala parsec, using monadic style, applicative style, >>>> >> and >>>> >> arrows, and then doing the same with FRP frameworks like Yampa, >>>> >> Elera, >>>> >> Reactive, etc... >>>> >> After that I would start writing tutorials that use OpenGL, making >>>> >> some >>>> >> very simple games, again with the above approaches, and ending with a >>>> >> conversion of a very old game of mine (Zarathrusta written in >>>> >> assembler from >>>> >> 1991, which was based on Thrust from 1986, converted by myself in C++ >>>> >> to >>>> >> PocketPC as G-Pod, and so I would like to make a version in Haskell >>>> >> that >>>> >> runs on the iPhone :-) >>>> >> This of course is a lot of work, and I would like to put this on the >>>> >> Haskell wiki or a blog or something, so others can contribute and >>>> >> comment. I >>>> >> would like to show real examples that explain the shortcomings of the >>>> >> FRP >>>> >> approaches, because now this is still a bit blurry to me. >>>> >> >>>> >> On Wed, Aug 19, 2009 at 5:43 PM, David Leimbach >>>> >> wrote: >>>> >>> >>>> >>> This Monad you've created is quite excellent. ?I was trying to do >>>> >>> something like this about a year ago, to make the input and output >>>> >>> handling >>>> >>> of an interactive bowling score card work nicely. ?I kept running >>>> >>> into >>>> >>> issues, and did not believe that seq was going to do the trick. >>>> >>> ?Nice work! >>>> >>> This is a very useful monad I think, it could be called "Prompter" >>>> >>> or >>>> >>> something to that effect. >>>> >>> Do you mind if I use it in some of my code? >>>> >>> Dave >>>> >>> >>>> >>> On Wed, Aug 19, 2009 at 8:42 AM, Peter Verswyvelen >>>> >>> >>>> >>> wrote: >>>> >>>> >>>> >>>> LOL. Maybe we should have that coffee together ;-) at least >>>> >>>> virtually! >>>> >>>> On Wed, Aug 19, 2009 at 5:39 PM, David Leimbach >>>> >>>> wrote: >>>> >>>>> >>>> >>>>> Argh... I too have been up too late :-). ?I edited THE WRONG FILE! >>>> >>>>> ?No >>>> >>>>> wonder your change didn't take effect! ?:-/ >>>> >>>>> Time for coffee I suppose. >>>> >>>>> >>>> >>>>> On Wed, Aug 19, 2009 at 8:38 AM, David Leimbach >>>> >>>>> >>>> >>>>> wrote: >>>> >>>>>> >>>> >>>>>> This doesn't seem to be working for me interactively though on a >>>> >>>>>> Mac. >>>> >>>>>> ?I still get "Welcome" before I've entered text. >>>> >>>>>> >>>> >>>>>> On Wed, Aug 19, 2009 at 8:25 AM, Peter Verswyvelen >>>> >>>>>> >>>> >>>>>> wrote: >>>> >>>>>>> >>>> >>>>>>> I fixed it myself but it's really tricky :-) >>>> >>>>>>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8330 >>>> >>>>>>> The idea is, that when the input is requested, the output that >>>> >>>>>>> is >>>> >>>>>>> then generated must be in sync with the input. >>>> >>>>>>> >>>> >>>>>>> inp = S $ \s i -> let r = (s `D.append` (i `seq` D.empty), head >>>> >>>>>>> i) in >>>> >>>>>>> (tail i, r) >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> I first had >>>> >>>>>>> >>>> >>>>>>> inp = S $ \s i -> let r = (i `seq` s, head i) in (tail i, r) >>>> >>>>>>> >>>> >>>>>>> But that was too eager, since i syncs the input not with the >>>> >>>>>>> output, >>>> >>>>>>> but with the function that will generate the output. >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> Okay, now I can sleep again :-) >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> On Wed, Aug 19, 2009 at 5:12 PM, Peter Verswyvelen >>>> >>>>>>> wrote: >>>> >>>>>>>> >>>> >>>>>>>> Thanks, but that doesn't really matter in my example, my code >>>> >>>>>>>> is >>>> >>>>>>>> just buggy, and I'm not sure why. For example if I change my >>>> >>>>>>>> test function >>>> >>>>>>>> so that it outputs lines only, then it still prints Welcome >>>> >>>>>>>> first before >>>> >>>>>>>> asking for input. >>>> >>>>>>>> See >>>> >>>>>>>> e.g.?http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328 >>>> >>>>>>>> On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach >>>> >>>>>>>> >>>> >>>>>>>> wrote: >>>> >>>>>>>>> >>>> >>>>>>>>> Try LineBuffering. >>>> >>>>>>>>> I do linewise stuff with interact a lot. ?You'll find stuff >>>> >>>>>>>>> like >>>> >>>>>>>>> unlines . lines >>>> >>>>>>>>> may help too. ?In fact I just wrote a blog post about this. >>>> >>>>>>>>> http://leimy9.blogspot.com >>>> >>>>>>>>> I'm trying to write some interactive code to automate working >>>> >>>>>>>>> with >>>> >>>>>>>>> serial console controlled power strips, so I need to either >>>> >>>>>>>>> use Expect >>>> >>>>>>>>> (yuck) or do my own thing. >>>> >>>>>>>>> Dave >>>> >>>>>>>>> >>>> >>>>>>>>> On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen >>>> >>>>>>>>> wrote: >>>> >>>>>>>>>> >>>> >>>>>>>>>> Apparently this particular example happens to work on Mac and >>>> >>>>>>>>>> Linux because of different buffering (thanks Martijn for the >>>> >>>>>>>>>> help!) >>>> >>>>>>>>>> To make sure we have no buffering at all, the main function >>>> >>>>>>>>>> should >>>> >>>>>>>>>> be: >>>> >>>>>>>>>> >>>> >>>>>>>>>> main = do >>>> >>>>>>>>>> ? hSetBuffering stdout NoBuffering >>>> >>>>>>>>>> ? hSetBuffering stdin NoBuffering >>>> >>>>>>>>>> ? test >>>> >>>>>>>>>> >>>> >>>>>>>>>> Now I think it should also be incorrect on Unix systems. >>>> >>>>>>>>>> I guess the way I'm concatenating the strings is not correct, >>>> >>>>>>>>>> not >>>> >>>>>>>>>> sure. >>>> >>>>>>>>>> I would like to use a graphical tool to show the graph >>>> >>>>>>>>>> reduction >>>> >>>>>>>>>> step by step, to get a better understanding of the laziness & >>>> >>>>>>>>>> strictness. >>>> >>>>>>>>>> Does such a tool exist? I know people often say this is not >>>> >>>>>>>>>> usable because >>>> >>>>>>>>>> the amount of information is too much, but I used to be an >>>> >>>>>>>>>> assembly language >>>> >>>>>>>>>> programmer so I still would like to give it a try :-) >>>> >>>>>>>>>> >>>> >>>>>>>>>> >>>> >>>>>>>>>> On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen >>>> >>>>>>>>>> wrote: >>>> >>>>>>>>>>> >>>> >>>>>>>>>>> In an attempt to get a deeper understanding of several >>>> >>>>>>>>>>> monads >>>> >>>>>>>>>>> (State, ST, IO, ...) I skimmed over some of the research >>>> >>>>>>>>>>> papers (but didn't >>>> >>>>>>>>>>> understand all of it, I lack the required education) and >>>> >>>>>>>>>>> decided to write a >>>> >>>>>>>>>>> little program myself without using any prefab monad >>>> >>>>>>>>>>> instances that should >>>> >>>>>>>>>>> mimic the following: >>>> >>>>>>>>>>> main = do >>>> >>>>>>>>>>> ??putStrLn "Enter your name:" >>>> >>>>>>>>>>> ??x <- getLine >>>> >>>>>>>>>>> ??putStr "Welcome " >>>> >>>>>>>>>>> ??putStrLn x >>>> >>>>>>>>>>> ??putStrLn "Goodbye!" >>>> >>>>>>>>>>> But instead of using IO, I wanted to make my own pure monad >>>> >>>>>>>>>>> that >>>> >>>>>>>>>>> gets evaluated with interact, and does the same. >>>> >>>>>>>>>>> However, I get the following output: >>>> >>>>>>>>>>> Enter your name: >>>> >>>>>>>>>>> Welcome ...... >>>> >>>>>>>>>>> So the Welcome is printed too soon. >>>> >>>>>>>>>>> This is obvious since my monad is lazy, so I tried to put a >>>> >>>>>>>>>>> seq >>>> >>>>>>>>>>> at some strategic places to get the same behavior as IO. But >>>> >>>>>>>>>>> I completely >>>> >>>>>>>>>>> failed doing so, either the program doesn't print anything >>>> >>>>>>>>>>> and asks input >>>> >>>>>>>>>>> first, or it still prints too much output. >>>> >>>>>>>>>>> Of course I could just use ST, State, transformers, etc, but >>>> >>>>>>>>>>> this >>>> >>>>>>>>>>> is purely an exercise I'm doing. >>>> >>>>>>>>>>> So, I could re-read all papers and look in detail at all the >>>> >>>>>>>>>>> code, but maybe someone could help me out where to put the >>>> >>>>>>>>>>> seq or what to do >>>> >>>>>>>>>>> :-) >>>> >>>>>>>>>>> The code is >>>> >>>>>>>>>>> at?http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 >>>> >>>>>>>>>>> Oh btw, the usage of DList here might not be needed; >>>> >>>>>>>>>>> intuitively >>>> >>>>>>>>>>> it felt like the correct thing to do, but when it comes to >>>> >>>>>>>>>>> Haskell, my >>>> >>>>>>>>>>> intuition is usually wrong ;-) >>>> >>>>>>>>>>> Thanks a lot, >>>> >>>>>>>>>>> Peter Verswyvelen >>>> >>>>>>>>>> >>>> >>>>>>>>>> >>>> >>>>>>>>>> _______________________________________________ >>>> >>>>>>>>>> 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 iainspeed at gmail.com Wed Aug 19 15:31:37 2009 From: iainspeed at gmail.com (Iain Barnett) Date: Wed Aug 19 15:11:41 2009 Subject: [Haskell-cafe] gbp sign showing as unknown character by GHC In-Reply-To: <1754123245.20090819223030@gmail.com> References: <3e1162e60908191039w7daeca17p13d4c79c549c6244@mail.gmail.com> <57526e770908191116q420a2efdude077719189d57b0@mail.gmail.com> <1754123245.20090819223030@gmail.com> Message-ID: 2009/8/19 Bulat Ziganshin > > probably, terminals reports some unusual symbols. but any panic should > be reported to GHC Trac - anyway > > I've added a new ticket here, in case you feel you want to add to it (or not :) http://hackage.haskell.org/trac/ghc/ticket/3443 Iain -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/6e1729ac/attachment.html From leimy2k at gmail.com Wed Aug 19 15:46:18 2009 From: leimy2k at gmail.com (David Leimbach) Date: Wed Aug 19 15:26:22 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <2f9b2d30908191228m5b38ddf0ib56052a60ef817ba@mail.gmail.com> References: <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <2f9b2d30908191023s2c11aa72m47fa8729868f6f23@mail.gmail.com> <3e1162e60908191031t63795c4apfbd47820647016ab@mail.gmail.com> <3e1162e60908191037m5c79d589ia78db27dd1449ae8@mail.gmail.com> <2f9b2d30908191228m5b38ddf0ib56052a60ef817ba@mail.gmail.com> Message-ID: <3e1162e60908191246g756c16d0ide067fba48b97c68@mail.gmail.com> Very cool! I am still wondering what the significance of the DList is with this though, or why it was needed to begin with. Dave On Wed, Aug 19, 2009 at 12:28 PM, Ryan Ingram wrote: > Added a new version (tested, works with infinite loops, no early output, > etc.) > > http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8343 > > I'll put up a short write-up after lunch. > > -- ryan > > On Wed, Aug 19, 2009 at 11:28 AM, Peter Verswyvelen > wrote: > > The cleaned up code didn't seem to work for me, it printed everything > before > > asking input again. > > But I added a patch that looks like it supports looping, but I don't > > understand exactly what is going on :-) > > I added the "delay" function which makes appending to the output less > > strict. > > Note that in this version I add a delay to each right argument of >>=, > but > > one could also do it manually > > On Wed, Aug 19, 2009 at 7:37 PM, David Leimbach > wrote: > >> > >> I've corrected it. It still doesn't suffer looping. :-) > >> > >> On Wed, Aug 19, 2009 at 10:31 AM, David Leimbach > >> wrote: > >>> > >>> Doesn't seem to compile. > >>> I nearly never use case statements in my code, so I'm not really sure > >>> what's going on. > >>> neat2.hs:14:39: parse error on input `=' > >>> Dave > >>> On Wed, Aug 19, 2009 at 10:23 AM, Ryan Ingram > >>> wrote: > >>>> > >>>> I posted a reply to your paste with a stricter version of S and some > >>>> cleanup. > >>>> > >>>> Untested, though I believe it should work without "seq". > >>>> > >>>> "case" provides all the strictness you need, I think! > >>>> > >>>> -- ryan > >>>> > >>>> On Wed, Aug 19, 2009 at 9:28 AM, Peter Verswyvelen > >>>> wrote: > >>>> > Expect more bugs with this though :-) Just found out that looping > does > >>>> > not > >>>> > work, it hangs, e.g. > >>>> > > >>>> > test = do > >>>> > out "Enter your first name:" > >>>> > fstName <- inp > >>>> > out "Enter your second name:" > >>>> > sndName <- inp > >>>> > out ("Welcome "++fstName++" "++sndName) > >>>> > out "Goodbye!" > >>>> > test > >>>> > > >>>> > Doesn't seem to work :-) Back to the drawing board. > >>>> > > >>>> > On Wed, Aug 19, 2009 at 5:55 PM, Peter Verswyvelen < > bugfact@gmail.com> > >>>> > wrote: > >>>> >> > >>>> >> Not at all, use it for whatever you want to :-) > >>>> >> I'm writing this code because I'm preparing to write a bunch of > >>>> >> tutorials > >>>> >> on FRP, and I first wanted to start with simple console based FRP, > >>>> >> e.g. > >>>> >> making a little text adventure game, where the input/choices of the > >>>> >> user > >>>> >> might be parsed ala parsec, using monadic style, applicative style, > >>>> >> and > >>>> >> arrows, and then doing the same with FRP frameworks like Yampa, > >>>> >> Elera, > >>>> >> Reactive, etc... > >>>> >> After that I would start writing tutorials that use OpenGL, making > >>>> >> some > >>>> >> very simple games, again with the above approaches, and ending with > a > >>>> >> conversion of a very old game of mine (Zarathrusta written in > >>>> >> assembler from > >>>> >> 1991, which was based on Thrust from 1986, converted by myself in > C++ > >>>> >> to > >>>> >> PocketPC as G-Pod, and so I would like to make a version in Haskell > >>>> >> that > >>>> >> runs on the iPhone :-) > >>>> >> This of course is a lot of work, and I would like to put this on > the > >>>> >> Haskell wiki or a blog or something, so others can contribute and > >>>> >> comment. I > >>>> >> would like to show real examples that explain the shortcomings of > the > >>>> >> FRP > >>>> >> approaches, because now this is still a bit blurry to me. > >>>> >> > >>>> >> On Wed, Aug 19, 2009 at 5:43 PM, David Leimbach > > >>>> >> wrote: > >>>> >>> > >>>> >>> This Monad you've created is quite excellent. I was trying to do > >>>> >>> something like this about a year ago, to make the input and output > >>>> >>> handling > >>>> >>> of an interactive bowling score card work nicely. I kept running > >>>> >>> into > >>>> >>> issues, and did not believe that seq was going to do the trick. > >>>> >>> Nice work! > >>>> >>> This is a very useful monad I think, it could be called "Prompter" > >>>> >>> or > >>>> >>> something to that effect. > >>>> >>> Do you mind if I use it in some of my code? > >>>> >>> Dave > >>>> >>> > >>>> >>> On Wed, Aug 19, 2009 at 8:42 AM, Peter Verswyvelen > >>>> >>> > >>>> >>> wrote: > >>>> >>>> > >>>> >>>> LOL. Maybe we should have that coffee together ;-) at least > >>>> >>>> virtually! > >>>> >>>> On Wed, Aug 19, 2009 at 5:39 PM, David Leimbach < > leimy2k@gmail.com> > >>>> >>>> wrote: > >>>> >>>>> > >>>> >>>>> Argh... I too have been up too late :-). I edited THE WRONG > FILE! > >>>> >>>>> No > >>>> >>>>> wonder your change didn't take effect! :-/ > >>>> >>>>> Time for coffee I suppose. > >>>> >>>>> > >>>> >>>>> On Wed, Aug 19, 2009 at 8:38 AM, David Leimbach > >>>> >>>>> > >>>> >>>>> wrote: > >>>> >>>>>> > >>>> >>>>>> This doesn't seem to be working for me interactively though on > a > >>>> >>>>>> Mac. > >>>> >>>>>> I still get "Welcome" before I've entered text. > >>>> >>>>>> > >>>> >>>>>> On Wed, Aug 19, 2009 at 8:25 AM, Peter Verswyvelen > >>>> >>>>>> > >>>> >>>>>> wrote: > >>>> >>>>>>> > >>>> >>>>>>> I fixed it myself but it's really tricky :-) > >>>> >>>>>>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8330 > >>>> >>>>>>> The idea is, that when the input is requested, the output that > >>>> >>>>>>> is > >>>> >>>>>>> then generated must be in sync with the input. > >>>> >>>>>>> > >>>> >>>>>>> inp = S $ \s i -> let r = (s `D.append` (i `seq` D.empty), > head > >>>> >>>>>>> i) in > >>>> >>>>>>> (tail i, r) > >>>> >>>>>>> > >>>> >>>>>>> > >>>> >>>>>>> I first had > >>>> >>>>>>> > >>>> >>>>>>> inp = S $ \s i -> let r = (i `seq` s, head i) in (tail i, r) > >>>> >>>>>>> > >>>> >>>>>>> But that was too eager, since i syncs the input not with the > >>>> >>>>>>> output, > >>>> >>>>>>> but with the function that will generate the output. > >>>> >>>>>>> > >>>> >>>>>>> > >>>> >>>>>>> > >>>> >>>>>>> > >>>> >>>>>>> > >>>> >>>>>>> > >>>> >>>>>>> > >>>> >>>>>>> Okay, now I can sleep again :-) > >>>> >>>>>>> > >>>> >>>>>>> > >>>> >>>>>>> > >>>> >>>>>>> > >>>> >>>>>>> > >>>> >>>>>>> > >>>> >>>>>>> > >>>> >>>>>>> > >>>> >>>>>>> > >>>> >>>>>>> > >>>> >>>>>>> On Wed, Aug 19, 2009 at 5:12 PM, Peter Verswyvelen > >>>> >>>>>>> wrote: > >>>> >>>>>>>> > >>>> >>>>>>>> Thanks, but that doesn't really matter in my example, my code > >>>> >>>>>>>> is > >>>> >>>>>>>> just buggy, and I'm not sure why. For example if I change my > >>>> >>>>>>>> test function > >>>> >>>>>>>> so that it outputs lines only, then it still prints Welcome > >>>> >>>>>>>> first before > >>>> >>>>>>>> asking for input. > >>>> >>>>>>>> See > >>>> >>>>>>>> e.g. > http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328 > >>>> >>>>>>>> On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach > >>>> >>>>>>>> > >>>> >>>>>>>> wrote: > >>>> >>>>>>>>> > >>>> >>>>>>>>> Try LineBuffering. > >>>> >>>>>>>>> I do linewise stuff with interact a lot. You'll find stuff > >>>> >>>>>>>>> like > >>>> >>>>>>>>> unlines . lines > >>>> >>>>>>>>> may help too. In fact I just wrote a blog post about this. > >>>> >>>>>>>>> http://leimy9.blogspot.com > >>>> >>>>>>>>> I'm trying to write some interactive code to automate > working > >>>> >>>>>>>>> with > >>>> >>>>>>>>> serial console controlled power strips, so I need to either > >>>> >>>>>>>>> use Expect > >>>> >>>>>>>>> (yuck) or do my own thing. > >>>> >>>>>>>>> Dave > >>>> >>>>>>>>> > >>>> >>>>>>>>> On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen > >>>> >>>>>>>>> wrote: > >>>> >>>>>>>>>> > >>>> >>>>>>>>>> Apparently this particular example happens to work on Mac > and > >>>> >>>>>>>>>> Linux because of different buffering (thanks Martijn for > the > >>>> >>>>>>>>>> help!) > >>>> >>>>>>>>>> To make sure we have no buffering at all, the main function > >>>> >>>>>>>>>> should > >>>> >>>>>>>>>> be: > >>>> >>>>>>>>>> > >>>> >>>>>>>>>> main = do > >>>> >>>>>>>>>> hSetBuffering stdout NoBuffering > >>>> >>>>>>>>>> hSetBuffering stdin NoBuffering > >>>> >>>>>>>>>> test > >>>> >>>>>>>>>> > >>>> >>>>>>>>>> Now I think it should also be incorrect on Unix systems. > >>>> >>>>>>>>>> I guess the way I'm concatenating the strings is not > correct, > >>>> >>>>>>>>>> not > >>>> >>>>>>>>>> sure. > >>>> >>>>>>>>>> I would like to use a graphical tool to show the graph > >>>> >>>>>>>>>> reduction > >>>> >>>>>>>>>> step by step, to get a better understanding of the laziness > & > >>>> >>>>>>>>>> strictness. > >>>> >>>>>>>>>> Does such a tool exist? I know people often say this is not > >>>> >>>>>>>>>> usable because > >>>> >>>>>>>>>> the amount of information is too much, but I used to be an > >>>> >>>>>>>>>> assembly language > >>>> >>>>>>>>>> programmer so I still would like to give it a try :-) > >>>> >>>>>>>>>> > >>>> >>>>>>>>>> > >>>> >>>>>>>>>> On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen > >>>> >>>>>>>>>> wrote: > >>>> >>>>>>>>>>> > >>>> >>>>>>>>>>> In an attempt to get a deeper understanding of several > >>>> >>>>>>>>>>> monads > >>>> >>>>>>>>>>> (State, ST, IO, ...) I skimmed over some of the research > >>>> >>>>>>>>>>> papers (but didn't > >>>> >>>>>>>>>>> understand all of it, I lack the required education) and > >>>> >>>>>>>>>>> decided to write a > >>>> >>>>>>>>>>> little program myself without using any prefab monad > >>>> >>>>>>>>>>> instances that should > >>>> >>>>>>>>>>> mimic the following: > >>>> >>>>>>>>>>> main = do > >>>> >>>>>>>>>>> putStrLn "Enter your name:" > >>>> >>>>>>>>>>> x <- getLine > >>>> >>>>>>>>>>> putStr "Welcome " > >>>> >>>>>>>>>>> putStrLn x > >>>> >>>>>>>>>>> putStrLn "Goodbye!" > >>>> >>>>>>>>>>> But instead of using IO, I wanted to make my own pure > monad > >>>> >>>>>>>>>>> that > >>>> >>>>>>>>>>> gets evaluated with interact, and does the same. > >>>> >>>>>>>>>>> However, I get the following output: > >>>> >>>>>>>>>>> Enter your name: > >>>> >>>>>>>>>>> Welcome ...... > >>>> >>>>>>>>>>> So the Welcome is printed too soon. > >>>> >>>>>>>>>>> This is obvious since my monad is lazy, so I tried to put > a > >>>> >>>>>>>>>>> seq > >>>> >>>>>>>>>>> at some strategic places to get the same behavior as IO. > But > >>>> >>>>>>>>>>> I completely > >>>> >>>>>>>>>>> failed doing so, either the program doesn't print anything > >>>> >>>>>>>>>>> and asks input > >>>> >>>>>>>>>>> first, or it still prints too much output. > >>>> >>>>>>>>>>> Of course I could just use ST, State, transformers, etc, > but > >>>> >>>>>>>>>>> this > >>>> >>>>>>>>>>> is purely an exercise I'm doing. > >>>> >>>>>>>>>>> So, I could re-read all papers and look in detail at all > the > >>>> >>>>>>>>>>> code, but maybe someone could help me out where to put the > >>>> >>>>>>>>>>> seq or what to do > >>>> >>>>>>>>>>> :-) > >>>> >>>>>>>>>>> The code is > >>>> >>>>>>>>>>> at http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 > >>>> >>>>>>>>>>> Oh btw, the usage of DList here might not be needed; > >>>> >>>>>>>>>>> intuitively > >>>> >>>>>>>>>>> it felt like the correct thing to do, but when it comes to > >>>> >>>>>>>>>>> Haskell, my > >>>> >>>>>>>>>>> intuition is usually wrong ;-) > >>>> >>>>>>>>>>> Thanks a lot, > >>>> >>>>>>>>>>> Peter Verswyvelen > >>>> >>>>>>>>>> > >>>> >>>>>>>>>> > >>>> >>>>>>>>>> _______________________________________________ > >>>> >>>>>>>>>> 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 > >>>> > > >>>> > > >>> > >> > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/ae29fd01/attachment-0001.html From bugfact at gmail.com Wed Aug 19 16:00:13 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 19 15:40:22 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <3e1162e60908191246g756c16d0ide067fba48b97c68@mail.gmail.com> References: <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <2f9b2d30908191023s2c11aa72m47fa8729868f6f23@mail.gmail.com> <3e1162e60908191031t63795c4apfbd47820647016ab@mail.gmail.com> <3e1162e60908191037m5c79d589ia78db27dd1449ae8@mail.gmail.com> <2f9b2d30908191228m5b38ddf0ib56052a60ef817ba@mail.gmail.com> <3e1162e60908191246g756c16d0ide067fba48b97c68@mail.gmail.com> Message-ID: Wow, very nice cleanup! That's really a good way for me to learn, thanks. Well, my intuition told me that strings and ++ wouldn't work, since what we want is an infinite list of output strings, and using ++ would result in (((s1++s2)++s3)++s4)++s5... which is highly inefficient and I think it would keep the complete output text in memory. Using difference lists results in right associative concatenation of s1++(s2++(s3++(s4++... which is efficient and can be garbage collected nicely. At least that's what I guess. I really would like to get a deeper understanding of all this but that will take lots of time and study, but if I'm lucky I still have 20 to 40 years to go, so I won't be bored :-) On Wed, Aug 19, 2009 at 9:46 PM, David Leimbach wrote: > Very cool! > I am still wondering what the significance of the DList is with this > though, or why it was needed to begin with. > > Dave > > > On Wed, Aug 19, 2009 at 12:28 PM, Ryan Ingram wrote: > >> Added a new version (tested, works with infinite loops, no early output, >> etc.) >> >> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8343 >> >> I'll put up a short write-up after lunch. >> >> -- ryan >> >> On Wed, Aug 19, 2009 at 11:28 AM, Peter Verswyvelen >> wrote: >> > The cleaned up code didn't seem to work for me, it printed everything >> before >> > asking input again. >> > But I added a patch that looks like it supports looping, but I don't >> > understand exactly what is going on :-) >> > I added the "delay" function which makes appending to the output less >> > strict. >> > Note that in this version I add a delay to each right argument of >>=, >> but >> > one could also do it manually >> > On Wed, Aug 19, 2009 at 7:37 PM, David Leimbach >> wrote: >> >> >> >> I've corrected it. It still doesn't suffer looping. :-) >> >> >> >> On Wed, Aug 19, 2009 at 10:31 AM, David Leimbach >> >> wrote: >> >>> >> >>> Doesn't seem to compile. >> >>> I nearly never use case statements in my code, so I'm not really sure >> >>> what's going on. >> >>> neat2.hs:14:39: parse error on input `=' >> >>> Dave >> >>> On Wed, Aug 19, 2009 at 10:23 AM, Ryan Ingram >> >>> wrote: >> >>>> >> >>>> I posted a reply to your paste with a stricter version of S and some >> >>>> cleanup. >> >>>> >> >>>> Untested, though I believe it should work without "seq". >> >>>> >> >>>> "case" provides all the strictness you need, I think! >> >>>> >> >>>> -- ryan >> >>>> >> >>>> On Wed, Aug 19, 2009 at 9:28 AM, Peter Verswyvelen> > >> >>>> wrote: >> >>>> > Expect more bugs with this though :-) Just found out that looping >> does >> >>>> > not >> >>>> > work, it hangs, e.g. >> >>>> > >> >>>> > test = do >> >>>> > out "Enter your first name:" >> >>>> > fstName <- inp >> >>>> > out "Enter your second name:" >> >>>> > sndName <- inp >> >>>> > out ("Welcome "++fstName++" "++sndName) >> >>>> > out "Goodbye!" >> >>>> > test >> >>>> > >> >>>> > Doesn't seem to work :-) Back to the drawing board. >> >>>> > >> >>>> > On Wed, Aug 19, 2009 at 5:55 PM, Peter Verswyvelen < >> bugfact@gmail.com> >> >>>> > wrote: >> >>>> >> >> >>>> >> Not at all, use it for whatever you want to :-) >> >>>> >> I'm writing this code because I'm preparing to write a bunch of >> >>>> >> tutorials >> >>>> >> on FRP, and I first wanted to start with simple console based FRP, >> >>>> >> e.g. >> >>>> >> making a little text adventure game, where the input/choices of >> the >> >>>> >> user >> >>>> >> might be parsed ala parsec, using monadic style, applicative >> style, >> >>>> >> and >> >>>> >> arrows, and then doing the same with FRP frameworks like Yampa, >> >>>> >> Elera, >> >>>> >> Reactive, etc... >> >>>> >> After that I would start writing tutorials that use OpenGL, making >> >>>> >> some >> >>>> >> very simple games, again with the above approaches, and ending >> with a >> >>>> >> conversion of a very old game of mine (Zarathrusta written in >> >>>> >> assembler from >> >>>> >> 1991, which was based on Thrust from 1986, converted by myself in >> C++ >> >>>> >> to >> >>>> >> PocketPC as G-Pod, and so I would like to make a version in >> Haskell >> >>>> >> that >> >>>> >> runs on the iPhone :-) >> >>>> >> This of course is a lot of work, and I would like to put this on >> the >> >>>> >> Haskell wiki or a blog or something, so others can contribute and >> >>>> >> comment. I >> >>>> >> would like to show real examples that explain the shortcomings of >> the >> >>>> >> FRP >> >>>> >> approaches, because now this is still a bit blurry to me. >> >>>> >> >> >>>> >> On Wed, Aug 19, 2009 at 5:43 PM, David Leimbach < >> leimy2k@gmail.com> >> >>>> >> wrote: >> >>>> >>> >> >>>> >>> This Monad you've created is quite excellent. I was trying to do >> >>>> >>> something like this about a year ago, to make the input and >> output >> >>>> >>> handling >> >>>> >>> of an interactive bowling score card work nicely. I kept running >> >>>> >>> into >> >>>> >>> issues, and did not believe that seq was going to do the trick. >> >>>> >>> Nice work! >> >>>> >>> This is a very useful monad I think, it could be called >> "Prompter" >> >>>> >>> or >> >>>> >>> something to that effect. >> >>>> >>> Do you mind if I use it in some of my code? >> >>>> >>> Dave >> >>>> >>> >> >>>> >>> On Wed, Aug 19, 2009 at 8:42 AM, Peter Verswyvelen >> >>>> >>> >> >>>> >>> wrote: >> >>>> >>>> >> >>>> >>>> LOL. Maybe we should have that coffee together ;-) at least >> >>>> >>>> virtually! >> >>>> >>>> On Wed, Aug 19, 2009 at 5:39 PM, David Leimbach < >> leimy2k@gmail.com> >> >>>> >>>> wrote: >> >>>> >>>>> >> >>>> >>>>> Argh... I too have been up too late :-). I edited THE WRONG >> FILE! >> >>>> >>>>> No >> >>>> >>>>> wonder your change didn't take effect! :-/ >> >>>> >>>>> Time for coffee I suppose. >> >>>> >>>>> >> >>>> >>>>> On Wed, Aug 19, 2009 at 8:38 AM, David Leimbach >> >>>> >>>>> >> >>>> >>>>> wrote: >> >>>> >>>>>> >> >>>> >>>>>> This doesn't seem to be working for me interactively though on >> a >> >>>> >>>>>> Mac. >> >>>> >>>>>> I still get "Welcome" before I've entered text. >> >>>> >>>>>> >> >>>> >>>>>> On Wed, Aug 19, 2009 at 8:25 AM, Peter Verswyvelen >> >>>> >>>>>> >> >>>> >>>>>> wrote: >> >>>> >>>>>>> >> >>>> >>>>>>> I fixed it myself but it's really tricky :-) >> >>>> >>>>>>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8330 >> >>>> >>>>>>> The idea is, that when the input is requested, the output >> that >> >>>> >>>>>>> is >> >>>> >>>>>>> then generated must be in sync with the input. >> >>>> >>>>>>> >> >>>> >>>>>>> inp = S $ \s i -> let r = (s `D.append` (i `seq` D.empty), >> head >> >>>> >>>>>>> i) in >> >>>> >>>>>>> (tail i, r) >> >>>> >>>>>>> >> >>>> >>>>>>> >> >>>> >>>>>>> I first had >> >>>> >>>>>>> >> >>>> >>>>>>> inp = S $ \s i -> let r = (i `seq` s, head i) in (tail i, r) >> >>>> >>>>>>> >> >>>> >>>>>>> But that was too eager, since i syncs the input not with the >> >>>> >>>>>>> output, >> >>>> >>>>>>> but with the function that will generate the output. >> >>>> >>>>>>> >> >>>> >>>>>>> >> >>>> >>>>>>> >> >>>> >>>>>>> >> >>>> >>>>>>> >> >>>> >>>>>>> >> >>>> >>>>>>> >> >>>> >>>>>>> Okay, now I can sleep again :-) >> >>>> >>>>>>> >> >>>> >>>>>>> >> >>>> >>>>>>> >> >>>> >>>>>>> >> >>>> >>>>>>> >> >>>> >>>>>>> >> >>>> >>>>>>> >> >>>> >>>>>>> >> >>>> >>>>>>> >> >>>> >>>>>>> >> >>>> >>>>>>> On Wed, Aug 19, 2009 at 5:12 PM, Peter Verswyvelen >> >>>> >>>>>>> wrote: >> >>>> >>>>>>>> >> >>>> >>>>>>>> Thanks, but that doesn't really matter in my example, my >> code >> >>>> >>>>>>>> is >> >>>> >>>>>>>> just buggy, and I'm not sure why. For example if I change my >> >>>> >>>>>>>> test function >> >>>> >>>>>>>> so that it outputs lines only, then it still prints Welcome >> >>>> >>>>>>>> first before >> >>>> >>>>>>>> asking for input. >> >>>> >>>>>>>> See >> >>>> >>>>>>>> e.g. >> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328 >> >>>> >>>>>>>> On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach >> >>>> >>>>>>>> >> >>>> >>>>>>>> wrote: >> >>>> >>>>>>>>> >> >>>> >>>>>>>>> Try LineBuffering. >> >>>> >>>>>>>>> I do linewise stuff with interact a lot. You'll find stuff >> >>>> >>>>>>>>> like >> >>>> >>>>>>>>> unlines . lines >> >>>> >>>>>>>>> may help too. In fact I just wrote a blog post about this. >> >>>> >>>>>>>>> http://leimy9.blogspot.com >> >>>> >>>>>>>>> I'm trying to write some interactive code to automate >> working >> >>>> >>>>>>>>> with >> >>>> >>>>>>>>> serial console controlled power strips, so I need to either >> >>>> >>>>>>>>> use Expect >> >>>> >>>>>>>>> (yuck) or do my own thing. >> >>>> >>>>>>>>> Dave >> >>>> >>>>>>>>> >> >>>> >>>>>>>>> On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen >> >>>> >>>>>>>>> wrote: >> >>>> >>>>>>>>>> >> >>>> >>>>>>>>>> Apparently this particular example happens to work on Mac >> and >> >>>> >>>>>>>>>> Linux because of different buffering (thanks Martijn for >> the >> >>>> >>>>>>>>>> help!) >> >>>> >>>>>>>>>> To make sure we have no buffering at all, the main >> function >> >>>> >>>>>>>>>> should >> >>>> >>>>>>>>>> be: >> >>>> >>>>>>>>>> >> >>>> >>>>>>>>>> main = do >> >>>> >>>>>>>>>> hSetBuffering stdout NoBuffering >> >>>> >>>>>>>>>> hSetBuffering stdin NoBuffering >> >>>> >>>>>>>>>> test >> >>>> >>>>>>>>>> >> >>>> >>>>>>>>>> Now I think it should also be incorrect on Unix systems. >> >>>> >>>>>>>>>> I guess the way I'm concatenating the strings is not >> correct, >> >>>> >>>>>>>>>> not >> >>>> >>>>>>>>>> sure. >> >>>> >>>>>>>>>> I would like to use a graphical tool to show the graph >> >>>> >>>>>>>>>> reduction >> >>>> >>>>>>>>>> step by step, to get a better understanding of the >> laziness & >> >>>> >>>>>>>>>> strictness. >> >>>> >>>>>>>>>> Does such a tool exist? I know people often say this is >> not >> >>>> >>>>>>>>>> usable because >> >>>> >>>>>>>>>> the amount of information is too much, but I used to be an >> >>>> >>>>>>>>>> assembly language >> >>>> >>>>>>>>>> programmer so I still would like to give it a try :-) >> >>>> >>>>>>>>>> >> >>>> >>>>>>>>>> >> >>>> >>>>>>>>>> On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen >> >>>> >>>>>>>>>> wrote: >> >>>> >>>>>>>>>>> >> >>>> >>>>>>>>>>> In an attempt to get a deeper understanding of several >> >>>> >>>>>>>>>>> monads >> >>>> >>>>>>>>>>> (State, ST, IO, ...) I skimmed over some of the research >> >>>> >>>>>>>>>>> papers (but didn't >> >>>> >>>>>>>>>>> understand all of it, I lack the required education) and >> >>>> >>>>>>>>>>> decided to write a >> >>>> >>>>>>>>>>> little program myself without using any prefab monad >> >>>> >>>>>>>>>>> instances that should >> >>>> >>>>>>>>>>> mimic the following: >> >>>> >>>>>>>>>>> main = do >> >>>> >>>>>>>>>>> putStrLn "Enter your name:" >> >>>> >>>>>>>>>>> x <- getLine >> >>>> >>>>>>>>>>> putStr "Welcome " >> >>>> >>>>>>>>>>> putStrLn x >> >>>> >>>>>>>>>>> putStrLn "Goodbye!" >> >>>> >>>>>>>>>>> But instead of using IO, I wanted to make my own pure >> monad >> >>>> >>>>>>>>>>> that >> >>>> >>>>>>>>>>> gets evaluated with interact, and does the same. >> >>>> >>>>>>>>>>> However, I get the following output: >> >>>> >>>>>>>>>>> Enter your name: >> >>>> >>>>>>>>>>> Welcome ...... >> >>>> >>>>>>>>>>> So the Welcome is printed too soon. >> >>>> >>>>>>>>>>> This is obvious since my monad is lazy, so I tried to put >> a >> >>>> >>>>>>>>>>> seq >> >>>> >>>>>>>>>>> at some strategic places to get the same behavior as IO. >> But >> >>>> >>>>>>>>>>> I completely >> >>>> >>>>>>>>>>> failed doing so, either the program doesn't print >> anything >> >>>> >>>>>>>>>>> and asks input >> >>>> >>>>>>>>>>> first, or it still prints too much output. >> >>>> >>>>>>>>>>> Of course I could just use ST, State, transformers, etc, >> but >> >>>> >>>>>>>>>>> this >> >>>> >>>>>>>>>>> is purely an exercise I'm doing. >> >>>> >>>>>>>>>>> So, I could re-read all papers and look in detail at all >> the >> >>>> >>>>>>>>>>> code, but maybe someone could help me out where to put >> the >> >>>> >>>>>>>>>>> seq or what to do >> >>>> >>>>>>>>>>> :-) >> >>>> >>>>>>>>>>> The code is >> >>>> >>>>>>>>>>> at http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 >> >>>> >>>>>>>>>>> Oh btw, the usage of DList here might not be needed; >> >>>> >>>>>>>>>>> intuitively >> >>>> >>>>>>>>>>> it felt like the correct thing to do, but when it comes >> to >> >>>> >>>>>>>>>>> Haskell, my >> >>>> >>>>>>>>>>> intuition is usually wrong ;-) >> >>>> >>>>>>>>>>> Thanks a lot, >> >>>> >>>>>>>>>>> Peter Verswyvelen >> >>>> >>>>>>>>>> >> >>>> >>>>>>>>>> >> >>>> >>>>>>>>>> _______________________________________________ >> >>>> >>>>>>>>>> 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 >> >>>> > >> >>>> > >> >>> >> >> >> > >> > >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/7c3da8e6/attachment.html From leimy2k at gmail.com Wed Aug 19 16:06:38 2009 From: leimy2k at gmail.com (David Leimbach) Date: Wed Aug 19 15:46:44 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <2f9b2d30908191023s2c11aa72m47fa8729868f6f23@mail.gmail.com> <3e1162e60908191031t63795c4apfbd47820647016ab@mail.gmail.com> <3e1162e60908191037m5c79d589ia78db27dd1449ae8@mail.gmail.com> <2f9b2d30908191228m5b38ddf0ib56052a60ef817ba@mail.gmail.com> <3e1162e60908191246g756c16d0ide067fba48b97c68@mail.gmail.com> Message-ID: <3e1162e60908191306p266b438fwcf814b43190295da@mail.gmail.com> Hmmm very interesting thinking on this. Perhaps ByteStrings would be a good way to go for efficiency of composition. I'd love to see some profiling of all of this as part of the lesson at some point. (Perhaps with vacuum visualization?) This thread has tackled 3 major tricky issue areas with Haskell so far: 1. Lazy IO and seq 2. Roll-your-own-Monad 3. Data growth profiling. It's been a good read anyway, and fun to play with the code. Dave On Wed, Aug 19, 2009 at 1:00 PM, Peter Verswyvelen wrote: > Wow, very nice cleanup! That's really a good way for me to learn, thanks. > Well, my intuition told me that strings and ++ wouldn't work, since what we > want is an infinite list of output strings, and using ++ would result in > (((s1++s2)++s3)++s4)++s5... which is highly inefficient and I think it would > keep the complete output text in memory. Using difference lists results in > right associative concatenation of s1++(s2++(s3++(s4++... which is efficient > and can be garbage collected nicely. At least that's what I guess. I really > would like to get a deeper understanding of all this but that will take lots > of time and study, but if I'm lucky I still have 20 to 40 years to go, so I > won't be bored :-) > > > > > On Wed, Aug 19, 2009 at 9:46 PM, David Leimbach wrote: > >> Very cool! >> I am still wondering what the significance of the DList is with this >> though, or why it was needed to begin with. >> >> Dave >> >> >> On Wed, Aug 19, 2009 at 12:28 PM, Ryan Ingram wrote: >> >>> Added a new version (tested, works with infinite loops, no early output, >>> etc.) >>> >>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8343 >>> >>> I'll put up a short write-up after lunch. >>> >>> -- ryan >>> >>> On Wed, Aug 19, 2009 at 11:28 AM, Peter Verswyvelen >>> wrote: >>> > The cleaned up code didn't seem to work for me, it printed everything >>> before >>> > asking input again. >>> > But I added a patch that looks like it supports looping, but I don't >>> > understand exactly what is going on :-) >>> > I added the "delay" function which makes appending to the output less >>> > strict. >>> > Note that in this version I add a delay to each right argument of >>=, >>> but >>> > one could also do it manually >>> > On Wed, Aug 19, 2009 at 7:37 PM, David Leimbach >>> wrote: >>> >> >>> >> I've corrected it. It still doesn't suffer looping. :-) >>> >> >>> >> On Wed, Aug 19, 2009 at 10:31 AM, David Leimbach >>> >> wrote: >>> >>> >>> >>> Doesn't seem to compile. >>> >>> I nearly never use case statements in my code, so I'm not really sure >>> >>> what's going on. >>> >>> neat2.hs:14:39: parse error on input `=' >>> >>> Dave >>> >>> On Wed, Aug 19, 2009 at 10:23 AM, Ryan Ingram >>> >>> wrote: >>> >>>> >>> >>>> I posted a reply to your paste with a stricter version of S and some >>> >>>> cleanup. >>> >>>> >>> >>>> Untested, though I believe it should work without "seq". >>> >>>> >>> >>>> "case" provides all the strictness you need, I think! >>> >>>> >>> >>>> -- ryan >>> >>>> >>> >>>> On Wed, Aug 19, 2009 at 9:28 AM, Peter Verswyvelen< >>> bugfact@gmail.com> >>> >>>> wrote: >>> >>>> > Expect more bugs with this though :-) Just found out that looping >>> does >>> >>>> > not >>> >>>> > work, it hangs, e.g. >>> >>>> > >>> >>>> > test = do >>> >>>> > out "Enter your first name:" >>> >>>> > fstName <- inp >>> >>>> > out "Enter your second name:" >>> >>>> > sndName <- inp >>> >>>> > out ("Welcome "++fstName++" "++sndName) >>> >>>> > out "Goodbye!" >>> >>>> > test >>> >>>> > >>> >>>> > Doesn't seem to work :-) Back to the drawing board. >>> >>>> > >>> >>>> > On Wed, Aug 19, 2009 at 5:55 PM, Peter Verswyvelen < >>> bugfact@gmail.com> >>> >>>> > wrote: >>> >>>> >> >>> >>>> >> Not at all, use it for whatever you want to :-) >>> >>>> >> I'm writing this code because I'm preparing to write a bunch of >>> >>>> >> tutorials >>> >>>> >> on FRP, and I first wanted to start with simple console based >>> FRP, >>> >>>> >> e.g. >>> >>>> >> making a little text adventure game, where the input/choices of >>> the >>> >>>> >> user >>> >>>> >> might be parsed ala parsec, using monadic style, applicative >>> style, >>> >>>> >> and >>> >>>> >> arrows, and then doing the same with FRP frameworks like Yampa, >>> >>>> >> Elera, >>> >>>> >> Reactive, etc... >>> >>>> >> After that I would start writing tutorials that use OpenGL, >>> making >>> >>>> >> some >>> >>>> >> very simple games, again with the above approaches, and ending >>> with a >>> >>>> >> conversion of a very old game of mine (Zarathrusta written in >>> >>>> >> assembler from >>> >>>> >> 1991, which was based on Thrust from 1986, converted by myself in >>> C++ >>> >>>> >> to >>> >>>> >> PocketPC as G-Pod, and so I would like to make a version in >>> Haskell >>> >>>> >> that >>> >>>> >> runs on the iPhone :-) >>> >>>> >> This of course is a lot of work, and I would like to put this on >>> the >>> >>>> >> Haskell wiki or a blog or something, so others can contribute and >>> >>>> >> comment. I >>> >>>> >> would like to show real examples that explain the shortcomings of >>> the >>> >>>> >> FRP >>> >>>> >> approaches, because now this is still a bit blurry to me. >>> >>>> >> >>> >>>> >> On Wed, Aug 19, 2009 at 5:43 PM, David Leimbach < >>> leimy2k@gmail.com> >>> >>>> >> wrote: >>> >>>> >>> >>> >>>> >>> This Monad you've created is quite excellent. I was trying to >>> do >>> >>>> >>> something like this about a year ago, to make the input and >>> output >>> >>>> >>> handling >>> >>>> >>> of an interactive bowling score card work nicely. I kept >>> running >>> >>>> >>> into >>> >>>> >>> issues, and did not believe that seq was going to do the trick. >>> >>>> >>> Nice work! >>> >>>> >>> This is a very useful monad I think, it could be called >>> "Prompter" >>> >>>> >>> or >>> >>>> >>> something to that effect. >>> >>>> >>> Do you mind if I use it in some of my code? >>> >>>> >>> Dave >>> >>>> >>> >>> >>>> >>> On Wed, Aug 19, 2009 at 8:42 AM, Peter Verswyvelen >>> >>>> >>> >>> >>>> >>> wrote: >>> >>>> >>>> >>> >>>> >>>> LOL. Maybe we should have that coffee together ;-) at least >>> >>>> >>>> virtually! >>> >>>> >>>> On Wed, Aug 19, 2009 at 5:39 PM, David Leimbach < >>> leimy2k@gmail.com> >>> >>>> >>>> wrote: >>> >>>> >>>>> >>> >>>> >>>>> Argh... I too have been up too late :-). I edited THE WRONG >>> FILE! >>> >>>> >>>>> No >>> >>>> >>>>> wonder your change didn't take effect! :-/ >>> >>>> >>>>> Time for coffee I suppose. >>> >>>> >>>>> >>> >>>> >>>>> On Wed, Aug 19, 2009 at 8:38 AM, David Leimbach >>> >>>> >>>>> >>> >>>> >>>>> wrote: >>> >>>> >>>>>> >>> >>>> >>>>>> This doesn't seem to be working for me interactively though >>> on a >>> >>>> >>>>>> Mac. >>> >>>> >>>>>> I still get "Welcome" before I've entered text. >>> >>>> >>>>>> >>> >>>> >>>>>> On Wed, Aug 19, 2009 at 8:25 AM, Peter Verswyvelen >>> >>>> >>>>>> >>> >>>> >>>>>> wrote: >>> >>>> >>>>>>> >>> >>>> >>>>>>> I fixed it myself but it's really tricky :-) >>> >>>> >>>>>>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8330 >>> >>>> >>>>>>> The idea is, that when the input is requested, the output >>> that >>> >>>> >>>>>>> is >>> >>>> >>>>>>> then generated must be in sync with the input. >>> >>>> >>>>>>> >>> >>>> >>>>>>> inp = S $ \s i -> let r = (s `D.append` (i `seq` D.empty), >>> head >>> >>>> >>>>>>> i) in >>> >>>> >>>>>>> (tail i, r) >>> >>>> >>>>>>> >>> >>>> >>>>>>> >>> >>>> >>>>>>> I first had >>> >>>> >>>>>>> >>> >>>> >>>>>>> inp = S $ \s i -> let r = (i `seq` s, head i) in (tail i, r) >>> >>>> >>>>>>> >>> >>>> >>>>>>> But that was too eager, since i syncs the input not with the >>> >>>> >>>>>>> output, >>> >>>> >>>>>>> but with the function that will generate the output. >>> >>>> >>>>>>> >>> >>>> >>>>>>> >>> >>>> >>>>>>> >>> >>>> >>>>>>> >>> >>>> >>>>>>> >>> >>>> >>>>>>> >>> >>>> >>>>>>> >>> >>>> >>>>>>> Okay, now I can sleep again :-) >>> >>>> >>>>>>> >>> >>>> >>>>>>> >>> >>>> >>>>>>> >>> >>>> >>>>>>> >>> >>>> >>>>>>> >>> >>>> >>>>>>> >>> >>>> >>>>>>> >>> >>>> >>>>>>> >>> >>>> >>>>>>> >>> >>>> >>>>>>> >>> >>>> >>>>>>> On Wed, Aug 19, 2009 at 5:12 PM, Peter Verswyvelen >>> >>>> >>>>>>> wrote: >>> >>>> >>>>>>>> >>> >>>> >>>>>>>> Thanks, but that doesn't really matter in my example, my >>> code >>> >>>> >>>>>>>> is >>> >>>> >>>>>>>> just buggy, and I'm not sure why. For example if I change >>> my >>> >>>> >>>>>>>> test function >>> >>>> >>>>>>>> so that it outputs lines only, then it still prints Welcome >>> >>>> >>>>>>>> first before >>> >>>> >>>>>>>> asking for input. >>> >>>> >>>>>>>> See >>> >>>> >>>>>>>> e.g. >>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328 >>> >>>> >>>>>>>> On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach >>> >>>> >>>>>>>> >>> >>>> >>>>>>>> wrote: >>> >>>> >>>>>>>>> >>> >>>> >>>>>>>>> Try LineBuffering. >>> >>>> >>>>>>>>> I do linewise stuff with interact a lot. You'll find >>> stuff >>> >>>> >>>>>>>>> like >>> >>>> >>>>>>>>> unlines . lines >>> >>>> >>>>>>>>> may help too. In fact I just wrote a blog post about >>> this. >>> >>>> >>>>>>>>> http://leimy9.blogspot.com >>> >>>> >>>>>>>>> I'm trying to write some interactive code to automate >>> working >>> >>>> >>>>>>>>> with >>> >>>> >>>>>>>>> serial console controlled power strips, so I need to >>> either >>> >>>> >>>>>>>>> use Expect >>> >>>> >>>>>>>>> (yuck) or do my own thing. >>> >>>> >>>>>>>>> Dave >>> >>>> >>>>>>>>> >>> >>>> >>>>>>>>> On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen >>> >>>> >>>>>>>>> wrote: >>> >>>> >>>>>>>>>> >>> >>>> >>>>>>>>>> Apparently this particular example happens to work on Mac >>> and >>> >>>> >>>>>>>>>> Linux because of different buffering (thanks Martijn for >>> the >>> >>>> >>>>>>>>>> help!) >>> >>>> >>>>>>>>>> To make sure we have no buffering at all, the main >>> function >>> >>>> >>>>>>>>>> should >>> >>>> >>>>>>>>>> be: >>> >>>> >>>>>>>>>> >>> >>>> >>>>>>>>>> main = do >>> >>>> >>>>>>>>>> hSetBuffering stdout NoBuffering >>> >>>> >>>>>>>>>> hSetBuffering stdin NoBuffering >>> >>>> >>>>>>>>>> test >>> >>>> >>>>>>>>>> >>> >>>> >>>>>>>>>> Now I think it should also be incorrect on Unix systems. >>> >>>> >>>>>>>>>> I guess the way I'm concatenating the strings is not >>> correct, >>> >>>> >>>>>>>>>> not >>> >>>> >>>>>>>>>> sure. >>> >>>> >>>>>>>>>> I would like to use a graphical tool to show the graph >>> >>>> >>>>>>>>>> reduction >>> >>>> >>>>>>>>>> step by step, to get a better understanding of the >>> laziness & >>> >>>> >>>>>>>>>> strictness. >>> >>>> >>>>>>>>>> Does such a tool exist? I know people often say this is >>> not >>> >>>> >>>>>>>>>> usable because >>> >>>> >>>>>>>>>> the amount of information is too much, but I used to be >>> an >>> >>>> >>>>>>>>>> assembly language >>> >>>> >>>>>>>>>> programmer so I still would like to give it a try :-) >>> >>>> >>>>>>>>>> >>> >>>> >>>>>>>>>> >>> >>>> >>>>>>>>>> On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen >>> >>>> >>>>>>>>>> wrote: >>> >>>> >>>>>>>>>>> >>> >>>> >>>>>>>>>>> In an attempt to get a deeper understanding of several >>> >>>> >>>>>>>>>>> monads >>> >>>> >>>>>>>>>>> (State, ST, IO, ...) I skimmed over some of the research >>> >>>> >>>>>>>>>>> papers (but didn't >>> >>>> >>>>>>>>>>> understand all of it, I lack the required education) and >>> >>>> >>>>>>>>>>> decided to write a >>> >>>> >>>>>>>>>>> little program myself without using any prefab monad >>> >>>> >>>>>>>>>>> instances that should >>> >>>> >>>>>>>>>>> mimic the following: >>> >>>> >>>>>>>>>>> main = do >>> >>>> >>>>>>>>>>> putStrLn "Enter your name:" >>> >>>> >>>>>>>>>>> x <- getLine >>> >>>> >>>>>>>>>>> putStr "Welcome " >>> >>>> >>>>>>>>>>> putStrLn x >>> >>>> >>>>>>>>>>> putStrLn "Goodbye!" >>> >>>> >>>>>>>>>>> But instead of using IO, I wanted to make my own pure >>> monad >>> >>>> >>>>>>>>>>> that >>> >>>> >>>>>>>>>>> gets evaluated with interact, and does the same. >>> >>>> >>>>>>>>>>> However, I get the following output: >>> >>>> >>>>>>>>>>> Enter your name: >>> >>>> >>>>>>>>>>> Welcome ...... >>> >>>> >>>>>>>>>>> So the Welcome is printed too soon. >>> >>>> >>>>>>>>>>> This is obvious since my monad is lazy, so I tried to >>> put a >>> >>>> >>>>>>>>>>> seq >>> >>>> >>>>>>>>>>> at some strategic places to get the same behavior as IO. >>> But >>> >>>> >>>>>>>>>>> I completely >>> >>>> >>>>>>>>>>> failed doing so, either the program doesn't print >>> anything >>> >>>> >>>>>>>>>>> and asks input >>> >>>> >>>>>>>>>>> first, or it still prints too much output. >>> >>>> >>>>>>>>>>> Of course I could just use ST, State, transformers, etc, >>> but >>> >>>> >>>>>>>>>>> this >>> >>>> >>>>>>>>>>> is purely an exercise I'm doing. >>> >>>> >>>>>>>>>>> So, I could re-read all papers and look in detail at all >>> the >>> >>>> >>>>>>>>>>> code, but maybe someone could help me out where to put >>> the >>> >>>> >>>>>>>>>>> seq or what to do >>> >>>> >>>>>>>>>>> :-) >>> >>>> >>>>>>>>>>> The code is >>> >>>> >>>>>>>>>>> at http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 >>> >>>> >>>>>>>>>>> Oh btw, the usage of DList here might not be needed; >>> >>>> >>>>>>>>>>> intuitively >>> >>>> >>>>>>>>>>> it felt like the correct thing to do, but when it comes >>> to >>> >>>> >>>>>>>>>>> Haskell, my >>> >>>> >>>>>>>>>>> intuition is usually wrong ;-) >>> >>>> >>>>>>>>>>> Thanks a lot, >>> >>>> >>>>>>>>>>> Peter Verswyvelen >>> >>>> >>>>>>>>>> >>> >>>> >>>>>>>>>> >>> >>>> >>>>>>>>>> _______________________________________________ >>> >>>> >>>>>>>>>> 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 >>> >>>> > >>> >>>> > >>> >>> >>> >> >>> > >>> > >>> >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/2c927b06/attachment.html From bugfact at gmail.com Wed Aug 19 16:20:58 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 19 16:01:04 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <3e1162e60908191306p266b438fwcf814b43190295da@mail.gmail.com> References: <2f9b2d30908191023s2c11aa72m47fa8729868f6f23@mail.gmail.com> <3e1162e60908191031t63795c4apfbd47820647016ab@mail.gmail.com> <3e1162e60908191037m5c79d589ia78db27dd1449ae8@mail.gmail.com> <2f9b2d30908191228m5b38ddf0ib56052a60ef817ba@mail.gmail.com> <3e1162e60908191246g756c16d0ide067fba48b97c68@mail.gmail.com> <3e1162e60908191306p266b438fwcf814b43190295da@mail.gmail.com> Message-ID: Well I really wrote this code as an exercise, and it was a good one. Now I (or someone) needs to explain why it works. But is this monad really useful? I mean it would be straightforward to write this using the ST monad I guess? Anyway, the reason why I want this pure code is that even with a console based game, I don't want IO in it, since recording the input and replaying it is vital to reproduce the actions the user did, and if things go wrong (they always do), the log of all input can be used to restore the exact game play. Of course you can do the same using imperative techniques and IO redirection (which I did for my old games), but with this pure code you don't have to worry about other places where IO could be used. On Wed, Aug 19, 2009 at 10:06 PM, David Leimbach wrote: > Hmmm very interesting thinking on this. Perhaps ByteStrings would be a > good way to go for efficiency of composition. > I'd love to see some profiling of all of this as part of the lesson at some > point. (Perhaps with vacuum visualization?) > > This thread has tackled 3 major tricky issue areas with Haskell so far: > > 1. Lazy IO and seq > 2. Roll-your-own-Monad > 3. Data growth profiling. > > It's been a good read anyway, and fun to play with the code. > > Dave > > On Wed, Aug 19, 2009 at 1:00 PM, Peter Verswyvelen wrote: > >> Wow, very nice cleanup! That's really a good way for me to learn, thanks. >> Well, my intuition told me that strings and ++ wouldn't work, since what >> we want is an infinite list of output strings, and using ++ would result in >> (((s1++s2)++s3)++s4)++s5... which is highly inefficient and I think it would >> keep the complete output text in memory. Using difference lists results in >> right associative concatenation of s1++(s2++(s3++(s4++... which is efficient >> and can be garbage collected nicely. At least that's what I guess. I really >> would like to get a deeper understanding of all this but that will take lots >> of time and study, but if I'm lucky I still have 20 to 40 years to go, so I >> won't be bored :-) >> >> >> >> >> On Wed, Aug 19, 2009 at 9:46 PM, David Leimbach wrote: >> >>> Very cool! >>> I am still wondering what the significance of the DList is with this >>> though, or why it was needed to begin with. >>> >>> Dave >>> >>> >>> On Wed, Aug 19, 2009 at 12:28 PM, Ryan Ingram wrote: >>> >>>> Added a new version (tested, works with infinite loops, no early output, >>>> etc.) >>>> >>>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8343 >>>> >>>> I'll put up a short write-up after lunch. >>>> >>>> -- ryan >>>> >>>> On Wed, Aug 19, 2009 at 11:28 AM, Peter Verswyvelen >>>> wrote: >>>> > The cleaned up code didn't seem to work for me, it printed everything >>>> before >>>> > asking input again. >>>> > But I added a patch that looks like it supports looping, but I don't >>>> > understand exactly what is going on :-) >>>> > I added the "delay" function which makes appending to the output less >>>> > strict. >>>> > Note that in this version I add a delay to each right argument of >>=, >>>> but >>>> > one could also do it manually >>>> > On Wed, Aug 19, 2009 at 7:37 PM, David Leimbach >>>> wrote: >>>> >> >>>> >> I've corrected it. It still doesn't suffer looping. :-) >>>> >> >>>> >> On Wed, Aug 19, 2009 at 10:31 AM, David Leimbach >>>> >> wrote: >>>> >>> >>>> >>> Doesn't seem to compile. >>>> >>> I nearly never use case statements in my code, so I'm not really >>>> sure >>>> >>> what's going on. >>>> >>> neat2.hs:14:39: parse error on input `=' >>>> >>> Dave >>>> >>> On Wed, Aug 19, 2009 at 10:23 AM, Ryan Ingram >>> > >>>> >>> wrote: >>>> >>>> >>>> >>>> I posted a reply to your paste with a stricter version of S and >>>> some >>>> >>>> cleanup. >>>> >>>> >>>> >>>> Untested, though I believe it should work without "seq". >>>> >>>> >>>> >>>> "case" provides all the strictness you need, I think! >>>> >>>> >>>> >>>> -- ryan >>>> >>>> >>>> >>>> On Wed, Aug 19, 2009 at 9:28 AM, Peter Verswyvelen< >>>> bugfact@gmail.com> >>>> >>>> wrote: >>>> >>>> > Expect more bugs with this though :-) Just found out that looping >>>> does >>>> >>>> > not >>>> >>>> > work, it hangs, e.g. >>>> >>>> > >>>> >>>> > test = do >>>> >>>> > out "Enter your first name:" >>>> >>>> > fstName <- inp >>>> >>>> > out "Enter your second name:" >>>> >>>> > sndName <- inp >>>> >>>> > out ("Welcome "++fstName++" "++sndName) >>>> >>>> > out "Goodbye!" >>>> >>>> > test >>>> >>>> > >>>> >>>> > Doesn't seem to work :-) Back to the drawing board. >>>> >>>> > >>>> >>>> > On Wed, Aug 19, 2009 at 5:55 PM, Peter Verswyvelen < >>>> bugfact@gmail.com> >>>> >>>> > wrote: >>>> >>>> >> >>>> >>>> >> Not at all, use it for whatever you want to :-) >>>> >>>> >> I'm writing this code because I'm preparing to write a bunch of >>>> >>>> >> tutorials >>>> >>>> >> on FRP, and I first wanted to start with simple console based >>>> FRP, >>>> >>>> >> e.g. >>>> >>>> >> making a little text adventure game, where the input/choices of >>>> the >>>> >>>> >> user >>>> >>>> >> might be parsed ala parsec, using monadic style, applicative >>>> style, >>>> >>>> >> and >>>> >>>> >> arrows, and then doing the same with FRP frameworks like Yampa, >>>> >>>> >> Elera, >>>> >>>> >> Reactive, etc... >>>> >>>> >> After that I would start writing tutorials that use OpenGL, >>>> making >>>> >>>> >> some >>>> >>>> >> very simple games, again with the above approaches, and ending >>>> with a >>>> >>>> >> conversion of a very old game of mine (Zarathrusta written in >>>> >>>> >> assembler from >>>> >>>> >> 1991, which was based on Thrust from 1986, converted by myself >>>> in C++ >>>> >>>> >> to >>>> >>>> >> PocketPC as G-Pod, and so I would like to make a version in >>>> Haskell >>>> >>>> >> that >>>> >>>> >> runs on the iPhone :-) >>>> >>>> >> This of course is a lot of work, and I would like to put this on >>>> the >>>> >>>> >> Haskell wiki or a blog or something, so others can contribute >>>> and >>>> >>>> >> comment. I >>>> >>>> >> would like to show real examples that explain the shortcomings >>>> of the >>>> >>>> >> FRP >>>> >>>> >> approaches, because now this is still a bit blurry to me. >>>> >>>> >> >>>> >>>> >> On Wed, Aug 19, 2009 at 5:43 PM, David Leimbach < >>>> leimy2k@gmail.com> >>>> >>>> >> wrote: >>>> >>>> >>> >>>> >>>> >>> This Monad you've created is quite excellent. I was trying to >>>> do >>>> >>>> >>> something like this about a year ago, to make the input and >>>> output >>>> >>>> >>> handling >>>> >>>> >>> of an interactive bowling score card work nicely. I kept >>>> running >>>> >>>> >>> into >>>> >>>> >>> issues, and did not believe that seq was going to do the trick. >>>> >>>> >>> Nice work! >>>> >>>> >>> This is a very useful monad I think, it could be called >>>> "Prompter" >>>> >>>> >>> or >>>> >>>> >>> something to that effect. >>>> >>>> >>> Do you mind if I use it in some of my code? >>>> >>>> >>> Dave >>>> >>>> >>> >>>> >>>> >>> On Wed, Aug 19, 2009 at 8:42 AM, Peter Verswyvelen >>>> >>>> >>> >>>> >>>> >>> wrote: >>>> >>>> >>>> >>>> >>>> >>>> LOL. Maybe we should have that coffee together ;-) at least >>>> >>>> >>>> virtually! >>>> >>>> >>>> On Wed, Aug 19, 2009 at 5:39 PM, David Leimbach < >>>> leimy2k@gmail.com> >>>> >>>> >>>> wrote: >>>> >>>> >>>>> >>>> >>>> >>>>> Argh... I too have been up too late :-). I edited THE WRONG >>>> FILE! >>>> >>>> >>>>> No >>>> >>>> >>>>> wonder your change didn't take effect! :-/ >>>> >>>> >>>>> Time for coffee I suppose. >>>> >>>> >>>>> >>>> >>>> >>>>> On Wed, Aug 19, 2009 at 8:38 AM, David Leimbach >>>> >>>> >>>>> >>>> >>>> >>>>> wrote: >>>> >>>> >>>>>> >>>> >>>> >>>>>> This doesn't seem to be working for me interactively though >>>> on a >>>> >>>> >>>>>> Mac. >>>> >>>> >>>>>> I still get "Welcome" before I've entered text. >>>> >>>> >>>>>> >>>> >>>> >>>>>> On Wed, Aug 19, 2009 at 8:25 AM, Peter Verswyvelen >>>> >>>> >>>>>> >>>> >>>> >>>>>> wrote: >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> I fixed it myself but it's really tricky :-) >>>> >>>> >>>>>>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8330 >>>> >>>> >>>>>>> The idea is, that when the input is requested, the output >>>> that >>>> >>>> >>>>>>> is >>>> >>>> >>>>>>> then generated must be in sync with the input. >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> inp = S $ \s i -> let r = (s `D.append` (i `seq` D.empty), >>>> head >>>> >>>> >>>>>>> i) in >>>> >>>> >>>>>>> (tail i, r) >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> I first had >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> inp = S $ \s i -> let r = (i `seq` s, head i) in (tail i, >>>> r) >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> But that was too eager, since i syncs the input not with >>>> the >>>> >>>> >>>>>>> output, >>>> >>>> >>>>>>> but with the function that will generate the output. >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> Okay, now I can sleep again :-) >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> >>>> >>>> >>>>>>> On Wed, Aug 19, 2009 at 5:12 PM, Peter Verswyvelen >>>> >>>> >>>>>>> wrote: >>>> >>>> >>>>>>>> >>>> >>>> >>>>>>>> Thanks, but that doesn't really matter in my example, my >>>> code >>>> >>>> >>>>>>>> is >>>> >>>> >>>>>>>> just buggy, and I'm not sure why. For example if I change >>>> my >>>> >>>> >>>>>>>> test function >>>> >>>> >>>>>>>> so that it outputs lines only, then it still prints >>>> Welcome >>>> >>>> >>>>>>>> first before >>>> >>>> >>>>>>>> asking for input. >>>> >>>> >>>>>>>> See >>>> >>>> >>>>>>>> e.g. >>>> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328 >>>> >>>> >>>>>>>> On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach >>>> >>>> >>>>>>>> >>>> >>>> >>>>>>>> wrote: >>>> >>>> >>>>>>>>> >>>> >>>> >>>>>>>>> Try LineBuffering. >>>> >>>> >>>>>>>>> I do linewise stuff with interact a lot. You'll find >>>> stuff >>>> >>>> >>>>>>>>> like >>>> >>>> >>>>>>>>> unlines . lines >>>> >>>> >>>>>>>>> may help too. In fact I just wrote a blog post about >>>> this. >>>> >>>> >>>>>>>>> http://leimy9.blogspot.com >>>> >>>> >>>>>>>>> I'm trying to write some interactive code to automate >>>> working >>>> >>>> >>>>>>>>> with >>>> >>>> >>>>>>>>> serial console controlled power strips, so I need to >>>> either >>>> >>>> >>>>>>>>> use Expect >>>> >>>> >>>>>>>>> (yuck) or do my own thing. >>>> >>>> >>>>>>>>> Dave >>>> >>>> >>>>>>>>> >>>> >>>> >>>>>>>>> On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen >>>> >>>> >>>>>>>>> wrote: >>>> >>>> >>>>>>>>>> >>>> >>>> >>>>>>>>>> Apparently this particular example happens to work on >>>> Mac and >>>> >>>> >>>>>>>>>> Linux because of different buffering (thanks Martijn for >>>> the >>>> >>>> >>>>>>>>>> help!) >>>> >>>> >>>>>>>>>> To make sure we have no buffering at all, the main >>>> function >>>> >>>> >>>>>>>>>> should >>>> >>>> >>>>>>>>>> be: >>>> >>>> >>>>>>>>>> >>>> >>>> >>>>>>>>>> main = do >>>> >>>> >>>>>>>>>> hSetBuffering stdout NoBuffering >>>> >>>> >>>>>>>>>> hSetBuffering stdin NoBuffering >>>> >>>> >>>>>>>>>> test >>>> >>>> >>>>>>>>>> >>>> >>>> >>>>>>>>>> Now I think it should also be incorrect on Unix systems. >>>> >>>> >>>>>>>>>> I guess the way I'm concatenating the strings is not >>>> correct, >>>> >>>> >>>>>>>>>> not >>>> >>>> >>>>>>>>>> sure. >>>> >>>> >>>>>>>>>> I would like to use a graphical tool to show the graph >>>> >>>> >>>>>>>>>> reduction >>>> >>>> >>>>>>>>>> step by step, to get a better understanding of the >>>> laziness & >>>> >>>> >>>>>>>>>> strictness. >>>> >>>> >>>>>>>>>> Does such a tool exist? I know people often say this is >>>> not >>>> >>>> >>>>>>>>>> usable because >>>> >>>> >>>>>>>>>> the amount of information is too much, but I used to be >>>> an >>>> >>>> >>>>>>>>>> assembly language >>>> >>>> >>>>>>>>>> programmer so I still would like to give it a try :-) >>>> >>>> >>>>>>>>>> >>>> >>>> >>>>>>>>>> >>>> >>>> >>>>>>>>>> On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen >>>> >>>> >>>>>>>>>> wrote: >>>> >>>> >>>>>>>>>>> >>>> >>>> >>>>>>>>>>> In an attempt to get a deeper understanding of several >>>> >>>> >>>>>>>>>>> monads >>>> >>>> >>>>>>>>>>> (State, ST, IO, ...) I skimmed over some of the >>>> research >>>> >>>> >>>>>>>>>>> papers (but didn't >>>> >>>> >>>>>>>>>>> understand all of it, I lack the required education) >>>> and >>>> >>>> >>>>>>>>>>> decided to write a >>>> >>>> >>>>>>>>>>> little program myself without using any prefab monad >>>> >>>> >>>>>>>>>>> instances that should >>>> >>>> >>>>>>>>>>> mimic the following: >>>> >>>> >>>>>>>>>>> main = do >>>> >>>> >>>>>>>>>>> putStrLn "Enter your name:" >>>> >>>> >>>>>>>>>>> x <- getLine >>>> >>>> >>>>>>>>>>> putStr "Welcome " >>>> >>>> >>>>>>>>>>> putStrLn x >>>> >>>> >>>>>>>>>>> putStrLn "Goodbye!" >>>> >>>> >>>>>>>>>>> But instead of using IO, I wanted to make my own pure >>>> monad >>>> >>>> >>>>>>>>>>> that >>>> >>>> >>>>>>>>>>> gets evaluated with interact, and does the same. >>>> >>>> >>>>>>>>>>> However, I get the following output: >>>> >>>> >>>>>>>>>>> Enter your name: >>>> >>>> >>>>>>>>>>> Welcome ...... >>>> >>>> >>>>>>>>>>> So the Welcome is printed too soon. >>>> >>>> >>>>>>>>>>> This is obvious since my monad is lazy, so I tried to >>>> put a >>>> >>>> >>>>>>>>>>> seq >>>> >>>> >>>>>>>>>>> at some strategic places to get the same behavior as >>>> IO. But >>>> >>>> >>>>>>>>>>> I completely >>>> >>>> >>>>>>>>>>> failed doing so, either the program doesn't print >>>> anything >>>> >>>> >>>>>>>>>>> and asks input >>>> >>>> >>>>>>>>>>> first, or it still prints too much output. >>>> >>>> >>>>>>>>>>> Of course I could just use ST, State, transformers, >>>> etc, but >>>> >>>> >>>>>>>>>>> this >>>> >>>> >>>>>>>>>>> is purely an exercise I'm doing. >>>> >>>> >>>>>>>>>>> So, I could re-read all papers and look in detail at >>>> all the >>>> >>>> >>>>>>>>>>> code, but maybe someone could help me out where to put >>>> the >>>> >>>> >>>>>>>>>>> seq or what to do >>>> >>>> >>>>>>>>>>> :-) >>>> >>>> >>>>>>>>>>> The code is >>>> >>>> >>>>>>>>>>> at http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316 >>>> >>>> >>>>>>>>>>> Oh btw, the usage of DList here might not be needed; >>>> >>>> >>>>>>>>>>> intuitively >>>> >>>> >>>>>>>>>>> it felt like the correct thing to do, but when it comes >>>> to >>>> >>>> >>>>>>>>>>> Haskell, my >>>> >>>> >>>>>>>>>>> intuition is usually wrong ;-) >>>> >>>> >>>>>>>>>>> Thanks a lot, >>>> >>>> >>>>>>>>>>> Peter Verswyvelen >>>> >>>> >>>>>>>>>> >>>> >>>> >>>>>>>>>> >>>> >>>> >>>>>>>>>> _______________________________________________ >>>> >>>> >>>>>>>>>> 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 >>>> >>>> > >>>> >>>> > >>>> >>> >>>> >> >>>> > >>>> > >>>> >>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/0c71f0fe/attachment-0001.html From sebastian.sylvan at gmail.com Wed Aug 19 18:24:18 2009 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Wed Aug 19 18:04:20 2009 Subject: [Haskell-cafe] gbp sign showing as unknown character by GHC In-Reply-To: References: <3e1162e60908191039w7daeca17p13d4c79c549c6244@mail.gmail.com> Message-ID: <3d96ac180908191524n652459a1rebacdf8f3a6d3be6@mail.gmail.com> Both of these happen on Windows 7 64-bit for me too. On Wed, Aug 19, 2009 at 7:08 PM, Iain Barnett wrote: > > > 2009/8/19 David Leimbach > >> Interesting... GHCI bug? Didn't the readline dependency go away not too >> long ago? Could it be related? >> > > I just tried this > > Prelude> putStrLn "\?" > ghc: panic! (the 'impossible' happened) > (GHC version 6.10.4 for i386-unknown-linux): > charType: '\163' > > Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug > > > So perhaps I should put in a bug report, as that shouldn't happen (it > doesn't with some other characters I tried), unless anyone has a different > idea? I'm running Arch Linux with xmonad and using roxterm, so perhaps it's > something to do with my setup? > > Iain > > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -- Sebastian Sylvan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/c6f86647/attachment.html From judah.jacobson at gmail.com Wed Aug 19 18:53:03 2009 From: judah.jacobson at gmail.com (Judah Jacobson) Date: Wed Aug 19 18:33:25 2009 Subject: [Haskell-cafe] gbp sign showing as unknown character by GHC In-Reply-To: References: Message-ID: <6d74b0d20908191553q6c8586f2y302f3e7c3055c9aa@mail.gmail.com> On Wed, Aug 19, 2009 at 10:31 AM, Iain Barnett wrote: > Quick question:?I've tested this in a couple of different terminals (roxterm > and xterm), so I'm fairly sure it's GHC that's the problem. Have I missed a > setting? > GHCi, version 6.10.4 > Prelude> putStrLn "?" > ? > Hugs98?200609-3 > Hugs> putStrLn "?" > ? > ghc-6.10.4 and earlier don't automatically encode/decode Unicode characters. So on terminals which don't use the latin-1 encoding, you need to do the conversion explicitly with a separate package such as utf8-string, iconv or text-icu. For example, on OS X: $ echo $LANG en_US.UTF-8 $ ghci Prelude> putStrLn "?" ? Prelude> System.IO.UTF8.putStrLn "?" ? The conversion is done automatically by hugs, which is why the outputs differ. This feature will also be supported in ghc-6.12. -Judah From florbitous at gmail.com Wed Aug 19 23:06:36 2009 From: florbitous at gmail.com (Bernie Pope) Date: Wed Aug 19 22:46:38 2009 Subject: [Haskell-cafe] Keeping an indexed collection of values? In-Reply-To: References: Message-ID: <4d8ad03a0908192006k11a72e98w2bf27bf9b48f8117@mail.gmail.com> 2009/8/19 Job Vranish : > > My first hacked up attempt is as follows: > > data IndexedCollection a = IndexedCollection { > ??? nextKey???? ? ? ?? :: Int, > ??? availableKeys :: [Int], > ??? items??? ? ? ? ? ??? :: (IntMap Int a) > } deriving (Show) > > emptyIndexedCollection :: IndexedCollection a > emptyIndexedCollection = IndexedCollection 0 [] empty > > addItem :: a -> IndexedCollection a -> (Int, IndexedCollection a) > addItem a (IndexedCollection nextKey' []???? t) = (nextKey', > IndexedCollection (nextKey' + 1) [] (insert nextKey' a t)) > addItem a (IndexedCollection nextKey' (k:ks) t) = (k, IndexedCollection > nextKey' ks (insert k a t)) > > removeItem :: Int -> IndexedCollection a -> IndexedCollection a > removeItem k (IndexedCollection nextKey' ks t) = IndexedCollection nextKey' > (k:ks) (delete k t) > > lookupItem :: Int -> IndexedCollection a -> Maybe a > lookupItem k (IndexedCollection _ _ t) = lookup k t It might be the case for IntMap (I haven't checked) that it is better to do a modify operation than to do a deletion followed by an insertion on the same key. One possible improvement is to delay deletions by putting them in a pending queue. A pending deletion followed by an addItem could be coalesced into a modify operation on the key to be deleted. You could even push lookupItems through pending deletions, assuming that they aren't on the same key (if they are on the same key then the lookup would fail). One question is how big should the pending deletion queue be allowed to become? A long queue might not be a good idea. One problem with delaying deletions is that it could introduce a space leak (same as unintended lazy evaluation). Maybe a queue of max length one is sufficient? I'm not sure it is worth the trouble, but it might be fun to try. Cheers, Bernie. From k2msmith at gmail.com Wed Aug 19 23:44:28 2009 From: k2msmith at gmail.com (Kevin Smith) Date: Wed Aug 19 23:24:30 2009 Subject: [Haskell-cafe] Control.Parallel on 6.10.4 - Mac OS X version In-Reply-To: <20090819031718.GA1623@whirlpool.galois.com> References: <49dd14e0908182015q10e80597n325658072ea74266@mail.gmail.com> <20090819031718.GA1623@whirlpool.galois.com> Message-ID: <49dd14e0908192044x744889f9w3a02417218e8cf94@mail.gmail.com> I ran the simple parallel "hello world" on my system. the output of the programs with N1 and N2 is shown below. I'm not sure how to interpret this - it looks like I am getting a little speedup on the "real time". I'm running the 6.10.4 install package for Mac OS X on a intel core 2 mac book. Here is output of ghc --info: Macintosh-4:~ kevinsmith$ ghc --info [("Project name","The Glorious Glasgow Haskell Compilation System") ,("Project version","6.10.4") ,("Booter version","6.10.3.20090628") ,("Stage","2") ,("Interface file version","6") ,("Have interpreter","YES") ,("Object splitting","YES") ,("Have native code generator","YES") ,("Support SMP","YES") ,("Unregisterised","NO") ,("Tables next to code","YES") ,("Win32 DLLs","") ,("RTS ways"," debug thr thr_p thr_debug") ,("Leading underscore","YES") ,("Debug on","False") ] Here is output from program: $ time ./paratest +RTS -N1 -s ./paratest +RTS -N1 -s 1405006117752879898543142606244511569936384005711076 758,080,164 bytes allocated in the heap 61,076 bytes copied during GC 3,044 bytes maximum residency (1 sample(s)) 16,204 bytes maximum slop 1 MB total memory in use (0 MB lost due to fragmentation) Generation 0: 1445 collections, 0 parallel, 0.08s, 0.08s elapsed Generation 1: 1 collections, 0 parallel, 0.00s, 0.00s elapsed Task 0 (worker) : MUT time: 0.00s ( 0.00s elapsed) GC time: 0.00s ( 0.00s elapsed) Task 1 (worker) : MUT time: 1.91s ( 1.86s elapsed) GC time: 0.00s ( 0.00s elapsed) Task 2 (worker) : MUT time: 1.83s ( 1.86s elapsed) GC time: 0.08s ( 0.08s elapsed) INIT time 0.00s ( 0.00s elapsed) MUT time 1.83s ( 1.86s elapsed) GC time 0.08s ( 0.08s elapsed) EXIT time 0.00s ( 0.00s elapsed) Total time 1.91s ( 1.94s elapsed) %GC time 4.1% (4.3% elapsed) Alloc rate 413,412,206 bytes per MUT second Productivity 95.9% of total user, 94.4% of total elapsed recordMutableGen_sync: 0 gc_alloc_block_sync: 0 whitehole_spin: 0 gen[0].steps[0].sync_todo: 0 gen[0].steps[0].sync_large_objects: 0 gen[0].steps[1].sync_todo: 0 gen[0].steps[1].sync_large_objects: 0 gen[1].steps[0].sync_todo: 0 gen[1].steps[0].sync_large_objects: 0 real 0m1.946s user 0m1.912s sys 0m0.025s Macintosh-4:~ kevinsmith$ time ./paratest +RTS -N2 -s ./paratest +RTS -N2 -s 1405006117752879898543142606244511569936384005711076 758,092,440 bytes allocated in the heap 79,084 bytes copied during GC 3,076 bytes maximum residency (1 sample(s)) 14,724 bytes maximum slop 2 MB total memory in use (0 MB lost due to fragmentation) Generation 0: 1024 collections, 0 parallel, 0.08s, 0.08s elapsed Generation 1: 1 collections, 0 parallel, 0.00s, 0.00s elapsed Parallel GC work balance: nan (0 / 0, ideal 2) Task 0 (worker) : MUT time: 1.84s ( 1.18s elapsed) GC time: 0.08s ( 0.08s elapsed) Task 1 (worker) : MUT time: 1.92s ( 1.18s elapsed) GC time: 0.00s ( 0.00s elapsed) Task 2 (worker) : MUT time: 1.92s ( 1.18s elapsed) GC time: 0.00s ( 0.00s elapsed) Task 3 (worker) : MUT time: 1.92s ( 1.18s elapsed) GC time: 0.00s ( 0.00s elapsed) INIT time 0.00s ( 0.00s elapsed) MUT time 1.84s ( 1.18s elapsed) GC time 0.08s ( 0.08s elapsed) EXIT time 0.00s ( 0.00s elapsed) Total time 1.92s ( 1.27s elapsed) %GC time 4.0% (6.5% elapsed) Alloc rate 411,138,454 bytes per MUT second Productivity 95.9% of total user, 145.6% of total elapsed recordMutableGen_sync: 0 gc_alloc_block_sync: 0 whitehole_spin: 0 gen[0].steps[0].sync_todo: 0 gen[0].steps[0].sync_large_objects: 0 gen[0].steps[1].sync_todo: 0 gen[0].steps[1].sync_large_objects: 0 gen[1].steps[0].sync_todo: 0 gen[1].steps[0].sync_large_objects: 0 real 0m1.269s user 0m1.922s sys 0m0.042s On Tue, Aug 18, 2009 at 8:17 PM, Don Stewart wrote: > k2msmith: > > I'm using the Control.Parallel package on ghc version 6.10.4 and I don't > seem > > to be getting any parallel threads or sparks created at all with the > > "-threaded" compilation option using runtime flags "+RTS -N2". I'm using > > simple examples from the paper "A Tutorial on Parallel and Concurrent > > Programming in Haskell" by Jones and Singh. > > > > I'm running on an Intel Mac core 2 duo. Does anyone know how I can check > if > > the parallel functionality in ghc is working on my 6.10.4 ghc package > installed > > on this platform ? I installed it from the "supported" runtime pkg for OS > X > > from the ghc website. > > > > A simple parallel 'hello world' > > > http://haskell.org/haskellwiki/Haskell_in_5_steps#Write_your_first_parallel_Haskell_program > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090819/bc5c8b58/attachment.html From ccshan at post.harvard.edu Wed Aug 19 23:38:19 2009 From: ccshan at post.harvard.edu (Chung-chieh Shan) Date: Wed Aug 19 23:40:34 2009 Subject: [Haskell-cafe] Re: Unifcation and matching in Abelian groups References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> Message-ID: John D. Ramsdell wrote in article <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> in gmane.comp.lang.haskell.cafe: > I've been studying equational unification. I decided to test my > understanding of it by implementing unification and matching in > Abelian groups. I am quite surprised by how little code it takes. > Let me share it with you. Thanks! Another small change that might shorten the code is to use Data.Map for linear combinations: type Lin = Data.Map.Map String Int -- Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig Shaik Riaz From gour at gour-nitai.com Thu Aug 20 01:25:44 2009 From: gour at gour-nitai.com (Gour) Date: Thu Aug 20 01:02:56 2009 Subject: [Haskell-cafe] Re: Planning for a website References: <87prasys1a.fsf@gaura-nitai.no-ip.org> Message-ID: <87ljlfdpk7.fsf@gaura-nitai.no-ip.org> >>>>> "Colin" == Colin Paul Adams writes: Colin> I'd much rather be using happstack's macid stuff, especially as I Colin> will have only very low usage, so i shouldn't have any Colin> scalability problems. Well, I do not have enough money to pay for Happs resources... Right, Turbinado is not perfect - lack of docs is one area and it is not clear if it's still developed. Otoh, although I'll use Haskell for my desktop app, atm, I'm learning Django to do the job... Sincerely, Gour -- Gour | Hlapi?ina, Croatia | GPG key: F96FF5F6 --------------------------------------------------------------------------- -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/f1289d93/attachment.bin From colin at colina.demon.co.uk Thu Aug 20 02:13:28 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Thu Aug 20 01:54:09 2009 Subject: [Haskell-cafe] gbp sign showing as unknown character by GHC In-Reply-To: <6d74b0d20908191553q6c8586f2y302f3e7c3055c9aa@mail.gmail.com> (Judah Jacobson's message of "Wed\, 19 Aug 2009 15\:53\:03 -0700") References: <6d74b0d20908191553q6c8586f2y302f3e7c3055c9aa@mail.gmail.com> Message-ID: >>>>> "Judah" == Judah Jacobson writes: Judah> On Wed, Aug 19, 2009 at 10:31 AM, Iain Barnett wrote: >> Quick question:?I've tested this in a couple of different >> terminals (roxterm and xterm), so I'm fairly sure it's GHC >> that's the problem. Have I missed a setting? GHCi, version >> 6.10.4 Prelude> putStrLn "?" >> ? Hugs98?200609-3 Hugs> putStrLn "?" >> ? >> ghc-6.10.4 and earlier don't automatically encode/decode Unicode Judah> characters. So on terminals which don't use the latin-1 Judah> encoding, you need to do the conversion explicitly with a Judah> separate package such as utf8-string, iconv or text-icu. I don't understand where latin-1 comes into this. String is supposed to be a list of Unicode characters. -- Colin Adams Preston Lancashire From bulat.ziganshin at gmail.com Thu Aug 20 02:23:25 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Aug 20 02:03:32 2009 Subject: [Haskell-cafe] gbp sign showing as unknown character by GHC In-Reply-To: References: <6d74b0d20908191553q6c8586f2y302f3e7c3055c9aa@mail.gmail.com> Message-ID: <1826825386.20090820102325@gmail.com> Hello Colin, Thursday, August 20, 2009, 10:13:28 AM, you wrote: > I don't understand where latin-1 comes into this. String is supposed > to be a list of Unicode characters. but ghc 6.10 i/o used String as list of bytes -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From colin at colina.demon.co.uk Thu Aug 20 02:28:31 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Thu Aug 20 02:08:39 2009 Subject: [Haskell-cafe] gbp sign showing as unknown character by GHC In-Reply-To: <1826825386.20090820102325@gmail.com> (Bulat Ziganshin's message of "Thu\, 20 Aug 2009 10\:23\:25 +0400") References: <6d74b0d20908191553q6c8586f2y302f3e7c3055c9aa@mail.gmail.com> <1826825386.20090820102325@gmail.com> Message-ID: >>>>> "Bulat" == Bulat Ziganshin writes: Bulat> Hello Colin, Bulat> Thursday, August 20, 2009, 10:13:28 AM, you wrote: > I don't understand where latin-1 comes into this. String is supposed >> to be a list of Unicode characters. Bulat> but ghc 6.10 i/o used String as list of bytes But how do you get Latin-1 bytes from a Unicode string? This would need a transcoding process. -- Colin Adams Preston Lancashire From ck_kashyap at yahoo.com Thu Aug 20 02:32:18 2009 From: ck_kashyap at yahoo.com (CK Kashyap) Date: Thu Aug 20 02:12:20 2009 Subject: [Haskell-cafe] Right way to implement setPixel function Message-ID: <365149.71856.qm@web112518.mail.gq1.yahoo.com> Hi, I had posted a note on line drawing algo with Haskell some time back. Now, I am trying to write a PNM image. import qualified Data.ByteString as B width = 256 height = 256 bytesInImage = width * height * 3 blankImage = B.pack $ take bytesInImage (repeat 0) type Color = (Int,Int,Int) setPixel :: B.ByteString -> Int -> Int -> Color -> B.ByteString setPixel image x y (r,g,b) = B.concat [beforePixel, pixel, afterPixel] where beforePixel = B.take before image afterPixel = B.drop (before+3) image pixel=B.pack [(fromIntegral r),(fromIntegral g),(fromIntegral b)] -- number of bytes before the 3 bytes of -- the pixel at x y before = (y * width * 3) + (x * 3) - 3 main = do putStrLn "P6" putStrLn ( (show width) ++ " " ++ (show height) ) putStrLn "255" -- Set a red pixel at 100 100 B.putStr (setPixel blankImage 100 100 (255,0,0)) Can I please have some review comments on the code above? Would recreating the entire ByteString for each setPixel be an overhead? Also, I am barely beginning to grasp the Monad concept....I was wondering if there could be a monadic style of implementation of this - that could potentially have a series of setPixels inside a do block? Regards, Kashyap -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/62977532/attachment.html From scook0 at gmail.com Thu Aug 20 02:50:12 2009 From: scook0 at gmail.com (Stuart Cook) Date: Thu Aug 20 02:30:13 2009 Subject: [Haskell-cafe] gbp sign showing as unknown character by GHC In-Reply-To: References: <6d74b0d20908191553q6c8586f2y302f3e7c3055c9aa@mail.gmail.com> <1826825386.20090820102325@gmail.com> Message-ID: <49b351060908192350o337ec2e9h3d46b521697a409b@mail.gmail.com> On Thu, Aug 20, 2009 at 4:28 PM, Colin Paul Adams wrote: > But how do you get Latin-1 bytes from a Unicode string? This would > need a transcoding process. The first 256 code-points of Unicode coincide with Latin-1. Therefore, if you truncate Unicode characters down to 8 bits you'll effectively end up with Latin-1 text (except that any code points above U+00FF will give strange results). If your terminal then interprets these bytes as UTF-8 (or anything else, really), the result will be gibberish or worse. Stuart From colin at colina.demon.co.uk Thu Aug 20 03:12:53 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Thu Aug 20 02:53:17 2009 Subject: [Haskell-cafe] gbp sign showing as unknown character by GHC In-Reply-To: <49b351060908192350o337ec2e9h3d46b521697a409b@mail.gmail.com> (Stuart Cook's message of "Thu\, 20 Aug 2009 16\:50\:12 +1000") References: <6d74b0d20908191553q6c8586f2y302f3e7c3055c9aa@mail.gmail.com> <1826825386.20090820102325@gmail.com> <49b351060908192350o337ec2e9h3d46b521697a409b@mail.gmail.com> Message-ID: >>>>> "Stuart" == Stuart Cook writes: Stuart> On Thu, Aug 20, 2009 at 4:28 PM, Colin Paul Stuart> Adams wrote: >> But how do you get Latin-1 bytes from a Unicode string? This >> would need a transcoding process. Stuart> The first 256 code-points of Unicode coincide with Stuart> Latin-1. Therefore, if you truncate Unicode characters Stuart> down to 8 bits you'll effectively end up with Latin-1 text Stuart> (except that any code points above U+00FF will give Stuart> strange results). Stuart> If your terminal then interprets these bytes as UTF-8 (or Stuart> anything else, really), the result will be gibberish or Stuart> worse. Yes, but surely this will work both ways. The same bytes on input should come back on output, shouldn't they? -- Colin Adams Preston Lancashire From bulat.ziganshin at gmail.com Thu Aug 20 03:15:26 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Aug 20 02:55:35 2009 Subject: [Haskell-cafe] gbp sign showing as unknown character by GHC In-Reply-To: References: <6d74b0d20908191553q6c8586f2y302f3e7c3055c9aa@mail.gmail.com> <1826825386.20090820102325@gmail.com> <49b351060908192350o337ec2e9h3d46b521697a409b@mail.gmail.com> Message-ID: <1216736056.20090820111526@gmail.com> Hello Colin, Thursday, August 20, 2009, 11:12:53 AM, you wrote: > Yes, but surely this will work both ways. The same bytes on input > should come back on output, shouldn't they? only ascii subset that have fixed encoding. the rest may migrate in some way -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From scook0 at gmail.com Thu Aug 20 03:32:01 2009 From: scook0 at gmail.com (Stuart Cook) Date: Thu Aug 20 03:12:02 2009 Subject: [Haskell-cafe] gbp sign showing as unknown character by GHC In-Reply-To: References: <6d74b0d20908191553q6c8586f2y302f3e7c3055c9aa@mail.gmail.com> <1826825386.20090820102325@gmail.com> <49b351060908192350o337ec2e9h3d46b521697a409b@mail.gmail.com> Message-ID: <49b351060908200032m4a828b43i9f76ff7e79339886@mail.gmail.com> On Thu, Aug 20, 2009 at 5:12 PM, Colin Paul Adams wrote: > Yes, but surely this will work both ways. The same bytes on input > should come back on output, shouldn't they? I would have thought so, but apparently this isn't actually what happens. GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help Loading package base ... linking ... done. Prelude> map Data.Char.ord "?" [39233] <== 0x9941 Prelude> putStrLn "?" A <== 0x41 It seems that GHCi is clever enough to decode UTF-8 input, which only serves to confuse System.IO even more. Stuart From ryani.spam at gmail.com Thu Aug 20 04:18:15 2009 From: ryani.spam at gmail.com (Ryan Ingram) Date: Thu Aug 20 03:58:16 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <2f9b2d30908191023s2c11aa72m47fa8729868f6f23@mail.gmail.com> <3e1162e60908191031t63795c4apfbd47820647016ab@mail.gmail.com> <3e1162e60908191037m5c79d589ia78db27dd1449ae8@mail.gmail.com> <2f9b2d30908191228m5b38ddf0ib56052a60ef817ba@mail.gmail.com> <3e1162e60908191246g756c16d0ide067fba48b97c68@mail.gmail.com> <3e1162e60908191306p266b438fwcf814b43190295da@mail.gmail.com> Message-ID: <2f9b2d30908200118i4d339bdevb2bcc2ca02e5337d@mail.gmail.com> On Wed, Aug 19, 2009 at 1:20 PM, Peter Verswyvelen wrote: > Well I really wrote this code as an exercise, and it was a good one. Now I > (or someone) needs to explain why it works. There's a bit of trickiness, but it's not that hard when you break it down. Lets look at a simplified version of "test": test = do x <- inp out "hello" out x test Desugaring a bit: test = inp >>= \x -> out hello >> out x >> test = S (\(i:is) -> (is, empty, i)) >>= \x -> S (\is -> (is, singleton "hello", ())) >>= \_ -> S (\is -> (is, singleton x, ())) >>= \_ -> test Now, inlining >>= and simplifying, we get: test = S (\i0 -> let (i1, o1, x) = (\(i:is) -> (is, empty, i)) i0 (i2, o2, _) = (i1, singleton "hello", ()) (i3, o3, _) = (i2, singleton x, ()) (i4, o4, res) = step test i3 outputs = o1 `mappend` o2 `mappend` o3 `mappend` o4 in (i4, outputs, res)) The first thing to notice is that when we run "test" by giving it some input, we *immediately* get a triple back: (i4, outputs, res) with the values in the triple being unevaluated thunks. "res" is _|_; trying to evaluate it will infinite loop. Similarily for i4. But fortunately we never do; getOutput throws them both away. So the only thing we care about is "outputs". outputs is infinite as well, but we have hope! As long as `mappend` is lazy in its second argument, we might be able to get some data out! Lets simplify Data.DList a bit: mappend = (.) singleton = (:) empty = id fromList = (++) toList = ($ []) Now lets try to evaluate (toList outputs): toList outputs = ($ []) (o1 . o2 . o3 . o4) = o1 . o2 . o3 . o4 $ [] = o1 (o2 (o3 (o4 []))) We need to evaluate o1 in order to call it. There is a possibility that it is _|_ : (i1, o1, x) = (\(i:is) -> (is, empty, i)) i0 Therefore o1 = case i0 of (i:is) -> empty [] -> error "pattern match failure" i1 = case i0 of (i:is) -> is [] -> error "pattern match failure" x = case i0 of (i:is) -> i [] -> error "pattern match failure" So as long as you type a line, "o1" will be "empty" (= id). But we don't know that you necessarily will type an input line, so the code *has* to wait for the line of input from the user, and can't print any later values. (This is where you get into some of the craziness of lazy I/O) Once you type a line, i0 gets bound to (whatever you type : some lazy thunk representing the rest of the input) and o1 gets evaluated to id. toList outputs = o1 (o2 (o3 (o4 []))) = id (o2 (o3 (o4 []))) = o2 (o3 (o4 [])) o2 and o3 are easy: (i2, o2, _) = (i1, singleton "hello", ()) (i3, o3, _) = (i2, singleton x, ()) therefore o2 = ("hello" :) o3 = (x :) toList outputs = o2 (o3 (o4 [])) = ("hello":) ( (x:) (o4 []) ) = "hello" : x : (o4 []) Now we have some data! We can output these two elements without evaluating o4 at all! So we do, and then we need to evaluate o4. But that just is starting over; o4 = getOutputs (step test i3). We do have a different input (i3 vs. i0), but the rest of the logic is the same, and we keep going until we get to the end of the input list, at which point the pattern match failure in "inp" hits us. > But is this monad really useful? I mean it would be straightforward to write > this using the ST monad I guess? It's kind of useful. I don't think I'd use ST, though. It's isomorphic to StateT [String] (Writer (DList String)) > Anyway, the reason why I want this pure code is that even with a console > based game, I don't want IO in it, since recording the input and replaying > it is vital to reproduce the actions the user did, and if things go wrong > (they always do), the log of all input can be used to restore the exact game > play. Of course you can do the same using imperative techniques and IO > redirection (which I did for my old games), but with this pure code you > don't have to worry about other places where IO could be used. For logging/testing/whatever, I suggest building your monad based off of MonadPrompt; it guarantees that all impure actions go through a datatype which you can then log. Check it out! http://hackage.haskell.org/package/MonadPrompt You can then change the implementation of "what does this impure action do" without changing any of the logging or gameplay code. For example, you could have a "object agent monad" which each character runs under, that is able to observe parts of the gamestate, and then write an interpreter that allows the user to play the game (through an impure I/O interface that draws to the screen) and another interpreter which runs an AI (through a pure functional or memory-state-based interface). -- ryan From bugfact at gmail.com Thu Aug 20 04:52:53 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Thu Aug 20 04:32:56 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <2f9b2d30908200118i4d339bdevb2bcc2ca02e5337d@mail.gmail.com> References: <3e1162e60908191031t63795c4apfbd47820647016ab@mail.gmail.com> <3e1162e60908191037m5c79d589ia78db27dd1449ae8@mail.gmail.com> <2f9b2d30908191228m5b38ddf0ib56052a60ef817ba@mail.gmail.com> <3e1162e60908191246g756c16d0ide067fba48b97c68@mail.gmail.com> <3e1162e60908191306p266b438fwcf814b43190295da@mail.gmail.com> <2f9b2d30908200118i4d339bdevb2bcc2ca02e5337d@mail.gmail.com> Message-ID: This is very very informative, thanks. One thing I still struggle with (because I haven't practiced much I guess) is writing down the desugaring/evaluation/expansion/reduction (how do you call it?). I know how to do it more or less (tried it for a fix fac, since fix feels like magic for an imperative programmer). This is unfortunate, because the claim that "Haskell is easier to reason with" together with "controlling space/time" only works I guess if you (1) developed an intuition about how the evaluation exactly works and/or (2) are trained in this algebraic rewriting (which I was 20 years ago ;-) If I do the rewriting, I often get it wrong (too lazy, too strict) and this it is rather useless. And many of the examples I've seem seem to skim many "obvious" rewriting steps that don't feel that obvious to me. But you gave a good exercise here :-) This is typical for when I see Haskell code from experts: how do they make it so compact? Often the code is unreadable then, but in the case of your cleanup, I had to feeling "why didn't write it like that in the first place? It seems so obvious" ;-) This also has an intimidating effect sometimes, since as a newbie (and it feels that I'm still a newbie after a year) it's hard to show code without looking like a fool. Luckily Haskell people are very friendly and helpful! On Thu, Aug 20, 2009 at 10:18 AM, Ryan Ingram wrote: > On Wed, Aug 19, 2009 at 1:20 PM, Peter Verswyvelen > wrote: > > Well I really wrote this code as an exercise, and it was a good one. Now > I > > (or someone) needs to explain why it works. > > There's a bit of trickiness, but it's not that hard when you break it down. > > Lets look at a simplified version of "test": > > test = do > x <- inp > out "hello" > out x > test > > Desugaring a bit: > > test > = inp >>= \x -> out hello >> out x >> test > = S (\(i:is) -> (is, empty, i)) > >>= \x -> S (\is -> (is, singleton "hello", ())) > >>= \_ -> S (\is -> (is, singleton x, ())) > >>= \_ -> test > > Now, inlining >>= and simplifying, we get: > > test = S (\i0 -> let > (i1, o1, x) = (\(i:is) -> (is, empty, i)) i0 > (i2, o2, _) = (i1, singleton "hello", ()) > (i3, o3, _) = (i2, singleton x, ()) > (i4, o4, res) = step test i3 > outputs = o1 `mappend` o2 `mappend` o3 `mappend` o4 > in (i4, outputs, res)) > > The first thing to notice is that when we run "test" by giving it some > input, we *immediately* get a triple back: > (i4, outputs, res) > with the values in the triple being unevaluated thunks. > > "res" is _|_; trying to evaluate it will infinite loop. Similarily > for i4. But fortunately we never do; getOutput throws them both away. > So the only thing we care about is "outputs". > > outputs is infinite as well, but we have hope! As long as `mappend` > is lazy in its second argument, we might be able to get some data out! > > Lets simplify Data.DList a bit: > > mappend = (.) > singleton = (:) > empty = id > fromList = (++) > toList = ($ []) > > Now lets try to evaluate (toList outputs): > > toList outputs > = ($ []) (o1 . o2 . o3 . o4) > = o1 . o2 . o3 . o4 $ [] > = o1 (o2 (o3 (o4 []))) > > We need to evaluate o1 in order to call it. There is a possibility > that it is _|_ : > (i1, o1, x) = (\(i:is) -> (is, empty, i)) i0 > > Therefore > o1 = case i0 of > (i:is) -> empty > [] -> error "pattern match failure" > i1 = case i0 of > (i:is) -> is > [] -> error "pattern match failure" > x = case i0 of > (i:is) -> i > [] -> error "pattern match failure" > > So as long as you type a line, "o1" will be "empty" (= id). But we > don't know that you necessarily will type an input line, so the code > *has* to wait for the line of input from the user, and can't print any > later values. (This is where you get into some of the craziness of > lazy I/O) > > Once you type a line, i0 gets bound to (whatever you type : some lazy > thunk representing the rest of the input) and o1 gets evaluated to id. > > toList outputs > = o1 (o2 (o3 (o4 []))) > = id (o2 (o3 (o4 []))) > = o2 (o3 (o4 [])) > > o2 and o3 are easy: > (i2, o2, _) = (i1, singleton "hello", ()) > (i3, o3, _) = (i2, singleton x, ()) > therefore > o2 = ("hello" :) > o3 = (x :) > > toList outputs > = o2 (o3 (o4 [])) > = ("hello":) ( (x:) (o4 []) ) > = "hello" : x : (o4 []) > > Now we have some data! We can output these two elements without > evaluating o4 at all! > > So we do, and then we need to evaluate o4. But that just is starting > over; o4 = getOutputs (step test i3). We do have a different input > (i3 vs. i0), but the rest of the logic is the same, and we keep going > until we get to the end of the input list, at which point the pattern > match failure in "inp" hits us. > > > But is this monad really useful? I mean it would be straightforward to > write > > this using the ST monad I guess? > > It's kind of useful. I don't think I'd use ST, though. It's isomorphic to > StateT [String] (Writer (DList String)) > > > Anyway, the reason why I want this pure code is that even with a console > > based game, I don't want IO in it, since recording the input and > replaying > > it is vital to reproduce the actions the user did, and if things go wrong > > (they always do), the log of all input can be used to restore the exact > game > > play. Of course you can do the same using imperative techniques and IO > > redirection (which I did for my old games), but with this pure code you > > don't have to worry about other places where IO could be used. > > For logging/testing/whatever, I suggest building your monad based off > of MonadPrompt; it guarantees that all impure actions go through a > datatype which you can then log. Check it out! > http://hackage.haskell.org/package/MonadPrompt > > You can then change the implementation of "what does this impure > action do" without changing any of the logging or gameplay code. For > example, you could have a "object agent monad" which each character > runs under, that is able to observe parts of the gamestate, and then > write an interpreter that allows the user to play the game (through an > impure I/O interface that draws to the screen) and another interpreter > which runs an AI (through a pure functional or memory-state-based > interface). > > -- ryan > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/84c451a9/attachment.html From ketil at malde.org Thu Aug 20 05:07:46 2009 From: ketil at malde.org (Ketil Malde) Date: Thu Aug 20 04:47:38 2009 Subject: [Haskell-cafe] gbp sign showing as unknown character by GHC In-Reply-To: <49b351060908200032m4a828b43i9f76ff7e79339886@mail.gmail.com> (Stuart Cook's message of "Thu\, 20 Aug 2009 17\:32\:01 +1000") References: <6d74b0d20908191553q6c8586f2y302f3e7c3055c9aa@mail.gmail.com> <1826825386.20090820102325@gmail.com> <49b351060908192350o337ec2e9h3d46b521697a409b@mail.gmail.com> <49b351060908200032m4a828b43i9f76ff7e79339886@mail.gmail.com> Message-ID: <877hwyam59.fsf@malde.org> Stuart Cook writes: > GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help > Loading package base ... linking ... done. > Prelude> map Data.Char.ord "?" > [39233] <== 0x9941 > Prelude> putStrLn "?" > A <== 0x41 > It seems that GHCi is clever enough to decode UTF-8 input, which only > serves to confuse System.IO even more. I get: GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help Loading package base ... linking ... done. Prelude> map Data.Char.ord "?" [39233] and Prelude> map Data.Char.ord "?" [163] but also: % ghci -e 'map Data.Char.ord "?"' :1:21: lexical error in string/character literal at character '\129' but again: % ghci -e 'map Data.Char.ord "?"' [194,163] So GHCi used interactively translates input from the terminal's UTF-8, but outputs truncates output to eight bits. Executing a string with -e, it appears to read byte for byte (which I think was the original behavior at some point). -k -- If I haven't seen further, it is by standing in the footprints of giants From explicitcall at googlemail.com Thu Aug 20 05:46:31 2009 From: explicitcall at googlemail.com (Max Desyatov) Date: Thu Aug 20 05:26:18 2009 Subject: [Haskell-cafe] Generics for constructing Rows Message-ID: <87r5v6izrc.fsf@zagan.made.you> Hi, all. I've come into trouble defining function `gmap` which will work on these data types: > data Row = Row > (E Name) > (E Salary) > (E Department) > type E a = Either (Maybe RowIndex) (Maybe a) > type RowIndex = Int `RowIndex`, `Name`, `Salary`, `Department` have kind * pseudocode: > gmap :: (E a -> E a) -> Row -> Row > readRow :: [String] -> Row -> Row > readRow l = gmap (\(Left (Just ri)) -> Right $ l `atMay` c >>= readMay) `atMay` and `readMay` are defined in module `Safe` from package `safe` > atMay :: [a] -> Int -> Maybe a > readMay :: (Read a) => String -> Maybe a Basically we have optional Row indices and try to read raw row (list of Strings) into the same Row type if index is present. At this moment I just have separate data type for row which has been read and just a list of row indices, but it is definitely flawed when I need to add fields to Row from time to time, as it is too easy to introduce bugs while positioning in list of row indices, not mentioning all those boilerplate code flowing around. I've tried to define gmap using libraries for generic programming but failed each time while type checking for different reasons. With `Data.Generics` and `gmapT` it fails because gmapT doesn't allow traversion function to have `Read a` constraint (Data and Typeable instances for Row and inner data types of course were derived). EMGM's map demands traversion function to be non-polymorphic, i.e. type-checker fails with the message, complaining it cannot match `E a` against `E Name`, against `E Salary` etc. For each of this I've spent smth about five hours just reading API docs, papers, and trying to beat type-checker. Maybe I'll look into Smash, RepLib and others, but I hope someone was also trying to define such gmap and succeeded. So, generic programming folks, is it even possible to define such function? I don't really care about using GHC extensions, I don't care about code being portable, I just want to remove boilerplate and prevent introducing bugs. Thanks in advance, Max. From jules at jellybean.co.uk Thu Aug 20 05:52:03 2009 From: jules at jellybean.co.uk (Jules Bean) Date: Thu Aug 20 05:32:04 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908190800j3888c2d9jf9f6f8342ba165ec@mail.gmail.com> <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> Message-ID: <4A8D1CC3.8080507@jellybean.co.uk> Peter Verswyvelen wrote: > Not at all, use it for whatever you want to :-) > > I'm writing this code because I'm preparing to write a bunch of > tutorials on FRP, and I first wanted to start with simple console based > FRP, e.g. making a little text adventure game, where the input/choices > of the user might be parsed ala parsec, using monadic style, applicative > style, and arrows, and then doing the same with FRP frameworks like This is a really bad place to start a FRP tutorial IMO. The interface for 'interact' does not make any promises about the relative evaluation order of the input list / production order of the output list. That's why you are having to play horrible tricks with seq to try to force the order to be what you want. I don't think this is the basis of a robust system or a sensible tutorial. Just my 2c. From explicitcall at googlemail.com Thu Aug 20 05:55:08 2009 From: explicitcall at googlemail.com (Max Desyatov) Date: Thu Aug 20 05:34:54 2009 Subject: [Haskell-cafe] Generics for constructing Rows Message-ID: <87my5uizcz.fsf@zagan.made.you> Sorry for a type and probably confusing you, it must be: > readRow l = gmap (\(Left (Just ri)) -> Right $ l `atMay` ri >>= readMay) instead of > l `atMay` c From apfelmus at quantentunnel.de Thu Aug 20 05:57:44 2009 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Thu Aug 20 05:40:06 2009 Subject: [Haskell-cafe] Re: Keeping an indexed collection of values? In-Reply-To: References: Message-ID: Job Vranish wrote: > I've been in a situation a lot lately where I need to keep a collection of > values, and keep track of them by a persistent index. > > data IndexedCollection a = IndexedCollection { > nextKey :: Int, > availableKeys :: [Int], > items :: IntMap a > } deriving (Show) > > emptyIndexedCollection :: IndexedCollection a > emptyIndexedCollection = IndexedCollection 0 [] empty > > addItem :: a -> IndexedCollection a -> (Int, IndexedCollection a) > addItem a (IndexedCollection nextKey' [] t) = (nextKey', > IndexedCollection (nextKey' + 1) [] (insert nextKey' a t)) > addItem a (IndexedCollection nextKey' (k:ks) t) = (k, IndexedCollection > nextKey' ks (insert k a t)) > > removeItem :: Int -> IndexedCollection a -> IndexedCollection a > removeItem k (IndexedCollection nextKey' ks t) = IndexedCollection nextKey' > (k:ks) (delete k t) > > lookupItem :: Int -> IndexedCollection a -> Maybe a > lookupItem k (IndexedCollection _ _ t) = lookup k t > > [...] > > Does anyone know of a better/already existent data structure for handling > this problem? > > Or perhaps a better way of keeping a "key pool" than my availableKeys > solution? I'd put it in a new module and use standard names, i.e. empty add -- instead of insert delete lookup Oh, and the name IndexedCollection is kinda long. ;) You may want to make the nextKey field strict, so that forcing the whole collection forces the available keys as well data IndexedCollection = IndexedCollection { nextKey :: !Int, ... Otherwise, a chain of (+ 1) may linger unintentionally. If you follow Sebastian's great suggestion, you'd need to do something like this: empty = IndexedCollection (nats 0) IntMap.empty where nats !n = n : nats (n+1) Is it important that the keys are integers? If not, then I suggest making it abstract, i.e. like this module Store (Key, Store, empty, add, delete, lookup) where import qualified Data.IntMap as Map newtype Key = Key { int :: Int } instance Show Key where show = show . int data Store a = Store [Key] (Map.IntMap a) empty :: Store a empty = Store (nats 0) Map.empty where nats !n = Key n : nats (n+1) add :: a -> Store a -> (Key, Store a) add a (Store (k:ks) m) = (k, Store ks $ Map.insert (int k) a m) delete :: Key -> Store a -> Store a delete k (Store ks m) = Store (k:ks) $ Map.delete (int k) m lookup :: Key -> Store a -> Maybe a lookup k (Store _ m) = Map.lookup (int k) m This way, the user doesn't know and care how Key is implemented. Last but not least, there is the issue that trying to use an already deleted key might yield a wrong result instead of an error. That shouldn't happen if used correctly, but might give a headache when debugging. Regards, apfelmus -- http://apfelmus.nfshost.com From bugfact at gmail.com Thu Aug 20 07:03:42 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Thu Aug 20 06:43:44 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <4A8D1CC3.8080507@jellybean.co.uk> References: <3e1162e60908190800j3888c2d9jf9f6f8342ba165ec@mail.gmail.com> <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <4A8D1CC3.8080507@jellybean.co.uk> Message-ID: I don't fully understand. interact gives you a stream of input characters that the user types, and produces a stream of output characters that are displayed back (with buffering set to NoBuffering). it should behave predictable no? and since the input that the user gives depends on the output on the screen (it represents the user <-> machine dialog loop), we must make sure that laziness does not go wild and strictness is needed to respect this dependency. But as Ryan showed, seq is not really needed (but pattern matching is), and his code is super elegant and simple. I also remember from the Haskell School of Expression that putting lazy pattern matches (in switch if I recall correctly) here and there is needed to avoid blocking or inf loops. Also in Reactive this was important. In Yampa you need to mark the outputs strict to avoid delayed computations from building up (like sum and foldl does). So it seems finding a good balance between strictness and laziness is really important in FRP, at least for the engine, and in the case of Yampa, also for the end user. E.g in Ryans cleanup, if you replace inp by inp :: S String inp = S $ \i -> (tail i, D.empty, head i) then the ordering of input to output is incorrect, too much output is printed before the input is requested. it clearly demonstrates the effect of laziness to me really, in a much easier to observe way than stack overflows or infinite loops no? how is interact different from a graphical user interface system or game simulation, in which the input is a stream of events (or behaviors, samples, whatever) from mouse, keyboard, timers, etc, and the output is a list of pictures or geometry? The tutorial I would like to make is exactly for this kind of feedback from domain experts, so maybe "tutorial" is not the correct word, more a discussion or journey. Anyway I don't think I'm qualified to make a tutorial since I'm still learning the basics, but with feedback from you guys (I already have interest from Hai (Paul) Liu (Yampa) and Patai Gergely (Elerea) it might still become a valuable resource? On Thu, Aug 20, 2009 at 11:52 AM, Jules Bean wrote: > Peter Verswyvelen wrote: > >> Not at all, use it for whatever you want to :-) >> >> I'm writing this code because I'm preparing to write a bunch of tutorials >> on FRP, and I first wanted to start with simple console based FRP, e.g. >> making a little text adventure game, where the input/choices of the user >> might be parsed ala parsec, using monadic style, applicative style, and >> arrows, and then doing the same with FRP frameworks like >> > > > This is a really bad place to start a FRP tutorial IMO. > > The interface for 'interact' does not make any promises about the relative > evaluation order of the input list / production order of the output list. > > That's why you are having to play horrible tricks with seq to try to force > the order to be what you want. > > I don't think this is the basis of a robust system or a sensible tutorial. > > Just my 2c. > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/0b1c437b/attachment.html From iainspeed at gmail.com Thu Aug 20 07:39:11 2009 From: iainspeed at gmail.com (Iain Barnett) Date: Thu Aug 20 07:19:13 2009 Subject: [Haskell-cafe] gbp sign showing as unknown character by GHC In-Reply-To: <877hwyam59.fsf@malde.org> References: <6d74b0d20908191553q6c8586f2y302f3e7c3055c9aa@mail.gmail.com> <1826825386.20090820102325@gmail.com> <49b351060908192350o337ec2e9h3d46b521697a409b@mail.gmail.com> <49b351060908200032m4a828b43i9f76ff7e79339886@mail.gmail.com> <877hwyam59.fsf@malde.org> Message-ID: 2009/8/20 Ketil Malde > > Stuart Cook writes: > > > GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help > > Loading package base ... linking ... done. > > Prelude> map Data.Char.ord "?" > > [39233] <== 0x9941 > > Prelude> putStrLn "?" > > A <== 0x41 > > > It seems that GHCi is clever enough to decode UTF-8 input, which only > > serves to confuse System.IO even more. > > I get: > > GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help > Loading package base ... linking ... done. > Prelude> map Data.Char.ord "?" > [39233] > > and > > Prelude> map Data.Char.ord "?" > [163] > > but also: > > % ghci -e 'map Data.Char.ord "?"' > :1:21: > lexical error in string/character literal at character '\129' > > but again: > > % ghci -e 'map Data.Char.ord "?"' > [194,163] > > So GHCi used interactively translates input from the terminal's UTF-8, > but outputs truncates output to eight bits. Executing a string with > -e, it appears to read byte for byte (which I think was the original > behavior at some point). > > -k > -- I get the same behaviour here. If you want to try Latin 1 (ISO-8859-1) then you can use a utility called Luit (maybe only Linux?) luit -encoding ISO-8859-1 ghci ? becomes ??, but gives the same byte output as above. Iain -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/c2fc7c10/attachment.html From leather at cs.uu.nl Thu Aug 20 07:43:38 2009 From: leather at cs.uu.nl (Sean Leather) Date: Thu Aug 20 07:23:59 2009 Subject: [Haskell-cafe] Generics for constructing Rows In-Reply-To: <87r5v6izrc.fsf@zagan.made.you> References: <87r5v6izrc.fsf@zagan.made.you> Message-ID: <3c6288ab0908200443w18110f45h8edc7353091100f2@mail.gmail.com> Hi Max, I've come into trouble defining function `gmap` which will work on these > data types: > > > data Row = Row > > (E Name) > > (E Salary) > > (E Department) > > > type E a = Either (Maybe RowIndex) (Maybe a) > > > type RowIndex = Int > > `RowIndex`, `Name`, `Salary`, `Department` have kind * > > pseudocode: > > > gmap :: (E a -> E a) -> Row -> Row > > [...] > So, generic programming folks, is it even possible to define such > function? I don't really care about using GHC extensions, I don't care > about code being portable, I just want to remove boilerplate and prevent > introducing bugs. > I'm not sure the problem you're running into is strictly a generic programming (GP) one. Typically, GP takes code that is often written and generalizes it, so that it doesn't have to be written for multiple datatypes. For your problem, I think the first issue is figuring out how to write the non-generic function. I don't know if this is exactly what you want, but you can write a version of gmap using GADTs and rank-2 types. I've simplified some types, but it should be easily transferable to your code. For example, change the String, Float, etc. to your Salary, Department, whatever. --- {-# LANGUAGE GADTs #-} {-# LANGUAGE Rank2Types #-} module Main where data T a where String :: T String Float :: T Float Integer :: T Integer data Row = Row (Maybe String) (Maybe Float) (Maybe Integer) deriving Show f :: T a -> Maybe a -> Maybe a f String (Just "a") = Just "z" f _ x = x gmap :: (forall a . T a -> Maybe a -> Maybe a) -> Row -> Row gmap f (Row x y z) = Row (f String x) (f Float y) (f Integer z) main = do print $ gmap f $ Row Nothing (Just 5.4) (Just 3) -- ==> Row Nothing (Just 5.4) (Just 3) print $ gmap f $ Row (Just "a") Nothing Nothing -- ==> Row (Just "z") Nothing Nothing --- If this is what you're looking for, then I think it might be possible to do this more generally, though I haven't looked into it. Regards, Sean -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/dee8db10/attachment.html From martijn at van.steenbergen.nl Thu Aug 20 07:44:15 2009 From: martijn at van.steenbergen.nl (Martijn van Steenbergen) Date: Thu Aug 20 07:24:22 2009 Subject: [Haskell-cafe] Parsec lookahead and <|> Message-ID: <4A8D370F.5000401@van.steenbergen.nl> Goedemiddag caf?, Consider the following function, using parsec-3.0.0: > la :: Parsec String () (Maybe Char) > la = lookAhead (optionMaybe anyChar) *Lookahead> parseTest (char 'a' <|> char 'b') "a" 'a' *Lookahead> parseTest (char 'a' <|> char 'b') "b" 'b' *Lookahead> parseTest (la *> char 'a' <|> char 'b') "a" 'a' *Lookahead> parseTest (la *> char 'a' <|> char 'b') "b" parse error at (line 1, column 2): unexpected "b" expecting "a" The first three work fine and as expected, but the fourth example fails where I would expect success. I know <|> won't try the rhs if the lhs consumed input, but lookAhead's documentation promises not to consume any input. Is this a bug in Parsec or am I missing something? Thanks, Martijn. From allbery at ece.cmu.edu Thu Aug 20 07:58:29 2009 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Thu Aug 20 07:38:34 2009 Subject: [Haskell-cafe] gbp sign showing as unknown character by GHC In-Reply-To: <877hwyam59.fsf@malde.org> References: <6d74b0d20908191553q6c8586f2y302f3e7c3055c9aa@mail.gmail.com> <1826825386.20090820102325@gmail.com> <49b351060908192350o337ec2e9h3d46b521697a409b@mail.gmail.com> <49b351060908200032m4a828b43i9f76ff7e79339886@mail.gmail.com> <877hwyam59.fsf@malde.org> Message-ID: On Aug 20, 2009, at 05:07 , Ketil Malde wrote: > % ghci -e 'map Data.Char.ord "?"' > :1:21: > lexical error in string/character literal at character '\129' > > but again: > > % ghci -e 'map Data.Char.ord "?"' > [194,163] > > So GHCi used interactively translates input from the terminal's UTF-8, > but outputs truncates output to eight bits. Executing a string with > -e, it appears to read byte for byte (which I think was the original > behavior at some point). Makes sense; absent utf8-string, System.Environment.getArgs only groks bytes. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 195 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/8864022a/PGP.bin From florbitous at gmail.com Thu Aug 20 08:11:45 2009 From: florbitous at gmail.com (Bernie Pope) Date: Thu Aug 20 07:51:48 2009 Subject: [Haskell-cafe] ANNOUNCE: ministg-0.2, an interpreter for STG operational semantics Message-ID: <4d8ad03a0908200511x36a198bay22216672016405c@mail.gmail.com> I'm pleased to announce the first public release of Ministg. Ministg is an interpreter for a high-level, small-step, operational semantics for the STG machine. The STG machine is the abstract machine at the core of GHC. The operational semantics used in Ministg is taken from the paper "Making a fast curry: push/enter vs. eval/apply for higher-order languages" by Simon Marlow and Simon Peyton Jones. Ministg implements both sets of evaluation rules from the paper. One of the main features of Ministg is the ability to record a trace of the execution steps as a sequence of html files. And example trace can be viewed here: ?http://www.cs.mu.oz.au/~bjpop/trace/step0.html The example shows the execution of a program which sums a list of three integers, using the well-known space-leaky version of sum. Follow the "next" and "previous" links to step forwards and backwards through the trace. The main reason I wrote Ministg is to explore various extensions to the STG machine. The current release features a simple extension in the form of call-stack tracing, which is strongly influenced by the cost-centre stacks of GHC. I expect it will also be a useful tool for people who are interested in learning more about the STG machine. More detailed information is available from the haskellwiki page: ?http://www.haskell.org/haskellwiki/Ministg You can download it from hackagedb: ?http://hackage.haskell.org/package/ministg Or you can get the latest code from patch-tag: ?darcs get http://patch-tag.com/r/ministg/pullrepo ministg Cheers, Bernie. From gue.schmidt at web.de Thu Aug 20 08:49:33 2009 From: gue.schmidt at web.de (=?iso-8859-15?Q?G=FCnther_Schmidt?=) Date: Thu Aug 20 08:29:57 2009 Subject: [Haskell-cafe] Tips for deployment? Message-ID: Hi all, my haskell app is getting closer to shipping and what I need to do now is to give product protection some thought. The product is for hospitals and therefore a very limited set of clients. I do not expect anyone to try to "hack" my application but I need a basic protection mechanism in place, if only to check for a valid license key. As I've never done this before I'd be grateful for some suggestions here. G?nther From ramsdell0 at gmail.com Thu Aug 20 08:57:00 2009 From: ramsdell0 at gmail.com (John D. Ramsdell) Date: Thu Aug 20 08:37:01 2009 Subject: [Haskell-cafe] Unifcation and matching in Abelian groups In-Reply-To: <4A8BF0D3.7050403@jellybean.co.uk> References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> <404396ef0908190316rc772614p9c660c8ab5095ed6@mail.gmail.com> <7687290b0908190345q23313f4bwf24b6868499ee704@mail.gmail.com> <4A8BF0D3.7050403@jellybean.co.uk> Message-ID: <7687290b0908200557i522f3d92jb4d20707baeb3694@mail.gmail.com> On Wed, Aug 19, 2009 at 8:32 AM, Jules Bean wrote: > > Do not blame haskell, blame emacs, if emacs is so stupid. How can you blame emacs? Do you expect emacs to read programmer's minds? John From jules at jellybean.co.uk Thu Aug 20 09:08:41 2009 From: jules at jellybean.co.uk (Jules Bean) Date: Thu Aug 20 08:48:42 2009 Subject: [Haskell-cafe] Unifcation and matching in Abelian groups In-Reply-To: <7687290b0908200557i522f3d92jb4d20707baeb3694@mail.gmail.com> References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> <404396ef0908190316rc772614p9c660c8ab5095ed6@mail.gmail.com> <7687290b0908190345q23313f4bwf24b6868499ee704@mail.gmail.com> <4A8BF0D3.7050403@jellybean.co.uk> <7687290b0908200557i522f3d92jb4d20707baeb3694@mail.gmail.com> Message-ID: <4A8D4AD9.1050701@jellybean.co.uk> John D. Ramsdell wrote: > On Wed, Aug 19, 2009 at 8:32 AM, Jules Bean wrote: >> Do not blame haskell, blame emacs, if emacs is so stupid. > > How can you blame emacs? Do you expect emacs to read programmer's minds? > No, I expect emacs to select a suitable first indentation guess and give the programmer a natural way to choose alternative ones. I don't think the initial haskell-mode implementation had that property. I don't find layout a problem, with good editor support. I agree it's a problem, with poor editor support. That's all I meant. From ramsdell0 at gmail.com Thu Aug 20 09:11:31 2009 From: ramsdell0 at gmail.com (John D. Ramsdell) Date: Thu Aug 20 08:51:33 2009 Subject: [Haskell-cafe] Re: Unifcation and matching in Abelian groups In-Reply-To: References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> Message-ID: <7687290b0908200611m5b3fc806qcba09d52873981f8@mail.gmail.com> On Wed, Aug 19, 2009 at 11:38 PM, Chung-chieh Shan wrote: > Thanks! ?Another small change that might shorten the code is to use > Data.Map for linear combinations: I chose to use association lists because I did not want to explain the adjust function one would use to implement the add function. I thought it would make the code cryptic for beginners. Your suggestion does raise an interesting question. When is it faster to to use associations list instead of Data.Map. For some applications of the matcher, the number of variables is usually, but not always small, like less than three, so association lists may actually be faster. I never know the number of keys it takes to make the overhead of Data.Map worthwhile. I also never know the number elements it takes to make the overhead of an array worthwhile over a list in applications that do a lot of indexing. John From ramsdell0 at gmail.com Thu Aug 20 09:37:12 2009 From: ramsdell0 at gmail.com (John D. Ramsdell) Date: Thu Aug 20 09:17:45 2009 Subject: [Haskell-cafe] Unifcation and matching in Abelian groups In-Reply-To: <4A8D4AD9.1050701@jellybean.co.uk> References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> <404396ef0908190316rc772614p9c660c8ab5095ed6@mail.gmail.com> <7687290b0908190345q23313f4bwf24b6868499ee704@mail.gmail.com> <4A8BF0D3.7050403@jellybean.co.uk> <7687290b0908200557i522f3d92jb4d20707baeb3694@mail.gmail.com> <4A8D4AD9.1050701@jellybean.co.uk> Message-ID: <7687290b0908200637u5022c4e6lf76b759a82222f1f@mail.gmail.com> On Thu, Aug 20, 2009 at 9:08 AM, Jules Bean wrote: > I don't find layout a problem, with good editor support. I agree it's a > problem, with poor editor support. That's all I meant. Let's put this issue in perspective. For those few Haskell programmers that do find layout irritating, I'm sure we would all agree it's but a minor irritation. The real downside of layout is if non-Haskell programmers use it as an excuse to dismiss the language. I happen to think that Data Parallel Haskell has great potential for use in high performance computations. I'd hate to see a bunch of Fortraners not try DPH because of Haskell syntax. In terms of irritating programmers, I think Wirth takes the cake. After advancing the art with Pascal, he correctly saw its lack of modules as a problem, and he solved the issue with the Modular-2 programming language. He made the improvement, but also required programmers to type keywords in all caps! I tried Modular-2 and quickly tired of using the caps lock key. Maude has this problem too. Very irritating. John From ramsdell0 at gmail.com Thu Aug 20 09:38:05 2009 From: ramsdell0 at gmail.com (John D. Ramsdell) Date: Thu Aug 20 09:18:10 2009 Subject: [Haskell-cafe] Unifcation and matching in Abelian groups In-Reply-To: <4A8D4AD9.1050701@jellybean.co.uk> References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> <404396ef0908190316rc772614p9c660c8ab5095ed6@mail.gmail.com> <7687290b0908190345q23313f4bwf24b6868499ee704@mail.gmail.com> <4A8BF0D3.7050403@jellybean.co.uk> <7687290b0908200557i522f3d92jb4d20707baeb3694@mail.gmail.com> <4A8D4AD9.1050701@jellybean.co.uk> Message-ID: <7687290b0908200638q4ea8e13alb2649f09f3a4e524@mail.gmail.com> On Thu, Aug 20, 2009 at 9:08 AM, Jules Bean wrote: > I don't find layout a problem, with good editor support. I agree it's a > problem, with poor editor support. That's all I meant. Let's put this issue in perspective. For those few Haskell programmers that do find layout irritating, I'm sure we would all agree it's but a minor irritation. The real downside of layout is if non-Haskell programmers use it as an excuse to dismiss the language. I happen to think that Data Parallel Haskell has great potential for use in high performance computations. I'd hate to see a bunch of Fortraners not try DPH because of Haskell syntax. In terms of irritating programmers, I think Wirth takes the cake. After advancing the art with Pascal, he correctly saw its lack of modules as a problem, and he solved the issue with the Modular-2 programming language. He made the improvement, but also required programmers to type keywords in all caps! I tried Modular-2 and quickly tired of using the caps lock key. Maude has this problem too. Very irritating. John From bugfact at gmail.com Thu Aug 20 09:42:50 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Thu Aug 20 09:22:51 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908191037m5c79d589ia78db27dd1449ae8@mail.gmail.com> <2f9b2d30908191228m5b38ddf0ib56052a60ef817ba@mail.gmail.com> <3e1162e60908191246g756c16d0ide067fba48b97c68@mail.gmail.com> <3e1162e60908191306p266b438fwcf814b43190295da@mail.gmail.com> <2f9b2d30908200118i4d339bdevb2bcc2ca02e5337d@mail.gmail.com> Message-ID: It seems that with Ryan's approach, DList is not needed, simple concat works fine. It also seems to run in constant space. Now I must do the exercise of rewriting it to see why concat works, since >>= is infixl and ++ is infixr, this seems odd :) But again, my mind might be thinking too strict (bad imperative habits?) http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8357 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/afa1755b/attachment.html From iainspeed at gmail.com Thu Aug 20 09:46:55 2009 From: iainspeed at gmail.com (Iain Barnett) Date: Thu Aug 20 09:26:56 2009 Subject: [Haskell-cafe] gbp sign showing as unknown character by GHC In-Reply-To: References: <6d74b0d20908191553q6c8586f2y302f3e7c3055c9aa@mail.gmail.com> <1826825386.20090820102325@gmail.com> <49b351060908192350o337ec2e9h3d46b521697a409b@mail.gmail.com> <49b351060908200032m4a828b43i9f76ff7e79339886@mail.gmail.com> <877hwyam59.fsf@malde.org> Message-ID: Got this back from the bug tracker 6.12.1 will have Unicode support in the IO library which mostly fixes this problem. The rest is fixed by #3398. Iain -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/aeab391c/attachment.html From colin at colina.demon.co.uk Thu Aug 20 09:58:58 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Thu Aug 20 09:39:01 2009 Subject: [Haskell-cafe] Where does documentation get installed with cabal? Message-ID: Hello, I'm trying to find the API documentation for happstack 0.3 (online is for 0.2). So I did: cabal install happstack --reinstall --enable-documentation but I can't find it anywhere within ~/.cabal - where should I look? -- Colin Adams Preston Lancashire From jules at jellybean.co.uk Thu Aug 20 10:04:17 2009 From: jules at jellybean.co.uk (Jules Bean) Date: Thu Aug 20 09:44:19 2009 Subject: [Haskell-cafe] Unifcation and matching in Abelian groups In-Reply-To: <7687290b0908200637u5022c4e6lf76b759a82222f1f@mail.gmail.com> References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> <404396ef0908190316rc772614p9c660c8ab5095ed6@mail.gmail.com> <7687290b0908190345q23313f4bwf24b6868499ee704@mail.gmail.com> <4A8BF0D3.7050403@jellybean.co.uk> <7687290b0908200557i522f3d92jb4d20707baeb3694@mail.gmail.com> <4A8D4AD9.1050701@jellybean.co.uk> <7687290b0908200637u5022c4e6lf76b759a82222f1f@mail.gmail.com> Message-ID: <4A8D57E1.2050002@jellybean.co.uk> John D. Ramsdell wrote: > On Thu, Aug 20, 2009 at 9:08 AM, Jules Bean wrote: > >> I don't find layout a problem, with good editor support. I agree it's a >> problem, with poor editor support. That's all I meant. > > Let's put this issue in perspective. For those few Haskell > programmers that do find layout irritating, I'm sure we would all > agree it's but a minor irritation. The real downside of layout is if > non-Haskell programmers use it as an excuse to dismiss the language. > I happen to think that Data Parallel Haskell has great potential for > use in high performance computations. I'd hate to see a bunch of > Fortraners not try DPH because of Haskell syntax. Well that's a reasonable point. They can still use the non-layout form if it bothers them that much? From simonpj at microsoft.com Thu Aug 20 10:29:23 2009 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Thu Aug 20 10:09:27 2009 Subject: [Haskell-cafe] generalize RecordPuns and RecordWildCards to work with qualified names? In-Reply-To: <2518b95d0908121558j477f061o591a4267efc40f4@mail.gmail.com> References: <2518b95d0907171556l3745912na56481698094b2dd@mail.gmail.com> <638ABD0A29C8884A91BC5FB5C349B1C34B7FA6CABB@EA-EXMSG-C334.europe.corp.microsoft.com> <5ab17e790907241648x77999baft925cac5d9af116d7@mail.gmail.com> <638ABD0A29C8884A91BC5FB5C349B1C35B30DEED90@EA-EXMSG-C334.europe.corp.microsoft.com> <2518b95d0908121558j477f061o591a4267efc40f4@mail.gmail.com> Message-ID: <638ABD0A29C8884A91BC5FB5C349B1C35CE7101966@EA-EXMSG-C334.europe.corp.microsoft.com> Evan, Lennart Thanks for the provocation. I've committed a patch that fixes all these issues. Try now! Simon Thu Aug 20 13:34:43 BST 2009 simonpj@microsoft.com * Improvements to record puns, wildcards * Make C { A.a } work with punning, expanding to C { A.a = a } * Make it so that, with -fwarn-unused-matches, f (C {..}) = x does not complain about the bindings introduced by the "..". * Make -XRecordWildCards implies -XDisambiguateRecordFields. * Overall refactoring of RnPat, which had become very crufty. In particular, there is now a monad, CpsRn, private to RnPat, which deals with the cps-style plumbing. This is why so many lines of RnPat have changed. * Refactor the treatment of renaming of record fields into two passes - rnHsRecFields1, used both for patterns and expressions, which expands puns, wild-cards - a local renamer in RnPat for fields in patterns - a local renamer in RnExpr for fields in construction and update This make it all MUCH easier to understand * Improve documentation of record puns, wildcards, and disambiguation | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On | Behalf Of Evan Laforge | Sent: 12 August 2009 23:59 | To: Simon Peyton-Jones | Cc: Augustsson, Lennart; haskell; GHC users | Subject: Re: [Haskell-cafe] generalize RecordPuns and RecordWildCards to work with | qualified names? | | > | Even is suggesting that instead of reporting an error, in the second | > | case we could use the translation: | > | | > | ? f (A.A { A.a }) = a ? --> ? f (A.A { A.a = a }) | > | | > | (i.e., when punning occurs with a qualified name, use just the | > | unqualified part of the name in the pattern) | > | > Yes, that'd be possible. ? But it seems debatable -- it doesn't *look* as if the | pattern (A.A { A.a }) binds 'a' -- and it seems even less desirable in record | construction and update. ?To be concrete, would you expect these to work too? | > | > ?g a = A.A { A.a } ? ? --> ? ?g a = A.A { A.a = a } | > ?h x a = x { A.a } ? ? --> ? ?h x a = a { A.a = a } | | Oh, I didn't realize that record punning included construction as | well. Yeah, that's a little funky looking. I don't mind seeing the | binding form and I think a new reader could figure it out without too | much trouble but I would be a little confused by the construction form | and think a new reader would also be confused. | | > With -XDisambiguateRecordFields you could say | > | > ?g a = A.A { a } | > | > which seems better. ?(But there's no help for record update, since we don't know | which data constructor is involved.) | | I didn't know about DisambiguateRecordFields! Looks like that also | makes the wildcard work like I want it to. | | The ghc docs for DisambiguateRecordFields don't make this very clear | to me... it talks about disambiguating names in scope, but if I say | "R.R { a = val}" I wouldn't expect it to "disambiguate" 'a', which is | not in scope at all, to 'R.a' which looks like a completely different | name. Rereading the paragraph at 7.3.11 I'm still surprised this | works. Maybe add something like: | | ... preceeding docs ... | | This also means that if you use qualified imports you can still use | unqualified field names. E.g. in the pattern @(R.R { a = a_val })@, | @a@ will be disambiguated to @R.a@, even if @R@ is imported qualified. | | I gather we're not supposed to call them "records" anymore, they're | supposed to be something I forget now, but the rest of the ghc docs | says records, so... | | > So my current conclusion is: improve the error message, perhaps suggesting the | flag -XDismabiguateRecordFields, but don't add the change you suggest. | > | > Comments? | | Sounds good to me. I'll try adding DisambiguateRecordFields and try | out the new punning, thanks! | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe From leimy2k at gmail.com Thu Aug 20 10:34:24 2009 From: leimy2k at gmail.com (David Leimbach) Date: Thu Aug 20 10:14:26 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <4A8D1CC3.8080507@jellybean.co.uk> References: <3e1162e60908190800j3888c2d9jf9f6f8342ba165ec@mail.gmail.com> <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <4A8D1CC3.8080507@jellybean.co.uk> Message-ID: <3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com> On Thu, Aug 20, 2009 at 2:52 AM, Jules Bean wrote: > Peter Verswyvelen wrote: > >> Not at all, use it for whatever you want to :-) >> >> I'm writing this code because I'm preparing to write a bunch of tutorials >> on FRP, and I first wanted to start with simple console based FRP, e.g. >> making a little text adventure game, where the input/choices of the user >> might be parsed ala parsec, using monadic style, applicative style, and >> arrows, and then doing the same with FRP frameworks like >> > > > This is a really bad place to start a FRP tutorial IMO. > > The interface for 'interact' does not make any promises about the relative > evaluation order of the input list / production order of the output list. > > That's why you are having to play horrible tricks with seq to try to force > the order to be what you want. > > I don't think this is the basis of a robust system or a sensible tutorial. > > Just my 2c. > Interesting feedback, but I don't get the reason really. How is using seq a "horrible trick"? It's there for strict evaluation when you need it, and in this case it was warranted. And as far as saying it's not a good basis for a robust system, I'm also not sure I agree, but a "sensible tutorial", that I could believe as I think it's actually quite difficult to explain these topics to people in a way they're going to understand right away. Could we perhaps bother you to suggest an alternative along with your criticism? It would feel a little more constructive at least (not that I think you were being terribly harsh) Dave -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/1883a7b7/attachment.html From explicitcall at googlemail.com Thu Aug 20 10:36:28 2009 From: explicitcall at googlemail.com (Max Desyatov) Date: Thu Aug 20 10:16:14 2009 Subject: [Haskell-cafe] Where does documentation get installed with cabal? In-Reply-To: (Colin Paul Adams's message of "Thu, 20 Aug 2009 14:58:58 +0100") References: Message-ID: <87praqr1qr.fsf@zagan.made.you> Colin Paul Adams writes: > I'm trying to find the API documentation for happstack 0.3 (online is > for 0.2). > > So I did: > > cabal install happstack --reinstall --enable-documentation > > but I can't find it anywhere within ~/.cabal - where should I look? In most cases it is installed in ~/.cabal/share/doc/happstack*/html. Is there any files at that directory? From leimy2k at gmail.com Thu Aug 20 10:37:51 2009 From: leimy2k at gmail.com (David Leimbach) Date: Thu Aug 20 10:17:50 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <4A8D1CC3.8080507@jellybean.co.uk> Message-ID: <3e1162e60908200737x60a922f7o5d64b70ae17a07ba@mail.gmail.com> > > > and since the input that the user gives depends on the output on the screen > (it represents the user <-> machine dialog loop), we must make sure that > laziness does not go wild and strictness is needed to respect this > dependency. But as Ryan showed, seq is not really needed (but pattern > matching is), and his code is super elegant and simple. I > I'm pretty certain that forcing a pattern match via case is what disallows the laziness to get out of hand. The case statement, when evaluated, must choose a matched pattern branch, even if it's the only possibility, which ends up boiling down to "seq" anyway doesn't it? Or is it that case doesn't have to go through as deep an evaluation as seq does in some cases? Does that even make any sense? :-) Dave > > On Thu, Aug 20, 2009 at 11:52 AM, Jules Bean wrote: > >> Peter Verswyvelen wrote: >> >>> Not at all, use it for whatever you want to :-) >>> >>> I'm writing this code because I'm preparing to write a bunch of tutorials >>> on FRP, and I first wanted to start with simple console based FRP, e.g. >>> making a little text adventure game, where the input/choices of the user >>> might be parsed ala parsec, using monadic style, applicative style, and >>> arrows, and then doing the same with FRP frameworks like >>> >> >> >> This is a really bad place to start a FRP tutorial IMO. >> >> The interface for 'interact' does not make any promises about the relative >> evaluation order of the input list / production order of the output list. >> >> That's why you are having to play horrible tricks with seq to try to force >> the order to be what you want. >> >> I don't think this is the basis of a robust system or a sensible tutorial. >> >> Just my 2c. >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/6928ebca/attachment.html From colin at colina.demon.co.uk Thu Aug 20 10:39:14 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Thu Aug 20 10:19:18 2009 Subject: [Haskell-cafe] Where does documentation get installed with cabal? In-Reply-To: <87praqr1qr.fsf@zagan.made.you> (Max Desyatov's message of "Thu\, 20 Aug 2009 17\:36\:28 +0300") References: <87praqr1qr.fsf@zagan.made.you> Message-ID: >>>>> "Max" == Max Desyatov writes: Max> Colin Paul Adams writes: >> I'm trying to find the API documentation for happstack 0.3 >> (online is for 0.2). >> >> So I did: >> >> cabal install happstack --reinstall --enable-documentation >> >> but I can't find it anywhere within ~/.cabal - where should I >> look? Max> In most cases it is installed in Max> ~/.cabal/share/doc/happstack*/html. Is there any files at Max> that directory? There are now, but only a very few. And very little contents in them. It's as if the --reinstall were partial. -- Colin Adams Preston Lancashire From explicitcall at googlemail.com Thu Aug 20 10:54:40 2009 From: explicitcall at googlemail.com (Max Desyatov) Date: Thu Aug 20 10:34:25 2009 Subject: [Haskell-cafe] Generics for constructing Rows In-Reply-To: <3c6288ab0908200443w18110f45h8edc7353091100f2@mail.gmail.com> (Sean Leather's message of "Thu, 20 Aug 2009 13:43:38 +0200") References: <87r5v6izrc.fsf@zagan.made.you> <3c6288ab0908200443w18110f45h8edc7353091100f2@mail.gmail.com> Message-ID: <87ocqar0wf.fsf@zagan.made.you> Sean Leather writes: > I'm not sure the problem you're running into is strictly a generic > programming (GP) one. Typically, GP takes code that is often written > and generalizes it, so that it doesn't have to be written for multiple > datatypes. That seems to be GP problem, as your solution doesn't scale well when I wan't to add/remove/change fields in the `Row` record. The perfect way as I see it, would be just editing `Row` data declaration, nothing else. Studying few papers about GP in Haskell, I reckon this could be represented as generic traversal, using my `Row` declaration with `Either`. I don't see really good way to write a generic producer from `[String]` to version of `Row` without `Either`. But SYB doesn't provide a way for passing type-class-parametric functions to gmapT, and SYB-with-class has large overhead of its usage. I don't have enough time to find out how this can be written in SYB-with-class, if it really can be written. The restriction of EMGM was described in my initial message. > For your problem, I think the first issue is figuring out how to write > the non-generic function. I don't know if this is exactly what you > want, but you can write a version of gmap using GADTs and rank-2 > types. I've simplified some types, but it should be easily > transferable to your code. For example, change the String, Float, > etc. to your Salary, Department, whatever. > --- > > {-# LANGUAGE GADTs #-} > {-# LANGUAGE Rank2Types #-} > > module Main where > > data T a where > ? String? :: T String > ? Float?? :: T Float > ? Integer :: T Integer > > data Row = Row (Maybe String) (Maybe Float) (Maybe Integer) > ? deriving Show > > f :: T a -> Maybe a -> Maybe a > f String (Just "a") = Just "z" > f _????? x = x > > gmap :: (forall a . T a -> Maybe a -> Maybe a) -> Row -> Row > gmap f (Row x y z) = Row (f String x) (f Float y) (f Integer z) > > main = do > ? print $ gmap f $ Row Nothing (Just 5.4) (Just 3) -- ==> Row Nothing (Just 5.4) (Just 3) > ? print $ gmap f $ Row (Just "a") Nothing Nothing -- ==> Row (Just "z") Nothing Nothing > > If this is what you're looking for, then I think it might be possible to do this more generally, though I haven't looked > into it. Many thanks for this code, I'll try to integrate it at this point. It seems to remove the burden of managing row indices list and implements some intended restrictions that will make my code less error prone, I hope. WBR, Max. From sargrigory at ya.ru Thu Aug 20 11:05:30 2009 From: sargrigory at ya.ru (Grigory Sarnitskiy) Date: Thu Aug 20 10:45:31 2009 Subject: [Haskell-cafe] Can't derive Binary for StdGen Message-ID: <38391250780730@webmail127.yandex.ru> Hello! I'm trying to derive Binary for StdGen with DrIFT: module Main where import System.Random import Data.Binary {-!for StdGen derive : Binary !-} data Foo = Foo StdGen StdGen deriving (Show) {-! derive : Binary !-} but I got error "DrIFT: can't find module System/Random" What shall I do? From jvranish at gmail.com Thu Aug 20 11:51:23 2009 From: jvranish at gmail.com (Job Vranish) Date: Thu Aug 20 11:31:25 2009 Subject: [Haskell-cafe] Parsec lookahead and <|> In-Reply-To: <4A8D370F.5000401@van.steenbergen.nl> References: <4A8D370F.5000401@van.steenbergen.nl> Message-ID: Yeah, that's weird. I played around with la and it seems to only cause problems when the parser passed into lookAhead succeeds, which seem to go directly against it's stated purpose. lookAhead isn't consuming, (hence the unexpected "b") but still prevents <|> from doing it's thing. Seems like a bug to me... My off the hip fix is a modified form of the ugly try: lookAhead (ParsecT p) = ParsecT $ \s@(State _ pos _) -> do res <- p s case res of Consumed rep -> do r <- rep case r of Error err -> return $ Empty $ return $ Error (setErrorPos pos err) Ok a state err -> return $ Empty $ return $ Ok a s err empty -> return $ empty The only potential annoyance with this fix that I can see, is that the error messages can be confusing if you are doing dumb things with your lookAhead parsers. For example: la :: Parsec String () (Char) la = lookAhead' (char 'r') *Main> parseTest ((la >> char 'a') <|> char 'b') "a" parse error at (line 1, column 1): unexpected "a" expecting "r" or "b" *Main> parseTest ((la >> char 'a') <|> char 'b') "r" parse error at (line 1, column 2): unexpected "r" expecting "a" or "b" But for the most part it behaves as expected. - Job (sorry for the double post Martijn, forgot to reply to all) On Thu, Aug 20, 2009 at 7:44 AM, Martijn van Steenbergen < martijn@van.steenbergen.nl> wrote: > Goedemiddag caf?, > > Consider the following function, using parsec-3.0.0: > > la :: Parsec String () (Maybe Char) >> la = lookAhead (optionMaybe anyChar) >> > > *Lookahead> parseTest (char 'a' <|> char 'b') "a" > 'a' > *Lookahead> parseTest (char 'a' <|> char 'b') "b" > 'b' > *Lookahead> parseTest (la *> char 'a' <|> char 'b') "a" > 'a' > *Lookahead> parseTest (la *> char 'a' <|> char 'b') "b" > parse error at (line 1, column 2): > unexpected "b" > expecting "a" > > The first three work fine and as expected, but the fourth example fails > where I would expect success. I know <|> won't try the rhs if the lhs > consumed input, but lookAhead's documentation promises not to consume any > input. Is this a bug in Parsec or am I missing something? > > Thanks, > > Martijn. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/b8db8db6/attachment.html From daniel.is.fischer at web.de Thu Aug 20 12:04:02 2009 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Thu Aug 20 11:45:01 2009 Subject: [Haskell-cafe] Parsec lookahead and <|> In-Reply-To: <4A8D370F.5000401@van.steenbergen.nl> References: <4A8D370F.5000401@van.steenbergen.nl> Message-ID: <200908201804.02394.daniel.is.fischer@web.de> Am Donnerstag 20 August 2009 13:44:15 schrieb Martijn van Steenbergen: > Goedemiddag caf?, > > Consider the following function, using parsec-3.0.0: > > la :: Parsec String () (Maybe Char) > > la = lookAhead (optionMaybe anyChar) > > *Lookahead> parseTest (char 'a' <|> char 'b') "a" > 'a' > *Lookahead> parseTest (char 'a' <|> char 'b') "b" > 'b' > *Lookahead> parseTest (la *> char 'a' <|> char 'b') "a" > 'a' > *Lookahead> parseTest (la *> char 'a' <|> char 'b') "b" > parse error at (line 1, column 2): > unexpected "b" > expecting "a" > > The first three work fine and as expected, but the fourth example fails > where I would expect success. I know <|> won't try the rhs if the lhs > consumed input, but lookAhead's documentation promises not to consume > any input. Is this a bug in Parsec or am I missing something? Bad bug in Parsec (from the beginning, the same happens in parsec-2), I'd say. Desugared, we have lookAhead p = getParserState >>= \st -> p >>= \r -> setParserState st >>= \_ -> return r Due to the (>>=), whenever p consumes input, lookAhead will return (Consumed _) and there's no way to get rid of it, so (la *> char 'a') returns Consumed (Error something) on the input "b" and (<|>) doesn't try char 'b'. The code for lookAhead should look something like (parsec-2, to avoid 'returns' cluttering the code): lookAhead p = Parser $ \st -> case parserReply $ runP p st of Ok x s err -> Empty (Ok x st err) Error err -> Empty (Error err) Since exporting an 'unconsume' function wouldn't be desirable, lookAhead would have to move to Text.Parse(rCombinators.Parse)c.Prim. (not necessary in parsec-3 yet, since that exports all top level definitions from all modules so far). > > Thanks, > > Martijn. From explicitcall at googlemail.com Thu Aug 20 12:15:59 2009 From: explicitcall at googlemail.com (Max Desyatov) Date: Thu Aug 20 11:55:44 2009 Subject: [Haskell-cafe] Can't derive Binary for StdGen In-Reply-To: <38391250780730@webmail127.yandex.ru> (Grigory Sarnitskiy's message of "Thu, 20 Aug 2009 19:05:30 +0400") References: <38391250780730@webmail127.yandex.ru> Message-ID: <87hbw2qx4w.fsf@zagan.made.you> Grigory Sarnitskiy writes: > Hello! I'm trying to derive Binary for StdGen with DrIFT: [...] > but I got error "DrIFT: can't find module System/Random" > What shall I do? I'd use http://hackage.haskell.org/packages/archive/derive/2.0.1/doc/html/Data-Derive-Binary.html instead. From jupdike at gmail.com Thu Aug 20 12:25:46 2009 From: jupdike at gmail.com (Jared Updike) Date: Thu Aug 20 12:05:47 2009 Subject: [Haskell-cafe] Re: Haddock: Failed to create dependency graph (when adding sections with * or a module heading) In-Reply-To: <8b108f950908190945m747b0df3m8bffdc81ed220a01@mail.gmail.com> References: <8b108f950908190945m747b0df3m8bffdc81ed220a01@mail.gmail.com> Message-ID: <8b108f950908200925l3b46ad2dk7ff8b359d5adfe9e@mail.gmail.com> Simple fix (terrible error message): Move the ( up to the line with the module name. Previous bad code: module Data.DualMap -- * The @DualMap@ abstract type ( DualMap () -- * (?) internal? -- exposed for testing purposes, for now... , dmFlip -- * converting to and from DualMap , toList, fromList, map -- * constructing a DualMap , empty, null, insert, union Happy code looks like this: module Data.DualMap ( -- * The @DualMap@ abstract type DualMap () -- * (?) internal? -- exposed for testing purposes, for now... , dmFlip -- * converting to and from DualMap , toList, fromList, map -- * constructing a DualMap , empty, null, insert, union Simple enough. I found this out by downloading DList [1] from hacakge and gutting it and replacing the code with my own code. When DList worked with 'cabal haddock' and mine didn't (when I tried to add some asterisks), I looked at the difference between the files and sure enough my parenthesis was on the wrong line. BTW I highly recommend DList as a starting place for a new Haskell project instead of hnop [2]. Jared. [1] http://hackage.haskell.org/package/dlist-0.5 [2] http://semantic.org/hnop/ On Wed, Aug 19, 2009 at 9:45 AM, Jared Updike wrote: > > I compiled and installed haddock-2.4.2 from the tarball source. > Adding a few simple comments to the code here: > ??https://dl.getdropbox.com/u/143480/doc/DualMap.hs > and running haddock > $ haddock -h -o doc Data/DualMap.hs > Warning: Data.DualMap: could not find link destinations for: > ?? ?Data.Typeable.Typeable2 GHC.Base.Eq GHC.Show.Show GHC.Base.Ord GHC.Base.Bool Data.Set.Set > yields: > ??https://dl.getdropbox.com/u/143480/doc/Data-DualMap.html > > Things look good. (Note that this module only depends on libs that ship with GHC and no other source modules.) > However, when I try to add sections?(a la?http://www.haskell.org/haddock/doc/html/ch03s04.html#id289234 )?in the comments with "-- * test" I get: > $ haddock -h -o doc Data/DualMap.hs > Data/DualMap.hs:20:0: parse error on input `-- * test' > haddock: Failed to create dependency graph > I have no idea where to begin getting this?to work since this error message only tells me that Haddock.Interface.depanal returned Nothing (according to a grep of the haddock sources) but not how to stop the dependency analysis from failing. Perhaps I need some more command line arguments or references to missing link destinations in GHC/base/containers documentation or some haddock config file? > Searching Google yielded plenty of cabal build errors of the same ilk for packages on hackage but nothing about how to fix them. > > ??Jared. From leather at cs.uu.nl Thu Aug 20 12:45:54 2009 From: leather at cs.uu.nl (Sean Leather) Date: Thu Aug 20 12:26:15 2009 Subject: [Haskell-cafe] Generics for constructing Rows In-Reply-To: <87ocqar0wf.fsf@zagan.made.you> References: <87r5v6izrc.fsf@zagan.made.you> <3c6288ab0908200443w18110f45h8edc7353091100f2@mail.gmail.com> <87ocqar0wf.fsf@zagan.made.you> Message-ID: <3c6288ab0908200945w5e715b6ci4c23d3363bebbad7@mail.gmail.com> > That seems to be GP problem, as your solution doesn't scale well when I > wan't to add/remove/change fields in the `Row` record. Ah yes, this is a good use case. I wasn't paying close enough attention before, and I didn't see an immediate implementation of your function at the time. > The perfect way > as I see it, would be just editing `Row` data declaration, nothing else. > Studying few papers about GP in Haskell, I reckon this could be > represented as generic traversal, using my `Row` declaration with > `Either`. I don't see really good way to write a generic producer from > `[String]` to version of `Row` without `Either`. But SYB doesn't > provide a way for passing type-class-parametric functions to gmapT, and > SYB-with-class has large overhead of its usage. I don't have enough > time to find out how this can be written in SYB-with-class, if it really > can be > written. The restriction of EMGM was described in my initial message. > I would suggest looking at Multirec. There's a draft of the paper to be published at ICFP, and the library is on Hackage. http://www.cs.uu.nl/wiki/GenericProgramming/Multirec http://hackage.haskell.org/package/multirec If you don't have anything generically useful by next week, I'll look at it again when I have more time. Regards, Sean -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/da3480ee/attachment.html From ryani.spam at gmail.com Thu Aug 20 12:56:43 2009 From: ryani.spam at gmail.com (Ryan Ingram) Date: Thu Aug 20 12:36:43 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <3e1162e60908200737x60a922f7o5d64b70ae17a07ba@mail.gmail.com> References: <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <4A8D1CC3.8080507@jellybean.co.uk> <3e1162e60908200737x60a922f7o5d64b70ae17a07ba@mail.gmail.com> Message-ID: <2f9b2d30908200956x39f0b4e9w234a00f7eeb235c4@mail.gmail.com> On Thu, Aug 20, 2009 at 7:37 AM, David Leimbach wrote: > I'm pretty certain that forcing a pattern match via case is what disallows > the laziness to get out of hand. ?The case statement, when evaluated, must > choose a matched pattern branch, even if it's the only possibility, which > ends up boiling down to "seq" anyway doesn't it? Yep, it's basically the same, just prettier, and, in my opinion, more clearly specifies what it is you are trying to do. Compare these identical code fragments: (a) \xs -> (tail xs, xs `seq` empty, head xs) (b) \(x:xs) -> (xs, empty, x) Here are the possibilities for input: (1) input is _|_ (a) (_|_, _|_, _|_) (b) _|_ (2) input is [] (a) (_|_, empty, _|_) (b) _|_ (3) input is (x:xs) (a) (xs, empty, x) (b) (xs, empty, x) In the case of lazy I/O, you can sort-of-imagine the _|_ input case as a value that means "don't know yet"; the computation is incrementally updated as the input becomes more defined. It's complicated because now you have to differentiate "don't know _|_" with "erroneous _|_" such as the results of case (2). If it helps you twist your head around it, think of the input to interact as coming from a big but slow pure function that is computing the behavior of every atom in the universe and returning what keys on a keyboard are getting pressed. So when you pattern match against that input, you have to wait for the computation to happen; someone who doesn't type anything is like that function going into an infinite loop _|_. But you can't know if it might decide to return a value (halting problem!) so you keep running it anyways. > Or is it that case doesn't have to go through as deep an evaluation as seq > does in some cases? ?Does that even make any sense? ?:-) It's the same as seq; both reduce the argument to WHNF which means that the constructor type ([] vs. (:) is known. -- ryan From ryani.spam at gmail.com Thu Aug 20 12:57:28 2009 From: ryani.spam at gmail.com (Ryan Ingram) Date: Thu Aug 20 12:37:27 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <2f9b2d30908200956x39f0b4e9w234a00f7eeb235c4@mail.gmail.com> References: <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <4A8D1CC3.8080507@jellybean.co.uk> <3e1162e60908200737x60a922f7o5d64b70ae17a07ba@mail.gmail.com> <2f9b2d30908200956x39f0b4e9w234a00f7eeb235c4@mail.gmail.com> Message-ID: <2f9b2d30908200957wd5a4a0cu3cc7afa31f2b83a9@mail.gmail.com> On Thu, Aug 20, 2009 at 9:56 AM, Ryan Ingram wrote: > Compare these identical code fragments: Er, strike "identical". Oops! Comparing identical fragments would be boring. -- ryan From jvranish at gmail.com Thu Aug 20 13:05:22 2009 From: jvranish at gmail.com (Job Vranish) Date: Thu Aug 20 12:45:24 2009 Subject: [Haskell-cafe] Right way to implement setPixel function In-Reply-To: <365149.71856.qm@web112518.mail.gq1.yahoo.com> References: <365149.71856.qm@web112518.mail.gq1.yahoo.com> Message-ID: Your setPixel function is almost ready to work in a State monad If you modify your setPixel function slightly like so: setPixel' :: Int -> Int -> Color -> B.ByteString -> ((), B.ByteString) setPixel' x y (r,g,b) image = ((), B.concat [beforePixel, pixel, afterPixel]) and then wrap it in the State monad constructor: setPixel = State setPixel' then you can do drawPixels = do setPixel 5 10 (200, 0, 0) setPixel 20 1 (0, 200, 0) setPixel 90 2 (0, 0, 200) modifiedImage = execState drawPixels originalImage See! you were already using a monad and didn't even know it! :D Performance wise, B.concat is O(n), which is very not good for your purpose. It copies the whole string and the optimizer won't be able to magically make it go away. For something that works in O(1), you will have to use something like STArrays instead of bytestrings. - Job On Thu, Aug 20, 2009 at 2:32 AM, CK Kashyap wrote: > Hi, > I had posted a note on line drawing algo with Haskell some time back. Now, > I am trying to write a PNM image. > > import qualified Data.ByteString as B > > width = 256 > height = 256 > bytesInImage = width * height * 3 > blankImage = B.pack $ take bytesInImage (repeat 0) > > type Color = (Int,Int,Int) > setPixel :: B.ByteString -> Int -> Int -> Color -> B.ByteString > setPixel image x y (r,g,b) = B.concat [beforePixel, pixel, afterPixel] > where > beforePixel = B.take before image > afterPixel = B.drop (before+3) image > pixel=B.pack [(fromIntegral r),(fromIntegral > g),(fromIntegral b)] > -- number of bytes before the 3 bytes of > -- the pixel at x y > before = (y * width * 3) + (x * 3) - 3 > > main = do > putStrLn "P6" > putStrLn ( (show width) ++ " " ++ (show height) ) > putStrLn "255" > -- Set a red pixel at 100 100 > B.putStr (setPixel blankImage 100 100 (255,0,0)) > > > Can I please have some review comments on the code above? Would recreating > the entire ByteString for each setPixel be an overhead? > Also, I am barely beginning to grasp the Monad concept....I was wondering > if there could be a monadic style of implementation of this - that could > potentially have a series of setPixels inside a do block? > > Regards, > Kashyap > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/34ac8254/attachment.html From lennart at augustsson.net Thu Aug 20 13:12:44 2009 From: lennart at augustsson.net (Lennart Augustsson) Date: Thu Aug 20 12:52:46 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com> References: <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <4A8D1CC3.8080507@jellybean.co.uk> <3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com> Message-ID: Using seq to control a program's semantics (as in, input-output behaviour) is a horrible hack. The seq operation there to control space and time aspects of your program. (The specification of seq doesn't even say that the first argument is evaluated before the second one.) You should use data dependencies to control your program's semantics. On Thu, Aug 20, 2009 at 4:34 PM, David Leimbach wrote: > > > On Thu, Aug 20, 2009 at 2:52 AM, Jules Bean wrote: >> >> Peter Verswyvelen wrote: >>> >>> Not at all, use it for whatever you want to :-) >>> >>> I'm writing this code because I'm preparing to write a bunch of tutorials >>> on FRP, and I first wanted to start with simple console based FRP, e.g. >>> making a little text adventure game, where the input/choices of the user >>> might be parsed ala parsec, using monadic style, applicative style, and >>> arrows, and then doing the same with FRP frameworks like >> >> >> This is a really bad place to start a FRP tutorial IMO. >> >> The interface for 'interact' does not make any promises about the relative >> evaluation order of the input list / production order of the output list. >> >> That's why you are having to play horrible tricks with seq to try to force >> the order to be what you want. >> >> I don't think this is the basis of a robust system or a sensible tutorial. >> >> Just my 2c. > > Interesting feedback, but I don't get the reason really. ?How is using seq a > "horrible trick"? ?It's there for strict evaluation when you need it, and in > this case it was warranted. > And as far as saying it's not a good basis for a robust system, I'm also not > sure I agree, but a "sensible tutorial", that I could believe as I think > it's actually quite difficult to explain these topics to people in a way > they're going to understand right away. > Could we perhaps bother you to suggest an alternative along with your > criticism? ?It would feel a little more constructive at least (not that I > think you were being terribly harsh) > Dave > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > From jvranish at gmail.com Thu Aug 20 13:13:40 2009 From: jvranish at gmail.com (Job Vranish) Date: Thu Aug 20 12:53:41 2009 Subject: [Haskell-cafe] Right way to implement setPixel function In-Reply-To: References: <365149.71856.qm@web112518.mail.gq1.yahoo.com> Message-ID: Opps: setPixel = State setPixel' should be: setPixel x y rgb = State $ setPixel' x y rgb - Job On Thu, Aug 20, 2009 at 1:05 PM, Job Vranish wrote: > Your setPixel function is almost ready to work in a State monad > If you modify your setPixel function slightly like so: > > setPixel' :: Int -> Int -> Color -> B.ByteString -> ((), B.ByteString) > setPixel' x y (r,g,b) image = ((), B.concat [beforePixel, pixel, > afterPixel]) > > and then wrap it in the State monad constructor: > > setPixel = State setPixel' > > then you can do > > drawPixels = do > setPixel 5 10 (200, 0, 0) > setPixel 20 1 (0, 200, 0) > setPixel 90 2 (0, 0, 200) > > modifiedImage = execState drawPixels originalImage > > See! you were already using a monad and didn't even know it! :D > > Performance wise, B.concat is O(n), which is very not good for your > purpose. It copies the whole string and the optimizer won't be able to > magically make it go away. For something that works in O(1), you will have > to use something like STArrays instead of bytestrings. > > - Job > > > > On Thu, Aug 20, 2009 at 2:32 AM, CK Kashyap wrote: > >> Hi, >> I had posted a note on line drawing algo with Haskell some time back. Now, >> I am trying to write a PNM image. >> >> import qualified Data.ByteString as B >> >> width = 256 >> height = 256 >> bytesInImage = width * height * 3 >> blankImage = B.pack $ take bytesInImage (repeat 0) >> >> type Color = (Int,Int,Int) >> setPixel :: B.ByteString -> Int -> Int -> Color -> B.ByteString >> setPixel image x y (r,g,b) = B.concat [beforePixel, pixel, afterPixel] >> where >> beforePixel = B.take before image >> afterPixel = B.drop (before+3) image >> pixel=B.pack [(fromIntegral r),(fromIntegral >> g),(fromIntegral b)] >> -- number of bytes before the 3 bytes of >> -- the pixel at x y >> before = (y * width * 3) + (x * 3) - 3 >> >> main = do >> putStrLn "P6" >> putStrLn ( (show width) ++ " " ++ (show height) ) >> putStrLn "255" >> -- Set a red pixel at 100 100 >> B.putStr (setPixel blankImage 100 100 (255,0,0)) >> >> >> Can I please have some review comments on the code above? Would recreating >> the entire ByteString for each setPixel be an overhead? >> Also, I am barely beginning to grasp the Monad concept....I was wondering >> if there could be a monadic style of implementation of this - that could >> potentially have a series of setPixels inside a do block? >> >> Regards, >> Kashyap >> >> >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/55b79cc8/attachment.html From ketil at malde.org Thu Aug 20 14:02:38 2009 From: ketil at malde.org (Ketil Malde) Date: Thu Aug 20 13:42:28 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <3e1162e60908200737x60a922f7o5d64b70ae17a07ba@mail.gmail.com> (David Leimbach's message of "Thu\, 20 Aug 2009 07\:37\:51 -0700") References: <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <4A8D1CC3.8080507@jellybean.co.uk> <3e1162e60908200737x60a922f7o5d64b70ae17a07ba@mail.gmail.com> Message-ID: <87ocqaz7lt.fsf@malde.org> David Leimbach writes: > I'm pretty certain that forcing a pattern match via case is what disallows > the laziness to get out of hand. The case statement, when evaluated, must > choose a matched pattern branch, even if it's the only possibility, which > ends up boiling down to "seq" anyway doesn't it? Prelude> case undefined of x -> () () So I think you are incorrect: the 'undefined' here isn't evaluated by the case. -k -- If I haven't seen further, it is by standing in the footprints of giants From aslatter at gmail.com Thu Aug 20 14:10:01 2009 From: aslatter at gmail.com (Antoine Latter) Date: Thu Aug 20 13:50:02 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <87ocqaz7lt.fsf@malde.org> References: <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <4A8D1CC3.8080507@jellybean.co.uk> <3e1162e60908200737x60a922f7o5d64b70ae17a07ba@mail.gmail.com> <87ocqaz7lt.fsf@malde.org> Message-ID: <694519c50908201110j2bc9a36che2d41eead5dcd25b@mail.gmail.com> On Thu, Aug 20, 2009 at 1:02 PM, Ketil Malde wrote: > David Leimbach writes: > >> I'm pretty certain that forcing a pattern match via case is what disallows >> the laziness to get out of hand. ?The case statement, when evaluated, must >> choose a matched pattern branch, even if it's the only possibility, which >> ends up boiling down to "seq" anyway doesn't it? > > ? ?Prelude> case undefined of x -> () > ? ?() > > So I think you are incorrect: the 'undefined' here isn't evaluated by > the case. > It's doing a case on a pattern match that forces evaluation. Try: > case undefined of (x:xs) -> () Antoine From haskell at colquitt.org Thu Aug 20 14:17:36 2009 From: haskell at colquitt.org (John Dorsey) Date: Thu Aug 20 13:57:59 2009 Subject: [Haskell-cafe] Where does documentation get installed with cabal? In-Reply-To: References: <87praqr1qr.fsf@zagan.made.you> Message-ID: <20090820181735.GH14826@colquitt.org> > >> I'm trying to find the API documentation for happstack 0.3 > >> (online is for 0.2). [...] > Max> In most cases it is installed in > Max> ~/.cabal/share/doc/happstack*/html. Is there any files at > Max> that directory? > > There are now, but only a very few. And very little contents in them. > It's as if the --reinstall were partial. Perhaps it's in /usr/local/share/doc. Mine seem to end up there, and I don't recall whether I specified that at any point. It's not in my ~/.cabal/config, but I am using the very helpful user-install: False documentation: True I suspect /usr/local/share/doc is the default for documentation in global installs, but I can't go verify that at the moment. Regards, John From Christian.Maeder at dfki.de Thu Aug 20 14:21:30 2009 From: Christian.Maeder at dfki.de (Christian Maeder) Date: Thu Aug 20 14:01:32 2009 Subject: [Haskell-cafe] Re: Parsec lookahead and <|> In-Reply-To: <200908201804.02394.daniel.is.fischer@web.de> References: <4A8D370F.5000401@van.steenbergen.nl> <200908201804.02394.daniel.is.fischer@web.de> Message-ID: <4A8D942A.7060206@dfki.de> Daniel Fischer wrote: > Am Donnerstag 20 August 2009 13:44:15 schrieb Martijn van Steenbergen: >> Goedemiddag caf?, >> >> Consider the following function, using parsec-3.0.0: >>> la :: Parsec String () (Maybe Char) >>> la = lookAhead (optionMaybe anyChar) >> *Lookahead> parseTest (char 'a' <|> char 'b') "a" >> 'a' >> *Lookahead> parseTest (char 'a' <|> char 'b') "b" >> 'b' >> *Lookahead> parseTest (la *> char 'a' <|> char 'b') "a" >> 'a' >> *Lookahead> parseTest (la *> char 'a' <|> char 'b') "b" >> parse error at (line 1, column 2): >> unexpected "b" >> expecting "a" >> >> The first three work fine and as expected, but the fourth example fails >> where I would expect success. I know <|> won't try the rhs if the lhs >> consumed input, but lookAhead's documentation promises not to consume >> any input. Is this a bug in Parsec or am I missing something? > > Bad bug in Parsec (from the beginning, the same happens in parsec-2), I'd say. I'd say, its a feature. lookAhead returns whatever its argument returns. So in this case it returns "Consumed" without consuming. You can always wrap around a "try" to force the alternative: parseTest (try (la >> char 'a') <|> char 'b') "b" Cheers Christian Maybe it should have been: la >> (char 'a' <|> char 'b') in the first place. From aslatter at gmail.com Thu Aug 20 15:09:13 2009 From: aslatter at gmail.com (Antoine Latter) Date: Thu Aug 20 14:49:14 2009 Subject: [Haskell-cafe] Where does documentation get installed with cabal? In-Reply-To: References: Message-ID: <694519c50908201209r1e2cc266q9ea4b34588f93663@mail.gmail.com> On Thu, Aug 20, 2009 at 8:58 AM, Colin Paul Adams wrote: > Hello, > > I'm trying to find the API documentation for happstack 0.3 (online is > for 0.2). > > So I did: > > cabal install happstack --reinstall --enable-documentation > > but I can't find it anywhere within ~/.cabal - where should I look? Most of hasppstack functionality is not in the "happstack" package, it's in the happstack-* packages. So installing the happstack package with documentation won't really pull in much documentation at all. Antoine From jvranish at gmail.com Thu Aug 20 15:34:25 2009 From: jvranish at gmail.com (Job Vranish) Date: Thu Aug 20 15:14:26 2009 Subject: [Haskell-cafe] Re: Parsec lookahead and <|> In-Reply-To: <4A8D942A.7060206@dfki.de> References: <4A8D370F.5000401@van.steenbergen.nl> <200908201804.02394.daniel.is.fischer@web.de> <4A8D942A.7060206@dfki.de> Message-ID: try works in this case, but it won't if we are using a parser which can consume and then fail (instead of char 'a'). In which case we may want it to fail without exploring the second option. Hmmm though you might be right. Having lookAhead return Consumed is only a problem if the parser passed to lookAhead succeeds, but the parser following lookAhead fails without consuming, which seems like a fairly rare case. Although, it would be a problem for cases where the lookAhead is checking for a negation. For example: parseStuff = (lookAhead parseNotCapital >> identifier) <|> number wouldn't work if lookAhead returned Consumed on success, and try doesn't save us either. Even if returning "Consumed" is the desired behavior I'd still say it at least deserves a note in the docs. Martijn, how did you encounter this problem? - Job On Thu, Aug 20, 2009 at 2:21 PM, Christian Maeder wrote: > Daniel Fischer wrote: > > Am Donnerstag 20 August 2009 13:44:15 schrieb Martijn van Steenbergen: > >> Goedemiddag caf?, > >> > >> Consider the following function, using parsec-3.0.0: > >>> la :: Parsec String () (Maybe Char) > >>> la = lookAhead (optionMaybe anyChar) > >> *Lookahead> parseTest (char 'a' <|> char 'b') "a" > >> 'a' > >> *Lookahead> parseTest (char 'a' <|> char 'b') "b" > >> 'b' > >> *Lookahead> parseTest (la *> char 'a' <|> char 'b') "a" > >> 'a' > >> *Lookahead> parseTest (la *> char 'a' <|> char 'b') "b" > >> parse error at (line 1, column 2): > >> unexpected "b" > >> expecting "a" > >> > >> The first three work fine and as expected, but the fourth example fails > >> where I would expect success. I know <|> won't try the rhs if the lhs > >> consumed input, but lookAhead's documentation promises not to consume > >> any input. Is this a bug in Parsec or am I missing something? > > > > Bad bug in Parsec (from the beginning, the same happens in parsec-2), I'd > say. > > I'd say, its a feature. lookAhead returns whatever its argument returns. > So in this case it returns "Consumed" without consuming. > > You can always wrap around a "try" to force the alternative: > > parseTest (try (la >> char 'a') <|> char 'b') "b" > > Cheers Christian > > Maybe it should have been: > > la >> (char 'a' <|> char 'b') > > in the first place. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/019ae1e6/attachment.html From bugfact at gmail.com Thu Aug 20 15:43:58 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Thu Aug 20 15:24:03 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <4A8D1CC3.8080507@jellybean.co.uk> <3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com> Message-ID: I totally agree that data dependencies are the best way to do that. And I'm beginning to see why interact might not be suitable for demonstrating FRP. On the other hand, when you say data dependencies, you mean that the value of expression A depends on the value of expression B, but what if that value is not really needed? For example, suppose you want a program that asks the name of the user and then outputs "What a nice name" or "What a weird name" depending on some random value. Even though the input value from the user is not used, we still can't output the text before the input is entered. Again the hidden dependency is time itself I guess, so we should do it the real FRP way, even with dumb console text IO. Also doesn't Haskell's IO system uses a hidden RealWorld type that has no value but which is passed from between monadics binds in a strict way to make the ordering work? So IO in Haskell is a horrible hack then? :-) If it would be done nicely, in the FRP way, then RealWorld IO would need time stamps to get rid of the hack? So to do console IO the FRP way (say like in Reactive), the input lines from the user would be Event String, and the output also Event String. Each event occurrence has a time stamp, and when merged, they would be ordered. It would be nice to show this example in Reactive. Too bad Reactive doesn't work (and it's not sure it ever will according to the comment of some users), but for a simple example like this, I'm sure it works. In Yampa, I'm not sure how console based IO would work, I guess it would need to generate event non-occurrences (Nothing) when the user did not type anything, and we would need non-blocking IO, so 100% CPU load, since it's pull based, not sure, to be investigated. I haven't worked with Elerea nor Grapefruit yet, but I'm not sure if I should treat the former as a real FRP system since it is not referentially transparent (it would be nice to know which combinators break it). On the other hand, in this simple example, I could use a strict field in an ADT to enforce the input-output dependency, but I guess this is just the same big hack? (see http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8367 ) This silly example is causing lots of feedback, cool :-) On Thu, Aug 20, 2009 at 7:12 PM, Lennart Augustsson wrote: > Using seq to control a program's semantics (as in, input-output > behaviour) is a horrible hack. > The seq operation there to control space and time aspects of your program. > (The specification of seq doesn't even say that the first argument is > evaluated before the second one.) > You should use data dependencies to control your program's semantics. > > On Thu, Aug 20, 2009 at 4:34 PM, David Leimbach wrote: > > > > > > On Thu, Aug 20, 2009 at 2:52 AM, Jules Bean > wrote: > >> > >> Peter Verswyvelen wrote: > >>> > >>> Not at all, use it for whatever you want to :-) > >>> > >>> I'm writing this code because I'm preparing to write a bunch of > tutorials > >>> on FRP, and I first wanted to start with simple console based FRP, e.g. > >>> making a little text adventure game, where the input/choices of the > user > >>> might be parsed ala parsec, using monadic style, applicative style, and > >>> arrows, and then doing the same with FRP frameworks like > >> > >> > >> This is a really bad place to start a FRP tutorial IMO. > >> > >> The interface for 'interact' does not make any promises about the > relative > >> evaluation order of the input list / production order of the output > list. > >> > >> That's why you are having to play horrible tricks with seq to try to > force > >> the order to be what you want. > >> > >> I don't think this is the basis of a robust system or a sensible > tutorial. > >> > >> Just my 2c. > > > > Interesting feedback, but I don't get the reason really. How is using > seq a > > "horrible trick"? It's there for strict evaluation when you need it, and > in > > this case it was warranted. > > And as far as saying it's not a good basis for a robust system, I'm also > not > > sure I agree, but a "sensible tutorial", that I could believe as I think > > it's actually quite difficult to explain these topics to people in a way > > they're going to understand right away. > > Could we perhaps bother you to suggest an alternative along with your > > criticism? It would feel a little more constructive at least (not that I > > think you were being terribly harsh) > > Dave > > _______________________________________________ > > 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/eb7dc0d8/attachment-0001.html From daniel.is.fischer at web.de Thu Aug 20 15:52:45 2009 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Thu Aug 20 15:33:43 2009 Subject: [Haskell-cafe] Re: Parsec lookahead and <|> Message-ID: <200908202152.46049.daniel.is.fischer@web.de> Apologies to Christian for the double post, didn't look at the To-field. Am Thursday 20 August 2009 20:21:30 schrieben Sie: > Daniel Fischer wrote: > > Am Donnerstag 20 August 2009 13:44:15 schrieb Martijn van Steenbergen: > >> Goedemiddag caf?, > >> > >> Consider the following function, using parsec-3.0.0: > >>> la :: Parsec String () (Maybe Char) > >>> la = lookAhead (optionMaybe anyChar) > >> > >> *Lookahead> parseTest (char 'a' <|> char 'b') "a" > >> 'a' > >> *Lookahead> parseTest (char 'a' <|> char 'b') "b" > >> 'b' > >> *Lookahead> parseTest (la *> char 'a' <|> char 'b') "a" > >> 'a' > >> *Lookahead> parseTest (la *> char 'a' <|> char 'b') "b" > >> parse error at (line 1, column 2): > >> unexpected "b" > >> expecting "a" > >> > >> The first three work fine and as expected, but the fourth example fails > >> where I would expect success. I know <|> won't try the rhs if the lhs > >> consumed input, but lookAhead's documentation promises not to consume > >> any input. Is this a bug in Parsec or am I missing something? > > > > Bad bug in Parsec (from the beginning, the same happens in parsec-2), I'd > > say. > > I'd say, its a feature. lookAhead returns whatever its argument returns. > So in this case it returns "Consumed" without consuming. In that case, the comment "lookAhead p parses p without consuming any input." from the parsec-3 docs is highly misleading. But lookAhead returning Consumed is not only counterintuitive, try parseTest (many la) "a" for a nice memory bomb. > > You can always wrap around a "try" to force the alternative: > > parseTest (try (la >> char 'a') <|> char 'b') "b" > > Cheers Christian > > Maybe it should have been: > > la >> (char 'a' <|> char 'b') > > in the first place. From westondan at imageworks.com Thu Aug 20 16:07:35 2009 From: westondan at imageworks.com (Dan Weston) Date: Thu Aug 20 15:47:41 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <4A8D1CC3.8080507@jellybean.co.uk> <3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com> Message-ID: <4A8DAD07.50501@imageworks.com> Peter, I think you are right that there is no way in general to prevent a valid graph rewrite to remove a vacuous dependency. That is why seq is there. The funny business is visible right in the type signature of seq: seq :: forall a t. a -> t -> t If seq had nonstrict semantics, this would be isomorphic to t -> t, which is inhabited only by id. So, if seq is going to have any useful effect, it must be strict. Since Haskell is nonstrict by default (absent some deconstruction, which requires knowledge of the value constructors), you need an extra-language primitive to do this. Don't look to "case" to do this. And other strictifying syntax constructs like ! are just syntactic sugar, so they don't count. Dan Peter Verswyvelen wrote: > I totally agree that data dependencies are the best way to do that. And > I'm beginning to see why interact might not be suitable for > demonstrating FRP. > > On the other hand, when you say data dependencies, you mean that the > value of expression A depends on the value of expression B, but what if > that value is not really needed? > > For example, suppose you want a program that asks the name of the user > and then outputs "What a nice name" or "What a weird name" depending on > some random value. Even though the input value from the user is not > used, we still can't output the text before the input is entered. Again > the hidden dependency is time itself I guess, so we should do it the > real FRP way, even with dumb console text IO. > > Also doesn't Haskell's IO system uses a hidden RealWorld type that has > no value but which is passed from between monadics binds in a strict way > to make the ordering work? So IO in Haskell is a horrible hack then? :-) > If it would be done nicely, in the FRP way, then RealWorld IO would need > time stamps to get rid of the hack? > > So to do console IO the FRP way (say like in Reactive), the input lines > from the user would be Event String, and the output also Event String. > Each event occurrence has a time stamp, and when merged, they would be > ordered. It would be nice to show this example in Reactive. Too bad > Reactive doesn't work (and it's not sure it ever will according to the > comment of some users), but for a simple example like this, I'm sure it > works. In Yampa, I'm not sure how console based IO would work, I guess > it would need to generate event non-occurrences (Nothing) when the user > did not type anything, and we would need non-blocking IO, so 100% CPU > load, since it's pull based, not sure, to be investigated. I haven't > worked with Elerea nor Grapefruit yet, but I'm not sure if I should > treat the former as a real FRP system since it is not referentially > transparent (it would be nice to know which combinators break it). > > On the other hand, in this simple example, I could use a strict field in > an ADT to enforce the input-output dependency, but I guess this is just > the same big hack? > (see http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8367) > > This silly example is causing lots of feedback, cool :-) > > On Thu, Aug 20, 2009 at 7:12 PM, Lennart Augustsson > > wrote: > > Using seq to control a program's semantics (as in, input-output > behaviour) is a horrible hack. > The seq operation there to control space and time aspects of your > program. > (The specification of seq doesn't even say that the first argument is > evaluated before the second one.) > You should use data dependencies to control your program's semantics. > > On Thu, Aug 20, 2009 at 4:34 PM, David Leimbach > wrote: > > > > > > On Thu, Aug 20, 2009 at 2:52 AM, Jules Bean > > wrote: > >> > >> Peter Verswyvelen wrote: > >>> > >>> Not at all, use it for whatever you want to :-) > >>> > >>> I'm writing this code because I'm preparing to write a bunch of > tutorials > >>> on FRP, and I first wanted to start with simple console based > FRP, e.g. > >>> making a little text adventure game, where the input/choices of > the user > >>> might be parsed ala parsec, using monadic style, applicative > style, and > >>> arrows, and then doing the same with FRP frameworks like > >> > >> > >> This is a really bad place to start a FRP tutorial IMO. > >> > >> The interface for 'interact' does not make any promises about > the relative > >> evaluation order of the input list / production order of the > output list. > >> > >> That's why you are having to play horrible tricks with seq to > try to force > >> the order to be what you want. > >> > >> I don't think this is the basis of a robust system or a sensible > tutorial. > >> > >> Just my 2c. > > > > Interesting feedback, but I don't get the reason really. How is > using seq a > > "horrible trick"? It's there for strict evaluation when you need > it, and in > > this case it was warranted. > > And as far as saying it's not a good basis for a robust system, > I'm also not > > sure I agree, but a "sensible tutorial", that I could believe as > I think > > it's actually quite difficult to explain these topics to people > in a way > > they're going to understand right away. > > Could we perhaps bother you to suggest an alternative along with your > > criticism? It would feel a little more constructive at least > (not that I > > think you were being terribly harsh) > > Dave > > _______________________________________________ > > 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 dave at zednenem.com Thu Aug 20 16:25:33 2009 From: dave at zednenem.com (David Menendez) Date: Thu Aug 20 16:05:33 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908190838h42864cd3s127c98371d366764@mail.gmail.com> <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <4A8D1CC3.8080507@jellybean.co.uk> <3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com> Message-ID: <49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> On Thu, Aug 20, 2009 at 3:43 PM, Peter Verswyvelen wrote: > > Also doesn't Haskell's IO system uses a hidden RealWorld type that has no > value but which is passed from between monadics binds in a strict way to > make the ordering work? Haskell only describes how the IO monad behaves. GHC's implementation uses a RealWorld type, but other implementations are possible. A quick sketch of an alternative implementation, data Trace = Done | Get (Char -> Trace) | Put Char Trace newtype IO a = IO { unIO :: (a -> Trace) -> Trace } instance Monad IO where return a = IO (\k -> k a) m >>= f = IO (\k -> unIO m (\a -> unIO (f a) k)) getChar :: IO Char getChar = IO Get putChar :: Char -> IO () putChar c = IO (\k -> Put c (k ())) The run-time system is responsible for interpreting the Trace and inputting/outputting characters as needed. All of IO can be implemented in this manner. > So IO in Haskell is a horrible hack then? :-) If it > would be done nicely, in the FRP way, then RealWorld IO would need time > stamps to get rid of the hack? Again, no. GHC's IO type uses the RealWorld value to create data dependencies. For example, putChar 'x' >> getChar, the getChar depends on the RealWorld returned by putChar 'x'. This is why it's dangerous to open up GHC's IO type unless you know what you're doing. If you aren't careful, you may accidentally duplicate or destroy the RealWorld, at which point you risk losing purity and referential transparency. I suppose you could consider the fact that GHC's IO is implemented using impure primitive operations a hack, but the whole point of the IO monad is to hide that impurity from the rest of the program. -- Dave Menendez From dons at galois.com Thu Aug 20 16:28:54 2009 From: dons at galois.com (Don Stewart) Date: Thu Aug 20 16:11:02 2009 Subject: [Haskell-cafe] Tips for deployment? In-Reply-To: References: Message-ID: <20090820202854.GG9507@whirlpool.galois.com> gue.schmidt: > Hi all, > > my haskell app is getting closer to shipping and what I need to do now is > to give product protection some thought. The product is for hospitals and > therefore a very limited set of clients. I do not expect anyone to try to > "hack" my application but I need a basic protection mechanism in place, > if only to check for a valid license key. Congratulations! > As I've never done this before I'd be grateful for some suggestions here. Some versions of Cryptol have private key signing / license checking component, built into the application, which checks the software was properly licensed. Essentially: grab some public key crypto, sign it with your company's key, and check the signature on startup. -- Don From bugfact at gmail.com Thu Aug 20 16:41:35 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Thu Aug 20 16:21:35 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> References: <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <4A8D1CC3.8080507@jellybean.co.uk> <3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com> <49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> Message-ID: But how does GHC implement the RealWorld internally? I guess this can't be done using standard Haskell stuff? It feels to me that if I would implement it, I would need seq again, or a strict field, or some incrementing "time" value that is a strict argument of each of the IO primitives. In any case, I would need strictness to control the dependencies no? I might be wrong (again) but this is all very interesting ;-) On Thu, Aug 20, 2009 at 10:25 PM, David Menendez wrote: > On Thu, Aug 20, 2009 at 3:43 PM, Peter Verswyvelen > wrote: > > > > Also doesn't Haskell's IO system uses a hidden RealWorld type that has no > > value but which is passed from between monadics binds in a strict way to > > make the ordering work? > > Haskell only describes how the IO monad behaves. GHC's implementation > uses a RealWorld type, but other implementations are possible. > > A quick sketch of an alternative implementation, > > data Trace = Done | Get (Char -> Trace) | Put Char Trace > > newtype IO a = IO { unIO :: (a -> Trace) -> Trace } > > instance Monad IO where > return a = IO (\k -> k a) > m >>= f = IO (\k -> unIO m (\a -> unIO (f a) k)) > > getChar :: IO Char > getChar = IO Get > > putChar :: Char -> IO () > putChar c = IO (\k -> Put c (k ())) > > The run-time system is responsible for interpreting the Trace and > inputting/outputting characters as needed. All of IO can be > implemented in this manner. > > > So IO in Haskell is a horrible hack then? :-) If it > > would be done nicely, in the FRP way, then RealWorld IO would need time > > stamps to get rid of the hack? > > Again, no. GHC's IO type uses the RealWorld value to create data > dependencies. For example, putChar 'x' >> getChar, the getChar depends > on the RealWorld returned by putChar 'x'. > > This is why it's dangerous to open up GHC's IO type unless you know > what you're doing. If you aren't careful, you may accidentally > duplicate or destroy the RealWorld, at which point you risk losing > purity and referential transparency. > > I suppose you could consider the fact that GHC's IO is implemented > using impure primitive operations a hack, but the whole point of the > IO monad is to hide that impurity from the rest of the program. > > -- > Dave Menendez > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/bc16498a/attachment.html From dave at zednenem.com Thu Aug 20 17:23:04 2009 From: dave at zednenem.com (David Menendez) Date: Thu Aug 20 17:03:03 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <4A8D1CC3.8080507@jellybean.co.uk> <3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com> <49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> Message-ID: <49a77b7a0908201423v178fc46kd2b2c715d017c765@mail.gmail.com> On Thu, Aug 20, 2009 at 4:41 PM, Peter Verswyvelen wrote: > But how does GHC implement the RealWorld internally? I guess this can't be > done using standard Haskell stuff? It feels to me that if I would implement > it, I would need seq again, or a strict field, or some incrementing "time" > value that is a strict argument of each of the IO primitives. In any case, I > would need strictness to control the dependencies no? I might be wrong > (again) but this is all very interesting ;-) The RealWorld is just a token that GHC uses to force IO computations to have the correct data dependencies. If you look at code like "putChar 'x' >> getChar", there's no obvious data dependency that would prevent executing getChar before putChar, so internally the IO monad passes around the RealWorld token to guarantee the ordering. I don't know the exact details of GHC's IO internals, but I'd expect putChar 'x' >> getChar to translate into something like this, \rw0 -> let ((), rw1) = putChar# 'x' rw0 in getChar# rw1 The important things to note are (1) getChar# depends on the token returned by putChar#, thus guaranteeing that putChar# gets executed first, and (2) putChar# and getChar# are impure and cannot normally be defined in Haskell. -- Dave Menendez From bugfact at gmail.com Thu Aug 20 18:57:48 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Thu Aug 20 18:37:48 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <49a77b7a0908201423v178fc46kd2b2c715d017c765@mail.gmail.com> References: <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <4A8D1CC3.8080507@jellybean.co.uk> <3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com> <49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> <49a77b7a0908201423v178fc46kd2b2c715d017c765@mail.gmail.com> Message-ID: On Thu, Aug 20, 2009 at 11:23 PM, David Menendez wrote: > The important things to note are (1) getChar# depends on the token > returned by putChar#, thus guaranteeing that putChar# gets executed > first, and (2) putChar# and getChar# are impure and cannot normally be > defined in Haskell. > Ok, that I understand. But if getChar# and putChar# would be pure functions that just generate some output string / consume some input string, then this realworld token passing would not work when used with interact, since neither the output or input string really depends on the dummy token, unless using a seq again (or strictness annotation, which was explained to be just syntactic sugar for seq)? But how would we then make a pure monad that can be used as in my example together with interact? I see no reason why to put everything in IO when it just comes to converting a stream of inputs to a stream of outputs? So interact really is useless, unless you just fmap something over the input or when the output is independent from the input? As Ryan said, I could use his MonadPrompt for this, but that's a different approach (and maybe the only correct one) I'm still curious to see how an FRP solution would look for simple console based IO though :-) Probably a good exercise to do. > > -- > Dave Menendez > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090820/2e536b33/attachment.html From dave at zednenem.com Thu Aug 20 23:03:10 2009 From: dave at zednenem.com (David Menendez) Date: Thu Aug 20 22:43:09 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <4A8D1CC3.8080507@jellybean.co.uk> <3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com> <49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> <49a77b7a0908201423v178fc46kd2b2c715d017c765@mail.gmail.com> Message-ID: <49a77b7a0908202003x1b69f91dxa69fb649d3c4aa82@mail.gmail.com> On Thu, Aug 20, 2009 at 6:57 PM, Peter Verswyvelen wrote: > > On Thu, Aug 20, 2009 at 11:23 PM, David Menendez wrote: >> >> The important things to note are (1) getChar# depends on the token >> returned by putChar#, thus guaranteeing that putChar# gets executed >> first, and (2) putChar# and getChar# are impure and cannot normally be >> defined in Haskell. > > Ok, that I understand. But if getChar# and putChar# would be pure functions > that just generate some output string / consume some input string, then this > realworld token passing would not work when used with interact, since > neither the output or input string really depends on the dummy token, unless > using a seq again (or strictness annotation, which was explained to be just > syntactic sugar for seq)? I'm not sure I understand your question, but I think it's possible to use interact in the way you want. For example, this code behaves correctly for me: foo i = let i1 = lines i in "Enter your name: " ++ (case i1 of [] -> error "EOF" name:i2 -> "Welcome " ++ name ++ "\n") Prelude> interact foo Enter your name: Bob Welcome Bob Note the dependencies here. When you call interact foo, the prompt can be immediately output without reading any of the input. However, "Welcome" cannot be printed until one line of the input has been read (or EOF reached) because it's inside the pattern match on i1. > But how would we then make a pure monad that can > be used as in my example together with interact? I see no reason why to put > everything in IO when it just comes to converting a stream of inputs to a > stream of outputs? So interact really is useless, unless you just fmap > something over the input or when the output is independent from the input? Not necessarily. Your situation reminds me of Haskell's I/O system before the IO monad was introduced. (See section 7 of "A History of Haskell: Being Lazy With Class" for details. ) In it, they describe how older versions of Haskell could be defined in terms of lazy request and response streams, how you can use continuation-passing to build the streams in a more localized way, and then how you could define the IO monad in terms of that. This works for me: import Control.Monad.Cont type Behavior = [String] -> String type MyIO = Cont Behavior putLine :: String -> MyIO () putLine s = Cont $ \k ss -> s ++ k () ss getLine :: MyIO String getLine = Cont $ \k (s:ss) -> k s ss run :: MyIO () -> Behavior run m = runCont m (\_ _ -> []) foo = do putLine "Enter name: " name <- getLine putLine ("Welcome " ++ name ++ "\n") Prelude Control.Monad.Cont> interact (run foo . lines) Enter name: Dave Welcome Dave It may be instructive to manually expand "run foo". -- Dave Menendez From bulat.ziganshin at gmail.com Fri Aug 21 01:20:49 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Aug 21 01:00:56 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com> <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <4A8D1CC3.8080507@jellybean.co.uk> <3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com> <49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> Message-ID: <1371197032.20090821092049@gmail.com> Hello Peter, Friday, August 21, 2009, 12:41:35 AM, you wrote: > But how does GHC implement the RealWorld internally? I guess look the "base" library sources for "RealWorld" -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From jpm at cs.uu.nl Fri Aug 21 03:07:00 2009 From: jpm at cs.uu.nl (=?ISO-8859-1?Q?Jos=E9_Pedro_Magalh=E3es?=) Date: Fri Aug 21 02:47:19 2009 Subject: [Haskell-cafe] Generics for constructing Rows In-Reply-To: <87ocqar0wf.fsf@zagan.made.you> References: <87r5v6izrc.fsf@zagan.made.you> <3c6288ab0908200443w18110f45h8edc7353091100f2@mail.gmail.com> <87ocqar0wf.fsf@zagan.made.you> Message-ID: <52f14b210908210007u675bac08n3eadf5461be6a838@mail.gmail.com> Hello, On Thu, Aug 20, 2009 at 16:54, Max Desyatov wrote: > Sean Leather writes: > > > I'm not sure the problem you're running into is strictly a generic > > programming (GP) one. Typically, GP takes code that is often written > > and generalizes it, so that it doesn't have to be written for multiple > > datatypes. > > That seems to be GP problem, as your solution doesn't scale well when I > wan't to add/remove/change fields in the `Row` record. The perfect way > as I see it, would be just editing `Row` data declaration, nothing else. > Studying few papers about GP in Haskell, I reckon this could be > represented as generic traversal, using my `Row` declaration with > `Either`. I don't see really good way to write a generic producer from > `[String]` to version of `Row` without `Either`. But SYB doesn't > provide a way for passing type-class-parametric functions to gmapT, and > SYB-with-class has large overhead of its usage. I don't have enough > time to find out how this can be written in SYB-with-class, if it really > can be > written. The restriction of EMGM was described in my initial message. Indeed SYB doesn't work here because Typeable-based run-time type comparison only works for monomorphic types. Doing something like readRow l = gmapT (mkT (\(Left (Just ri) :: E Name) -> Right $ l `atMay` ri > >>= readMay)) > would work, but this, of course, is not what you want. I'm guessing the polymorphic typeOf previously described by Oleg [1] could help here, were it integrated in SYB. I don't think syb-with-class will help you here, since it only adds modularity to the type-based function extension. I think you would still have to write a case for every field in the Row record. Multirec would possibly work, were it not for the fact that it doesn't support parametric datatypes yet... Cheers, Pedro [1] http://osdir.com/ml/haskell-cafe@haskell.org/2009-03/msg00212.html -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090821/47903166/attachment.html From colin at colina.demon.co.uk Fri Aug 21 04:28:23 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Fri Aug 21 04:09:00 2009 Subject: [Haskell-cafe] Where does documentation get installed with cabal? In-Reply-To: <694519c50908201209r1e2cc266q9ea4b34588f93663@mail.gmail.com> (Antoine Latter's message of "Thu\, 20 Aug 2009 14\:09\:13 -0500") References: <694519c50908201209r1e2cc266q9ea4b34588f93663@mail.gmail.com> Message-ID: >>>>> "Antoine" == Antoine Latter writes: Antoine> On Thu, Aug 20, 2009 at 8:58 AM, Colin Paul Antoine> Adams wrote: >> Hello, >> >> I'm trying to find the API documentation for happstack 0.3 >> (online is for 0.2). >> >> So I did: >> >> cabal install happstack --reinstall --enable-documentation >> >> but I can't find it anywhere within ~/.cabal - where should I >> look? Antoine> Most of hasppstack functionality is not in the Antoine> "happstack" package, it's in the happstack-* packages. So Antoine> installing the happstack package with documentation won't Antoine> really pull in much documentation at all. Thanks. That was what I was missing. -- Colin Adams Preston Lancashire From bugfact at gmail.com Fri Aug 21 04:37:55 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Fri Aug 21 04:17:55 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <49a77b7a0908202003x1b69f91dxa69fb649d3c4aa82@mail.gmail.com> References: <4A8D1CC3.8080507@jellybean.co.uk> <3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com> <49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> <49a77b7a0908201423v178fc46kd2b2c715d017c765@mail.gmail.com> <49a77b7a0908202003x1b69f91dxa69fb649d3c4aa82@mail.gmail.com> Message-ID: On Fri, Aug 21, 2009 at 5:03 AM, David Menendez wrote: > On Thu, Aug 20, 2009 at 6:57 PM, Peter Verswyvelen > wrote: > > > > On Thu, Aug 20, 2009 at 11:23 PM, David Menendez > wrote: > >> > >> The important things to note are (1) getChar# depends on the token > >> returned by putChar#, thus guaranteeing that putChar# gets executed > >> first, and (2) putChar# and getChar# are impure and cannot normally be > >> defined in Haskell. > > > > Ok, that I understand. But if getChar# and putChar# would be pure > functions > > that just generate some output string / consume some input string, then > this > > realworld token passing would not work when used with interact, since > > neither the output or input string really depends on the dummy token, > unless > > using a seq again (or strictness annotation, which was explained to be > just > > syntactic sugar for seq)? > > I'm not sure I understand your question, but I think it's possible to > use interact in the way you want. For example, this code behaves > correctly for me: > > foo i = > let i1 = lines i > in "Enter your name: " ++ > (case i1 of > [] -> error "EOF" > name:i2 -> "Welcome " ++ name ++ "\n") > > Prelude> interact foo > Enter your name: Bob > Welcome Bob Yes but this also enforce strictness, since you're pattern matching against the input, forcing it to be evaluated. If for example the empty string would be valid input, this wouldn't work, and seq would be needed again no? > Note the dependencies here. When you call interact foo, the prompt can > be immediately output without reading any of the input. However, > "Welcome" cannot be printed until one line of the input has been read > (or EOF reached) because it's inside the pattern match on i1. > > > > But how would we then make a pure monad that can > > be used as in my example together with interact? I see no reason why to > put > > everything in IO when it just comes to converting a stream of inputs to a > > stream of outputs? So interact really is useless, unless you just fmap > > something over the input or when the output is independent from the > input? > > Not necessarily. Your situation reminds me of Haskell's I/O system > before the IO monad was introduced. (See section 7 of "A History of > Haskell: Being Lazy With Class" for details. > < > http://research.microsoft.com/en-us/um/people/simonpj/papers/history-of-haskell/history.pdf > >) > > In it, they describe how older versions of Haskell could be defined in > terms of lazy request and response streams, how you can use > continuation-passing to build the streams in a more localized way, and > then how you could define the IO monad in terms of that. > > This works for me: > > import Control.Monad.Cont > > type Behavior = [String] -> String > type MyIO = Cont Behavior > > putLine :: String -> MyIO () > putLine s = Cont $ \k ss -> s ++ k () ss > > getLine :: MyIO String > getLine = Cont $ \k (s:ss) -> k s ss > > run :: MyIO () -> Behavior > run m = runCont m (\_ _ -> []) > > foo = do > putLine "Enter name: " > name <- getLine > putLine ("Welcome " ++ name ++ "\n") > > Prelude Control.Monad.Cont> interact (run foo . lines) > Enter name: Dave > Welcome Dave > > It may be instructive to manually expand "run foo". This suffers from the same strictness problem on the input, e.g. when making getLine less strict, as in: import Prelude hiding (getLine) import Control.Monad.Cont type Behavior = [String] -> String type MyIO = Cont Behavior putLine :: String -> MyIO () putLine s = Cont $ \k ss -> s ++ k () ss getLine :: MyIO String -- Was: getLine = Cont $ \k *(s:ss) -> k s ss* *getLine = Cont $ \k ss -> k (head ss) (tail ss)* run :: MyIO () -> Behavior run m = runCont m (\_ _ -> []) foo = do putLine "Enter name: " name <- getLine putLine ("Welcome " ++ name ++ "\n") main = interact (run foo . lines) You get the "Welcome" before the name again. To be honest I don't fully understand why this is a horrible hack. From a pure point of view, the behavior is the same, weither or not the input is made strict. When side effects are present (interactive input/output from the user), it does matter, but aren't all space/time leaks to be considered as some sort of "operational effects"? In a pure mathematical world, space and time leaks would not really matter? I do understand much more now, thanks. The best solution for making this IO pure remains MonadPrompt I guess. Too bad that something extremely simple like console text IO doesn't seem to be a good start for introducing FRP, or maybe seen from another angle (using Reactive) it might still be, dono > > -- > Dave Menendez > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090821/90204822/attachment.html From Alistair.Bayley at invesco.com Fri Aug 21 04:52:58 2009 From: Alistair.Bayley at invesco.com (Bayley, Alistair) Date: Fri Aug 21 04:32:58 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <1371197032.20090821092049@gmail.com> References: <3e1162e60908190839j19682355u5a5bb21da341a434@mail.gmail.com><3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com><4A8D1CC3.8080507@jellybean.co.uk><3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com><49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> <1371197032.20090821092049@gmail.com> Message-ID: <125EACD0CAE4D24ABDB4D148C4593DA91102621C@GBLONXMB02.corp.amvescap.net> > From: haskell-cafe-bounces@haskell.org > [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Bulat Ziganshin > To: Peter Verswyvelen > > > But how does GHC implement the RealWorld internally? I guess > > look the "base" library sources for "RealWorld" http://www.haskell.org/ghc/docs/latest/html/libraries/base/src/GHC-IOBas e.html#IO ***************************************************************** 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 bugfact at gmail.com Fri Aug 21 05:04:19 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Fri Aug 21 04:44:19 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <125EACD0CAE4D24ABDB4D148C4593DA91102621C@GBLONXMB02.corp.amvescap.net> References: <4A8D1CC3.8080507@jellybean.co.uk> <3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com> <49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> <1371197032.20090821092049@gmail.com> <125EACD0CAE4D24ABDB4D148C4593DA91102621C@GBLONXMB02.corp.amvescap.net> Message-ID: IO also seems to use unboxed (hence strict?) tuples newtype IO a = IO (State# RealWorld -> (# State# RealWorld, a #)) Not sure if this is just for performance, but if the strictness is required, here we have the horrible hack again then (would behave different without it?). I guess it works because when applying primitive function likes putChar#, these could be considered as fully strict, since putChar# c really does force evaluation of c strictly and puts in the screen. This is different from the lazy IO situation, where a string is concatenated lazily, and put on the screen by the consumer as soon as it's available. Ah I'm having troubles to explain myself formally, never mind :) Actually RealWorld is not defined in that file, it is defined here, but hidden file:///C:/app/ghp/doc/libraries/ghc-prim/GHC-Prim.html#t%3ARealWorld But I don't understand the comment data *RealWorld*Source RealWorld is deeply magical. It is *primitive*, but it is not *unlifted* (hence ptrArg). We never manipulate values of type RealWorld; it's only used in the type system, to parameterise State#. Maybe I should reread the papers, but it seems lots of magic is needed to get IO right (such as the existential types to make sure different state threads are kept separate) On Fri, Aug 21, 2009 at 10:52 AM, Bayley, Alistair < Alistair.Bayley@invesco.com> wrote: > > From: haskell-cafe-bounces@haskell.org > > [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Bulat Ziganshin > > To: Peter Verswyvelen > > > > > But how does GHC implement the RealWorld internally? I guess > > > > look the "base" library sources for "RealWorld" > > http://www.haskell.org/ghc/docs/latest/html/libraries/base/src/GHC-IOBas > e.html#IO > ***************************************************************** > 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. > ***************************************************************** > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090821/1f761220/attachment.html From lennart at augustsson.net Fri Aug 21 06:01:50 2009 From: lennart at augustsson.net (Lennart Augustsson) Date: Fri Aug 21 05:41:49 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908190843yfecdbe7geba8988e8ad5d18@mail.gmail.com> <4A8D1CC3.8080507@jellybean.co.uk> <3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com> <49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> Message-ID: Internally GHC does have to enforce the ordering on IO operations somehow. If there actually was a RealWorld value being passed around you could use some version of seq the guarantees sequential evaluation. But GHC doesn't even pass a RealWorld around, the sequencing is enforced by different means. It's uninteresting for this discussion how GHC enforces the sequencing internally, the important part is that it is part the sequencing is part of the IO monad semantics and this is what should be used to guarantee the sequencing of IO operations in a program. -- Lennart On Thu, Aug 20, 2009 at 10:41 PM, Peter Verswyvelen wrote: > But how does GHC implement the RealWorld internally? I guess this can't be > done using standard Haskell stuff? It feels to me that if I would implement > it, I would need seq again, or a strict field, or some incrementing "time" > value that is a strict argument of each of the IO primitives. In any case, I > would need strictness to control the dependencies no? I might be wrong > (again) but this is all very interesting ;-) > > On Thu, Aug 20, 2009 at 10:25 PM, David Menendez wrote: >> >> On Thu, Aug 20, 2009 at 3:43 PM, Peter Verswyvelen >> wrote: >> > >> > Also doesn't Haskell's IO system uses a hidden RealWorld type that has >> > no >> > value but which is passed from between monadics binds in a strict way to >> > make the ordering work? >> >> Haskell only describes how the IO monad behaves. GHC's implementation >> uses a RealWorld type, but other implementations are possible. >> >> A quick sketch of an alternative implementation, >> >> data Trace = Done | Get (Char -> Trace) | Put Char Trace >> >> newtype IO a = IO { unIO :: (a -> Trace) -> Trace } >> >> instance Monad IO where >> ? ?return a = IO (\k -> k a) >> ? ?m >>= f = IO (\k -> unIO m (\a -> unIO (f a) k)) >> >> getChar :: IO Char >> getChar = IO Get >> >> putChar :: Char -> IO () >> putChar c = IO (\k -> Put c (k ())) >> >> The run-time system is responsible for interpreting the Trace and >> inputting/outputting characters as needed. All of IO can be >> implemented in this manner. >> >> > So IO in Haskell is a horrible hack then? :-) If it >> > would be done nicely, in the FRP way, then RealWorld IO would need time >> > stamps to get rid of the hack? >> >> Again, no. GHC's IO type uses the RealWorld value to create data >> dependencies. For example, putChar 'x' >> getChar, the getChar depends >> on the RealWorld returned by putChar 'x'. >> >> This is why it's dangerous to open up GHC's IO type unless you know >> what you're doing. If you aren't careful, you may accidentally >> duplicate or destroy the RealWorld, at which point you risk losing >> purity and referential transparency. >> >> I suppose you could consider the fact that GHC's IO is implemented >> using impure primitive operations a hack, but the whole point of the >> IO monad is to hide that impurity from the rest of the program. >> >> -- >> Dave Menendez >> > > From lennart at augustsson.net Fri Aug 21 06:04:06 2009 From: lennart at augustsson.net (Lennart Augustsson) Date: Fri Aug 21 05:44:05 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <4A8D1CC3.8080507@jellybean.co.uk> <3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com> <49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> <1371197032.20090821092049@gmail.com> <125EACD0CAE4D24ABDB4D148C4593DA91102621C@GBLONXMB02.corp.amvescap.net> Message-ID: You need a lot of magic to make the IO monad efficient. You don't really want to pass around (and pattern match on) a RealWorld token, that would be inefficient. On Fri, Aug 21, 2009 at 11:04 AM, Peter Verswyvelen wrote: > IO also seems to use unboxed (hence strict?) tuples > > newtype IO a = IO (State# RealWorld -> (# State# RealWorld, a #)) > > Not sure if this is just for performance, but if the strictness is required, > here we have the horrible hack again then (would behave different without > it?). I guess it works because when applying primitive function likes > putChar#, these could be considered as fully strict, since putChar# c really > does force evaluation of c strictly and puts in the screen. This is > different from the lazy IO situation, where a string is concatenated lazily, > and put on the screen by the consumer as soon as it's available. Ah I'm > having troubles to explain myself formally, never mind :) > Actually RealWorld is not defined in that file, it is defined here, but > hidden > file:///C:/app/ghp/doc/libraries/ghc-prim/GHC-Prim.html#t%3ARealWorld > But I don't understand the comment > data?RealWorld Source > RealWorld?is deeply magical. It is?primitive, but it is > not?unlifted?(hence?ptrArg). We never manipulate values of type?RealWorld; > it's only used in the type system, to parameterise?State#. > Maybe I should reread the papers, but it seems lots of magic is needed to > get IO right (such as the existential types to make sure?different state > threads are kept separate) > On Fri, Aug 21, 2009 at 10:52 AM, Bayley, Alistair > wrote: >> >> > From: haskell-cafe-bounces@haskell.org >> > [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Bulat Ziganshin >> > To: Peter Verswyvelen >> > >> > > But how does GHC implement the RealWorld internally? I guess >> > >> > look the "base" library sources for "RealWorld" >> >> http://www.haskell.org/ghc/docs/latest/html/libraries/base/src/GHC-IOBas >> e.html#IO >> ***************************************************************** >> 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 simonpj at microsoft.com Fri Aug 21 06:11:46 2009 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Fri Aug 21 05:51:46 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <4A8D1CC3.8080507@jellybean.co.uk> <3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com> <49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> <1371197032.20090821092049@gmail.com> <125EACD0CAE4D24ABDB4D148C4593DA91102621C@GBLONXMB02.corp.amvescap.net> Message-ID: <638ABD0A29C8884A91BC5FB5C349B1C35CE7101BEB@EA-EXMSG-C334.europe.corp.microsoft.com> Actually GHC *does* pass around a RealWorld token right through the optimiser. Just at the moment of code generation we drop it, so that it's not *actually* passed. But for almost all of compilation it's just as if it *was*. Simon | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On | Behalf Of Lennart Augustsson | Sent: 21 August 2009 11:04 | To: Peter Verswyvelen | Cc: Bayley, Alistair; The Haskell Cafe | Subject: Re: Re[2]: [Haskell-cafe] Re: Where do I put the seq? | | You need a lot of magic to make the IO monad efficient. | You don't really want to pass around (and pattern match on) a | RealWorld token, that would be inefficient. | | | On Fri, Aug 21, 2009 at 11:04 AM, Peter Verswyvelen wrote: | > IO also seems to use unboxed (hence strict?) tuples | > | > newtype IO a = IO (State# RealWorld -> (# State# RealWorld, a #)) | > | > Not sure if this is just for performance, but if the strictness is required, | > here we have the horrible hack again then (would behave different without | > it?). I guess it works because when applying primitive function likes | > putChar#, these could be considered as fully strict, since putChar# c really | > does force evaluation of c strictly and puts in the screen. This is | > different from the lazy IO situation, where a string is concatenated lazily, | > and put on the screen by the consumer as soon as it's available. Ah I'm | > having troubles to explain myself formally, never mind :) | > Actually RealWorld is not defined in that file, it is defined here, but | > hidden | > file:///C:/app/ghp/doc/libraries/ghc-prim/GHC-Prim.html#t%3ARealWorld | > But I don't understand the comment | > data?RealWorld Source | > RealWorld?is deeply magical. It is?primitive, but it is | > not?unlifted?(hence?ptrArg). We never manipulate values of type?RealWorld; | > it's only used in the type system, to parameterise?State#. | > Maybe I should reread the papers, but it seems lots of magic is needed to | > get IO right (such as the existential types to make sure?different state | > threads are kept separate) | > On Fri, Aug 21, 2009 at 10:52 AM, Bayley, Alistair | > wrote: | >> | >> > From: haskell-cafe-bounces@haskell.org | >> > [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Bulat Ziganshin | >> > To: Peter Verswyvelen | >> > | >> > > But how does GHC implement the RealWorld internally? I guess | >> > | >> > look the "base" library sources for "RealWorld" | >> | >> http://www.haskell.org/ghc/docs/latest/html/libraries/base/src/GHC-IOBas | >> e.html#IO | >> ***************************************************************** | >> 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 | > | > | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe From apfelmus at quantentunnel.de Fri Aug 21 07:26:19 2009 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Fri Aug 21 07:07:22 2009 Subject: [Haskell-cafe] Re: Keeping an indexed collection of values? In-Reply-To: References: Message-ID: Heinrich Apfelmus wrote: > Job Vranish wrote: >> I've been in a situation a lot lately where I need to keep a collection of >> values, and keep track of them by a persistent index. >> > > module Store (Key, Store, empty, add, delete, lookup) where > > newtype Key = Key { int :: Int } > > empty :: Store a > add :: a -> Store a -> (Key, Store a) > delete :: Key -> Store a -> Store a > lookup :: Key -> Store a -> Maybe a > > This way, the user doesn't know and care how Key is implemented. > > Last but not least, there is the issue that trying to use an already > deleted key might yield a wrong result instead of an error. That > shouldn't happen if used correctly, but might give a headache when > debugging. There is even a very simple way to prevent at least some cases of misuse, when one key is accidentally used on stores of different type. A phantom parameter will do the trick: newtype Key a = Key { int :: Int } add :: a -> Store a -> (Key a , Store a) delete :: Key a -> Store a -> Store a lookup :: Key a -> Store a -> Maybe a Regards, apfelmus -- http://apfelmus.nfshost.com From v.dijk.bas at gmail.com Fri Aug 21 07:41:26 2009 From: v.dijk.bas at gmail.com (Bas van Dijk) Date: Fri Aug 21 07:21:25 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? Message-ID: Hello, We're working on a Haskell binding to levmar[1] a C implementation of the Levenberg-Marquardt optimization algorithm. The Levenberg-Marquardt algorithm is an iterative technique that finds a local minimum of a function that is expressed as the sum of squares of nonlinear functions. It has become a standard technique for nonlinear least-squares problems. It's for example ideal for curve fitting. The binding is nearly finished and consists of two layers: a low-level layer that directly exports the C bindings and a medium-level layer that wraps the lower-level functions and provides a more Haskell friendly interface. The Medium-Level (ML) layer has a function which is similar to: > levmarML :: (a -> [Double] -> Double) > -> [Double] > -> [(a, Double)] > -> [Double] > levmarML model initParams samples = ... So you give it a model function, an initial guess of the parameters and some input samples. levmarML than tries to find the parameters that best describe the input samples. Of course, the real function has more arguments and return values but this simple version will do for this discussion. Al-dough this medium-level layer is more Haskell friendly than the low-level layer it still has some issues. For example a model function is represented as a function that takes a list of parameters. For example: > \x [p1, p2, p3] -> p1*x^2 + p2*x + p3 You have to ensure that the length of the initial guess of parameters is exactly 3. Otherwise you get run-time pattern-match failures. So I would like to create a new High-Level (HL) layer that overcomes this problem. First of all I need the following language extensions: > {-# LANGUAGE EmptyDataDecls #-} > {-# LANGUAGE UndecidableInstances #-} > {-# LANGUAGE TypeFamilies #-} > {-# LANGUAGE GADTs #-} I want to represent the model function as a normal Haskell function. So instead of passing the parameters as a list I want to pass them as arguments: > \x p1 p2 p3 -> p1*x^2 + p2*x + p3 Because we would like to be able to use model functions of different arity it means the levmarHL function needs to be polymorphic in the model function: > levmarHL :: (ModelFunc f, Arity f ~ n, Arg f ~ Double) > => (a -> f) > -> Vector Double n > -> [(a, Double)] > -> Vector Double n > levmarHL model initParams samples = > fromList $ levmarML (\x params -> model x $* fromList params) > (toList initParams) > samples You can see that the initial parameters and the result are passed as Vectors that encode their length 'n' in their type. This length must equal the arity of the model function: 'Arity f ~ n'. The arity of the model function and the length of the vectors are represented as type level naturals: > data Z > data S n Lets look at the implementation of ModelFunc: > class ModelFunc f where > type Arg f :: * > type Arity f :: * > > ($*) :: f -> Vector (Arg f) (Arity f) -> Arg f $* is similar to $ but instead of applying a function to a single argument it applies it to a vector of multiple arguments. > instance (ModelFunc f, Arg f ~ b) => ModelFunc (b -> f) where > type Arg (b -> f) = b > type Arity (b -> f) = S (Arity f) > > f $* (x :*: xs) = f x $* xs You can see that we restrict the arguments of module functions to have the same type: 'Arg f ~ b'. This is the base case: > instance ModelFunc Double where > type Arg Double = Double > type Arity Double = Z > > d $* Nil = d We represent Vectors using a GADT: > data Vector a n where > Nil :: Vector a Z > (:*:) :: a -> Vector a n -> Vector a (S n) > infixr :*: Converting a Vector to a list is easy: > toList :: Vector b n -> [b] > toList Nil = [] > toList (x :*: xs) = x : toList xs My single question is: how can I convert a list to a Vector??? > fromList :: [b] -> Vector b n > fromList = ? regards, Roel and Bas van Dijk [1] http://www.ics.forth.gr/~lourakis/levmar/ From Christian.Maeder at dfki.de Fri Aug 21 07:51:42 2009 From: Christian.Maeder at dfki.de (Christian Maeder) Date: Fri Aug 21 07:31:41 2009 Subject: [Haskell-cafe] Re: Parsec lookahead and <|> In-Reply-To: <200908202152.46049.daniel.is.fischer@web.de> References: <200908202152.46049.daniel.is.fischer@web.de> Message-ID: <4A8E8A4E.6070001@dfki.de> Daniel Fischer wrote: >>> Bad bug in Parsec (from the beginning, the same happens in parsec-2), I'd >>> say. >> I'd say, its a feature. lookAhead returns whatever its argument returns. >> So in this case it returns "Consumed" without consuming. > > In that case, the comment > > "lookAhead p parses p without consuming any input." > > from the parsec-3 docs is highly misleading. Yes, it isn't even documented in http://legacy.cs.uu.nl/daan/parsec.html I'ld say not consuming something after a successful lookAhead is an error (and if the argument of lookAhead consumes nothing, that is also odd.) In most cases "try" is the better alternative, where the result of try should be used as input for the following parser: (try identifierStart >>= indentifierRest) <|> constant > But lookAhead returning Consumed is not only counterintuitive, try > > parseTest (many la) "a" > > for a nice memory bomb. It's as dangerous as using "setInput" and making the input longer (for recursive calls). But I don't see any disadvantages if "lookAhead" would return "Empty (Ok ...)", so I'ld also propose to change it (as you did). Cheers Christian From miguelimo38 at yandex.ru Fri Aug 21 08:02:34 2009 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Fri Aug 21 07:44:08 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: References: Message-ID: <4A8E8CDA.7080401@yandex.ru> >> {-# LANGUAGE UndecidableInstances #-} Ouch! Don't worry, it's just me not liking UndecidableInstances. > So instead of passing the parameters as a list I want to pass them as > arguments: > >> \x p1 p2 p3 -> p1*x^2 + p2*x + p3 Why not use tuples? \x (p1, p2, p3) -> p1 * x^2 + p2 * x + p3 Or a special list-like data type data a :* b = ($*) a b func :: Double -> (Double :* Double :* Double) -> Double func x (p1 $* p2 $* p3) = p1 * x^2 + p2 * x + p3 From martijn at van.steenbergen.nl Fri Aug 21 08:40:25 2009 From: martijn at van.steenbergen.nl (Martijn van Steenbergen) Date: Fri Aug 21 08:20:35 2009 Subject: [Haskell-cafe] Re: Parsec lookahead and <|> In-Reply-To: References: <4A8D370F.5000401@van.steenbergen.nl> <200908201804.02394.daniel.is.fischer@web.de> <4A8D942A.7060206@dfki.de> Message-ID: <4A8E95B9.8030907@van.steenbergen.nl> Thanks for your replies. Job Vranish wrote: > Martijn, how did you encounter this problem? My list of input symbols contains some extra information and I was using lookahead to query for that information before doing the actual parsing. I was using it in various places, including a list of choices separated by <|>. I was assuming it wouldn't affect the choice but it turned out that Parsec was always going for the first one because I used a lookahead (see la) that always succeeds. Martijn. From derek.a.elkins at gmail.com Fri Aug 21 09:14:07 2009 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Fri Aug 21 08:54:48 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com> <49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> <1371197032.20090821092049@gmail.com> <125EACD0CAE4D24ABDB4D148C4593DA91102621C@GBLONXMB02.corp.amvescap.net> Message-ID: <61f84eff0908210614s7009e7cbu3d6997c4966e43f@mail.gmail.com> On Fri, Aug 21, 2009 at 5:04 AM, Lennart Augustsson wrote: >> On Fri, Aug 21, 2009 at 10:52 AM, Bayley, Alistair >> wrote: >>> >>> > From: haskell-cafe-bounces@haskell.org >>> > [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Bulat Ziganshin >>> > To: Peter Verswyvelen >>> > >>> > > But how does GHC implement the RealWorld internally? I guess >>> > >>> > look the "base" library sources for "RealWorld" >>> >>> http://www.haskell.org/ghc/docs/latest/html/libraries/base/src/GHC-IOBas >>> e.html#IO >>> > On Fri, Aug 21, 2009 at 11:04 AM, Peter Verswyvelen wrote: >> IO also seems to use unboxed (hence strict?) tuples >> >> newtype IO a = IO (State# RealWorld -> (# State# RealWorld, a #)) >> >> Not sure if this is just for performance, but if the strictness is required, >> here we have the horrible hack again then (would behave different without >> it?). I guess it works because when applying primitive function likes >> putChar#, these could be considered as fully strict, since putChar# c really >> does force evaluation of c strictly and puts in the screen. This is >> different from the lazy IO situation, where a string is concatenated lazily, >> and put on the screen by the consumer as soon as it's available. Ah I'm >> having troubles to explain myself formally, never mind :) >> Actually RealWorld is not defined in that file, it is defined here, but >> hidden >> file:///C:/app/ghp/doc/libraries/ghc-prim/GHC-Prim.html#t%3ARealWorld >> But I don't understand the comment >> data RealWorld Source >> RealWorld is deeply magical. It is primitive, but it is >> not unlifted (hence ptrArg). We never manipulate values of type RealWorld; >> it's only used in the type system, to parameterise State#. >> Maybe I should reread the papers, but it seems lots of magic is needed to >> get IO right (such as the existential types to make sure different state >> threads are kept separate) > > You need a lot of magic to make the IO monad efficient. > You don't really want to pass around (and pattern match on) a > RealWorld token, that would be inefficient. I've always preferred the continuation based implementation of IO as used in Hugs and I believe in HBC. GHC's handling of it has always seemed hack-y to me. I don't recall any special treatment of IO by HBC, though Lennart will definitely be able to verify or deny that. From v.dijk.bas at gmail.com Fri Aug 21 10:59:02 2009 From: v.dijk.bas at gmail.com (Bas van Dijk) Date: Fri Aug 21 10:38:59 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: <4A8E8CDA.7080401@yandex.ru> References: <4A8E8CDA.7080401@yandex.ru> Message-ID: On Fri, Aug 21, 2009 at 2:02 PM, Miguel Mitrofanov wrote: >>> {-# LANGUAGE UndecidableInstances #-} > > Ouch! > > Don't worry, it's just me not liking UndecidableInstances. Without it, GHC doesn't like the 'Arg f ~ b' constraint not being smaller than the instance head in: instance (ModelFunc f, Arg f ~ b) => ModelFunc (b -> f) where ... >> So instead of passing the parameters as a list I want to pass them as >> arguments: >> >>> \x p1 p2 p3 -> p1*x^2 + p2*x + p3 > > Why not use tuples? > > \x (p1, p2, p3) -> p1 * x^2 + p2 * x + p3 > > Or a special list-like data type > > data a :* b = ($*) a b > > func :: Double -> (Double :* Double :* Double) -> Double > func x (p1 $* p2 $* p3) = p1 * x^2 + p2 * x + p3 What will the type of 'levmarHL' look like using tuples or using your special list-like type? Thanks, Bas From jvranish at gmail.com Fri Aug 21 11:11:03 2009 From: jvranish at gmail.com (Job Vranish) Date: Fri Aug 21 10:51:02 2009 Subject: [Haskell-cafe] Re: Keeping an indexed collection of values? In-Reply-To: References: Message-ID: Thanks for all the input! :) My current code (unfinished) is here: http://github.com/jvranish/IndexedCollection/tree/master but I think I'll shorten the names as you suggest. (and add some strictness to availableKeys) I also added an extra phantom type parameter to the collection (and key) so that I can prevent keys from being used on different collections even if they hold elements of the same type. There is still problem that trying to use a deleted key might return a bad result rather than an error. I'm not sure how to fix that one. I could keep another buffer, perhaps of the last 100 or so deleted keys, so that a key doesn't get recycled until 100 other keys have been freed. This would increase the chances of detecting this type of error. I could also possibly integrate it with Bernie's suggestion, which would probably significantly improve performance in my case. But the added complexity might not be worth it. Hmm although... I could potentially do something evil and detect the use of a deleted key via stableNames. I'd rewrap my keys on recycle so that there stablenames change. Then I can check on lookup if the key used has the same stableName as the key in the collection, if they don't match either raise an error or return Nothing. Not sure if I feel that evil though :D Thanks again for the input :) - Job On Fri, Aug 21, 2009 at 7:26 AM, Heinrich Apfelmus < apfelmus@quantentunnel.de> wrote: > Heinrich Apfelmus wrote: > > Job Vranish wrote: > >> I've been in a situation a lot lately where I need to keep a collection > of > >> values, and keep track of them by a persistent index. > >> > > > > module Store (Key, Store, empty, add, delete, lookup) where > > > > newtype Key = Key { int :: Int } > > > > empty :: Store a > > add :: a -> Store a -> (Key, Store a) > > delete :: Key -> Store a -> Store a > > lookup :: Key -> Store a -> Maybe a > > > > This way, the user doesn't know and care how Key is implemented. > > > > Last but not least, there is the issue that trying to use an already > > deleted key might yield a wrong result instead of an error. That > > shouldn't happen if used correctly, but might give a headache when > > debugging. > > There is even a very simple way to prevent at least some cases of > misuse, when one key is accidentally used on stores of different type. A > phantom parameter will do the trick: > > newtype Key a = Key { int :: Int } > > add :: a -> Store a -> (Key a , Store a) > delete :: Key a -> Store a -> Store a > lookup :: Key a -> Store a -> Maybe a > > > > Regards, > apfelmus > > -- > http://apfelmus.nfshost.com > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090821/72257621/attachment.html From pumpkingod at gmail.com Fri Aug 21 12:18:13 2009 From: pumpkingod at gmail.com (Daniel Peebles) Date: Fri Aug 21 11:58:10 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: References: Message-ID: I'm pretty sure you're going to need an existential wrapper for your fromList function. Something like: data AnyVector a where AnyVector :: Vector a n -> AnyVector a because otherwise you'll be returning different types from intermediate iterations of your fromList function. I was playing with n-ary functions yesterday too, and came up with the following, which doesn't need undecidable instances, if you're interested: type family Replicate n (a :: * -> *) b :: * type instance Replicate (S x) a b = a (Replicate x a b) type instance Replicate Z a b = b type Function n a b = Replicate n ((->) a) b (you can also use the Replicate "function" to make type-level n-ary vectors and maybe other stuff, who knows) Hope this helps, Dan On Fri, Aug 21, 2009 at 7:41 AM, Bas van Dijk wrote: > Hello, > > We're working on a Haskell binding to levmar[1] a C implementation of > the Levenberg-Marquardt optimization algorithm. The > Levenberg-Marquardt algorithm is an iterative technique that finds a > local minimum of a function that is expressed as the sum of squares of > nonlinear functions. It has become a standard technique for nonlinear > least-squares problems. It's for example ideal for curve fitting. > > The binding is nearly finished and consists of two layers: a low-level > layer that directly exports the C bindings and a medium-level layer > that wraps the lower-level functions and provides a more Haskell > friendly interface. > > The Medium-Level (ML) layer has a function which is similar to: > >> levmarML :: (a -> [Double] -> Double) >> ? ? ? ? ?-> [Double] >> ? ? ? ? ?-> [(a, Double)] >> ? ? ? ? ?-> [Double] >> levmarML model initParams samples = ... > > So you give it a model function, an initial guess of the parameters > and some input samples. levmarML than tries to find the parameters > that best describe the input samples. Of course, the real function has > more arguments and return values but this simple version will do for > this discussion. > > Al-dough this medium-level layer is more Haskell friendly than the > low-level layer it still has some issues. For example a model function > is represented as a function that takes a list of parameters. For > example: > >> \x [p1, p2, p3] -> p1*x^2 + p2*x + p3 > > You have to ensure that the length of the initial guess of parameters > is exactly 3. Otherwise you get run-time pattern-match failures. > > So I would like to create a new High-Level (HL) layer that overcomes > this problem. > > First of all I need the following language extensions: > >> {-# LANGUAGE EmptyDataDecls #-} >> {-# LANGUAGE UndecidableInstances #-} >> {-# LANGUAGE TypeFamilies #-} >> {-# LANGUAGE GADTs #-} > > I want to represent the model function as a normal Haskell function. > So instead of passing the parameters as a list I want to pass them as > arguments: > >> \x p1 p2 p3 -> p1*x^2 + p2*x + p3 > > Because we would like to be able to use model functions of different > arity it means the levmarHL function needs to be polymorphic in the > model function: > >> levmarHL :: (ModelFunc f, Arity f ~ n, Arg f ~ Double) >> ? ? ? ? ?=> (a -> f) >> ? ? ? ? ?-> Vector Double n >> ? ? ? ? ?-> [(a, Double)] >> ? ? ? ? ?-> Vector Double n >> levmarHL model initParams samples = >> ? ? fromList $ levmarML (\x params -> model x $* fromList params) >> ? ? ? ? ? ? ? ? ? ? ? ? (toList initParams) >> ? ? ? ? ? ? ? ? ? ? ? ? samples > > You can see that the initial parameters and the result are passed as > Vectors that encode their length 'n' in their type. This length must > equal the arity of the model function: 'Arity f ~ n'. The arity of the > model function and the length of the vectors are represented as type > level naturals: > >> data Z >> data S n > > Lets look at the implementation of ModelFunc: > >> class ModelFunc f where >> ? ? type Arg ? f :: * >> ? ? type Arity f :: * >> >> ? ? ($*) :: f -> Vector (Arg f) (Arity f) -> Arg f > > $* is similar to $ but instead of applying a function to a single > argument it applies it to a vector of multiple arguments. > >> instance (ModelFunc f, Arg f ~ b) => ModelFunc (b -> f) where >> ? ? type Arg ? (b -> f) = b >> ? ? type Arity (b -> f) = S (Arity f) >> >> ? ? f $* (x :*: xs) = f x $* xs > > You can see that we restrict the arguments of module functions to have > the same type: 'Arg f ~ b'. > > This is the base case: > >> instance ModelFunc Double where >> ? ? type Arg ? Double = Double >> ? ? type Arity Double = Z >> >> ? ? d $* Nil = d > > We represent Vectors using a GADT: > >> data Vector a n where >> ? ? Nil :: Vector a Z >> ? ? (:*:) :: a -> Vector a n -> Vector a (S n) > >> infixr :*: > > Converting a Vector to a list is easy: > >> toList :: Vector b n -> [b] >> toList Nil ? ? ? ?= [] >> toList (x :*: xs) = x : toList xs > > My single question is: how can I convert a list to a Vector??? > >> fromList :: [b] -> Vector b n >> fromList = ? > > regards, > > Roel and Bas van Dijk > > [1] http://www.ics.forth.gr/~lourakis/levmar/ > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From miguelimo38 at yandex.ru Fri Aug 21 12:23:27 2009 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Fri Aug 21 12:03:26 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: References: <4A8E8CDA.7080401@yandex.ru> Message-ID: >> Don't worry, it's just me not liking UndecidableInstances. > > Without it, GHC doesn't like the 'Arg f ~ b' constraint He's probably right. I don't like it either. > What will the type of 'levmarHL' look like using tuples or using your > special list-like type? I guess it would be something like LevMarParamCoolType c => (a -> c -> Double) -> c -> [(a, Double)] -> c From sebf at informatik.uni-kiel.de Fri Aug 21 12:24:54 2009 From: sebf at informatik.uni-kiel.de (Sebastian Fischer) Date: Fri Aug 21 12:04:59 2009 Subject: [Haskell-cafe] Re: Keeping an indexed collection of values? In-Reply-To: References: Message-ID: <62905C59-1D81-4915-8822-7186B39723D6@informatik.uni-kiel.de> On Aug 21, 2009, at 5:11 PM, Job Vranish wrote: > I also added an extra phantom type parameter to the collection (and > key) so that I can prevent keys from being used on different > collections even if they hold elements of the same type. I have the impression that this requires explicit type annotations with your current solution which seems a bit tiresome. If not instantiated to specific different types, the additional phantom types of different collections can just be unified which does not lead to a type error. As you seem to implement a monadic interface, you might be able to steal the idea of using higher-rank polymorphism (that is used in the ST monad implementation) to ensure that the phantom types of different collections cannot be unified. But that would probably mean to implement your own monad that carries this phantom type too.. Cheers, Sebastian -- Underestimating the novelty of the future is a time-honored tradition. (D.G.) From conor at strictlypositive.org Fri Aug 21 12:47:22 2009 From: conor at strictlypositive.org (Conor McBride) Date: Fri Aug 21 12:27:30 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: References: Message-ID: <68BBEEF3-F3F0-4405-B2D0-2F5563A1AEF5@strictlypositive.org> Hi I'm sure it won't be to everyone's taste, but here's what SHE makes of this problem. SHE lives here http://personal.cis.strath.ac.uk/~conor/pub/she > {-# OPTIONS_GHC -F -pgmF she #-} > {-# LANGUAGE GADTs, KindSignatures, TypeOperators, TypeFamilies, FlexibleContexts, > MultiParamTypeClasses, RankNTypes #-} You need to turn lots of stuff on to support the coding: it would need much less machinery if this stuff were directly implemented. > module Vec where > import ShePrelude > data Nat :: * where > Z :: Nat > S :: Nat -> Nat > deriving (SheSingleton) I'm asking for the generation of the singleton family, so that I can form pi-types over Nat. > data Vec :: {Nat} -> * -> * where > VNil :: Vec {Z} x > (:>) :: x -> Vec {n} x -> Vec {S n} x Vectors, in the dependently typed tradition. > instance Show x => Show (Vec {n} x) where > show VNil = "VNil" > show (x :> xs) = show x ++ " :> " ++ show xs I gather I won't need to roll my own, next version. > listVec :: [a] -> (pi (n :: Nat). Vec {n} a -> t) -> t > listVec [] f = f {Z} VNil > listVec (x : xs) f = listVec xs (\ n ys -> f {S n} (x :> ys)) And that's your gadget: it gives you the length and the vector. *Vec> listVec "Broad" (const show) listVec "Broad" (const show) "'B' :> 'r' :> 'o' :> 'a' :> 'd' :> VNil" If you're curious, here's what SHE generates for the above. {-# OPTIONS_GHC -F -pgmF she #-} {-# LANGUAGE GADTs, KindSignatures, TypeOperators, TypeFamilies, FlexibleContexts, MultiParamTypeClasses, RankNTypes #-} module Vec where import ShePrelude data Nat :: * where Z :: Nat S :: Nat -> Nat data Vec :: * -> * -> * where VNil :: Vec (SheTyZ) x (:>) :: x -> Vec (n) x -> Vec (SheTyS n) x instance Show x => Show (Vec (n) x) where show VNil = "VNil" show (x :> xs) = show x ++ " :> " ++ show xs listVec :: [a] -> (forall n . SheSingleton ( Nat) n -> Vec (n) a -> t) -> t listVec [] f = f (SheWitZ) VNil listVec (x : xs) f = listVec xs (\ n ys -> f (SheWitS n) (x :> ys)) data SheTyZ = SheTyZ data SheTyS x1 = SheTyS x1 data SheTyVNil = SheTyVNil data (:$#$#$#:>) x1 x2 = (:$#$#$#:>) x1 x2 type instance SheSingleton (Nat) = SheSingNat data SheSingNat :: * -> * where SheWitZ :: SheSingNat (SheTyZ) SheWitS :: forall sha0. SheSingleton (Nat ) sha0 -> SheSingNat (SheTyS sha0) instance SheChecks (Nat ) (SheTyZ) where sheTypes _ = SheWitZ instance SheChecks (Nat ) sha0 => SheChecks (Nat ) (SheTyS sha0) where sheTypes _ = SheWitS (sheTypes (SheProxy :: SheProxy (Nat ) (sha0))) All good clean fun Conor On 21 Aug 2009, at 17:18, Daniel Peebles wrote: > I'm pretty sure you're going to need an existential wrapper for your > fromList function. Something like: > > data AnyVector a where > AnyVector :: Vector a n -> AnyVector a > > because otherwise you'll be returning different types from > intermediate iterations of your fromList function. > > I was playing with n-ary functions yesterday too, and came up with the > following, which doesn't need undecidable instances, if you're > interested: > > type family Replicate n (a :: * -> *) b :: * > type instance Replicate (S x) a b = a (Replicate x a b) > type instance Replicate Z a b = b > > type Function n a b = Replicate n ((->) a) b > > (you can also use the Replicate "function" to make type-level n-ary > vectors and maybe other stuff, who knows) > > Hope this helps, > Dan > > On Fri, Aug 21, 2009 at 7:41 AM, Bas van Dijk > wrote: >> Hello, >> >> We're working on a Haskell binding to levmar[1] a C implementation of >> the Levenberg-Marquardt optimization algorithm. The >> Levenberg-Marquardt algorithm is an iterative technique that finds a >> local minimum of a function that is expressed as the sum of squares >> of >> nonlinear functions. It has become a standard technique for nonlinear >> least-squares problems. It's for example ideal for curve fitting. >> >> The binding is nearly finished and consists of two layers: a low- >> level >> layer that directly exports the C bindings and a medium-level layer >> that wraps the lower-level functions and provides a more Haskell >> friendly interface. >> >> The Medium-Level (ML) layer has a function which is similar to: >> >>> levmarML :: (a -> [Double] -> Double) >>> -> [Double] >>> -> [(a, Double)] >>> -> [Double] >>> levmarML model initParams samples = ... >> >> So you give it a model function, an initial guess of the parameters >> and some input samples. levmarML than tries to find the parameters >> that best describe the input samples. Of course, the real function >> has >> more arguments and return values but this simple version will do for >> this discussion. >> >> Al-dough this medium-level layer is more Haskell friendly than the >> low-level layer it still has some issues. For example a model >> function >> is represented as a function that takes a list of parameters. For >> example: >> >>> \x [p1, p2, p3] -> p1*x^2 + p2*x + p3 >> >> You have to ensure that the length of the initial guess of parameters >> is exactly 3. Otherwise you get run-time pattern-match failures. >> >> So I would like to create a new High-Level (HL) layer that overcomes >> this problem. >> >> First of all I need the following language extensions: >> >>> {-# LANGUAGE EmptyDataDecls #-} >>> {-# LANGUAGE UndecidableInstances #-} >>> {-# LANGUAGE TypeFamilies #-} >>> {-# LANGUAGE GADTs #-} >> >> I want to represent the model function as a normal Haskell function. >> So instead of passing the parameters as a list I want to pass them as >> arguments: >> >>> \x p1 p2 p3 -> p1*x^2 + p2*x + p3 >> >> Because we would like to be able to use model functions of different >> arity it means the levmarHL function needs to be polymorphic in the >> model function: >> >>> levmarHL :: (ModelFunc f, Arity f ~ n, Arg f ~ Double) >>> => (a -> f) >>> -> Vector Double n >>> -> [(a, Double)] >>> -> Vector Double n >>> levmarHL model initParams samples = >>> fromList $ levmarML (\x params -> model x $* fromList params) >>> (toList initParams) >>> samples >> >> You can see that the initial parameters and the result are passed as >> Vectors that encode their length 'n' in their type. This length must >> equal the arity of the model function: 'Arity f ~ n'. The arity of >> the >> model function and the length of the vectors are represented as type >> level naturals: >> >>> data Z >>> data S n >> >> Lets look at the implementation of ModelFunc: >> >>> class ModelFunc f where >>> type Arg f :: * >>> type Arity f :: * >>> >>> ($*) :: f -> Vector (Arg f) (Arity f) -> Arg f >> >> $* is similar to $ but instead of applying a function to a single >> argument it applies it to a vector of multiple arguments. >> >>> instance (ModelFunc f, Arg f ~ b) => ModelFunc (b -> f) where >>> type Arg (b -> f) = b >>> type Arity (b -> f) = S (Arity f) >>> >>> f $* (x :*: xs) = f x $* xs >> >> You can see that we restrict the arguments of module functions to >> have >> the same type: 'Arg f ~ b'. >> >> This is the base case: >> >>> instance ModelFunc Double where >>> type Arg Double = Double >>> type Arity Double = Z >>> >>> d $* Nil = d >> >> We represent Vectors using a GADT: >> >>> data Vector a n where >>> Nil :: Vector a Z >>> (:*:) :: a -> Vector a n -> Vector a (S n) >> >>> infixr :*: >> >> Converting a Vector to a list is easy: >> >>> toList :: Vector b n -> [b] >>> toList Nil = [] >>> toList (x :*: xs) = x : toList xs >> >> My single question is: how can I convert a list to a Vector??? >> >>> fromList :: [b] -> Vector b n >>> fromList = ? >> >> regards, >> >> Roel and Bas van Dijk >> >> [1] http://www.ics.forth.gr/~lourakis/levmar/ >> _______________________________________________ >> 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 dave at zednenem.com Fri Aug 21 12:53:41 2009 From: dave at zednenem.com (David Menendez) Date: Fri Aug 21 12:33:39 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <3e1162e60908200734v4a626760m3e128e8117b477bd@mail.gmail.com> <49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> <49a77b7a0908201423v178fc46kd2b2c715d017c765@mail.gmail.com> <49a77b7a0908202003x1b69f91dxa69fb649d3c4aa82@mail.gmail.com> Message-ID: <49a77b7a0908210953q7d2b630dh8d38715b57e8122d@mail.gmail.com> On Fri, Aug 21, 2009 at 4:37 AM, Peter Verswyvelen wrote: > On Fri, Aug 21, 2009 at 5:03 AM, David Menendez wrote: >> >> I'm not sure I understand your question, but I think it's possible to >> use interact in the way you want. For example, this code behaves >> correctly for me: >> >> ? ?foo i = >> ? ? ? ?let i1 = lines i >> ? ? ? ?in "Enter your name: " ++ >> ? ? ? ? ? ?(case i1 of >> ? ? ? ? ? ? ? ?[] -> error "EOF" >> ? ? ? ? ? ? ? ?name:i2 -> "Welcome " ++ name ++ "\n") >> >> Prelude> interact foo >> Enter your name: Bob >> Welcome Bob > > Yes but this also enforce strictness, since you're pattern matching against > the input, forcing it to be evaluated. If for example the empty string would > be valid input, this wouldn't work, and seq would be needed again no? You would still need to determine whether you've reached EOF or not, which forces the input to be determined up to the first line-break or EOF. > This suffers from the same strictness problem on the input, e.g. when making > getLine less strict, as in: > import Prelude hiding (getLine) > import Control.Monad.Cont > type Behavior = [String] -> String > type MyIO = Cont Behavior > putLine :: String -> MyIO () > putLine s = Cont $ \k ss -> s ++ k () ss > getLine :: MyIO String > -- Was:?getLine = Cont $ \k (s:ss) -> k s ss > getLine = Cont $ \k ss -> k (head ss) (tail ss) Technically, these are both wrong, because they don't allow for EOF. getLine should be more like this: getLine = Cont $ \k ss -> if null ss then error "EOF" else k (head ss) (tail ss) > run :: MyIO () -> Behavior > run m = runCont m (\_ _ -> []) > foo = do > ?? putLine "Enter name: " > ?? name <- getLine > ?? putLine ("Welcome " ++ name ++ "\n") > main = interact (run foo . lines) > You get the "Welcome" before the name again. > To be honest I don't fully understand why this is a horrible hack. It isn't. Some people dislike seq because it lets you force strictness in cases where pattern matching cannot (like function arguments), but hardly anyone objects to pattern matching. (I just read a paper arguing that pattern matching is bad because it introduces interpretation. The proposed solution, Church encoding everything, seemed impractical.) > I do understand much more now, thanks. The best solution for making this IO > pure remains MonadPrompt I guess. Or the trace technique I mentioned earlier. I believe they're equivalent in expressive power. > Too bad that something extremely simple like console text IO doesn't seem to > be a good start for introducing FRP, or maybe seen from another angle (using > Reactive) it might still be, dono Are you writing an introduction to using FRP, or an introduction to implementing FRP? Every Haskell FRP implementation I'm aware of uses the IO monad internally. If you want to be able to run in an entirely pure manner, you might investigate IOSpec. -- Dave Menendez From dagit at codersbase.com Fri Aug 21 13:03:29 2009 From: dagit at codersbase.com (Jason Dagit) Date: Fri Aug 21 12:43:27 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: References: Message-ID: On Fri, Aug 21, 2009 at 4:41 AM, Bas van Dijk wrote: > My single question is: how can I convert a list to a Vector??? > >> fromList :: [b] -> Vector b n >> fromList = ? A simpler thing to help you see why this is such a problem is, the problem of how to get a type level natural from Int. data Z = Z newtype S n = S n toPeano :: Int -> n toPeano n = {- what goes here? -} Going the other way is not bad. I found this in an Oleg paper: npred :: S n -> n npred = undefined class Nat n where nat2num :: Num a => n -> a instance Nat Z where nat2num _ = 0 instance Nat n => Nat (S n) where nat2num n = 1 + (nat2num (npred n)) Even with a type class for our type level numbers I'm at a loss. I just don't understand how to convert an arbitrary int into an arbitrary but fixed type. Perhaps someone else on the list knows. I would like to know, if it's possible, how to do it. toPeano :: Nat n => Int -> n If we had this, we could define the 'AnyVector' that Daniel Peebles suggested. With it, you can write: fromList' :: [b] -> AnyVector b fromList' [] = AnyVector Nil fromList' (b:bs) = case fromList' bs of AnyVector bs' -> AnyVector (b :*: bs') fromList :: (Nat size) => size -> [b] -> Vector b size fromList _ xs = case fromList' xs of -- can't use a where because of existential type AnyVector v -> unsafeCoerce v -- needed due to existential type, but safe-ish because of the type sig of fromList You would expose fromList to the real world (eg., export it from the module but hide fromList'). But, now how to bootstrap 'size'? Perhaps Oleg has a trick for writing the toPeano function I proposed above. With it, you could write a wrapper around fromList like this: fromList2 :: [b] -> Vector b size fromList2 xs = fromList (toPeano (length xs)) -- you may still need to wrap this in unsafeCoerce I found this in a paper about type families which would help in some cases: type family Add a b type instance Add Z a = a type instance Add (S a) b = S (Add a b) appendVec :: Vector a n -> Vector a m -> Vector a (Add n m) appendVec Nil y = y appendVec (x:*:xs) ys = x :*: (xs `appendVec` ys) For a brief second I thought it may be possible to define fromList in terms of appendVec. For example, you wrote a fold to and used appendVec you could append them all together. That quickly gets you back to the problem of "What peano number corresponds to the length of a given list?". I'd love to see what you figure out. Jason From paolo.veronelli at gmail.com Fri Aug 21 13:21:23 2009 From: paolo.veronelli at gmail.com (Paolino) Date: Fri Aug 21 13:01:23 2009 Subject: [Haskell-cafe] testing par with simple program Message-ID: Hi, reading a previous thread I got interested. I simplified the example pointed by dons in import Control.Parallel main = a `par` b `pseq` print (a + b ) where a = ack 3 11 b = ack 3 11 ack 0 n = n+1 ack m 0 = ack (m-1) 1 ack m n = ack (m-1) (ack m (n-1)) compiled with ghc --make prova -O2 -threaded timings paolino@paolino-casa:~$ time ./prova +RTS -N1 32762 real 0m7.031s user 0m6.304s sys 0m0.004s paolino@paolino-casa:~$ time ./prova +RTS -N2 32762 real 0m6.997s user 0m6.728s sys 0m0.020s paolino@paolino-casa:~$ without optimizations it gets worse paolino@paolino-casa:~$ time ./prova +RTS -N1 32762 real 1m20.706s user 1m18.197s sys 0m0.104s paolino@paolino-casa:~$ time ./prova +RTS -N2 32762 real 1m38.927s user 1m45.039s sys 0m0.536s paolino@paolino-casa:~$ staring at the resource usage graph I can see it does use 2 cores when told to do it, but with -N1 the used cpu goes 100% and with -N2 they both run just over 50% thanks for comments paolino -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090821/a605e3d9/attachment.html From ck_kashyap at yahoo.com Fri Aug 21 13:33:15 2009 From: ck_kashyap at yahoo.com (CK Kashyap) Date: Fri Aug 21 13:13:13 2009 Subject: [Haskell-cafe] Right way to implement setPixel function Message-ID: <111288.18145.qm@web112503.mail.gq1.yahoo.com> thank you very much Job. Regards, Kashyap On Thu Aug 20th, 2009 1:13 PM EDT Job Vranish wrote: >Opps: >setPixel = State setPixel' > >should be: >setPixel x y rgb = State $ setPixel' x y rgb > >- Job > >On Thu, Aug 20, 2009 at 1:05 PM, Job Vranish wrote: > >> Your setPixel function is almost ready to work in a State monad >> If you modify your setPixel function slightly like so: >> >> setPixel' :: Int -> Int -> Color -> B.ByteString -> ((), B.ByteString) >> setPixel' x y (r,g,b) image = ((), B.concat [beforePixel, pixel, >> afterPixel]) >> >> and then wrap it in the State monad constructor: >> >> setPixel = State setPixel' >> >> then you can do >> >> drawPixels = do >> setPixel 5 10 (200, 0, 0) >> setPixel 20 1 (0, 200, 0) >> setPixel 90 2 (0, 0, 200) >> >> modifiedImage = execState drawPixels originalImage >> >> See! you were already using a monad and didn't even know it! :D >> >> Performance wise, B.concat is O(n), which is very not good for your >> purpose. It copies the whole string and the optimizer won't be able to >> magically make it go away. For something that works in O(1), you will have >> to use something like STArrays instead of bytestrings. >> >> - Job >> >> >> >> On Thu, Aug 20, 2009 at 2:32 AM, CK Kashyap wrote: >> >>> Hi, >>> I had posted a note on line drawing algo with Haskell some time back. Now, >>> I am trying to write a PNM image. >>> >>> import qualified Data.ByteString as B >>> >>> width = 256 >>> height = 256 >>> bytesInImage = width * height * 3 >>> blankImage = B.pack $ take bytesInImage (repeat 0) >>> >>> type Color = (Int,Int,Int) >>> setPixel :: B.ByteString -> Int -> Int -> Color -> B.ByteString >>> setPixel image x y (r,g,b) = B.concat [beforePixel, pixel, afterPixel] >>> where >>> beforePixel = B.take before image >>> afterPixel = B.drop (before+3) image >>> pixel=B.pack [(fromIntegral r),(fromIntegral >>> g),(fromIntegral b)] >>> -- number of bytes before the 3 bytes of >>> -- the pixel at x y >>> before = (y * width * 3) + (x * 3) - 3 >>> >>> main = do >>> putStrLn "P6" >>> putStrLn ( (show width) ++ " " ++ (show height) ) >>> putStrLn "255" >>> -- Set a red pixel at 100 100 >>> B.putStr (setPixel blankImage 100 100 (255,0,0)) >>> >>> >>> Can I please have some review comments on the code above? Would recreating >>> the entire ByteString for each setPixel be an overhead? >>> Also, I am barely beginning to grasp the Monad concept....I was wondering >>> if there could be a monadic style of implementation of this - that could >>> potentially have a series of setPixels inside a do block? >>> >>> Regards, >>> Kashyap >>> >>> >>> _______________________________________________ >>> Haskell-Cafe mailing list >>> Haskell-Cafe@haskell.org >>> http://www.haskell.org/mailman/listinfo/haskell-cafe >>> >>> >> From dons at galois.com Fri Aug 21 13:37:01 2009 From: dons at galois.com (Don Stewart) Date: Fri Aug 21 13:19:10 2009 Subject: [Haskell-cafe] testing par with simple program In-Reply-To: References: Message-ID: <20090821173701.GF14014@whirlpool.galois.com> paolo.veronelli: > Hi, reading a previous thread I got interested. > I simplified the example pointed by dons in > > import Control.Parallel > > main = a `par` b `pseq` print (a + b ) > where > a = ack 3 11 > b = ack 3 11 > > ack 0 n = n+1 > ack m 0 = ack (m-1) 1 > ack m n = ack (m-1) (ack m (n-1)) > > compiled with > ghc --make prova -O2 -threaded > > timings > paolino@paolino-casa:~$ time ./prova +RTS -N1 > 32762 > > real 0m7.031s > user 0m6.304s > sys 0m0.004s > paolino@paolino-casa:~$ time ./prova +RTS -N2 > 32762 > > real 0m6.997s > user 0m6.728s > sys 0m0.020s > paolino@paolino-casa:~$ > > without optimizations it gets worse > > paolino@paolino-casa:~$ time ./prova +RTS -N1 > 32762 > > real 1m20.706s > user 1m18.197s > sys 0m0.104s > paolino@paolino-casa:~$ time ./prova +RTS -N2 > 32762 > > real 1m38.927s > user 1m45.039s > sys 0m0.536s > paolino@paolino-casa:~$ > > staring at the resource usage graph I can see it does use 2 cores when told to > do it, but with -N1 the used cpu goes 100% and with -N2 they both run just over > 50% > > thanks for comments Firstly, a and b are identical, so GHC commons them up. The compiler transforms it into: a `par` a `seq` print (a + a) So you essentially fork a spark to evaluate 'a', and then have the main thread also evaluate 'a' again. One of them wins, then you add the result to itself. The runtime may choose not to convert your first spark into a thread. Running with a 2009 GHC head snapshot, we can see with +RTS -sstderr SPARKS: 1 (0 converted, 0 pruned) That indeed, it doesn't convert your `par` into a real thread. While, for example, the helloworld on the wiki: http://haskell.org/haskellwiki/Haskell_in_5_steps Converts 2 sparks to 2 theads: SPARKS: 2 (2 converted, 0 pruned) ./B +RTS -threaded -N2 -sstderr 2.13s user 0.04s system 137% cpu 1.570 total -- Don From dave at zednenem.com Fri Aug 21 14:03:17 2009 From: dave at zednenem.com (David Menendez) Date: Fri Aug 21 13:43:36 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: References: Message-ID: <49a77b7a0908211103u29118f95m2ba22d9dc85a3c46@mail.gmail.com> On Fri, Aug 21, 2009 at 1:03 PM, Jason Dagit wrote: > > Even with a type class for our type level numbers I'm at a loss. ?I > just don't understand how to convert an arbitrary int into an > arbitrary but fixed type. ?Perhaps someone else on the list knows. ?I > would like to know, if it's possible, how to do it. > > toPeano :: Nat n => Int -> n The problem is that the parameter, n, is part of the input to toPeano, but you need it to be part of the output. To rephrase slightly, you have toPeano :: forall n. (Nat n) => Int -> n but you need, toPeano :: Int -> exists n. (Nat n) => n which states that toPeano determines the type of its return value. In Haskell, you can encode this with an existential data type, data SomeNat where SomeNat :: (Nat n) => n -> SomeNat toPeano :: Int -> SomeNat or, equivalently, by using a higher-order function. toPeano :: Int -> (forall n. Nat n => n -> t) -> t -- Dave Menendez From pumpkingod at gmail.com Fri Aug 21 14:16:24 2009 From: pumpkingod at gmail.com (Daniel Peebles) Date: Fri Aug 21 13:56:21 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: <49a77b7a0908211103u29118f95m2ba22d9dc85a3c46@mail.gmail.com> References: <49a77b7a0908211103u29118f95m2ba22d9dc85a3c46@mail.gmail.com> Message-ID: Just to expand on David's higher-order function for the original Vector type, we can do: data AnyVec a where AnyVec :: Vec a n -> AnyVec a listToVec :: [a] -> AnyVec a listToVec = worker AnyVec worker :: (forall n. Nat n => Vec a n -> t) -> [a] -> t worker f [] = f Nil worker f (x:xs) = worker (f . (Cons x)) xs and have it behave as you'd expect. Note that in a sense this is "forgetful" of the original length of the list. Dan On Fri, Aug 21, 2009 at 2:03 PM, David Menendez wrote: > On Fri, Aug 21, 2009 at 1:03 PM, Jason Dagit wrote: >> >> Even with a type class for our type level numbers I'm at a loss. ?I >> just don't understand how to convert an arbitrary int into an >> arbitrary but fixed type. ?Perhaps someone else on the list knows. ?I >> would like to know, if it's possible, how to do it. >> >> toPeano :: Nat n => Int -> n > > The problem is that the parameter, n, is part of the input to toPeano, > but you need it to be part of the output. To rephrase slightly, you > have > > ? ?toPeano :: forall n. (Nat n) => ?Int -> n > > but you need, > > ? ?toPeano :: Int -> exists n. (Nat n) => n > > which states that toPeano determines the type of its return value. In > Haskell, you can encode this with an existential data type, > > ? ?data SomeNat where SomeNat :: (Nat n) => n -> SomeNat > ? ?toPeano :: Int -> SomeNat > > or, equivalently, by using a higher-order function. > > ? ?toPeano :: Int -> (forall n. Nat n => n -> t) -> t > > -- > Dave Menendez > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From paolo.veronelli at gmail.com Fri Aug 21 14:17:42 2009 From: paolo.veronelli at gmail.com (Paolino) Date: Fri Aug 21 13:57:39 2009 Subject: [Haskell-cafe] testing par with simple program In-Reply-To: <20090821173701.GF14014@whirlpool.galois.com> References: <20090821173701.GF14014@whirlpool.galois.com> Message-ID: A better test program import Control.Parallel main = a `par` b `pseq` print (a + b ) where a = ack 3 11 b = fib 39 ack 0 n = n+1 ack m 0 = ack (m-1) 1 ack m n = ack (m-1) (ack m (n-1)) fib 0 = 0 fib 1 = 1 fib n = fib (n-1) + fib (n-2) running it , these are the results paolino@paolino-casa:~$ ghc --make prova -threaded [1 of 1] Compiling Main ( prova.hs, prova.o ) Linking prova ... paolino@paolino-casa:~$ time ./prova +RTS -N1 63262367 real 1m17.485s user 1m16.473s sys 0m0.392s paolino@paolino-casa:~$ time ./prova +RTS -N2 63262367 real 1m20.186s user 1m31.554s sys 0m0.600s paolino@paolino-casa:~$ touch prova.hs paolino@paolino-casa:~$ ghc --make prova -O2 -threaded [1 of 1] Compiling Main ( prova.hs, prova.o ) Linking prova ... paolino@paolino-casa:~$ time ./prova +RTS -N1 63262367 real 0m17.652s user 0m15.277s sys 0m0.108s paolino@paolino-casa:~$ time ./prova +RTS -N2 63262367 real 0m13.650s user 0m15.121s sys 0m0.188s >From the resource graph and the timings it is clear that the program is not able to use all the 2 cores powers, considering computing 'a' alone is about 7 seconds and 'b' alone 9. What is retaining the cpu's to run full power ? paolino 2009/8/21 Don Stewart > paolo.veronelli: > > Hi, reading a previous thread I got interested. > > I simplified the example pointed by dons in > > > > import Control.Parallel > > > > main = a `par` b `pseq` print (a + b ) > > where > > a = ack 3 11 > > b = ack 3 11 > > > > ack 0 n = n+1 > > ack m 0 = ack (m-1) 1 > > ack m n = ack (m-1) (ack m (n-1)) > > > > compiled with > > ghc --make prova -O2 -threaded > > > > timings > > paolino@paolino-casa:~$ time ./prova +RTS -N1 > > 32762 > > > > real 0m7.031s > > user 0m6.304s > > sys 0m0.004s > > paolino@paolino-casa:~$ time ./prova +RTS -N2 > > 32762 > > > > real 0m6.997s > > user 0m6.728s > > sys 0m0.020s > > paolino@paolino-casa:~$ > > > > without optimizations it gets worse > > > > paolino@paolino-casa:~$ time ./prova +RTS -N1 > > 32762 > > > > real 1m20.706s > > user 1m18.197s > > sys 0m0.104s > > paolino@paolino-casa:~$ time ./prova +RTS -N2 > > 32762 > > > > real 1m38.927s > > user 1m45.039s > > sys 0m0.536s > > paolino@paolino-casa:~$ > > > > staring at the resource usage graph I can see it does use 2 cores when > told to > > do it, but with -N1 the used cpu goes 100% and with -N2 they both run > just over > > 50% > > > > thanks for comments > > > Firstly, a and b are identical, so GHC commons them up. The compiler > transforms it into: > > a `par` a `seq` print (a + a) > > So you essentially fork a spark to evaluate 'a', and then have the main > thread also evaluate 'a' again. One of them wins, then you add the > result to itself. The runtime may choose not to convert your first spark > into a thread. > > Running with a 2009 GHC head snapshot, we can see with +RTS -sstderr > > SPARKS: 1 (0 converted, 0 pruned) > > That indeed, it doesn't convert your `par` into a real thread. > > While, for example, the helloworld on the wiki: > > http://haskell.org/haskellwiki/Haskell_in_5_steps > > Converts 2 sparks to 2 theads: > > SPARKS: 2 (2 converted, 0 pruned) > ./B +RTS -threaded -N2 -sstderr 2.13s user 0.04s system 137% cpu 1.570 > total > > -- Don > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090821/f92a3f18/attachment.html From jvranish at gmail.com Fri Aug 21 14:17:52 2009 From: jvranish at gmail.com (Job Vranish) Date: Fri Aug 21 13:57:50 2009 Subject: [Haskell-cafe] Re: Keeping an indexed collection of values? In-Reply-To: <62905C59-1D81-4915-8822-7186B39723D6@informatik.uni-kiel.de> References: <62905C59-1D81-4915-8822-7186B39723D6@informatik.uni-kiel.de> Message-ID: It only requires type annotations on your uses of empty (as that is the only way to construct a collection). The phantom type sticks to everything after that. If you don't care to add a signature then things still work just fine, you just won't be prevented from using indexes from the wrong collection if the the collection type is the same. I think this is nice, because if you are working with just one collection, or collections of only different types you probably don't want to care about the phantom type. But if you do care, it adds extra protection. For example: data P1 data P2 to = runState inCol = evalState a = empty :: IndexedCollection Int P1 b = empty :: IndexedCollection Int P2 (i1, a') = add 5 `to` a (i2, b') = add 16 `to` b test = lookup i2 `inCol` a' -- type error, but type checks if no signatures on a or b - Job On Fri, Aug 21, 2009 at 12:24 PM, Sebastian Fischer < sebf@informatik.uni-kiel.de> wrote: > > On Aug 21, 2009, at 5:11 PM, Job Vranish wrote: > > I also added an extra phantom type parameter to the collection (and key) >> so that I can prevent keys from being used on different collections even if >> they hold elements of the same type. >> > > > I have the impression that this requires explicit type annotations with > your current solution which seems a bit tiresome. If not instantiated to > specific different types, the additional phantom types of different > collections can just be unified which does not lead to a type error. > > As you seem to implement a monadic interface, you might be able to steal > the idea of using higher-rank polymorphism (that is used in the ST monad > implementation) to ensure that the phantom types of different collections > cannot be unified. But that would probably mean to implement your own monad > that carries this phantom type too.. > > Cheers, > Sebastian > > > -- > Underestimating the novelty of the future is a time-honored tradition. > (D.G.) > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090821/9a891407/attachment.html From dons at galois.com Fri Aug 21 14:30:21 2009 From: dons at galois.com (Don Stewart) Date: Fri Aug 21 14:12:25 2009 Subject: [Haskell-cafe] testing par with simple program In-Reply-To: References: <20090821173701.GF14014@whirlpool.galois.com> Message-ID: <20090821183021.GO14014@whirlpool.galois.com> paolo.veronelli: > A better test program > > import Control.Parallel > > main = a `par` b `pseq` print (a + b ) > where > a = ack 3 11 > b = fib 39 > > ack 0 n = n+1 > ack m 0 = ack (m-1) 1 > ack m n = ack (m-1) (ack m (n-1)) > > fib 0 = 0 > fib 1 = 1 > fib n = fib (n-1) + fib (n-2) > > running it , these are the results > > From the resource graph and the timings it is clear that the program is not > able to use all the 2 cores powers, considering computing 'a' alone is about 7 > seconds and 'b' alone 9. > What is retaining the cpu's to run full power ? > Some advice on analysing parallel programs: * Read Simon Marlow's excellent paper: "Runtime Support for Multicore Haskell" http://ghcmutterings.wordpress.com/2009/03/03/new-paper-runtime-support-for-multicore-haskell/ * Install GHC Head from 2009, it includes spark profiling. * Never bother measuring without using -O or -O2 -- unoptimized code is just not useful to think about. * Compile your program: $ ghc-6.11.20090228 -O2 --make -threaded A.hs [1 of 1] Compiling Main ( A.hs, A.o ) Linking A ... * Run it with +RTS -sstderr $ ./A +RTS -N2 -sstderr ./A +RTS -N2 -sstderr 63262367 ... Generation 0: 12021 collections, 0 parallel, 1.33s, 1.42s elapsed Generation 1: 2 collections, 1 parallel, 0.00s, 0.00s elapsed Parallel GC work balance: 1.03 (426 / 414, ideal 2) SPARKS: 1 (1 converted, 0 pruned) Productivity 90.7% of total user, 126.4% of total elapsed And we see 3 things: * It did use the parallel GC : good! * It did convert 1 spark to a thread: good! * Productivity was greater than 100%: good! So this looks fine! So I suspect you're falling into the ghc 6.10.x series bug where < 3 sparks would not be converted. Try with either 3 sparks, or using GHC 6.11.x series. -- Don From dagit at codersbase.com Fri Aug 21 14:50:09 2009 From: dagit at codersbase.com (Jason Dagit) Date: Fri Aug 21 14:30:06 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: References: <49a77b7a0908211103u29118f95m2ba22d9dc85a3c46@mail.gmail.com> Message-ID: For some reason I never saw David's reply to my email. On Fri, Aug 21, 2009 at 11:16 AM, Daniel Peebles wrote: > Just to expand on David's higher-order function for the original > Vector type, we can do: > > data AnyVec a where > ?AnyVec :: Vec a n -> AnyVec a > > listToVec :: [a] -> AnyVec a > listToVec = worker AnyVec > > worker :: (forall n. Nat n => Vec a n -> t) -> [a] -> t > worker f [] = f Nil > worker f (x:xs) = worker (f . (Cons x)) xs > > and have it behave as you'd expect. Note that in a sense this is > "forgetful" of the original length of the list. Isn't this the case every time you open open up the AnyVector type? The only way you can use the vector's size is when you want to do something that works with all sizes unless you're willing to walk the vector back to Nil? For example, if you started with two equal size vectors, wrap them in an AnyVector, then pass them off to a function that can append them, the type system won't know that you have a vector which is twice the original size. > > Dan > > On Fri, Aug 21, 2009 at 2:03 PM, David Menendez wrote: >> On Fri, Aug 21, 2009 at 1:03 PM, Jason Dagit wrote: >>> >>> Even with a type class for our type level numbers I'm at a loss. ?I >>> just don't understand how to convert an arbitrary int into an >>> arbitrary but fixed type. ?Perhaps someone else on the list knows. ?I >>> would like to know, if it's possible, how to do it. >>> >>> toPeano :: Nat n => Int -> n >> >> The problem is that the parameter, n, is part of the input to toPeano, >> but you need it to be part of the output. To rephrase slightly, you >> have >> >> ? ?toPeano :: forall n. (Nat n) => ?Int -> n >> >> but you need, >> >> ? ?toPeano :: Int -> exists n. (Nat n) => n Yes, that's exactly what I meant by my verbage above :) Guess I should have explicitly used the forall/exists terminology. >> >> which states that toPeano determines the type of its return value. In >> Haskell, you can encode this with an existential data type, >> >> ? ?data SomeNat where SomeNat :: (Nat n) => n -> SomeNat >> ? ?toPeano :: Int -> SomeNat Okay, that's what we did with AnyVector. What I don't understand is how you'll actually use this. Once you create SomeNat, the type system no longer remembers which Nat. So to me, you're back where you started. >> >> or, equivalently, by using a higher-order function. >> >> ? ?toPeano :: Int -> (forall n. Nat n => n -> t) -> t This looks a bit more promising. For those unfamiliar with this form, it is the logical "negation" of the previous type. One description is here [1], where it is mentioned that the type of t cannot depend on n. So you could not for example, return Vector a n or do, "toPeano 5 id". I guess you end up writing your program inside out in a sense which is fine, but then how do you address the forgetfulness? Everything has to be inside one scope where you never wrap things in an existential type? Perhaps via the negated existential encoding your last version of toPeano? I have a hard time wrapping my head around it at this point. Jason [1] http://www.ofb.net/~frederik/vectro/draft-r2.pdf From v.dijk.bas at gmail.com Fri Aug 21 14:50:20 2009 From: v.dijk.bas at gmail.com (Bas van Dijk) Date: Fri Aug 21 14:30:19 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: References: <49a77b7a0908211103u29118f95m2ba22d9dc85a3c46@mail.gmail.com> Message-ID: Thanks for all the advice. I have this so far. Unfortunately I have to use unsafeCoerce: ------------------------------------------------------------------------- {-# LANGUAGE EmptyDataDecls #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE RankNTypes #-} module LevMar where import Unsafe.Coerce levmarML :: (a -> [Double] -> Double) -> [Double] -> [(a, Double)] -> [Double] levmarML model initParams samples = initParams data Z data S n data Nat n where Zero :: Nat Z Succ :: Nat n -> Nat (S n) data Vector a n where Nil :: Vector a Z (:*:) :: a -> Vector a n -> Vector a (S n) infixr :*: instance Show a => Show (Vector a n) where show Nil = "Nil" show (x :*: xs) = show x ++ " :*: " ++ show xs toList :: Vector b n -> [b] toList Nil = [] toList (x :*: xs) = x : toList xs listVec :: [a] -> (forall n. Vector a n -> t) -> t listVec [] f = f Nil listVec (x : xs) f = listVec xs (\ys -> f (x :*: ys)) type family Replicate n (a :: * -> *) b :: * type instance Replicate (S x) a b = a (Replicate x a b) type instance Replicate Z a b = b type Function n a b = Replicate n ((->) a) b ($*) :: Function n a a -> Vector a n -> a f $* Nil = f f $* (x :*: xs) = f x $* xs levmarHL :: (a -> Function n Double Double) -> Vector Double n -> [(a, Double)] -> Vector Double n levmarHL model initParams samples = listVec (levmarML (\x params -> listVec params $ \v -> unsafeCoerce (model x) $* v) (toList initParams) samples) (unsafeCoerce) ------------------------------------------------------------------------- regards, Bas From v.dijk.bas at gmail.com Fri Aug 21 14:55:41 2009 From: v.dijk.bas at gmail.com (Bas van Dijk) Date: Fri Aug 21 14:35:40 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: References: <49a77b7a0908211103u29118f95m2ba22d9dc85a3c46@mail.gmail.com> Message-ID: On Fri, Aug 21, 2009 at 8:50 PM, Jason Dagit wrote: >>> ? ?toPeano :: Int -> (forall n. Nat n => n -> t) -> t > > This looks a bit more promising. ?For those unfamiliar with this form, > it is the logical "negation" of the previous type. ?One description is > here [1], where it is mentioned that the type of t cannot depend on n. > ?So you could not for example, return Vector a n or do, "toPeano 5 > id". > > I guess you end up writing your program inside out in a sense which is > fine, but then how do you address the forgetfulness? ?Everything has > to be inside one scope where you never wrap things in an existential > type? ?Perhaps via the negated existential encoding your last version > of toPeano? ?I have a hard time wrapping my head around it at this > point. I got out of the scope using unsafeCoerce. I think its safe because I know my levmarML function is correct. However I can't express that in the type. Bas From pumpkingod at gmail.com Fri Aug 21 14:58:49 2009 From: pumpkingod at gmail.com (Daniel Peebles) Date: Fri Aug 21 14:38:45 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: References: <49a77b7a0908211103u29118f95m2ba22d9dc85a3c46@mail.gmail.com> Message-ID: Hi Bas, I haven't looked at your code too carefully, but unsafeCoerce amounts to proof by violence :) If you want to construct a (much more verbose, probably) "real" proof of your constraints, you might want to refer to Ryan Ingram's email[1] from a few months ago about lightweight dependent(-ish) types in Haskell. Hope this helps, Dan [1] http://www.haskell.org/pipermail/haskell-cafe/2009-June/062690.html On Fri, Aug 21, 2009 at 2:50 PM, Bas van Dijk wrote: > Thanks for all the advice. > > I have this so far. Unfortunately I have to use unsafeCoerce: > > ------------------------------------------------------------------------- > {-# LANGUAGE EmptyDataDecls #-} > {-# LANGUAGE TypeFamilies #-} > {-# LANGUAGE GADTs #-} > {-# LANGUAGE RankNTypes #-} > > module LevMar where > > import Unsafe.Coerce > > levmarML :: (a -> [Double] -> Double) > ? ? ? ? -> [Double] > ? ? ? ? -> [(a, Double)] > ? ? ? ? -> [Double] > levmarML model initParams samples = initParams > > data Z > data S n > > data Nat n where > ? ?Zero :: Nat Z > ? ?Succ :: Nat n -> Nat (S n) > > data Vector a n where > ? ?Nil ? :: Vector a Z > ? ?(:*:) :: a -> Vector a n -> Vector a (S n) > > infixr :*: > > instance Show a => Show (Vector a n) where > ? ?show Nil = "Nil" > ? ?show (x :*: xs) = show x ++ " :*: " ++ show xs > > toList :: Vector b n -> [b] > toList Nil ? ? ? ?= [] > toList (x :*: xs) = x : toList xs > > listVec :: [a] -> (forall n. Vector a n -> t) -> t > listVec [] ? ? ? f = f Nil > listVec (x : xs) f = listVec xs (\ys -> f (x :*: ys)) > > type family Replicate n (a :: * -> *) b :: * > type instance Replicate (S x) a b = a (Replicate x a b) > type instance Replicate Z a b = b > > type Function n a b = Replicate n ((->) a) b > > ($*) :: Function n a a -> Vector a n -> a > f $* Nil ? ? ? ?= f > f $* (x :*: xs) = f x $* xs > > levmarHL :: (a -> Function n Double Double) > ? ? ? ? -> Vector Double n > ? ? ? ? -> [(a, Double)] > ? ? ? ? -> Vector Double n > levmarHL model initParams samples = > ? ?listVec (levmarML (\x params -> listVec params $ \v -> > unsafeCoerce (model x) $* v) > ? ? ? ? ? ? ? ? ? ? ?(toList initParams) > ? ? ? ? ? ? ? ? ? ? ?samples) > ? ? ? ? ? ?(unsafeCoerce) > ------------------------------------------------------------------------- > > regards, > > Bas > From bugfact at gmail.com Fri Aug 21 15:29:46 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Fri Aug 21 15:09:43 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <49a77b7a0908210953q7d2b630dh8d38715b57e8122d@mail.gmail.com> References: <49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> <49a77b7a0908201423v178fc46kd2b2c715d017c765@mail.gmail.com> <49a77b7a0908202003x1b69f91dxa69fb649d3c4aa82@mail.gmail.com> <49a77b7a0908210953q7d2b630dh8d38715b57e8122d@mail.gmail.com> Message-ID: On Fri, Aug 21, 2009 at 6:53 PM, David Menendez wrote: > You would still need to determine whether you've reached EOF or not, > which forces the input to be determined up to the first line-break or > EOF. Good point! I actually had it on my TODO list, but that settles it then :) run :: MyIO () -> Behavior > > run m = runCont m (\_ _ -> []) > > foo = do > > putLine "Enter name: " > > name <- getLine > > putLine ("Welcome " ++ name ++ "\n") > > main = interact (run foo . lines) > > You get the "Welcome" before the name again. > > To be honest I don't fully understand why this is a horrible hack. > > It isn't. Some people dislike seq because it lets you force strictness > in cases where pattern matching cannot (like function arguments), but > hardly anyone objects to pattern matching. Ah so it's subjective. Okay, it's sometimes hard for a newbie to find the "truth" when several experts contradict eachother. Because often when people claim something here, they have very good reasons for it, reasons that are not obvious at all to your average newbie! > > Too bad that something extremely simple like console text IO doesn't seem > to > > be a good start for introducing FRP, or maybe seen from another angle > (using > > Reactive) it might still be, dono > > Are you writing an introduction to using FRP, or an introduction to > implementing FRP? Every Haskell FRP implementation I'm aware of uses > the IO monad internally. Both really. I think to start with I just want to start a blog to write down random pieces (like this interesting conversation), and then see where this will lead me. I'm mainly interested in doing a survey of existing systems, comparing pros/cons with clear examples (at least for myself ;), and also making minimal implementations so I understand the essence of the various techniques. If you want to be able to run in an entirely pure manner, you might > investigate IOSpec. > > > Ah I didn't know that one yet, thanks > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090821/c113b2ab/attachment.html From dave at zednenem.com Fri Aug 21 16:03:52 2009 From: dave at zednenem.com (David Menendez) Date: Fri Aug 21 15:43:49 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: References: <49a77b7a0908211103u29118f95m2ba22d9dc85a3c46@mail.gmail.com> Message-ID: <49a77b7a0908211303n9e7a5ddu3ac912c65d12643a@mail.gmail.com> On Fri, Aug 21, 2009 at 2:50 PM, Jason Dagit wrote: >> On Fri, Aug 21, 2009 at 2:03 PM, David Menendez wrote: >>> >>> The problem is that the parameter, n, is part of the input to toPeano, >>> but you need it to be part of the output. To rephrase slightly, you >>> have >>> >>> ? ?toPeano :: forall n. (Nat n) => ?Int -> n >>> >>> but you need, >>> >>> ? ?toPeano :: Int -> exists n. (Nat n) => n > > Yes, that's exactly what I meant by my verbage above :) ?Guess I > should have explicitly used the forall/exists terminology. > >>> >>> which states that toPeano determines the type of its return value. In >>> Haskell, you can encode this with an existential data type, >>> >>> ? ?data SomeNat where SomeNat :: (Nat n) => n -> SomeNat >>> ? ?toPeano :: Int -> SomeNat > > Okay, that's what we did with AnyVector. ?What I don't understand is > how you'll actually use this. ?Once you create SomeNat, the type > system no longer remembers which Nat. ?So to me, you're back where you > started. I'm assuming you want toPeano and fromList to work on any possible input. In that case, the context has to be able to work for any nat type. It's not quite true that the type system doesn't remember the nat: it's bundled inside the data type, along with the class instance. Depending on what operations are available, you can recover the type as specifically as you want. For example, it's perfectly valid to write a function with this type: testLength :: (Nat n) => SomeVector a -> Maybe (Vector a n) which can then be used for distinguishing vectors of different lengths. It's also possible to prove that two vectors have the same (unknown) length and then use that fact elsewhere. data a :==: b where Eq :: a :==: a eqLengths :: Vector a n -> Vector b m -> Maybe (n :==: m) eqLengths Nil Nil = Just Eq eqLengths (_ :*: as) (_ :*: bs) = do Eq <- eqLengths as bs return Eq eqLengths _ _ = Nothing zipVectors :: Vector a n -> Vector b n -> Vector (a,b) n foo v1 v2 = case v1 of SomeVector v'1 -> case v2 of SomeVector v'2 -> case eqLengths v'1 v'2 of Nothing -> error "Something has gone wrong!" Just Eq -> let v3 = zipVectors v'1 v'2 in ... >>> or, equivalently, by using a higher-order function. >>> >>> ? ?toPeano :: Int -> (forall n. Nat n => n -> t) -> t > > This looks a bit more promising. It's an illusion; the two forms are inter-convertible. toPeanoX :: Int -> SomeNat toPeanoK :: Int -> (forall n. (Nat n) => n -> t) -> t toPeanoX n = toPeanoK n SomeNat toPeanoK n k = case toPeanoX n of (SomeNat n) -> k n > I guess you end up writing your program inside out in a sense which is > fine, but then how do you address the forgetfulness? You can't forget something you never knew in the first place. At compile-time, the length of the list isn't known, so it can't be reflected in the type. -- Dave Menendez From dave at zednenem.com Fri Aug 21 16:20:01 2009 From: dave at zednenem.com (David Menendez) Date: Fri Aug 21 15:59:58 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> <49a77b7a0908201423v178fc46kd2b2c715d017c765@mail.gmail.com> <49a77b7a0908202003x1b69f91dxa69fb649d3c4aa82@mail.gmail.com> <49a77b7a0908210953q7d2b630dh8d38715b57e8122d@mail.gmail.com> Message-ID: <49a77b7a0908211320p7aaa541bh13bc689106b94cf6@mail.gmail.com> On Fri, Aug 21, 2009 at 3:29 PM, Peter Verswyvelen wrote: > On Fri, Aug 21, 2009 at 6:53 PM, David Menendez wrote: >> >> Some people dislike seq because it lets you force strictness >> in cases where pattern matching cannot (like function arguments), but >> hardly anyone objects to pattern matching. > > Ah so it's subjective. Okay, it's sometimes hard for a newbie to find the > "truth" when several experts contradict eachother. Because often when people > claim something here, they have very good reasons for it, reasons that are > not obvious at all to your average newbie! You can make a pretty good argument that programs which rely on strictness for correctness (as opposed to space/time issues) are risky, because it's easy to get things wrong by accident. Internally, the IO monad may rely on strictness to make sure things happen in the proper sequence, but all of that is hidden so we don't have to worry about things like output happening too early because we haven't examined some input yet. This is also why some people object to getContents. For laughs, here's an example of IO code written using Haskell's old stream-based IO system, taken from "A History of Haskell": main :: Behaviour main ~(Success : ~((Str userInput) : ~(Success : ~(r4 : _)))) = [ AppendChan stdout "enter filename\n", ReadChan stdin, AppendChan stdout name, ReadFile name, AppendChan stdout (case r4 of Str contents -> contents Failure ioerr -> "can?t open file") ] where (name : _) = lines userInput It has a certain elegant purity, but I'm glad I don't have to use it. -- Dave Menendez From bugfact at gmail.com Fri Aug 21 16:28:56 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Fri Aug 21 16:08:54 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <49a77b7a0908211320p7aaa541bh13bc689106b94cf6@mail.gmail.com> References: <49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> <49a77b7a0908201423v178fc46kd2b2c715d017c765@mail.gmail.com> <49a77b7a0908202003x1b69f91dxa69fb649d3c4aa82@mail.gmail.com> <49a77b7a0908210953q7d2b630dh8d38715b57e8122d@mail.gmail.com> <49a77b7a0908211320p7aaa541bh13bc689106b94cf6@mail.gmail.com> Message-ID: The question is, in this case when the user gets to see a bit too much of the output before he sees the input, if that really qualifies as an "incorrect" program. It's a bit in the gray zone I guess. You could even argue that it's a feature that input and output are not really synched, they are lazy, input is only read when evaluated; if you want to sync them, use a syncIO action ;-) no that's silly of course. Oh well, thanks for all the input, this was very informative for me hacker. On Fri, Aug 21, 2009 at 10:20 PM, David Menendez wrote: > On Fri, Aug 21, 2009 at 3:29 PM, Peter Verswyvelen > wrote: > > On Fri, Aug 21, 2009 at 6:53 PM, David Menendez > wrote: > >> > >> Some people dislike seq because it lets you force strictness > >> in cases where pattern matching cannot (like function arguments), but > >> hardly anyone objects to pattern matching. > > > > Ah so it's subjective. Okay, it's sometimes hard for a newbie to find the > > "truth" when several experts contradict eachother. Because often when > people > > claim something here, they have very good reasons for it, reasons that > are > > not obvious at all to your average newbie! > > You can make a pretty good argument that programs which rely on > strictness for correctness (as opposed to space/time issues) are > risky, because it's easy to get things wrong by accident. Internally, > the IO monad may rely on strictness to make sure things happen in the > proper sequence, but all of that is hidden so we don't have to worry > about things like output happening too early because we haven't > examined some input yet. > > This is also why some people object to getContents. > > > For laughs, here's an example of IO code written using Haskell's old > stream-based IO system, taken from "A History of Haskell": > > main :: Behaviour > main ~(Success : ~((Str userInput) : ~(Success : ~(r4 : _)))) > = [ AppendChan stdout "enter filename\n", > ReadChan stdin, > AppendChan stdout name, > ReadFile name, > AppendChan stdout > (case r4 of > Str contents -> contents > Failure ioerr -> "can?t open file") > ] where (name : _) = lines userInput > > > It has a certain elegant purity, but I'm glad I don't have to use it. > > -- > Dave Menendez > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090821/029a9767/attachment.html From bugfact at gmail.com Fri Aug 21 16:32:36 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Fri Aug 21 16:12:34 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: References: <49a77b7a0908201423v178fc46kd2b2c715d017c765@mail.gmail.com> <49a77b7a0908202003x1b69f91dxa69fb649d3c4aa82@mail.gmail.com> <49a77b7a0908210953q7d2b630dh8d38715b57e8122d@mail.gmail.com> <49a77b7a0908211320p7aaa541bh13bc689106b94cf6@mail.gmail.com> Message-ID: typo, "sees the input" => "must enter the input" On Fri, Aug 21, 2009 at 10:28 PM, Peter Verswyvelen wrote: > The question is, in this case when the user gets to see a bit too much of > the output before he sees the input, if that really qualifies as an > "incorrect" program. It's a bit in the gray zone I guess. You could even > argue that it's a feature that input and output are not really synched, they > are lazy, input is only read when evaluated; if you want to sync them, use a > syncIO action ;-) no that's silly of course. > Oh well, thanks for all the input, this was very informative for me hacker. > > On Fri, Aug 21, 2009 at 10:20 PM, David Menendez wrote: > >> On Fri, Aug 21, 2009 at 3:29 PM, Peter Verswyvelen >> wrote: >> > On Fri, Aug 21, 2009 at 6:53 PM, David Menendez >> wrote: >> >> >> >> Some people dislike seq because it lets you force strictness >> >> in cases where pattern matching cannot (like function arguments), but >> >> hardly anyone objects to pattern matching. >> > >> > Ah so it's subjective. Okay, it's sometimes hard for a newbie to find >> the >> > "truth" when several experts contradict eachother. Because often when >> people >> > claim something here, they have very good reasons for it, reasons that >> are >> > not obvious at all to your average newbie! >> >> You can make a pretty good argument that programs which rely on >> strictness for correctness (as opposed to space/time issues) are >> risky, because it's easy to get things wrong by accident. Internally, >> the IO monad may rely on strictness to make sure things happen in the >> proper sequence, but all of that is hidden so we don't have to worry >> about things like output happening too early because we haven't >> examined some input yet. >> >> This is also why some people object to getContents. >> >> >> For laughs, here's an example of IO code written using Haskell's old >> stream-based IO system, taken from "A History of Haskell": >> >> main :: Behaviour >> main ~(Success : ~((Str userInput) : ~(Success : ~(r4 : _)))) >> = [ AppendChan stdout "enter filename\n", >> ReadChan stdin, >> AppendChan stdout name, >> ReadFile name, >> AppendChan stdout >> (case r4 of >> Str contents -> contents >> Failure ioerr -> "can?t open file") >> ] where (name : _) = lines userInput >> >> >> It has a certain elegant purity, but I'm glad I don't have to use it. >> >> -- >> Dave Menendez >> >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090821/2a64b876/attachment.html From ravi_n at alum.mit.edu Fri Aug 21 18:30:07 2009 From: ravi_n at alum.mit.edu (Ravi Nanavati) Date: Fri Aug 21 18:10:04 2009 Subject: [Haskell-cafe] Fwd: [BostonHaskell] September meeting polls In-Reply-To: <161d443c0908211526nf62ddcbje299385cc1ab464@mail.gmail.com> References: <161d443c0908211526nf62ddcbje299385cc1ab464@mail.gmail.com> Message-ID: <7b977d860908211530r3b46aaebp4ebe9d2959fa0ec1@mail.gmail.com> I'm forwarding this to haskell-cafe to catch any current or new Boston-area Haskellers who haven't yet joined the BostonHaskell Google group: http://groups.google.com/group/bostonhaskell If you're interested in Boston-area Haskell activity, please join the Google group so you won't miss out on relevant discussions and announcements. Thanks, - Ravi Nanavati ---------- Forwarded message ---------- From: Ravi Nanavati Date: Fri, Aug 21, 2009 at 6:26 PM Subject: [BostonHaskell] September meeting polls To: bostonhaskell@googlegroups.com In the interests of getting the September BostonHaskell meeting organized sooner rather than later (and because Doodle polling has been successful so far), I'd like to take a different approach to arranging the meeting. I've created three polls to get the BostonHaskell community's opinion on the three decision points required before I can organize the meeting: 1. When: https://doodle.com/upd74stbe4d95zpb 2. Where: https://doodle.com/fpicbvb927nbb72v 3. What (to talk about): https://doodle.com/7b8kkcb9queiv89k If you're interested in attending the September BostonHaskell meeting, please answer any of the polls you have opinions about. The first two polls are approval polls (where you can indicate which alternatives you approve of), while the third poll (about choosing which talks) is a binary choice. Thank you in advance for participating. I'd also love to hear any comments people have on this new approach to organizing meetings. Thank you, ?- Ravi Nanavati --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "BostonHaskell" group. To post to this group, send email to bostonhaskell@googlegroups.com To unsubscribe from this group, send email to bostonhaskell+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/bostonhaskell?hl=en -~----------~----~----~----~------~----~------~--~--- From G.C.Stavenga at uu.nl Fri Aug 21 18:42:27 2009 From: G.C.Stavenga at uu.nl (Stavenga, G.C.) Date: Fri Aug 21 18:22:28 2009 Subject: [Haskell-cafe] (no subject) Message-ID: <40EBDEED77D2DE44B91E9AFCC63142C8018498EE@uu01msg-exb02.soliscom.uu.nl> Hi, I'm just started to learn Haskell. Coming from a programming contest background (where it is important to be able to solve problems in a small amount of code) I'm wondering what the best way is for simple IO. A typical input file (in a programming contest) is just a bunch of numbers which you want to read one by one (sometimes interspersed with strings). In C/C++ this is easily done with either scanf or cin which reads data separated by spaces. In Haskell I have not found an equally satisfactionary method. The methods I know of 1) Stay in the IO monad and write your own readInt readString functions. A lot of code for something easy. 2) Use interact together with words and put the list of lexemes in a State monad and define getInt where at least you can use read. 3) Use ByteString.Char8 which has readInt (but I couldn't find a readString). But one has to put it also in a State monad. I think that there must be standard function that can do this. What do experienced Haskellers use? Thanks in advance -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090821/c797ed79/attachment.html From dons at galois.com Fri Aug 21 18:42:21 2009 From: dons at galois.com (Don Stewart) Date: Fri Aug 21 18:24:25 2009 Subject: [Haskell-cafe] (no subject) In-Reply-To: <40EBDEED77D2DE44B91E9AFCC63142C8018498EE@uu01msg-exb02.soliscom.uu.nl> References: <40EBDEED77D2DE44B91E9AFCC63142C8018498EE@uu01msg-exb02.soliscom.uu.nl> Message-ID: <20090821224221.GE15454@whirlpool.galois.com> G.C.Stavenga: > > > Hi, I'm just started to learn Haskell. Coming from a programming contest > background (where it is important to be able to solve problems in a small > amount of code) I'm wondering what the best way is for simple IO. > > A typical input file (in a programming contest) is just a bunch of numbers > which you want to read one by one (sometimes interspersed with strings). In > C/C++ this is easily done with either scanf or cin which reads data > separated by spaces. In Haskell I have not found an equally satisfactionary > method. The methods I know of > > 1) Stay in the IO monad and write your own readInt readString functions. A lot > of code for something easy. > > 2) Use interact together with words and put the list of lexemes in a State > monad and define getInt where at least you can use read. > > 3) Use ByteString.Char8 which has readInt (but I couldn't find a > readString). But one has to put it also in a State monad. > > I think that there must be standard function that can do this. What do > experienced Haskellers use? map read . lines From jwlato at gmail.com Fri Aug 21 18:57:14 2009 From: jwlato at gmail.com (John Lato) Date: Fri Aug 21 18:37:12 2009 Subject: [Haskell-cafe] Re: How to convert a list to a vector encoding its length in its type? Message-ID: <9979e72e0908211557g2bbc844bs7995746e19d56a64@mail.gmail.com> > From: David Menendez > > or, equivalently, by using a higher-order function. > > ? ?toPeano :: Int -> (forall n. Nat n => n -> t) -> t > Incidentally, this is the approach used in the type-level library [1], which provides the function: reifyIntegral :: Integral i => i -> (forall n. Nat n => n -> r) -> r The docs describe this as "In CPS style (best possible solution)," although I didn't see any reference for that assertion. Bas, if you'd like some examples, the ForSyDe project [2] has a tutorial on using type-level vectors, which I found helpful when faced with the same problem recently [3], [4]. Cheers, John Lato [1] http://hackage.haskell.org/package/type-level [2] http://www.ict.kth.se/forsyde/files/tutorial/apa.html [3] http://inmachina.net/~jwlato/haskell/iter-audio/src/Sound/Iteratee/Channelized.hs [4] http://inmachina.net/~jwlato/haskell/iter-audio/examples/channelized_reader.hs From lennart at augustsson.net Fri Aug 21 19:11:14 2009 From: lennart at augustsson.net (Lennart Augustsson) Date: Fri Aug 21 18:51:12 2009 Subject: [Haskell-cafe] Re: Where do I put the seq? In-Reply-To: <61f84eff0908210614s7009e7cbu3d6997c4966e43f@mail.gmail.com> References: <49a77b7a0908201325jdc9a1abu54459d5e733c4e45@mail.gmail.com> <1371197032.20090821092049@gmail.com> <125EACD0CAE4D24ABDB4D148C4593DA91102621C@GBLONXMB02.corp.amvescap.net> <61f84eff0908210614s7009e7cbu3d6997c4966e43f@mail.gmail.com> Message-ID: The IO in hbc was (is) the old request-response model, on top of which there was also a continuation layer, as well as the monadic IO (once that was invented). It involved a lot more C code handling the requests than I really liked. BTW, unsafePerformIO is pretty ugly to implement in the request-response model. I take that as a sign that unsafePerformIO is bad. :) -- Lennart On Fri, Aug 21, 2009 at 3:14 PM, Derek Elkins wrote: > On Fri, Aug 21, 2009 at 5:04 AM, Lennart > Augustsson wrote: >>> On Fri, Aug 21, 2009 at 10:52 AM, Bayley, Alistair >>> wrote: >>>> >>>> > From: haskell-cafe-bounces@haskell.org >>>> > [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Bulat Ziganshin >>>> > To: Peter Verswyvelen >>>> > >>>> > > But how does GHC implement the RealWorld internally? I guess >>>> > >>>> > look the "base" library sources for "RealWorld" >>>> >>>> http://www.haskell.org/ghc/docs/latest/html/libraries/base/src/GHC-IOBas >>>> e.html#IO >>>> >> On Fri, Aug 21, 2009 at 11:04 AM, Peter Verswyvelen wrote: >>> IO also seems to use unboxed (hence strict?) tuples >>> >>> newtype IO a = IO (State# RealWorld -> (# State# RealWorld, a #)) >>> >>> Not sure if this is just for performance, but if the strictness is required, >>> here we have the horrible hack again then (would behave different without >>> it?). I guess it works because when applying primitive function likes >>> putChar#, these could be considered as fully strict, since putChar# c really >>> does force evaluation of c strictly and puts in the screen. This is >>> different from the lazy IO situation, where a string is concatenated lazily, >>> and put on the screen by the consumer as soon as it's available. Ah I'm >>> having troubles to explain myself formally, never mind :) >>> Actually RealWorld is not defined in that file, it is defined here, but >>> hidden >>> file:///C:/app/ghp/doc/libraries/ghc-prim/GHC-Prim.html#t%3ARealWorld >>> But I don't understand the comment >>> data RealWorld Source >>> RealWorld is deeply magical. It is primitive, but it is >>> not unlifted (hence ptrArg). We never manipulate values of type RealWorld; >>> it's only used in the type system, to parameterise State#. >>> Maybe I should reread the papers, but it seems lots of magic is needed to >>> get IO right (such as the existential types to make sure different state >>> threads are kept separate) >> >> You need a lot of magic to make the IO monad efficient. >> You don't really want to pass around (and pattern match on) a >> RealWorld token, that would be inefficient. > > I've always preferred the continuation based implementation of IO as > used in Hugs and I believe in HBC. ?GHC's handling of it has always > seemed hack-y to me. ?I don't recall any special treatment of IO by > HBC, though Lennart will definitely be able to verify or deny that. > From g.c.stavenga at uu.nl Fri Aug 21 19:23:25 2009 From: g.c.stavenga at uu.nl (staafmeister) Date: Fri Aug 21 19:03:21 2009 Subject: [Haskell-cafe] (no subject) In-Reply-To: <20090821224221.GE15454@whirlpool.galois.com> References: <40EBDEED77D2DE44B91E9AFCC63142C8018498EE@uu01msg-exb02.soliscom.uu.nl> <20090821224221.GE15454@whirlpool.galois.com> Message-ID: <25088830.post@talk.nabble.com> Don Stewart-2 wrote: > > G.C.Stavenga: >> >> >> Hi, I'm just started to learn Haskell. Coming from a programming contest >> background (where it is important to be able to solve problems in a small >> amount of code) I'm wondering what the best way is for simple IO. >> >> A typical input file (in a programming contest) is just a bunch of >> numbers >> which you want to read one by one (sometimes interspersed with strings). >> In >> C/C++ this is easily done with either scanf or cin which reads data >> separated by spaces. In Haskell I have not found an equally >> satisfactionary >> method. The methods I know of >> >> 1) Stay in the IO monad and write your own readInt readString functions. >> A lot >> of code for something easy. >> >> 2) Use interact together with words and put the list of lexemes in a >> State >> monad and define getInt where at least you can use read. >> >> 3) Use ByteString.Char8 which has readInt (but I couldn't find a >> readString). But one has to put it also in a State monad. >> >> I think that there must be standard function that can do this. What do >> experienced Haskellers use? > > > map read . lines > > Thank you for the reply. But this only works for if you read only integers > all on different lines. > But in general you have a structure like > > first line -- integer specifying the number of testcases (n) > Then for each testcase > a line with an integer specifying the number of edges (e) > a line with e pairs of string s and int p where p is the number asociated > with string s, etc. > > Such a structure cannot be parsed by map read.lines > What I used is "words" to tokenize and put the list in a State monad with > readInt, readString, etc. functions, to mimic > C code. This seems to be a lot of overkill, so there must be an simpler > way > _______________________________________________ > 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/%28no-subject%29-tp25088427p25088830.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From mwassell at bigpond.net.au Fri Aug 21 19:49:54 2009 From: mwassell at bigpond.net.au (Mark Wassell) Date: Fri Aug 21 19:29:56 2009 Subject: [Haskell-cafe] Converting typeset mathematics into Haskell ? Message-ID: <4A8F32A2.6060608@bigpond.net.au> Does anyone know of any papers or projects, either for Haskell or any other language, that relate to what I am going to attempt to describe in the following: Go to any paper or book that includes some amount of calculation type mathematics. An example is the formula in the Description section of http://en.wikipedia.org/wiki/K-means_clustering. Think about how you would convert this into Haskell. You might then find yourself wondering why you have to convert it into Haskell at all. Given that most mathematics online is typeset using something like latex or mathml, why can't we parse this typesetting and convert it into Haskell code? In all likelyhood the conversion might be ambiguous so some rules might be needed to guide the conversion. Furthermore, if there are editors that allow you to edit these sorts of equations in a wysiwyg style, why not leverage these to edit the Haskell+Math code also in a wysiwyg style. I think this goes to the larger question of why are most programming languages (or to be more exact the way we write programs in those languages) is still based around a linear sequence of tokens rather than something that is more 2D (there is still some linearity as even in math formula there is still a top down and left to right flow). Mark From sebastian.sylvan at gmail.com Fri Aug 21 21:03:10 2009 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Fri Aug 21 20:43:06 2009 Subject: [Haskell-cafe] (no subject) In-Reply-To: <40EBDEED77D2DE44B91E9AFCC63142C8018498EE@uu01msg-exb02.soliscom.uu.nl> References: <40EBDEED77D2DE44B91E9AFCC63142C8018498EE@uu01msg-exb02.soliscom.uu.nl> Message-ID: <3d96ac180908211803w13eea95cq9bde6d82da590d0d@mail.gmail.com> On Fri, Aug 21, 2009 at 11:42 PM, Stavenga, G.C. wrote: > > > Hi, I'm just started to learn Haskell. Coming from a programming contest > background (where it is important to be able to solve problems in a small > amount of code) I'm wondering what the best way is for simple IO. > > A typical input file (in a programming contest) is just a bunch of numbers > which you want to read one by one (sometimes interspersed with strings). In > C/C++ this is easily done with either scanf or cin which reads data > separated by spaces. In Haskell I have not found an equally satisfactionary > method. The methods I know of > > 1) Stay in the IO monad and write your own readInt readString functions. A > lot > of code for something easy. > > 2) Use interact together with words and put the list of lexemes in a State > monad and define getInt where at least you can use read. > > 3) Use ByteString.Char8 which has readInt (but I couldn't find a > readString). But one has to put it also in a State monad. > > I think that there must be standard function that can do this. What do > experienced Haskellers use? > I usually just whip up a quick parser using Text.ParserCombinators.Parsec -- Sebastian Sylvan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090821/52aaf7ca/attachment.html From ramsdell0 at gmail.com Fri Aug 21 21:19:21 2009 From: ramsdell0 at gmail.com (John D. Ramsdell) Date: Fri Aug 21 20:59:18 2009 Subject: [Haskell-cafe] Converting typeset mathematics into Haskell ? In-Reply-To: <4A8F32A2.6060608@bigpond.net.au> References: <4A8F32A2.6060608@bigpond.net.au> Message-ID: <7687290b0908211819t5613a598td83f320325694119@mail.gmail.com> The purpose of mathematic syntax is to comunicate mathematical ideas between humans. Programmirng languages both communicate mathmatical ideas among humans and specify sequences of operations performed by computing machinery to achieve a goal. The trouble is is the first goal is often forgotten. The Haskell community tends to be less likely to forget the first goal. The fact is the dual purpose of programming languages causes conflicts. Let's focus on currying. I'm sure that most in this community think that currying is wonderful, but many pure mathematicians look at us quizically. What's all the excitent about? How does this help me communicate with other homosapians? Comunication appears to be a driving force of the Fortress languge . Personally, I think that Data Parallel Haskell (DPH) plus Haskell's commitment to currying is a viable approach to high performance computing. John From ramsdell0 at gmail.com Fri Aug 21 21:51:58 2009 From: ramsdell0 at gmail.com (John D. Ramsdell) Date: Fri Aug 21 21:31:54 2009 Subject: [Haskell-cafe] Unifcation and matching in Abelian groups In-Reply-To: <4A8D57E1.2050002@jellybean.co.uk> References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> <404396ef0908190316rc772614p9c660c8ab5095ed6@mail.gmail.com> <7687290b0908190345q23313f4bwf24b6868499ee704@mail.gmail.com> <4A8BF0D3.7050403@jellybean.co.uk> <7687290b0908200557i522f3d92jb4d20707baeb3694@mail.gmail.com> <4A8D4AD9.1050701@jellybean.co.uk> <7687290b0908200637u5022c4e6lf76b759a82222f1f@mail.gmail.com> <4A8D57E1.2050002@jellybean.co.uk> Message-ID: <7687290b0908211851n689b8219p6d19c158cf45e090@mail.gmail.com> Let me put all my cards on the table. You see, I really am only slightly irrigated by offset syntax. In contrast, I am a strong proponent of functional programming for parallel programming. In my opinion, it has to be the "new way" for multiprocessor machines. Just think about it and if other paradym could possibly work. We've tried many on them. Many years ago, I wrote SISAl programs. There were many good ideas in SISAL, but it did not catch on. Perhaps Data Parallel Haskell will catch on. In my opinion, something like it is the ``answer.'' Even though the code I submitted is not parallel, I've thought about how to make it so. And isn't thinking parallelism iour future? I think so. John On Thu, Aug 20, 2009 at 10:04 AM, Jules Bean wrote: > John D. Ramsdell wrote: >> >> On Thu, Aug 20, 2009 at 9:08 AM, Jules Bean wrote: >> >>> I don't find layout a problem, with good editor support. I agree it's a >>> problem, with poor editor support. That's all I meant. >> >> Let's put this issue in perspective. ?For those few Haskell >> programmers that do find layout irritating, I'm sure we would all >> agree it's but a minor irritation. ?The real downside of layout is if >> non-Haskell programmers use it as an excuse to dismiss the language. >> I happen to think that Data Parallel Haskell has great potential ?for >> use in high performance computations. ?I'd hate to see a bunch of >> Fortraners not try DPH because of Haskell syntax. > > Well that's a reasonable point. > > They can still use the non-layout form if it bothers them that much? > From lrpalmer at gmail.com Sat Aug 22 02:28:30 2009 From: lrpalmer at gmail.com (Luke Palmer) Date: Sat Aug 22 02:08:25 2009 Subject: [Haskell-cafe] (no subject) In-Reply-To: <3d96ac180908211803w13eea95cq9bde6d82da590d0d@mail.gmail.com> References: <40EBDEED77D2DE44B91E9AFCC63142C8018498EE@uu01msg-exb02.soliscom.uu.nl> <3d96ac180908211803w13eea95cq9bde6d82da590d0d@mail.gmail.com> Message-ID: <7ca3f0160908212328o5bc005f9g4eba30cfd60f6b8c@mail.gmail.com> On Fri, Aug 21, 2009 at 7:03 PM, Sebastian Sylvan wrote: >> I think that there must be standard function that can do this. What do >> experienced Haskellers use? > > I usually just whip up a quick parser using?Text.ParserCombinators.Parsec I usually prefer ReadP for quick stuff, for an unknown reason. I guess it feels like there is less infrastructure to penetrate, it gives me the primitives and I structure the parser according to my needs. But yeah, I think parser combinators are the way to go. It's really not much work at all once you get the hang of it. From plastermoso at hotmail.com Fri Aug 21 15:00:58 2009 From: plastermoso at hotmail.com (Roberto) Date: Sat Aug 22 03:30:00 2009 Subject: [Haskell-cafe] Is logBase right? Message-ID: Hi, There is a mistake is logBase: $ ghci GHCi, version 6.10.4: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. Prelude> logBase 10 10 1.0 Prelude> logBase 10 100 2.0 Prelude> logBase 10 1000 2.9999999999999996 <--- eeeerrgghhhh! Prelude> logBase 10 10000 4.0 My host is a Debian GNU/Linux 5.0.2 (lenny) with the following GHC packages: ii ghc6 6.10.4-1 ii ghc6-doc 6.10.4-1 ii libghc6-mtl-dev 1.1.0.2-7+b1 ii libghc6-utf8-string-dev 0.3.5-1+b1 ii libghc6-x11-dev 1.4.5-6 rc libghc6-x11-doc 1.4.2-1 ii libghc6-x11-xft-dev 0.3-3+b3 ii libghc6-xmonad-contrib-dev 0.8.1-3+b3 rc libghc6-xmonad-contrib-doc 0.8-2 ii libghc6-xmonad-dev 0.8.1-5 Regards! From ekirpichov at gmail.com Sat Aug 22 04:02:20 2009 From: ekirpichov at gmail.com (Eugene Kirpichov) Date: Sat Aug 22 03:42:17 2009 Subject: [Haskell-cafe] Is logBase right? In-Reply-To: References: Message-ID: <5e0214850908220102n52d636duf1848828dfd9c3f5@mail.gmail.com> What do you consider to be the specification of logBase? Exact floating-point numbers don't exist, so it has to return an approximation. The standard doesn't give any guarantees as to the precision of the approximation. Is a precision of 0.00000000000004 not satisfactory for you? 2009/8/21 Roberto : > Hi, > > There is a mistake is logBase: > > $ ghci > GHCi, version 6.10.4: http://www.haskell.org/ghc/ ?:? for help > Loading package ghc-prim ... linking ... done. > Loading package integer ... linking ... done. > Loading package base ... linking ... done. > Prelude> logBase 10 10 > 1.0 > Prelude> logBase 10 100 > 2.0 > Prelude> logBase 10 1000 > 2.9999999999999996 ? ? ? ? ? ? ? ? ?<--- eeeerrgghhhh! > Prelude> logBase 10 10000 > 4.0 > > > My host is a Debian GNU/Linux 5.0.2 (lenny) with the following GHC packages: > > ii ?ghc6 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 6.10.4-1 > ii ?ghc6-doc ? ? ? ? ? ? ? ? ? ? ? ? ? ? 6.10.4-1 > ii ?libghc6-mtl-dev ? ? ? ? ? ? ? ? ? ? ?1.1.0.2-7+b1 > ii ?libghc6-utf8-string-dev ? ? ? ? ? ? ?0.3.5-1+b1 > ii ?libghc6-x11-dev ? ? ? ? ? ? ? ? ? ? ?1.4.5-6 > rc ?libghc6-x11-doc ? ? ? ? ? ? ? ? ? ? ?1.4.2-1 > ii ?libghc6-x11-xft-dev ? ? ? ? ? ? ? ? ?0.3-3+b3 > ii ?libghc6-xmonad-contrib-dev ? ? ? ? ? 0.8.1-3+b3 > rc ?libghc6-xmonad-contrib-doc ? ? ? ? ? 0.8-2 > ii ?libghc6-xmonad-dev ? ? ? ? ? ? ? ? ? 0.8.1-5 > > Regards! > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Eugene Kirpichov Web IR developer, market.yandex.ru From mwotton at gmail.com Sat Aug 22 04:02:51 2009 From: mwotton at gmail.com (Mark Wotton) Date: Sat Aug 22 03:42:54 2009 Subject: [Haskell-cafe] Is logBase right? In-Reply-To: References: Message-ID: he who compares floating point numbers for equality is in a state of sin. mark On 22/08/2009, at 5:00 AM, Roberto wrote: > Hi, > > There is a mistake is logBase: > > $ ghci > GHCi, version 6.10.4: http://www.haskell.org/ghc/ :? for help > Loading package ghc-prim ... linking ... done. > Loading package integer ... linking ... done. > Loading package base ... linking ... done. > Prelude> logBase 10 10 > 1.0 > Prelude> logBase 10 100 > 2.0 > Prelude> logBase 10 1000 > 2.9999999999999996 <--- eeeerrgghhhh! > Prelude> logBase 10 10000 > 4.0 > > > My host is a Debian GNU/Linux 5.0.2 (lenny) with the following GHC > packages: > > ii ghc6 6.10.4-1 > ii ghc6-doc 6.10.4-1 > ii libghc6-mtl-dev 1.1.0.2-7+b1 > ii libghc6-utf8-string-dev 0.3.5-1+b1 > ii libghc6-x11-dev 1.4.5-6 > rc libghc6-x11-doc 1.4.2-1 > ii libghc6-x11-xft-dev 0.3-3+b3 > ii libghc6-xmonad-contrib-dev 0.8.1-3+b3 > rc libghc6-xmonad-contrib-doc 0.8-2 > ii libghc6-xmonad-dev 0.8.1-5 > > Regards! > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From plastermoso at hotmail.com Sat Aug 22 05:24:21 2009 From: plastermoso at hotmail.com (Roberto =?UTF-8?B?TMOzcGV6?=) Date: Sat Aug 22 05:04:45 2009 Subject: [Haskell-cafe] Re: Is logBase right? References: <5e0214850908220102n52d636duf1848828dfd9c3f5@mail.gmail.com> Message-ID: If 4.0 / 2.0 was 1.9999999999999999999998, it would be ok? The real value of log10 1000 is 3 (3.0). It can be represented with accuracy and it should be. You get the accuracy value in Perl, but there is the same problem in Python. It's a bit discouraging. Eugene Kirpichov wrote: > What do you consider to be the specification of logBase? Exact > floating-point numbers don't exist, so it has to return an > approximation. The standard doesn't give any guarantees as to the > precision of the approximation. Is a precision of 0.00000000000004 not > satisfactory for you? > From ekirpichov at gmail.com Sat Aug 22 05:34:51 2009 From: ekirpichov at gmail.com (Eugene Kirpichov) Date: Sat Aug 22 05:14:46 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: References: <5e0214850908220102n52d636duf1848828dfd9c3f5@mail.gmail.com> Message-ID: <5e0214850908220234k6dd9f205pe59d5e2a17c8d627@mail.gmail.com> 2009/8/22 Roberto L?pez : > If 4.0 / 2.0 was 1.9999999999999999999998, it would be ok? I think yes. However, hardware can afford to do computations "as accurately as possible", whereas software like Haskell Prelude can't. > > The real value of log10 1000 is 3 (3.0). It can be represented with accuracy > and it should be. Doing so would not be of much use and would impose a performance penalty required to achieve this accuracy. I looked into the Prelude source and saw that logBase is implemented like x`logBase`y = log x / log y. I think it is quite a sensible definition, and there's no point in modifying it just to make accuracy even better than 0.000000000000000004 in certain cases where it is possible. To my mind, an accuracy of "the representable number closest to the exact answer" is only required in very specific circumstances, for example when you are converting a string to a float. If you have a good reason to need exact real numbers, you can use a corresponding package for exact reals. However, if you propose an equivalently fast definition of logBase that achieves better accuracy, I am sure it will be much welcomed. > > You get the accuracy value in Perl, but there is the same problem in Python. > It's a bit discouraging. > > > Eugene Kirpichov wrote: > >> What do you consider to be the specification of logBase? Exact >> floating-point numbers don't exist, so it has to return an >> approximation. The standard doesn't give any guarantees as to the >> precision of the approximation. Is a precision of 0.00000000000004 not >> satisfactory for you? >> > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Eugene Kirpichov Web IR developer, market.yandex.ru From miguelimo38 at yandex.ru Sat Aug 22 06:00:26 2009 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Sat Aug 22 05:40:24 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: References: <5e0214850908220102n52d636duf1848828dfd9c3f5@mail.gmail.com> Message-ID: Even in Perl you've got MigMit:~ MigMit$ perl -e 'printf("%.20f\n",log(125)/log(5))' 3.00000000000000044409 On 22 Aug 2009, at 13:24, Roberto L?pez wrote: > If 4.0 / 2.0 was 1.9999999999999999999998, it would be ok? > > The real value of log10 1000 is 3 (3.0). It can be represented with > accuracy > and it should be. > > You get the accuracy value in Perl, but there is the same problem in > Python. > It's a bit discouraging. > > > Eugene Kirpichov wrote: > >> What do you consider to be the specification of logBase? Exact >> floating-point numbers don't exist, so it has to return an >> approximation. The standard doesn't give any guarantees as to the >> precision of the approximation. Is a precision of 0.00000000000004 >> not >> satisfactory for you? >> > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From ttencate at gmail.com Sat Aug 22 06:32:17 2009 From: ttencate at gmail.com (Thomas ten Cate) Date: Sat Aug 22 06:12:13 2009 Subject: [Haskell-cafe] (no subject) In-Reply-To: <25088830.post@talk.nabble.com> References: <40EBDEED77D2DE44B91E9AFCC63142C8018498EE@uu01msg-exb02.soliscom.uu.nl> <20090821224221.GE15454@whirlpool.galois.com> <25088830.post@talk.nabble.com> Message-ID: On Sat, Aug 22, 2009 at 01:23, staafmeister wrote: > But in general you have a structure like > > first line -- integer specifying the number of testcases (n) > Then for each testcase > a line with an integer specifying the number of edges (e) > a line with e pairs of string s and int p where p is the number asociated > with string s, etc. > > Such a structure cannot be parsed by map read.lines > What I used is "words" to tokenize and put the list in a State monad with > readInt, readString, etc. functions, to mimic > C code. This seems to be a lot of overkill, so there must be an simpler > way Although you most certainly can use a State monad, in most problems this isn't necessary. Most algorithms that you need to solve programming contest problems can be written in a purely functional style, so you can limit monadic code to just a few helper functions. For example, this reads input in the style you mention (assuming the strings don't contain whitespace): > import Control.Monad > > answer = id > > parse [] = [] > parse (s:p:r) = (s, (read p) :: Int) : parse r > > run = getLine >> getLine >>= putStrLn . show . answer . parse . words > > main = flip replicateM_ run =<< readLn The answer function would be a pure function that computes the answer for a particular run. This main function is reusable for all problems with many runs. Observe that the number of edges (e), provided as a convenience for memory allocation in many other languages, is not even necessary in Haskell :) (If anyone knows a better way than explicit recursion to map over a list, two elements at a time, or zip its even elements with its odd elements, I'd love to hear! I can imagine a convoluted fold with a boolean in its state, but it's ugly.) Hope that helps, Thomas From bugfact at gmail.com Sat Aug 22 06:35:52 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Sat Aug 22 06:15:48 2009 Subject: [Haskell-cafe] Help starting a Haskell blog Message-ID: I'm going start my very first blog, documenting my everyday struggle to switch my old imperative mind to the lazy functional setting, with a focus on FRP. Although you can find a lot of articles that provide help to get started with general blogging, it might be useful to pick a blog in which presenting Haskell code is easy (e.g. like hpaste that does the syntax coloring for you), and where users can give feedback, providing code, also with syntax coloring preferably. It would also be nice to allow hyperlinking every function in the code to the standard Haskell library docs or to the docs on Hackage. Googling for "how to start a Haskell blog" just revealed a lot of Haskell blogs. Could you share your experiences with me about starting a blog? BTW: I'm on Windows. Thanks a lot, Peter Verswyvelen -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090822/6d09ac05/attachment.html From gwern0 at gmail.com Sat Aug 22 06:51:18 2009 From: gwern0 at gmail.com (Gwern Branwen) Date: Sat Aug 22 06:31:12 2009 Subject: [Haskell-cafe] Help starting a Haskell blog In-Reply-To: References: Message-ID: On Sat, Aug 22, 2009 at 6:35 AM, Peter Verswyvelen wrote: > I'm going start my very first blog, documenting my everyday struggle to > switch my old imperative mind to the lazy functional setting, with a focus > on FRP. > Although you can find a lot of articles that provide help to get started > with general blogging, it might be useful to pick a blog in which presenting > Haskell code is easy (e.g. like hpaste that does the syntax coloring for > you), and where users can give feedback, providing code, also with syntax > coloring preferably. It would also be nice to allow hyperlinking every > function in the code to the standard Haskell library docs or to the docs on > Hackage. > Googling for "how to start a Haskell blog" just revealed a lot of Haskell > blogs. > Could you share your experiences with me about starting a blog? > BTW: I'm on Windows. > Thanks a lot, > Peter Verswyvelen Being a lazy person, I would just use Gitit. There are a lot of advantages to doing so. You get the highlighting-kate syntax-hilighting for your Haskell code (and your Scheme code and your...); you get a server; you get various plugins like interwiki links to all the Wikipedias and Wikias or graphviz image generation; you get RSS feeds for pages*, such as your Front Page so you can in effect have your Front Page be a blog just by writing articles and adding to the Front Page a link to them; you get sane markup (either Markup, Markdown, or literate Haskell), which *won't* mangle, spindle, and fold whatever you write**; you get a nice Git or Darcs repo of your writings which you can share or backup; etc. About the only disadvantages to this lightweight blogging approach are that the wiki might not look 'blog-like' unless you edit the CSS/HTML, and Gitit currently doesn't allow anonymous page creation or edits of the Discussion pages. (I'm fairly sure Gitit is supposed to work on Windows, also.) * HEAD only ** sad to say, not something that can be assumed; more than once I've seen Haskell-related blog posts or comments get mangled by the blogging software -- gwern From ivan.miljenovic at gmail.com Sat Aug 22 07:06:53 2009 From: ivan.miljenovic at gmail.com (Ivan Lazar Miljenovic) Date: Sat Aug 22 06:46:54 2009 Subject: [Haskell-cafe] Requesting suggestions for the GraphViz library Message-ID: <87bpm85cqa.fsf@gmail.com> Whilst I've apparently been on holidays overseas, I was bored enough (and frustrated enough with it) to re-write large parts of the GraphViz library. In particular, I now use a pretty-printing class and a new parsing class so I think the problem with quotes is over \o/ However, there are some design decisions I'd like advice on from users of this library; these are items that I can implement either way but I'm not sure what other people would prefer: * I have re-written large parts of the overall DotGraph and associated data structures, with one difference being that they are polymorphic in the node type; this should make the eventual change to the generic graph class (whenever we get around to doing it) simpler. However, I have left the ID of the DotGraph and the new DotSubGraph data structures as being the GraphID type (which is an algebraic type with number, string and URL support to match the official types of values understood by GraphViz); should I leave it as this or make them polymorphic in the Graph ID type as well? That is, you would have something like "DotGraph l n", with `l' being the type of the GraphIDs and `n' being the type of the node IDs. * With parsing of Dot code, the new data structure layout now more fully/correctly supports upstream by specifying a "DotStatements" data structure for use with DotGraph and DotSubGraph; DotStatements contains a list of (Global) Attributes, a list of DotSubGraphs, a list of Nodes and a list of Edges. At the moment, the parser expects these four types of statements to indeed be listed in that order, though it would be feasible to have the parser accept them in any order and then split them into these four types. Note that this could change the behaviour of how the graph is drawn (specifically in terms of where the Attributes are listed). Do people want a fully-fledged/capable parser or is the current setup sufficient? * The FGL <-> DotGraph functions now have the option to take a Bool parameter which indicates whether the specified graph is directed or undirected (with primed versions attempting to automatically determine this). If the graph is indicated to be undirected, then an edge (n1,n2) is kept if n1 <= n2; should I replace this Bool with a ternary algebraic type that allows the user to indicate that the graph is undirected but to keep all edges? * In the current available release, I had rudimentary error detection support for misuse of attributes. I have re-written this to an extent, and can do so even more to find even more possible errors (e.g. duplicate node IDs); do people actually care about this type of error detection? Am I just wasting my time on this? * With Color values (and since the issue seems to have re-arisen about spelling regarding Russell O'Connor's colour package, I use the American spelling because that's what upstream uses), I do not as yet bother matching up String color names with the colorset being used, etc. Something like this would require a State-based parser; does anyone care enough about this that they want it? The same thing goes for LayerSep, etc. Note that the user would then have to check themselves to make sure that they are using these correctly (that is, they have previously set which colorset they are using). If you're interested in seeing exactly what I've done, the darcs repo is at http://code.haskell.org/graphviz. Han Joosten has already asked me to implement record-based shapes, which I'll be looking at at some point to see how I can implement it into the current system. Otherwise, out of the 7 items on the TODO list I had from the previous version, this as-yet unreleased version has fixed 4 of them. If there's any other requests on what to do, please let me know. -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com From bugfact at gmail.com Sat Aug 22 09:34:09 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Sat Aug 22 09:14:08 2009 Subject: [Haskell-cafe] Help starting a Haskell blog In-Reply-To: References: Message-ID: Thanks. At first sight gitit requires that I setup my own server. Although this has advantages and I did that in the past, I prefer to use a public server (actually my internet provider's license forbids hosting a server) Does one exist for gitit? Also Gitit is an unfortunate name since "Git It" has become a saying apparently, so googling for it give me all the wrong hits ;-) Bing guided me towards http://www.johnmacfarlane.net, but I guess that site is just a showcase for the author? On Sat, Aug 22, 2009 at 12:51 PM, Gwern Branwen wrote: > On Sat, Aug 22, 2009 at 6:35 AM, Peter Verswyvelen > wrote: > > I'm going start my very first blog, documenting my everyday struggle to > > switch my old imperative mind to the lazy functional setting, with a > focus > > on FRP. > > Although you can find a lot of articles that provide help to get started > > with general blogging, it might be useful to pick a blog in which > presenting > > Haskell code is easy (e.g. like hpaste that does the syntax coloring for > > you), and where users can give feedback, providing code, also with syntax > > coloring preferably. It would also be nice to allow hyperlinking every > > function in the code to the standard Haskell library docs or to the docs > on > > Hackage. > > Googling for "how to start a Haskell blog" just revealed a lot of Haskell > > blogs. > > Could you share your experiences with me about starting a blog? > > BTW: I'm on Windows. > > Thanks a lot, > > Peter Verswyvelen > > Being a lazy person, I would just use Gitit. There are a lot of > advantages to doing so. > > You get the highlighting-kate syntax-hilighting for your Haskell code > (and your Scheme code and your...); you get a server; you get various > plugins like interwiki links to all the Wikipedias and Wikias or > graphviz image generation; you get RSS feeds for pages*, such as your > Front Page so you can in effect have your Front Page be a blog just by > writing articles and adding to the Front Page a link to them; you get > sane markup (either Markup, Markdown, or literate Haskell), which > *won't* mangle, spindle, and fold whatever you write**; you get a nice > Git or Darcs repo of your writings which you can share or backup; etc. > > About the only disadvantages to this lightweight blogging approach are > that the wiki might not look 'blog-like' unless you edit the CSS/HTML, > and Gitit currently doesn't allow anonymous page creation or edits of > the Discussion pages. (I'm fairly sure Gitit is supposed to work on > Windows, also.) > > * HEAD only > ** sad to say, not something that can be assumed; more than once I've > seen Haskell-related blog posts or comments get mangled by the > blogging software > > -- > gwern > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090822/dc94e4ea/attachment.html From daniel.is.fischer at web.de Sat Aug 22 10:14:03 2009 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Sat Aug 22 09:54:59 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: <5e0214850908220234k6dd9f205pe59d5e2a17c8d627@mail.gmail.com> References: <5e0214850908220234k6dd9f205pe59d5e2a17c8d627@mail.gmail.com> Message-ID: <200908221614.04057.daniel.is.fischer@web.de> Am Samstag 22 August 2009 11:34:51 schrieb Eugene Kirpichov: > 2009/8/22 Roberto L?pez : > > If 4.0 / 2.0 was 1.9999999999999999999998, it would be ok? > > I think yes. I don't. Not for (+), (-), (*), (/). There I want "the representable number closest to the exact answer". > However, hardware can afford to do computations "as > accurately as possible", whereas software like Haskell Prelude can't. > > > The real value of log10 1000 is 3 (3.0). It can be represented with > > accuracy and it should be. > > Doing so would not be of much use and would impose a performance > penalty required to achieve this accuracy. +1 It is so rare that such functions have exactly representable results that it's absolutely not worth to check. Hence it is the programmer's obligation to test and adjust if it's moderately likely that such a case arises and it's important. From g.c.stavenga at uu.nl Sat Aug 22 10:20:05 2009 From: g.c.stavenga at uu.nl (staafmeister) Date: Sat Aug 22 09:59:59 2009 Subject: [Haskell-cafe] (no subject) In-Reply-To: References: <40EBDEED77D2DE44B91E9AFCC63142C8018498EE@uu01msg-exb02.soliscom.uu.nl> <20090821224221.GE15454@whirlpool.galois.com> <25088830.post@talk.nabble.com> Message-ID: <25094244.post@talk.nabble.com> Thank you for the reply. Thomas ten Cate wrote: > > Although you most certainly can use a State monad, in most problems > this isn't necessary. Most algorithms that you need to solve > programming contest problems can be written in a purely functional > style, so you can limit monadic code to just a few helper functions. > Yes I know but there are a lot of problems requiring O(1) array updates so then you are stuck with IO again Thomas ten Cate wrote: > > For example, this reads input in the style you mention (assuming the > strings don't contain whitespace): > >> import Control.Monad >> >> answer = id >> >> parse [] = [] >> parse (s:p:r) = (s, (read p) :: Int) : parse r >> >> run = getLine >> getLine >>= putStrLn . show . answer . parse . words >> >> main = flip replicateM_ run =<< readLn > > The answer function would be a pure function that computes the answer > for a particular run. This main function is reusable for all problems > with many runs. > > Observe that the number of edges (e), provided as a convenience for > memory allocation in many other languages, is not even necessary in > Haskell :) > Yes you're main is short. But how would you do it elegantly if instead of line breaks and spaces one would have only spaces. Every thing on one big line. My C code would not mind one bit. Thomas ten Cate wrote: > > (If anyone knows a better way than explicit recursion to map over a > list, two elements at a time, or zip its even elements with its odd > elements, I'd love to hear! I can imagine a convoluted fold with a > boolean in its state, but it's ugly.) > Yes I missed such a function in a couple of problems I wanted to solve. I would expect a generic function groupN::Int -> [a] -> [[a]] that groups a list into groups of N Best, Gerben -- View this message in context: http://www.nabble.com/%28no-subject%29-tp25088427p25094244.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From sebastian.sylvan at gmail.com Sat Aug 22 11:36:39 2009 From: sebastian.sylvan at gmail.com (Sebastian Sylvan) Date: Sat Aug 22 11:16:33 2009 Subject: [Haskell-cafe] (no subject) In-Reply-To: <25094244.post@talk.nabble.com> References: <40EBDEED77D2DE44B91E9AFCC63142C8018498EE@uu01msg-exb02.soliscom.uu.nl> <20090821224221.GE15454@whirlpool.galois.com> <25088830.post@talk.nabble.com> <25094244.post@talk.nabble.com> Message-ID: <3d96ac180908220836w50b8425bkf543a965ee8e8adf@mail.gmail.com> On Sat, Aug 22, 2009 at 3:20 PM, staafmeister wrote: > > > Thank you for the reply. > > > Thomas ten Cate wrote: > > > > Although you most certainly can use a State monad, in most problems > > this isn't necessary. Most algorithms that you need to solve > > programming contest problems can be written in a purely functional > > style, so you can limit monadic code to just a few helper functions. > > > > Yes I know but there are a lot of problems requiring O(1) array updates > so then you are stuck with IO again Not necessarily. The ST monad will usually do just as well. -- Sebastian Sylvan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090822/e598bff3/attachment.html From jeremy at n-heptane.com Sat Aug 22 12:49:02 2009 From: jeremy at n-heptane.com (Jeremy Shaw) Date: Sat Aug 22 12:28:57 2009 Subject: [Haskell-cafe] Help starting a Haskell blog In-Reply-To: References: Message-ID: <87k50vztdt.wl%jeremy@n-heptane.com> Hello, What I do is I write my blog posts using a literate Haskell + html. This allows me to actually run all the code and make sure it works. I can then use hscolour to transform the literal Haskell into html (with syntax highlighting). As a reader, I think you imagine that I have two distinct things: 1. some application I have written with comments, etc 2. a blog post I have written about the app, by copying and pasting the code into the blog post But, having two copies of the code in play is tricky. Instead I have a single set of source, and I generate the normal looking code and the blog post from the same source. This ensures that everything stays in-sync. So, I actually have three things going on: 1. a literate Haskell document which contains the source code, the blog post markup, and is directly executable. I can load this document directly into GHCi while I work on it -- no extra steps required. From that literate document I generate: 2. a blog post where all the source code has been highlighting via HsColour. The non-source parts are just the HTML I wrote in the literate comments. 3. a plain old Haskell code version of my codebase which includes Haskell comments, but none of the literate comments. This post: http://nhlab.blogspot.com/2008_07_01_archive.html was generated from this source: darcs get http://src.seereason.com/examples/happs-hsp-quickstart/ running 'make' will generate the html which can be copied into the blog posting form. running 'make test' will actually run the literate code. running 'make template' will produce a non-literate version of the code base in the template directory. The following 'tricks' are used: 1. use cpp and #ifdef HsColour, so that some bits of code get syntax highlighting, but aren't compiled when you actually run the literate Haskell. 2. If your application is spread across multiple modules, you can use: #ifdef HsColour #include "SimpleExample.lhs" #endif to merge all the dependent modules into a single .html file. 3. Sometimes in a blog post you want to show multiple interations of a function. But, you can't reuse the same name because you get name collisions, so you have to keep renaming the function as you talk about it: myfunc = ... myfunc' = ... myfunc'' = ... sometimes you can work around this by putting each iteration in a separate file, #ifdef HsColour #include "MyFunc1.lhs" #endif #ifdef HsColour #include "MyFunc2.lhs" #endif #ifdef HsColour #include "MyFunc3.lhs" #endif You can then run each version independently in ghci to test them, but they will all be included in the master .html file. 4. The following targets run the preprocessor and then invoke HsColour with the correct arguments for turning code parts into html while preserving the existing html in the literate comments: %.html: %.cpphs HsColour -css $< -o$@ -lit validate -w --verbose --emacs $@ %.cpphs: %.lhs cpp -traditional-cpp -DHsColour -P $< $@ 5. this target can be used to extract just the non-literate parts from the .lhs %.hs: %.lhs sed -n 's/^> \?//p' $^ > $@ 6. hide the pre-processor option In order to be able to load the .lhs files into GHCi, the preprocessor needs to run. But, that is just a side effect of this blogging system, so I don't want the pragma for running cpp to show up in the blog post itself. This turns out to be a bit tricky. The work around is to enable the cpp flag inside an HTML comment, so that the option is enabled, but the user doesn't see it: 7. other And, finally, to get the highlight code to show up highlight in blogger, I had to modify my default blogger template to include the css from emacs.css in the HsColour package. I don't claim that this is the most elegant setup. It's key benefits are that you can actually run the code in the blog post, and not worry about copy and paste errors, or updating your code and forgetting to update the blog post as well. Additionally, you can automatically extract the code and non-literate comments from the blogpost to get a nice stand alone, commented program. I like this approach, because as I blog about an application, I often see improvements, bug fixes, or other changes I want to make. By having only one copy of the code, I don't have to worry about the blog post and code base getting out of sync. - jeremy p.s. That post is old and depends on a bunch of obsolete libraries, so I would not spend anytime trying to get the Haskell code in it to actually run. At Sat, 22 Aug 2009 12:35:52 +0200, Peter Verswyvelen wrote: > > [1 ] > [1.1 ] > I'm going start my very first blog, documenting my everyday struggle to > switch my old imperative mind to the lazy functional setting, with a focus > on FRP. > Although you can find a lot of articles that provide help to get started > with general blogging, it might be useful to pick a blog in which presenting > Haskell code is easy (e.g. like hpaste that does the syntax coloring for > you), and where users can give feedback, providing code, also with syntax > coloring preferably. It would also be nice to allow hyperlinking every > function in the code to the standard Haskell library docs or to the docs on > Hackage. > > Googling for "how to start a Haskell blog" just revealed a lot of Haskell > blogs. > > Could you share your experiences with me about starting a blog? > > BTW: I'm on Windows. > > Thanks a lot, > Peter Verswyvelen > [1.2 ] > > [2 ] > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From dpiponi at gmail.com Sat Aug 22 12:56:16 2009 From: dpiponi at gmail.com (Dan Piponi) Date: Sat Aug 22 12:36:10 2009 Subject: [Haskell-cafe] Help starting a Haskell blog In-Reply-To: References: Message-ID: <625b74080908220956g20b506fw7e4864ed06c173cf@mail.gmail.com> On Sat, Aug 22, 2009 at 3:35 AM, Peter Verswyvelen wrote: > Could you share your experiences with me about starting a blog? > BTW: I'm on Windows. I've found it hard work to post a mixture of English, Mathematics and Haskell. Neither of the most popular blogging web sites are very helpful in this regard: wordpress.com and blogger.com. I did write a little Haskell program to do some markup suitable for blogger.com but it's very limited for embedding mathematics, knowing only a handful of TeX commands, and doesn't play well with blogger's system for uploading images. Wordpress looked good at first but I found all kinds of problems with it. I guess I should force myself to catch up with the 21st century and learn how to write code to talk directly to these web sites, but I find it hard to motivate myself to be interested in writing code for all that HTML/XML/ATOM/ stuff. (I think my day job is one of the few remaining software jobs that hasn't been XMLified.) But I've seen lots of nice Haskell blogs with embedded mathematics so there must be good solutions out there. What are they? What I'd really like is to blog in PDF. -- Dan From plastermoso at hotmail.com Sat Aug 22 13:19:26 2009 From: plastermoso at hotmail.com (Roberto =?UTF-8?B?TMOzcGV6?=) Date: Sat Aug 22 12:59:47 2009 Subject: [Haskell-cafe] How to calculate de number of digits of an integer? (was: Is logBase right?) Message-ID: Ok. I wonder if someone could help me with this problem... I want to calculate the number of digits of a positive integer. I was thinking of ... numDigits n = truncate (logBase 10 n) + 1 But (logBase 10 1000) = 2.9999999999999996 so numDigits 1000 = 2. Maybe adding a small amount numDigits n = truncate ((logBase 10 n) + 0.0000000000000005) + 1 Prelude> numDigits 100 3 Prelude> numDigits 1000 4 Prelude> numDigits 10000 5 Prelude> numDigits 10000 5 Prelude> numDigits 100000 6 Prelude> numDigits 1000000 7 Prelude> numDigits 10000000 8 Prelude> numDigits 100000000 9 Prelude> numDigits 1000000000 9 <---- This is wrong!!!! Prelude> numDigits 10000000000 11 Is there a reliable way to calculate the number of digits by means of logBase? Regards! From ekirpichov at gmail.com Sat Aug 22 13:23:47 2009 From: ekirpichov at gmail.com (Eugene Kirpichov) Date: Sat Aug 22 13:03:41 2009 Subject: [Haskell-cafe] How to calculate de number of digits of an integer? (was: Is logBase right?) In-Reply-To: References: Message-ID: <5e0214850908221023u62c29bb9r385b3fbcdf1ac4c8@mail.gmail.com> Use 'round' instead of 'truncate'. Prelude> let numDigits = (+1) . round . logBase 10 . fromIntegral Prelude> map (numDigits . (10^)) [0..9] [1,2,3,4,5,6,7,8,9,10] 2009/8/22 Roberto L?pez : > Ok. I wonder if someone could help me with this problem... > > I want to calculate the number of digits of a positive integer. I was > thinking of ... > > ? ? ? ?numDigits n = truncate (logBase 10 n) + 1 > > But (logBase 10 1000) = 2.9999999999999996 so numDigits 1000 = 2. > > Maybe adding a small amount > > ? ? ? ?numDigits n = truncate ((logBase 10 n) + 0.0000000000000005) + 1 > > Prelude> numDigits 100 > 3 > Prelude> numDigits 1000 > 4 > Prelude> numDigits 10000 > 5 > Prelude> numDigits 10000 > 5 > Prelude> numDigits 100000 > 6 > Prelude> numDigits 1000000 > 7 > Prelude> numDigits 10000000 > 8 > Prelude> numDigits 100000000 > 9 > Prelude> numDigits 1000000000 > 9 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?<---- This is wrong!!!! > Prelude> numDigits 10000000000 > 11 > > Is there a reliable way to calculate the number of digits by means of > logBase? > > > Regards! > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Eugene Kirpichov Web IR developer, market.yandex.ru From ekirpichov at gmail.com Sat Aug 22 13:25:37 2009 From: ekirpichov at gmail.com (Eugene Kirpichov) Date: Sat Aug 22 13:05:32 2009 Subject: [Haskell-cafe] How to calculate de number of digits of an integer? (was: Is logBase right?) In-Reply-To: <5e0214850908221023u62c29bb9r385b3fbcdf1ac4c8@mail.gmail.com> References: <5e0214850908221023u62c29bb9r385b3fbcdf1ac4c8@mail.gmail.com> Message-ID: <5e0214850908221025m4c6dd988g66260afd25a1f890@mail.gmail.com> Or better numDigits = length . show It's probably even faster. 2009/8/22 Eugene Kirpichov : > Use 'round' instead of 'truncate'. > > Prelude> let numDigits = (+1) . round . logBase 10 . fromIntegral > Prelude> map (numDigits . (10^)) [0..9] > [1,2,3,4,5,6,7,8,9,10] > > 2009/8/22 Roberto L?pez : >> Ok. I wonder if someone could help me with this problem... >> >> I want to calculate the number of digits of a positive integer. I was >> thinking of ... >> >> ? ? ? ?numDigits n = truncate (logBase 10 n) + 1 >> >> But (logBase 10 1000) = 2.9999999999999996 so numDigits 1000 = 2. >> >> Maybe adding a small amount >> >> ? ? ? ?numDigits n = truncate ((logBase 10 n) + 0.0000000000000005) + 1 >> >> Prelude> numDigits 100 >> 3 >> Prelude> numDigits 1000 >> 4 >> Prelude> numDigits 10000 >> 5 >> Prelude> numDigits 10000 >> 5 >> Prelude> numDigits 100000 >> 6 >> Prelude> numDigits 1000000 >> 7 >> Prelude> numDigits 10000000 >> 8 >> Prelude> numDigits 100000000 >> 9 >> Prelude> numDigits 1000000000 >> 9 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?<---- This is wrong!!!! >> Prelude> numDigits 10000000000 >> 11 >> >> Is there a reliable way to calculate the number of digits by means of >> logBase? >> >> >> Regards! >> >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> > > > > -- > Eugene Kirpichov > Web IR developer, market.yandex.ru > -- Eugene Kirpichov Web IR developer, market.yandex.ru From derek.a.elkins at gmail.com Sat Aug 22 13:31:31 2009 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Sat Aug 22 13:11:25 2009 Subject: [Haskell-cafe] How to calculate de number of digits of an integer? (was: Is logBase right?) In-Reply-To: <5e0214850908221023u62c29bb9r385b3fbcdf1ac4c8@mail.gmail.com> References: <5e0214850908221023u62c29bb9r385b3fbcdf1ac4c8@mail.gmail.com> Message-ID: <61f84eff0908221031p123615f8kf2e22a245d20677b@mail.gmail.com> 2009/8/22 Eugene Kirpichov : > Use 'round' instead of 'truncate'. > > Prelude> let numDigits = (+1) . round . logBase 10 . fromIntegral > Prelude> map (numDigits . (10^)) [0..9] > [1,2,3,4,5,6,7,8,9,10] > round won't work because 999 is close to 1000. You simply need to use logBase 10 as a guess and then check the answer, e.g. numDigits n | n < n' = e | otherwise = e + 1 where e = ceiling $ logBase 10 $ fromIntegral n n' = 10^e This will need to special case 0 which it currently doesn't do. From derek.a.elkins at gmail.com Sat Aug 22 13:33:47 2009 From: derek.a.elkins at gmail.com (Derek Elkins) Date: Sat Aug 22 13:13:40 2009 Subject: [Haskell-cafe] How to calculate de number of digits of an integer? (was: Is logBase right?) In-Reply-To: <61f84eff0908221031p123615f8kf2e22a245d20677b@mail.gmail.com> References: <5e0214850908221023u62c29bb9r385b3fbcdf1ac4c8@mail.gmail.com> <61f84eff0908221031p123615f8kf2e22a245d20677b@mail.gmail.com> Message-ID: <61f84eff0908221033x11086828m7fce7b59e632c78e@mail.gmail.com> On Sat, Aug 22, 2009 at 12:31 PM, Derek Elkins wrote: > 2009/8/22 Eugene Kirpichov : >> Use 'round' instead of 'truncate'. >> >> Prelude> let numDigits = (+1) . round . logBase 10 . fromIntegral >> Prelude> map (numDigits . (10^)) [0..9] >> [1,2,3,4,5,6,7,8,9,10] >> > > round won't work because 999 is close to 1000. > > You simply need to use logBase 10 as a guess and then check the answer, e.g. > numDigits n | n < n' ? ? ? = e > ? ? ? ? ? ? ? ? ?| otherwise = e + 1 > ? ?where e = ceiling $ logBase 10 $ fromIntegral n > ? ? ? ? ? ? n' = 10^e > This will need to special case 0 which it currently doesn't do. > Note that logBase 10 will start failing for large Integers (or rather fromIntegral will.) Writing an integer log using a binary search would be relatively easy, reasonably efficient, and would work for all Integers. From ekirpichov at gmail.com Sat Aug 22 13:34:32 2009 From: ekirpichov at gmail.com (Eugene Kirpichov) Date: Sat Aug 22 13:14:26 2009 Subject: [Haskell-cafe] How to calculate de number of digits of an integer? (was: Is logBase right?) In-Reply-To: <61f84eff0908221031p123615f8kf2e22a245d20677b@mail.gmail.com> References: <5e0214850908221023u62c29bb9r385b3fbcdf1ac4c8@mail.gmail.com> <61f84eff0908221031p123615f8kf2e22a245d20677b@mail.gmail.com> Message-ID: <5e0214850908221034w2d20426ar220239c0c2fb32a4@mail.gmail.com> Ouch, my bad. length.show is better :) 2009/8/22 Derek Elkins : > 2009/8/22 Eugene Kirpichov : >> Use 'round' instead of 'truncate'. >> >> Prelude> let numDigits = (+1) . round . logBase 10 . fromIntegral >> Prelude> map (numDigits . (10^)) [0..9] >> [1,2,3,4,5,6,7,8,9,10] >> > > round won't work because 999 is close to 1000. > > You simply need to use logBase 10 as a guess and then check the answer, e.g. > numDigits n | n < n' ? ? ? = e > ? ? ? ? ? ? ? ? ?| otherwise = e + 1 > ? ?where e = ceiling $ logBase 10 $ fromIntegral n > ? ? ? ? ? ? n' = 10^e > This will need to special case 0 which it currently doesn't do. > -- Eugene Kirpichov Web IR developer, market.yandex.ru From gwern0 at gmail.com Sat Aug 22 13:39:41 2009 From: gwern0 at gmail.com (Gwern Branwen) Date: Sat Aug 22 13:19:35 2009 Subject: [Haskell-cafe] Help starting a Haskell blog In-Reply-To: <625b74080908220956g20b506fw7e4864ed06c173cf@mail.gmail.com> References: <625b74080908220956g20b506fw7e4864ed06c173cf@mail.gmail.com> Message-ID: On Sat, Aug 22, 2009 at 12:56 PM, Dan Piponi wrote: > On Sat, Aug 22, 2009 at 3:35 AM, Peter Verswyvelen wrote: > >> Could you share your experiences with me about starting a blog? >> BTW: I'm on Windows. > > I've found it hard work to post a mixture of English, Mathematics and > Haskell. Neither of the most popular blogging web sites are very > helpful in this regard: wordpress.com and blogger.com. I did write a > little Haskell program to do some markup suitable for blogger.com but > it's very limited for embedding mathematics, knowing only a handful of > TeX commands, and doesn't play well with blogger's system for > uploading images. Wordpress looked good at first but I found all kinds > of problems with it. Gitit handles simple TeX fairly well; and it can even compile the TeX to MathML so one doesn't need JsMath to display the TeX. > I guess I should force myself to catch up with the 21st century and > learn how to write code to talk directly to these web sites, but I > find it hard to motivate myself to be interested in writing code for > all that HTML/XML/ATOM/ stuff. (I > think my day job is one of the few remaining software jobs that hasn't > been XMLified.) > > But I've seen lots of nice Haskell blogs with embedded mathematics so > there must be good solutions out there. What are they? > > What I'd really like is to blog in PDF. Gitit can export pages to LaTeX, thanks to pandoc, which is easy to turn into PDFs. :) -- gwern From gwern0 at gmail.com Sat Aug 22 13:43:55 2009 From: gwern0 at gmail.com (Gwern Branwen) Date: Sat Aug 22 13:23:49 2009 Subject: [Haskell-cafe] Help starting a Haskell blog In-Reply-To: References: Message-ID: On Sat, Aug 22, 2009 at 9:34 AM, Peter Verswyvelen wrote: > Thanks. At first sight gitit requires that I setup my own server. That's how the Happstack model works. > Although this has advantages and I did that in the past, I prefer to use a > public server (actually my internet provider's license forbids hosting a > server) > Does one exist for gitit? Nothing stops you from proxying through Apache, for example. That's how the Darcs wiki does it - Gitit listens on 127.0.0.1:5001 and Apache forwards from wiki.darcs.net:80. Or something like that. > Also Gitit is an unfortunate name since "Git It" has become a saying > apparently, so googling for it give me all the wrong hits ;-) Well, I've been pushing for any Gitit site backed by a darcs repo to be called a 'darcsit', which is very Google-search-friendly a name. > Bing guided me towards?http://www.johnmacfarlane.net, but I guess that site > is just a showcase for the author? Well, what are you looking for? Gitit's obviously on Hackage, and it links to the homepage (such as it is) on Github; there are a number of running examples besides John's site, such as http://wiki.darcs.net/ or http://lhc.seize.it/ -- gwern From bulat.ziganshin at gmail.com Sat Aug 22 13:45:37 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sat Aug 22 13:25:44 2009 Subject: [Haskell-cafe] How to calculate de number of digits of an integer? (was: Is logBase right?) In-Reply-To: References: Message-ID: <549488306.20090822214537@gmail.com> Hello Roberto, Saturday, August 22, 2009, 9:19:26 PM, you wrote: > I want to calculate the number of digits of a positive integer. I was fastest way digits = iterate (`div` 10) >>> takeWhile (>0) >>> length -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From simon at joyful.com Sat Aug 22 14:20:34 2009 From: simon at joyful.com (Simon Michael) Date: Sat Aug 22 14:00:55 2009 Subject: [Haskell-cafe] Re: Help starting a Haskell blog In-Reply-To: <87k50vztdt.wl%jeremy@n-heptane.com> References: <87k50vztdt.wl%jeremy@n-heptane.com> Message-ID: Nice tricks! From hiena03 at gmail.com Sat Aug 22 14:36:33 2009 From: hiena03 at gmail.com (=?ISO-8859-1?Q?Jos=E9_Prous?=) Date: Sat Aug 22 14:16:27 2009 Subject: [Haskell-cafe] How to calculate de number of digits of an integer? (was: Is logBase right?) In-Reply-To: <549488306.20090822214537@gmail.com> References: <549488306.20090822214537@gmail.com> Message-ID: It looks like length . show is faster Prelude Control.Arrow> let numDigits n = length $ show n Prelude Control.Arrow> let digits = iterate (`div` 10) >>> takeWhile (>0) >>> length Prelude Control.Arrow> let n=2^1000000 Prelude Control.Arrow> :set +s Prelude Control.Arrow> numDigits n 301030 (0.39 secs, 23001616 bytes) Prelude Control.Arrow> digits n 301030 (51.06 secs, 19635437248 bytes) 2009/8/22 Bulat Ziganshin > Hello Roberto, > > Saturday, August 22, 2009, 9:19:26 PM, you wrote: > > > I want to calculate the number of digits of a positive integer. I was > > fastest way > > digits = iterate (`div` 10) >>> takeWhile (>0) >>> length > > > -- > Best regards, > Bulat mailto:Bulat.Ziganshin@gmail.com > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090822/3095f192/attachment.html From bulat.ziganshin at gmail.com Sat Aug 22 14:46:56 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sat Aug 22 14:27:04 2009 Subject: [Haskell-cafe] How to calculate de number of digits of an integer? (was: Is logBase right?) In-Reply-To: References: <549488306.20090822214537@gmail.com> Message-ID: <1486723975.20090822224656@gmail.com> Hello Jos?, Saturday, August 22, 2009, 10:36:33 PM, you wrote: ghci doesn't optimize > It looks like length . show is faster -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From jwlato at gmail.com Sat Aug 22 16:20:59 2009 From: jwlato at gmail.com (John Lato) Date: Sat Aug 22 16:00:53 2009 Subject: [Haskell-cafe] Re: quick and dirty file parsing (was: no subject) Message-ID: <9979e72e0908221320q54745fb3yb03a9f44fa1de461@mail.gmail.com> > From: staafmeister > > Thank you for the reply. > > > Thomas ten Cate wrote: >> >> Although you most certainly can use a State monad, in most problems >> this isn't necessary. Most algorithms that you need to solve >> programming contest problems can be written in a purely functional >> style, so you can limit monadic code to just a few helper functions. >> > > Yes I know but there are a lot of problems requiring O(1) array updates > so then you are stuck with IO again Depending on the problem, you may be able to find a better data type than an array. Of course, since we're discussing generalities it's hard to make any specific recommendations. > > Thomas ten Cate wrote: >> >> For example, this reads input in the style you mention (assuming the >> strings don't contain whitespace): >> >>> import Control.Monad >>> >>> answer = id >>> >>> parse [] = [] >>> parse (s:p:r) = (s, (read p) :: Int) : parse r >>> >>> run = getLine >> getLine >>= putStrLn . show . answer . parse . words >>> >>> main = flip replicateM_ run =<< readLn >> >> The answer function would be a pure function that computes the answer >> for a particular run. This main function is reusable for all problems >> with many runs. >> >> Observe that the number of edges (e), provided as a convenience for >> memory allocation in many other languages, is not even necessary in >> Haskell :) >> > > Yes you're main is short. But how would you do it elegantly if > instead of line breaks and spaces one would have only spaces. > Every thing on one big line. My C code would not mind one bit. If I read it properly, this code won't either. The "words" function at the end of the pipeline will split tokens on any whitespace. > > > Thomas ten Cate wrote: >> >> (If anyone knows a better way than explicit recursion to map over a >> list, two elements at a time, or zip its even elements with its odd >> elements, I'd love to hear! I can imagine a convoluted fold with a >> boolean in its state, but it's ugly.) >> > > Yes I missed such a function in a couple of problems I wanted to solve. > I would expect a generic function > groupN::Int -> [a] -> [[a]] > that groups a list into groups of N I often use this function as well. I think it's not in the libraries because it's so simple to define: groupN :: Int -> [a] -> [[a]] groupN n [] = [] groupN n xs = let (h,t) = splitAt n xs in h:groupN n t Or, for a nonrecursive version: groupN2 = fix g where g f n [] = [] g f n xs = let (h,t) = splitAt n xs in h: f n t but that's probably not what you had in mind. I've found that using unfoldr is simpler than fold if you wish to use HOFs to accomplish this, but neither is as simple as explicit recursion. John Lato From niklas.broberg at gmail.com Sat Aug 22 16:26:46 2009 From: niklas.broberg at gmail.com (Niklas Broberg) Date: Sat Aug 22 16:06:39 2009 Subject: [Haskell-cafe] ANN: haskell-src-exts-1.1.3 Message-ID: Fellow Haskelleers, I'm pleased to announce the release of haskell-src-exts-1.1.3. * On hackage: http://hackage.haskell.org/package/haskell-src-exts * Via darcs: darcs get http://code.haskell.org/haskell-src-exts * Report bugs: http://trac.haskell.org/haskell-src-exts haskell-src-exts is a package for Haskell source code manipulation. In particular it defines an abstract syntax tree representation, and a parser and pretty-printer to convert between this representation and String. It handles (almost) all syntactic extensions to the Haskell 98 standard implemented by GHC, and the parsing can be parametrised on what extensions to recognise. haskell-src-exts-1.1.3 is a highly experimental release, which (apart from a small bug fix, see below) doesn't do anything at all to the current stable part of haskell-src-exts. But the release is far from as boring as all that may sound, as it includes a whole new set of modules implementing a new and more accurate syntax tree where all nodes are adorned with annotations. Together with this comes a parser that retains exact source information, stored in the aforementioned annotations. There is also support for various precision for source information, including SrcSpans. The new modules mirror the ones in the stable part of haskell-src-exts but instead live in Language.Haskell.Exts.Annotated{.Syntax,.Parser,...} (except that SrcLoc and friends now have their own module). The point of this release is that those of you that for one reason or other are waiting for these features can help me look, feel, test and comment these things in isolation, and hopefully report a lot of bugs, before I integrate this stuff with the main haskell-src-exts body of code. Note that that coming integration is intended to be backwards-compatible, but a lot of the behind-the-scenes will be switched over to the new and more general machinery. Feature-wise, with this accurate source tree in hand, the next step is to write a printer that uses the full location information to allow full and exact round-tripping, i.e. (print . parse == id). == haskell-src-exts-1.1.3 == * Adds support for more accurate, and fully annotated, abstract syntax, see above. * Fixes a bug that forced 'rec' statement groups to end with a qualifier (like 'do'). Cheers and Happy Haskelling, /Niklas From jeremy at n-heptane.com Sat Aug 22 16:34:56 2009 From: jeremy at n-heptane.com (Jeremy Shaw) Date: Sat Aug 22 16:14:51 2009 Subject: [Haskell-cafe] ANN: haskell-src-exts-1.1.3 In-Reply-To: References: Message-ID: <87iqgfzixb.wl%jeremy@n-heptane.com> Nice! Does this mean that in the near future trhsx won't strip out all the haddock comments? That would be great. - jeremy From bugfact at gmail.com Sat Aug 22 17:14:00 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Sat Aug 22 16:53:55 2009 Subject: [Haskell-cafe] Strange console IO behavior (at least on Windows) Message-ID: The following program http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8445#a8445 should echo the ASCII code of each character the user types, on the fly, with no line buffering whatsoever. But it doesn't. At least not under Windows's cmd, and even less with msys. Under Windows, I have to press enter before anything is printed to the screen. It then always prints 71 (that's upper G, no idea where that comes from), and then blocks. Pressing enter again prints the codes of all characters typed, except the first one, following by the two codes of the linefeeds. So e.g. when I type "abc" ENTER, I get 71, then hitting ENTER again, I get 98 99 10 10. Under msys, it just ignores both the hSetBuffering and hSetEcho, but when hitting enter, it at least prints the codes correctly. How does it behave under OSX and Linux? Is this a bug or am I doing something wrong? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090822/eeb27ed2/attachment.html From dagit at codersbase.com Sat Aug 22 17:36:14 2009 From: dagit at codersbase.com (Jason Dagit) Date: Sat Aug 22 17:16:08 2009 Subject: [Haskell-cafe] Strange console IO behavior (at least on Windows) In-Reply-To: References: Message-ID: On Sat, Aug 22, 2009 at 2:14 PM, Peter Verswyvelen wrote: > The following program > http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8445#a8445 > should echo the ASCII code of each character the user types, on the fly, > with no line buffering whatsoever. > But it doesn't. At least not under Windows's cmd, and even less with msys. > Under Windows, I have to press enter before anything is printed to the > screen. It then always prints 71 (that's upper G, no idea where that comes > from), and then blocks. Pressing enter again prints the codes of all > characters typed, except the first one, following by the two codes of the > linefeeds. So e.g. when I type "abc" ENTER, I get 71, then hitting ENTER > again, I get?98?99?10?10. > Under msys, it just ignores both the?hSetBuffering and hSetEcho, but when > hitting enter, it at least prints the codes correctly. > How does it behave under OSX and Linux? Is this a bug or am I doing > something wrong? For me on OSX it has the intended behavior. Which is to say, every time I type a key I see the ascii value of the key. I have no idea why windows is being different. Jason From bugfact at gmail.com Sat Aug 22 17:37:46 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Sat Aug 22 17:17:40 2009 Subject: [Haskell-cafe] Strange console IO behavior (at least on Windows) In-Reply-To: References: Message-ID: Okay, I'll file a bug report. Maybe someone else on Windows could confirm this behavior? On Sat, Aug 22, 2009 at 11:36 PM, Jason Dagit wrote: > On Sat, Aug 22, 2009 at 2:14 PM, Peter Verswyvelen > wrote: > > The following program > > http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8445#a8445 > > should echo the ASCII code of each character the user types, on the fly, > > with no line buffering whatsoever. > > But it doesn't. At least not under Windows's cmd, and even less with > msys. > > Under Windows, I have to press enter before anything is printed to the > > screen. It then always prints 71 (that's upper G, no idea where that > comes > > from), and then blocks. Pressing enter again prints the codes of all > > characters typed, except the first one, following by the two codes of the > > linefeeds. So e.g. when I type "abc" ENTER, I get 71, then hitting ENTER > > again, I get 98 99 10 10. > > Under msys, it just ignores both the hSetBuffering and hSetEcho, but when > > hitting enter, it at least prints the codes correctly. > > How does it behave under OSX and Linux? Is this a bug or am I doing > > something wrong? > > For me on OSX it has the intended behavior. Which is to say, every > time I type a key I see the ascii value of the key. I have no idea > why windows is being different. > > Jason > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090822/68282612/attachment.html From judah.jacobson at gmail.com Sat Aug 22 17:40:53 2009 From: judah.jacobson at gmail.com (Judah Jacobson) Date: Sat Aug 22 17:21:16 2009 Subject: [Haskell-cafe] Strange console IO behavior (at least on Windows) In-Reply-To: References: Message-ID: <6d74b0d20908221440h8b74550vd1706c0a3fd69aaa@mail.gmail.com> On Sat, Aug 22, 2009 at 2:37 PM, Peter Verswyvelen wrote: > Okay, I'll file a bug report. Maybe someone else on Windows could confirm > this behavior? > On Sat, Aug 22, 2009 at 11:36 PM, Jason Dagit wrote: >> >> On Sat, Aug 22, 2009 at 2:14 PM, Peter Verswyvelen >> wrote: >> > The following program >> > http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8445#a8445 >> > should echo the ASCII code of each character the user types, on the fly, >> > with no line buffering whatsoever. >> > But it doesn't. At least not under Windows's cmd, and even less with >> > msys. This is probably the following issue: http://hackage.haskell.org/trac/ghc/ticket/2189 -Judah From bugfact at gmail.com Sat Aug 22 17:46:56 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Sat Aug 22 17:26:51 2009 Subject: [Haskell-cafe] Strange console IO behavior (at least on Windows) In-Reply-To: <6d74b0d20908221440h8b74550vd1706c0a3fd69aaa@mail.gmail.com> References: <6d74b0d20908221440h8b74550vd1706c0a3fd69aaa@mail.gmail.com> Message-ID: Yep, that seems to be it. I should first do a search on trac before spamming here! But my first reaction when something basic as this goes wrong is blame myself and ask for help :-) On Sat, Aug 22, 2009 at 11:40 PM, Judah Jacobson wrote: > On Sat, Aug 22, 2009 at 2:37 PM, Peter Verswyvelen > wrote: > > Okay, I'll file a bug report. Maybe someone else on Windows could confirm > > this behavior? > > On Sat, Aug 22, 2009 at 11:36 PM, Jason Dagit > wrote: > >> > >> On Sat, Aug 22, 2009 at 2:14 PM, Peter Verswyvelen > >> wrote: > >> > The following program > >> > http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8445#a8445 > >> > should echo the ASCII code of each character the user types, on the > fly, > >> > with no line buffering whatsoever. > >> > But it doesn't. At least not under Windows's cmd, and even less with > >> > msys. > > This is probably the following issue: > > http://hackage.haskell.org/trac/ghc/ticket/2189 > > -Judah > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090822/f3b03991/attachment.html From dsouza at bitforest.org Sat Aug 22 19:36:54 2009 From: dsouza at bitforest.org (Diego Souza) Date: Sat Aug 22 19:20:22 2009 Subject: [Haskell-cafe] oauth in haskell - reviewers? Message-ID: <20090822233654.GA16495@mephisto.bitforest.org> Hi all, I wrote a small library in haskell do deal with oauth authentication. It turns out it is my first library in haskell as well. As I'm beginner in haskell, I'm asking for a review of someone more experienced/proficient before even daring to create a cabal pkg and dist it to hackage. :-) Any help/comments on this will be highly welcome. http://projects.bitforest.org/hoauth/ $ darcs get http://projects.bitforest.org/hoauth/ # should do the trick Thanks in advance, -- ~dsouza yahoo!im: paravinicius gpg key fingerprint: 71B8 CE21 3A6E F894 5B1B 9ECE F88E 067F E891 651E From lennart at augustsson.net Sat Aug 22 20:30:37 2009 From: lennart at augustsson.net (Lennart Augustsson) Date: Sat Aug 22 20:10:30 2009 Subject: [Haskell-cafe] Unifcation and matching in Abelian groups In-Reply-To: <7687290b0908211851n689b8219p6d19c158cf45e090@mail.gmail.com> References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> <404396ef0908190316rc772614p9c660c8ab5095ed6@mail.gmail.com> <7687290b0908190345q23313f4bwf24b6868499ee704@mail.gmail.com> <4A8BF0D3.7050403@jellybean.co.uk> <7687290b0908200557i522f3d92jb4d20707baeb3694@mail.gmail.com> <4A8D4AD9.1050701@jellybean.co.uk> <7687290b0908200637u5022c4e6lf76b759a82222f1f@mail.gmail.com> <4A8D57E1.2050002@jellybean.co.uk> <7687290b0908211851n689b8219p6d19c158cf45e090@mail.gmail.com> Message-ID: Even if you are only slightly irritated by offset syntax, why are you using it? {;} works fine. On Sat, Aug 22, 2009 at 3:51 AM, John D. Ramsdell wrote: > Let me put all my cards on the table. ?You see, I really am only > slightly irrigated by offset syntax. ?In contrast, I am a strong > proponent of functional programming for parallel programming. ?In my > opinion, it has to be the "new way" for multiprocessor machines. ?Just > think about it and if other paradym could possibly work. ?We've tried > many on them. ?Many years ago, I wrote SISAl programs. ?There were > many good ideas in SISAL, but it did not catch on. ?Perhaps Data > Parallel Haskell will catch on. ?In my opinion, something like it is > the ``answer.'' ?Even though the code I submitted is not parallel, > I've thought about how to make it so. ?And isn't thinking parallelism > iour future? ?I think so. > > John > > On Thu, Aug 20, 2009 at 10:04 AM, Jules Bean wrote: >> John D. Ramsdell wrote: >>> >>> On Thu, Aug 20, 2009 at 9:08 AM, Jules Bean wrote: >>> >>>> I don't find layout a problem, with good editor support. I agree it's a >>>> problem, with poor editor support. That's all I meant. >>> >>> Let's put this issue in perspective. ?For those few Haskell >>> programmers that do find layout irritating, I'm sure we would all >>> agree it's but a minor irritation. ?The real downside of layout is if >>> non-Haskell programmers use it as an excuse to dismiss the language. >>> I happen to think that Data Parallel Haskell has great potential ?for >>> use in high performance computations. ?I'd hate to see a bunch of >>> Fortraners not try DPH because of Haskell syntax. >> >> Well that's a reasonable point. >> >> They can still use the non-layout form if it bothers them that much? >> > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From gue.schmidt at web.de Sat Aug 22 23:01:01 2009 From: gue.schmidt at web.de (=?iso-8859-15?Q?G=FCnther_Schmidt?=) Date: Sat Aug 22 22:41:19 2009 Subject: [Haskell-cafe] Takusen - is anyone currently using it on Win32 - ODBC? Message-ID: Hi all, is anyone currently using takusen with odbc on Win32? In particular with MS Access? I'm asking because I noticed that when database libraries are declared to work with ODBC no one seems to mean Win32 ODBC, but rather Unix ODBC. G?nther From alexander.dunlap at gmail.com Sat Aug 22 23:08:53 2009 From: alexander.dunlap at gmail.com (Alexander Dunlap) Date: Sat Aug 22 22:49:05 2009 Subject: [Haskell-cafe] oauth in haskell - reviewers? In-Reply-To: <20090822233654.GA16495@mephisto.bitforest.org> References: <20090822233654.GA16495@mephisto.bitforest.org> Message-ID: <57526e770908222008o25780147ve211a8279dc82f56@mail.gmail.com> On Sat, Aug 22, 2009 at 4:36 PM, Diego Souza wrote: > Hi all, > > I wrote a small library in haskell do deal with oauth authentication. It > turns out it is my first library in haskell as well. As I'm beginner in > haskell, I'm asking for a review of someone more experienced/proficient > before even daring to create a cabal pkg and dist it to hackage. :-) > > Any help/comments on this will be highly welcome. > > http://projects.bitforest.org/hoauth/ > > $ darcs get http://projects.bitforest.org/hoauth/ > # should do the trick > > Thanks in advance, > -- > ~dsouza > yahoo!im: paravinicius > gpg key fingerprint: 71B8 CE21 3A6E F894 5B1B ?9ECE F88E 067F E891 651E > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > Hi, I'm not familiar at all with OAuth but I have some general suggestions that might make your code in "Consumer.hs" a bit nicer. These suggestions also probably apply elsewhere in your code. - In the Token datatype, you can automatically create the accessor functions (oath_token, etc.) by using named fields: data Token = Request { oath_token :: String, oath_token_secret :: String, oath_extra :: R.Parameter } | Access { oath_token :: String, oath_token_secret :: String, oath_extra :: R.Parameter } This will create your accessor functions for free, and you get update syntax to boot. (Google for "haskell named fields" for details.) - When you have multiple datatype constructors with similar arguments (as with Token or Request), it may be better to use a Boolean-type flag saying which one it is (e.g. HTTP or HTTPS) and then a single datatype with all of the different arguments in it. This may help you remove code duplication elsewhere. - I think you can use join from Control.Monad and functions from Control.Applicative in your "response" function to make it quite a bit cleaner. I know this email has been a bit terse; ask if you have any questions about the above. Hope that helps, Alex From timothyea at comcast.net Sat Aug 22 23:28:58 2009 From: timothyea at comcast.net (Tim Attwood) Date: Sat Aug 22 23:09:10 2009 Subject: [Haskell-cafe] Re: Strange console IO behavior (at least on Windows) In-Reply-To: References: <6d74b0d20908221440h8b74550vd1706c0a3fd69aaa@mail.gmail.com> Message-ID: Yeah, it's broken in windows. Here's the workaround courtesy of Alistar Bayley. (ticket 2189) {-# LANGUAGE ForeignFunctionInterface #-} import Data.Char import Control.Monad (liftM, forever) import Foreign.C.Types getHiddenChar = liftM (chr.fromEnum) c_getch foreign import ccall unsafe "conio.h getch" c_getch :: IO CInt main = do forever $ do c <- getHiddenChar putStrLn $ show (fromEnum c) From jake.mcarthur at gmail.com Sun Aug 23 00:49:53 2009 From: jake.mcarthur at gmail.com (Jake McArthur) Date: Sun Aug 23 00:29:47 2009 Subject: [Haskell-cafe] (no subject) In-Reply-To: <25094244.post@talk.nabble.com> References: <40EBDEED77D2DE44B91E9AFCC63142C8018498EE@uu01msg-exb02.soliscom.uu.nl> <20090821224221.GE15454@whirlpool.galois.com> <25088830.post@talk.nabble.com> <25094244.post@talk.nabble.com> Message-ID: <4A90CA71.5050004@gmail.com> staafmeister wrote: > Yes I know but there are a lot of problems requiring O(1) array updates > so then you are stuck with IO again Or use ST. Or use IntMap (which is O(log n), but n is going to max out on the integer size for your architecture, so it's really just O(32) or O(64), which is really just constant time). And, realistically, very few problems actually require indexed access on a large scale like this. > [parsing stuff] As far as parsing is concerned, maybe you should look at Parsec. I know it sounds like overkill, but it's easy enough to use that it's quite lightweight in practice. Your example scenario: inputData :: Parser InputData inputData = many1 digit *> newline *> many (testCase <* newline) where testCase = many1 digit *> newline *> sepBy edge (char ' ') edge = liftA2 (,) (many nonspace <* char ' ') (read <$> digits) - Jake From jason.dusek at gmail.com Sun Aug 23 03:26:31 2009 From: jason.dusek at gmail.com (Jason Dusek) Date: Sun Aug 23 03:06:24 2009 Subject: [Haskell-cafe] ANN: ByteString Nums Message-ID: <42784f260908230026s497b40b0ybbcd8ae9d1a6ac9e@mail.gmail.com> This is a simple package for relatively careless parsing of numbers from ByteStrings. It works to parse out integer strings, floating point strings and hex strings. http://hackage.haskell.org/package/bytestring-nums For integer strings, an initial sign is detected and non-digit characters are ignored: Prelude> :load Data.ByteString.Nums.Careless.Int *Data.ByteString.Nums.Careless.Int> let strings = ["121.3040", "1o2", "-a1", "0xff", "-0x30"] *Data.ByteString.Nums.Careless.Int> fmap (int . pack) strings :: [Int] [1213040,12,-1,0,-30] *Data.ByteString.Nums.Careless.Int> fmap (int . pack) strings :: [Double] [1213040.0,12.0,-1.0,0.0,-30.0] For hexadecimal strings, no signs are recognized and characters that aren't hex digits are ignored. One consequence of this is that an initial `0x` is skipped. Prelude> :load Data.ByteString.Nums.Careless.Hex *Data.ByteString.Nums.Careless.Hex> let strings = ["121.3040", "1o2", "-a1", "0xff", "-0x30"] *Data.ByteString.Nums.Careless.Hex> fmap (hex . pack) strings :: [Int] [18952256,18,161,255,48] The float parser recognizes the last group of digits behind a comma or period as the fractional part; all preceding digits are treated as the integral part. Naturally, signs are handled. Prelude> :load Data.ByteString.Nums.Careless.Float *Data.ByteString.Nums.Careless.Float> let strings = ["121.3040", "2.100,32", "1,o2", "-a1", "0xff", "-0x30"] *Data.ByteString.Nums.Careless.Float> fmap (float . pack) strings :: [Double] [122.304,2100.32,1.2,-1.0,0.0,-30.0] *Data.ByteString.Nums.Careless.Float> fmap (float . pack) strings :: [Rational] [15163 % 125,52508 % 25,6 % 5,(-1) % 1,0 % 1,(-30) % 1] I have not applied any `SPECIALIZE` or `INLINE` directives at this time; it'd be great to have some insight in to optimizing collections of small functions like this library. -- Jason Dusek From knomenet at gmail.com Sun Aug 23 03:33:12 2009 From: knomenet at gmail.com (Michael Speer) Date: Sun Aug 23 03:13:04 2009 Subject: [Haskell-cafe] STM problems Message-ID: <314e9ce40908230033s73854343v466a659073f14d9@mail.gmail.com> I am playing a writing a simple STM hashtable. I expected the following code to alter the TVars in it, but they appear immutable. I assume I am simply doing something wrong, but I am not sure what it is. Any pointers would be greatly appreciated. import Control.Concurrent.STM import Control.Concurrent import Array data HashTable a b = HashTable (a -> Int) (STM (Array Int (TVar (Maybe b)))) mkHashTable :: ( a -> Int ) -> Int -> HashTable a b mkHashTable hashfn numBuckets | numBuckets > 0 = do HashTable hashfn $ do vs <- mapM (\v -> newTVar Nothing >>= \tv -> return (v,tv) ) [1..numBuckets] return $ array (1,numBuckets) vs readHashTable :: HashTable a b -> a -> STM (Maybe b) readHashTable hashtable key = let (HashTable hashfn table) = hashtable in table >>= \tb -> readTVar (tb ! hashfn key) writeHashTable :: HashTable a b -> a -> (Maybe b) -> STM () writeHashTable hashtable key value = let (HashTable hashfn table) = hashtable in table >>= \tb -> writeTVar (tb ! hashfn key) value >> return () main = let ht = mkHashTable id 10 :: HashTable Int String in do v <- atomically $ do mapM_ (\n -> writeHashTable ht n (Just $ "hello " ++ show n)) [1..10] mapM (\n -> readHashTable ht n) [1..10] print v From magnus at therning.org Sun Aug 23 04:35:19 2009 From: magnus at therning.org (Magnus Therning) Date: Sun Aug 23 04:15:14 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: References: <5e0214850908220102n52d636duf1848828dfd9c3f5@mail.gmail.com> Message-ID: 2009/8/22 Roberto L?pez : > If 4.0 / 2.0 was 1.9999999999999999999998, it would be ok? > > The real value of log10 1000 is 3 (3.0). It can be represented with accuracy > and it should be. Well, it already can be, you just need to choose your representation properly: > logBase 10 1000 :: Double 2.9999999999999996 > logBase 10 1000 :: Float 3.0 Welcome the wonderful land of floating point numbers. (The examples above are from an Intel 32-bit machine, I suspect it'd change on any other type of architecture.) /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?org http://therning.org/magnus identi.ca|twitter: magthe From magnus at therning.org Sun Aug 23 04:41:45 2009 From: magnus at therning.org (Magnus Therning) Date: Sun Aug 23 04:21:42 2009 Subject: [Haskell-cafe] Help starting a Haskell blog In-Reply-To: References: Message-ID: On Sat, Aug 22, 2009 at 11:35 AM, Peter Verswyvelen wrote: > I'm going start my very first blog, documenting my everyday struggle to > switch my old imperative mind to the lazy functional setting, with a focus > on FRP. > Although you can find a lot of articles that provide help to get started > with general blogging, it might be useful to pick a blog in which presenting > Haskell code is easy (e.g. like hpaste that does the syntax coloring for > you), and where users can give feedback, providing code, also with syntax > coloring preferably. It would also be nice to allow hyperlinking every > function in the code to the standard Haskell library docs or to the docs on > Hackage. > Googling for "how to start a Haskell blog" just revealed a lot of Haskell > blogs. > Could you share your experiences with me about starting a blog? > BTW: I'm on Windows. Wordpress with wp-syntax works fine for me. /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?org http://therning.org/magnus identi.ca|twitter: magthe From lrpalmer at gmail.com Sun Aug 23 05:12:01 2009 From: lrpalmer at gmail.com (Luke Palmer) Date: Sun Aug 23 04:51:53 2009 Subject: [Haskell-cafe] STM problems In-Reply-To: <314e9ce40908230033s73854343v466a659073f14d9@mail.gmail.com> References: <314e9ce40908230033s73854343v466a659073f14d9@mail.gmail.com> Message-ID: <7ca3f0160908230212s1e429d9j7545a229e5b97747@mail.gmail.com> On Sun, Aug 23, 2009 at 1:33 AM, Michael Speer wrote: > data HashTable a b = HashTable (a -> Int) (STM (Array Int (TVar (Maybe b)))) So wait... a HashTable is a hash function together with an *action returning an array of TVars?* I don't think that's right. It looks like that action is recreating an empty table each time it is accessed. You probably want: data HashTable a b = HashTable (a -> Int) (TVar (Array Int (TVar (Maybe b)))) instead. The rest of the implementation will follow the type. > > mkHashTable :: ( a -> Int ) -> Int -> HashTable a b > mkHashTable hashfn numBuckets | numBuckets > 0 = do > ?HashTable hashfn $ do > ? ?vs <- mapM (\v -> newTVar Nothing >>= \tv -> return (v,tv) ) [1..numBuckets] > ? ?return $ array (1,numBuckets) vs > > readHashTable :: HashTable a b -> a -> STM (Maybe b) > readHashTable hashtable key = > ?let (HashTable hashfn table) = hashtable > ?in table >>= \tb -> readTVar (tb ! hashfn key) > > writeHashTable :: HashTable a b -> a -> (Maybe b) -> STM () > writeHashTable hashtable key value = > ? ?let (HashTable hashfn table) = hashtable > ? ?in table >>= \tb -> writeTVar (tb ! hashfn key) value >> return () > > main = ?let ht = mkHashTable id 10 :: HashTable Int String > ? ? ? ?in do > ? ? ? ? ?v <- atomically $ do > ? ? ? ? ? ? mapM_ (\n -> writeHashTable ht n (Just $ "hello " ++ show > n)) [1..10] > ? ? ? ? ? ? mapM (\n -> readHashTable ht n) [1..10] > ? ? ? ? ?print v > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From niklas.broberg at gmail.com Sun Aug 23 05:47:28 2009 From: niklas.broberg at gmail.com (Niklas Broberg) Date: Sun Aug 23 05:27:20 2009 Subject: [Haskell-cafe] ANN: haskell-src-exts-1.1.3 In-Reply-To: <87iqgfzixb.wl%jeremy@n-heptane.com> References: <87iqgfzixb.wl%jeremy@n-heptane.com> Message-ID: Oops, please consider this the announcement of the release of haskell-src-exts-1.1.3.1, since I stupidly forgot to add the new SrcLoc module to the list of exposed modules in cabal (why doesn't cabal warn about that? *grumble*). So those of you who already tried 1.1.3 it will have noticed that it failed to compile, sorry about that! On Sat, Aug 22, 2009 at 10:34 PM, Jeremy Shaw wrote: > Does this mean that in the near future trhsx won't strip out all the > haddock comments? That would be great. I can't promise about the *near* future, there's that little matter of time, but it's definitely the plan to turn trhsx over to the new cool machinery at some point, which will indeed allow it to retain all comments. :-) Cheers, /Niklas From gwern0 at gmail.com Sun Aug 23 06:01:58 2009 From: gwern0 at gmail.com (Gwern Branwen) Date: Sun Aug 23 05:41:50 2009 Subject: [Haskell-cafe] ANN: haskell-src-exts-1.1.3 In-Reply-To: References: <87iqgfzixb.wl%jeremy@n-heptane.com> Message-ID: On Sun, Aug 23, 2009 at 5:47 AM, Niklas Broberg wrote: > Oops, please consider this the announcement of the release of > haskell-src-exts-1.1.3.1, since I stupidly forgot to add the new > SrcLoc module to the list of exposed modules in cabal (why doesn't > cabal warn about that? *grumble*). http://hackage.haskell.org/trac/hackage/ticket/274 -- gwern From stevech1097 at yahoo.com.au Sun Aug 23 06:41:36 2009 From: stevech1097 at yahoo.com.au (Steve) Date: Sun Aug 23 06:20:43 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: <20090822170352.5A3C53245AF@www.haskell.org> References: <20090822170352.5A3C53245AF@www.haskell.org> Message-ID: <1251024096.2246.21.camel@localhost> On Sat, 2009-08-22 at 13:03 -0400, haskell-cafe-request@haskell.org wrote: > Message: 10 > Date: Sat, 22 Aug 2009 11:24:21 +0200 > From: Roberto L?pez > Subject: [Haskell-cafe] Re: Is logBase right? > To: haskell-cafe@haskell.org > Message-ID: > Content-Type: text/plain; charset="ISO-8859-1" > > If 4.0 / 2.0 was 1.9999999999999999999998, it would be ok? > > The real value of log10 1000 is 3 (3.0). It can be represented with > accuracy > and it should be. > > You get the accuracy value in Perl, but there is the same problem in > Python. > It's a bit discouraging. > There is *not* the same problem in Python: $ python Python 2.6.2 (r262:71600, Jul 9 2009, 23:16:53) [GCC 4.4.0 20090506 (Red Hat 4.4.0-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import math >>> math.log10(1000) 3.0 Recent work in Python 3 (and Python 2.6) has improved the handling of floating point numbers, and addresses exactly the problem that Roberto has raised. I see no reason why Haskell could not improve its handling of floating point numbers by using similar techniques. Steve From ekirpichov at gmail.com Sun Aug 23 07:12:54 2009 From: ekirpichov at gmail.com (Eugene Kirpichov) Date: Sun Aug 23 06:52:45 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: <1251024096.2246.21.camel@localhost> References: <20090822170352.5A3C53245AF@www.haskell.org> <1251024096.2246.21.camel@localhost> Message-ID: <5e0214850908230412s199c79absc66f47e03a539eb7@mail.gmail.com> 2009/8/23 Steve : > On Sat, 2009-08-22 at 13:03 -0400, haskell-cafe-request@haskell.org > wrote: >> Message: 10 >> Date: Sat, 22 Aug 2009 11:24:21 +0200 >> From: Roberto L?pez >> Subject: [Haskell-cafe] Re: Is logBase right? >> To: haskell-cafe@haskell.org >> Message-ID: >> Content-Type: text/plain; charset="ISO-8859-1" >> >> If 4.0 / 2.0 was 1.9999999999999999999998, it would be ok? >> >> The real value of log10 1000 is 3 (3.0). It can be represented with >> accuracy >> and it should be. >> >> You get the accuracy value in Perl, but there is the same problem in >> Python. >> It's a bit discouraging. >> > > There is *not* the same problem in Python: > $ python > Python 2.6.2 (r262:71600, Jul ?9 2009, 23:16:53) > [GCC 4.4.0 20090506 (Red Hat 4.4.0-4)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import math >>>> math.log10(1000) > 3.0 > >>> import math >>> math.log(1000,10) 2.9999999999999996 > Recent work in Python 3 (and Python 2.6) has improved the handling of > floating point numbers, and addresses exactly the problem that Roberto > has raised. > > I see no reason why Haskell could not improve its handling of floating > point numbers by using similar techniques. You mean introducing a "log10" function into the definition of the Floating class ? That might be a proposal for Haskell Prime. > > Steve > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Eugene Kirpichov Web IR developer, market.yandex.ru From lennart at augustsson.net Sun Aug 23 07:25:14 2009 From: lennart at augustsson.net (Lennart Augustsson) Date: Sun Aug 23 07:05:06 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: <1251024096.2246.21.camel@localhost> References: <20090822170352.5A3C53245AF@www.haskell.org> <1251024096.2246.21.camel@localhost> Message-ID: You're absolutely right. It would be easy to change logBase to have special cases for, say, base 2 and base 10, and call the C library functions for those. In fact, I think it's a worth while change, since it's easy and get's better results for some cases. -- Lennart On Sun, Aug 23, 2009 at 12:41 PM, Steve wrote: > On Sat, 2009-08-22 at 13:03 -0400, haskell-cafe-request@haskell.org > wrote: >> Message: 10 >> Date: Sat, 22 Aug 2009 11:24:21 +0200 >> From: Roberto L?pez >> Subject: [Haskell-cafe] Re: Is logBase right? >> To: haskell-cafe@haskell.org >> Message-ID: >> Content-Type: text/plain; charset="ISO-8859-1" >> >> If 4.0 / 2.0 was 1.9999999999999999999998, it would be ok? >> >> The real value of log10 1000 is 3 (3.0). It can be represented with >> accuracy >> and it should be. >> >> You get the accuracy value in Perl, but there is the same problem in >> Python. >> It's a bit discouraging. >> > > There is *not* the same problem in Python: > $ python > Python 2.6.2 (r262:71600, Jul ?9 2009, 23:16:53) > [GCC 4.4.0 20090506 (Red Hat 4.4.0-4)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import math >>>> math.log10(1000) > 3.0 > > Recent work in Python 3 (and Python 2.6) has improved the handling of > floating point numbers, and addresses exactly the problem that Roberto > has raised. > > I see no reason why Haskell could not improve its handling of floating > point numbers by using similar techniques. > > Steve > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From felipe.lessa at gmail.com Sun Aug 23 08:13:29 2009 From: felipe.lessa at gmail.com (Felipe Lessa) Date: Sun Aug 23 07:53:26 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: References: <20090822170352.5A3C53245AF@www.haskell.org> <1251024096.2246.21.camel@localhost> Message-ID: <20090823121329.GA30645@kira.casa> On Sun, Aug 23, 2009 at 01:25:14PM +0200, Lennart Augustsson wrote: > You're absolutely right. It would be easy to change logBase to have > special cases for, say, base 2 and base 10, and call the C library > functions for those. In fact, I think it's a worth while change, > since it's easy and get's better results for some cases. For a short-term solution there's Don's cmath[1]. [1] http://hackage.haskell.org/packages/archive/cmath/0.3/doc/html/Foreign-C-Math-Double.html#v:log10 -- Felipe. From knomenet at gmail.com Sun Aug 23 08:36:36 2009 From: knomenet at gmail.com (Michael Speer) Date: Sun Aug 23 08:16:29 2009 Subject: [Haskell-cafe] STM problems In-Reply-To: <7ca3f0160908230212s1e429d9j7545a229e5b97747@mail.gmail.com> References: <314e9ce40908230033s73854343v466a659073f14d9@mail.gmail.com> <7ca3f0160908230212s1e429d9j7545a229e5b97747@mail.gmail.com> Message-ID: <314e9ce40908230536p265abd2cjbcdb6facc8488189@mail.gmail.com> Thank you for pointing me back on track. I got caught in a sleepy mindset of thinking of (STM a) as a datatype only reachable while in an STM context rather than an action returning an a. I wanted a fixed-sized array with mutable variables ( no need to mutate the array ) so here is the working next iteration. import Control.Concurrent.STM import Control.Concurrent import Array data HashTable a b = HashTable (a -> Int) (Array Int (TVar (Maybe b))) mkHashTable :: ( a -> Int ) -> Int -> STM (HashTable a b) mkHashTable hashfn numBuckets | numBuckets > 0 = do vs <- mapM (\v -> newTVar Nothing >>= \nt -> return (v,nt)) [1..numBuckets] return $ HashTable hashfn $ array (1,numBuckets) vs readHashTable :: HashTable a b -> a -> STM (Maybe b) readHashTable hashtable key = let (HashTable hashfn table) = hashtable in readTVar (table ! hashfn key) writeHashTable :: HashTable a b -> a -> (Maybe b) -> STM () writeHashTable hashtable key value = let (HashTable hashfn table) = hashtable in writeTVar (table ! hashfn key) value >> return () main = do v <- atomically $ do ht <- mkHashTable id 10 :: STM (HashTable Int String) mapM_ (\n -> writeHashTable ht n (Just $ "hello " ++ show n)) [1..10] mapM (\n -> readHashTable ht n) [1..10] print v On Sun, Aug 23, 2009 at 5:12 AM, Luke Palmer wrote: > On Sun, Aug 23, 2009 at 1:33 AM, Michael Speer wrote: >> data HashTable a b = HashTable (a -> Int) (STM (Array Int (TVar (Maybe b)))) > > So wait... a HashTable is a hash function together with an *action > returning an array of TVars?* ? ?I don't think that's right. ?It looks > like that action is recreating an empty table each time it is > accessed. ?You probably want: > > data HashTable a b = HashTable (a -> Int) (TVar (Array Int (TVar (Maybe b)))) > > instead. ?The rest of the implementation will follow the type. > >> >> mkHashTable :: ( a -> Int ) -> Int -> HashTable a b >> mkHashTable hashfn numBuckets | numBuckets > 0 = do >> ?HashTable hashfn $ do >> ? ?vs <- mapM (\v -> newTVar Nothing >>= \tv -> return (v,tv) ) [1..numBuckets] >> ? ?return $ array (1,numBuckets) vs >> >> readHashTable :: HashTable a b -> a -> STM (Maybe b) >> readHashTable hashtable key = >> ?let (HashTable hashfn table) = hashtable >> ?in table >>= \tb -> readTVar (tb ! hashfn key) >> >> writeHashTable :: HashTable a b -> a -> (Maybe b) -> STM () >> writeHashTable hashtable key value = >> ? ?let (HashTable hashfn table) = hashtable >> ? ?in table >>= \tb -> writeTVar (tb ! hashfn key) value >> return () >> >> main = ?let ht = mkHashTable id 10 :: HashTable Int String >> ? ? ? ?in do >> ? ? ? ? ?v <- atomically $ do >> ? ? ? ? ? ? mapM_ (\n -> writeHashTable ht n (Just $ "hello " ++ show >> n)) [1..10] >> ? ? ? ? ? ? mapM (\n -> readHashTable ht n) [1..10] >> ? ? ? ? ?print v >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> > From stevech1097 at yahoo.com.au Sun Aug 23 09:27:48 2009 From: stevech1097 at yahoo.com.au (Steve) Date: Sun Aug 23 09:06:47 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: <5e0214850908230412s199c79absc66f47e03a539eb7@mail.gmail.com> References: <20090822170352.5A3C53245AF@www.haskell.org> <1251024096.2246.21.camel@localhost> <5e0214850908230412s199c79absc66f47e03a539eb7@mail.gmail.com> Message-ID: <1251034068.3085.55.camel@localhost> On Sun, 2009-08-23 at 15:12 +0400, Eugene Kirpichov wrote: > > There is *not* the same problem in Python: > > $ python > > Python 2.6.2 (r262:71600, Jul 9 2009, 23:16:53) > > [GCC 4.4.0 20090506 (Red Hat 4.4.0-4)] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> import math > >>>> math.log10(1000) > > 3.0 > > > > >>> import math > >>> math.log(1000,10) > 2.9999999999999996 That is surprising. I think its a Python bug - the results should be consistent. > > > Recent work in Python 3 (and Python 2.6) has improved the handling of > > floating point numbers, and addresses exactly the problem that Roberto > > has raised. > > > > I see no reason why Haskell could not improve its handling of floating > > point numbers by using similar techniques. > > You mean introducing a "log10" function into the definition of the > Floating class ? That might be a proposal for Haskell Prime. I was not thinking of the log10 function. I was thinking of the changes mentioned in http://docs.python.org/3.1/whatsnew/3.1.html where it says "Python now uses David Gay?s algorithm for finding the shortest floating point representation that doesn?t change its value. This should help mitigate some of the confusion surrounding binary floating point numbers." Also, I had a problem using floating point in Python where >>> round(697.04157958254996, 10) gave 697.04157958259998 which is closer to 697.0415795826 than the desired result of 697.0415795825 Its been fixed in the latest versions of Python: >>> round(697.04157958254996, 10) 697.0415795825 I'm not sure what the equivalent in Haskell is. Is there a function for rounding to a number of decimal digits ? I came up with this: roundN :: Double -> Int -> Double roundN n ndigits = fromIntegral (round $ n * m) / m where m = 10 ^ ndigits ghci> roundN 697.04157958254996 10 697.0415795826 which is not the desired result. Steve From bulat.ziganshin at gmail.com Sun Aug 23 09:36:57 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Sun Aug 23 09:17:01 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: <1251034068.3085.55.camel@localhost> References: <20090822170352.5A3C53245AF@www.haskell.org> <1251024096.2246.21.camel@localhost> <5e0214850908230412s199c79absc66f47e03a539eb7@mail.gmail.com> <1251034068.3085.55.camel@localhost> Message-ID: <1048018947.20090823173657@gmail.com> Hello Steve, Sunday, August 23, 2009, 5:27:48 PM, you wrote: ghci>> roundN 697.04157958254996 10 > 697.0415795826 afair, double has 13 decimal digits precision, so your 697.04157958254996 represented by another value. you just looking for miracles -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From magnus at therning.org Sun Aug 23 09:41:01 2009 From: magnus at therning.org (Magnus Therning) Date: Sun Aug 23 09:20:52 2009 Subject: [Haskell-cafe] hslogger and syslog-ng Message-ID: I'm having some problem with logging to syslog using System.Log.Logger and friends. I have the following: > :m +System.Log.Logger > :m +System.Log.Handler.Syslog > sl <- openlog "foo" [PID] USER DEBUG > updateGlobalLogger rootLoggerName (addHandler sl) > warningM "bar" "test" *** Exception: sendTo: protocol error (Protocol wrong type for socket) What could be the cause for this? I've tried hsyslog and it reports to my instance of syslog without problems. My system is a 32-bit Arch Linux, running syslog-ng 3.0.3. /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?org http://therning.org/magnus identi.ca|twitter: magthe From stevech1097 at yahoo.com.au Sun Aug 23 09:51:03 2009 From: stevech1097 at yahoo.com.au (Steve) Date: Sun Aug 23 09:30:08 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: <1048018947.20090823173657@gmail.com> References: <20090822170352.5A3C53245AF@www.haskell.org> <1251024096.2246.21.camel@localhost> <5e0214850908230412s199c79absc66f47e03a539eb7@mail.gmail.com> <1251034068.3085.55.camel@localhost> <1048018947.20090823173657@gmail.com> Message-ID: <1251035463.3727.10.camel@localhost> On Sun, 2009-08-23 at 17:36 +0400, Bulat Ziganshin wrote: > Hello Steve, > > Sunday, August 23, 2009, 5:27:48 PM, you wrote: > > ghci>> roundN 697.04157958254996 10 > > 697.0415795826 > > afair, double has 13 decimal digits precision, so your > 697.04157958254996 represented by another value. you just looking for > miracles > > I think its 16 or 17 (significant not decimal digits). Its a miracle that Python achieves! But Haskell does not. Python uses doubles too, and for certain operations it uses arbitrary precision floating point (I think). Steve From greenspan.levi at googlemail.com Sun Aug 23 10:23:54 2009 From: greenspan.levi at googlemail.com (Levi Greenspan) Date: Sun Aug 23 10:03:46 2009 Subject: [Haskell-cafe] Monad woes Message-ID: <3e62d4360908230723v1362c51j57816b78e828201b@mail.gmail.com> Hi all, I try to create a simple monad using a stack of Reader and IO but when using it, I encounter some problems. The Monad is defined as M a: {-# LANGUAGE GeneralizedNewtypeDeriving #-} module Main where import Control.Monad.Reader import Control.Concurrent newtype M a = M { unM :: ReaderT String IO a } deriving (Monad, MonadIO, MonadReader String) runM :: String -> M a -> IO a runM s m = runReaderT (unM m) s loop :: (String -> M ()) -> M () loop f = forever $ f "hello" I then define a callback function to be invoked by 'loop': callback :: String -> M () callback s = liftIO $ print s >> threadDelay 1000000 So far so good. Then I test it like this: test1 :: IO () test1 = runM "foo" $ do loop callback liftIO $ print "here" -- OK. Never reached Still works fine. 'loop' never returns. In a real life application 'loop' is an event loop and I'd like to fork it into a new thread like this: test3 :: IO () test3 = runM "foo" $ liftIO $ do forkIO $ do return $ loop callback return () print "here" threadDelay 2000000 This not only looks ugly, it also doesn't work. For 'loop callback' to pass the type checker, it had to be returned into the IO monad. But I guess due to laziness, 'loop' will never be called. This can be confirmed without forkIO: test2 :: IO () test2 = runM "foo" $ liftIO $ do return $ loop callback print "here" Again, 'loop callback' will not be invoked. Now, given that I must find a way to combine IO and my M monad I don't know what to try next. Prima facie it seems I must somehow force 'loop callback' to be evaluated, but how? Not to mention all the liftIO clutter. I would greatly appreciate some help here. Thank you very much! Cheers, Levi -------------- next part -------------- A non-text attachment was scrubbed... Name: Test.hs Type: text/x-haskell Size: 872 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090823/6842ab4c/Test.bin From jeremy at n-heptane.com Sun Aug 23 11:08:08 2009 From: jeremy at n-heptane.com (Jeremy Shaw) Date: Sun Aug 23 10:47:59 2009 Subject: [Haskell-cafe] Monad woes In-Reply-To: <3e62d4360908230723v1362c51j57816b78e828201b@mail.gmail.com> References: <3e62d4360908230723v1362c51j57816b78e828201b@mail.gmail.com> Message-ID: <87hbvyzhyf.wl%jeremy@n-heptane.com> At Sun, 23 Aug 2009 16:23:54 +0200, Levi Greenspan wrote: What you probably want is: test2' :: IO () test2' = runM "foo" $ do loop callback liftIO $ print "here" Taking a look at your version: > test2 :: IO () > test2 = runM "foo" $ liftIO $ do > return $ loop callback > print "here" Since 'print' has the type IO (), this whole do statement has the type IO (): do return $ loop callback print "here" In isolation, we see the following expression has the type: *Main> :t return $ loop callback return $ loop callback :: (Monad m) => m (M ()) so, in context it has the type: return $ loop callback :: (Monad m) => IO (M ()) It is an IO operation which returns a value of type, M (). But, nothing is done with that value, it is just thrown away. We could hack it to work like this: test2'' :: IO () test2'' = runM "foo" $ liftIO $ do m <- return $ loop callback runM "m" m print "here" but test2' seems better. If you want to add a forkIO, the forkIO must go before the runM: testFork :: IO ThreadId testFork = forkIO $ runM "foo" $ do loop callback liftIO $ print "here" Let's say we try to put it after the runM: testFork :: IO ThreadId testFork = runM "foo" $ forkIO $ do loop callback liftIO $ print "here" This will fail with the error: Couldn't match expected type `M ()' against inferred type `IO ()' Because runM expects something of type M (), but forkIO has the type IO ThreadId. So, we can use liftIO to convert the forkIO into a value of type M: testFork :: IO ThreadId testFork = runM "foo" $ liftIO (forkIO $ do loop callback liftIO $ print "here") Now we get the error: Couldn't match expected type `M ()' against inferred type `IO ()' In a stmt of a 'do' expression: loop callback because forkIO expects values of type IO (), but the do block has the type M (). So, we can use runM to convert the M () to an IO () testFork :: IO ThreadId testFork = runM "foo" $ liftIO (forkIO $ do runM "loop" $ loop callback print "here") But, we see that we are now back to the position of having the forkIO before the (second) runM. We can simplfy that expression to just: testFork :: IO ThreadId testFork = forkIO $ do runM "loop" $ loop callback print "here" hope this helps. - jeremy From allbery at ece.cmu.edu Sun Aug 23 11:13:11 2009 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Sun Aug 23 10:53:32 2009 Subject: [Haskell-cafe] hslogger and syslog-ng In-Reply-To: References: Message-ID: <73DA6693-CDBE-4FCD-A26D-CCCB4754BDE0@ece.cmu.edu> On Aug 23, 2009, at 09:41 , Magnus Therning wrote: > I'm having some problem with logging to syslog using System.Log.Logger > and friends. I have the following: > >> :m +System.Log.Logger >> :m +System.Log.Handler.Syslog >> sl <- openlog "foo" [PID] USER DEBUG >> updateGlobalLogger rootLoggerName (addHandler sl) >> warningM "bar" "test" > *** Exception: sendTo: protocol error (Protocol wrong type for socket) > > What could be the cause for this? > I've tried hsyslog and it reports to my instance of syslog without > problems. Looks like hslogger assumes /dev/log is always a datagram socket; hsyslog uses the system openlog(), which correctly recognizes that syslog-ng uses a stream socket. (Think UDP and TCP, respectively, except that there's no IP involved with local sockets.) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 195 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090823/810aeb6f/PGP.bin From jeremy at n-heptane.com Sun Aug 23 11:21:01 2009 From: jeremy at n-heptane.com (Jeremy Shaw) Date: Sun Aug 23 11:00:53 2009 Subject: [Haskell-cafe] Monad woes In-Reply-To: <87hbvyzhyf.wl%jeremy@n-heptane.com> References: <3e62d4360908230723v1362c51j57816b78e828201b@mail.gmail.com> <87hbvyzhyf.wl%jeremy@n-heptane.com> Message-ID: <87fxbizhcy.wl%jeremy@n-heptane.com> Also, you could define a forkM function like this: forkM :: M () -> M ThreadId forkM (M r) = M $ mapReaderT forkIO r which could be used like this: test = runM "foo" $ do forkM $ loop callback liftIO $ print "here" If we were to expand forkM in test, we would get something like: test' = runM "foo" $ do env <- ask liftIO $ forkIO (runM env $ loop callback) liftIO $ print "here" So, this does not change the 'rule' of forkIO having to come before a runM. It just wraps it up nicely. - jeremy From magnus at therning.org Sun Aug 23 11:33:39 2009 From: magnus at therning.org (Magnus Therning) Date: Sun Aug 23 11:13:43 2009 Subject: [Haskell-cafe] hslogger and syslog-ng In-Reply-To: <73DA6693-CDBE-4FCD-A26D-CCCB4754BDE0@ece.cmu.edu> References: <73DA6693-CDBE-4FCD-A26D-CCCB4754BDE0@ece.cmu.edu> Message-ID: <4A916153.6050009@therning.org> Brandon S. Allbery KF8NH wrote: > On Aug 23, 2009, at 09:41 , Magnus Therning wrote: >> I'm having some problem with logging to syslog using System.Log.Logger >> and friends. I have the following: >> >>> :m +System.Log.Logger >>> :m +System.Log.Handler.Syslog >>> sl <- openlog "foo" [PID] USER DEBUG >>> updateGlobalLogger rootLoggerName (addHandler sl) >>> warningM "bar" "test" >> *** Exception: sendTo: protocol error (Protocol wrong type for socket) >> >> What could be the cause for this? >> I've tried hsyslog and it reports to my instance of syslog without >> problems. > > > Looks like hslogger assumes /dev/log is always a datagram socket; > hsyslog uses the system openlog(), which correctly recognizes that > syslog-ng uses a stream socket. (Think UDP and TCP, respectively, > except that there's no IP involved with local sockets.) Oh, though logging to a dgram socket doesn't seem to work either. I added the following line to /etc/syslog-ng.conf: unix-dgram("/dev/dlog"); Restarted it and checked that the socket was there. Then I ran the following: > :m +System.Log.Logger > :m +System.Log.Handler.Syslog > sl <- openlog_local "/dev/dlog" "foo" [PID] USER DEBUG > updateGlobalLogger rootLoggerName (addHandler sl) > warningM "bar" "test" *** Exception: sendTo: protocol error (Protocol wrong type for socket) Still the same result :-( /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?org http://therning.org/magnus identi.ca|twitter: magthe -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: OpenPGP digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090823/e27d8365/signature.bin From daniel.is.fischer at web.de Sun Aug 23 11:41:07 2009 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Sun Aug 23 11:22:03 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: <1251034068.3085.55.camel@localhost> References: <20090822170352.5A3C53245AF@www.haskell.org> <5e0214850908230412s199c79absc66f47e03a539eb7@mail.gmail.com> <1251034068.3085.55.camel@localhost> Message-ID: <200908231741.07367.daniel.is.fischer@web.de> Am Sonntag 23 August 2009 15:27:48 schrieb Steve: > On Sun, 2009-08-23 at 15:12 +0400, Eugene Kirpichov wrote: > > > There is *not* the same problem in Python: > > > $ python > > > Python 2.6.2 (r262:71600, Jul 9 2009, 23:16:53) > > > [GCC 4.4.0 20090506 (Red Hat 4.4.0-4)] on linux2 > > > Type "help", "copyright", "credits" or "license" for more information. > > > > > >>>> import math > > >>>> math.log10(1000) > > > > > > 3.0 > > > > > >>> import math > > >>> math.log(1000,10) > > > > 2.9999999999999996 > > That is surprising. I think its a Python bug - the results should be > consistent. On the other hand, it is also desirable to have log(a,b) == log(a)/log(b). If you have a special implementation of log10, you must decide which consistency you want to break, log(a,10) == log10(a) or log(a,10) == log(a)/log(10). > > > > Recent work in Python 3 (and Python 2.6) has improved the handling of > > > floating point numbers, and addresses exactly the problem that Roberto > > > has raised. > > > > > > I see no reason why Haskell could not improve its handling of floating > > > point numbers by using similar techniques. > > > > You mean introducing a "log10" function into the definition of the > > Floating class ? That might be a proposal for Haskell Prime. > > I was not thinking of the log10 function. I was thinking of the changes > mentioned in > http://docs.python.org/3.1/whatsnew/3.1.html > where it says > "Python now uses David Gay?s algorithm for finding the shortest floating > point representation that doesn?t change its value. This should help > mitigate some of the confusion surrounding binary floating point > numbers." Note however that that only concerns the output, not the underlying value. It doesn't change the fact that log(1000)/log(10) (== log(1000,10)) < 3 in Python, too. > > Also, I had a problem using floating point in Python where > > >>> round(697.04157958254996, 10) > > gave > 697.04157958259998 > which is closer to > 697.0415795826 > than the desired result of > 697.0415795825 Well, 10^10*(697.04157958254996 :: Double) == 6970415795825.5, that gets rounded to 6970415795826 under both, round-half-up and round-half-to-even, and (6970415795826/10^10 :: Double) == 697.04157958259998 Though ghci displays it as 697.0415795826, unlike Python. > > Its been fixed in the latest versions of Python: > >>> round(697.04157958254996, 10) > > 697.0415795825 > > > I'm not sure what the equivalent in Haskell is. Is there a function for > rounding to a number of decimal digits ? > I came up with this: > > roundN :: Double -> Int -> Double > roundN n ndigits = fromIntegral (round $ n * m) / m > where m = 10 ^ ndigits > > ghci> roundN 697.04157958254996 10 > 697.0415795826 > > which is not the desired result. Prelude Numeric> let roundN :: Double -> Int -> Double; roundN x d = let { m = 10^(d+1); i = floor (m*x); r = i `mod` 10; j = if r < 5 then i-r else i-r+10 } in fromInteger j/m roundN :: Double -> Int -> Double roundN x d = fromInteger j / m where m = 10^(d+1) i = floor (m*x) r = i `mod` 10 j | r < 5 = i-r | otherwise = i+10-r ghci> roundN 697.04157958254996 10 697.0415795825 I haven't treated negative input, but, more importantly, floating point representation being what it is, there are cases where this doesn't do what you want/expect either. > > Steve From greenspan.levi at googlemail.com Sun Aug 23 12:14:30 2009 From: greenspan.levi at googlemail.com (Levi Greenspan) Date: Sun Aug 23 11:54:21 2009 Subject: [Haskell-cafe] Monad woes In-Reply-To: <87hbvyzhyf.wl%jeremy@n-heptane.com> References: <3e62d4360908230723v1362c51j57816b78e828201b@mail.gmail.com> <87hbvyzhyf.wl%jeremy@n-heptane.com> Message-ID: <3e62d4360908230914y7b1f1df8gf5ed273907a83e5a@mail.gmail.com> Hi Jeremy, On Sun, Aug 23, 2009 at 5:08 PM, Jeremy Shaw wrote: > What you probably want is: > > test2' :: IO () > test2' = runM "foo" $ do > ? ?loop callback > ? ?liftIO $ print "here" This equals my test1 version which is fine without forkIO. > return $ loop callback :: (Monad m) => IO (M ()) > > It is an IO operation which returns a value of type, M (). But, > nothing is done with that value, it is just thrown away. I see. This is what I feared. > If you want to add a forkIO, the forkIO must go before the runM: OK. I tried all kinds of combinations, but not forkIO in front of 'runM' . The reason being that I only use forkIO because 'loop' never returns so in order to proceed I would have to put it into the background. Basically I want two threads running inside the same M monad. > hope this helps. Many thanks Jeremy. Your explanations are indeed very helpful. But they also strengthen my gut feeling that running two threads in the same M monad is hard (if not impossible) to do. Cheers, Levi From allbery at ece.cmu.edu Sun Aug 23 12:19:59 2009 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Sun Aug 23 12:00:17 2009 Subject: [Haskell-cafe] hslogger and syslog-ng In-Reply-To: <4A916153.6050009@therning.org> References: <73DA6693-CDBE-4FCD-A26D-CCCB4754BDE0@ece.cmu.edu> <4A916153.6050009@therning.org> Message-ID: <2B9BD2ED-E271-4FD0-BB4B-4E5413CA3B60@ece.cmu.edu> On Aug 23, 2009, at 11:33 , Magnus Therning wrote: > Brandon S. Allbery KF8NH wrote: >> On Aug 23, 2009, at 09:41 , Magnus Therning wrote: >>> I'm having some problem with logging to syslog using >>> System.Log.Logger >>> and friends. I have the following: >>> >>>> :m +System.Log.Logger >>>> :m +System.Log.Handler.Syslog >>>> sl <- openlog "foo" [PID] USER DEBUG >>>> updateGlobalLogger rootLoggerName (addHandler sl) >>>> warningM "bar" "test" >>> *** Exception: sendTo: protocol error (Protocol wrong type for >>> socket) >>> >>> What could be the cause for this? >>> I've tried hsyslog and it reports to my instance of syslog without >>> problems. >> Looks like hslogger assumes /dev/log is always a datagram socket; >> hsyslog uses the system openlog(), which correctly recognizes that >> syslog-ng uses a stream socket. (Think UDP and TCP, respectively, >> except that there's no IP involved with local sockets.) > > Oh, though logging to a dgram socket doesn't seem to work either. > > I added the following line to /etc/syslog-ng.conf: > > unix-dgram("/dev/dlog"); > > Restarted it and checked that the socket was there. Then I ran the > following: > > > :m +System.Log.Logger > > :m +System.Log.Handler.Syslog > > sl <- openlog_local "/dev/dlog" "foo" [PID] USER DEBUG > > updateGlobalLogger rootLoggerName (addHandler sl) > > warningM "bar" "test" > *** Exception: sendTo: protocol error (Protocol wrong type for > socket) Hm. hslogger uses a hardcoded 0 instead of PF_UNSPEC (not that Network.BSD exports PF_*, and it too hardcodes defaultProtocol as 0) but a spot check of system under my control suggests it should work most places. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 195 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090823/65378315/PGP.bin From dsouza at bitforest.org Sun Aug 23 12:25:55 2009 From: dsouza at bitforest.org (Diego Souza) Date: Sun Aug 23 12:09:20 2009 Subject: [Haskell-cafe] oauth in haskell - reviewers? In-Reply-To: <57526e770908222008o25780147ve211a8279dc82f56@mail.gmail.com> References: <20090822233654.GA16495@mephisto.bitforest.org> <57526e770908222008o25780147ve211a8279dc82f56@mail.gmail.com> Message-ID: <20090823162555.GA4190@mephisto.bitforest.org> Hi Alex, > - In the Token datatype, you can automatically create the accessor > functions (oath_token, etc.) by using named fields: I though about that too and I was not sure about what to do. The reason I didn't use it is because I don't export the value constructors of Token type, that is why I created the access functions explicitly. > - When you have multiple datatype constructors with similar arguments > (as with Token or Request), it may be better to use a Boolean-type > flag saying which one it is (e.g. HTTP or HTTPS) and then a single > datatype with all of the different arguments in it. This may help you > remove code duplication elsewhere. Right, it makes sense. > - I think you can use join from Control.Monad and functions from > Control.Applicative in your "response" function to make it quite a bit > cleaner. To be honest I'm not familiar with Control.Applicative at all. I'll read about it and see if I can figure how to do this. A quick search pointed me to this: http://www.soi.city.ac.uk/~ross/papers/Applicative.html Is there any other resources you would suggest me to read? Thanks at lot, -- ~dsouza yahoo!im: paravinicius gpg key fingerprint: 71B8 CE21 3A6E F894 5B1B 9ECE F88E 067F E891 651E From greenspan.levi at googlemail.com Sun Aug 23 12:38:33 2009 From: greenspan.levi at googlemail.com (Levi Greenspan) Date: Sun Aug 23 12:18:26 2009 Subject: [Haskell-cafe] Monad woes In-Reply-To: <87fxbizhcy.wl%jeremy@n-heptane.com> References: <3e62d4360908230723v1362c51j57816b78e828201b@mail.gmail.com> <87hbvyzhyf.wl%jeremy@n-heptane.com> <87fxbizhcy.wl%jeremy@n-heptane.com> Message-ID: <3e62d4360908230938r55989adev1c6a046d0d18d71b@mail.gmail.com> On Sun, Aug 23, 2009 at 5:21 PM, Jeremy Shaw wrote: > Also, you could define a forkM function like this: > > forkM :: M () -> M ThreadId > forkM (M r) = M $ mapReaderT forkIO r > > which could be used like this: > > test = runM "foo" $ do > ? ? ? ? forkM $ loop callback > ? ? ? ? liftIO $ print "here" > > If we were to expand forkM in test, we would get something like: > > test' = runM "foo" $ do > ? ? ? ? ?env <- ask > ? ? ? ? ?liftIO $ forkIO (runM env $ loop callback) > ? ? ? ? ?liftIO $ print "here" > > So, this does not change the 'rule' of forkIO having to come before a > runM. It just wraps it up nicely. Somehow I missed this e-mail when I replied last time. Now this is actually the solution to my problem. I didn't think of a second runM with the same environment. Brilliant (OTOH it probably highlights the fact that I am only a Monad novice). Many thanks Jeremy. You saved my day! Cheers, Levi From ryani.spam at gmail.com Sun Aug 23 13:25:39 2009 From: ryani.spam at gmail.com (Ryan Ingram) Date: Sun Aug 23 13:05:29 2009 Subject: [Haskell-cafe] Monad woes In-Reply-To: <3e62d4360908230914y7b1f1df8gf5ed273907a83e5a@mail.gmail.com> References: <3e62d4360908230723v1362c51j57816b78e828201b@mail.gmail.com> <87hbvyzhyf.wl%jeremy@n-heptane.com> <3e62d4360908230914y7b1f1df8gf5ed273907a83e5a@mail.gmail.com> Message-ID: <2f9b2d30908231025ue4004b2rbc5cc25e04666ab8@mail.gmail.com> On Sun, Aug 23, 2009 at 9:14 AM, Levi Greenspan wrote: > Many thanks Jeremy. Your explanations are indeed very helpful. But > they also strengthen my gut feeling that running two threads in the > same M monad is hard (if not impossible) to do. I think here is where you are going wrong; there is no "same M monad". Perhaps it will help if you saw how ReaderT works: newtype ReaderT r m a = ReaderT { runReaderT :: r -> m a } That gives you these two functions: ReaderT :: (r -> m a) -> ReaderT r m a runReaderT :: ReaderT r m a -> r -> m a There's nothing magic about it; ReaderT just wraps up a function and provides "bind" and "return" so that you can glue actions together: (>>=) :: Monad m => ReaderT r m a -> (a -> ReaderT r m b) -> ReaderT r m b ma >>= f = ReaderT $ \r -> do a <- runReaderT ma r let mb = f a b <- runReaderT mb r return b (of course the code is written more concisely than this, but I am trying to help make it explicit) So internally *every* bind has multiple "runM"s inside of it, magically whipped up by the compiler inside of "deriving Monad". When you do "runM" explicitly here, you are just helping to lift "forkIO" back into your monad. -- ryan From magnus at therning.org Sun Aug 23 14:05:48 2009 From: magnus at therning.org (Magnus Therning) Date: Sun Aug 23 13:45:41 2009 Subject: [Haskell-cafe] hslogger and syslog-ng In-Reply-To: <2B9BD2ED-E271-4FD0-BB4B-4E5413CA3B60@ece.cmu.edu> References: <73DA6693-CDBE-4FCD-A26D-CCCB4754BDE0@ece.cmu.edu> <4A916153.6050009@therning.org> <2B9BD2ED-E271-4FD0-BB4B-4E5413CA3B60@ece.cmu.edu> Message-ID: <4A9184FC.5020208@therning.org> Brandon S. Allbery KF8NH wrote: >> Oh, though logging to a dgram socket doesn't seem to work either. >> >> I added the following line to /etc/syslog-ng.conf: >> >> unix-dgram("/dev/dlog"); >> >> Restarted it and checked that the socket was there. Then I ran the >> following: >> >> > :m +System.Log.Logger >> > :m +System.Log.Handler.Syslog >> > sl <- openlog_local "/dev/dlog" "foo" [PID] USER DEBUG >> > updateGlobalLogger rootLoggerName (addHandler sl) >> > warningM "bar" "test" >> *** Exception: sendTo: protocol error (Protocol wrong type for socket) > > > Hm. hslogger uses a hardcoded 0 instead of PF_UNSPEC (not that > Network.BSD exports PF_*, and it too hardcodes defaultProtocol as 0) but > a spot check of system under my control suggests it should work most > places. What kind of systems to you have under your control? /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?org http://therning.org/magnus identi.ca|twitter: magthe -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: OpenPGP digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090823/ecd17803/signature.bin From allbery at ece.cmu.edu Sun Aug 23 14:11:15 2009 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Sun Aug 23 13:51:23 2009 Subject: [Haskell-cafe] hslogger and syslog-ng In-Reply-To: <4A9184FC.5020208@therning.org> References: <73DA6693-CDBE-4FCD-A26D-CCCB4754BDE0@ece.cmu.edu> <4A916153.6050009@therning.org> <2B9BD2ED-E271-4FD0-BB4B-4E5413CA3B60@ece.cmu.edu> <4A9184FC.5020208@therning.org> Message-ID: <24AA27CD-F35E-4030-B114-CFF6427BAEFC@ece.cmu.edu> On Aug 23, 2009, at 14:05 , Magnus Therning wrote: > Brandon S. Allbery KF8NH wrote: >>> Oh, though logging to a dgram socket doesn't seem to work either. >>> >>> I added the following line to /etc/syslog-ng.conf: >>> >>> unix-dgram("/dev/dlog"); >>> >>> Restarted it and checked that the socket was there. Then I ran >>> the following: >>> >>> > :m +System.Log.Logger >>> > :m +System.Log.Handler.Syslog >>> > sl <- openlog_local "/dev/dlog" "foo" [PID] USER DEBUG >>> > updateGlobalLogger rootLoggerName (addHandler sl) >>> > warningM "bar" "test" >>> *** Exception: sendTo: protocol error (Protocol wrong type for >>> socket) >> Hm. hslogger uses a hardcoded 0 instead of PF_UNSPEC (not that >> Network.BSD exports PF_*, and it too hardcodes defaultProtocol as >> 0) but a spot check of system under my control suggests it should >> work most places. > > What kind of systems to you have under your control? Various SuSE Linux, Solaris 8/9/10, Mac OS X (should be mostly the same as FreeBSD at this level). -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 195 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090823/a29d3cf2/PGP-0001.bin From alexander.dunlap at gmail.com Sun Aug 23 14:13:27 2009 From: alexander.dunlap at gmail.com (Alexander Dunlap) Date: Sun Aug 23 13:53:36 2009 Subject: [Haskell-cafe] oauth in haskell - reviewers? In-Reply-To: <20090823162555.GA4190@mephisto.bitforest.org> References: <20090822233654.GA16495@mephisto.bitforest.org> <57526e770908222008o25780147ve211a8279dc82f56@mail.gmail.com> <20090823162555.GA4190@mephisto.bitforest.org> Message-ID: <57526e770908231113ma2685b5k5d84fa93f3a2d60f@mail.gmail.com> On Sun, Aug 23, 2009 at 9:25 AM, Diego Souza wrote: > Hi Alex, > >> - In the Token datatype, you can automatically create the accessor >> functions (oath_token, etc.) by using named fields: > I though about that too and I was not sure about what to do. The reason > I didn't use it is because I don't export the value constructors of > Token type, that is why I created the access functions explicitly. I'm pretty sure you can export just the access functions and not the data constructors. They're just ordinary functions with a bit of syntactic sugar, so they can be exported even if the constructors aren't. >> - I think you can use join from Control.Monad and functions from >> Control.Applicative in your "response" function to make it quite a bit >> cleaner. > To be honest I'm not familiar with Control.Applicative at all. ?I'll > read about it and see if I can figure how to do this. > > A quick search pointed me to this: > http://www.soi.city.ac.uk/~ross/papers/Applicative.html > > Is there any other resources you would suggest me to read? > The rule of thumb I use is that you can replace foo = do x1 <- action1 x2 <- action2 x3 <- action3 ... xn <- actionn return (bar x1 x2 x3 ... xn) by foo = bar <$> action1 <*> action2 <*> action3 <*> ... <*> actionn for any number of actions. (<$>) is a synonym for fmap and (<*>) is the same as Control.Monad.ap if the applicative functor is also a monad. (All monads can be made instances of Applicative, and most [all?] of the standard ones are.) Alex From magnus at therning.org Sun Aug 23 15:38:03 2009 From: magnus at therning.org (Magnus Therning) Date: Sun Aug 23 15:17:59 2009 Subject: [Haskell-cafe] hslogger and syslog-ng In-Reply-To: <24AA27CD-F35E-4030-B114-CFF6427BAEFC@ece.cmu.edu> References: <73DA6693-CDBE-4FCD-A26D-CCCB4754BDE0@ece.cmu.edu> <4A916153.6050009@therning.org> <2B9BD2ED-E271-4FD0-BB4B-4E5413CA3B60@ece.cmu.edu> <4A9184FC.5020208@therning.org> <24AA27CD-F35E-4030-B114-CFF6427BAEFC@ece.cmu.edu> Message-ID: <4A919A9B.3090208@therning.org> Brandon S. Allbery KF8NH wrote: > On Aug 23, 2009, at 14:05 , Magnus Therning wrote: >> Brandon S. Allbery KF8NH wrote: >>>> Oh, though logging to a dgram socket doesn't seem to work either. >>>> >>>> I added the following line to /etc/syslog-ng.conf: >>>> >>>> unix-dgram("/dev/dlog"); >>>> >>>> Restarted it and checked that the socket was there. Then I ran the >>>> following: >>>> >>>> > :m +System.Log.Logger >>>> > :m +System.Log.Handler.Syslog >>>> > sl <- openlog_local "/dev/dlog" "foo" [PID] USER DEBUG >>>> > updateGlobalLogger rootLoggerName (addHandler sl) >>>> > warningM "bar" "test" >>>> *** Exception: sendTo: protocol error (Protocol wrong type for socket) >>> Hm. hslogger uses a hardcoded 0 instead of PF_UNSPEC (not that >>> Network.BSD exports PF_*, and it too hardcodes defaultProtocol as 0) >>> but a spot check of system under my control suggests it should work >>> most places. >> >> What kind of systems to you have under your control? > > Various SuSE Linux, Solaris 8/9/10, Mac OS X (should be mostly the same > as FreeBSD at this level). It seems to be depending on the syslog daemon to some extent. Debian with sysklogd: no problems, Debian with syslog-ng: exactly the problem I see on my Arch system. I've raised a bug on the dev site: http://software.complete.org/software/issues/show/178 /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus?therning?org Jabber: magnus?therning?org http://therning.org/magnus identi.ca|twitter: magthe -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: OpenPGP digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090823/c0b7d6f9/signature.bin From alistair at abayley.org Sun Aug 23 16:47:02 2009 From: alistair at abayley.org (Alistair Bayley) Date: Sun Aug 23 16:26:52 2009 Subject: [Haskell-cafe] Takusen - is anyone currently using it on Win32 - ODBC? In-Reply-To: References: Message-ID: <79d7c4980908231347i630c29fdk147ab17303e56368@mail.gmail.com> 2009/8/23 G?nther Schmidt : > > is anyone currently using takusen with odbc on Win32? In particular with MS > Access? > > I'm asking because I noticed that when database libraries are declared to > work with ODBC no one seems to mean Win32 ODBC, but rather Unix ODBC. Yes. The ODBC backend is tested on Win32, although not with MS Access (Oracle, PostgreSQL, and MS SQL Server have been tested). If you have problems with MS Access, do let me know. Alistair From ok at cs.otago.ac.nz Sun Aug 23 19:08:23 2009 From: ok at cs.otago.ac.nz (Richard O'Keefe) Date: Sun Aug 23 18:48:19 2009 Subject: [Haskell-cafe] Converting typeset mathematics into Haskell ? In-Reply-To: <4A8F32A2.6060608@bigpond.net.au> References: <4A8F32A2.6060608@bigpond.net.au> Message-ID: <447AAD9A-7BEF-4944-83D0-EB560B151423@cs.otago.ac.nz> On Aug 22, 2009, at 11:49 AM, Mark Wassell wrote: > Think about how you would convert this into Haskell. You might then > find yourself wondering why you have to convert it into Haskell at > all. But very quickly you realise that it is because a lot of mathematical notation is heavily ambiguous and requires fairly sophisticated N.I. to parse correctly. [N.I. = natural intelligence. I don't know how to program a computer to do it.] -1 For example, if x is a number, x is its reciprocal. But if x is a function, it's the inverse function. Some of the most appalling mathematical notation can be found in the Correspondence Analysis community, where the meaning of a subscript may depend not on the value of the subscript expression but its spelling. In that case, converting the mathematics to Haskell would be an act of great charity not for programmers but for _any_ mortals trying to make sense of the formulas. From duncan.coutts at worc.ox.ac.uk Sun Aug 23 17:11:36 2009 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Sun Aug 23 20:26:25 2009 Subject: [Haskell-cafe] Where does documentation get installed with cabal? In-Reply-To: <20090820181735.GH14826@colquitt.org> References: <87praqr1qr.fsf@zagan.made.you> <20090820181735.GH14826@colquitt.org> Message-ID: <1251061896.30910.5158.camel@localhost> On Thu, 2009-08-20 at 14:17 -0400, John Dorsey wrote: > Perhaps it's in /usr/local/share/doc. Mine seem to end up there, and I > don't recall whether I specified that at any point. > > It's not in my ~/.cabal/config, but I am using the very helpful > user-install: False > documentation: True > > I suspect /usr/local/share/doc is the default for documentation in global > installs, but I can't go verify that at the moment. It's given further down in the ~/.cabal/config file. The commented out fields show the default values: install-dirs global -- prefix: /usr/local [..snip..] -- datadir: $prefix/share [..snip..] -- docdir: $datadir/doc/$pkgid hence "/usr/local/share/doc/$pkgid" Duncan From ramsdell0 at gmail.com Sun Aug 23 21:14:10 2009 From: ramsdell0 at gmail.com (John D. Ramsdell) Date: Sun Aug 23 20:54:02 2009 Subject: [Haskell-cafe] Re: Unifcation and matching in Abelian groups In-Reply-To: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> Message-ID: <7687290b0908231814g3acb9e79j97e57e8bc137f618@mail.gmail.com> The patch avoids a redundant zeroing of c[i]. $ diff -u {a,b}/Main.lhs --- a/Main.lhs 2009-08-23 21:07:08.000000000 -0400 +++ b/Main.lhs 2009-08-23 21:09:54.000000000 -0400 @@ -255,12 +255,11 @@ > -- where n is the length of c. > -- x[n] = sum[j] (c[j] div c[i] * x[j]) > -- The new equation to be solved is: -> -- c[i]*x[n] + sum[j] c'[j]*x[j] = d[k] for all k -> -- where c'[j] = c[j] mod c[i] for j /= i and c'[i] = 0. -> let c' = map (\x -> mod x ci) (zero i c) -> c'' = divide ci (zero i c) -> subst' = eliminate n (i, (invert c'' ++ [1], [])) subst in -> intLinEqLoop n (c' ++ [ci], d) subst' +> -- c[i]*x[n] + sum[j] (c[j] mod c[i])*x[j] = d[k] for all k +> intLinEqLoop n (map (\x -> mod x ci) c ++ [ci], d) subst' +> where +> subst' = eliminate n (i, (invert c' ++ [1], [])) subst +> c' = divide ci (zero i c) > > -- Find the smallest coefficient in absolute value > smallest :: [Int] -> (Int, Int) $ From ramsdell0 at gmail.com Sun Aug 23 21:18:21 2009 From: ramsdell0 at gmail.com (John D. Ramsdell) Date: Sun Aug 23 20:58:11 2009 Subject: [Haskell-cafe] Unifcation and matching in Abelian groups In-Reply-To: References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> <404396ef0908190316rc772614p9c660c8ab5095ed6@mail.gmail.com> <7687290b0908190345q23313f4bwf24b6868499ee704@mail.gmail.com> <4A8BF0D3.7050403@jellybean.co.uk> <7687290b0908200557i522f3d92jb4d20707baeb3694@mail.gmail.com> <4A8D4AD9.1050701@jellybean.co.uk> <7687290b0908200637u5022c4e6lf76b759a82222f1f@mail.gmail.com> <4A8D57E1.2050002@jellybean.co.uk> <7687290b0908211851n689b8219p6d19c158cf45e090@mail.gmail.com> Message-ID: <7687290b0908231818o2b01ca11rf8b05984dbb5c034@mail.gmail.com> On Sat, Aug 22, 2009 at 8:30 PM, Lennart Augustsson wrote: > Even if you are only slightly irritated by offset syntax, why are you using it? > {;} works fine. I hadn't thought about that option. I'll give it a try on my next program. John From harald.rotter at sagem.com Mon Aug 24 07:17:28 2009 From: harald.rotter at sagem.com (Harald ROTTER) Date: Mon Aug 24 06:57:28 2009 Subject: [Haskell-cafe] Functional Dependencies and multiparameter typeclasses Message-ID: Dear Haskellers, I am using multi parameter typeclasses to represent images consisting of pixels (e.g. bitmap images). {-# OPTIONS_GHC -XMultiParamTypeClasses #-} module Bitmap where -- | a pixel could be a Word8 (e.g. a graysclale image) -- | or a 3-tuple for RGB images class Pixel p where .... -- | an image could be a UArray or a list of lists of pixels class Pixel p => Image a p where width :: a -> Int height :: a -> Int dims :: a -> (Int, Int) dims img = (height img, width img) If I try to load this module into ghci I get: Could not deduce (Image a p) from the context (Image a p2) arising from a use of 'height' at ..... and Could not deduce (Image a p1) from the context (Image a p2) arising from a use of 'width' at ...... where both errors originate from the 'dims' function. Eventually I figured out that I could remedy the situattion by using functional dependencies like this: class Pixel p => Image a p | a -> p where ... However, I do not really understand the cause of the original problem. Why do I need the functional dependency to make this work ? Any help is appreciated. Thanks Harald. " Ce courriel et les documents qui y sont attaches peuvent contenir des informations confidentielles. Si vous n'etes pas le destinataire escompte, merci d'en informer l'expediteur immediatement et de detruire ce courriel ainsi que tous les documents attaches de votre systeme informatique. Toute divulgation, distribution ou copie du present courriel et des documents attaches sans autorisation prealable de son emetteur est interdite." " This e-mail and any attached documents may contain confidential or proprietary information. If you are not the intended recipient, please advise the sender immediately and delete this e-mail and all attached documents from your computer system. Any unauthorised disclosure, distribution or copying hereof is prohibited." From miguelimo38 at yandex.ru Mon Aug 24 07:29:46 2009 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Mon Aug 24 07:11:13 2009 Subject: [Haskell-cafe] Functional Dependencies and multiparameter typeclasses In-Reply-To: References: Message-ID: <4A9279AA.1030607@yandex.ru> > However, I do not really understand the cause of the original problem. Why > do I need the functional dependency to make this work ? Suppose you have an instance: instance Pixel MyPixel where... instance Image MyImage MyPixel where width i = countPixels i ... And somebody (not necessarily you) makes another instance: instance Pixel CustomPixel where... instance Image MyImage CustomPixel where width i = 0 ... Now, take any image im :: MyImage Then you'd expect that width im :: Int But now there are TWO implementations of "width :: MyImage -> Int" and no way for compiler to figure out which one to use. GHC sort of foresees this problem. By adding a functional dependency you instruct it to forbid the second declaration, when the first one is present, thus removing the problem. From dsouza at bitforest.org Mon Aug 24 07:40:47 2009 From: dsouza at bitforest.org (Diego Souza) Date: Mon Aug 24 07:24:11 2009 Subject: [Haskell-cafe] oauth in haskell - reviewers? In-Reply-To: <57526e770908231113ma2685b5k5d84fa93f3a2d60f@mail.gmail.com> References: <20090822233654.GA16495@mephisto.bitforest.org> <57526e770908222008o25780147ve211a8279dc82f56@mail.gmail.com> <20090823162555.GA4190@mephisto.bitforest.org> <57526e770908231113ma2685b5k5d84fa93f3a2d60f@mail.gmail.com> Message-ID: <20090824114047.GB3400@mephisto.bitforest.org> Hi Alex, It indeed helped a lot. I'm still reading more about Control.Applicative, but I applied your other suggestions and they in fact reduced duplication. I'm going to upload it to hackage and let's see how it goes. Thanks, -- ~dsouza yahoo!im: paravinicius gpg key fingerprint: 71B8 CE21 3A6E F894 5B1B 9ECE F88E 067F E891 651E From harald.rotter at sagem.com Mon Aug 24 07:51:03 2009 From: harald.rotter at sagem.com (Harald ROTTER) Date: Mon Aug 24 07:31:00 2009 Subject: [Haskell-cafe] Functional Dependencies and multiparametertypeclasses Message-ID: Thanks for the quick response. Your explanation is so much clearer than ghc's error messages :-)) Harald. |---------+------------------------------> | | Miguel Mitrofanov | | | | | | | | | | | | 24.08.2009 13:29 | | | Delivered date: | | | 24.08.2009 13:31 | | | | |---------+------------------------------> >------------------------------------------------------------------------------------------------------------| | | | To: Harald ROTTER | | cc: haskell-cafe@haskell.org | | Subject: Re: [Haskell-cafe] Functional Dependencies and multiparameter typeclasses | >------------------------------------------------------------------------------------------------------------| > However, I do not really understand the cause of the original problem. Why > do I need the functional dependency to make this work ? Suppose you have an instance: instance Pixel MyPixel where... instance Image MyImage MyPixel where width i = countPixels i ... And somebody (not necessarily you) makes another instance: instance Pixel CustomPixel where... instance Image MyImage CustomPixel where width i = 0 ... Now, take any image im :: MyImage Then you'd expect that width im :: Int But now there are TWO implementations of "width :: MyImage -> Int" and no way for compiler to figure out which one to use. GHC sort of foresees this problem. By adding a functional dependency you instruct it to forbid the second declaration, when the first one is present, thus removing the problem. " Ce courriel et les documents qui y sont attaches peuvent contenir des informations confidentielles. Si vous n'etes pas le destinataire escompte, merci d'en informer l'expediteur immediatement et de detruire ce courriel ainsi que tous les documents attaches de votre systeme informatique. Toute divulgation, distribution ou copie du present courriel et des documents attaches sans autorisation prealable de son emetteur est interdite." " This e-mail and any attached documents may contain confidential or proprietary information. If you are not the intended recipient, please advise the sender immediately and delete this e-mail and all attached documents from your computer system. Any unauthorised disclosure, distribution or copying hereof is prohibited." From dsouza at bitforest.org Mon Aug 24 07:48:14 2009 From: dsouza at bitforest.org (Diego Souza) Date: Mon Aug 24 07:31:36 2009 Subject: [Haskell-cafe] ANNOUNCE: OAuth library in haskell Message-ID: <20090824114814.GC3400@mephisto.bitforest.org> Dear Haskellers, hoauth is a library which helps you to deal with oauth protocol. Currently it supports only consumer side applications, but there are plans to add service providers support in near future. The source code can be found at [darcs]: http://projects.bitforest.org/hoauth/ and now in hackage: http://hackage.haskell.org/package/hoauth If you have any questions, comments or criticism, please get in touch with me. I'll appreciate it very much, specially because there are so many things yet to learn. Thanks, PS: This is the first piece of code I produce in Haskell since I've start learning it few months ago. I must say it has been a joy since then. -- ~dsouza yahoo!im: paravinicius gpg key fingerprint: 71B8 CE21 3A6E F894 5B1B 9ECE F88E 067F E891 651E From explicitcall at googlemail.com Mon Aug 24 08:49:20 2009 From: explicitcall at googlemail.com (Max Desyatov) Date: Mon Aug 24 08:29:08 2009 Subject: [Haskell-cafe] ANNOUNCE: graphtype =?utf-8?b?4oCU?= A simple tool to illustrate dependencies between Haskell types Message-ID: <87y6p9v0kv.fsf@zagan.made.you> While developing applications which deal with complex data it is crucial to know how exactly you manipulate this data. Haskell provides excellent tools for expressing a data scheme you work with: ADTs, `type` and `newtype` declarations, type classes and much more is hidden in rich Haskell's type system. Obviously, when types of data in your domain you work with grow ? all declarations grow, and it becomes hard to grasp all dependencies, to change them and to remove them deliberately. graphtype was developed to visualise type declarations in you Haskell source files. It produces .dot-file for subsequent processing with graphviz. Results for example file bundled with graphtype: http://i.piccy.info/i4/00/90/bfa07290012c2d3b455696bdaa86.png To play with it, you can use hackage: http://hackage.haskell.org/package/graphtype or hack some code: http://github.com/explicitcall/graphtype Visualisation of dependencies in complex type class hierarchies is still on the way. It isn't obvious how do to this nicely, as in most cases type class declarations are imported from other libraries, and you don't always have source files for them. Anyway, graphtype is fairly usable. Leave here your questions, suggestions and have fun looking at type dependencies in your code. WBR, Max From bulat.ziganshin at gmail.com Mon Aug 24 08:43:58 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Mon Aug 24 08:31:22 2009 Subject: [Haskell-cafe] Functional Dependencies and multiparameter typeclasses In-Reply-To: References: Message-ID: <56605980.20090824164358@gmail.com> Hello Harald, Monday, August 24, 2009, 3:17:28 PM, you wrote: > class Pixel p where > -- | an image could be a UArray or a list of lists of pixels > class Pixel p => Image a p where read http://haskell.org/haskellwiki/OOP_vs_type_classes here you say that Image is a particular case of Pixel :) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From chris at eidhof.nl Mon Aug 24 10:11:16 2009 From: chris at eidhof.nl (Chris Eidhof) Date: Mon Aug 24 09:51:06 2009 Subject: [Haskell-cafe] [ann] formlets 0.6 Message-ID: <80CE43C3-0EE4-4ED4-BDCA-0C06A1AC3F0F@eidhof.nl> Hey everyone, I wanted to let you know that the formlets team has released a new version of the formlets [1] on hackage, a library to build type-safe, composable web forms. Most notably, Mightybyte and I worked on the massInput functionality, which is now ready for use! Mightybyte has an excellent article [2] on how to use the massInput to build dynamic forms on the client side. If you're building web apps with Haskell, make sure you check it out. -chris [1]: http://hackage.haskell.org/package/formlets [2]: http://softwaresimply.blogspot.com/2009/08/dynamic-list-formlets-in-haskell.html From frantisek.kocun at gmail.com Mon Aug 24 10:53:03 2009 From: frantisek.kocun at gmail.com (frantisek kocun) Date: Mon Aug 24 10:32:54 2009 Subject: [Haskell-cafe] Gtk2Hs drag and drop Message-ID: Hi, have somebody used drag and drop feature of Gtk2hs? I can't find any tutorial or demo. I'm using only the documentation but I think I'm missing something. Can anyone give me an example? Thanks in forward! Fero From joaoraf at gmail.com Mon Aug 24 12:39:51 2009 From: joaoraf at gmail.com (=?ISO-8859-1?Q?Jo=E3o_Rafael_Nicola?=) Date: Mon Aug 24 12:19:40 2009 Subject: [Haskell-cafe] Problem building encoding-0.6.0: missing Data.CharMap.Builder Message-ID: <5ce143f50908240939r59d15082m5227c465c3e925e4@mail.gmail.com> Hi, I am trying to install the encoding-0.6.0 package, but it complains that that package "Data.CharMap.Builder" is missing. I could not find any reference to that package anywhere on the web. Does anyone know where I can find it or a workaround? Thanks, Jo?o Rafael > cabal install encoding Resolving dependencies... /tmp/encoding-0.6.08632/encoding-0.6.0/Data/Encoding/Preprocessor/XMLMappingBuilder.hs:11:7: Could not find module `Data.CharMap.Builder': Use -v to see a list of the files searched for. cabal: Error: some packages failed to install: encoding-0.6.0 failed during the configure step. The exception was: exit: ExitFailure 1 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090824/377b1d31/attachment.html From bbr at informatik.uni-kiel.de Mon Aug 24 13:59:45 2009 From: bbr at informatik.uni-kiel.de (Bernd Brassel) Date: Mon Aug 24 13:39:37 2009 Subject: [Haskell-cafe] Re: Converting typeset mathematics into Haskell ? Message-ID: <2D9927E2-F8DF-4A59-BA15-AD118B827241@informatik.uni-kiel.de> Sometimes the synchronicity of events is eery. Incidentally I have just written a proposal for just such a project. You can have a look at it at http://www-ps.informatik.uni-kiel.de/~bbr/WebOfProofs.html Although not directly mentioned in the proposal, there will be a lot of "Converting typeset mathematics into Haskell" going on. Kind regards Bernd PS: And just in case I did it wrong again; this is the message I wanted to reply to http://www.haskell.org/pipermail/haskell-cafe/2009-August/065572.html From mauricio.antunes at gmail.com Mon Aug 24 15:06:02 2009 From: mauricio.antunes at gmail.com (=?ISO-8859-1?Q?Maur=ED=ADcio_CA?=) Date: Mon Aug 24 14:46:14 2009 Subject: [Haskell-cafe] Linking problem with GHCi Message-ID: With a specific package (bindings-common, with the latest version in hackage) if I ask GHCi to read it I get: ghc-6.8.2: /home/mauricio/lib/bindings-common-0.2.5/ghc-6.8.2/HSbindings-common-0.2.5.o: unknown symbol `atexit' If I build a library or executable cabal package depending on it, I have no problems. Also, if I remove that 'atexit' wrap from 'bindings-common' I don't get this ghci error message anymore. Why would just this 'atexit' function be a problem? It's wrap does work well, and I can use it from a Haskell program through bindings-common (although not in ghci, of course). This happens at least in ghc-6.8.2 and 6.10.3. Thanks, Maur?cio From simon at joyful.com Mon Aug 24 15:28:38 2009 From: simon at joyful.com (Simon Michael) Date: Mon Aug 24 15:08:29 2009 Subject: [Haskell-cafe] ANN: rss2irc 0.3 released Message-ID: <8C9FDF81-21FD-42DA-A42C-ED9EC1A76E3F@joyful.com> rss2irc is an irc bot created by Don Stewart to watch rss feeds and announce new items on irc. I have been tweaking and testing it for a while, and have taken up the maintainer reins. I'm happy to announce release 0.3, with: - reliable http networking - irc flood protection - better error handling & reporting - extensive debugging output - Atom support - more useful defaults (enter channel silently, hide email addresses etc.) - precise control of irc output, including regexp rewrites - installable on mac osx Feedback and patches welcome. I am currently using it to run a number of announce-bots on freenode, including hackagebot and darcscommitbot. (A tip: if you experiment, avoid joining the irc server too frequently; once per minute may be ok.) home: http://hackage.haskell.org/package/rss2irc darcs repo: http://joyful.com/darcsweb/darcsweb.cgi?r=rss2irc -Simon From h._h._h._ at hotmail.com Mon Aug 24 15:57:53 2009 From: h._h._h._ at hotmail.com (h) Date: Mon Aug 24 15:38:13 2009 Subject: [Haskell-cafe] rotate image Message-ID: Hello, I already studied the references of gtk2hs for hours, as well as searched in the web, but didn't found any working solution. The problem is to load an image, a png with alpha channel, rotate it e.g. 10 degree, and show it on the screen, basically as when it would be shown with imageNewFromFile with transparency. Thanks in advance for your help. -- Best regards H. From jefferson.r.heard at gmail.com Mon Aug 24 16:14:02 2009 From: jefferson.r.heard at gmail.com (Jeff Heard) Date: Mon Aug 24 15:54:11 2009 Subject: [Haskell-cafe] rotate image In-Reply-To: References: Message-ID: <4165d3a70908241314o7589d532tef67bfaa9c4d3c37@mail.gmail.com> You could use Cairo. Load the image to a surface, then rotate the surface 10 degrees and paint it. Alternately, in Hieroglyph: renderToPNG w h "image.png" $ rotate 10 image{ filename='whatever.png' } On Mon, Aug 24, 2009 at 3:57 PM, h wrote: > Hello, > > I already studied the references of gtk2hs for hours, as well as searched in > the web, but didn't found any working solution. > > The problem is to load an image, a png with alpha channel, rotate it e.g. 10 > degree, and show it on the screen, basically as when it would be shown with > imageNewFromFile with transparency. > > Thanks in advance for your help. > > -- > Best regards > H. > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From wei.hoo at gmail.com Mon Aug 24 16:56:09 2009 From: wei.hoo at gmail.com (Wei Hu) Date: Mon Aug 24 16:35:59 2009 Subject: [Haskell-cafe] oauth in haskell - reviewers? In-Reply-To: <20090823162555.GA4190@mephisto.bitforest.org> References: <20090822233654.GA16495@mephisto.bitforest.org> <57526e770908222008o25780147ve211a8279dc82f56@mail.gmail.com> <20090823162555.GA4190@mephisto.bitforest.org> Message-ID: <71fd12e60908241356n70525f9ep6a3d32ca28505091@mail.gmail.com> I recommend "Learn you a Haskell for great good": http://learnyouahaskell.com/functors-applicative-functors-and-monoids#applicative-functors On Sun, Aug 23, 2009 at 12:25 PM, Diego Souza wrote: > A quick search pointed me to this: > http://www.soi.city.ac.uk/~ross/papers/Applicative.html > > Is there any other resources you would suggest me to read? > > Thanks at lot, > -- > ~dsouza > yahoo!im: paravinicius > gpg key fingerprint: 71B8 CE21 3A6E F894 5B1B ?9ECE F88E 067F E891 651E > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From h._h._h._ at hotmail.com Mon Aug 24 17:01:56 2009 From: h._h._h._ at hotmail.com (h.) Date: Mon Aug 24 16:42:08 2009 Subject: [Haskell-cafe] rotate image In-Reply-To: <4165d3a70908241314o7589d532tef67bfaa9c4d3c37@mail.gmail.com> References: <4165d3a70908241314o7589d532tef67bfaa9c4d3c37@mail.gmail.com> Message-ID: <25123653.post@talk.nabble.com> Hello, > You could use Cairo. Load the image to a surface, then rotate the surface > 10 degrees and paint it. The first steps aren?t problematic, but how can I paint it - in which widget - so that the background is transparent, with drawingArea it doesn?t seem to work. -- best regards H. -- View this message in context: http://www.nabble.com/rotate-image-tp25122912p25123653.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From dons at galois.com Mon Aug 24 17:24:09 2009 From: dons at galois.com (Don Stewart) Date: Mon Aug 24 17:06:06 2009 Subject: [Haskell-cafe] oauth in haskell - reviewers? In-Reply-To: <71fd12e60908241356n70525f9ep6a3d32ca28505091@mail.gmail.com> References: <20090822233654.GA16495@mephisto.bitforest.org> <57526e770908222008o25780147ve211a8279dc82f56@mail.gmail.com> <20090823162555.GA4190@mephisto.bitforest.org> <71fd12e60908241356n70525f9ep6a3d32ca28505091@mail.gmail.com> Message-ID: <20090824212409.GI28658@whirlpool.galois.com> I notice hoauth is packaged as LGPL. Since we use static linking in GHC, this makes it in practice GPL. Is that the intent? -- Don wei.hoo: > I recommend "Learn you a Haskell for great good": > http://learnyouahaskell.com/functors-applicative-functors-and-monoids#applicative-functors > > On Sun, Aug 23, 2009 at 12:25 PM, Diego Souza wrote: > > A quick search pointed me to this: > > http://www.soi.city.ac.uk/~ross/papers/Applicative.html > > > > Is there any other resources you would suggest me to read? > > > > Thanks at lot, > > -- > > ~dsouza > > yahoo!im: paravinicius > > gpg key fingerprint: 71B8 CE21 3A6E F894 5B1B ?9ECE F88E 067F E891 651E > > _______________________________________________ > > 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 westondan at imageworks.com Mon Aug 24 17:31:28 2009 From: westondan at imageworks.com (Dan Weston) Date: Mon Aug 24 17:11:23 2009 Subject: [Haskell-cafe] Is logBase right? In-Reply-To: References: Message-ID: <4A9306B0.3050607@imageworks.com> I don't know if anyone actually answered the question you didn't ask, but you can always improve an inaccurate guess when you need to. A limit will always exist, and should be unique (independent of the initial guess), assuming (+) and (*) are well-conditioned. In practice, a single first-order Taylor step should be enough: logBase' :: Double -> Double -> Double logBase' b y = if b == 0.0 then 1.0 else improve x0 where bLogInv = 1.0 / log(b) f x = x + (1.0-b**x/y) * bLogInv -- First step is enough, if we guess smartly improve = f x0 = log(y) * bLogInv -- or use the limit from any initial guess -- improve x = let y = f x in if y == x then y else improve y -- x0 = 0.0 Dan Roberto wrote: > Hi, > > There is a mistake is logBase: > > $ ghci > GHCi, version 6.10.4: http://www.haskell.org/ghc/ :? for help > Loading package ghc-prim ... linking ... done. > Loading package integer ... linking ... done. > Loading package base ... linking ... done. > Prelude> logBase 10 10 > 1.0 > Prelude> logBase 10 100 > 2.0 > Prelude> logBase 10 1000 > 2.9999999999999996 <--- eeeerrgghhhh! > Prelude> logBase 10 10000 > 4.0 > > > My host is a Debian GNU/Linux 5.0.2 (lenny) with the following GHC packages: > > ii ghc6 6.10.4-1 > ii ghc6-doc 6.10.4-1 > ii libghc6-mtl-dev 1.1.0.2-7+b1 > ii libghc6-utf8-string-dev 0.3.5-1+b1 > ii libghc6-x11-dev 1.4.5-6 > rc libghc6-x11-doc 1.4.2-1 > ii libghc6-x11-xft-dev 0.3-3+b3 > ii libghc6-xmonad-contrib-dev 0.8.1-3+b3 > rc libghc6-xmonad-contrib-doc 0.8-2 > ii libghc6-xmonad-dev 0.8.1-5 > > Regards! > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > From ryani.spam at gmail.com Mon Aug 24 18:07:58 2009 From: ryani.spam at gmail.com (Ryan Ingram) Date: Mon Aug 24 17:47:47 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: References: <49a77b7a0908211103u29118f95m2ba22d9dc85a3c46@mail.gmail.com> Message-ID: <2f9b2d30908241507r24a52821tc7f343c12fea967f@mail.gmail.com> unsafeCoerce is ugly and I wouldn't count on that working properly. Here's a real solution: > {-# LANGUAGE GADTs, RankNTypes, TypeFamilies, ScopedTypeVariables, FlexibleContexts #-} > {-# LANGUAGE FlexibleInstances #-} > module LevMar where > import Data.Maybe (fromJust) Type-level number scaffold: > data Z = Z > newtype S n = S n > class Nat n where > caseNat :: forall r. n -> (n ~ Z => r) -> (forall p. (n ~ S p, Nat p) => p -> r) -> r > instance Nat Z where > caseNat _ z _ = z > instance Nat n => Nat (S n) where > caseNat (S n) _ s = s n > induction :: forall p n. Nat n => n -> p Z -> (forall x. Nat x => p x -> p (S x)) -> p n > induction n z s = caseNat n isZ isS where > isZ :: n ~ Z => p n > isZ = z > isS :: forall x. (n ~ S x, Nat x) => x -> p n > isS x = s (induction x z s) > newtype Witness x = Witness { unWitness :: x } > witnessNat :: forall n. Nat n => n > witnessNat = theWitness where > theWitness = unWitness $ induction (undefined `asTypeOf` theWitness) (Witness Z) (Witness . S . unWitness) Sized list type: > data SizedList a n where > Nil :: SizedList a Z > Cons :: a -> SizedList a n -> SizedList a (S n) > infixr 2 `Cons` toList. Your implementation is simpler, but this gives you an idea of how to use "induction" to generate a function that you need. > newtype ToList a n = ToList { unToList :: SizedList a n -> [a] } > toList :: forall a n. Nat n => SizedList a n -> [a] > toList = unToList $ induction (witnessNat :: n) (ToList tl0) (ToList . tlS . unToList) where > tl0 :: SizedList a Z -> [a] > tl0 Nil = [] > tlS :: forall x. Nat x => (SizedList a x -> [a]) -> SizedList a (S x) -> [a] > tlS f (Cons x xs) = x : f xs fromList. Here we return a "Maybe" value to represent that the list might not be the right size. > newtype FromList a n = FromList { unFromList :: [a] -> Maybe (SizedList a n) } > fromList :: forall a n. Nat n => [a] -> Maybe (SizedList a n) > fromList = unFromList $ induction (witnessNat :: n) (FromList fl0) (FromList . flS . unFromList) where > fl0 [] = Just Nil > fl0 _ = Nothing > flS k [] = Nothing > flS k (x:xs) = fmap (Cons x) $ k xs "Model" for your levMar functions > class (Nat (Arity f)) => Model f where > type Arity f > app :: f -> SizedList Double (Arity f) -> Double > instance Model Double where > type Arity Double = Z > app v Nil = v > instance Model f => Model (Double -> f) where > type Arity (Double -> f) = S (Arity f) > app f (Cons v vs) = app (f v) vs And the levmar implementations: > levmarML :: (a -> [Double] -> Double) -> [Double] -> [(a,Double)] -> [Double] > levmarML f inits samples = inits > levmarHL :: (Model f) => > (a -> f) -> SizedList Double (Arity f) -> [(a, Double)] -> SizedList Double (Arity f) > levmarHL f inits samples = fromJust $ fromList $ > levmarML (\a -> app (f a) . fromJust . fromList) (toList inits) samples We rely on levmarML only calling the passed-in function with a correctly-sized list, and returning a similarily correctly-sized list. That assumption is made explicit with the calls to "fromJust". > testModel :: Double -> Double -> Double -> Double > testModel n x y = x*y - n*n > test = levmarHL testModel (1 `Cons` 2 `Cons` Nil) [(3, 10), (4, 20)] *LevMar> :t test test :: SizedList Double (Arity (Double -> Double -> Double)) *LevMar> toList test [1.0, 2.0] -- ryan On Fri, Aug 21, 2009 at 11:50 AM, Bas van Dijk wrote: > Thanks for all the advice. > > I have this so far. Unfortunately I have to use unsafeCoerce: > > ------------------------------------------------------------------------- > {-# LANGUAGE EmptyDataDecls #-} > {-# LANGUAGE TypeFamilies #-} > {-# LANGUAGE GADTs #-} > {-# LANGUAGE RankNTypes #-} > > module LevMar where > > import Unsafe.Coerce > > levmarML :: (a -> [Double] -> Double) > ? ? ? ? -> [Double] > ? ? ? ? -> [(a, Double)] > ? ? ? ? -> [Double] > levmarML model initParams samples = initParams > > data Z > data S n > > data Nat n where > ? ?Zero :: Nat Z > ? ?Succ :: Nat n -> Nat (S n) > > data Vector a n where > ? ?Nil ? :: Vector a Z > ? ?(:*:) :: a -> Vector a n -> Vector a (S n) > > infixr :*: > > instance Show a => Show (Vector a n) where > ? ?show Nil = "Nil" > ? ?show (x :*: xs) = show x ++ " :*: " ++ show xs > > toList :: Vector b n -> [b] > toList Nil ? ? ? ?= [] > toList (x :*: xs) = x : toList xs > > listVec :: [a] -> (forall n. Vector a n -> t) -> t > listVec [] ? ? ? f = f Nil > listVec (x : xs) f = listVec xs (\ys -> f (x :*: ys)) > > type family Replicate n (a :: * -> *) b :: * > type instance Replicate (S x) a b = a (Replicate x a b) > type instance Replicate Z a b = b > > type Function n a b = Replicate n ((->) a) b > > ($*) :: Function n a a -> Vector a n -> a > f $* Nil ? ? ? ?= f > f $* (x :*: xs) = f x $* xs > > levmarHL :: (a -> Function n Double Double) > ? ? ? ? -> Vector Double n > ? ? ? ? -> [(a, Double)] > ? ? ? ? -> Vector Double n > levmarHL model initParams samples = > ? ?listVec (levmarML (\x params -> listVec params $ \v -> > unsafeCoerce (model x) $* v) > ? ? ? ? ? ? ? ? ? ? ?(toList initParams) > ? ? ? ? ? ? ? ? ? ? ?samples) > ? ? ? ? ? ?(unsafeCoerce) > ------------------------------------------------------------------------- > > regards, > > Bas > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From mauricio.antunes at gmail.com Mon Aug 24 18:27:52 2009 From: mauricio.antunes at gmail.com (=?ISO-8859-1?Q?Maur=ED=ADcio_CA?=) Date: Mon Aug 24 18:08:06 2009 Subject: [Haskell-cafe] Re: Linking problem with GHCi In-Reply-To: References: Message-ID: > With a specific package (bindings-common, with the latest version > in hackage) if I ask GHCi to read it I get: > > ghc-6.8.2: > /home/mauricio/lib/bindings-common-0.2.5/ghc-6.8.2/HSbindings-common-0.2.5.o: > unknown symbol `atexit' > > If I build a library or executable cabal package depending on it, > I have no problems. Also, if I remove that 'atexit' wrap from > 'bindings-common' I don't get this ghci error message anymore. This is actually not specific to that package. Attached is a darcs patch to a package where the only exported module contains just a wrapped 'atexit'. Thanks, Maur?cio -------------- next part -------------- Mon Aug 24 19:24:20 BRT 2009 mauricio.antunes@gmail.com * All New patches: [All mauricio.antunes@gmail.com**20090824222420 Ignore-this: e09fe2a2596b6e041c7297efcaad55cb ] adddir ./BaseName addfile ./BaseName/JustAtexit.hs hunk ./BaseName/JustAtexit.hs 1 +module BaseName.JustAtexit where +import Foreign +import Foreign.C + +foreign import ccall atexit :: FunPtr (IO ()) -> IO CInt + + addfile ./Setup.hs hunk ./Setup.hs 1 +#!/usr/bin/env runhaskell + +module Main (main) where +import Distribution.Simple + +main = defaultMain addfile ./teste.cabal hunk ./teste.cabal 1 +cabal-version: >= 1.2.3 +name: teste +version: 0.0.1 +synopsis: + Test +description: + Test +version: 1 +license: BSD3 +build-type: Simple +library + hs-source-dirs: . + extensions: + ForeignFunctionInterface + build-depends: base >=3 && <5 + exposed-modules: + BaseName.JustAtexit Context: Patch bundle hash: b4c77eef776e4e5c0b7266156fe638c82a6ab1da From h._h._h._ at hotmail.com Mon Aug 24 18:34:51 2009 From: h._h._h._ at hotmail.com (h) Date: Mon Aug 24 18:14:52 2009 Subject: [Haskell-cafe] Re: rotate image Message-ID: Hello, > You could use Cairo. Load the image to a surface, then rotate the surface 10 degrees and paint it. The first steps aren?t problematic, but how can I paint it - in which widget - so that the background is transparent, with drawingArea it doesn't seem to work. -- best regards H. From dsouza at bitforest.org Mon Aug 24 18:54:22 2009 From: dsouza at bitforest.org (Diego Souza) Date: Mon Aug 24 18:34:16 2009 Subject: [Haskell-cafe] oauth in haskell - reviewers? In-Reply-To: <20090824212409.GI28658@whirlpool.galois.com> References: <20090822233654.GA16495@mephisto.bitforest.org> <57526e770908222008o25780147ve211a8279dc82f56@mail.gmail.com> <20090823162555.GA4190@mephisto.bitforest.org> <71fd12e60908241356n70525f9ep6a3d32ca28505091@mail.gmail.com> <20090824212409.GI28658@whirlpool.galois.com> Message-ID: <20090824225422.GA28522@clockdistance.saopaulo.corp.yahoo.com> Hi Don, no, not really, I completely missed that point. But if that is the case, I presume there is no difference in using other licenses, like BSD3. Is that the case? Thanks, On Mon, Aug 24, 2009 at 02:24:09PM -0700, Don Stewart wrote: > I notice hoauth is packaged as LGPL. Since we use static linking in GHC, > this makes it in practice GPL. Is that the intent? -- ~dsouza yahoo!im: paravinicius gpg key fingerprint: 71B8 CE21 3A6E F894 5B1B 9ECE F88E 067F E891 651E From v.dijk.bas at gmail.com Mon Aug 24 19:24:48 2009 From: v.dijk.bas at gmail.com (Bas van Dijk) Date: Mon Aug 24 19:04:36 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: <2f9b2d30908241507r24a52821tc7f343c12fea967f@mail.gmail.com> References: <49a77b7a0908211103u29118f95m2ba22d9dc85a3c46@mail.gmail.com> <2f9b2d30908241507r24a52821tc7f343c12fea967f@mail.gmail.com> Message-ID: On Tue, Aug 25, 2009 at 12:07 AM, Ryan Ingram wrote: > unsafeCoerce is ugly and I wouldn't count on that working properly. > > Here's a real solution: > ... Thanks very much! I'm beginning to understand the code. The only thing I don't understand is why you need: > newtype Witness x = Witness { unWitness :: x } > witnessNat :: forall n. Nat n => n > witnessNat = theWitness where > theWitness = unWitness $ induction (undefined `asTypeOf` theWitness) (Witness Z) (Witness . S . unWitness) I understand that 'witnessNat' is a overloaded value-level generator for Nats. So for example: 'witnessNat :: S (S (S Z))' returns the value: 'S (S (S Z))'. Then you use it in the implementation of 'toList' and 'fromList': > toList = ... induction (witnessNat :: n) ... > fromList = ... induction (witnessNat :: n) ... I guess so that 'induction' will then receive the right 'Nat' _value_. However the following also works: > toList = ... induction (undefined :: n) ... > fromList = ... induction (undefined :: n) ... Indeed, 'witnessNat' itself is implemented this way: > witnessNat = theWitness where theWitness = ... induction (undefined `asTypeOf` theWitness) ... So the 'n' in 'induction n' is just a "type carrying parameter" i.e. it doesn't need to have a run-time representation. Al dough it looks like that a case analysis on 'n' is made at run-time in: > instance Nat n => Nat (S n) where > caseNat (S n) _ s = s n But I guess that is desugared away because 'S' is implemented as a newtype: > newtype S n = S n Indeed, when I make an actual datatype of it then 'witnessNat :: S (S (S Z))' will crash with "*** Exception: Prelude.undefined". Again, thanks very much for this! Do you mind if I use this code in the levmar package (soon to be released on hackage)? regards, Bas From jefferson.r.heard at gmail.com Mon Aug 24 19:40:46 2009 From: jefferson.r.heard at gmail.com (Jeff Heard) Date: Mon Aug 24 19:20:59 2009 Subject: [Haskell-cafe] Re: rotate image In-Reply-To: References: Message-ID: <4165d3a70908241640i323988afs90fe553ca210420a@mail.gmail.com> ahh, you want to paint against the desktop, then, yes? That requires compositing, and I'm not sure there's a way to do that with Gtk directly. Probably easier with X and OpenGL. Needs more of a Gnome expert than me. On Mon, Aug 24, 2009 at 6:34 PM, h wrote: > Hello, > >> You could use Cairo. ?Load the image to a surface, then rotate the surface 10 > degrees and paint it. > > The first steps aren?t problematic, but how can I paint it - in which widget - > so that the background is transparent, with drawingArea it doesn't seem to > work. > > -- > best regards > H. > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From h._h._h._ at hotmail.com Mon Aug 24 20:36:56 2009 From: h._h._h._ at hotmail.com (H. M.) Date: Mon Aug 24 20:16:43 2009 Subject: [Haskell-cafe] Re: rotate image In-Reply-To: <4165d3a70908241640i323988afs90fe553ca210420a@mail.gmail.com> References: <4165d3a70908241640i323988afs90fe553ca210420a@mail.gmail.com> Message-ID: Hello, I want to paint in some widget, but this will be in front of some background, so the bg should be transparent. At the moment it looks something like this (where it isn't the case): -- drawA <- drawingAreaNew widgetSetSizeRequest drawA 30 30 fixedPut fBox drawA (400,400) imgAt <- imageSurfaceCreateFromPNG "some.png" let drawC = do dw <- widgetGetDrawWindow drawA drawWindowClear dw renderWithDrawable dw $ do translate 9 9 rotate 0.3 translate (-9) (-9) setSourceSurface imgAt 0 0 paint onExpose drawA (const $ drawC>> return True) -- -- best regards H. > From: jefferson.r.heard@gmail.com > Date: Mon, 24 Aug 2009 19:40:46 -0400 > Subject: Re: [Haskell-cafe] Re: rotate image > To: h._h._h._@hotmail.com > CC: haskell-cafe@haskell.org > > ahh, you want to paint against the desktop, then, yes? That requires > compositing, and I'm not sure there's a way to do that with Gtk > directly. Probably easier with X and OpenGL. Needs more of a Gnome > expert than me. _________________________________________________________________ Hol dir 30 kostenlose Emoticons f?r deinen Windows Live Messenger http://www.livemessenger-emoticons.com/funfamily/de-at/ From ramsdell0 at gmail.com Mon Aug 24 20:51:16 2009 From: ramsdell0 at gmail.com (John D. Ramsdell) Date: Mon Aug 24 20:31:04 2009 Subject: [Haskell-cafe] Unifcation and matching in Abelian groups In-Reply-To: <404396ef0908190351v3f206ae1y63e0152255dd4da2@mail.gmail.com> References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> <404396ef0908190316rc772614p9c660c8ab5095ed6@mail.gmail.com> <7687290b0908190345q23313f4bwf24b6868499ee704@mail.gmail.com> <404396ef0908190351v3f206ae1y63e0152255dd4da2@mail.gmail.com> Message-ID: <7687290b0908241751n21546920oab8855fe747ec73d@mail.gmail.com> > ... Haskell is old and has the optional offset rule: > > do { prob <- getLine > ? ? ; test prob > ? ? ; main} It's interesting to see people put semicolons at the begining of a line of code. In 1970s, people used to draw lines on printouts of Ada and Pascal code to connect the begins with the ends. My first publication Ramsdell, J. D., "Prettyprinting Structured Programs with Connector Lines," ACM SIGPLAN Notices, Vol. 14, No. 9, p. 74, September 1979 suggested prettyprinting Ada and Pascal programs with the semicolons at the begining of the lines and use them as the connector lines. Thus a prettyprinted Ada program looked like: package Mine is ... begin ; while i < Integer'Last loop ; ; Print (i) ; end loop; end Mine; It didn't work quite as well in Pascal, because semicolon was a statement separator instead of a statement terminator. In those day, procedures tended to large and deeply nested because procedure invocation was expensive. John From bulat.ziganshin at gmail.com Mon Aug 24 23:42:31 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Mon Aug 24 23:22:26 2009 Subject: [Haskell-cafe] Unifcation and matching in Abelian groups In-Reply-To: <7687290b0908241751n21546920oab8855fe747ec73d@mail.gmail.com> References: <7687290b0908190243y70541426x3d485267c4a941ec@mail.gmail.com> <404396ef0908190316rc772614p9c660c8ab5095ed6@mail.gmail.com> <7687290b0908190345q23313f4bwf24b6868499ee704@mail.gmail.com> <404396ef0908190351v3f206ae1y63e0152255dd4da2@mail.gmail.com> <7687290b0908241751n21546920oab8855fe747ec73d@mail.gmail.com> Message-ID: <1767385492.20090825074231@gmail.com> Hello John, Tuesday, August 25, 2009, 4:51:16 AM, you wrote: > In those day, procedures tended to large and deeply nested because > procedure invocation was expensive. interesting story. in 80s, virtual method call was expensive. now lazy evaluation is expensive. what's next? :) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From john at repetae.net Tue Aug 25 00:13:36 2009 From: john at repetae.net (John Meacham) Date: Mon Aug 24 23:53:25 2009 Subject: [Haskell-cafe] ANNOUNCE: jhc 0.7.1 Message-ID: <20090825041336.GI18852@sliver.repetae.net> Hi, I am happy to announce the jhc optimizing haskell compiler version 0.7.1. Information on installing jhc is here: http://repetae.net/computer/jhc/building.shtml And the Main page is here: http://repetae.net/computer/jhc There have been a lot of changes since the last public release, Some notable ones are: * The use of a general compiler cache by default rather than object files. This means work done by jhc is shared between projects, jhc uses cryptographic hashes internally to never compile the same piece of code more than once. This has numerous benefits, a notable one being speed. * Reworked library support. Jhc libraries are now much more general, when linking only the bits needed are loaded from the hl file, libraries are allowed to re-export modules from other libraries, making versioning or providing multiple interfaces to the same functionality a lot simpler. Library conflicts are 'lazy', like ambiguity errors now. * Updated Manual, clearer build instructions * Support for writing pure C libraries in Haskell. * numerous library updates, filled out many IO routines that were stubs before * Smart progress meters when compiler for a better user experience * performs all typechecking before compilation, for a faster edit-compile loop when writing code with jhc. * various bug fixes * Cross Compilation improvements, for instance you can compile for windows transparently on a linux box. Or for an embedded target that is independent of the host. * Better Mac OSX Support, as both a host and target. If you are wondering about the large version number bump since the last release, It is because several versions were released only internally to the jhc list for testing. If you are interested in jhc, join the list at: http://www.haskell.org/mailman/listinfo/jhc John -- John Meacham - ?repetae.net?john? - http://notanumber.net/ From tanimoto at arizona.edu Tue Aug 25 00:39:10 2009 From: tanimoto at arizona.edu (Paulo Tanimoto) Date: Tue Aug 25 00:19:17 2009 Subject: [Haskell-cafe] ANNOUNCE: jhc 0.7.1 In-Reply-To: <20090825041336.GI18852@sliver.repetae.net> References: <20090825041336.GI18852@sliver.repetae.net> Message-ID: Hi John, On Mon, Aug 24, 2009 at 11:13 PM, John Meacham wrote: > Hi, I am happy to announce the jhc optimizing haskell compiler version 0.7.1. > > Information on installing jhc is here: http://repetae.net/computer/jhc/building.shtml > And the Main page is here: ?http://repetae.net/computer/jhc > Cheers! Thanks for the great work. It took me 5 minutes between downloading the tarball and compiling "hello world", and this is my first time. There should be no excuses for not giving jhc a whirl. : ) Paulo From florbitous at gmail.com Tue Aug 25 01:20:51 2009 From: florbitous at gmail.com (Bernie Pope) Date: Tue Aug 25 01:00:37 2009 Subject: =?windows-1252?Q?Re=3A_=5BHaskell=2Dcafe=5D_ANNOUNCE=3A_graphtype_=97_A_simple_?= =?windows-1252?Q?tool_to_illustrate_dependencies_between_Haskell_types?= In-Reply-To: <87y6p9v0kv.fsf@zagan.made.you> References: <87y6p9v0kv.fsf@zagan.made.you> Message-ID: <4d8ad03a0908242220y38282054l5808ceeef3602c31@mail.gmail.com> 2009/8/24 Max Desyatov : > graphtype was developed to visualise type declarations in you Haskell > source files. ?It produces .dot-file for subsequent processing with > graphviz. > Anyway, graphtype is fairly usable. ?Leave here your questions, > suggestions and have fun looking at type dependencies in your code. Neat. You could probably get some leverage from the GHC API for reading .hi files to find out information about imported types. It looks to me like you generate one image file for the whole graph. It could get quite big. I think dot supports hyperlinks, and so do some image formats (SVG I believe). Maybe you could split it up into pieces with hyperlinks between them. Browser support for SVG appears to be getting better these days. I've sometimes mused about the idea of graphing the static function call graph of programs and annotating arcs with type information. For that the GHC API would be the way to go (might need to do a little type reconstruction along the way to figure out the concrete types at which polymorphic functions are used.) Cheers, Bernie. From ekirpichov at gmail.com Tue Aug 25 03:24:01 2009 From: ekirpichov at gmail.com (Eugene Kirpichov) Date: Tue Aug 25 03:03:50 2009 Subject: [Haskell-cafe] ANNOUNCE: jhc 0.7.1 In-Reply-To: <20090825041336.GI18852@sliver.repetae.net> References: <20090825041336.GI18852@sliver.repetae.net> Message-ID: <5e0214850908250024u1ed5dfa5s209a594936dfeb04@mail.gmail.com> WOW! Congratulations, I am impressed: I ran it on a small example program and jhc produced output that was 3x faster than ghc -O2! Serious stuff. However: I tried it on a different very simple program (a projecteuler one): module Main where isReversible n | n`mod`10 == 0 = False | otherwise = all (`elem` "1357") . show $ (n + (read.reverse.show$n)) main = putStrLn . show . length . filter isReversible $ [1..1000000::Int] ghc took 6s on this one, whereas jhc took 2 minutes real time (of which 5s user time and 5s system time), which also froze the system completely! Most probably it allocated a ton of memory, because the system was very slow for a while after the program completed. Same thing happened with a different but bigger number-crunching program. Also: I tried to build a program that uses uvector, and for that I needed an uvector.hl file: I unarchived the package and did this: jkff@jkff-laptop:~/.cabal/packages/hackage.haskell.org/uvector/0.1.0.4/uvector-0.1.0.4$ jhc --build-hl uvector.cabal jhc --build-hl uvector.cabal jhc 0.7.1 (0.7.0-13) Creating library from description file: "uvector.cabal" Reading: "uvector.cabal" Finding Dependencies... Using Ho Cache: '/home/jkff/.jhc/cache' Typechecking... Compiling... Writing Library: uvector-0.1.0.4.hl jkff@jkff-laptop:~/.cabal/packages/hackage.haskell.org/uvector/0.1.0.4/uvector-0.1.0.4$ ls -l uvector-0.1.0.4.hl -rw-r--r-- 1 jkff jkff 1248 2009-08-25 10:58 uvector-0.1.0.4.hl (is it correct that actually no compilation occured at all?) jkff@jkff-laptop:~/projects/for-fun/haskell/mandelbrot$ jhc -p /home/jkff/.cabal/packages/hackage.haskell.org/uvector/0.1.0.4/uvector-0.1.0.4/uvector-0.1.0.4.hl Low.hs jhc -p /home/jkff/.cabal/packages/hackage.haskell.org/uvector/0.1.0.4/uvector-0.1.0.4/uvector-0.1.0.4.hl Low.hs jhc 0.7.1 (0.7.0-13) Finding Dependencies... Using Ho Cache: '/home/jkff/.jhc/cache' Library was not found '/home/jkff/.cabal/packages/hackage.haskell.org/uvector/0.1.0.4/uvector-0.1.0.4/uvector-0.1.0.4.hl' Now this seems strange. The documentation to jhc was not of much help. What should be done to use libraries from hackage? Would it be hard to give jhc some integration with ghc's package.conf? 2009/8/25 John Meacham : > Hi, I am happy to announce the jhc optimizing haskell compiler version 0.7.1. > > Information on installing jhc is here: http://repetae.net/computer/jhc/building.shtml > And the Main page is here: ?http://repetae.net/computer/jhc > > There have been a lot of changes since the last public release, Some > notable ones are: > > ?* The use of a general compiler cache by default rather than object > ? files. This means work done by jhc is shared between projects, jhc > ? uses cryptographic hashes internally to never compile the same piece of > ? code more than once. This has numerous benefits, a notable one being > ? speed. > ?* Reworked library support. Jhc libraries are now much more general, > ? when linking only the bits needed are loaded from the hl > ? file, libraries are allowed to re-export modules from other > ? libraries, making versioning or providing multiple interfaces to the > ? same functionality a lot simpler. Library conflicts are 'lazy', like > ? ambiguity errors now. > ?* Updated Manual, clearer build instructions > ?* Support for writing pure C libraries in Haskell. > ?* numerous library updates, filled out many IO routines that were stubs > ? before > ?* Smart progress meters when compiler for a better user experience > ?* performs all typechecking before compilation, for a faster > ? edit-compile loop when writing code with jhc. > ?* various bug fixes > ?* Cross Compilation improvements, for instance you can compile for windows transparently on > ? a linux box. Or for an embedded target that is independent of the > ? host. > ?* Better Mac OSX Support, as both a host and target. > > > If you are wondering about the large version number bump since the last > release, It is because several versions were released only internally to > the jhc list for testing. If you are interested in jhc, join the list at: > http://www.haskell.org/mailman/listinfo/jhc > > ? ? ? ?John > > -- > John Meacham - ?repetae.net?john? - http://notanumber.net/ > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Eugene Kirpichov Web IR developer, market.yandex.ru From ryani.spam at gmail.com Tue Aug 25 03:41:46 2009 From: ryani.spam at gmail.com (Ryan Ingram) Date: Tue Aug 25 03:21:31 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: References: <49a77b7a0908211103u29118f95m2ba22d9dc85a3c46@mail.gmail.com> <2f9b2d30908241507r24a52821tc7f343c12fea967f@mail.gmail.com> Message-ID: <2f9b2d30908250041s1c19d1d9w98d48fbf8baaccef@mail.gmail.com> On Mon, Aug 24, 2009 at 4:24 PM, Bas van Dijk wrote: > Thanks very much! I'm beginning to understand the code. > > The only thing I don't understand is why you need [witnessNat] > >> toList = ... induction (witnessNat :: n) ... >> fromList = ... induction (witnessNat :: n) ... > > However the following also works: > >> toList = ... induction (undefined :: n) ... >> fromList = ... induction (undefined :: n) ... Yes, that's true. But because we have lazy evaluation, witnessNat never gets evaluated, so it doesn't matter :) And I prefer to keep the (undefined/error) calls, along with recursion, in my code to a minimum, since both of those can lead to _|_ and runtime errors. So, by keeping the calls to "undefined" and the use of recursion limited to "induction" and "witnessNat", I create a very small 'trusted core' of code that has to be checked carefully for errors. Other code that uses these functions are entirely safe as long as we keep those functions total and avoid explicit recursion. This is why I called out "fromJust" in my example; it's the one use of non-totality outside of the kernel. > Although it looks like that a case analysis on 'n' is made at run-time in: > >> instance Nat n => Nat (S n) where >> ? caseNat (S n) _ s = s n > > But I guess that is desugared away because 'S' is implemented as a newtype: > >> newtype S n = S n Yes, in my original post[1] I comment about this nicety; if I used "data" instead of "newtype" I would have implemented it as ] instance Nat Z where caseNat ~Z z _ = z ] instance Nat n => Nat (S n) where caseNat ~(S n) _ s = s n > Again, thanks very much for this! > > Do you mind if I use this code in the levmar package (soon to be > released on hackage)? No problem. I hereby release this code under the WTFPL[2], version 2 with the "no warranty" clause. -- ryan [1] Lightweight type-level dependent programming in Haskell. http://www.haskell.org/pipermail/haskell-cafe/2009-June/062690.html [2] http://sam.zoy.org/wtfpl/ From ryani.spam at gmail.com Tue Aug 25 03:49:04 2009 From: ryani.spam at gmail.com (Ryan Ingram) Date: Tue Aug 25 03:28:50 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: References: <49a77b7a0908211103u29118f95m2ba22d9dc85a3c46@mail.gmail.com> <2f9b2d30908241507r24a52821tc7f343c12fea967f@mail.gmail.com> Message-ID: <2f9b2d30908250049q70bf8fe8s80d2f9991a016074@mail.gmail.com> Also, be aware that we are testing the edges of what the compiler supports for type families here. I ran into a bug in my initial implementation which I submitted as http://hackage.haskell.org/trac/ghc/ticket/3460 -- ryan From leather at cs.uu.nl Tue Aug 25 07:43:59 2009 From: leather at cs.uu.nl (Sean Leather) Date: Tue Aug 25 07:24:06 2009 Subject: [Haskell-cafe] Generics for constructing Rows In-Reply-To: <87r5v6izrc.fsf@zagan.made.you> References: <87r5v6izrc.fsf@zagan.made.you> Message-ID: <3c6288ab0908250443g362661c5vb1a16b888dc6d36e@mail.gmail.com> Hi Max, EMGM's > map demands traversion function to be non-polymorphic, i.e. type-checker > fails with the message, complaining it cannot match `E a` against > `E Name`, against `E Salary` etc. I'm wondering if you tried everywhere' (or everywhere) [1]. Here's one solution, but I'm not sure if it does what you what it to. -- {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE TemplateHaskell #-} module Rows where import qualified Generics.EMGM as G import Generics.EMGM.Derive data Row = Row (Either (Maybe Int) (Maybe String)) (Either (Maybe Int) (Maybe Float)) (Either (Maybe Int) (Maybe Integer)) deriving Show $(derive ''Row) gmap :: (Rep (Everywhere' (Either (Maybe Int) (Maybe a))) Row) => (Either (Maybe Int) (Maybe a) -> Either (Maybe Int) (Maybe a)) -> Row -> Row gmap = G.everywhere' -- top-down readRow :: [String] -> Row -> Row readRow l = gmap app where app :: Either (Maybe Int) (Maybe String) -> Either (Maybe Int) (Maybe String) app (Left (Just ri)) = Right (l `atMay` ri >>= G.read) app x = x atMay :: [a] -> Int -> Maybe a atMay = undefined -- This appears to implement your desired functionality. Here are some points to note about what I did to get it working: * EMGM has problems resolving type synonyms, so I expanded your E here. * I just defined gmap to show what the type signature would be here. You could get rid of gmap and just use everywhere'. * I used everywhere' instead of everywhere, because you appear to want a top-down traversal. Depending on your types, it may not matter. * I gave app a concrete type signature, because as you noted, EMGM needs to be non-polymorphic here. * I also gave app a fallback case, so you don't get any unexpected surprises at runtime. * I used EMGM's read function [2] which seemed to be what you wanted for readMay. You could still use readMay here, of course. [1] http://hackage.haskell.org/packages/archive/emgm/0.3.1/doc/html/Generics-EMGM-Functions-Everywhere.html [2] http://hackage.haskell.org/packages/archive/emgm/0.3.1/doc/html/Generics-EMGM-Functions-Read.html Regards, Sean -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090825/0523994e/attachment.html From frodo at theshire.org Tue Aug 25 09:07:32 2009 From: frodo at theshire.org (Cristiano Paris) Date: Tue Aug 25 08:47:38 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: <2f9b2d30908241507r24a52821tc7f343c12fea967f@mail.gmail.com> References: <49a77b7a0908211103u29118f95m2ba22d9dc85a3c46@mail.gmail.com> <2f9b2d30908241507r24a52821tc7f343c12fea967f@mail.gmail.com> Message-ID: On Tue, Aug 25, 2009 at 12:07 AM, Ryan Ingram wrote: > unsafeCoerce is ugly and I wouldn't count on that working properly. > > Here's a real solution: > > >> {-# LANGUAGE GADTs, RankNTypes, TypeFamilies, ScopedTypeVariables, FlexibleContexts #-} >> {-# LANGUAGE FlexibleInstances #-} > ... Disturbing... I must admin it: I'll never be a Haskell Guru (tm). Cristiano From lemming at henning-thielemann.de Tue Aug 25 09:20:23 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Tue Aug 25 09:00:09 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: References: <20090822170352.5A3C53245AF@www.haskell.org> <1251024096.2246.21.camel@localhost> Message-ID: On Sun, 23 Aug 2009, Lennart Augustsson wrote: > You're absolutely right. It would be easy to change logBase to have > special cases for, say, base 2 and base 10, and call the C library > functions for those. In fact, I think it's a worth while change, > since it's easy and get's better results for some cases. I think, the current implementation should left as it is. For fractional bases, no one would easily detect such imprecise results and report them as problem. So, it seems like people need a logarithm of integers, so they should be supplied with a special logarithm function for integers. For the other use cases, where 10 as base is one choice amongst a continuous set of rational numbers it would not be a problem to give the imprecise result. In the general case I would not accept a speed loss due to a check against 2 and 10 as base. In dynamically typed languages like Python this might be different, because their users might not care much about types. It may not be important for them, whether a number is an integer or a floating point number that is accidentally integral. However, Python distinguishes between these two kinds of integers, but only dynamically. From schlepptop at henning-thielemann.de Tue Aug 25 09:47:38 2009 From: schlepptop at henning-thielemann.de (Henning Thielemann) Date: Tue Aug 25 09:24:26 2009 Subject: [Haskell-cafe] Converting typeset mathematics into Haskell ? In-Reply-To: <447AAD9A-7BEF-4944-83D0-EB560B151423@cs.otago.ac.nz> References: <4A8F32A2.6060608@bigpond.net.au> <447AAD9A-7BEF-4944-83D0-EB560B151423@cs.otago.ac.nz> Message-ID: <4A93EB7A.6080707@henning-thielemann.de> Richard O'Keefe schrieb: > > On Aug 22, 2009, at 11:49 AM, Mark Wassell wrote: >> Think about how you would convert this into Haskell. You might then >> find yourself wondering why you have to convert it into Haskell at all. > > But very quickly you realise that it is because a lot of > mathematical notation is heavily ambiguous and requires > fairly sophisticated N.I. to parse correctly. Thus I had the idea to do it the other round: Typeset formulas as executable Haskell programs that can be converted and pretty printed by LaTeX. lhs2TeX allows a bit of this procedure. From duncan.coutts at worc.ox.ac.uk Tue Aug 25 09:15:14 2009 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Tue Aug 25 09:25:59 2009 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: jhc 0.7.1 In-Reply-To: <20090825041336.GI18852@sliver.repetae.net> References: <20090825041336.GI18852@sliver.repetae.net> Message-ID: <1251206114.30910.8061.camel@localhost> On Mon, 2009-08-24 at 21:13 -0700, John Meacham wrote: > Hi, I am happy to announce the jhc optimizing haskell compiler version 0.7.1. Congratulations on getting a public release out. A few comments: 1. Would it be possible to have a machine-readable form of: jhc --list-libraries It's possible to parse the output of course but the worry is always that the format will change again. 2. In older jhc versions it was possible to specify .hl libraries by name and version, eg jhc -p filepath-1.0.1.1. In the latest release it is only possible by name. Is this intentional? I know jhc uses hashes to uniquely identify installed packages, perhaps it should be possible to specify packages by hash for the case that one has several instances of the same package (possibly different versions, or built against different versions of various dependencies). 3. Related to 1 and 2, what does the jhc --list-libraries output look like when there are several packages of the same version but with a different hash? Maybe a machine readable --list-libraries should list the hash too. 4. Is there a way to get back the library/package description that jhc bakes into the .hl files? There's a --show-ho. Perhaps we want a --show-hl that dumps the library description? I guess that should also tell us the package hash. 5. The ./configure doesn't check for the Haskell readline package. Duncan From lemming at henning-thielemann.de Tue Aug 25 10:11:00 2009 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Tue Aug 25 09:50:46 2009 Subject: [Haskell-cafe] How to calculate de number of digits of an integer? (was: Is logBase right?) In-Reply-To: <549488306.20090822214537@gmail.com> References: <549488306.20090822214537@gmail.com> Message-ID: On Sat, 22 Aug 2009, Bulat Ziganshin wrote: > Hello Roberto, > > Saturday, August 22, 2009, 9:19:26 PM, you wrote: > >> I want to calculate the number of digits of a positive integer. I was > > fastest way > > digits = iterate (`div` 10) >>> takeWhile (>0) >>> length This needs quadratic time with respect to the number of digits, doesn't it? If (show . length) is not fast enough, I would try to catch the magnitude by repeated squaring of 10. If you have found a 'k' with 10^(2^k) <= n < 10^(2^(k+1)) then you can start to find the exact number of digits with bisection. From bulat.ziganshin at gmail.com Tue Aug 25 10:16:49 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Aug 25 09:56:50 2009 Subject: [Haskell-cafe] How to calculate de number of digits of an integer? (was: Is logBase right?) In-Reply-To: References: <549488306.20090822214537@gmail.com> Message-ID: <1068833549.20090825181649@gmail.com> Hello Henning, Tuesday, August 25, 2009, 6:11:00 PM, you wrote: >> digits = iterate (`div` 10) >>> takeWhile (>0) >>> length > This needs quadratic time with respect to the number of digits, doesn't > it? why? i think that `show` uses pretty the same way to build list of digits, so we just omit unneeded computations -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From lennart at augustsson.net Tue Aug 25 10:26:44 2009 From: lennart at augustsson.net (Lennart Augustsson) Date: Tue Aug 25 10:06:32 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: References: <20090822170352.5A3C53245AF@www.haskell.org> <1251024096.2246.21.camel@localhost> Message-ID: I don't really care much one way or the other, but since C (math.h) provides functions for base 2 and base 10 with some additional accuracy, I wouldn't mind using them. For a constant base I'd expect the extra comparison to be constant folded, so that's ok. For a non-constant base there would be a small penalty. -- Lennart On Tue, Aug 25, 2009 at 3:20 PM, Henning Thielemann wrote: > > On Sun, 23 Aug 2009, Lennart Augustsson wrote: > >> You're absolutely right. ?It would be easy to change logBase to have >> special cases for, say, base 2 and base 10, and call the C library >> functions for those. ?In fact, I think it's a worth while change, >> since it's easy and get's better results for some cases. > > I think, the current implementation should left as it is. For fractional > bases, no one would easily detect such imprecise results and report them as > problem. So, it seems like people need a logarithm of integers, so they > should be supplied with a special logarithm function for integers. For the > other use cases, where 10 as base is one choice amongst a continuous set of > rational numbers it would not be a problem to give the imprecise result. In > the general case I would not accept a speed loss due to a check against 2 > and 10 as base. > > In dynamically typed languages like Python this might be different, because > their users might not care much about types. It may not be important for > them, whether a number is an integer or a floating point number that is > accidentally integral. However, Python distinguishes between these two kinds > of integers, but only dynamically. > From jefferson.r.heard at gmail.com Tue Aug 25 10:29:47 2009 From: jefferson.r.heard at gmail.com (Jeff Heard) Date: Tue Aug 25 10:09:54 2009 Subject: [Haskell-cafe] Is logBase right? In-Reply-To: References: Message-ID: <4165d3a70908250729p34bad534rc55a9270b16d1c17@mail.gmail.com> I always thought that he who compares floating point numbers for equality was acting in tangent of reason... -- Jeff On Sat, Aug 22, 2009 at 4:02 AM, Mark Wotton wrote: > he who compares floating point numbers for equality is in a state of sin. > > mark > > On 22/08/2009, at 5:00 AM, Roberto wrote: > >> Hi, >> >> There is a mistake is logBase: >> >> $ ghci >> GHCi, version 6.10.4: http://www.haskell.org/ghc/ ?:? for help >> Loading package ghc-prim ... linking ... done. >> Loading package integer ... linking ... done. >> Loading package base ... linking ... done. >> Prelude> logBase 10 10 >> 1.0 >> Prelude> logBase 10 100 >> 2.0 >> Prelude> logBase 10 1000 >> 2.9999999999999996 ? ? ? ? ? ? ? ? ?<--- eeeerrgghhhh! >> Prelude> logBase 10 10000 >> 4.0 >> >> >> My host is a Debian GNU/Linux 5.0.2 (lenny) with the following GHC >> packages: >> >> ii ?ghc6 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 6.10.4-1 >> ii ?ghc6-doc ? ? ? ? ? ? ? ? ? ? ? ? ? ? 6.10.4-1 >> ii ?libghc6-mtl-dev ? ? ? ? ? ? ? ? ? ? ?1.1.0.2-7+b1 >> ii ?libghc6-utf8-string-dev ? ? ? ? ? ? ?0.3.5-1+b1 >> ii ?libghc6-x11-dev ? ? ? ? ? ? ? ? ? ? ?1.4.5-6 >> rc ?libghc6-x11-doc ? ? ? ? ? ? ? ? ? ? ?1.4.2-1 >> ii ?libghc6-x11-xft-dev ? ? ? ? ? ? ? ? ?0.3-3+b3 >> ii ?libghc6-xmonad-contrib-dev ? ? ? ? ? 0.8.1-3+b3 >> rc ?libghc6-xmonad-contrib-doc ? ? ? ? ? 0.8-2 >> ii ?libghc6-xmonad-dev ? ? ? ? ? ? ? ? ? 0.8.1-5 >> >> Regards! >> >> >> _______________________________________________ >> 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 schlepptop at henning-thielemann.de Tue Aug 25 11:01:24 2009 From: schlepptop at henning-thielemann.de (Henning Thielemann) Date: Tue Aug 25 10:38:06 2009 Subject: [Haskell-cafe] How to calculate de number of digits of an integer? In-Reply-To: <1068833549.20090825181649@gmail.com> References: <549488306.20090822214537@gmail.com> <1068833549.20090825181649@gmail.com> Message-ID: <4A93FCC4.7020706@henning-thielemann.de> Bulat Ziganshin schrieb: > Hello Henning, > > Tuesday, August 25, 2009, 6:11:00 PM, you wrote: > >>> digits = iterate (`div` 10) >>> takeWhile (>0) >>> length > >> This needs quadratic time with respect to the number of digits, doesn't >> it? > > why? Because division by 10 needs linear time. > i think that `show` uses pretty the same way to build list of > digits, so we just omit unneeded computations I hope that 'show' will not need quadratic time but will employ a more efficient algorithm that is certainly implemented in the GNU multiprecision library. I assume that a division by 10^(2^k) will require about 2^k * k operations. At least, it should be considerably faster than repeatedly dividing by 10. From schlepptop at henning-thielemann.de Tue Aug 25 11:21:56 2009 From: schlepptop at henning-thielemann.de (Henning Thielemann) Date: Tue Aug 25 10:58:38 2009 Subject: [Haskell-cafe] Re: Converting typeset mathematics into Haskell ? In-Reply-To: <2D9927E2-F8DF-4A59-BA15-AD118B827241@informatik.uni-kiel.de> References: <2D9927E2-F8DF-4A59-BA15-AD118B827241@informatik.uni-kiel.de> Message-ID: <4A940194.70703@henning-thielemann.de> Bernd Brassel schrieb: > Sometimes the synchronicity of events is eery. Incidentally I have just > written a proposal for just such a project. > You can have a look at it at > > http://www-ps.informatik.uni-kiel.de/~bbr/WebOfProofs.html > > Although not directly mentioned in the proposal, there will be a lot of > "Converting typeset mathematics into Haskell" going on. For completeness I want to add a pointer to other projects supporting the "semantic math web": http://kwarc.info/kohlhase/research.html From fiddlosopher at gmail.com Tue Aug 25 11:54:34 2009 From: fiddlosopher at gmail.com (John MacFarlane) Date: Tue Aug 25 11:34:47 2009 Subject: [Haskell-cafe] ANN: gitit 0.6.1 Message-ID: <20090825155434.GB10361@protagoras.phil.berkeley.edu> I'm pleased to announce the release of gitit 0.6.1. Gitit is a wiki program that runs on happstack, the Haskell web application server stack, and stores pages and other content in a git or darcs filestore. The wiki can be updated either directly through the VCS or through gitit's web interface. Pages can be written in (extended) markdown, reStructuredText, HTML, or LaTeX, and exported in ten different formats. TeX math is rendered using MathML by default, and syntax highlighting is provided for over fifty languages. demo: http://gitit.johnmacfarlane.net manual: http://gitit.johnmacfarlane.net/README api: http://hackage.haskell.org/package/gitit-0.6.1 code: http://github.com/jgm/gitit bugs: http://code.google.com/p/gitit/issues/list group: http://groups.google.com/group/gitit-discuss Here is how you can install and run gitit. You'll need GHC and cabal-install. If you don't have these, install the Haskell Platform . Then: cabal update cabal install gitit mkdir mywiki cd mywiki gitit # now browse to http://localhost:5001 Or, if you want to change the defaults (say, reStructuredText instead of markdown, or darcs instead of git): gitit --print-default-config > gitit.conf # edit gitit.conf, which is self-documenting gitit -f gitit.conf The whole code base has been overhauled since the last release. Gitit is now faster, more memory efficient, more modular, and more secure. It also has many new features, including - page metadata and categories - atom feeds (sitewide and per-page) - support for literate Haskell - a better configuration system - an improved caching system - a Haskell library exporting happstack wiki handlers - a plugin system The last two items are the most exciting and deserve special comment. First, in addition to providing an executable, gitit now provides a library, Network.Gitit, which makes it easy to include a gitit wiki (or many of them) in any happstack application. It is even possible to use the containing application's authentication system for the wiki. Second, gitit can now be extended through plugins, short Haskell programs that are loaded dynamically when the server starts. For examples of the things that can be done with plugins, see the plugins directory, which contains (among other things) a plugin for adding graphviz diagrams to pages and a plugin for adding interwiki links. For a full description of the plugin system, see the haddock documentation for Network.Gitit.Interface. Full changes from version 0.5.3, as well as upgrade instructions, are available in the file CHANGES. Thanks are due to - the happstack team, for big improvements in happstack-server that make it much easier to work with, - the darcs team, for using gitit/darcsit for , giving gitit a real-world test, - Gwern Branwen, who helped to optimize gitit, wrote the InterwikiPlugin, and wrote the guts of the Feed module, - Simon Michael, who contributed several patches, - Henry Laxen, who added support for password resets and helped with the apache proxy instructions, - Anton van Straaten, who made the process of page generation more modular by adding Gitit.ContentTransformer, - Robin Green, who helped improve the plugin API and interface, fixed a security problem with the reset password code, and made saving of the user's file more robust, - Thomas Hartman, who helped improve the index page, making directory browsing persistent, - Kohei Ozaki, who contributed the ImgTexPlugin, - mightybyte, who suggested making gitit available as a library, and contributed a patch to the authentication system, - and everyone else who contributed suggestions and bug reports. From dagit at codersbase.com Tue Aug 25 12:06:20 2009 From: dagit at codersbase.com (Jason Dagit) Date: Tue Aug 25 11:46:08 2009 Subject: [Haskell-cafe] ANN: gitit 0.6.1 In-Reply-To: <20090825155434.GB10361@protagoras.phil.berkeley.edu> References: <20090825155434.GB10361@protagoras.phil.berkeley.edu> Message-ID: Thanks John! On Tue, Aug 25, 2009 at 8:54 AM, John MacFarlane wrote: > I'm pleased to announce the release of gitit 0.6.1. > > Gitit is a wiki program that runs on happstack, the Haskell web > application server stack, and stores pages and other content in a > git or darcs filestore. The wiki can be updated either directly > through the VCS or through gitit's web interface. Pages can be written > in (extended) markdown, reStructuredText, HTML, or LaTeX, and exported > in ten different formats. TeX math is rendered using MathML by default, > and syntax highlighting is provided for over fifty languages. > > demo: ? http://gitit.johnmacfarlane.net > manual: http://gitit.johnmacfarlane.net/README > api: ? ?http://hackage.haskell.org/package/gitit-0.6.1 > code: ? http://github.com/jgm/gitit > bugs: ? http://code.google.com/p/gitit/issues/list > group: ?http://groups.google.com/group/gitit-discuss If anyone would like to see an example of gitit using the darcs filestore (we affectionately call it 'darcsit'), you can take a look at the darcs project wiki: http://wiki.darcs.net/ Jason From bos at serpentine.com Tue Aug 25 12:23:03 2009 From: bos at serpentine.com (Bryan O'Sullivan) Date: Tue Aug 25 12:02:48 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: References: <5e0214850908220102n52d636duf1848828dfd9c3f5@mail.gmail.com> Message-ID: 2009/8/22 Roberto L?pez > > You get the accuracy value in Perl, but there is the same problem in > Python. > It's a bit discouraging. > You don't get an accurate answer with Perl. It just lies to you to keep you happy in your ignorance. $ perl -e 'printf "%.22f\n", log(1000)/log(10);' 2.9999999999999995559108 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090825/b20fb587/attachment.html From robgreayer at gmail.com Tue Aug 25 12:43:04 2009 From: robgreayer at gmail.com (Robert Greayer) Date: Tue Aug 25 12:22:52 2009 Subject: [Haskell-cafe] oauth in haskell - reviewers? In-Reply-To: <20090824212409.GI28658@whirlpool.galois.com> References: <20090822233654.GA16495@mephisto.bitforest.org> <57526e770908222008o25780147ve211a8279dc82f56@mail.gmail.com> <20090823162555.GA4190@mephisto.bitforest.org> <71fd12e60908241356n70525f9ep6a3d32ca28505091@mail.gmail.com> <20090824212409.GI28658@whirlpool.galois.com> Message-ID: <4ec472cb0908250943h693c47abuc50d06a51864fadd@mail.gmail.com> On Mon, Aug 24, 2009 at 5:24 PM, Don Stewart wrote: > I notice hoauth is packaged as LGPL. Since we use static linking in GHC, > this makes it in practice GPL. Is that the intent? > > -- Don > I don't think this is 100% true -- the requirement is to allow the end user the ability to replace the version of the library they're using with something else, which can be accomplished by dynamically linked libraries, but also means that if the rest of the program is open source (but not GPL), the requirement is satisfied. LGPL is generally compatible with GPL-incompatible open-source, whether statically linked or not. It is true it is incompatible with closed source licensing. There are some real situations where this might matter -- you could use this library in an an executable in which the remainder of the source was MPL, I think, as long as there were the possibility of relinking with a different version of the LGPL library. You couldn't do this if it were GPL. This is the section of the LGPL that mentions this: "Do one of the following: * 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. *1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version." So, Haskell libraries licensed under LGPL (without the static linking exception) force option 0, but that doesn't make them completely equivalent to GPL. At least that's my understanding (which could be flawed!). -Rob > wei.hoo: >> I recommend "Learn you a Haskell for great good": >> http://learnyouahaskell.com/functors-applicative-functors-and-monoids#applicative-functors >> >> On Sun, Aug 23, 2009 at 12:25 PM, Diego Souza wrote: >> > A quick search pointed me to this: >> > http://www.soi.city.ac.uk/~ross/papers/Applicative.html >> > >> > Is there any other resources you would suggest me to read? >> > >> > Thanks at lot, >> > -- >> > ~dsouza >> > yahoo!im: paravinicius >> > gpg key fingerprint: 71B8 CE21 3A6E F894 5B1B ?9ECE F88E 067F E891 651E >> > _______________________________________________ >> > 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 dons at galois.com Tue Aug 25 12:47:40 2009 From: dons at galois.com (Don Stewart) Date: Tue Aug 25 12:29:33 2009 Subject: [Haskell-cafe] oauth in haskell - reviewers? In-Reply-To: <4ec472cb0908250943h693c47abuc50d06a51864fadd@mail.gmail.com> References: <20090822233654.GA16495@mephisto.bitforest.org> <57526e770908222008o25780147ve211a8279dc82f56@mail.gmail.com> <20090823162555.GA4190@mephisto.bitforest.org> <71fd12e60908241356n70525f9ep6a3d32ca28505091@mail.gmail.com> <20090824212409.GI28658@whirlpool.galois.com> <4ec472cb0908250943h693c47abuc50d06a51864fadd@mail.gmail.com> Message-ID: <20090825164740.GA1136@whirlpool.galois.com> robgreayer: > On Mon, Aug 24, 2009 at 5:24 PM, Don Stewart wrote: > > I notice hoauth is packaged as LGPL. Since we use static linking in GHC, > > this makes it in practice GPL. Is that the intent? > > > > -- Don > > > > I don't think this is 100% true -- the requirement is to allow the end > user the ability to replace the version of the library they're using > with something else, which can be accomplished by dynamically linked > libraries, but also means that if the rest of the program is open > source (but not GPL), the requirement is satisfied. LGPL is generally > compatible with GPL-incompatible open-source, whether statically > linked or not. It is true it is incompatible with closed source > licensing. > > There are some real situations where this might matter -- you could > use this library in an an executable in which the remainder of the > source was MPL, I think, as long as there were the possibility of > relinking with a different version of the LGPL library. You couldn't > do this if it were GPL. This is the section of the LGPL that mentions > this: > > "Do one of the following: > > * 0) Convey the Minimal Corresponding Source under the terms of > this License, and the Corresponding Application Code in a form > suitable for, and under terms that permit, the user to recombine or > relink the Application with a modified version of the Linked Version > to produce a modified Combined Work, in the manner specified by > section 6 of the GNU GPL for conveying Corresponding Source. > *1) Use a suitable shared library mechanism for linking with the > Library. A suitable mechanism is one that (a) uses at run time a copy > of the Library already present on the user's computer system, and (b) > will operate properly with a modified version of the Library that is > interface-compatible with the Linked Version." > > So, Haskell libraries licensed under LGPL (without the static linking > exception) force option 0, but that doesn't make them completely > equivalent to GPL. At least that's my understanding (which could be > flawed!). That's quite true. It's not completely equivalent. It is just very difficult to distribute your Haskell app in such a way that it can be relinked against LGPL licensed Haskell libraries. If the intent is that the improvements to the source remain open, and are contributed back, but you want to allow commercial use, a different license would be appropriate. -- Don From kowey at darcs.net Tue Aug 25 12:51:30 2009 From: kowey at darcs.net (Eric Kow) Date: Tue Aug 25 12:31:16 2009 Subject: [Haskell-cafe] Re: ANN: gitit 0.6.1 In-Reply-To: <20090825155434.GB10361@protagoras.phil.berkeley.edu> References: <20090825162303.6F7F93247CB@www.haskell.org> Message-ID: <20090825165129.GA31293@brighton.ac.uk> > - the darcs team, for using gitit/darcsit for , > giving gitit a real-world test, I think other Darcs hackers will agree with me when I say that we're pretty thrilled with gitit (ahem, darcsit as Jason points out). Thanks to fantastic response by John and Gwern, we were able to work through the initial web spider hiccups. It's great to be able to just darcs get --lazy http://wiki.darcs.net and go! -- Eric Kow PGP Key ID: 08AC04F9 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090825/716b75dd/attachment.bin From toralf.wittner at gmail.com Tue Aug 25 12:53:33 2009 From: toralf.wittner at gmail.com (Toralf Wittner) Date: Tue Aug 25 12:33:19 2009 Subject: [Haskell-cafe] ANN: epoll bindings 0.1.1 Message-ID: Hi, I am pleased to announce the release of epoll bindings 0.1.1 available from: http://hackage.haskell.org/package/epoll Epoll is an I/O event notification facility for Linux similar to poll but with good scaling characteristics. Currently the bindings are fairly low level and close to the C API. In the future I hope to add some buffer or stream abstraction on top. Eventually, when GHC can make use of epoll/kqueue etc. in addition to select, this library will not be needed anymore. Until then it might be useful for applications which monitor large numbers of file descriptors. -Toralf From ketil at malde.org Tue Aug 25 13:11:18 2009 From: ketil at malde.org (Ketil Malde) Date: Tue Aug 25 12:50:44 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: <1251034068.3085.55.camel@localhost> (Steve's message of "Sun\, 23 Aug 2009 21\:27\:48 +0800") References: <20090822170352.5A3C53245AF@www.haskell.org> <1251024096.2246.21.camel@localhost> <5e0214850908230412s199c79absc66f47e03a539eb7@mail.gmail.com> <1251034068.3085.55.camel@localhost> Message-ID: <8763cbx1hl.fsf@malde.org> Steve writes: > Also, I had a problem using floating point in Python where >>>> round(697.04157958254996, 10) > gave > 697.04157958259998 > Its been fixed in the latest versions of Python: >>>> round(697.04157958254996, 10) > 697.0415795825 > ghci> roundN 697.04157958254996 10 > 697.0415795826 Is there something special with this number? Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 697.04157958259998 697.04157958259998 >>> 12345.678901234567890 12345.678901234567 GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help Loading package base ... linking ... done. Prelude> 697.04157958259998 697.0415795826 Prelude> 12345.678901234567890 12345.678901234567 So, Python manages to keep more decimals than GHC for your number, but for other numbers, the precision appears to be the same. -k -- If I haven't seen further, it is by standing in the footprints of giants From ryani.spam at gmail.com Tue Aug 25 13:15:39 2009 From: ryani.spam at gmail.com (Ryan Ingram) Date: Tue Aug 25 12:55:25 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: References: <49a77b7a0908211103u29118f95m2ba22d9dc85a3c46@mail.gmail.com> <2f9b2d30908241507r24a52821tc7f343c12fea967f@mail.gmail.com> Message-ID: <2f9b2d30908251015j8ded70brae6f2011c78d3844@mail.gmail.com> On Tue, Aug 25, 2009 at 6:07 AM, Cristiano Paris wrote: > On Tue, Aug 25, 2009 at 12:07 AM, Ryan Ingram wrote: >>> {-# LANGUAGE GADTs, RankNTypes, TypeFamilies, ScopedTypeVariables, FlexibleContexts #-} >>> {-# LANGUAGE FlexibleInstances #-} > Disturbing... I must admin it: I'll never be a Haskell Guru (tm). That's funny, I consider GADTs, RankNTypes, and ScopedTypeVariables to be the starting point for real code. They just go at the top of the file without thinking at this point. (Well, sometimes I leave GADTs out) -- ryan From jgm at berkeley.edu Tue Aug 25 13:22:51 2009 From: jgm at berkeley.edu (John MacFarlane) Date: Tue Aug 25 13:03:02 2009 Subject: [Haskell-cafe] Re: ANN: gitit 0.6.1 In-Reply-To: <20090825155434.GB10361@protagoras.phil.berkeley.edu> References: <20090825155434.GB10361@protagoras.phil.berkeley.edu> Message-ID: <20090825172251.GA1027@protagoras.phil.berkeley.edu> PS. I've put the library documentation here: http://gitit.johnmacfarlane.net/doc/gitit/index.html Does anyone understand why HackageDB is having trouble building filestore 0.3.2? http://hackage.haskell.org/packages/archive/filestore/0.3.2/logs/failure/ghc-6.10 John +++ John MacFarlane [Aug 25 09 08:54 ]: > I'm pleased to announce the release of gitit 0.6.1. > > Gitit is a wiki program that runs on happstack, the Haskell web > application server stack, and stores pages and other content in a > git or darcs filestore. The wiki can be updated either directly > through the VCS or through gitit's web interface. Pages can be written > in (extended) markdown, reStructuredText, HTML, or LaTeX, and exported > in ten different formats. TeX math is rendered using MathML by default, > and syntax highlighting is provided for over fifty languages. > > demo: http://gitit.johnmacfarlane.net > manual: http://gitit.johnmacfarlane.net/README > api: http://hackage.haskell.org/package/gitit-0.6.1 > code: http://github.com/jgm/gitit > bugs: http://code.google.com/p/gitit/issues/list > group: http://groups.google.com/group/gitit-discuss > > Here is how you can install and run gitit. You'll need GHC and > cabal-install. If you don't have these, install the Haskell Platform > . Then: > > cabal update > cabal install gitit > mkdir mywiki > cd mywiki > gitit # now browse to http://localhost:5001 > > Or, if you want to change the defaults (say, reStructuredText > instead of markdown, or darcs instead of git): > > gitit --print-default-config > gitit.conf > # edit gitit.conf, which is self-documenting > gitit -f gitit.conf > > The whole code base has been overhauled since the last release. > Gitit is now faster, more memory efficient, more modular, and more > secure. It also has many new features, including > > - page metadata and categories > - atom feeds (sitewide and per-page) > - support for literate Haskell > - a better configuration system > - an improved caching system > - a Haskell library exporting happstack wiki handlers > - a plugin system > > The last two items are the most exciting and deserve special comment. > > First, in addition to providing an executable, gitit now provides a > library, Network.Gitit, which makes it easy to include a gitit > wiki (or many of them) in any happstack application. It is > even possible to use the containing application's authentication > system for the wiki. > > Second, gitit can now be extended through plugins, short Haskell > programs that are loaded dynamically when the server starts. For > examples of the things that can be done with plugins, see the > plugins directory, which contains (among other things) a plugin > for adding graphviz diagrams to pages and a plugin for adding > interwiki links. For a full description of the plugin system, > see the haddock documentation for Network.Gitit.Interface. > > Full changes from version 0.5.3, as well as upgrade instructions, > are available in the file CHANGES. > > Thanks are due to > > - the happstack team, for big improvements in happstack-server > that make it much easier to work with, > > - the darcs team, for using gitit/darcsit for , > giving gitit a real-world test, > > - Gwern Branwen, who helped to optimize gitit, wrote the > InterwikiPlugin, and wrote the guts of the Feed module, > > - Simon Michael, who contributed several patches, > > - Henry Laxen, who added support for password resets and helped with > the apache proxy instructions, > > - Anton van Straaten, who made the process of page generation > more modular by adding Gitit.ContentTransformer, > > - Robin Green, who helped improve the plugin API and interface, > fixed a security problem with the reset password code, and made > saving of the user's file more robust, > > - Thomas Hartman, who helped improve the index page, making directory > browsing persistent, > > - Kohei Ozaki, who contributed the ImgTexPlugin, > > - mightybyte, who suggested making gitit available as a library, > and contributed a patch to the authentication system, > > - and everyone else who contributed suggestions and bug reports. > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From martijn at van.steenbergen.nl Tue Aug 25 14:45:42 2009 From: martijn at van.steenbergen.nl (Martijn van Steenbergen) Date: Tue Aug 25 14:25:35 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: <49a77b7a0908211103u29118f95m2ba22d9dc85a3c46@mail.gmail.com> References: <49a77b7a0908211103u29118f95m2ba22d9dc85a3c46@mail.gmail.com> Message-ID: <4A943156.8030508@van.steenbergen.nl> David Menendez wrote: > data SomeNat where SomeNat :: (Nat n) => n -> SomeNat > toPeano :: Int -> SomeNat > > or, equivalently, by using a higher-order function. > > toPeano :: Int -> (forall n. Nat n => n -> t) -> t Nice! I thought the only way to create them was with a new datatype, but this works too. I guess the nontrivial bit to think of is the introduction of a fresh type (t in this case). Thanks for this insight! Martijn. From frodo at theshire.org Tue Aug 25 15:55:13 2009 From: frodo at theshire.org (Cristiano Paris) Date: Tue Aug 25 15:35:17 2009 Subject: [Haskell-cafe] How to convert a list to a vector encoding its length in its type? In-Reply-To: <2f9b2d30908251015j8ded70brae6f2011c78d3844@mail.gmail.com> References: <49a77b7a0908211103u29118f95m2ba22d9dc85a3c46@mail.gmail.com> <2f9b2d30908241507r24a52821tc7f343c12fea967f@mail.gmail.com> <2f9b2d30908251015j8ded70brae6f2011c78d3844@mail.gmail.com> Message-ID: On Tue, Aug 25, 2009 at 7:15 PM, Ryan Ingram wrote: > On Tue, Aug 25, 2009 at 6:07 AM, Cristiano Paris wrote: >> On Tue, Aug 25, 2009 at 12:07 AM, Ryan Ingram wrote: >>>> {-# LANGUAGE GADTs, RankNTypes, TypeFamilies, ScopedTypeVariables, FlexibleContexts #-} >>>> {-# LANGUAGE FlexibleInstances #-} > >> Disturbing... I must admin it: I'll never be a Haskell Guru (tm). > > That's funny, I consider GADTs, RankNTypes, and ScopedTypeVariables to > be the starting point for real code. ?They just go at the top of the > file without thinking at this point. ?(Well, sometimes I leave GADTs > out) It was not the pragmas, it was the type machinery that bit of scared me :) Cristiano From ryani.spam at gmail.com Tue Aug 25 18:03:31 2009 From: ryani.spam at gmail.com (Ryan Ingram) Date: Tue Aug 25 17:43:16 2009 Subject: [Haskell-cafe] Is it possible to prove type *non*-equality in Haskell? Message-ID: <2f9b2d30908251503v42ac7052qd6dd93e1443e44bd@mail.gmail.com> Short version: How can I get from (Z ~ S n) to a useful contradiction? Type equality coercions[1] let us write proofs in Haskell that two types are equal: > {-# LANGUAGE GADTs, RankNTypes, TypeFamilies #-} > {-# OPTIONS_GHC -Wall #-} > module TEq where > data TEq a b = (a ~ b) => TEq This provides all the expected properties for equality: > refl :: TEq a a > refl = TEq > symm :: TEq a b -> TEq b a > symm TEq = TEq > trans :: TEq a b -> TEq b c -> TEq a c > trans TEq TEq = TEq Here's an example use: > data Z = Z > newtype S n = S n > data Nat a where > Nz :: Nat Z > Ns :: Nat x -> Nat (S x) > proveEq :: Nat a -> Nat b -> Maybe (TEq a b) > proveEq Nz Nz = return TEq > proveEq (Ns a) (Ns b) = do > TEq <- proveEq a b > return TEq > proveEq _ _ = Nothing But if you get "Nothing" back, there's no proof that the two types are in fact non-equal. You can use "_|_ as negation": > newtype Not p = Contr { contradiction :: forall a. p -> a } > > nsymm :: Not (TEq a b) -> Not (TEq b a) > nsymm pf = Contr (contradiction pf . symm) We know by parametricity that "contradiction n p" isn't inhabited as its type is (forall a. a) But I can't figure out a way to write this without "error": > notZeqS :: forall n. Not (TEq Z (S n)) > notZeqS = Contr (\x -> x `seq` error "impossible") As a first step, I'd like to write this: > -- notZeqS = Contr (\TEq -> error "impossible") but the compiler complains immediately about the pattern match being unsound: TEq.lhs:39:20: Couldn't match expected type `S n' against inferred type `Z' In the pattern: TEq In the first argument of `Contr', namely `(\ TEq -> error "impossible")' In the expression: Contr (\ TEq -> error "impossible") Is there any way to use the obvious unsoundness we get from (Z ~ S n) to generate a contradiction? Ideally I'd like to be able to implement ] natEqDec :: Nat a -> Nat b -> Either (TEq a b) (Not (TEq a b)) as follows: > predEq :: TEq (f a) (f b) -> TEq a b > predEq TEq = TEq > natEqDec :: Nat a -> Nat b -> Either (TEq a b) (Not (TEq a b)) > natEqDec Nz Nz = Left TEq > natEqDec (Ns a) (Ns b) = case natEqDec a b of > Left TEq -> Left TEq > Right pf -> Right $ Contr $ \eq -> contradiction pf (predEq eq) > natEqDec Nz (Ns _) = Right notZeqS > natEqDec (Ns _) Nz = Right (nsymm notZeqS) Which compiles successfully, but the "error" call in "notZeqS" is a big wart. Is there a better implementation of "Not" that allows us to avoid this wart? -- ryan [1] http://research.microsoft.com/en-us/um/people/simonpj/papers/ext-f/ From dan.doel at gmail.com Tue Aug 25 18:39:06 2009 From: dan.doel at gmail.com (Dan Doel) Date: Tue Aug 25 18:18:56 2009 Subject: [Haskell-cafe] Is it possible to prove type *non*-equality in Haskell? In-Reply-To: <2f9b2d30908251503v42ac7052qd6dd93e1443e44bd@mail.gmail.com> References: <2f9b2d30908251503v42ac7052qd6dd93e1443e44bd@mail.gmail.com> Message-ID: <200908251839.06581.dan.doel@gmail.com> On Tuesday 25 August 2009 6:03:31 pm Ryan Ingram wrote: > > proveEq :: Nat a -> Nat b -> Maybe (TEq a b) > > proveEq Nz Nz = return TEq > > proveEq (Ns a) (Ns b) = do > > TEq <- proveEq a b > > return TEq > > proveEq _ _ = Nothing > > But if you get "Nothing" back, there's no proof that the two types are > in fact non-equal. Well, this isn't surprising; you wouldn't have it even in a more rigorous proof environment. Instead, you'd have to make the return type something like Either (a == b) (a /= b) > You can use "_|_ as negation": > > newtype Not p = Contr { contradiction :: forall a. p -> a } > > > > nsymm :: Not (TEq a b) -> Not (TEq b a) > > nsymm pf = Contr (contradiction pf . symm) > > We know by parametricity that "contradiction n p" isn't inhabited as > its type is (forall a. a) But in Haskell, we know that it _is_ inhabited, because every type is inhabited by bottom. And one way to access this element is with undefined. > But I can't figure out a way to write this without "error": > > notZeqS :: forall n. Not (TEq Z (S n)) > > notZeqS = Contr (\x -> x `seq` error "impossible") > > As a first step, I'd like to write this: > > -- notZeqS = Contr (\TEq -> error "impossible") Well, matching against TEq is not going to work. The way you do this in Agda, for instance, is: notZeqS :: forall n -> Not (TEq Z (S n)) notZeqS = Contr (\()) Where () is the 'absurd pattern'. It's used to indicate that argument is expected to have an uninhabited type, and if Agda can prove that it is uninhabited, then a lambda expression like the above denotes the empty function. But Haskell has no such animal. You could kind of adapt it to empty case expressions: notZeqS = Contr (\pf -> case pf of {}) And perhaps require that the type system can verify that the types of such cases are uninhabited except for bottom (although that isn't strictly necessary; you could leave it as simply desugaring to a catch-all call to error and it'd work), if that's even a feasible thing to do. Currently, though, you'll get a parse error on }. > but the compiler complains immediately about the pattern match being > unsound: TEq.lhs:39:20: > Couldn't match expected type `S n' against inferred type `Z' > In the pattern: TEq > In the first argument of `Contr', namely > `(\ TEq -> error "impossible")' > In the expression: Contr (\ TEq -> error "impossible") > > Is there any way to use the obvious unsoundness we get from (Z ~ S n) to > generate a contradiction? > > Ideally I'd like to be able to implement > ] natEqDec :: Nat a -> Nat b -> Either (TEq a b) (Not (TEq a b)) > > as follows: > > predEq :: TEq (f a) (f b) -> TEq a b > > predEq TEq = TEq > > > > natEqDec :: Nat a -> Nat b -> Either (TEq a b) (Not (TEq a b)) > > natEqDec Nz Nz = Left TEq > > natEqDec (Ns a) (Ns b) = case natEqDec a b of > > Left TEq -> Left TEq > > Right pf -> Right $ Contr $ \eq -> contradiction pf (predEq eq) > > natEqDec Nz (Ns _) = Right notZeqS > > natEqDec (Ns _) Nz = Right (nsymm notZeqS) > > Which compiles successfully, but the "error" call in "notZeqS" is a > big wart. Is there a better implementation of "Not" that allows us to > avoid this wart? You could build more complex, positive proofs of inequality (having a 3-way decision between m < n, m == n and m > n might be a good one), but I don't think you'll find a notion of negation that avoids some sort of call to undefined in GHC as it currently stands. -- Dan From bugfact at gmail.com Tue Aug 25 20:30:09 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Tue Aug 25 20:09:53 2009 Subject: [Haskell-cafe] haddock: parse error in doc string Message-ID: I'm getting the error mentioned in the subject, but without any indication where in my file this error occurs. What does this mean? Thanks, Peter -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090825/a4d4cd12/attachment.html From gwern0 at gmail.com Tue Aug 25 20:47:33 2009 From: gwern0 at gmail.com (Gwern Branwen) Date: Tue Aug 25 20:27:20 2009 Subject: [Haskell-cafe] haddock: parse error in doc string In-Reply-To: References: Message-ID: On Tue, Aug 25, 2009 at 8:30 PM, Peter Verswyvelen wrote: > I'm getting the error mentioned in the subject, but without any indication > where in my file this error occurs. > What does this mean? > Thanks, > Peter It means exactly that - something in that file's comments is causing Haddock to choke. It could be using '*' inside some --s, it could be something else. Haddock won't really say. Your best bet is the old bisect/binary-search method: remove half the comments & retry, narrowing it down until you've found the offending line and then character. Then you can either remove it or read the Haddock manual and see what the right thing looks like. -- gwern From john at repetae.net Tue Aug 25 21:13:11 2009 From: john at repetae.net (John Meacham) Date: Tue Aug 25 20:52:56 2009 Subject: [Haskell-cafe] Re: [Haskell] ANNOUNCE: jhc 0.7.1 In-Reply-To: <1251206114.30910.8061.camel@localhost> References: <20090825041336.GI18852@sliver.repetae.net> <1251206114.30910.8061.camel@localhost> Message-ID: <20090826011310.GA5620@sliver.repetae.net> On Tue, Aug 25, 2009 at 02:15:14PM +0100, Duncan Coutts wrote: > 1. Would it be possible to have a machine-readable form of: > jhc --list-libraries > > It's possible to parse the output of course but the worry is always that > the format will change again. Good Idea, I'll modify the output to be a proper YAML file with a few guarenteed fields, that will leave room for expansion later and backwards compatability. > 2. In older jhc versions it was possible to specify .hl libraries by > name and version, eg jhc -p filepath-1.0.1.1. In the latest release it > is only possible by name. Is this intentional? I know jhc uses hashes to > uniquely identify installed packages, perhaps it should be possible to > specify packages by hash for the case that one has several instances of > the same package (possibly different versions, or built against > different versions of various dependencies). Ah, this is an unintentional regression. I intended to keep the behavior of being able to specify a library name/version or file name. Being able to specify a hash is also a good idea. > like when there are several packages of the same version but with a > different hash? Maybe a machine readable --list-libraries should list > the hash too. > > > 4. Is there a way to get back the library/package description that jhc > bakes into the .hl files? There's a --show-ho. Perhaps we want a > --show-hl that dumps the library description? I guess that should also > tell us the package hash. --show-ho will also work on hl files, which probably isn't mentioned anywhere in the manual. I think I will add a verbose mode to --list-libraries that will also spit out much of this meta-info (in the aforementioned YAML format) > 5. The ./configure doesn't check for the Haskell readline package. Yeah, I am currently only checking for the purpose of ghc 6.8/6.10 compatibility, but adding checks for all dependencies is a good idea. As an aside, here are the principles that guided the design of the new library system and ho cache. The main motivations were ameliorating two notable shortcomings of jhc, its speed and compatibility with other compilers: * Ho files will only affect speed of compilation, never results. No matter what. This allows the shared ho cache and decoupling the unit of caching from module granularity. * Only the interface of libraries explicitly mentioned on the command line shall affect code compiled by jhc. For instance, a libraries implementation can use an alternate prelude without hurting its compatibility with haskell 98 code. * From the users perspective, a library defines an interface, which is not necessarily coupled to the implementation. I have thought long and hard on the problem of being able to maintain some level of compatibility with ghc and hackage without sacrificing jhc's ability to innovate, or tying its development to the ghc libraries. Making libraries logical 'interfaces' rather than 'implementations' decouples compatibility issues from the compiler itself, anyone can write a library that emulates a particular interface. For instance, a compat-ghc-base3 library might have things like 'Reexport: Compat.Haskell98.Prelude as Prelude, Compat.Ghc.Base3.Monad as Control.Monad, ... '. Or more interestingly, you might create your own library that does a 'Reexport: MyApplicativePrelude as Prelude' to get your own prelude. (this is not fully realized yet in 0.7.1, but will be in a point release soon. The mechanism and framework is there though.) * Stateless. There is no such thing as hidden libraries, libraries mentioned on the command line are available, libraries not mentioned are not. Since libraries can re-export modules this won't cause a command line explosion. For instance, a -phaskell-platform could pull in and make available all the libraries in the haskell platform. * Adding libraries, even incompatible ones, won't break working builds unless said libraries are explicitly mentioned by the build in a non-precise way. This is necessary so a theoretical 'jhc-pkg' tool need only worry about adding required libraries, not cleaning up or worrying about finding consistent sets of libraries. A simple recursive download on dependencies suffices as a rudimentary cabal-install style tool. John -- John Meacham - ?repetae.net?john? - http://notanumber.net/ From phil at beadling.co.uk Tue Aug 25 21:37:36 2009 From: phil at beadling.co.uk (phil@beadling.co.uk) Date: Tue Aug 25 21:17:22 2009 Subject: [Haskell-cafe] FFI link failing due to no main? Message-ID: Hi, After creating my stub objects etc using GHC, I'm trying to create a library with a C interface to some Haskell functions. I'm explicitly passing in -no-hs-main yet the linker still fails due to missing main? I'm sure I've had this working before with a slightly simpler example, but can't work out what is wrong here. If I give it a main (to humor it - it's not a solution), then it links and produces an executable - so it looks to me like I'm not telling the linker what I want correctly? Any ideas? Cheers, Phil. ghc -O2 --make -no-hs-main -package mtl -package array -optl '- shared' FFI/Octave/MyInterface.c FFI/Octave/OptionInterface_stub.o FFI/ Octave/OptionInterface.o ./FrameworkInterface.o ./Maths/Prime.o ./ MonteCarlo/DataStructures.o ./MonteCarlo/European.o ./MonteCarlo/ Framework.o ./MonteCarlo/Interface.o ./MonteCarlo/Lookback.o ./Normal/ Acklam.o ./Normal/BoxMuller.o ./Normal/Framework.o ./Normal/ Interface.o ./Random/Framework.o ./Random/Halton.o ./Random/ Interface.o ./Random/Ranq1.o -o FFI/Octave/libMyInterface.so Linking FFI/Octave/libMyInterface.so ... Undefined symbols: "___stginit_ZCMain", referenced from: ___stginit_ZCMain$non_lazy_ptr in libHSrts.a(Main.o) "_ZCMain_main_closure", referenced from: _ZCMain_main_closure$non_lazy_ptr in libHSrts.a(Main.o) ld: symbol(s) not found collect2: ld returned 1 exit status From ryani.spam at gmail.com Tue Aug 25 22:45:30 2009 From: ryani.spam at gmail.com (Ryan Ingram) Date: Tue Aug 25 22:25:14 2009 Subject: [Haskell-cafe] Is it possible to prove type *non*-equality in Haskell? In-Reply-To: <200908251839.06581.dan.doel@gmail.com> References: <2f9b2d30908251503v42ac7052qd6dd93e1443e44bd@mail.gmail.com> <200908251839.06581.dan.doel@gmail.com> Message-ID: <2f9b2d30908251945i1eacb81bye78e53236670b4f6@mail.gmail.com> Hi Dan, thanks for the great reply! Some thoughts/questions follow. On Tue, Aug 25, 2009 at 3:39 PM, Dan Doel wrote: > Well, this isn't surprising; you wouldn't have it even in a more rigorous > proof environment. Instead, you'd have to make the return type something like > > ?Either (a == b) (a /= b) Yes, and as you see I immediately headed in that direction :) >> We know by parametricity that "contradiction n p" isn't inhabited as >> its type is (forall a. a) > > But in Haskell, we know that it _is_ inhabited, because every type is > inhabited by bottom. And one way to access this element is with undefined. Of course. But it is uninhabited in the sense that if you case analyze on it, you're guaranteed not to reach the RHS of the case. Which is as close to "uninhabited" as you get in Haskell. > Well, matching against TEq is not going to work. The way you do this in Agda, > for instance, is: > > ?notZeqS :: forall n -> Not (TEq Z (S n)) > ?notZeqS = Contr (\()) Yes, I had seen Agda's notation for this and I think it is quite elegant. Perhaps {} as a pattern in Haskell as an extension? I'm happy if it desugars into (\x -> x `seq` undefined) after the typechecker proves that x is uninhabited except by _|_. (This guarantees that "undefined" never gets evaluated and any exception/infinite loop happens inside of x.) In fact, I would be happy if there was a way to localize the call to "error" to a single location, which could then be the center of a trusted kernel of logic functions for inequality. But right now it seems that I need to make a separate "notEq" for each pair of concrete types, which isn't really acceptable to me. Can you think of any way to do so? Basically what I want is this function: notEq :: (compiler can prove a ~ b is unsound) => Not (TEq a b) Sadly, I think you are right that there isn't a way to write this in current GHC. -- ryan From dsouza at bitforest.org Tue Aug 25 23:19:01 2009 From: dsouza at bitforest.org (Diego Souza) Date: Tue Aug 25 23:02:24 2009 Subject: [Haskell-cafe] oauth in haskell - reviewers? In-Reply-To: <20090824225422.GA28522@clockdistance.saopaulo.corp.yahoo.com> References: <20090822233654.GA16495@mephisto.bitforest.org> <57526e770908222008o25780147ve211a8279dc82f56@mail.gmail.com> <20090823162555.GA4190@mephisto.bitforest.org> <71fd12e60908241356n70525f9ep6a3d32ca28505091@mail.gmail.com> <20090824212409.GI28658@whirlpool.galois.com> <20090824225422.GA28522@clockdistance.saopaulo.corp.yahoo.com> Message-ID: <20090826031901.GA3875@mephisto.bitforest.org> I've found [obviously] a huge thread about licensing on haskell-cafe@. After reading [most] of it, I realized the best thing to do is change the license and start using BSD3. -- ~dsouza yahoo!im: paravinicius gpg key fingerprint: 71B8 CE21 3A6E F894 5B1B 9ECE F88E 067F E891 651E From porges at porg.es Wed Aug 26 00:29:47 2009 From: porges at porg.es (George Pollard) Date: Wed Aug 26 00:09:30 2009 Subject: [Haskell-cafe] How to calculate de number of digits of an integer? (was: Is logBase right?) In-Reply-To: References: Message-ID: <6d942a4a0908252129n1fa82e23y11dba95b5ac37140@mail.gmail.com> You could also fudge the input: {-# LANGUAGE NoMonomorphismRestriction #-} log10 = floor . logBase 10 . (0.5+) . fromIntegral numDigits n | n < 0 = 1 + numDigits (-n) numDigits 0 = 1 numDigits n = 1 + log10 n -- checked [0..10^8], finding a counter-example is left as an exercise :P From bugfact at gmail.com Wed Aug 26 05:30:02 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 26 05:09:49 2009 Subject: [Haskell-cafe] haddock: parse error in doc string In-Reply-To: References: Message-ID: Ouch, with all the great Haskell parsers like Parsec around I think I was expecting a line/column number :-) But I see a ticket is already open for this http://trac.haskell.org/haddock/ticket/83 On Wed, Aug 26, 2009 at 2:47 AM, Gwern Branwen wrote: > On Tue, Aug 25, 2009 at 8:30 PM, Peter Verswyvelen > wrote: > > I'm getting the error mentioned in the subject, but without any > indication > > where in my file this error occurs. > > What does this mean? > > Thanks, > > Peter > > It means exactly that - something in that file's comments is causing > Haddock to choke. It could be using '*' inside some --s, it could be > something else. Haddock won't really say. Your best bet is the old > bisect/binary-search method: remove half the comments & retry, > narrowing it down until you've found the offending line and then > character. Then you can either remove it or read the Haddock manual > and see what the right thing looks like. > > -- > gwern > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090826/2a555ee4/attachment.html From daniel.is.fischer at web.de Wed Aug 26 05:46:28 2009 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Wed Aug 26 05:27:11 2009 Subject: [Haskell-cafe] How to calculate de number of digits of an integer? (was: Is logBase right?) In-Reply-To: <6d942a4a0908252129n1fa82e23y11dba95b5ac37140@mail.gmail.com> References: <6d942a4a0908252129n1fa82e23y11dba95b5ac37140@mail.gmail.com> Message-ID: <200908261146.28732.daniel.is.fischer@web.de> Am Mittwoch 26 August 2009 06:29:47 schrieb George Pollard: > You could also fudge the input: > > {-# LANGUAGE NoMonomorphismRestriction #-} > > log10 = floor . logBase 10 . (0.5+) . fromIntegral > > numDigits n | n < 0 = 1 + numDigits (-n) > numDigits 0 = 1 > numDigits n = 1 + log10 n > > -- checked [0..10^8], finding a counter-example is left as an exercise :P Prelude> numDigits (10^15) 15 From bugfact at gmail.com Wed Aug 26 06:15:14 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 26 05:54:59 2009 Subject: [Haskell-cafe] Suggestion: define a standard keyboard codes library? Message-ID: Several libraries define their own codes for they keyboard (GLFW, GTK, GLUT, etc) Maybe it would be nice to agree on a standard datatype for keys? This might also include digital buttons on a joystick, etc... The Windows API has virtual key codes for this. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090826/d93efa5e/attachment.html From gale at sefer.org Wed Aug 26 06:42:11 2009 From: gale at sefer.org (Yitzchak Gale) Date: Wed Aug 26 06:22:18 2009 Subject: [Haskell-cafe] Suggestion: define a standard keyboard codes library? In-Reply-To: References: Message-ID: <2608b8a80908260342v26a7a1eds89e6a0bb28c328e3@mail.gmail.com> Peter Verswyvelen wrote: > Several libraries define their own codes for they keyboard (GLFW, GTK, GLUT, > etc) > Maybe it would be nice to agree on a standard datatype for keys? This might > also include digital buttons on a joystick, etc... > The Windows API has virtual key codes for this. X windows key symbols are used extensively in XMonad. They are found in the X11 package, in the modules Graphics.X11.Types and Graphics.X11.ExtraTypes. -Yitz From bugfact at gmail.com Wed Aug 26 06:47:39 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 26 06:27:23 2009 Subject: [Haskell-cafe] Suggestion: define a standard keyboard codes library? In-Reply-To: <2608b8a80908260342v26a7a1eds89e6a0bb28c328e3@mail.gmail.com> References: <2608b8a80908260342v26a7a1eds89e6a0bb28c328e3@mail.gmail.com> Message-ID: But should we use X11 as the standard library then, even on Windows or Mac? It surely is better than nothing, but it feels a bit weird to install X11 just for using the key codes. Maybe splitting these keys into a separate package would be a good idea? On Wed, Aug 26, 2009 at 12:42 PM, Yitzchak Gale wrote: > Peter Verswyvelen wrote: > > Several libraries define their own codes for they keyboard (GLFW, GTK, > GLUT, > > etc) > > Maybe it would be nice to agree on a standard datatype for keys? This > might > > also include digital buttons on a joystick, etc... > > The Windows API has virtual key codes for this. > > X windows key symbols are used extensively in XMonad. > They are found in the X11 package, in the modules > Graphics.X11.Types and Graphics.X11.ExtraTypes. > > -Yitz > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090826/944d8511/attachment.html From david.waern at gmail.com Wed Aug 26 07:04:15 2009 From: david.waern at gmail.com (David Waern) Date: Wed Aug 26 06:43:58 2009 Subject: [Haskell-cafe] haddock: parse error in doc string In-Reply-To: References: Message-ID: 2009/8/26 Peter Verswyvelen : > Ouch, with all the great Haskell parsers like Parsec around I think I was > expecting a line/column number :-) > But I see a ticket is?already?open for this > http://trac.haskell.org/haddock/ticket/83 Yes, and the line-number part of that ticket has been fixed in 2.4.2 and higher versions. So the best idea is to upgrade Haddock. David From bugfact at gmail.com Wed Aug 26 07:06:17 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 26 06:46:01 2009 Subject: [Haskell-cafe] haddock: parse error in doc string In-Reply-To: References: Message-ID: Oh, I just installed the Haskell platform. I have Haddock version 2.4.2, (c) Simon Marlow 2006 Ported to use the GHC API by David Waern 2006-2008 But I noticed that my bad comments were in the description of the cabal file, not the source file. So that might be a new ticket? On Wed, Aug 26, 2009 at 1:04 PM, David Waern wrote: > 2009/8/26 Peter Verswyvelen : > > Ouch, with all the great Haskell parsers like Parsec around I think I was > > expecting a line/column number :-) > > But I see a ticket is already open for this > > http://trac.haskell.org/haddock/ticket/83 > > Yes, and the line-number part of that ticket has been fixed in 2.4.2 > and higher versions. So the best idea is to upgrade Haddock. > > David > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090826/da802b43/attachment.html From porges at porg.es Wed Aug 26 07:22:58 2009 From: porges at porg.es (George Pollard) Date: Wed Aug 26 07:02:40 2009 Subject: [Haskell-cafe] How to calculate de number of digits of an integer? (was: Is logBase right?) In-Reply-To: References: <6d942a4a0908252129n1fa82e23y11dba95b5ac37140@mail.gmail.com> Message-ID: <6d942a4a0908260422v1a2715w5886c06a45e20c67@mail.gmail.com> 2009/8/26 Lennart Augustsson : > Try 10^1000 Cheat :) From gale at sefer.org Wed Aug 26 07:31:03 2009 From: gale at sefer.org (Yitzchak Gale) Date: Wed Aug 26 07:11:05 2009 Subject: [Haskell-cafe] Suggestion: define a standard keyboard codes library? In-Reply-To: References: <2608b8a80908260342v26a7a1eds89e6a0bb28c328e3@mail.gmail.com> Message-ID: <2608b8a80908260431m54f84dd7l511156d4ac981180@mail.gmail.com> Peter Verswyvelen wrote: >>> Several libraries define their own codes for they keyboard >>> (GLFW, GTK, GLUT, etc) >>> Maybe it would be nice to agree on a standard datatype >>> for keys? >>> ...The Windows API has virtual key codes for this. I wrote: >> X windows key symbols... >> are found in the X11 package > But should we use X11 as the standard library then, > even on Windows or Mac? Certainly not. X11 has its own philosophy of key virtualization. You would likely encounter serious impedance mismatch on other platforms. > Maybe splitting these keys into a separate package would > be a good idea? No, they are an integral part of X. I would assume the same is true for WinAPI VKeys, and whatever the corresponding thing is on the Mac. That probably explains why each graphics framework defines its own concept of key mapping, to match its own concept of platform dependence. Here's an example: suppose you want ^C to be "copy" in your app. Well, what if the user currently has a Dvorak layout - do you really want ^C, or do you want the third physical key to the right of the left shift key? And what if the current keyboard layout is Russian - which Cyrillic letter should be "copy"? And what if we happen to be on a mobile device or a tablet? Etc. Each platform addresses these issues in its own way, so the concept of a "key code" doesn't necessarily translate directly from one to the other. I don't think that key binding is so complicated that it's impossible to come up with a reasonable "one ring that binds them all" library. But it's not so simple as just lining up key code charts with one another. -Yitz From conor at strictlypositive.org Wed Aug 26 09:33:00 2009 From: conor at strictlypositive.org (Conor McBride) Date: Wed Aug 26 09:12:58 2009 Subject: [Haskell-cafe] Is it possible to prove type *non*-equality in Haskell? In-Reply-To: <2f9b2d30908251945i1eacb81bye78e53236670b4f6@mail.gmail.com> References: <2f9b2d30908251503v42ac7052qd6dd93e1443e44bd@mail.gmail.com> <200908251839.06581.dan.doel@gmail.com> <2f9b2d30908251945i1eacb81bye78e53236670b4f6@mail.gmail.com> Message-ID: <453D97EB-6026-4993-8418-0ADE9F5DF2E6@strictlypositive.org> Hi all Interesting stuff. Thanks for this. On 26 Aug 2009, at 03:45, Ryan Ingram wrote: > Hi Dan, thanks for the great reply! Some thoughts/questions follow. > > On Tue, Aug 25, 2009 at 3:39 PM, Dan Doel wrote: >> Well, this isn't surprising; you wouldn't have it even in a more >> rigorous >> proof environment. Instead, you'd have to make the return type >> something like >> >> Either (a == b) (a /= b) > > Yes, and as you see I immediately headed in that direction :) > >>> We know by parametricity that "contradiction n p" isn't inhabited as >>> its type is (forall a. a) >> >> But in Haskell, we know that it _is_ inhabited, because every type is >> inhabited by bottom. And one way to access this element is with >> undefined. > > Of course. But it is uninhabited in the sense that if you case > analyze on it, you're guaranteed not to reach the RHS of the case. > Which is as close to "uninhabited" as you get in Haskell. I think that's close enough to make "uninhabited" a useful shorthand. >> Well, matching against TEq is not going to work. The way you do >> this in Agda, >> for instance, is: >> >> notZeqS :: forall n -> Not (TEq Z (S n)) >> notZeqS = Contr (\()) > > Yes, I had seen Agda's notation for this and I think it is quite > elegant. Perhaps {} as a pattern in Haskell as an extension? Something of the sort has certainly been suggested before. At the very least, we should have empty case expressions, with at least a warning generated when there is a constructor case apparently possible. [..] > But right now it > seems that I need to make a separate "notEq" for each pair of concrete > types, which isn't really acceptable to me. > > Can you think of any way to do so? I think it's likely to be quite tricky, but you might be able to minimize the burden by adapting an old trick (see my thesis, or "Eliminating Dependent Pattern Matching" by Goguen, McBride, McKinna, or "A Few Constructions on Constructors" by the same authors). > Basically what I want is this function: > notEq :: (compiler can prove a ~ b is unsound) => Not (TEq a b) > > Sadly, I think you are right that there isn't a way to write this in > current GHC. Perhaps it's not exactly what you want, but check this out. I've used SHE, but I'll supply the translation so you know there's no cheating. > {-# OPTIONS_GHC -F -pgmF she #-} > {-# LANGUAGE GADTs, KindSignatures, TypeOperators, TypeFamilies, FlexibleContexts, > MultiParamTypeClasses, UndecidableInstances, RankNTypes, > EmptyDataDecls #-} > module NoConfusion where Some type theorists call the fact that constructors are injective and disjoint the "no confusion" property, and the fact (?) that they cover the datatype the "no junk" property. In Haskell, junk there is, but there is strictly no junk. > import ShePrelude > data Nat :: * where > Z :: Nat > S :: Nat -> Nat > deriving SheSingleton The "deriving SheSingleton" bit makes the preprocessor build the singleton GADT for Nat. From ShePrelude we have type family SheSingleton ty :: * -> * and from the above, we get data SheTyZ = SheTyZ data SheTyS x1 = SheTyS x1 type instance SheSingleton (Nat) = SheSingNat data SheSingNat :: * -> * where SheWitZ :: SheSingNat (SheTyZ) SheWitS :: forall sha0. SheSingleton (Nat ) sha0 -> SheSingNat (SheTyS sha0) Now, let's have > newtype Naught = Naught {naughtE :: forall a. a} Thanks to Dave Menendez for suggesting this coding of the empty type. > data EQ :: forall (a :: *). {a} -> {a} -> * where > Refl :: EQ a a It may look like I've given EQ a polykind, but after translation, the forall vanishes and the {a}s become *s. My EQ is just the usual thing in * -> * -> *. OK, here's the trick I learned from Healf Goguen one day in 1997. Define a type-level function which explains the consequences of knowing that two numbers are equal. > type family WhatNatEQProves (m :: {Nat})(n :: {Nat}) :: * > type instance WhatNatEQProves {Z} {Z} = () > type instance WhatNatEQProves {Z} {S n} = Naught > type instance WhatNatEQProves {S m} {Z} = Naught > type instance WhatNatEQProves {S m} {S n} = EQ m n Those type-level {Z} and {S n} guys just translate to SheTyZ and (SheTyS n), respectively. Now, here's the proof I learned from James McKinna, ten minutes later. > noConf :: pi (m :: Nat). pi (n :: Nat). EQ m n -> WhatNatEQProves m n > noConf m n Refl = noConfDiag m > noConfDiag :: pi (n :: Nat). WhatNatEQProves n n > noConfDiag {Z} = () > noConfDiag {S n} = Refl This pi (n :: Nat). ... is translated to forall n. SheSingleton Nat n -> ... which computes to forall n. SheSingNat n -> ... The expression-level {Z} and {S n} translate to SheWitZ and (SheWitS n), accessing the singleton family. Preprocessed, we get noConf :: forall m . SheSingleton ( Nat) m -> forall n . SheSingleton ( Nat) n -> EQ m n -> WhatNatEQProves m n noConf m n Refl = noConfDiag m noConfDiag :: forall n . SheSingleton ( Nat) n -> WhatNatEQProves n n noConfDiag (SheWitZ) = () noConfDiag (SheWitS n) = Refl James's cunning idea was to match on the equation first, so that we need only consider the diagonal cases where there is genuine work to do. If this looks like a nuisance, compared to exploiting unification on types, it is! It's how I showed that the type-unification approach to pattern matching with GADTs could be explained in terms of case analysis operators like the ones Ryan likes to define. So yes, it would be nice to have a neater way to refute falsehood which says "this really can't happen" rather than "this merely shouldn't happen". But this is not an example which necessitates that feature. All the best Conor From marco-oweber at gmx.de Wed Aug 26 09:34:43 2009 From: marco-oweber at gmx.de (Marc Weber) Date: Wed Aug 26 09:14:28 2009 Subject: [Haskell-cafe] Suggestion: define a standard keyboard codes library? In-Reply-To: References: Message-ID: <1251293586-sup-7500@nixos> Excerpts from Peter Verswyvelen's message of Wed Aug 26 12:15:14 +0200 2009: > Maybe it would be nice to agree on a standard datatype for keys? This might > also include digital buttons on a joystick, etc... The synergy project (sourceforge) already does some mapping from Windows <-> Linux <-> Mac AFAIK. It forwards key input to the other system over network. This could be a source of additional information. However I haven't looked at the code yet. Sincerly Marc Weber From kolar at fit.vutbr.cz Wed Aug 26 09:49:36 2009 From: kolar at fit.vutbr.cz (Dusan Kolar) Date: Wed Aug 26 09:29:19 2009 Subject: [Haskell-cafe] Error during hlint install ? Message-ID: <4A953D70.30106@fit.vutbr.cz> Hello all, Am I doing something wrong if I get the following error during cabal installation of hlint? Is there any way how to solve it? I run on: Linux pc 2.6.30-ARCH #1 SMP PREEMPT Fri Jul 31 07:30:28 CEST 2009 x86_64 Intel(R) Core(TM)2 Quad CPU Q9300 @ 2.50GHz GenuineIntel GNU/Linux The Glorious Glasgow Haskell Compilation System, version 6.10.4 Error: cabal install hlint Resolving dependencies... Configuring hlint-1.6.5... Preprocessing executables for hlint-1.6.5... Building hlint-1.6.5... [ 1 of 25] Compiling Paths_hlint ( dist/build/autogen/Paths_hlint.hs, dist/build/hlint/hlint-tmp/Paths_hlint.o ) [ 2 of 25] Compiling Parallel ( src/Parallel.hs, dist/build/hlint/hlint-tmp/Parallel.o ) [ 3 of 25] Compiling HSE.Generics ( src/HSE/Generics.hs, dist/build/hlint/hlint-tmp/HSE/Generics.o ) [ 4 of 25] Compiling HSE.NameMatch ( src/HSE/NameMatch.hs, dist/build/hlint/hlint-tmp/HSE/NameMatch.o ) [ 5 of 25] Compiling Util ( src/Util.hs, dist/build/hlint/hlint-tmp/Util.o ) [ 6 of 25] Compiling HSE.Util ( src/HSE/Util.hs, dist/build/hlint/hlint-tmp/HSE/Util.o ) [ 7 of 25] Compiling HSE.Match ( src/HSE/Match.hs, dist/build/hlint/hlint-tmp/HSE/Match.o ) [ 8 of 25] Compiling HSE.Bracket ( src/HSE/Bracket.hs, dist/build/hlint/hlint-tmp/HSE/Bracket.o ) [ 9 of 25] Compiling HSE.Evaluate ( src/HSE/Evaluate.hs, dist/build/hlint/hlint-tmp/HSE/Evaluate.o ) [10 of 25] Compiling HSE.All ( src/HSE/All.hs, dist/build/hlint/hlint-tmp/HSE/All.o ) [11 of 25] Compiling CmdLine ( src/CmdLine.hs, dist/build/hlint/hlint-tmp/CmdLine.o ) [12 of 25] Compiling Type ( src/Type.hs, dist/build/hlint/hlint-tmp/Type.o ) [13 of 25] Compiling Hint.Naming ( src/Hint/Naming.hs, dist/build/hlint/hlint-tmp/Hint/Naming.o ) [14 of 25] Compiling Hint.Bracket ( src/Hint/Bracket.hs, dist/build/hlint/hlint-tmp/Hint/Bracket.o ) [15 of 25] Compiling Hint.Lambda ( src/Hint/Lambda.hs, dist/build/hlint/hlint-tmp/Hint/Lambda.o ) [16 of 25] Compiling Hint.Monad ( src/Hint/Monad.hs, dist/build/hlint/hlint-tmp/Hint/Monad.o ) [17 of 25] Compiling Hint.ListRec ( src/Hint/ListRec.hs, dist/build/hlint/hlint-tmp/Hint/ListRec.o ) [18 of 25] Compiling Hint.List ( src/Hint/List.hs, dist/build/hlint/hlint-tmp/Hint/List.o ) [19 of 25] Compiling Hint.Match ( src/Hint/Match.hs, dist/build/hlint/hlint-tmp/Hint/Match.o ) [20 of 25] Compiling Settings ( src/Settings.hs, dist/build/hlint/hlint-tmp/Settings.o ) [21 of 25] Compiling Report ( src/Report.hs, dist/build/hlint/hlint-tmp/Report.o ) src/Report.hs:49:22: Couldn't match expected type `String' against inferred type `Bool' In the second argument of `hscolour', namely `True' In the expression: hscolour False True "" In the definition of `code': code = hscolour False True "" cabal: Error: some packages failed to install: hlint-1.6.5 failed during the building phase. The exception was: exit: ExitFailure 1 Regards Du?an P.S. Registered packages: Cabal-1.6.0.3, HUnit-1.2.0.3, QuickCheck-1.2.0.0, array-0.2.0.0, base-3.0.3.1, base-4.1.0.0, bytestring-0.9.1.4, containers-0.2.0.1, cpphs-1.8, directory-1.0.0.3, (dph-base-0.3), (dph-par-0.3), (dph-prim-interface-0.3), (dph-prim-par-0.3), (dph-prim-seq-0.3), (dph-seq-0.3), extensible-exceptions-0.1.1.0, filepath-1.1.0.2, (ghc-6.10.4), ghc-prim-0.1.0.0, haddock-2.4.2, haskell-src-1.0.1.3, haskell-src-exts-1.0.1, haskell98-1.0.1.0, hpc-0.5.0.3, hscolour-1.15, html-1.0.1.2, integer-0.1.0.1, mtl-1.1.0.2, network-2.2.1.2, old-locale-1.0.0.1, old-time-1.0.0.2, packedstring-0.1.0.1, parallel-1.1.0.1, parsec-2.1.0.1, pretty-1.0.1.0, process-1.0.1.1, random-1.0.0.1, regex-base-0.72.0.2, regex-compat-0.71.0.1, regex-posix-0.72.0.3, rts-1.0, stm-2.1.1.2, syb-0.1.0.1, template-haskell-2.3.0.1, time-1.1.4, uniplate-1.2.0.3, unix-2.3.2.0, xhtml-3000.2.0.1 From uhollerbach at gmail.com Wed Aug 26 10:42:06 2009 From: uhollerbach at gmail.com (Uwe Hollerbach) Date: Wed Aug 26 10:21:50 2009 Subject: [Haskell-cafe] How to calculate de number of digits of an integer? (was: Is logBase right?) In-Reply-To: <200908261146.28732.daniel.is.fischer@web.de> References: <6d942a4a0908252129n1fa82e23y11dba95b5ac37140@mail.gmail.com> <200908261146.28732.daniel.is.fischer@web.de> Message-ID: <65d7a7e0908260742t56fa14ffp958cd9824f3c81e2@mail.gmail.com> Here's my version... maybe not as elegant as some, but it seems to work. For base 2 (or 2^k), it's probably possible to make this even more efficient by just walking along the integer as stored in memory, but that difference probably won't show up until at least tens of thousands of digits. Uwe ilogb :: Integer -> Integer -> Integer ilogb b n | n < 0 = ilogb b (- n) | n < b = 0 | otherwise = (up 1) - 1 where up a = if n < (b ^ a) then bin (quot a 2) a else up (2*a) bin lo hi = if (hi - lo) <= 1 then hi else let av = quot (lo + hi) 2 in if n < (b ^ av) then bin lo av else bin av hi numDigits n = 1 + ilogb 10 n [fire up ghci, load, etc] *Main> numDigits (10^1500 - 1) 1500 *Main> numDigits (10^1500) 1501 From jeremy at n-heptane.com Wed Aug 26 11:20:03 2009 From: jeremy at n-heptane.com (Jeremy Shaw) Date: Wed Aug 26 10:59:48 2009 Subject: [Haskell-cafe] Applicative and Monad transformers Message-ID: <87eiqyzjoc.wl%jeremy@n-heptane.com> Hello, I have seen it said that all Monads are Applicative Functors because you can just do: instance (Monad f, Applicative f) => Applicative (ReaderT r f) where pure = return (<*>) = ap However, that instance for ReaderT does not exhibit the properties I was hoping for. By substitution the definition of ap: ap :: (Monad m) => m (a -> b) -> m a -> m b ap = liftM2 id liftM2 :: (Monad m) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r liftM2 f m1 m2 = do { x1 <- m1; x2 <- m2; return (f x1 x2) } we see that it becomes: instance (Monad f, Applicative f) => Applicative (ReaderT r f) where pure = return f <*> x = do { f' <- f; x' <- x; return (f' x') } What I would prefer is: instance (Monad f, Applicative f) => Applicative (ReaderT r f) where pure a = ReaderT $ const (pure a) f <*> a = ReaderT $ \r -> ((runReaderT f r) <*> (runReaderT a r)) I assume that only one version is correct, but I am having a hard time figuring out which one. I have attached a file which shows my motivation for prefering the second variation. There is a 'looker' function which does three lookups and combines the results using the Applicative Functor. With the first Applicative instance for ReaderT you will only get a failure message for the first lookup that fails -- which is what you expect with monadic behaviour. With the second instance, you get back a list of all the lookups that failed, which seems like what I would expect with Applicative Functor behaviour. Thanks! - jeremy -------------- next part -------------- {-# LANGUAGE FlexibleContexts, FlexibleInstances #-} module Main where import Control.Applicative (Applicative((<*>), pure), (<$>)) import Control.Monad (Monad((>>=), return), ap) import Control.Monad.Reader (MonadReader(ask, local), ReaderT(ReaderT, runReaderT)) import Data.Monoid(Monoid(mappend)) instance (Monad f, Applicative f) => Applicative (ReaderT r f) where pure = return (<*>) = ap {- instance (Monad f, Applicative f) => Applicative (ReaderT r f) where pure a = ReaderT $ const (pure a) f <*> a = ReaderT $ \r -> ((runReaderT f r) <*> (runReaderT a r)) -} instance (Monoid e) => Applicative (Either e) where pure = Right (Left errF) <*> (Left errA) = Left (errF `mappend` errA) (Left err) <*> _ = Left err _ <*> (Left err) = Left err (Right f) <*> (Right a) = Right (f a) instance Monad (Either [String]) where return = Right (Right a) >>= f = f a (Left e) >>= f = (Left e) fail str = Left [str] lookupE :: (Eq a) => a -> [(a,b)] -> (Either a b) lookupE a env = case lookup a env of Just b -> Right b Nothing -> Left a look :: String -> ReaderT [(String,b)] (Either [String]) b look a = do env <- ask case lookup a env of Just b -> return b Nothing -> fail a looker :: ReaderT [(String, Int)] (Either [String]) (Int, Int, Int) looker = ((,,) <$> look "foo" <*> look "bar" <*> look "baz") test :: Either [String] (Int, Int, Int) test = runReaderT looker [("bar", 1)] -------------- next part -------------- From jeremy at n-heptane.com Wed Aug 26 11:48:55 2009 From: jeremy at n-heptane.com (Jeremy Shaw) Date: Wed Aug 26 11:28:38 2009 Subject: [Haskell-cafe] Applicative and Monad transformers In-Reply-To: <87eiqyzjoc.wl%jeremy@n-heptane.com> References: <87eiqyzjoc.wl%jeremy@n-heptane.com> Message-ID: <87d46izic8.wl%jeremy@n-heptane.com> Attached is as slight better test example which does not rely on the 'fail' method. Doesn't really change anything significant though. -------------- next part -------------- {-# LANGUAGE FlexibleContexts, FlexibleInstances #-} module Main where import Control.Applicative (Applicative((<*>), pure), (<$>)) import Control.Monad (Monad((>>=), return), ap) import Control.Monad.Reader (MonadReader(ask, local), ReaderT(ReaderT, runReaderT), mapReaderT) import Data.Monoid(Monoid(mappend)) {- instance (Monad f, Applicative f) => Applicative (ReaderT r f) where pure = return (<*>) = ap -} instance (Monad f, Applicative f) => Applicative (ReaderT r f) where pure a = ReaderT $ const (pure a) f <*> a = ReaderT $ \r -> ((runReaderT f r) <*> (runReaderT a r)) instance (Monoid e) => Applicative (Either e) where pure = Right (Left errF) <*> (Left errA) = Left (errF `mappend` errA) (Left err) <*> _ = Left err _ <*> (Left err) = Left err (Right f) <*> (Right a) = Right (f a) instance Monad (Either e) where return = Right (Right a) >>= f = f a (Left e) >>= f = (Left e) -- fail str = Left [str] lookupE :: (Eq a) => a -> [(a,b)] -> (Either a b) lookupE a env = case lookup a env of Just b -> Right b Nothing -> Left a look :: (Eq a) => a -> ReaderT [(a,b)] (Either [a]) b look a = do env <- ask case lookup a env of (Just b) -> return b Nothing -> asLeft a asLeft :: a -> ReaderT r (Either [a]) b asLeft a = mapReaderT (\m -> case m of (Left as) -> Left (a:as) (Right _) -> Left [a]) (return ()) looker :: ReaderT [(String, Int)] (Either [String]) (Int, Int, Int) looker = ((,,) <$> look "foo" <*> look "bar" <*> look "baz") test :: Either [String] (Int, Int, Int) test = runReaderT looker [("bar", 1)] From martijn at van.steenbergen.nl Wed Aug 26 12:04:44 2009 From: martijn at van.steenbergen.nl (Martijn van Steenbergen) Date: Wed Aug 26 11:44:30 2009 Subject: [Haskell-cafe] Applicative and Monad transformers In-Reply-To: <87eiqyzjoc.wl%jeremy@n-heptane.com> References: <87eiqyzjoc.wl%jeremy@n-heptane.com> Message-ID: <4A955D1C.40605@van.steenbergen.nl> Jeremy Shaw wrote: > What I would prefer is: > > instance (Monad f, Applicative f) => Applicative (ReaderT r f) where > pure a = ReaderT $ const (pure a) > f <*> a = ReaderT $ \r -> > ((runReaderT f r) <*> (runReaderT a r)) Right. This doesn't only go for ReaderT, it already goes for Either, too: you don't want the 'ap' implementation for <*> there either. These are beautiful examples of how applicative style gives the caller less power, but the callee more information, allowing more information to be retained. In this case it allows you to concatenate errors using mappend. Another example is parsing: I believe Doaitse's parsers allow more optimization if they are only used in applicative style (but I'm not sure of this). This shows there can be several sensible implementations of a type class. You ask which instance is right--that depends entirely on what you want it to do! Setting (<*>) = ap is just one of them, one you happen to get for free if your functor is already a monad. Hope this helps, Martijn. From haskellmail at gmail.com Wed Aug 26 12:33:24 2009 From: haskellmail at gmail.com (kenny lu) Date: Wed Aug 26 12:13:07 2009 Subject: [Haskell-cafe] Network.Socket error in MacOS 10.5? Message-ID: <90bba1dc0908260933k10c28c21g5553e54f70ba0bc6@mail.gmail.com> Hi, I encountered a problem with Network.Socket in MacOS 10.5 Here is the code that I am testing, ----------------------------------------- ----------------------------------------- module Main where import qualified Network.Socket as Socket main :: IO () main = do { (hostname, _) <- Socket.getNameInfo [] True False (Socket.SockAddrUnix "localhost") -- (hostname, _) <- Socket.getNameInfo [] True False (Socket.SockAddrInet 9000 (127 + 0 * 256 + 0 * 256^2 + 1 * 256^3)) ; putStrLn (show hostname) } Running the above code yields the following error ghc --make -O2 TestSocket.hs [1 of 1] Compiling Main ( TestSocket.hs, TestSocket.o ) Linking TestSocket ... $ ./TestSocket TestSocket: getNameInfo: does not exist (ai_family not supported) If I switch to SockAddrInet instead, the error is gone. I am using GHC 6.10.3 and Network 2.2.1 Regards, Kenny -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090826/22607be6/attachment.html From ekmett at gmail.com Wed Aug 26 13:20:31 2009 From: ekmett at gmail.com (Edward Kmett) Date: Wed Aug 26 13:00:13 2009 Subject: [Haskell-cafe] Applicative and Monad transformers In-Reply-To: <4A955D1C.40605@van.steenbergen.nl> References: <87eiqyzjoc.wl%jeremy@n-heptane.com> <4A955D1C.40605@van.steenbergen.nl> Message-ID: <7fb8f82f0908261020i4c802930obb9153a023afad4b@mail.gmail.com> On Wed, Aug 26, 2009 at 12:04 PM, Martijn van Steenbergen < martijn@van.steenbergen.nl> wrote: > > Another example is parsing: I believe Doaitse's parsers allow more > optimization if they are only used in applicative style (but I'm not sure of > this). > That is correct. When you glue together P_m's applicatively the applicative P_f 'future' parser can be used, but when you use it monadically the context sensitive parts are glued together using the monadic P_h 'history' parser. -Edward Kmett -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090826/72c699d4/attachment.html From bugfact at gmail.com Wed Aug 26 13:47:38 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Wed Aug 26 13:27:20 2009 Subject: [Haskell-cafe] Suggestion: define a standard keyboard codes library? In-Reply-To: <1251293586-sup-7500@nixos> References: <1251293586-sup-7500@nixos> Message-ID: I would already be happy with a low level library that holds the union of all keys, assigning them unique codes. So you would have keys like Apple, Amiga, Windows, Start, Popup, LeftControl, RightControl, etc... No mapping is done at the low level. Then one would need an OS dependent interface to figure out which keys are available. Which keyboard bindings (like CTRL+C or CTRL+INSERT) are assigned to which user interface commands is a high level binding, which in the perfect UI is configurable anyway, although the OS dependent interface should provide a lot of defaults (again different on each system) However I only have experience with Windows, Amiga, a bit of OSX and tiny bit of Linux, so I don't know all the details of all esoteric systems. For now I will just use the bindings in the GLFW package. On Wed, Aug 26, 2009 at 3:34 PM, Marc Weber wrote: > Excerpts from Peter Verswyvelen's message of Wed Aug 26 12:15:14 +0200 > 2009: > > Maybe it would be nice to agree on a standard datatype for keys? This > might > > also include digital buttons on a joystick, etc... > > The synergy project (sourceforge) already does some mapping from Windows > <-> Linux <-> Mac AFAIK. > > It forwards key input to the other system over network. > This could be a source of additional information. However I haven't > looked at the code yet. > > Sincerly > Marc Weber > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090826/51173f93/attachment.html From johan.tibell at gmail.com Wed Aug 26 14:07:39 2009 From: johan.tibell at gmail.com (Johan Tibell) Date: Wed Aug 26 13:47:40 2009 Subject: [Haskell-cafe] Network.Socket error in MacOS 10.5? In-Reply-To: <90bba1dc0908260933k10c28c21g5553e54f70ba0bc6@mail.gmail.com> References: <90bba1dc0908260933k10c28c21g5553e54f70ba0bc6@mail.gmail.com> Message-ID: <90889fe70908261107y61fa2042g499b082be1cb815c@mail.gmail.com> On Wed, Aug 26, 2009 at 6:33 PM, kenny lu wrote: > Hi, > > I encountered a problem with Network.Socket in MacOS 10.5 > Here is the code that I am testing, > > ----------------------------------------- > ----------------------------------------- > module Main where > > import qualified Network.Socket as Socket > > main :: IO () > main = > ??? do { (hostname, _) <- Socket.getNameInfo [] True False > (Socket.SockAddrUnix "localhost") > ?????? -- (hostname, _) <- Socket.getNameInfo [] True False > (Socket.SockAddrInet 9000? (127 + 0 * 256 + 0 * 256^2 + 1 * 256^3)) > ?????? ; putStrLn (show hostname) > ?????? } > > > Running the above code yields the following error > ghc --make -O2 TestSocket.hs > [1 of 1] Compiling Main???????????? ( TestSocket.hs, TestSocket.o ) > Linking TestSocket ... > $ ./TestSocket > TestSocket: getNameInfo: does not exist (ai_family not supported) > > If I switch to SockAddrInet instead, the error is gone. > > I am using GHC 6.10.3 and Network 2.2.1 Is SockAddrUnix supposed to work on Mac OS X? Could you test it by e.g. writing a small C program that uses it? -- Johan From rmm-haskell at z.odi.ac Wed Aug 26 14:20:03 2009 From: rmm-haskell at z.odi.ac (Ross Mellgren) Date: Wed Aug 26 13:59:47 2009 Subject: [Haskell-cafe] Network.Socket error in MacOS 10.5? In-Reply-To: <90889fe70908261107y61fa2042g499b082be1cb815c@mail.gmail.com> References: <90bba1dc0908260933k10c28c21g5553e54f70ba0bc6@mail.gmail.com> <90889fe70908261107y61fa2042g499b082be1cb815c@mail.gmail.com> Message-ID: <62991611-270F-46B4-B967-40980FF0B20A@z.odi.ac> I don't think getNameInfo should work for for AF_UNIX -- the name given to SockAddrUnix is a file path, there is no name resolution. From the man page for getnameinfo(3) on OS X: NAME getnameinfo -- socket address structure to hostname and service name ... DESCRIPTION ... The sockaddr structure sa should point to either a sockaddr_in or sockaddr_in6 structure (for IPv4 or IPv6 respectively) that is salen bytes long. Similarly, from the man page for getnameinfo on my linux box: ... The sa argument is a pointer to a generic socket address structure (of type sockaddr_in or sockaddr_in6) of size salen that holds the input IP address and port number. -Ross On Aug 26, 2009, at 2:07 PM, Johan Tibell wrote: > On Wed, Aug 26, 2009 at 6:33 PM, kenny lu > wrote: >> Hi, >> >> I encountered a problem with Network.Socket in MacOS 10.5 >> Here is the code that I am testing, >> >> ----------------------------------------- >> ----------------------------------------- >> module Main where >> >> import qualified Network.Socket as Socket >> >> main :: IO () >> main = >> do { (hostname, _) <- Socket.getNameInfo [] True False >> (Socket.SockAddrUnix "localhost") >> -- (hostname, _) <- Socket.getNameInfo [] True False >> (Socket.SockAddrInet 9000 (127 + 0 * 256 + 0 * 256^2 + 1 * 256^3)) >> ; putStrLn (show hostname) >> } >> >> >> Running the above code yields the following error >> ghc --make -O2 TestSocket.hs >> [1 of 1] Compiling Main ( TestSocket.hs, TestSocket.o ) >> Linking TestSocket ... >> $ ./TestSocket >> TestSocket: getNameInfo: does not exist (ai_family not supported) >> >> If I switch to SockAddrInet instead, the error is gone. >> >> I am using GHC 6.10.3 and Network 2.2.1 > > Is SockAddrUnix supposed to work on Mac OS X? Could you test it by > e.g. writing a small C program that uses it? > > -- Johan > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From byorgey at seas.upenn.edu Wed Aug 26 15:39:55 2009 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Wed Aug 26 15:19:38 2009 Subject: [Haskell-cafe] Re: [Hackathon] Edinburgh Meetup (Sat 29 Aug) and Hack Day (Sun 30 Aug) In-Reply-To: <20090814160359.GG26689@brighton.ac.uk> References: <20090814160359.GG26689@brighton.ac.uk> Message-ID: <20090826193955.GA26504@seas.upenn.edu> On Fri, Aug 14, 2009 at 05:04:00PM +0100, Eric Kow wrote: > Dear Haskellers, > > Just a quick reminder that we will be having a Hack Day in Edinburgh > on Sunday 30 August (ICFP venue). That's in two weeks! > > For the interested, we will also be meeting up the day before 09:30 > Saturday 29 August just outside the RCPE (ie. the ICFP venue again). > We'll have a quick wander and hopefully find some nice places to sit and > chat, whip out the occasional laptop and fling a lambda or not being > careful not to injure the passers-by. I'll be there Saturday morning---looking forward to meeting people! Also, I have purchased a ticket to hear a concert of some 16th-century a capella 16th-century music at the Canongate Kirk at 5pm on Saturday: http://www.edfringe.com/ticketing/detail.php?id=13649 Just thought I'd mention it, so if there's anyone else coming to the meetup day and 16th-century a capella sounds like your cup of tea, you can get a ticket too and we can go together. -Brent From david.waern at gmail.com Wed Aug 26 15:51:20 2009 From: david.waern at gmail.com (David Waern) Date: Wed Aug 26 15:31:02 2009 Subject: [Haskell-cafe] haddock: parse error in doc string In-Reply-To: References: Message-ID: 2009/8/26 Peter Verswyvelen : > Oh, I just installed the Haskell platform. > I have > Haddock version 2.4.2, (c) Simon Marlow 2006 > Ported to use the GHC API by David Waern 2006-2008 > But I noticed that my bad comments were in the description of the cabal > file, not the source file. > So that might be a new ticket? My guess is that Cabal passes the description via the --prologue flag and Haddock doesn't print which file it was passed. I'll fix this for the next release, you don't have to file a ticket. Thanks, David From nominolo at googlemail.com Wed Aug 26 18:50:53 2009 From: nominolo at googlemail.com (Thomas Schilling) Date: Wed Aug 26 18:30:44 2009 Subject: [Haskell-cafe] ANN: scion 0.1 Message-ID: Hello, I am pleased to announce the first release of Scion. Scion [1] is a Haskell library that aims to implement those parts of a Haskell IDE which are independent of a particular front-end. Scion is based on the GHC API and Cabal. It provides both a Haskell API and a server for non-Haskell clients such as Emacs and Vim. Scion is bundled with two front-ends, Emacs and Vim, and is used by the Haskell Eclipse plugin EclipseFP. Work on Yi support is underway. Scion's current features include: - Opening (that is, typechecking) a component of a Cabal project or a single file [Emacs, Vim]. Error messages are highlighted in the source [Emacs]. - Saving a file automatically typechecks the file [Emacs, Vim]. This feature can be turned off. - Look up the type of any identifier (even local variables) [Emacs, Vim]. Requires that the file typechecks. - Jump to definition of an identifier defined in the current project [Emacs]. For more details on the provided features and instructions of how to set up a particular front-end see the README [2]. Patches are always welcome. The main source repository is hosted on Github [3]. If you find a problem please file a bug [4] and/or join the developer's mailing list [5]. [1]: http://code.google.com/p/scion-lib/ [2]: http://github.com/nominolo/scion/blob/master/README.markdown [3]: http://github.com/nominolo/scion [4]: http://code.google.com/p/scion-lib/issues/list [5]: http://groups.google.com/group/scion-lib-devel Thanks ------ The following people contributed to patches to this release: Marc Weber Thomas ten Cate Sudish Joseph -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 194 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090826/9fdc2372/PGP.bin From byorgey at seas.upenn.edu Wed Aug 26 18:56:56 2009 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Wed Aug 26 18:36:37 2009 Subject: [Haskell-cafe] Haskell Weekly News: Issue 128 - August 26, 2009 Message-ID: <20090826225656.GA13785@seas.upenn.edu> --------------------------------------------------------------------------- Haskell Weekly News http://sequence.complete.org/hwn/20090826 Issue 128 - August 26, 2009 --------------------------------------------------------------------------- Welcome to issue 128 of HWN, a newsletter covering developments in the [1]Haskell community. New releases of haddock, gitit, jhc, formlets, and lots of other libraries and tools; Edinburgh Hack Day, ICFP, and HacPDX coming up; exciting times! The Google Summer of Code has also wrapped up. See below for final progress reports from this summer's Haskell participants. PS: Just as this was going to press, Thomas Ten Cate released the Scion library from his Google Summer of Code project; hence it isn't listed below but you should check it out anyway! Announcements GLUT 2.2.1.0. Sven Panne [2]announced a new version of the [3]GLUT package. The package is now autoconf-free, with API entries are resolved dynamically at runtime; support for sRGB framebuffers has been added; and support for context profiles has been added. Potential Network SIG. Thomas DuBuisson [4]announced the formation of a SIG to hammer out a design for a new Network API, seeing as the current API, a straight-forward Berkeley binding, doesn't seem to please anyone in a Haskell context. epoll bindings 0.1.1. Toralf Wittner [5]announced the release of [6]epoll bindings 0.1.1. Epoll is an I/O event notification facility for Linux similar to poll but with good scaling characteristics. Currently the bindings are fairly low level and close to the C API, but there are plans to add some buffer or stream abstraction on top. Eventually, when GHC can make use of epoll/kqueue in addition to select, this library will not be needed anymore. Until then it might be useful for applications which monitor large numbers of file descriptors. gitit 0.6.1. John MacFarlane [7]announced the release of [8]gitit 0.6.1, a wiki program that runs on happstack, the Haskell web application server stack, and stores pages and other content in a git or darcs filestore. The whole code base has been overhauled since the last release: gitit is now faster, more memory efficient, more modular, and more secure. It also has many new features, including page metadata and categories, atom feeds (sitewide and per-page), support for literate Haskell, a better configuration system, an improved caching system, a Haskell library exporting happstack wiki handlers, and a plugin system. jhc 0.7.1. John Meacham [9]announced the 0.7.1 release of the [10]jhc optimizing Haskell compiler. There have been a lot of changes since the last public release. Some notable ones include the use of a general compiler cache by default rather than object files; reworked library support; an updated manual, with clearer build instructions; support for writing pure C libraries in Haskell; numerous library updates; smart progress meters; typechecking before compilation; and various bug fixes and cross compilation improvements. rss2irc 0.3 released. Simon Michael [11]announced the release of [12]rss2irc version 0.3, an irc bot created by Don Stewart to watch rss feeds and announce new items on irc, now maintained by Simon. This version includes reliable http networking, irc flood protection, better error handling & reporting, extensive debugging output, Atom support, more useful defaults, precise control of irc output, and is now installable on OSX. Feedback and patches welcome. formlets 0.6. Chris Eidhof [13]announced that the formlets team has released a new version of [14]formlets, a library to build type-safe, composable web forms. Most notably, Mightybyte and Chris worked on the [15]massInput functionality, which is now ready for use! graphtype -- A simple tool to illustrate dependencies between Haskell types. Max Desyatov [16]announced the release of [17]graphtype, a tool for visualising type declarations in Haskell source files. It produces [18].dot-files for subsequent processing with graphviz. OAuth library in haskell. Diego Souza [19]announced the release of [20]hoauth, a library which helps you to deal with the [21]oauth protocol. Currently it supports only consumer side applications, but there are plans to add service providers support in near future. ByteString Nums. Jason Dusek [22]announced [23]bytestring-nums, a simple package for relatively careless parsing of numbers from ByteStrings. It works to parse out integer strings, floating point strings and hex strings. haskell-src-exts-1.1.3. Niklas Broberg [24]announced the release of [25]haskell-src-exts-1.1.3, a package for Haskell source code manipulation. It handles (almost) all syntactic extensions to the Haskell 98 standard implemented by GHC, and the parsing can be parametrised on what extensions to recognise. haskell-src-exts-1.1.3 is a highly experimental release, which does not change the current stable part of haskell-src-exts. But it includes a whole new set of modules implementing a new and more accurate syntax tree where all nodes are adorned with annotations. Together with this comes a parser that retains exact source information, stored in the aforementioned annotations. Help in testing and bug reporting is welcome and appreciated! ministg-0.2, an interpreter for STG operational semantics. Bernie Pope [26]announced the first public release of [27]Ministg, an interpreter for a high-level, small-step, operational semantics for the STG machine, the abstract machine at the core of GHC. One of the main features of Ministg is the ability to record a trace of the execution steps as a sequence of HTML files; here is an [28]example trace. OpenCLRaw 1.0.1000. Jeff Heard [29]announced the release of [30]OpenCLRaw, a raw binding to the OpenCL, a platform for single-host heterogeneous, data-parallel computing. He has future plans to create higher-level bindings on top of these raw ones. compose-trans-0.0. Miguel Mitrofanov [31]announced [32]compose-trans, a small library intended to make monad transformers composable. Haddock version 2.5.0. David Waern [33]announced the release of [34]Haddock 2.5.0. This version reverts to the old multi-page index for large packages, shows GADT records in the generated documentation, adds a --use-unicode flag for displaying prettier versions of common symbols, and many other changes. Edinburgh Meetup (Sat 29 Aug) and Hack Day (Sun 30 Aug). Eric Kow [35]sent a reminder that we will be having a [36]Hack Day in Edinburgh on Sunday 30 August at the ICFP venue. There will also be a meetup the day before, 09:30 Saturday 29 August just outside the ICFP venue; we'll have a quick wander and hopefully find some nice places to sit and chat, whip out the occasional laptop and fling a lambda or not being careful not to injure the passers-by. Cleaner networking API - network-fancy. Taru Karttunen [37]announced [38]network-fancy, which offers a cleaner API to networking facilities in Haskell. It supports high-level operations on tcp, udp and unix sockets. Feedback on the API is welcome! GLFW-0.4.1. Paul L [39]announced a new version of [40]GLFW, 0.4.1. Notable changes include a workaround for a FFI bug that affects GHC < 6.10 on 64-bit machines, a fix for the compilation problem on OS X for GHC > 6.10.1, a compatibility fix to work with both OpenGL 2.3.0.0 and older versions, choice of a "dynamic" flag to link with dynamic GLFW C library instead, and a number of other fixes, cleanups and improvements. HacPDX, A Hackathon in Portland. Thomas DuBuisson [41]announced [42]HacPDX, an opportunity for Portland Haskell hackers to join together in building and improving libraries and tools. If you've never been, hackathons are typically not only a good opportunity for experienced devs to work together but also a great way for newcomers to get involved in the community. HacPDX will take place Friday September 25 to Sunday September 27 at Portland State University; see the email for more specific details. Hack on the Delve core, with Delve and Haskell. spoon [43]announced [44]Delve, a new programming language intended to bring the benefits of static type checking and functional programming to object-oriented design and development, currently being implemented in Haskell. Contributors welcome! cabal-query 0.1. Max Desyatov [45]announced the release of [46]cabal-query, a package to assist in finding a set of Cabal packages which satisfy your needs. EnumMap-0.0.1. John Van Enk [47]announced the first version of [48]EnumMap, a generalization of IntMap that constrains the key to Enum rather than forcing it to be Int. Google Summer of Code Progress updates from participants in the 2008 [49]Google Summer of Code. Haddock improvements! Isaac Dupree has [50]wrapped up his project, with patches waiting to be merged back into both Haddock and GHC. His final post contains a detailed description of the work he did; looks like we'll have much better cross-package documentation support in Haddock soon! EclipseFP. Thomas Ten Cate began adding a notion of [51]build targets to EclipseFP, so that projects can be created without .cabal files. He has [52]wrapped up the project for now, and although he isn't fully happy with the results that he achieved, he was able to make useful contributions which hopefully others can continue to build on. Improving the Haskell space profiling experience. Gergely Patai's project is done: he [53]uploaded hp2any, a set of realtime space profiling tools, to Hackage. He also [54]created a [55]haskellwiki page describing it and its use. haskell-src-exts -> haskell-src. Niklas Broberg has been [56]working on a complete revamp of the AST, lexer and parser to allow for exact source info to be kept in the tree, which in turn will allow exact printing of the code as it was read. darcs. Petr Rockai posted a [57]final report where he described his accomplishments: the hashed-storage library for reading and writing filesystem trees in hash-based formats; darcs whatsnew integration with hashed-storage; progress on a new and improved version of hashed-storage, and a branch of darcs depending on it; and darcs-benchmark, a standalone package for benchmarking darcs. Discussion Unification and matching in Abelian groups. John D. Ramsdell [58]shared some code implementing unification and matching in Abelian groups. Grouping and SIMD in parallel Haskell (using Nested Data Parallel Haskell ideas in legacy code). Zefirov Sergey [59]posted some code showing how to translate Parallel Haskell programs (expressed with par and pseq) into Nested Data Parallel Haskell. Request for Comments - hscurrency 0.0.1. Max Cantor [60]requested feedback on some simple tools to do safe calculations on different currencies. DDC compiler and effects; better than Haskell? (was Re: unsafeDestructiveAssign?). Peter Verswyvelen began a long [61]discussion about the DDC compiler and its effect system, and the relationship to Haskell and monads. Jobs Credit Suisse is hiring. Ganesh Sittampalam [62]announced that the Global Modelling and Analytics Group (GMAG) at Credit Suisse is once again looking to hire functional programmers; see his email for more information. Jane Street is Hiring (as if you didn't already know). Yaron Minsky sent out a [63]reminder that [64]Jane Street is looking to hire functional programmers; see his email for more details. He also mentioned that he will be at parts of ICFP, CUFP and DEFUN this year, so if you're interested, come and talk to him there. Galois is Hiring. Don Stewart [65]announced that Galois is continuing to hire, with multiple positions for talented functional programmers (with both junior and senior positions). They will be at ICFP and related events; see Don or Lee Pike. Blog noise [66]Haskell news from the [67]blogosphere. Blog posts from people new to the Haskell community are marked with >>>, be sure to welcome them! * Isaac Dupree: [68]Summer of Code Wrap-Up.. * Thomas ten Cate: [69]Endgame. * Jeff Heard: [70]Followup to my earlier post on Hilbert curve timeseries plots. * Jeff Heard: [71]Plotting timeseries in space filling curves. * Magnus Therning: [72]Making a choice from a list in Haskell, Vty (part 5, the last one). * Magnus Therning: [73]Fork/exec in Haskell. * Edward Kmett: [74]Iteratees, Parsec and Monoids (Slides). * Chris Smith: [75]Flow Equivalence Code in Haskell. * Thomas Ten Cate: [76]Build targets. * Chris Smith: [77]Catching a Mathematical Error Using Haskell's Type System. * Well-Typed: [78]Industrial Haskell Group meeting at CUFP. * London HUG: [79]Next meeting: Alex McLean, Live coding music with Haskell. * David Amos: [80]Finite fields, part 1. * Greg Bacon: [81]Simple analogy for lazy evaluation . * Magnus Therning: [82]JSON in Haskell. * Notes on the LHC: [83]Status update: New Integer implementation.. * Edward Kmett: [84]Clearer Reflections. * Petr Rockai: [85]soc final report. * Gergely Patai: [86]hp2any overview online. * Brent Yorgey: [87]New 2D text layout library. * Manuel Chakravarty: [88]World's first formal machine-checked proof of a general-purpose operating system kernel.. * Bryan O'Sullivan: [89]Haskell Platform support for Fedora: we're almost there. * Gergely Patai: [90]hp2any on Hackage. * Doug Beardsley: [91]Dynamic List Formlets in Haskell . * Niklas Broberg: [92]Quick update. * Christopher Lane Hinson: [93]FactoryArrow. * Michael Feathers: [94]Imposing the Edges Later . * Brent Yorgey: [95]Species operations: differentiation. * >>> Ron Leisti: [96]A prime number sieve in Haskell. Quotes of the Week * bos: You don't get accurate answers from Perl. It just lies to you to keep you happy. * ray: haskell' will come out in 2020 and be h98 with hierarchical modules * ray: enlarge your kleisli arrow, please the category ladies * quicksilver: making the compiler writer's job painful is one of the main duties of a language designer. * gwern: as a plugin, yes, but that's like being so out of shape that a guy in a wheelchair can outrace you - yes, he needs a tool, but you should still be ashamed of yourself * Cale's Lemma: Any sufficiently long string of operator symbols looks like a fish. * randomwords: How "complete" does an application before it's OK to upload to hackage? there are no standards lawless wasteland. Got it. * ndm: I was browsing through the Yhc standard libraries, as one does on the weekend, and was drawn to Yhc's sort function. * michaelfeathers: I did a parody post to Haskell Cafe last year where I had some code that was calling (nub . nub) zip12 and asked if there was a zip13 and no one called it out as a joke. About the Haskell Weekly News New editions are posted to [97]the Haskell mailing list as well as to [98]the Haskell Sequence and [99]Planet Haskell. [100]RSS is also available, and headlines appear on [101]haskell.org. To help create new editions of this newsletter, please see the information on [102]how to contribute. Send stories to byorgey at cis dot upenn dot edu. The darcs repository is available at darcs get [103]http://code.haskell.org/~byorgey/code/hwn/ . References 1. http://haskell.org/ 2. http://article.gmane.org/gmane.comp.lang.haskell.general/17442 3. http://hackage.haskell.org/package/GLUT 4. http://article.gmane.org/gmane.comp.lang.haskell.libraries/11813 5. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62782 6. http://hackage.haskell.org/package/epoll 7. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62776 8. http://gitit.johnmacfarlane.net/ 9. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62759 10. http://repetae.net/computer/jhc 11. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62743 12. http://hackage.haskell.org/package/rss2irc 13. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62738 14. http://hackage.haskell.org/package/formlets 15. http://softwaresimply.blogspot.com/2009/08/dynamic-list-formlets-in-haskell.html 16. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62736 17. http://hackage.haskell.org/package/graphtype 18. http://i.piccy.info/i4/00/90/bfa07290012c2d3b455696bdaa86.png 19. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62735 20. http://hackage.haskell.org/package/hoauth 21. http://oauth.net/ 22. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62695 23. http://hackage.haskell.org/package/bytestring-nums 24. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62682 25. http://hackage.haskell.org/package/haskell-src-exts 26. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62559 27. http://www.haskell.org/haskellwiki/Ministg 28. http://www.cs.mu.oz.au/~bjpop/trace/step0.html 29. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62414 30. http://hackage.haskell.org/package/OpenCLRaw 31. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62390 32. http://hackage.haskell.org/package/compose%2Dtrans 33. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62341 34. http://www.haskell.org/haddock 35. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62324 36. http://www.haskell.org/haskellwiki/Hac7 37. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62277 38. http://hackage.haskell.org/package/network%2Dfancy 39. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62259 40. http://hackage.haskell.org/package/GLFW 41. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62195 42. http://haskell.org/haskellwiki/HacPDX 43. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62173 44. http://killersmurf.blogspot.com/ 45. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62139 46. http://hackage.haskell.org/package/cabal%2Dquery 47. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62119 48. http://hackage.haskell.org/package/EnumMap 49. http://hackage.haskell.org/trac/summer-of-code/wiki/SoC2008 50. http://haddock2009.wordpress.com/2009/08/26/summer-of-code-wrap-up/ 51. http://eclipsefp.wordpress.com/2009/08/20/build-targets/ 52. http://eclipsefp.wordpress.com/2009/08/25/endgame/ 53. http://just-bottom.blogspot.com/2009/08/hp2any-on-hackage.html 54. http://just-bottom.blogspot.com/2009/08/hp2any-overview-online.html 55. http://www.haskell.org/haskellwiki/Hp2any 56. http://nibrofun.blogspot.com/2009/08/just-quick-note-since-i-realise-i.html 57. http://web.mornfall.net/blog/soc_final_report.html 58. http://thread.gmane.org/gmane.comp.lang.haskell.cafe/62486 59. http://thread.gmane.org/gmane.comp.lang.haskell.cafe/62403 60. http://thread.gmane.org/gmane.comp.lang.haskell.cafe/62342 61. http://thread.gmane.org/gmane.comp.lang.haskell.cafe/62205 62. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62406 63. http://article.gmane.org/gmane.comp.lang.haskell.general/17436 64. http://www.janestreet.com/ 65. http://article.gmane.org/gmane.comp.lang.haskell.cafe/62191 66. http://planet.haskell.org/ 67. http://haskell.org/haskellwiki/Blog_articles 68. http://haddock2009.wordpress.com/2009/08/26/summer-of-code-wrap-up/ 69. http://eclipsefp.wordpress.com/ 70. http://vis.renci.org/jeff/2009/08/24/followup-to-my-earlier-post-on-hilbert-curve-timeseries-plots/ 71. http://vis.renci.org/jeff/2009/08/24/plotting-timeseries-in-space-filling-curves/ 72. http://therning.org/magnus/archives/732 73. http://therning.org/magnus/archives/727 74. http://comonad.com/reader/2009/iteratees-parsec-and-monoid/ 75. http://cdsmith.wordpress.com/2009/08/20/flow-equivalence-code-in-haskell/ 76. http://eclipsefp.wordpress.com/2009/08/20/build-targets/ 77. http://cdsmith.wordpress.com/2009/08/19/catching-a-mathematical-error-using-haskells-type-system/ 78. http://blog.well-typed.com/2009/08/industrial-haskell-group-meeting-at-cufp/ 79. http://www.londonhug.net/2009/08/18/next-meeting-alex-mclean-live-coding-music-with-haskell/ 80. http://haskellformaths.blogspot.com/2009/08/finite-fields-part-1.html 81. http://gbacon.blogspot.com/2009/08/simple-analogy-for-lazy-evaluation.html 82. http://therning.org/magnus/archives/719 83. http://lhc-compiler.blogspot.com/2009/08/status-update-new-integer.html 84. http://comonad.com/reader/2009/clearer-reflection/ 85. http://web.mornfall.net/blog/soc_final_report.html 86. http://just-bottom.blogspot.com/2009/08/hp2any-overview-online.html 87. http://byorgey.wordpress.com/2009/08/14/new-2d-text-layout-library/ 88. http://justtesting.org/post/162408446/worlds-first-formal-machine-checked-proof-of-a 89. http://www.serpentine.com/blog/2009/08/12/haskell-platform-support-for-fedora-were-almost-there/ 90. http://just-bottom.blogspot.com/2009/08/hp2any-on-hackage.html 91. http://softwaresimply.blogspot.com/2009/08/dynamic-list-formlets-in-haskell.html 92. http://nibrofun.blogspot.com/2009/08/just-quick-note-since-i-realise-i.html 93. http://blog.downstairspeople.org/2009/08/09/factoryarrow/ 94. http://blog.objectmentor.com/articles/2009/08/08/imposing-the-edges-later 95. http://byorgey.wordpress.com/2009/08/05/species-operations-differentiation/ 96. http://www.ronleisti.com/wp/2009/07/26/a-prime-number-sieve-in-haskell/ 97. http://www.haskell.org/mailman/listinfo/haskell 98. http://sequence.complete.org/ 99. http://planet.haskell.org/ 100. http://sequence.complete.org/node/feed 101. http://haskell.org/ 102. http://haskell.org/haskellwiki/HWN 103. http://code.haskell.org/~byorgey/code/hwn/ From phil at beadling.co.uk Wed Aug 26 21:53:17 2009 From: phil at beadling.co.uk (phil@beadling.co.uk) Date: Wed Aug 26 21:33:02 2009 Subject: [Haskell-cafe] FFI link failing due to no main? In-Reply-To: References: Message-ID: Thanks for the reply! I think this might be a Mac OS X issue. I've stripped my rather longwinded example down to the simplest case (one Haskell source file to create a single shared library containing a single exported function) and this compiles (and ultimately runs) fine on Linux. So I'm either doing something wrong which shouldn't really work on Linux (and I'm getting lucky!)... or something screwy is happening on Mac version: This exports a single function which is then #included in CInterface.c to create a new pure-C wrapper to the function. ghc -O2 -c HaskellFuncs.hs ghc -O2 -no-hs-main --make -optl '-shared' CInterface.c HaskellFuncs_stub.o HaskellFuncs.o -o libCInterface.so One Mac OS X I get the following error - but it works fine on Ubuntu. I'm using 6.10.4 on both machines: Linking libCInterface.so ... Undefined symbols: "_ZCMain_main_closure", referenced from: _ZCMain_main_closure$non_lazy_ptr in libHSrts.a(Main.o) "___stginit_ZCMain", referenced from: ___stginit_ZCMain$non_lazy_ptr in libHSrts.a(Main.o) ld: symbol(s) not found Could anyone comment if I'm doing anything wrong, or is this a case of unsupported functionality on (PPC/Leopard) Mac OS X? Has anyone succeeded in getting a similar example to work on Mac OS X? I notice on Linux it is still very temperamental, if I play around with the arguments even slightly I get the same error there. Cheers, Phil. On 26 Aug 2009, at 06:51, Yusaku Hashimoto wrote: > Missing -c option? > > And -v option to see what's going on. > > On Wed, Aug 26, 2009 at 10:37 AM, wrote: >> Hi, >> >> After creating my stub objects etc using GHC, I'm trying to create >> a library >> with a C interface to some Haskell functions. I'm explicitly >> passing in >> -no-hs-main yet the linker still fails due to missing main? >> >> I'm sure I've had this working before with a slightly simpler >> example, but >> can't work out what is wrong here. >> >> If I give it a main (to humor it - it's not a solution), then it >> links and >> produces an executable - so it looks to me like I'm not telling the >> linker >> what I want correctly? >> >> Any ideas? >> >> Cheers, >> >> Phil. >> >> >> ghc -O2 --make -no-hs-main -package mtl -package array -optl '- >> shared' >> FFI/Octave/MyInterface.c FFI/Octave/OptionInterface_stub.o >> FFI/Octave/OptionInterface.o ./FrameworkInterface.o ./Maths/Prime.o >> ./MonteCarlo/DataStructures.o ./MonteCarlo/European.o >> ./MonteCarlo/Framework.o ./MonteCarlo/Interface.o ./MonteCarlo/ >> Lookback.o >> ./Normal/Acklam.o ./Normal/BoxMuller.o ./Normal/Framework.o >> ./Normal/Interface.o ./Random/Framework.o ./Random/Halton.o >> ./Random/Interface.o ./Random/Ranq1.o -o FFI/Octave/ >> libMyInterface.so >> Linking FFI/Octave/libMyInterface.so ... >> Undefined symbols: >> "___stginit_ZCMain", referenced from: >> ___stginit_ZCMain$non_lazy_ptr in libHSrts.a(Main.o) >> "_ZCMain_main_closure", referenced from: >> _ZCMain_main_closure$non_lazy_ptr in libHSrts.a(Main.o) >> ld: symbol(s) not found >> collect2: ld returned 1 exit status >> >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> From haskellmail at gmail.com Wed Aug 26 21:57:31 2009 From: haskellmail at gmail.com (kenny lu) Date: Wed Aug 26 21:37:14 2009 Subject: [Haskell-cafe] Network.Socket error in MacOS 10.5? In-Reply-To: <62991611-270F-46B4-B967-40980FF0B20A@z.odi.ac> References: <90bba1dc0908260933k10c28c21g5553e54f70ba0bc6@mail.gmail.com> <90889fe70908261107y61fa2042g499b082be1cb815c@mail.gmail.com> <62991611-270F-46B4-B967-40980FF0B20A@z.odi.ac> Message-ID: <90bba1dc0908261857n5abf2303n38032307bfdecc0a@mail.gmail.com> Thanks for the pointers. I will take a look. Kenny On Thu, Aug 27, 2009 at 2:20 AM, Ross Mellgren wrote: > I don't think getNameInfo should work for for AF_UNIX -- the name given to > SockAddrUnix is a file path, there is no name resolution. From the man page > for getnameinfo(3) on OS X: > > NAME > getnameinfo -- socket address structure to hostname and service name > > ... > > DESCRIPTION > > ... > > The sockaddr structure sa should point to either a sockaddr_in or > sockaddr_in6 structure > (for IPv4 or IPv6 respectively) that is salen bytes long. > > > > Similarly, from the man page for getnameinfo on my linux box: > > ... > > The sa argument is a pointer to a generic socket address structure (of type > sockaddr_in or sockaddr_in6) of size salen that holds the input IP address > and port number. > > -Ross > On Aug 26, 2009, at 2:07 PM, Johan Tibell wrote: > > On Wed, Aug 26, 2009 at 6:33 PM, kenny lu wrote: >> >>> Hi, >>> >>> I encountered a problem with Network.Socket in MacOS 10.5 >>> Here is the code that I am testing, >>> >>> ----------------------------------------- >>> ----------------------------------------- >>> module Main where >>> >>> import qualified Network.Socket as Socket >>> >>> main :: IO () >>> main = >>> do { (hostname, _) <- Socket.getNameInfo [] True False >>> (Socket.SockAddrUnix "localhost") >>> -- (hostname, _) <- Socket.getNameInfo [] True False >>> (Socket.SockAddrInet 9000 (127 + 0 * 256 + 0 * 256^2 + 1 * 256^3)) >>> ; putStrLn (show hostname) >>> } >>> >>> >>> Running the above code yields the following error >>> ghc --make -O2 TestSocket.hs >>> [1 of 1] Compiling Main ( TestSocket.hs, TestSocket.o ) >>> Linking TestSocket ... >>> $ ./TestSocket >>> TestSocket: getNameInfo: does not exist (ai_family not supported) >>> >>> If I switch to SockAddrInet instead, the error is gone. >>> >>> I am using GHC 6.10.3 and Network 2.2.1 >>> >> >> Is SockAddrUnix supposed to work on Mac OS X? Could you test it by >> e.g. writing a small C program that uses it? >> >> -- Johan >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090826/71d7874d/attachment.html From ralf.hinze at comlab.ox.ac.uk Thu Aug 27 01:48:39 2009 From: ralf.hinze at comlab.ox.ac.uk (Ralf Hinze) Date: Thu Aug 27 01:28:22 2009 Subject: [Haskell-cafe] Applicative and Monad transformers In-Reply-To: <87eiqyzjoc.wl%jeremy@n-heptane.com> References: <87eiqyzjoc.wl%jeremy@n-heptane.com> Message-ID: <200908270748.40317.ralf.hinze@comlab.ox.ac.uk> Hi Jeremy, > I have seen it said that all Monads are Applicative Functors because > you can just do: > > instance (Monad f, Applicative f) => Applicative (ReaderT r f) where > pure = return > (<*>) = ap > > However, that instance for ReaderT does not exhibit the properties I > was hoping for. OK, let's calculate. Here are the necessary definitions for the reader monad (not the monad transformer). m >>= k = \ x -> k (m x) x u <*> v = \ x -> (u x) (v x) return a = pure a = \ x -> a So, <*> is the S combinator and pure is the K combinator. u >>= \ f -> v >>= \ a -> return (f a) = { definition of >>= } \ x -> (\ f -> v >>= \ a -> return (f a)) (u x) x = { beta } \ x -> (v >>= \ a -> return ((u x) a)) x = { definition of >>= } \ x -> (\ a -> return ((u x) a)) (v x) x = { beta } \ x -> return ((u x) (v x)) x = { definition of return } \ x -> (u x) (v x) = { definition of <*> } u <*> v Yes, both definitions are, in fact, equal. So, what went wrong in your program? Observe that the first instance declaration can be simplified to instance (Monad f) => Applicative (ReaderT r f) where pure = return (<*>) = ap which is suspicious. Hope this helps, Ralf From phil at beadling.co.uk Thu Aug 27 03:24:06 2009 From: phil at beadling.co.uk (phil@beadling.co.uk) Date: Thu Aug 27 03:03:49 2009 Subject: [Haskell-cafe] FFI link failing due to no main? In-Reply-To: <4d8ad03a0908262038n47499ed1ra6b93198130fe37b@mail.gmail.com> References: <4d8ad03a0908262038n47499ed1ra6b93198130fe37b@mail.gmail.com> Message-ID: > I'm not really sure, but does the linking step really need to be given > the --make flag? I would try linking without that in the first > instance. I think so - it's not just a link step, it does the following: Compile: CInterface.c -> CInterface.o Link: CInterface.o HaskellFuncs_stub.o Hasnkell.Funcs.o -> libCInterface.so I'll take a look at the full -v output and see if that reveals anything. Thanks, Phil. On 27 Aug 2009, at 04:38, Bernie Pope wrote: > Hi Phil, From haskell at kudling.de Thu Aug 27 04:19:00 2009 From: haskell at kudling.de (haskell@kudling.de) Date: Thu Aug 27 03:58:42 2009 Subject: [Haskell-cafe] Mapping over multiple values of a list at once? Message-ID: <32478061.199701251361140344.JavaMail.servlet@kundenserver> Hi, Imagine you have a list with n-values. You are asked to iterate over the list and calculate the average value of each 3 neighbouring values. For example, starting from [4,3,2,6,7] you need to find the averages of 4,3,2 and 3,2,6 and 2,6,7 resulting in [3,4,5] What is the most elegant way to do that? The naive ansatz to use "(!!") excessively sounds pretty inefficient. Bye, Lenny From miguelimo38 at yandex.ru Thu Aug 27 04:22:10 2009 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Thu Aug 27 04:03:31 2009 Subject: [Haskell-cafe] Mapping over multiple values of a list at once? In-Reply-To: <32478061.199701251361140344.JavaMail.servlet@kundenserver> References: <32478061.199701251361140344.JavaMail.servlet@kundenserver> Message-ID: <4A964232.4040607@yandex.ru> transpose & tails, I guess. haskell@kudling.de wrote: > Hi, > > Imagine you have a list with n-values. You are asked to iterate over the list and calculate the average value of each 3 neighbouring values. > > For example, starting from > > [4,3,2,6,7] > > you need to find the averages of > > 4,3,2 and 3,2,6 and 2,6,7 > > resulting in > > [3,4,5] > > What is the most elegant way to do that? > The naive ansatz to use "(!!") excessively sounds pretty inefficient. > > Bye, > Lenny > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From martijn at van.steenbergen.nl Thu Aug 27 04:28:33 2009 From: martijn at van.steenbergen.nl (Martijn van Steenbergen) Date: Thu Aug 27 04:08:23 2009 Subject: [Haskell-cafe] Mapping over multiple values of a list at once? In-Reply-To: <4A964232.4040607@yandex.ru> References: <32478061.199701251361140344.JavaMail.servlet@kundenserver> <4A964232.4040607@yandex.ru> Message-ID: <4A9643B1.7000705@van.steenbergen.nl> Right. How about: f = map ((`div` 3) . sum . take 3) . tails You probably want to do filter out some of the tails. Not sure where transpose comes into play, but tails is your friend here. Martijn. Miguel Mitrofanov wrote: > transpose & tails, I guess. From miguelimo38 at yandex.ru Thu Aug 27 04:28:52 2009 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Thu Aug 27 04:10:13 2009 Subject: [Haskell-cafe] Mapping over multiple values of a list at once? In-Reply-To: <4A9643B1.7000705@van.steenbergen.nl> References: <32478061.199701251361140344.JavaMail.servlet@kundenserver> <4A964232.4040607@yandex.ru> <4A9643B1.7000705@van.steenbergen.nl> Message-ID: <4A9643C4.7050401@yandex.ru> > Not sure where transpose comes into play, My original attempt was "transpose . take 3 . tails". There's more than one way to do the job... From max.rabkin at gmail.com Thu Aug 27 04:30:12 2009 From: max.rabkin at gmail.com (Max Rabkin) Date: Thu Aug 27 04:10:17 2009 Subject: [Haskell-cafe] Mapping over multiple values of a list at once? In-Reply-To: <32478061.199701251361140344.JavaMail.servlet@kundenserver> References: <32478061.199701251361140344.JavaMail.servlet@kundenserver> Message-ID: My first approach would be to generate the list of sliding windows: [[4,3,2],[3,2,6],[2,6,7]] after importing Data.List: > map (take 3) . tails $ [4,3,2,6,7] [[4,3,2],[3,2,6],[2,6,7],[6,7],[7],[]] Not quite what we want, but close: > filter ((== 3) . length) . map (take 3) . tails $ [4,3,2,6,7] [[4,3,2],[3,2,6],[2,6,7]] So (filter ((== 3) . length) . map (take 3) . tails) seems to be the desired function. Now just map average. However, we don't really need the sliding windows themselves, just the sliding sum. There might be a slightly more efficient way to do that, but I'll leave it as an exercise for you or somebody else. --Max On Thu, Aug 27, 2009 at 10:19 AM, wrote: > Hi, > > Imagine you have a list with n-values. You are asked to iterate over the list and calculate the average value of each 3 neighbouring values. > > For example, starting from > > [4,3,2,6,7] > > you need to find the averages of > > 4,3,2 and 3,2,6 and 2,6,7 > > resulting in > > [3,4,5] > > What is the most elegant way to do that? > The naive ansatz to use "(!!") excessively sounds pretty inefficient. > > Bye, > Lenny > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From haskell at kudling.de Thu Aug 27 04:52:06 2009 From: haskell at kudling.de (haskell@kudling.de) Date: Thu Aug 27 04:31:46 2009 Subject: [Haskell-cafe] Mapping over multiple values of a list at once? Message-ID: <23225216.206071251363126391.JavaMail.servlet@kundenserver> "tails" seems to be the key. I haven't thought of this before. Thanks for pointing me in the right direction, guys. From valgarv at gmx.net Thu Aug 27 05:00:49 2009 From: valgarv at gmx.net (Ariel J. Birnbaum) Date: Thu Aug 27 04:40:33 2009 Subject: [Haskell-cafe] Mapping over multiple values of a list at once? In-Reply-To: <23225216.206071251363126391.JavaMail.servlet@kundenserver> References: <23225216.206071251363126391.JavaMail.servlet@kundenserver> Message-ID: <1251363649.6682.5.camel@lnx-arielb> > "tails" seems to be the key. I haven't thought of this before. > > Thanks for pointing me in the right direction, guys. For a more "interesting" solution: http://blog.sigfpe.com/2006/12/evaluating-cellular-automata-is.html I believe you can adapt his 'rule' function to your problem. It's probably overkill, but good learning material =) Have fun! -- Ariel J. Birnbaum From patai_gergely at fastmail.fm Thu Aug 27 05:06:59 2009 From: patai_gergely at fastmail.fm (Patai Gergely) Date: Thu Aug 27 04:46:40 2009 Subject: [Haskell-cafe] Mapping over multiple values of a list at once? Message-ID: <1251364019.9550.1331868129@webmail.messagingengine.com> > For example, starting from > > [4,3,2,6,7] > > you need to find the averages of > > 4,3,2 and 3,2,6 and 2,6,7 > > resulting in > > [3,4,5] > > What is the most elegant way to do that? It's probably less elegant than tails, but very likely more efficient to keep track of running sums instead of summing the sublists over and over again. import Data.Ratio nsums n xs = map (% n) $ scanl (+) (sum (take n xs)) $ zipWith (-) (drop n xs) xs Gergely -- http://www.fastmail.fm - The professional email service From ekirpichov at gmail.com Thu Aug 27 05:19:32 2009 From: ekirpichov at gmail.com (Eugene Kirpichov) Date: Thu Aug 27 04:59:11 2009 Subject: [Haskell-cafe] Mapping over multiple values of a list at once? In-Reply-To: <1251364019.9550.1331868129@webmail.messagingengine.com> References: <1251364019.9550.1331868129@webmail.messagingengine.com> Message-ID: <5e0214850908270219l1c5bb0cbx31c36ead7dcba17c@mail.gmail.com> How about this one? Should be pretty efficient. let mavg n xs = let (sum -> seed,rest) = splitAt n xs in map (%n) . scanl (\a (p,n) -> a+n-p) seed $ xs `zip` rest 2009/8/27 Patai Gergely : >> For example, starting from >> >> [4,3,2,6,7] >> >> you need to find the averages of >> >> 4,3,2 and 3,2,6 and 2,6,7 >> >> resulting in >> >> [3,4,5] >> >> What is the most elegant way to do that? > It's probably less elegant than tails, but very likely more efficient to > keep track of running sums instead of summing the sublists over and over > again. > > import Data.Ratio > > nsums n xs = map (% n) $ scanl (+) (sum (take n xs)) $ zipWith (-) (drop > n xs) xs > > Gergely > > -- > http://www.fastmail.fm - The professional email service > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Eugene Kirpichov Web IR developer, market.yandex.ru From nominolo at googlemail.com Thu Aug 27 05:44:32 2009 From: nominolo at googlemail.com (Thomas Schilling) Date: Thu Aug 27 05:24:20 2009 Subject: [Haskell-cafe] ANN: scion 0.1 In-Reply-To: <90889fe70908270117s490a62ccs781758ab10169cc1@mail.gmail.com> References: <90889fe70908270117s490a62ccs781758ab10169cc1@mail.gmail.com> Message-ID: On 27 Aug 2009, at 09:17, Johan Tibell wrote: > Hi Thomas, > > This is really cool stuff. I played with it this morning and found a > potential bug. Both the emacs and vim client libraries refer to the > binary "scion_server" but the binary that gets built and put in > ~/.cabal/bin is called "scion-server" (note the dash). I worked around > the problem by putting this in my .emacs: Right, I changed that before the release and apparently forgot to change a few places. Will be fixed in the next minor version. > > (setq scion-program "scion-server") > > Also, I tried to play with the scion-open-cabal-project function. I'm > not sure I understand how it's intended to be used. Does it make sure > that if you compile a file using C-c C-x C-l the right source > directories are used? Could you give a usage example? I eventually want to get rid of it and let scion-load figure out itself when the project needs to be reconfigured. At the moment you have to delete the .dist-scion directory if you changed your .cabal file. :/ > > One problem I frequently have with emacs-mode is that you can't use it > to load a file if > > * your sources don't live in the same directory as the Cabal file, or Actually, the latest version of haskell-mode has some heuristics. It sets the working directory to where the .cabal file lives. > * the file needs preprocessing (e.g. it's a .hsc) file. > > Now when we have the Cabal file loaded would it be possible to have > Cabal compile the project and then try to load the .hs file generated > from the .hsc file that is currently opened? Right, so those files should be generated, but it's quite difficult to update them automatically and recompile the necessary files. Also, some preprocessers don't add the proper {-# LINE #-} markers, so the error messages will be all wrong. So, I think it should work this way: User opens a .hsc / .y / .x file, Scion figures out that the file needs preprocessing, loads the generated file and highlights the error messages and highlights them in the original file. > > Thanks! > > -- Johan / Thomas -- Push the envelope. Watch it bend. -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 194 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090827/4c345863/PGP.bin From shinnonoir at gmail.com Thu Aug 27 06:41:51 2009 From: shinnonoir at gmail.com (Raynor Vliegendhart) Date: Thu Aug 27 06:21:30 2009 Subject: [Haskell-cafe] Mapping over multiple values of a list at once? In-Reply-To: <32478061.199701251361140344.JavaMail.servlet@kundenserver> References: <32478061.199701251361140344.JavaMail.servlet@kundenserver> Message-ID: <6d961e560908270341r29c313c3hcaeb6835fa092f1a@mail.gmail.com> Just wondering, what should be the expected output be of something like mavg 4 [1..3]? [3%2] or []? Patai's and Eugene's solutions assume the former. On Thu, Aug 27, 2009 at 10:19 AM, wrote: > Hi, > > Imagine you have a list with n-values. You are asked to iterate over the list and calculate the average value of each 3 neighbouring values. > > For example, starting from > > [4,3,2,6,7] > > you need to find the averages of > > 4,3,2 and 3,2,6 and 2,6,7 > > resulting in > > [3,4,5] > > What is the most elegant way to do that? > The naive ansatz to use "(!!") excessively sounds pretty inefficient. > > Bye, > Lenny > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From sfvisser at cs.uu.nl Thu Aug 27 07:49:48 2009 From: sfvisser at cs.uu.nl (Sebastiaan Visser) Date: Thu Aug 27 07:29:31 2009 Subject: [Haskell-cafe] Mapping over multiple values of a list at once? In-Reply-To: <5e0214850908270219l1c5bb0cbx31c36ead7dcba17c@mail.gmail.com> References: <1251364019.9550.1331868129@webmail.messagingengine.com> <5e0214850908270219l1c5bb0cbx31c36ead7dcba17c@mail.gmail.com> Message-ID: <317C45EF-CB25-4754-A76E-92D9E040BAF4@cs.uu.nl> Or, when the list is infinite, turn it into a some neat but cryptic State computation: avgs = (:) <$> ((\d -> sum d `div` 3) <$> StateT (pure . splitAt 3)) <*> avgs test = evalState avgs [1,2..] -- Sebastiaan Visser On Aug 27, 2009, at 11:19 AM, Eugene Kirpichov wrote: > How about this one? Should be pretty efficient. > > let mavg n xs = let (sum -> seed,rest) = splitAt n xs in map (%n) . > scanl (\a (p,n) -> a+n-p) seed $ xs `zip` rest > > > 2009/8/27 Patai Gergely : >>> For example, starting from >>> >>> [4,3,2,6,7] >>> >>> you need to find the averages of >>> >>> 4,3,2 and 3,2,6 and 2,6,7 >>> >>> resulting in >>> >>> [3,4,5] >>> >>> What is the most elegant way to do that? >> It's probably less elegant than tails, but very likely more >> efficient to >> keep track of running sums instead of summing the sublists over and >> over >> again. >> >> import Data.Ratio >> >> nsums n xs = map (% n) $ scanl (+) (sum (take n xs)) $ zipWith (-) >> (drop >> n xs) xs >> >> Gergely From bulat.ziganshin at gmail.com Thu Aug 27 08:01:19 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Aug 27 07:41:08 2009 Subject: [Haskell-cafe] Mapping over multiple values of a list at once? In-Reply-To: <317C45EF-CB25-4754-A76E-92D9E040BAF4@cs.uu.nl> References: <1251364019.9550.1331868129@webmail.messagingengine.com> <5e0214850908270219l1c5bb0cbx31c36ead7dcba17c@mail.gmail.com> <317C45EF-CB25-4754-A76E-92D9E040BAF4@cs.uu.nl> Message-ID: <1035164564.20090827160119@gmail.com> Hello Sebastiaan, Thursday, August 27, 2009, 3:49:48 PM, you wrote: you also need to replace (\d -> sum d `div` 3) with (`div` 3) . sum in order to keep Haskell spirit :) > Or, when the list is infinite, turn it into a some neat but cryptic > State computation: > avgs = (:) <$> ((\d -> sum d `div` 3) <$> StateT (pure . splitAt 3)) > <*> avgs > test = evalState avgs [1,2..] > -- > Sebastiaan Visser > On Aug 27, 2009, at 11:19 AM, Eugene Kirpichov wrote: >> How about this one? Should be pretty efficient. >> >> let mavg n xs = let (sum -> seed,rest) = splitAt n xs in map (%n) . >> scanl (\a (p,n) -> a+n-p) seed $ xs `zip` rest >> >> >> 2009/8/27 Patai Gergely : >>>> For example, starting from >>>> >>>> [4,3,2,6,7] >>>> >>>> you need to find the averages of >>>> >>>> 4,3,2 and 3,2,6 and 2,6,7 >>>> >>>> resulting in >>>> >>>> [3,4,5] >>>> >>>> What is the most elegant way to do that? >>> It's probably less elegant than tails, but very likely more >>> efficient to >>> keep track of running sums instead of summing the sublists over and >>> over >>> again. >>> >>> import Data.Ratio >>> >>> nsums n xs = map (% n) $ scanl (+) (sum (take n xs)) $ zipWith (-) >>> (drop >>> n xs) xs >>> >>> Gergely > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From sfvisser at cs.uu.nl Thu Aug 27 10:09:20 2009 From: sfvisser at cs.uu.nl (Sebastiaan Visser) Date: Thu Aug 27 09:49:06 2009 Subject: [Haskell-cafe] ANN: jail-0.0.1 - Jailed IO monad Message-ID: <9EEA7730-D953-41BE-86D3-2788518A5F2E@cs.uu.nl> Hi all, I am very pleased to announce the first release of the jail[1,2] package. A jailed IO monad that can restrict filesystem access for your code. This package will soon be an integral part of the Salvia web server. (a new and improved Salvia will be released soon) Basic documentation of the jail package is included below. Any comments, suggestions, audits, etc. are welcome! Gr, -- Sebastiaan Visser [1] Source repo: http://github.com/sebastiaanvisser/jail/ [2] Hackage: http://hackage.haskell.org/package/jail -------- Like all of us know, the IO monad from the System.IO module is a wild beast allowing all forms of insecure computations that can read, or even worse, alter the real world. Writing to sockets, deleting files or even launching missiles, its possibilities are endless. This library provides a special IO module that wraps all file and handle based IO operations from the System.IO module, but provides a possibility to run them in an restricted environment. When running a jailed IO computation a file path can be specified all IO operations will be checked against. Accessing files outside this directory is not allowed and results in a runtime error. Additionally, when running a jailed IO computation a whitelist of file handles can be specified that are accessible as well. For example, running some code with the permission to access all files within (and only within) my home directory and allowing to access the standard output and standard error can be enforced like this: Jail.run (Just "/home/sebas") [stdout, stderr] yourUntrustworthyComputation Only allowing the code to access the standard input and nothing else can be enforced like this: Jail.run Nothing [stdin] yourEvenMoreUntrustworthyComputation Because the jailed IO environment keeps track of all file handles and checks that are opened by its own operations, smuggling in evil file handles from the fierce and dangerous outside world will be punished by border patrol. Only handles from the whitelist or handles securely opened by functions like openFile will be accepted. Because of the opaque IO constructor and the restricted set of exported operations this module is not easily fooled. I would almost dare to say this module is conceptually safe and code with the jailed IO type can blindly be trusted. Except, yes unfortunately except, unsafePerformIO ruins it all. I would almost suggest adding a flag to the compiler to enforce the absence ofunsafeRuinMyTypeSafety-alike functions in order to be able to create systems in which code can be trusted by its type alone. Nonetheless, this module is one step forward in trusting your own programs. Some real http://tinyurl.com/paranoidpeople prefer writing there software in one of the most insecure programming languages and perform security audits by hand, I'd rather have my compiler do the job. (Anyone who wants to audit this library is more than welcome!) From vanenkj at gmail.com Thu Aug 27 10:14:21 2009 From: vanenkj at gmail.com (John Van Enk) Date: Thu Aug 27 09:54:03 2009 Subject: [Haskell-cafe] ANN: jail-0.0.1 - Jailed IO monad In-Reply-To: <9EEA7730-D953-41BE-86D3-2788518A5F2E@cs.uu.nl> References: <9EEA7730-D953-41BE-86D3-2788518A5F2E@cs.uu.nl> Message-ID: Neat! On Thu, Aug 27, 2009 at 10:09 AM, Sebastiaan Visser wrote: > Hi all, > > I am very pleased to announce the first release of the jail[1,2] package. A > jailed IO monad that can restrict filesystem access for your code. This > package will soon be an integral part of the Salvia web server. (a new and > improved Salvia will be released soon) > > Basic documentation of the jail package is included below. > > Any comments, suggestions, audits, etc. are welcome! > > Gr, > > -- > Sebastiaan Visser > > [1] Source repo: http://github.com/sebastiaanvisser/jail/ > > [2] Hackage: http://hackage.haskell.org/package/jail > > > > -------- > > Like all of us know, the IO monad from the System.IO module is a wild beast > allowing all forms of insecure computations that can read, or even worse, > alter the real world. Writing to sockets, deleting files or even launching > missiles, its possibilities are endless. This library provides a special IO > module that wraps all file and handle based IO operations from the System.IO > module, but provides a possibility to run them in an restricted environment. > When running a jailed IO computation a file path can be specified all IO > operations will be checked against. Accessing files outside this directory > is not allowed and results in a runtime error. Additionally, when running a > jailed IO computation a whitelist of file handles can be specified that are > accessible as well. > > For example, running some code with the permission to access all files > within (and only within) my home directory and allowing to access the > standard output and standard error can be enforced like this: > > Jail.run (Just "/home/sebas") [stdout, stderr] > yourUntrustworthyComputation > Only allowing the code to access the standard input and nothing else can be > enforced like this: > > Jail.run Nothing [stdin] yourEvenMoreUntrustworthyComputation > Because the jailed IO environment keeps track of all file handles and > checks that are opened by its own operations, smuggling in evil file handles > from the fierce and dangerous outside world will be punished by border > patrol. Only handles from the whitelist or handles securely opened by > functions like openFile will be accepted. Because of the opaque IO > constructor and the restricted set of exported operations this module is not > easily fooled. > > I would almost dare to say this module is conceptually safe and code with > the jailed IO type can blindly be trusted. Except, yes unfortunately except, > unsafePerformIO ruins it all. I would almost suggest adding a flag to the > compiler to enforce the absence ofunsafeRuinMyTypeSafety-alike functions in > order to be able to create systems in which code can be trusted by its type > alone. > > Nonetheless, this module is one step forward in trusting your own programs. > Some real http://tinyurl.com/paranoidpeople prefer writing there software > in one of the most insecure programming languages and perform security > audits by hand, I'd rather have my compiler do the job. (Anyone who wants to > audit this library is more than welcome!) > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090827/d685a718/attachment.html From ekirpichov at gmail.com Thu Aug 27 10:16:51 2009 From: ekirpichov at gmail.com (Eugene Kirpichov) Date: Thu Aug 27 09:56:30 2009 Subject: [Haskell-cafe] ANN: jail-0.0.1 - Jailed IO monad In-Reply-To: <9EEA7730-D953-41BE-86D3-2788518A5F2E@cs.uu.nl> References: <9EEA7730-D953-41BE-86D3-2788518A5F2E@cs.uu.nl> Message-ID: <5e0214850908270716p6ef1c528tb4c95ddf7163ce86@mail.gmail.com> Cool! However, it does not protect me from doing System.IO.Unsafe.unsafePerformIO in whatever fashion I like, does it? 2009/8/27 Sebastiaan Visser : > Hi all, > > I am very pleased to announce the first release of the jail[1,2] package. A > jailed IO monad that can restrict filesystem access for your code. This > package will soon be an integral part of the Salvia web server. (a new and > improved Salvia will be released soon) > > Basic documentation of the jail package is included below. > > Any comments, suggestions, audits, etc. are welcome! > > Gr, > > -- > Sebastiaan Visser > > [1] Source repo: http://github.com/sebastiaanvisser/jail/ > > [2] Hackage: http://hackage.haskell.org/package/jail > > > > -------- > > Like all of us know, the IO monad from the System.IO module is a wild beast > allowing all forms of insecure computations that can read, or even worse, > alter the real world. Writing to sockets, deleting files or even launching > missiles, its possibilities are endless. This library provides a special IO > module that wraps all file and handle based IO operations from the System.IO > module, but provides a possibility to run them in an restricted environment. > When running a jailed IO computation a file path can be specified all IO > operations will be checked against. Accessing files outside this directory > is not allowed and results in a runtime error. Additionally, when running a > jailed IO computation a whitelist of file handles can be specified that are > accessible as well. > > For example, running some code with the permission to access all files > within (and only within) my home directory and allowing to access the > standard output and standard error can be enforced like this: > > ?Jail.run (Just "/home/sebas") [stdout, stderr] yourUntrustworthyComputation > Only allowing the code to access the standard input and nothing else can be > enforced like this: > > ?Jail.run Nothing [stdin] yourEvenMoreUntrustworthyComputation > Because the jailed IO environment keeps track of all file handles and checks > that are opened by its own operations, smuggling in evil file handles from > the fierce and dangerous outside world will be punished by border patrol. > Only handles from the whitelist or handles securely opened by functions like > openFile will be accepted. Because of the opaque IO constructor and the > restricted set of exported operations this module is not easily fooled. > > I would almost dare to say this module is conceptually safe and code with > the jailed IO type can blindly be trusted. Except, yes unfortunately except, > unsafePerformIO ruins it all. I would almost suggest adding a flag to the > compiler to enforce the absence ofunsafeRuinMyTypeSafety-alike functions in > order to be able to create systems in which code can be trusted by its type > alone. > > Nonetheless, this module is one step forward in trusting your own programs. > Some real http://tinyurl.com/paranoidpeople prefer writing there software in > one of the most insecure programming languages and perform security audits > by hand, I'd rather have my compiler do the job. (Anyone who wants to audit > this library is more than welcome!) > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Eugene Kirpichov Web IR developer, market.yandex.ru From colin at colina.demon.co.uk Thu Aug 27 10:21:00 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Thu Aug 27 10:00:44 2009 Subject: [Haskell-cafe] Qualified operators Message-ID: What's the syntax for using a qualified operator (I have a clash of !)? -- Colin Adams Preston Lancashire From miguelimo38 at yandex.ru Thu Aug 27 10:22:52 2009 From: miguelimo38 at yandex.ru (Miguel Mitrofanov) Date: Thu Aug 27 10:04:12 2009 Subject: [Haskell-cafe] Qualified operators In-Reply-To: References: Message-ID: <4A9696BC.90003@yandex.ru> firstArgument Cool.Module.Name.%-& secondArgument Colin Paul Adams wrote: > What's the syntax for using a qualified operator (I have a clash of !)? From sfvisser at cs.uu.nl Thu Aug 27 10:39:09 2009 From: sfvisser at cs.uu.nl (Sebastiaan Visser) Date: Thu Aug 27 10:18:57 2009 Subject: [Haskell-cafe] ANN: jail-0.0.1 - Jailed IO monad In-Reply-To: <5e0214850908270716p6ef1c528tb4c95ddf7163ce86@mail.gmail.com> References: <9EEA7730-D953-41BE-86D3-2788518A5F2E@cs.uu.nl> <5e0214850908270716p6ef1c528tb4c95ddf7163ce86@mail.gmail.com> Message-ID: On Aug 27, 2009, at 4:16 PM, Eugene Kirpichov wrote: > Cool! > > However, it does not protect me from doing > System.IO.Unsafe.unsafePerformIO in whatever fashion I like, does it? Unfortunately not, hence my disclaimer: "I would almost dare to say this module is conceptually safe and code with the jailed IO type can blindly be trusted. Except, yes unfortunately except, unsafePerformIO ruins it all. I would almost suggest adding a flag to the compiler to enforce the absence ofunsafeRuinMyTypeSafety-alike functions in order to be able to create systems in which code can be trusted by its type alone." Hope there will once be a nice solution to this... -- Sebastiaan Visser 2009/8/27 Sebastiaan Visser : >> Hi all, >> >> I am very pleased to announce the first release of the jail[1,2] >> package. A >> jailed IO monad that can restrict filesystem access for your code. >> This >> package will soon be an integral part of the Salvia web server. (a >> new and >> improved Salvia will be released soon) >> >> Basic documentation of the jail package is included below. >> >> Any comments, suggestions, audits, etc. are welcome! >> >> Gr, >> >> -- >> Sebastiaan Visser >> >> [1] Source repo: http://github.com/sebastiaanvisser/jail/ >> >> [2] Hackage: http://hackage.haskell.org/package/jail >> >> ... From leimy2k at gmail.com Thu Aug 27 10:41:04 2009 From: leimy2k at gmail.com (David Leimbach) Date: Thu Aug 27 10:20:47 2009 Subject: [Haskell-cafe] ANN: jail-0.0.1 - Jailed IO monad In-Reply-To: References: <9EEA7730-D953-41BE-86D3-2788518A5F2E@cs.uu.nl> <5e0214850908270716p6ef1c528tb4c95ddf7163ce86@mail.gmail.com> Message-ID: <3e1162e60908270741q76b998c6rc0287134c5170ed7@mail.gmail.com> http://hackage.haskell.org/package/IOSpec <-- ? Looks kind of promising though I must confess I've never used it. Dave On Thu, Aug 27, 2009 at 7:39 AM, Sebastiaan Visser wrote: > On Aug 27, 2009, at 4:16 PM, Eugene Kirpichov wrote: > > Cool! >> >> However, it does not protect me from doing >> System.IO.Unsafe.unsafePerformIO in whatever fashion I like, does it? >> > > Unfortunately not, hence my disclaimer: > > "I would almost dare to say this module is conceptually safe and code with > the jailed IO type can blindly be trusted. Except, yes unfortunately except, > unsafePerformIO ruins it all. I would almost suggest adding a flag to the > compiler to enforce the absence ofunsafeRuinMyTypeSafety-alike functions in > order to be able to create systems in which code can be trusted by its type > alone." > > Hope there will once be a nice solution to this... > > -- > Sebastiaan Visser > > 2009/8/27 Sebastiaan Visser : > >> Hi all, >>> >>> I am very pleased to announce the first release of the jail[1,2] package. >>> A >>> jailed IO monad that can restrict filesystem access for your code. This >>> package will soon be an integral part of the Salvia web server. (a new >>> and >>> improved Salvia will be released soon) >>> >>> Basic documentation of the jail package is included below. >>> >>> Any comments, suggestions, audits, etc. are welcome! >>> >>> Gr, >>> >>> -- >>> Sebastiaan Visser >>> >>> [1] Source repo: http://github.com/sebastiaanvisser/jail/ >>> >>> [2] Hackage: http://hackage.haskell.org/package/jail >>> >>> ... >>> >> > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090827/55ac97f3/attachment.html From colin at colina.demon.co.uk Thu Aug 27 10:44:54 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Thu Aug 27 10:24:35 2009 Subject: [Haskell-cafe] Qualified operators In-Reply-To: <4A9696BC.90003@yandex.ru> (Miguel Mitrofanov's message of "Thu\, 27 Aug 2009 18\:22\:52 +0400") References: <4A9696BC.90003@yandex.ru> Message-ID: >>>>> "Miguel" == Miguel Mitrofanov writes: Miguel> firstArgument Cool.Module.Name.%-& secondArgument Thanks. I think I tried that first, must have have got misled by ghc's other confusing messages. Compiling ok now. -- Colin Adams Preston Lancashire From jvranish at gmail.com Thu Aug 27 10:47:43 2009 From: jvranish at gmail.com (Job Vranish) Date: Thu Aug 27 10:27:24 2009 Subject: [Haskell-cafe] Applicative and Monad transformers In-Reply-To: <4A955D1C.40605@van.steenbergen.nl> References: <87eiqyzjoc.wl%jeremy@n-heptane.com> <4A955D1C.40605@van.steenbergen.nl> Message-ID: You could test your instance using the checkers package on hackage (has quickcheck properties for common typeclasses) to see if it fulfills the applicative laws. But I'm not sure if it is acceptable to define applicative instances that don't match the monad instance. Does anyone know of libraries that depend on applicative instances matching their corresponding monad instance? I've often wanted an applicative instance for a datatype that didn't match the monad instance. For example, I find the "zipping" applicative list instance more useful than the current "choice" applicative list instance instance Applicative [] where pure x = repeat x fs <*> xs = zipWith ($) fs xs This actually also has a corresponding Monad instance (with a couple restrictions). It would be nice if there was a way to hide instances so that they could be redefined. - Job On Wed, Aug 26, 2009 at 12:04 PM, Martijn van Steenbergen < martijn@van.steenbergen.nl> wrote: > Jeremy Shaw wrote: > >> What I would prefer is: >> >> instance (Monad f, Applicative f) => Applicative (ReaderT r f) where >> pure a = ReaderT $ const (pure a) >> f <*> a = ReaderT $ \r -> ((runReaderT f r) <*> >> (runReaderT a r)) >> > > Right. This doesn't only go for ReaderT, it already goes for Either, too: > you don't want the 'ap' implementation for <*> there either. > > These are beautiful examples of how applicative style gives the caller less > power, but the callee more information, allowing more information to be > retained. In this case it allows you to concatenate errors using mappend. > > Another example is parsing: I believe Doaitse's parsers allow more > optimization if they are only used in applicative style (but I'm not sure of > this). > > This shows there can be several sensible implementations of a type class. > You ask which instance is right--that depends entirely on what you want it > to do! Setting (<*>) = ap is just one of them, one you happen to get for > free if your functor is already a monad. > > Hope this helps, > > Martijn. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090827/facb0c6e/attachment.html From johan.tibell at gmail.com Thu Aug 27 10:57:47 2009 From: johan.tibell at gmail.com (Johan Tibell) Date: Thu Aug 27 10:37:45 2009 Subject: [Haskell-cafe] ANN: scion 0.1 In-Reply-To: References: <90889fe70908270117s490a62ccs781758ab10169cc1@mail.gmail.com> Message-ID: <90889fe70908270757k75e25c60o2925657d9e381c41@mail.gmail.com> On Thu, Aug 27, 2009 at 11:44 AM, Thomas Schilling wrote: > On 27 Aug 2009, at 09:17, Johan Tibell wrote: >> Also, I tried to play with the scion-open-cabal-project function. I'm >> not sure I understand how it's intended to be used. Does it make sure >> that if you compile a file using C-c C-x C-l the right source >> directories are used? Could you give a usage example? > > I eventually want to get rid of it and let scion-load figure out itself when > the project needs to be reconfigured. ?At the moment you have to delete the > .dist-scion directory if you changed your .cabal file. :/ My question was probably a bit unclear so let me try to clarify it. What's the purpose of scion-open-cabal-project? Does it set the include path used for subsequent scion-loads? What's the ".dist-scion" directory and how does it differ from the normal "dist" directory? >> One problem I frequently have with emacs-mode is that you can't use it >> to load a file if >> >> ?* your sources don't live in the same directory as the Cabal file, or > > Actually, the latest version of haskell-mode has some heuristics. ?It sets > the working directory to where the .cabal file lives. Right. I meant if I don't root my source files in the same directory as the Cabal file it won't work. Cheers, Johan From colin at colina.demon.co.uk Thu Aug 27 11:09:18 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Thu Aug 27 10:48:58 2009 Subject: [Haskell-cafe] Problem with monadic formlets Message-ID: I'm trying to validate user input against a database (using HaskellDB, but that doesn't seem to be the problem, as replacing the database monadic code with return True gives the same problem. This is part of my code: register :: Database -> XForm Registration --register db = Registration <$> pure_user <*> passConfirmed register db = Registration <$> (user db) <*> passConfirmed user :: Database -> XForm String user db = pure_user `F.checkM` F.ensureM valid error where valid name = do let q = do t <- table user_table restrict (t!user_name .==. constant name) return t rs <- query db q return $ null rs error = "Username already exists in the database!" pure_user :: XForm String pure_user = input `F.check` F.ensure valid error where input = "Username" `label` F.input Nothing valid = (>= 3) . length error = "Username must be three characters or longer." passConfirmed :: XForm String passConfirmed = fst <$> passwords `F.check` F.ensure equal error where passwords = (,) <$> pass "Password" <*> pass "Password (confirm)" equal (a, b) = a == b error = "The entered passwords do not match!" pass :: String -> XForm String pass caption = input `F.check` F.ensure valid error where input = caption `label` F.password Nothing valid = (>=6) . length error = "Password must be six characters or longer." If I uncomment the commented line, and comment out the line after it (in register), then everything works as expected. However, using it as it is, one of the calls to pass gets the user's name for validation (and consequently either fails if the user name is only 5 characters, or the comparison of the two passwords fail (unless I type the user name as the password). I thought the applicative style meant the effects did not influence one another, but here there is clear contamination. What am i doing wrong? -- Colin Adams Preston Lancashire From stephen.tetley at gmail.com Thu Aug 27 13:50:17 2009 From: stephen.tetley at gmail.com (Stephen Tetley) Date: Thu Aug 27 13:29:57 2009 Subject: [Haskell-cafe] Mapping over multiple values of a list at once? In-Reply-To: References: <32478061.199701251361140344.JavaMail.servlet@kundenserver> Message-ID: <5fdc56d70908271050o74ebff57l948bf6be7faba0bd@mail.gmail.com> Hi Max How about a paramorphism? slideAvg3 :: [Int] -> [Int] slideAvg3 = para phi [] where phi x ((y:z:_),acc) = average3 x y z : acc phi x (_,acc) = acc -- helpers -- paramorphism (generalizes catamorphism (fold)) para :: (a -> ([a], b) -> b) -> b -> [a] -> b para phi b [] = b para phi b (x:xs) = phi x (xs, para phi b xs) average3 :: Int -> Int -> Int -> Int average3 a b c = round $ (fromIntegral $ a+b+c)/3 I haven't tested for efficiency though. Best wishes Stephen 2009/8/27 Max Rabkin : > > However, we don't really need the sliding windows themselves, just the > sliding sum. There might be a slightly more efficient way to do that, > but I'll leave it as an exercise for you or somebody else. > > --Max From haskell at rohanlean.de Thu Aug 27 14:04:47 2009 From: haskell at rohanlean.de (Rohan Lean) Date: Thu Aug 27 13:49:43 2009 Subject: [Haskell-cafe] Inexplicable allocation Message-ID: Hello, this is my first posting to this List, I hope everything goes well. Seeing that the haskell is currently poorly represented in the fasta benchmark at http://shootout.alioth.debian.org/u64q/benchmark.php?test=fasta&lang=all , I decided to help out the contributors a bit. My draft already performs considerably better than the current program, but while optimizing I ran into a weird problem. I already reported this as a ghc bug, but on IRC I was encouraged to also describe my problem here. Source of the program: http://rohanlean.de/pub/ghc_alloc/fasta.hs Core: http://rohanlean.de/pub/ghc_alloc/fasta.core Relevant port of the core (`gen' with inlined `pick'): http://rohanlean.de/pub/ghc_alloc/fasta_snip.core Running with the -p option suggested that `gen' and `pick' allocate a lot of memory throughout the run of the program (that memory is not retained). I managed to confirm that for non-profiling builds by observing how the the output of -sstderr changed when I modified `gen' to call itself fewer times. This came as a surprise, because expected these two functions to be completely allocation free, and the core does not suggest any allocation to me. I would very much welcome explanations for these reported allocations. Thank you, Rohan Lean From simonkaltenbacher at googlemail.com Thu Aug 27 15:24:14 2009 From: simonkaltenbacher at googlemail.com (SimonK77) Date: Thu Aug 27 15:03:53 2009 Subject: Re[Haskell-cafe] duction Sequence of simple Fibonacci sequence implementation Message-ID: <25178377.post@talk.nabble.com> Hallo everyone, as Haskell uses the Lazy Evaluation reduction policy also known as Outermost Graph Reduction, I was wondering if the following simple implementation of the Fibonacci sequence would result in linear runtime behaviour. fib :: Integer -> Integer fib 0 = 0 fib 1 = 1 fib n = fib (n - 2) + fib (n - 1) Is the following reduction sequence realistic, or am I admitting to much intelligence to the Haskell Compiler? http://www.bilder-hochladen.net/files/bxlk-6-jpg.html http://www.bilder-hochladen.net/files/thumbs/bxlk-6.jpg I hope someone can help... -- View this message in context: http://www.nabble.com/Reduction-Sequence-of-simple-Fibonacci-sequence-implementation-tp25178377p25178377.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090827/b03f8d40/attachment-0001.html From bulat.ziganshin at gmail.com Thu Aug 27 15:32:08 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Aug 27 15:11:57 2009 Subject: Re[Haskell-cafe] duction Sequence of simple Fibonacci sequence implementation In-Reply-To: <25178377.post@talk.nabble.com> References: <25178377.post@talk.nabble.com> Message-ID: <1375440851.20090827233208@gmail.com> Hello SimonK77, Thursday, August 27, 2009, 11:24:14 PM, you wrote: for linear timing it needs memoization of previous results. haskell compilers doesn't do it automatically since it may change space properties of program. well-known example is: main = print (sum[1..1000] + prod[1..1000]) in order to use memoization you should declare fib as array: fib = array (1,999) ([1,1]++map (\i -> fib!(i-1) + fib!(i-2)) [3..999]) > Hallo everyone, > as Haskell uses the Lazy Evaluation reduction policy also known > as Outermost Graph Reduction, I was wondering if the following > simple implementation of the Fibonacci sequence would result in linear runtime behaviour. > fib :: Integer -> Integer > fib 0 = 0 > fib 1 = 1 > fib n = fib (n - 2) + fib (n - 1) > Is the following reduction sequence realistic, or am I admitting > to much intelligence to the Haskell Compiler? > I hope someone can help... > View this message in context: Reduction Sequence of simple Fibonacci sequence implementation > Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. > -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From haskell at rohanlean.de Thu Aug 27 15:34:43 2009 From: haskell at rohanlean.de (Rohan Lean) Date: Thu Aug 27 15:14:46 2009 Subject: [Haskell-cafe] Re: Reduction Sequence of simple Fibonacci sequence implementation References: <25178377.post@talk.nabble.com> Message-ID: SimonK77 googlemail.com> writes: > as Haskell uses the Lazy Evaluation reduction policy also known as Outermost Graph Reduction, I was wondering if the following simple implementation of the Fibonacci sequence would result in linear runtime behaviour. > > fib :: Integer -> Integer > fib 0 = 0 > fib 1 = 1 > fib n = fib (n - 2) + fib (n - 1) > > Is the following reduction sequence realistic, or am I admitting to much intelligence to the Haskell Compiler? You are, as easily seen when you try to calculate (fib 30). A version that works: import Data.MemoTrie fib :: Integer -> Integer fib = memo \n -> case n of 0 -> 0 1 -> 1 n -> fib (n-1) + fib (n-2) From dagit at codersbase.com Thu Aug 27 15:41:49 2009 From: dagit at codersbase.com (Jason Dagit) Date: Thu Aug 27 15:21:27 2009 Subject: Re[Haskell-cafe] duction Sequence of simple Fibonacci sequence implementation In-Reply-To: <1375440851.20090827233208@gmail.com> References: <25178377.post@talk.nabble.com> <1375440851.20090827233208@gmail.com> Message-ID: On Thu, Aug 27, 2009 at 12:32 PM, Bulat Ziganshin wrote: > Hello SimonK77, > > Thursday, August 27, 2009, 11:24:14 PM, you wrote: > > for linear timing it needs memoization of previous results. haskell > compilers doesn't do it automatically since it may change space > properties of program. well-known example is: > > main = print (sum[1..1000] + prod[1..1000]) > > in order to use memoization you should declare fib as array: > > fib = array (1,999) ([1,1]++map (\i -> fib!(i-1) + fib!(i-2)) [3..999]) Unless I'm mistaken this one is also memoized and simpler: fibs = 1 : 1 : zipWith (+) fibs (tail fibs) Then to get a specific fib, zero index, you do: fib n = fibs !! n Jason From bulat.ziganshin at gmail.com Thu Aug 27 15:42:18 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Aug 27 15:22:32 2009 Subject: Re[Haskell-cafe] duction Sequence of simple Fibonacci sequence implementation In-Reply-To: <25178377.post@talk.nabble.com> References: <25178377.post@talk.nabble.com> Message-ID: <971856457.20090827234218@gmail.com> Hello SimonK77, Thursday, August 27, 2009, 11:24:14 PM, you wrote: list-based memoization for fibs should look as fibs = 1 : 1 : map (sum.take 2) (tails fibs) > Hallo everyone, > as Haskell uses the Lazy Evaluation reduction policy also known > as Outermost Graph Reduction, I was wondering if the following > simple implementation of the Fibonacci sequence would result in linear runtime behaviour. > fib :: Integer -> Integer > fib 0 = 0 > fib 1 = 1 > fib n = fib (n - 2) + fib (n - 1) > Is the following reduction sequence realistic, or am I admitting > to much intelligence to the Haskell Compiler? > I hope someone can help... > View this message in context: Reduction Sequence of simple Fibonacci sequence implementation > Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. > -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From daniel.is.fischer at web.de Thu Aug 27 16:04:22 2009 From: daniel.is.fischer at web.de (Daniel Fischer) Date: Thu Aug 27 15:45:02 2009 Subject: Re[Haskell-cafe] duction Sequence of simple Fibonacci sequence implementation In-Reply-To: References: <25178377.post@talk.nabble.com> <1375440851.20090827233208@gmail.com> Message-ID: <200908272204.22461.daniel.is.fischer@web.de> Am Donnerstag 27 August 2009 21:41:49 schrieb Jason Dagit: > On Thu, Aug 27, 2009 at 12:32 PM, Bulat > > Ziganshin wrote: > > Hello SimonK77, > > > > Thursday, August 27, 2009, 11:24:14 PM, you wrote: > > > > for linear timing it needs memoization of previous results. haskell > > compilers doesn't do it automatically since it may change space > > properties of program. well-known example is: > > > > main = print (sum[1..1000] + prod[1..1000]) > > > > in order to use memoization you should declare fib as array: > > > > fib = array (1,999) ([1,1]++map (\i -> fib!(i-1) + fib!(i-2)) [3..999]) > > Unless I'm mistaken this one is also memoized and simpler: > fibs = 1 : 1 : zipWith (+) fibs (tail fibs) Should be fibs = 0:1:zipWith (+) fibs (tail fibs) of course. > > Then to get a specific fib, zero index, you do: > fib n = fibs !! n > > Jason From jeremy at n-heptane.com Thu Aug 27 16:37:14 2009 From: jeremy at n-heptane.com (Jeremy Shaw) Date: Thu Aug 27 16:16:52 2009 Subject: [Haskell-cafe] Problem with monadic formlets In-Reply-To: References: Message-ID: <878wh5yow5.wl%jeremy@n-heptane.com> Hello, I hacked your code into a runnable example, and it seems to work for me. What happens if you do something like: let (c, xml, _) = runFormState [("input0",Left "name"), ("input1", Left "password"), ("input2", Left "password") ] "" (register "foo") in c >>= \r -> do print xml >> print r (except you need to pass in a Database instead of "foo" as the argument to register.) I get: Success (Registration "name" "password") Which looks correct to me. Your code looks fine to me as well... Perhaps the error is not in the code you pasted, but somewhere else. I am running on an older, and somewhat forked version of Formlets, so there could also be a bug in the new code I guess. Though, that seems unlikely. But it is worth noting that we are not using the same version of the formlets library. - jeremy At Thu, 27 Aug 2009 16:09:18 +0100, Colin Paul Adams wrote: > > I'm trying to validate user input against a database (using HaskellDB, > but that doesn't seem to be the problem, as replacing the database > monadic code with return True gives the same problem. > > This is part of my code: > > register :: Database -> XForm Registration > --register db = Registration <$> pure_user <*> passConfirmed > register db = Registration <$> (user db) <*> passConfirmed > > user :: Database -> XForm String > user db = pure_user `F.checkM` F.ensureM valid error where > valid name = do > let q = do > t <- table user_table > restrict (t!user_name .==. constant name) > return t > rs <- query db q > return $ null rs > error = "Username already exists in the database!" > > pure_user :: XForm String > pure_user = input `F.check` F.ensure valid error where > input = "Username" `label` F.input Nothing > valid = (>= 3) . length > error = "Username must be three characters or longer." > > passConfirmed :: XForm String > passConfirmed = fst <$> passwords `F.check` F.ensure equal error where > passwords = (,) <$> pass "Password" <*> pass "Password (confirm)" > equal (a, b) = a == b > error = "The entered passwords do not match!" > > pass :: String -> XForm String > pass caption = input `F.check` F.ensure valid error where > input = caption `label` F.password Nothing > valid = (>=6) . length > error = "Password must be six characters or longer." > > If I uncomment the commented line, and comment out the line after it > (in register), then everything works as expected. However, using it as > it is, one of the calls to pass gets the user's name for validation > (and consequently either fails if the user name is only 5 characters, > or the comparison of the two passwords fail (unless I type the user > name as the password). > > I thought the applicative style meant the effects did not influence > one another, but here there is clear contamination. What am i doing wrong? > -- > Colin Adams > Preston Lancashire > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe From vanenkj at gmail.com Thu Aug 27 16:44:40 2009 From: vanenkj at gmail.com (John Van Enk) Date: Thu Aug 27 16:31:44 2009 Subject: [Haskell-cafe] Killing a thread blocking on a foreign call Message-ID: Hi List, I'm trying to kill a thread (during program cleanup) that is almost always going to be perma-blocking on a foreign call (read). It seems that there's no facility to do this built into Haskell at this point, or is there? /jve -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090827/b19c30d7/attachment.html From sylvain.nahas at googlemail.com Thu Aug 27 16:52:30 2009 From: sylvain.nahas at googlemail.com (sylvain) Date: Thu Aug 27 16:32:16 2009 Subject: [Haskell] Re: [Haskell-cafe] ANNOUNCE: jhc 0.7.1 In-Reply-To: References: <20090825041336.GI18852@sliver.repetae.net> Message-ID: <1251406350.4998.13.camel@dell.linuxdev.us.dell.com> > There should be no excuses for not giving jhc a whirl. Agreed. In a lot of ways, jhc seems like a Haskell compiler done right. It generates very fast and lean binaries - using C as an intermediary language - which makes it a natural cross-compiler and indicates it should not be too difficult to write a back-end for the CIL and the jvm. On the other hand, it is still far away from GHC features-wise. So there is definitively room for people looking to contribute to a compiler with a high potential. Wouldn't that be fun? Sylvain. From ia at stryx.demon.co.uk Thu Aug 27 20:01:09 2009 From: ia at stryx.demon.co.uk (Iain Alexander) Date: Thu Aug 27 19:48:40 2009 Subject: [Haskell-cafe] Applicative and Monad transformers In-Reply-To: <200908270748.40317.ralf.hinze@comlab.ox.ac.uk> Message-ID: <4A972C55.18402.C32239@ia.stryx.demon.co.uk> On 27 Aug 2009 at 07:48, Ralf Hinze wrote: > \ x -> (v >>= \ a -> return ((u x) a)) x > = { definition of >>= } > \ x -> (\ a -> return ((u x) a)) (v x) x > Something seems to have gone wrong here - shouldn't that be \x -> (\y -> (\a -> return ((u x) a)) (v y) y) x = { beta } \x -> (\a -> return ((u x) a)) (v x) x ? ... but then we appear to end up in the same place. Now all I've got to do is figure out what you were trying to establish in the first place. :-) I don't entirely follow what the OP's up to, so you may have a point, but it's far from clear. You're talking about the reader monad, whereas he's talking about the effects in the ReaderT-transformed monad. -- Iain Alexander ia@stryx.demon.co.uk From lennart at augustsson.net Thu Aug 27 20:45:04 2009 From: lennart at augustsson.net (Lennart Augustsson) Date: Thu Aug 27 20:24:43 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: <8763cbx1hl.fsf@malde.org> References: <20090822170352.5A3C53245AF@www.haskell.org> <1251024096.2246.21.camel@localhost> <5e0214850908230412s199c79absc66f47e03a539eb7@mail.gmail.com> <1251034068.3085.55.camel@localhost> <8763cbx1hl.fsf@malde.org> Message-ID: Prelude> toRational 697.04157958259998 3065621287177675 % 4398046511104 Prelude> toRational 697.0415795826 3065621287177675 % 4398046511104 As you can see, both numbers are represented by the same Double. Haskell prints a Double with the simplest number that converts back to the same bit pattern. So there's no "keep more decimals", just a matter of string conversion. -- Lennart On Tue, Aug 25, 2009 at 7:11 PM, Ketil Malde wrote: > Steve writes: > >> Also, I had a problem using floating point in Python where >>>>> round(697.04157958254996, 10) >> gave >> 697.04157958259998 > >> Its been fixed in the latest versions of Python: >>>>> round(697.04157958254996, 10) >> 697.0415795825 > >> ghci> roundN 697.04157958254996 10 >> 697.0415795826 > > Is there something special with this number? > > ?Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > ?[GCC 4.3.3] on linux2 > ?Type "help", "copyright", "credits" or "license" for more information. > ?>>> 697.04157958259998 > ?697.04157958259998 > ?>>> 12345.678901234567890 > ?12345.678901234567 > > ?GHCi, version 6.8.2: http://www.haskell.org/ghc/ ?:? for help > ?Loading package base ... linking ... done. > ?Prelude> 697.04157958259998 > ?697.0415795826 > ?Prelude> 12345.678901234567890 > ?12345.678901234567 > > So, Python manages to keep more decimals than GHC for your number, but > for other numbers, the precision appears to be the same. > > -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 > From jeremy at n-heptane.com Thu Aug 27 21:49:21 2009 From: jeremy at n-heptane.com (Jeremy Shaw) Date: Thu Aug 27 21:28:59 2009 Subject: [Haskell-cafe] Applicative and Monad transformers In-Reply-To: <4A972C55.18402.C32239@ia.stryx.demon.co.uk> References: <200908270748.40317.ralf.hinze@comlab.ox.ac.uk> <4A972C55.18402.C32239@ia.stryx.demon.co.uk> Message-ID: <877hwozp0e.wl%jeremy@n-heptane.com> At Fri, 28 Aug 2009 01:01:09 +0100, > I don't entirely follow what the OP's up to, so you may have a point, but it's > far from clear. You're talking about the reader monad, whereas he's talking > about the effects in the ReaderT-transformed monad. oops. Apparently I forgot to explictly state the issue :) I am using ReaderT to lookup symbols in an environment. I am using the inner monad/applicative functor to record whether the lookup failed or succeeded. So I essential have the type: > ReaderT [(a,b)] (Either [a]) b [(a,b)] is the environment. In the end I get back a value: Either [a] b where [a] is all the symbols that weren't found or 'b' is the final value. For example, if I have: looker :: ReaderT [(String, Int)] (Either [String]) (Int, Int, Int) looker = ((,,) <$> look "foo" <*> look "bar" <*> look "baz") and none of the symbols are in the enviroment then I should get: Left ["foo", "bar", "baz"] The issue is that if I use the free (?) applicative functor instance for ReaderT then I only get back the *first* failure: Left ["foo"] But, if I used my alternative definition, then I get back all the failures. My concern is that my alternative version was somehow violating an applicative functor law. My secondary concern was the free version was somehow violating a law. It seems though, that both are valid... - jeremy From jeremy at n-heptane.com Thu Aug 27 21:57:32 2009 From: jeremy at n-heptane.com (Jeremy Shaw) Date: Thu Aug 27 21:37:10 2009 Subject: [Haskell-cafe] Applicative and Monad transformers In-Reply-To: References: <87eiqyzjoc.wl%jeremy@n-heptane.com> <4A955D1C.40605@van.steenbergen.nl> Message-ID: <8763c8zomr.wl%jeremy@n-heptane.com> At Thu, 27 Aug 2009 10:47:43 -0400, Job Vranish wrote: > I've often wanted an applicative instance for a datatype that didn't match > the monad instance. > It would be nice if there was a way to hide instances so that > they could be redefined. Yeah, this is similar to the issue of multiple sensible instances for Data.Monoid. This issue has come up several times for me recently. A bit of a shortcoming in the type class design I think. There was once a proposal to help address this, but it never gained tracation: http://scholar.google.com/scholar?hl=en&lr=&cluster=8306039955712318110&um=1&ie=UTF-8&ei=JTmXSvmTJ4a4M6TJlfkN&sa=X&oi=science_links&resnum=1&ct=sl-allversions Recently I have wondered if module functors might somehow be a solution somehow. But I have not actually investigated at all. - jeremy From nfjinjing at gmail.com Fri Aug 28 01:08:58 2009 From: nfjinjing at gmail.com (Jinjing Wang) Date: Fri Aug 28 00:48:35 2009 Subject: [Haskell-cafe] ANN: moe html combinator Message-ID: <81ea7d400908272208r43193b39r6eb1372545020b5c@mail.gmail.com> hand written html is fine, except for the closing tags: what if html' - do head' - do meta [http_equiv "Content-Type", content "text/html; charset-utf-8"] (/) title' - str "my title" link [rel "icon", _type "image/png", href "panda_icon.png"] (/) body' - do div [_class "container"] - do str "hello world" produces my title
hello world
That's moe. There's also extra dsl sugar / flavors for your convienence, including (currently available) markdown and kawaii. It's a new library, tries to bring some haskell fun back to web programming, so .. enjoy. - moe: http://hackage.haskell.org/package/moe -- jinjing From bulat.ziganshin at gmail.com Fri Aug 28 01:28:09 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Aug 28 01:07:51 2009 Subject: [Haskell-cafe] ANN: moe html combinator In-Reply-To: <81ea7d400908272208r43193b39r6eb1372545020b5c@mail.gmail.com> References: <81ea7d400908272208r43193b39r6eb1372545020b5c@mail.gmail.com> Message-ID: <1344735757.20090828092809@gmail.com> Hello Jinjing, Friday, August 28, 2009, 9:08:58 AM, you wrote: > hand written html is fine, except for the closing tags: may be it's possible to omit them using type machinery? > link [rel "icon", _type "image/png", href "panda_icon.png"] (/) it contains unpredictable mix of xxx', _xxx and xxx identifiers. how about using the same style, say _xxx, for everything? and stop reusing Prelude operators, in particular, replace "-" with "$"? -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From colin at colina.demon.co.uk Fri Aug 28 02:06:05 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Fri Aug 28 01:45:45 2009 Subject: [Haskell-cafe] Problem with monadic formlets In-Reply-To: <878wh5yow5.wl%jeremy@n-heptane.com> (Jeremy Shaw's message of "Thu\, 27 Aug 2009 15\:37\:14 -0500") References: <878wh5yow5.wl%jeremy@n-heptane.com> Message-ID: >>>>> "Jeremy" == Jeremy Shaw writes: Jeremy> Hello, I hacked your code into a runnable example, and it Jeremy> seems to work for me. Jeremy> Which looks correct to me. Your code looks fine to me as Jeremy> well... Perhaps the error is not in the code you pasted, Jeremy> but somewhere else. I am running on an older, and somewhat Jeremy> forked version of Formlets, so there could also be a bug Jeremy> in the new code I guess. Though, that seems unlikely. But Jeremy> it is worth noting that we are not using the same version Jeremy> of the formlets library. I did some debugging in ghci, but was unable to step through the ensure and check routines, which is where the apparent data corruprion is occurring. I am suspecting a bug in the formlets library (I have version 0.6). So I have created a slightly cut-down (no database involved) complete working program. Can you see if this works ok with your version of formlets: module Main where import Control.Applicative import Control.Applicative.Error import Control.Applicative.State import Data.List as List import Text.Formlets import qualified Text.XHtml.Strict.Formlets as F import qualified Text.XHtml.Strict as X import Text.XHtml.Strict ((+++), (<<)) import Happstack.Server type XForm a = F.XHtmlForm IO a data Registration = Registration { regUser :: String , regPass :: String } deriving Show handleRegistration :: ServerPartT IO Response handleRegistration = withForm "register" register showErrorsInline (\u -> okHtml $ regUser u ++ " is successfully registered") withForm :: String -> XForm a -> (X.Html -> [String] -> ServerPartT IO Response) -> (a -> ServerPartT IO Response) -> ServerPartT IO Response withForm name frm handleErrors handleOk = dir name $ msum [ methodSP GET $ createForm [] frm >>= okHtml , withDataFn lookPairs $ \d -> methodSP POST $ handleOk' $ simple d ] where handleOk' d = do let (extractor, html, _) = runFormState d frm v <- liftIO extractor case v of Failure faults -> do f <- createForm d frm handleErrors f faults Success s -> handleOk s simple d = List.map (\(k,v) -> (k, Left v)) d showErrorsInline :: X.Html -> [String] -> ServerPartT IO Response showErrorsInline renderedForm errors = okHtml $ X.toHtml (show errors) +++ renderedForm createForm :: Env -> XForm a -> ServerPartT IO X.Html createForm env frm = do let (extractor, xml, endState) = runFormState env frm xml' <- liftIO xml return $ X.form X.! [X.method "POST"] << (xml' +++ X.submit "submit" "Submit") okHtml :: (X.HTML a) => a -> ServerPartT IO Response okHtml content = ok $ toResponse $ htmlPage $ content htmlPage :: (X.HTML a) => a -> X.Html htmlPage content = (X.header << (X.thetitle << "Testing forms")) +++ (X.body << content) register :: XForm Registration register = Registration <$> user <*> passConfirmed user :: XForm String user = pure_user `F.checkM` F.ensureM valid error where valid name = return True error = "Username already exists in the database!" pure_user :: XForm String pure_user = input `F.check` F.ensure valid error where input = "Username" `label` F.input Nothing valid = (>= 3) . length error = "Username must be three characters or longer." passConfirmed :: XForm String passConfirmed = fst <$> passwords `F.check` F.ensure equal error where passwords = (,) <$> pass "Password" <*> pass "Password (confirm)" equal (a, b) = a == b error = "The entered passwords do not match!" pass :: String -> XForm String pass caption = input `F.check` F.ensure valid error where input = caption `label` F.password Nothing valid = (>=6) . length error = "Password must be six characters or longer." label :: String -> XForm String -> XForm String label l = F.plug (\xhtml -> X.p << (X.label << (l ++ ": ") +++ xhtml)) main = simpleHTTP (nullConf {port = 9959}) handleRegistration -- Colin Adams Preston Lancashire From jason.dusek at gmail.com Fri Aug 28 02:11:40 2009 From: jason.dusek at gmail.com (Jason Dusek) Date: Fri Aug 28 01:51:17 2009 Subject: [Haskell-cafe] ANN: moe html combinator In-Reply-To: <1344735757.20090828092809@gmail.com> References: <81ea7d400908272208r43193b39r6eb1372545020b5c@mail.gmail.com> <1344735757.20090828092809@gmail.com> Message-ID: <42784f260908272311r4ea6910s289870b8c960dcde@mail.gmail.com> 2009/08/27 Bulat Ziganshin : > ...stop reusing Prelude operators, in particular, replace "-" > with "$"? I have to say, the `$ do` construct is an eyesore and `- do` is a lot easier on the eyes. Would it introduce ambiguity in the Haskell grammar if foo do... foo case... foo if... were always parsed as: foo (do...) foo (case...) foo (if...) This is what is usually meant. -- Jason Dusek From ketil at malde.org Fri Aug 28 03:24:03 2009 From: ketil at malde.org (Ketil Malde) Date: Fri Aug 28 03:03:17 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: (Lennart Augustsson's message of "Fri\, 28 Aug 2009 02\:45\:04 +0200") References: <20090822170352.5A3C53245AF@www.haskell.org> <1251024096.2246.21.camel@localhost> <5e0214850908230412s199c79absc66f47e03a539eb7@mail.gmail.com> <1251034068.3085.55.camel@localhost> <8763cbx1hl.fsf@malde.org> Message-ID: <8763c8jt9o.fsf@malde.org> Lennart Augustsson writes: > Prelude> toRational 697.04157958259998 > 3065621287177675 % 4398046511104 > Prelude> toRational 697.0415795826 > 3065621287177675 % 4398046511104 > As you can see, both numbers are represented by the same Double. > Haskell prints a Double with the simplest number that converts back to > the same bit pattern. > So there's no "keep more decimals", just a matter of string conversion. What puzzled me (and the parent article indicated), was that Python appeared to be able to work with more precision, and thus be more "numerically correct" than GHC. Since it's all machine precision floating point, this is even more strange, and I couldn't reproduce the behavior for any other numbers than the one used in the example. One test that I *didn't* make is this one: Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 697.0415795826 697.04157958259998 So yes - it's just a matter of Python printing the number as 697.04157958259998, while GHC prints it as 697.0415795826. Thanks for clarifying, and apologies for the confusion. >>> Its been fixed in the latest versions of Python: >>>>>> round(697.04157958254996, 10) >>> 697.0415795825 I get (Python 2.6.2): >>> round(697.04157958254996,10) 697.04157958259998 >>> ghci> roundN 697.04157958254996 10 >>> 697.0415795826 I suppose it is likely that 697.04157958254996 is closer to the real decimal value of this particular number than GHC's representation, which is 697.04157958255. Whether this is a problem is a different matter, and I'm curious what programs usefully depend on one behavior or the other in decimal rounding near the limit of precision. -k -- If I haven't seen further, it is by standing in the footprints of giants From jon.fairbairn at cl.cam.ac.uk Fri Aug 28 04:53:30 2009 From: jon.fairbairn at cl.cam.ac.uk (Jon Fairbairn) Date: Fri Aug 28 04:33:25 2009 Subject: [Haskell-cafe] Re: Mapping over multiple values of a list at once? References: <32478061.199701251361140344.JavaMail.servlet@kundenserver> <6d961e560908270341r29c313c3hcaeb6835fa092f1a@mail.gmail.com> Message-ID: Raynor Vliegendhart writes: > Just wondering, what should be the expected output be of something > like mavg 4 [1..3]? [3%2] or []? [0%1, 1%4, 3%4, 3%2, 3%2, 5%4, 3%4, 0%1], of course ;-P -- J?n Fairbairn Jon.Fairbairn@cl.cam.ac.uk From kowey at darcs.net Fri Aug 28 05:14:27 2009 From: kowey at darcs.net (Eric Y. Kow) Date: Fri Aug 28 04:54:06 2009 Subject: [Haskell-cafe] tomorrow: Edinburgh Meetup (Sat 29 Aug) and Hack Day (Sun 30 Aug) Message-ID: <20090828091427.GE36022@dewdrop.local> Dear Haskellers, Last minute reminder: We will be having a Hack Day in Edinburgh on Sunday 30 August (ICFP venue). That's this weekend! For the interested, we will also be meeting up the day before 09:30 Saturday 29 August just outside the RCPE (ie. the ICFP venue again). We'll have a quick wander and hopefully find some nice places to sit, chat and hack. On Sunday the real Hack Day begins at the ICFP venue, rooms 4/5. http://www.haskell.org/haskellwiki/Hac7 And for the interested, Brent says: > I'll be there Saturday morning---looking forward to meeting people! > > Also, I have purchased a ticket to hear a concert of some 16th-century > a capella 16th-century music at the Canongate Kirk at 5pm on Saturday: > > http://www.edfringe.com/ticketing/detail.php?id=13649 > > Just thought I'd mention it, so if there's anyone else coming to the > meetup day and 16th-century a capella sounds like your cup of tea, you > can get a ticket too and we can go together. Looking forward to seeing you, Eric PS. Bring a name tag if you've got one. There are about 15 people registered so far. It's not too late to register! (yes, you could also just drop by...) -- Eric Kow PGP Key ID: 08AC04F9 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 194 bytes Desc: not available Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090828/bd6ab36f/attachment.bin From colin at colina.demon.co.uk Fri Aug 28 05:25:54 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Fri Aug 28 05:05:31 2009 Subject: [Haskell-cafe] Uninstall a cabal package? Message-ID: What is the procedure to uninstall a cabal package? -- Colin Adams Preston Lancashire From g.c.stavenga at uu.nl Fri Aug 28 05:54:38 2009 From: g.c.stavenga at uu.nl (staafmeister) Date: Fri Aug 28 05:34:14 2009 Subject: Re[Haskell-cafe] duction Sequence of simple Fibonacci sequence implementation In-Reply-To: References: <25178377.post@talk.nabble.com> Message-ID: <25187256.post@talk.nabble.com> Thanks for the memo trick! Now I understand that the haskell compiler cannot memoize functions of integers, because it could change the space behaviour. However I think it could memoize everything else. Because all types that are data objects sitting in memory (so the arg is essentially a reference) can be memoized, without changing the space properties (except for overall constants). Does haskell do this? And if it doesn't can you turn it on? Cheers, Gerben -- View this message in context: http://www.nabble.com/Reduction-Sequence-of-simple-Fibonacci-sequence-implementation-tp25178377p25187256.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From bulat.ziganshin at gmail.com Fri Aug 28 06:10:43 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Aug 28 05:58:13 2009 Subject: Re[Haskell-cafe] duction Sequence of simple Fibonacci sequence implementation In-Reply-To: <25187256.post@talk.nabble.com> References: <25178377.post@talk.nabble.com> <25187256.post@talk.nabble.com> Message-ID: <288877954.20090828141043@gmail.com> Hello staafmeister, Friday, August 28, 2009, 1:54:38 PM, you wrote: it just works other way. imagine a whole haskell program as a graph. i.e. expression 1+2, for example, forms a node with (=) in its root and 1 and 2 as its subtrees. computation of program is a series of graph reductions, replacing nodes with results, f.e. 1+2 => 3 this graph can share computations in only one way - when you give sharec node a name and use this name twice. for example, the following sum[1..1000] + prod[1..1000] don't share anything, but this let list = [1..1000] in sum list + prod list share the list. performing sharing via explicit naming common subexpressions is the only way to memoize results you imagine something highly inefficient like storing results of every computation ever done. are you think it really makes a sense? sometimes haskell compilers may deduce that some computation is used twice. if result of this computation definitely require less memory than computation itself, compiler may perform optimization by storing its result. it's called Common Subexpression Elimination. but its' not guaranteed, and afaik is pretty limited in ghc > Thanks for the memo trick! Now I understand that the haskell compiler > cannot memoize functions of integers, because it could change the space > behaviour. However I think it could memoize everything else. Because all > types that are data objects sitting in memory (so the arg is essentially a > reference) > can be memoized, without changing the space properties (except for overall > constants). Does haskell do this? And if it doesn't can you turn it on? > Cheers, Gerben -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From lrpalmer at gmail.com Fri Aug 28 06:28:02 2009 From: lrpalmer at gmail.com (Luke Palmer) Date: Fri Aug 28 06:07:38 2009 Subject: Re[Haskell-cafe] duction Sequence of simple Fibonacci sequence implementation In-Reply-To: <25187256.post@talk.nabble.com> References: <25178377.post@talk.nabble.com> <25187256.post@talk.nabble.com> Message-ID: <7ca3f0160908280328w4559e620s999ec31d0629e914@mail.gmail.com> On Fri, Aug 28, 2009 at 3:54 AM, staafmeister wrote: > Thanks for the memo trick! Now I understand that the haskell compiler > cannot memoize functions of integers, because it could change the space > behaviour. However I think it could memoize everything else. Because all > types that are data objects sitting in memory (so the arg is essentially a > reference) > can be memoized, without changing the space properties (except for overall > constants). Does haskell do this? And if it doesn't can you turn it on? Integers are nothing special. Consider functions on: data Nat = Zero | Succ Nat Now, perhaps you mean memoize specific Nat *references* (a meaningless question for Haskell, only for specific implementations) rather than the *values*. Eg., for some f: would not. let x = Succ Zero in f x + f x would memoize the result of f, but: f (Succ Zero) + f (Succ Zero) would not. GHC does not do this. However, I am working in my free time on an experimental graph reducer which does. It implements a semantics called "complete laziness"[1]. I'm experimenting to see how that changes the engineering trade-offs (I have a blog post about what I expect those to be: http://lukepalmer.wordpress.com/2009/07/07/emphasizing-specialization/) For programs that do not benefit from the extra sharing, I should be lucky to run them only 50 times slower. This is an indication why GHC doesn't do this. Complete laziness is a fairly young research field. Maybe someday we'll get a smokin' fast completely lazy reducer. [1] http://www.lsv.ens-cachan.fr/Publis/PAPERS/PDF/sinot-wrs07.pdf From g.c.stavenga at uu.nl Fri Aug 28 06:34:07 2009 From: g.c.stavenga at uu.nl (staafmeister) Date: Fri Aug 28 06:13:43 2009 Subject: Re[Haskell-cafe] [2]: Reduction Sequence of simple Fibonacci sequence implementation In-Reply-To: <288877954.20090828141043@gmail.com> References: <25178377.post@talk.nabble.com> <25187256.post@talk.nabble.com> <288877954.20090828141043@gmail.com> Message-ID: <25187710.post@talk.nabble.com> Bulat Ziganshin-2 wrote: > > > this graph can share computations in only one way - when you give > sharec node a name and use this name twice. for example, the following > > sum[1..1000] + prod[1..1000] > > don't share anything, but this > > let list = [1..1000] > in sum list + prod list > > share the list. performing sharing via explicit naming common > subexpressions is the only way to memoize results > > you imagine something highly inefficient like storing results of every > computation ever done. are you think it really makes a sense? > > Well in case I call (prod list) again it could lookup the reference and see that this computation has already been performed and just lookup the answer. In case `list' becomes GCed the GC should also destroy the lookup in the cache. The overhead is a O(1) overhead for the function because it needs to check if a computation has already performed. And the space overhead is not so big because every data object in memory there are a couple of references to be stored in lookup tables. So although there is space overhead it is not excessive. -- View this message in context: http://www.nabble.com/Reduction-Sequence-of-simple-Fibonacci-sequence-implementation-tp25178377p25187710.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From thaldyron at gmail.com Fri Aug 28 06:36:10 2009 From: thaldyron at gmail.com (Peter Robinson) Date: Fri Aug 28 06:16:06 2009 Subject: [Haskell-cafe] Uninstall a cabal package? In-Reply-To: References: Message-ID: As far as I know the current stable release of Cabal doesn't keep track of installed packages, so you can only # ghc-pkg unregister pkg-id and then manually delete the files. Peter 2009/8/28 Colin Paul Adams : > What is the procedure to uninstall a cabal package? > -- > Colin Adams > Preston Lancashire > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From bulat.ziganshin at gmail.com Fri Aug 28 06:53:40 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Aug 28 06:33:23 2009 Subject: Re[Haskell-cafe] [2]: Reduction Sequence of simple Fibonacci sequence implementation In-Reply-To: <25187710.post@talk.nabble.com> References: <25178377.post@talk.nabble.com> <25187256.post@talk.nabble.com> <288877954.20090828141043@gmail.com> <25187710.post@talk.nabble.com> Message-ID: <1678580063.20090828145340@gmail.com> Hello staafmeister, Friday, August 28, 2009, 2:34:07 PM, you wrote: > Well in case I call (prod list) again it could lookup the reference and see so it should keep a list of all values ever computed in program, together with their expressions? :) are you like idea of prod[1..10^6] computation taking 10 mbytes of memory? -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From g.c.stavenga at uu.nl Fri Aug 28 07:03:13 2009 From: g.c.stavenga at uu.nl (staafmeister) Date: Fri Aug 28 06:42:49 2009 Subject: Re[Haskell-cafe] [2]: Re[2]: Reduction Sequence of simple Fibonacci sequence implementation In-Reply-To: <1678580063.20090828145340@gmail.com> References: <25178377.post@talk.nabble.com> <25187256.post@talk.nabble.com> <288877954.20090828141043@gmail.com> <25187710.post@talk.nabble.com> <1678580063.20090828145340@gmail.com> Message-ID: <25188000.post@talk.nabble.com> Bulat Ziganshin-2 wrote: > > Hello staafmeister, > > Friday, August 28, 2009, 2:34:07 PM, you wrote: >> Well in case I call (prod list) again it could lookup the reference and >> see > > so it should keep a list of all values ever computed in program, > together with their expressions? :) are you like idea of prod[1..10^6] > computation taking 10 mbytes of memory? > > The list you give prod is also 10 MB so it not a terribly inefficient program. It's a factor of 2. Well haskell also has often a factor of 2 overhead with respect to C and people are not terribl concerned about that -- View this message in context: http://www.nabble.com/Reduction-Sequence-of-simple-Fibonacci-sequence-implementation-tp25178377p25188000.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From dav.vire+haskell at gmail.com Fri Aug 28 07:17:27 2009 From: dav.vire+haskell at gmail.com (david48) Date: Fri Aug 28 06:57:03 2009 Subject: Re[Haskell-cafe] [2]: Re[2]: Reduction Sequence of simple Fibonacci sequence implementation In-Reply-To: <25188000.post@talk.nabble.com> References: <25178377.post@talk.nabble.com> <25187256.post@talk.nabble.com> <288877954.20090828141043@gmail.com> <25187710.post@talk.nabble.com> <1678580063.20090828145340@gmail.com> <25188000.post@talk.nabble.com> Message-ID: <4c88418c0908280417k7c66a2f5na5a5664c7c28128@mail.gmail.com> On Fri, Aug 28, 2009 at 1:03 PM, staafmeister wrote: > The list you give prod is also 10 MB so it not a terribly inefficient > program. That list takes memory only if it is forced. If it is passed to a lazy function, all the list may not be in memory at once. From bulat.ziganshin at gmail.com Fri Aug 28 07:23:01 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Aug 28 07:02:44 2009 Subject: Re[Haskell-cafe] [2]: Re[2]: Reduction Sequence of simple Fibonacci sequence implementation In-Reply-To: <25188000.post@talk.nabble.com> References: <25178377.post@talk.nabble.com> <25187256.post@talk.nabble.com> <288877954.20090828141043@gmail.com> <25187710.post@talk.nabble.com> <1678580063.20090828145340@gmail.com> <25188000.post@talk.nabble.com> Message-ID: <1222781234.20090828152301@gmail.com> Hello staafmeister, Friday, August 28, 2009, 3:03:13 PM, you wrote: >> so it should keep a list of all values ever computed in program, >> together with their expressions? :) are you like idea of prod[1..10^6] >> computation taking 10 mbytes of memory? > The list you give prod is also 10 MB so it not a terribly inefficient > program. no, it's produced on need so it needs O(1) memory > It's a factor of 2. Well haskell also has often a factor of 2 overhead with > respect to C and people are not terribl concerned about that factor of 2 compared to ALL VALUES ever produced when evaluating program. since computer performs about 10^9 computations per second, you are going to store 10^9 values each second, some of those may be multi-megabyte by itself -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From g.c.stavenga at uu.nl Fri Aug 28 07:23:41 2009 From: g.c.stavenga at uu.nl (staafmeister) Date: Fri Aug 28 07:03:18 2009 Subject: Re[Haskell-cafe] [2]: Re[2]: Reduction Sequence of simple Fibonacci sequence implementation In-Reply-To: <4c88418c0908280417k7c66a2f5na5a5664c7c28128@mail.gmail.com> References: <25178377.post@talk.nabble.com> <25187256.post@talk.nabble.com> <288877954.20090828141043@gmail.com> <25187710.post@talk.nabble.com> <1678580063.20090828145340@gmail.com> <25188000.post@talk.nabble.com> <4c88418c0908280417k7c66a2f5na5a5664c7c28128@mail.gmail.com> Message-ID: <25188238.post@talk.nabble.com> david48 wrote: > > On Fri, Aug 28, 2009 at 1:03 PM, staafmeister wrote: > > >> The list you give prod is also 10 MB so it not a terribly inefficient >> program. > > That list takes memory only if it is forced. If it is passed to a lazy > function, all the list may not be in memory at once. > In that case the GC cleaned up the whole list and while cleaning up it should also clean up the references in the cache lookup table. So then there is no space overhead either. -- View this message in context: http://www.nabble.com/Reduction-Sequence-of-simple-Fibonacci-sequence-implementation-tp25178377p25188238.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From g.c.stavenga at uu.nl Fri Aug 28 07:31:13 2009 From: g.c.stavenga at uu.nl (staafmeister) Date: Fri Aug 28 07:10:49 2009 Subject: Re[Haskell-cafe] [2]: Re[2]: Re[2]: Reduction Sequence of simple Fibonacci sequence implementation In-Reply-To: <1222781234.20090828152301@gmail.com> References: <25178377.post@talk.nabble.com> <25187256.post@talk.nabble.com> <288877954.20090828141043@gmail.com> <25187710.post@talk.nabble.com> <1678580063.20090828145340@gmail.com> <25188000.post@talk.nabble.com> <1222781234.20090828152301@gmail.com> Message-ID: <25188333.post@talk.nabble.com> Bulat Ziganshin-2 wrote: > > Hello staafmeister, > > Friday, August 28, 2009, 3:03:13 PM, you wrote: >>> so it should keep a list of all values ever computed in program, >>> together with their expressions? :) are you like idea of prod[1..10^6] >>> computation taking 10 mbytes of memory? > >> The list you give prod is also 10 MB so it not a terribly inefficient >> program. > > no, it's produced on need so it needs O(1) memory > >> It's a factor of 2. Well haskell also has often a factor of 2 overhead >> with >> respect to C and people are not terribl concerned about that > > factor of 2 compared to ALL VALUES ever produced when evaluating > program. since computer performs about 10^9 computations per second, > you are going to store 10^9 values each second, some of those may be > multi-megabyte by itself > > Hi Bulat, All the values that are computed but are also GCed (and they will be, 10^9 bytes is the mem limit). If the GC removes a value then all references in cache to those values can also be removed. Gerben -- View this message in context: http://www.nabble.com/Reduction-Sequence-of-simple-Fibonacci-sequence-implementation-tp25178377p25188333.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From colin at colina.demon.co.uk Fri Aug 28 07:41:56 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Fri Aug 28 07:21:32 2009 Subject: [Haskell-cafe] Uninstall a cabal package? In-Reply-To: (Peter Robinson's message of "Fri\, 28 Aug 2009 12\:36\:10 +0200") References: Message-ID: >>>>> "Peter" == Peter Robinson writes: Peter> As far as I know the current stable release of Cabal Peter> doesn't keep track of installed packages, so you can only # Peter> ghc-pkg unregister pkg-id and then manually delete the Peter> files. Thanks. That works. -- Colin Adams Preston Lancashire From colin at colina.demon.co.uk Fri Aug 28 07:49:08 2009 From: colin at colina.demon.co.uk (Colin Paul Adams) Date: Fri Aug 28 07:28:45 2009 Subject: [Haskell-cafe] Problem with monadic formlets In-Reply-To: (Colin Paul Adams's message of "Fri\, 28 Aug 2009 07\:06\:05 +0100") References: <878wh5yow5.wl%jeremy@n-heptane.com> Message-ID: >>>>> "Colin" == Colin Paul Adams writes: >>>>> "Jeremy" == Jeremy Shaw writes: Colin> apparent data corruprion is occurring. I am suspecting a Colin> bug in the formlets library (I have version 0.6). Colin> So I have created a slightly cut-down (no database Colin> involved) complete working program. Can you see if this Colin> works ok with your version of formlets: I managed to uninstall formlets-0.6 myself, and then installed 0.5 instead. After adding the necessary extra argument to runFormletState (an empty string), the test program works fine. So this seems to be a bug in formlets-0.6. -- Colin Adams Preston Lancashire From ketil at malde.org Fri Aug 28 08:09:36 2009 From: ketil at malde.org (Ketil Malde) Date: Fri Aug 28 07:48:49 2009 Subject: Re[Haskell-cafe] [2]: Re[2]: Reduction Sequence of simple Fibonacci sequence implementation In-Reply-To: <25188000.post@talk.nabble.com> (staafmeister's message of "Fri\, 28 Aug 2009 04\:03\:13 -0700 \(PDT\)") References: <25178377.post@talk.nabble.com> <25187256.post@talk.nabble.com> <288877954.20090828141043@gmail.com> <25187710.post@talk.nabble.com> <1678580063.20090828145340@gmail.com> <25188000.post@talk.nabble.com> Message-ID: <87fxbci1hb.fsf@malde.org> staafmeister writes: > The list you give prod is also 10 MB so it not a terribly > inefficient program. It's a factor of 2. No, it is not. The expression: prod [1..1000] + sum [1..1000] will first evaluate prod [1..1000], generating values from 1 to 1000 lazily and accumulating the product incrementally, allowing the used values to be GC'ed. Then the sum will be evaluated similarly, and the two results will be added. It will run in constant - and very small space. If you do common sub-expression elimination (CSE), and write let ls = [1..1000] in prod ls + sum ls the product will force ls to be evaluated, but since there is another reference to this value (for the sum), it cannot be garbage collected. Thus, the difference is more like a factor of 1000, which is a big deal. -k -- If I haven't seen further, it is by standing in the footprints of giants From bulat.ziganshin at gmail.com Fri Aug 28 08:04:25 2009 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Fri Aug 28 07:55:25 2009 Subject: Re[Haskell-cafe] [2]: Re[2]: Re[2]: Reduction Sequence of simple Fibonacci sequence implementation In-Reply-To: <25188333.post@talk.nabble.com> References: <25178377.post@talk.nabble.com> <25187256.post@talk.nabble.com> <288877954.20090828141043@gmail.com> <25187710.post@talk.nabble.com> <1678580063.20090828145340@gmail.com> <25188000.post@talk.nabble.com> <1222781234.20090828152301@gmail.com> <25188333.post@talk.nabble.com> Message-ID: <19310543690.20090828160425@gmail.com> Hello staafmeister, Friday, August 28, 2009, 3:31:13 PM, you wrote: > All the values that are computed but are also GCed (and they will be, 10^9 > bytes > is the mem limit). If the GC removes a value then all references in cache to > those > values can also be removed. it looks like cache of values computed since the last GC, because on GC all those intermediate results will be collected. i think it's not very useful outside of fib example that does exact that - reusing recently computed values -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From uzytkownik2 at gmail.com Fri Aug 28 08:33:08 2009 From: uzytkownik2 at gmail.com (Maciej Piechotka) Date: Fri Aug 28 08:12:47 2009 Subject: [Haskell-cafe] Arrows extentions and ArrowApplicable Message-ID: <1251462789.24942.6.camel@kirk> Arrows syntax supports Arrow, ArrowChoice(if, case etc.) and ArrowLoop(rec) - but not ArrowApplicable. Therefore it is not possible to write: proc x -> do a <- someArrow -< x a -< x but proc x -> do a <- someArrow -< x app -< (a, x) and proc x -> do a <- someArrow -< x app -< (otherArrow a, x) instead of proc x -> do a <- someArrow -< x otherArrow a -< x Such approach adds some syntax sugar but without adding any additional keyword and IMHO it can simplify writing ArrowApply (especially Kleisli IO). Regards -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090828/59db3bfa/attachment.bin From apfelmus at quantentunnel.de Fri Aug 28 08:38:40 2009 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Fri Aug 28 08:18:40 2009 Subject: [Haskell-cafe] Re: Mapping over multiple values of a list at once? In-Reply-To: <32478061.199701251361140344.JavaMail.servlet@kundenserver> References: <32478061.199701251361140344.JavaMail.servlet@kundenserver> Message-ID: haskell@kudling.de wrote: > You are asked to iterate over the list and calculate the average value > of each 3 neighbouring values. Lambda Fu, form 72 - three way dragon zip averages3 xs = zipWith3 avg xs (drop 1 xs) (drop 2 xs) where avg a b c = (a+b+c) / 3 Regards, apfelmus -- http://apfelmus.nfshost.com From ross at soi.city.ac.uk Fri Aug 28 08:44:40 2009 From: ross at soi.city.ac.uk (Ross Paterson) Date: Fri Aug 28 08:24:19 2009 Subject: [Haskell-cafe] Arrows extentions and ArrowApplicable In-Reply-To: <1251462789.24942.6.camel@kirk> References: <1251462789.24942.6.camel@kirk> Message-ID: <20090828124440.GA7040@soi.city.ac.uk> On Fri, Aug 28, 2009 at 02:33:08PM +0200, Maciej Piechotka wrote: > Arrows syntax supports Arrow, ArrowChoice(if, case etc.) and > ArrowLoop(rec) - but not ArrowApplicable. Therefore it is not possible > to write: > > proc x -> do > a <- someArrow -< x > a -< x You can write proc x -> do a <- someArrow -< x a -<< x (See the Arrow notation section of the GHC User's Guide.) From mmitar at gmail.com Fri Aug 28 08:45:54 2009 From: mmitar at gmail.com (Mitar) Date: Fri Aug 28 08:25:30 2009 Subject: [Haskell-cafe] Time constrained computation Message-ID: Hi! I am not really sure if this is correct term for it but I am open to better (search) terms. pure From mmitar at gmail.com Fri Aug 28 09:01:55 2009 From: mmitar at gmail.com (Mitar) Date: Fri Aug 28 08:41:32 2009 Subject: [Haskell-cafe] Re: Time constrained computation In-Reply-To: References: Message-ID: Hi! Ups, missed save button and pressed send. ;-) So I am not really sure if this is correct term for it but I am open to better (search) terms. I am wondering if it is possible to make a time constrained computation. For example if I have a computation of an approximation of a value which can take more or less time (and you get more or less precise value) or if I have an algorithm which is searching some search-space it can find better or worse solution depending how much time you allow. So I would like to say to Haskell to (lazily, if it really needs it) get me some value but not to spend more than so much time calculating it. One abstraction of this would be to have an infinity list of values and I would like to get the last element I can get in t milliseconds of computational time. One step further would be to be able to stop computation not at predefined time but with some other part of the program deciding it is enough. So I would have a system which would monitor computation and a pure computation I would be able to stop. Is this possible? Is it possible to have a pure computation interrupted and get whatever it has computed until then? How could I make this? Is there anything already done for it? Some library I have not found? Of course all this should be as performance wise as it is possible. So the best interface for me would be to be able to start a pure computation and put an upper bound on computation time but also be able to stop it before that upper bound. And all this should be as abstracted as it is possible. Mitar From bugfact at gmail.com Fri Aug 28 09:54:08 2009 From: bugfact at gmail.com (Peter Verswyvelen) Date: Fri Aug 28 09:33:44 2009 Subject: [Haskell-cafe] strictness analysis on algebraic data types Message-ID: I'm reading the book "Modern Compiler Design", and in the chapter about functional programming it is stated that strictness analysis in the presence of ADTs (aka records) is a very hard problem to tackle. I'm not sure what the current state of art is here (e.g GHC or JHC), and don't understand what the problem is. Does it mean that it's a good idea to carefully consider when to make data constructor arguments (aka fields) strict, since the compiler can't do good strictness analysis when it encounters say a record with many lazy fields? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090828/dc386051/attachment.html From gue.schmidt at web.de Fri Aug 28 10:28:15 2009 From: gue.schmidt at web.de (=?iso-8859-15?Q?G=FCnther_Schmidt?=) Date: Fri Aug 28 10:08:20 2009 Subject: [Haskell-cafe] Another thanks for inspiration to RWH - Bloom Filters Message-ID: Hi all, My app has to use rather large amounts of static data in order to run. I have been using an SQLite database to hold this data so far. The largest chunk of data was a table with roughly 80k records. I only make use of this table to see if a particular key is present. Reading RWH over from time to time I came accross the Bloom Filter and finally realized that this would be a much better solution. So I could insert all the keys in the table into a suitable bloom filter instead and the just query the bloom filter instead of the database. I haven't figured out yet how to write a "literal" representation of the "filled" bloom filter yet though and could do with some tipps. I'm using the bloomfilter package from hackage. G?nther From alexander.dunlap at gmail.com Fri Aug 28 11:24:22 2009 From: alexander.dunlap at gmail.com (Alexander Dunlap) Date: Fri Aug 28 11:04:18 2009 Subject: [Haskell-cafe] Re: Time constrained computation In-Reply-To: References: Message-ID: <57526e770908280824w61d46547ve7981c73008d23c8@mail.gmail.com> On Fri, Aug 28, 2009 at 6:01 AM, Mitar wrote: > Hi! > > Ups, missed save button and pressed send. ;-) > > So I am not really sure if this is correct term for it but I am open > to better (search) terms. > > I am wondering if it is possible to make a time constrained > computation. For example if I have a computation of an approximation > of a value which can take more or less time (and you get more or less > precise value) or if I have an algorithm which is searching some > search-space it can find better or worse solution depending how much > time you allow. So I would like to say to Haskell to (lazily, if it > really needs it) get me some value but not to spend more than so much > time calculating it. > > One abstraction of this would be to have an infinity list of values > and I would like to get the last element I can get in t milliseconds > of computational time. > > One step further would be to be able to stop computation not at > predefined time but with some other part of the program deciding it is > enough. So I would have a system which would monitor computation and a > pure computation I would be able to stop. Is this possible? Is it > possible to have a pure computation interrupted and get whatever it > has computed until then? > > How could I make this? Is there anything already done for it? Some > library I have not found? > > Of course all this should be as performance wise as it is possible. > > So the best interface for me would be to be able to start a pure > computation and put an upper bound on computation time but also be > able to stop it before that upper bound. And all this should be as > abstracted as it is possible. > > > Mitar > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > In general, you need to do this either within the IO monad, to avoid breaking referential transparency, or using unsafePerformIO, if you know that your use of it is safe, which seems somewhat unlikely. You may want to look at System.Timeout. Another possibility would be the unamb package from Hackage. Hope that helps, Alex From jvranish at gmail.com Fri Aug 28 12:32:04 2009 From: jvranish at gmail.com (Job Vranish) Date: Fri Aug 28 12:11:40 2009 Subject: [Haskell-cafe] Re: Time constrained computation In-Reply-To: References: Message-ID: I tried this using timeout, but was never able to get it to work. The timeout doesn't behave like I expect. I can take several seconds for it to timeout, even with very low timeouts. Any ideas? - Job module Main where import Data.IORef import System.Timeout import System.IO.Unsafe tailScan f (x:xs) = resultList where resultList = x : zipWith f resultList xs facts = 1 : tailScan (*) [1..] fac n = facts !! n eterm x n = x^n / (fac n) eseries x = fmap (eterm x) [0..] ePrecisionList x = tailScan (+) $ eseries x computeUntil t xs = do a <- newIORef undefined timeout t $ sequence $ fmap (writeIORef a) xs readIORef a -- compute e for only 10 microseconds e x = computeUntil 10 (ePrecisionList x) main = do -- compute e print =<< e 1 On Fri, Aug 28, 2009 at 9:01 AM, Mitar wrote: > Hi! > > Ups, missed save button and pressed send. ;-) > > So I am not really sure if this is correct term for it but I am open > to better (search) terms. > > I am wondering if it is possible to make a time constrained > computation. For example if I have a computation of an approximation > of a value which can take more or less time (and you get more or less > precise value) or if I have an algorithm which is searching some > search-space it can find better or worse solution depending how much > time you allow. So I would like to say to Haskell to (lazily, if it > really needs it) get me some value but not to spend more than so much > time calculating it. > > One abstraction of this would be to have an infinity list of values > and I would like to get the last element I can get in t milliseconds > of computational time. > > One step further would be to be able to stop computation not at > predefined time but with some other part of the program deciding it is > enough. So I would have a system which would monitor computation and a > pure computation I would be able to stop. Is this possible? Is it > possible to have a pure computation interrupted and get whatever it > has computed until then? > > How could I make this? Is there anything already done for it? Some > library I have not found? > > Of course all this should be as performance wise as it is possible. > > So the best interface for me would be to be able to start a pure > computation and put an upper bound on computation time but also be > able to stop it before that upper bound. And all this should be as > abstracted as it is possible. > > > Mitar > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090828/5f2d4b41/attachment.html From vandijk.roel at gmail.com Fri Aug 28 12:58:36 2009 From: vandijk.roel at gmail.com (Roel van Dijk) Date: Fri Aug 28 12:38:12 2009 Subject: [Haskell-cafe] Re: Time constrained computation In-Reply-To: References: Message-ID: This is my go at the problem: module Main where import Control.Concurrent import Data.IORef -- From the Haskell wiki primes :: [Integer] primes = sieve [2..] where sieve (p:xs) = p : sieve [x | x <- xs, x `mod` p /= 0] producePrimes :: IORef [Integer] -> IO () producePrimes ref = go primes where go (x:xs) = modifyIORef ref (\ys -> x:ys) >> go xs go [] = error "Euclid was wrong!" -- Calculate as much primes as possible in 't' picoseconds getPrimes :: Int -> IO [Integer] getPrimes t = do ref <- newIORef [] producer <- forkIO (producePrimes ref) threadDelay t killThread producer readIORef ref main = do ps <- getPrimes 1000000 print $ length ps Or view my hpaste: http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8782#a8782 If you run this a few times in GHCI you will find that it calculates an increasingly large number of primes within the same time span. This is because the previous results are retained. Compile and run or restart GHCI for every run for accurate results. On Fri, Aug 28, 2009 at 3:01 PM, Mitar wrote: > Hi! > > Ups, missed save button and pressed send. ;-) > > So I am not really sure if this is correct term for it but I am open > to better (search) terms. > > I am wondering if it is possible to make a time constrained > computation. For example if I have a computation of an approximation > of a value which can take more or less time (and you get more or less > precise value) or if I have an algorithm which is searching some > search-space it can find better or worse solution depending how much > time you allow. So I would like to say to Haskell to (lazily, if it > really needs it) get me some value but not to spend more than so much > time calculating it. > > One abstraction of this would be to have an infinity list of values > and I would like to get the last element I can get in t milliseconds > of computational time. > > One step further would be to be able to stop computation not at > predefined time but with some other part of the program deciding it is > enough. So I would have a system which would monitor computation and a > pure computation I would be able to stop. Is this possible? Is it > possible to have a pure computation interrupted and get whatever it > has computed until then? > > How could I make this? Is there anything already done for it? Some > library I have not found? > > Of course all this should be as performance wise as it is possible. > > So the best interface for me would be to be able to start a pure > computation and put an upper bound on computation time but also be > able to stop it before that upper bound. And all this should be as > abstracted as it is possible. > > > Mitar > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > From allbery at ece.cmu.edu Fri Aug 28 17:01:28 2009 From: allbery at ece.cmu.edu (Brandon S. Allbery KF8NH) Date: Fri Aug 28 16:41:19 2009 Subject: [Haskell-cafe] Re: Is logBase right? In-Reply-To: <8763c8jt9o.fsf@malde.org> References: <20090822170352.5A3C53245AF@www.haskell.org> <1251024096.2246.21.camel@localhost> <5e0214850908230412s199c79absc66f47e03a539eb7@mail.gmail.com> <1251034068.3085.55.camel@localhost> <8763cbx1hl.fsf@malde.org> <8763c8jt9o.fsf@malde.org> Message-ID: On Aug 28, 2009, at 03:24 , Ketil Malde wrote: > What puzzled me (and the parent article indicated), was that Python > appeared to be able to work with more precision, and thus be more > "numerically correct" than GHC. Since it's all machine precision > floating point, this is even more strange, and I couldn't reproduce > the behavior for any other numbers than the one used in the > example. -fexcess-precision or other gcc compile options? -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 195 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090828/34a24ac8/PGP.bin From lrpalmer at gmail.com Fri Aug 28 18:34:17 2009 From: lrpalmer at gmail.com (Luke Palmer) Date: Fri Aug 28 18:13:52 2009 Subject: Re[Haskell-cafe] [2]: Re[2]: Re[2]: Reduction Sequence of simple Fibonacci sequence implementation In-Reply-To: <19310543690.20090828160425@gmail.com> References: <25178377.post@talk.nabble.com> <25187256.post@talk.nabble.com> <288877954.20090828141043@gmail.com> <25187710.post@talk.nabble.com> <1678580063.20090828145340@gmail.com> <25188000.post@talk.nabble.com> <1222781234.20090828152301@gmail.com> <25188333.post@talk.nabble.com> <19310543690.20090828160425@gmail.com> Message-ID: <7ca3f0160908281534x3ba7edecj2aa164ef1627bda1@mail.gmail.com> On Fri, Aug 28, 2009 at 6:04 AM, Bulat Ziganshin wrote: > Hello staafmeister, > > Friday, August 28, 2009, 3:31:13 PM, you wrote: > >> All the values that are computed but are also GCed (and they will be, 10^9 >> bytes >> is the mem limit). If the GC removes a value then all references in cache to >> those >> values can also be removed. > > it looks like cache of values computed since the last GC, because on > GC all those intermediate results will be collected. i think it's not > very useful outside of fib example that does exact that - reusing > recently computed values I wouldn't be so quick to call it useless. This caching idea, when combined with HNF instead of WHNF reduction, leads to a strategy which is capable of automatically specializing away layers of interpretation. That is to say, it turns all interpreters into compilers. Now, there are some disadvantages too, some of which have to do with memory performance. But it's not clear that the disadvantages always outweigh the advantages; rather I suspect you get a strategy which implies a whole different set of trade-offs for engineering efficient programs. Luke From h._h._h._ at hotmail.com Fri Aug 28 18:38:26 2009 From: h._h._h._ at hotmail.com (h.) Date: Fri Aug 28 18:18:02 2009 Subject: [Haskell-cafe] rotate image In-Reply-To: References: <4165d3a70908241640i323988afs90fe553ca210420a@mail.gmail.com> Message-ID: <25198054.post@talk.nabble.com> Hello, Nobody any idea? > I want to paint in some widget, but this will be in front of some > background, so the bg should be transparent. -- best regards h. -- View this message in context: http://www.nabble.com/rotate-image-tp25122912p25198054.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. From bock.steffen at yahoo.de Fri Aug 28 19:03:24 2009 From: bock.steffen at yahoo.de (Steffen Bock) Date: Fri Aug 28 18:43:00 2009 Subject: [Haskell-cafe] SLD resolution code in Haskell Message-ID: <393416.65788.qm@web24711.mail.ird.yahoo.com> Hi, is there any haskell code for SLD-resolution; I wanna learn it. Thanks a lot. Steffen. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090828/1f05998c/attachment.html From jefferson.r.heard at gmail.com Fri Aug 28 19:14:11 2009 From: jefferson.r.heard at gmail.com (Jeff Heard) Date: Fri Aug 28 18:54:06 2009 Subject: [Haskell-cafe] rotate image In-Reply-To: <25198054.post@talk.nabble.com> References: <4165d3a70908241640i323988afs90fe553ca210420a@mail.gmail.com> <25198054.post@talk.nabble.com> Message-ID: <4165d3a70908281614j555e696apa9667f7