Re: [Haskell-cafe] bit of help with n-ary please...
Ketil Malde ke...@malde.org writes: data Tree a = Empty | Branch a [Tree a] What would the consequences be if you replaced your definition with this one? And, for extra credit, can you identify similar issues with this definition? Can you improve on it? -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Area from [(x,y)] using foldl
On Sun, Nov 8, 2009 at 10:30 PM, michael rice nowg...@yahoo.com wrote: This doesn't. area :: [(Double,Double)] - Double area p = abs $ (/2) $ area' (last p):p where area' [] = 0 area' ((x0,y0),(x,y):ps) = ((x0-x)*(y0+y)) + area' (x,y):ps This function is almost correct except you got your priorities wrong : application priority is always stronger than any operator's so area' (last p):p is read as (area' (last p)) : p... Besides your second pattern is also wrong, the correct code is : area :: [(Double,Double)] - Double area p = abs $ (/2) $ area' (last p : p) where area' ((x0,y0):(x,y):ps) = ((x0-x)*(y0+y)) + area' (x,y):ps area' _ = 0 -- Jedaï ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: control-monad-exception 0.5 with monadic call traces
Excerpts from Michael Snoyman's message of Sat Nov 07 22:55:14 +0100 2009: On Sat, Nov 7, 2009 at 9:54 PM, Henning Thielemann lemm...@henning-thielemann.de wrote: On Sat, 7 Nov 2009, Jose Iborra wrote: Sorry for the confusion, I never meant that c-m-e can show stack traces for asynchronous exceptions. It can not. My post was not related in any way to asynchronous exceptions. It's just the everlasting issue of the distinction of programming errors and exceptions. I'm not sure if I managed to dispel your doubts, if not perhaps you could make your points more clear. I'm trying that for years now, repeatedly in this mailing list and on the Wiki: http://www.haskell.org/haskellwiki/Error http://www.haskell.org/haskellwiki/Exception I don't know how I can make it still clearer. It's just like concurrency vs. parallelism - somehow related, but it is important to distinguish them. And yet if I use library ABC, which I expected to be error-free, and it in fact has a programming error, is this an error or an exception from my point of view? Based on the definitions you posted, I believe the correct answer is error. However, I'd much rather have a way to recover from that kind of error if it's logical. For example, let's say that I'm writing a web browser in Haskell (it could happen). If there's an error in the HTTP library which causes it to die on certain types of headers, I'd much rather be able to tell the user sorry and let them continue browsing than to up and die with a Prelude.head message in their console. If there is an error raised by the HTTP library on some headers, then this is a bug (a programming error), and so by using it your program is buggy too. However I would say that in this case wrapping the buggy function into safely-failing one is a valid temporary hack. A way to help distinguishing errors and exceptions would be to have pre and post conditions on function (as in Static Contract Checking for Haskell[1]). For instance head would have the following contract: {-# CONTRACT head :: { xs | not (null xs) } - Ok #-} head :: [a] - a head []= error head: empty list head (x:_) = x When there is a pre-condition (or a contract) like here, it is a programming error to give an empty list to head. This means that checking if the list is empty must be done before the call. It has to statically deductible from the call site. If you write a function and cannot prove that you will not call head on the empty list then either you check before calling, or you use a safe-head function or you add a pre-condition to your function. [1]: http://www.cl.cam.ac.uk/~nx200/ -- Nicolas Pouillard http://nicolaspouillard.fr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] WinGHCi stuck in a loop
WinGHCi options are stored under HKEY_CURRENT_USER\Software\Haskell\WinGhciversion in the Windows registry. Cheers, Pepe 2009/11/7 Henk-Jan van Tuyl hjgt...@chello.nl L.S., I changed the options in WinGHCi and now WinGHCi is stuck in a loop each time I start it; how can I edit the options? I cannot find them in the registry. -- Met vriendelijke groet, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ http://van.tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html -- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: feldspar-language
Tom Hawkins skrev: On Fri, Nov 6, 2009 at 6:28 AM, Emil Axelsson e...@chalmers.se wrote: I'm trying to get realtime signal processing with Haskell for long. I make progress, but slowly. Has Ericsson ever thought about using Haskell itself for signal processing? (But I think they already have Erlang?) No, using Haskell directly is not an option (at least with current compiler technology). Their performance requirements are very high, and the signal processors have quite limited memory, so putting a Haskell RTS on them wouldn't work. Atom may be another option. Though it is not intended for high performance DSP, we do use it for basic signal processing. Here is an IIR filter that is used is some fault detection logic on our application: -- | IIR filter implemented using direct form 2. iirFilter :: Name - Float - [(Float, Float)] - E Float - Atom (E Float) iirFilter name b0 coeffs x = do -- Create the filter taps. vs - mapM (\ i - float (name ++ show i) 0) [1 .. length coeffs] -- Cascade the filter taps together. mapM_ (\ (vA, vB) - vA == value vB) $ zip (tail vs) vs -- Calculate the input to the chain of taps. let w0 = sum ( x : [ (value v) * Const (-a) | (v, (a, _)) - zip vs coeffs ]) bs = b0 : (snd $ unzip coeffs) ws = w0 : map value vs us = [ w * Const b | (w, b) - zip ws bs ] head vs == w0 -- Return the output. return $ sum us http://hackage.haskell.org/package/atom Nice! One of our project members has been looking at Atom, not for numerical computations, but for real-time scheduling (which Feldspar should deal with eventually). What kind of code (in terms of efficiency) does the above description compile to? / Emil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell image libraries
there is also a binding for libGD on hackage : http://hackage.haskell.org/package/gd And, of course, you can improve it, or write a binding to a more complete library. Or, even better, write a mix between http://www.libpng.org/pub/png/pngdocs.html and http://hackage.haskell.org/package/binary ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANN: acme-dont
Hello fellow haskellers, While reading reddit in the morning today: http://www.reddit.com/r/programming/comments/a26fe/dont/ I was shocked and surprised to see that Haskell lacks a very important feature present in Perl. It appeared that Haskell cannot not do monadic actions! I decided to act as fast as possible. Luckily, monads enable us to create control flow constructs on enterprise level. I'm proud to present the Acme.Dont module, that implements the indispensable don't monadic action. http://hackage.haskell.org/package/acme-dont-1.0 With special apologies to Luke Palmer that it took the Haskell community 7.5 years to catch up with Perl. Thanks go to Damian Conway. Have fun! Gracjan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: acme-dont
2009/11/9 Gracjan Polak gracjanpo...@gmail.com: Hello fellow haskellers, While reading reddit in the morning today: http://www.reddit.com/r/programming/comments/a26fe/dont/ I was shocked and surprised to see that Haskell lacks a very important feature present in Perl. It appeared that Haskell cannot not do monadic actions! I decided to act as fast as possible. Luckily, monads enable us to create control flow constructs on enterprise level. I'm proud to present the Acme.Dont module, that implements the indispensable don't monadic action. http://hackage.haskell.org/package/acme-dont-1.0 With special apologies to Luke Palmer that it took the Haskell community 7.5 years to catch up with Perl. Thanks go to Damian Conway. Have fun! Gracjan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe Are you sure you want to license this as BSD? -- Deniz Dogan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ANN: acme-dont
Deniz Dogan deniz.a.m.dogan at gmail.com writes: Are you sure you want to license this as BSD? Yes, BSD3 to be more exact. Of course commercial options are available on case by case basis. -- Gracjan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: ANN: acme-dont
On Mon, Nov 9, 2009 at 4:01 AM, Gracjan Polak gracjanpo...@gmail.com wrote: Of course commercial options are available on case by case basis. When Acme.Dont licensing has made you a billionaire, remember the little people. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] O'Haskell
Hi, Somebody has idea, how to achieve reactive in O'Haskell? Shawn Wang _ MSN十年回馈,每位用户可免费获得价值25元的卡巴斯基反病毒软件2010激活码,快来领取! http://kaba.msn.com.cn/?k=1___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Cabal
On Sun, 2009-11-08 at 20:47 -0800, Gregory Crosswhite wrote: Actually, let me clarify my point: I have rarely encountered problems when using Cabal as a package distribution system, but I have run into problems when using it as a build system in a non-trivial manner. For example, when I wanted to build a lot of small utility programs I found that it was re-compiling commonly-shared source files for each program, rather than compiling the source file once and re-using the object file. This was sufficiently annoying that I migrated the build process of my utilities to scons. You'll be glad to know this is addressed in Cabal-1.8, though not in a fully automatic way. The problem with sharing automatically is knowing when it is safe to do so and when it is not. Each component that shares a source file can use different compiler options, cpp flags, and include dirs (and perhaps other stuff that we cannot easily track). Also, when you link it into a library you actually compile it differently than when you compile it into an executable (the -package-name flag is different). So what we've done is to let executables depend on libraries. That makes the sharing explicit. At some point I also want to add support for private libs which would make this feature useful in more cases. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Cabal
Hello Gregory and Philippos Gregory, methinks you are a unix user as Cabal gives you a carefree existence (the scare quotes do highlight that it's not poor Cabal's fault). Philippos, the problems you are having aren't which cabal per-se but Haskell libraries that bind C libraries. On Windows I strongly recommend you install Cygwin, outside of the Microsoft toolchain (Visual Studio, C# etc.) any serious development on Windows really is troublesome without it, some development still is but that's another story. Installing Cygwin will pull in a huge amount of code first time round but after that it it manageable. Once you have Cygwin – here's how to install the pcre and readline bindings. Re-run the cygwin installer. For pcre you will need Devel/pcre and Libs/libpcre. For readline you will need Devel/readline and Lib/libreadlineN – I have both libreadline5 and libreadline6 installed, so clearly they can coexist. To build the Haskell bindings you want to be running Cygwin naturally. I'd make a directory in /usr/local tagged to the version of GHC I'm using eg Haskell_ghc_6_10_3 and copy the tar.gz's there (having a directory for a particular GHC version makes it easier to track which packages you are depending upon across GHC updates). Untar the packages with tar (some Windows archivers don't handle Unixed archives well) tar xvfz readline-1.0.1.0.tar.gz tar xvfz pcre-0.3.1.tar.gz At this point I'd edit the *.cabal files in each component – this is not 'the done thing', but both libraries need extra flags and as I have to compile them rarely I tend to forget the format (which appears to be Windows style full paths even though you are running Cygwin). Append this to the end of readline.cabal extra-lib-dirs: C:\cygwin\lib include-dirs: C:\cygwin\usr\include\readline C:\cygwin\usr\include Append this to the end of pcre-light.cabal extra-lib-dirs: C:\cygwin\lib include-dirs: C:\cygwin\usr\include Provide you have cygwin at the root of C: (which is very wise!), you should be able to build with the usual runhaskell Setup.lhs { configure | build | install | hadock } Best wishes Stephen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Cabal
On Sun, 2009-11-08 at 19:29 -0800, Philippos Apolinarius wrote: I made small improvements in the Small Japi Binding, and asked how to make it available. I received a few private messages advising me to build and package the library using a tool called cabal. Since I have used installation tools for PLT, R and LaTeX libraries, I thought cabal was something similar. However, I noticed that there are a lot of complaints against cabal. Therefore, I decided to install cabal, and try it. It seems that it is easier to install packages by hand than using cabal. Here is a typical cabal session: D:\ghc\ghcapicabal update Downloading the latest package list from hackage.haskell.org D:\ghc\ghcapicabal install mkcabal Resolving dependencies... Downloading pcre-light-0.3.1... Configuring pcre-light-0.3.1... Downloading readline-1.0.1.0... Configuring readline-1.0.1.0... cabal: Error: some packages failed to install: mkcabal-0.4.2 depends on readline-1.0.1.0 which failed to install. pcre-light-0.3.1 failed during the configure step. The exception was: exit: ExitFailure 1 readline-1.0.1.0 failed during the configure step. The exception was: exit: ExitFailure 1 Hmm, I get a slightly different error that indicates somewhat better the actual cause. It says that it cannot find sh.exe. The real problem here is that those two packages use ./configure scripts. Those rarely work under windows. For starters you need msys and mingw installed. Even once you've done that however we get the problem of missing C libs. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] cabal with non-default cc1
Hello friends, I want a package which can't be built with the version of gcc coming with the current release of ghc, so I installed a sufficient version of gcc and called cabal with the parameters that should override it's default settings (see the failure.log, line 112). But I have the impression(*) that the remaining process doesn't use my settings related to the version of cc1 to use but still uses the one coming with ghc (6.10.4). Can you help further? Cheers Daniel * See: *** Assembler:, *** Linker: searching for ghc in path. found ghc at e:\programme\ghc\ghc-6.10.4\bin\ghc.exe (e:\\programme\\ghc\\ghc-6.10.4\\bin\\ghc.exe,[--numeric-version]) e:\programme\ghc\ghc-6.10.4\bin\ghc.exe is version 6.10.4 looking for package tool: ghc-pkg near compiler in e:\programme\ghc\ghc-6.10.4\bin found package tool in e:\programme\ghc\ghc-6.10.4\bin\ghc-pkg.exe (e:\\programme\\ghc\\ghc-6.10.4\\bin\\ghc-pkg.exe,[--version]) e:\programme\ghc\ghc-6.10.4\bin\ghc-pkg.exe is version 6.10.4 (e:\\programme\\ghc\\ghc-6.10.4\\bin\\ghc.exe,[--supported-languages]) Reading installed packages... (e:\\programme\\ghc\\ghc-6.10.4\\bin\\ghc-pkg.exe,[dump,--global]) (e:\\programme\\ghc\\ghc-6.10.4\\bin\\ghc-pkg.exe,[dump,--package-conf=h:\\.homedir\\ghc\\i386-mingw32-6.10.4\\package.conf]) Reading available packages... Resolving dependencies... selecting bindings-common-1.3.3 (hackage) and discarding bindings-common-0.1, 0.1.1, 0.1.2, 0.1.3, 0.1.4, 0.2, 0.2.1, 0.2.2, 0.2.3, 0.2.4, 0.2.5, 0.2.6, 1.0, 1.1, 1.2, 1.3, 1.3.1 and 1.3.2 selecting base-3.0.3.1 (installed) and 4.1.0.0 (installed) and discarding syb-0.1.0.0 and 0.1.0.1 selecting ghc-prim-0.1.0.0 (installed) selecting integer-0.1.0.1 (installed) selecting rts-1.0 (installed) selecting syb-0.1.0.1 (installed) In order, the following would be installed: bindings-common-1.3.3 (new package) bindings-common-1.3.3 has already been downloaded. Extracting C:\Dokumente und Einstellungen\Zyx\Anwendungsdaten\cabal\packages\hackage.haskell.org\bindings-common\1.3.3\bindings-common-1.3.3.tar.gz to c:\DOKUME~1\Zyx\LOKALE~1\Temp\bindings-common-1.3.31176... Using external setup method with build-type Simple Creating h:\.homedir\hugsdata\setup (and its parents) Using Cabal library version 1.6.0.3 Using h:\.homedir\hugsdata\setup\setup.hs as setup script. Setup script is out of date, compiling... (e:\\programme\\ghc\\ghc-6.10.4\\bin\\ghc.exe,[-v,--make,h:\\.homedir\\hugsdata\\setup\\setup.hs,-o,h:\\.homedir\\hugsdata\\setup\\setup.exe,-odir,h:\\.homedir\\hugsdata\\setup,-hidir,h:\\.homedir\\hugsdata\\setup,-i,-ic:\\DOKUME~1\\Zyx\\LOKALE~1\\Temp\\bindings-common-1.3.31176\\bindings-common-1.3.3,-no-user-package-conf,-package-conf,h:\\.homedir\\ghc\\i386-mingw32-6.10.4\\package.conf,-package,Cabal-1.6.0.3]) Glasgow Haskell Compiler, Version 6.10.4, for Haskell 98, stage 2 booted by GHC version 6.10.1 Using package config file: E:\programme\ghc\ghc-6.10.4\package.conf Using package config file: h:\.homedir\ghc\i386-mingw32-6.10.4\package.conf Using package config file: h:\.homedir\ghc\i386-mingw32-6.10.4\package.conf hiding package base-3.0.3.1 to avoid conflict with later version base-4.1.0.0 hiding package regex-base-0.72.0.2 to avoid conflict with later version regex-base-0.93.1 hiding package parsec-2.1.0.1 to avoid conflict with later version parsec-3.0.1 hiding package QuickCheck-1.2.0.0 to avoid conflict with later version QuickCheck-2.1.0.2 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 *** Chasing dependencies: Chasing modules from: *H:\.homedir\hugsdata\setup\setup.hs Stable obj: [] Stable BCO: [] Ready for upsweep [NONREC ModSummary { ms_hs_date = Mon Nov 9 14:45:34 Westeuropäische Normalzeit 2009 ms_mod = main:Main, ms_imps = [Distribution.Simple] ms_srcimps = [] }] compile: input file H:\.homedir\hugsdata\setup\setup.hs Created temporary directory: C:\DOKUME~1\Zyx\LOKALE~1\Temp\/ghc2388_0 *** Checking old interface for main:Main: [1 of 1] Compiling Main ( H:\.homedir\hugsdata\setup\setup.hs, H:\.homedir\hugsdata\setup\Main.o ) *** Parser: *** Renamer/typechecker: *** Desugar: Result size = 8 *** Simplify: Result size = 6 Result size = 6 *** Tidy Core: Result size = 6 writeBinIface: 1 Names writeBinIface: 28 dict entries *** CorePrep: Result size = 6 *** Stg2Stg: *** CodeGen: *** CodeOutput: *** Assembler: E:\programme\ghc\ghc-6.10.4\gcc -BE:\programme\ghc\ghc-6.10.4\gcc-lib/ -IE:\programme\ghc\ghc-6.10.4\include/mingw -IH:\.homedir\hugsdata\setup -c
[Haskell-cafe] Observer pattern in Haskell?
Hi all, I've been doing some GUI programming recently, using wx. To help manage dependencies between state and UI elements, I looked for a Haskell version of the Observer design pattern, and I found an implementation written by Bastiaan Heeren of ou.nl [1]. It pretty much did what I wanted, though I made a few changes along the way. Since this seems to be of general use (ie beyond wx), I've proposed to Bastiaan that I package it up for release on hackage, and he's happy for me to do so. Before I do so, I thought I'd ask for comments. The code is on github: http://github.com/gimbo/observer.hs where we have: Control.Observer - a typeclass for observable objects. Control.Observer.Synchronous - an implementation based on IORefs. This is essentially the same as Bastiaan's original, except I've changed the names, split it into two modules, commented it, added one or two small things, and Cabalised it. I've also made a branch where Control.Observer.Synchronous uses MVars instead of IORefs, in an attempt to achieve thread safety: http://github.com/gimbo/observer.hs/blob/threadsafeSync/Control/Observer/Synchronous.hs Now, before I make a hackage release: 0. Is this completely insane, in a Haskell setting? Are there better ways to do this that aren't laden with OO-worldview baggage? 1. Does anyone have any comments, on either version? 2. In particular, is the MVar version sensible? I'm aiming for mutual exclusion between threads. I _think_ I've got it, but I'm perhaps not familiar enough with the semantics of MVar to be certain. Advice appreciated. If it _is_ sensible, then is there any reason not to just use this, and discard the IORef version? The current implementation is synchronous, in that any observer functions are called immediately and synchronously (and in the same thread as the change of subject value). I'm pondering extending the package with an asynchronous version where the update just trips a flag, and the observer function picks this up later - possibly in another thread. The idea there is to help in cases where certain operations have to be in a particular thread. But this will mean a change to the typeclass too, I guess - or the addition of another one for observers themselves. Again, any thoughts? Thanks! -Andy [1] http://www.cs.uu.nl/wiki/bin/view/Afp0607/ExerciseWXHaskell ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Observer pattern in Haskell?
Andy Gimblett wrote: Hi all, I've been doing some GUI programming recently, using wx. To help manage dependencies between state and UI elements, I looked for a Haskell version of the Observer design pattern, and I found an implementation written by Bastiaan Heeren of ou.nl [1]. Now, before I make a hackage release: 1. Does anyone have any comments, on either version? There is no way to remove an observer, which is something I'd expect to have available. I realise this would require assigning a key to each observer (and thus perhaps storing them in an associative map) or some way to filter them, but I think if you can only ever add observers, it will get awkward. 2. In particular, is the MVar version sensible? I'm aiming for mutual exclusion between threads. I _think_ I've got it, but I'm perhaps not familiar enough with the semantics of MVar to be certain. Advice appreciated. If it _is_ sensible, then is there any reason not to just use this, and discard the IORef version? It looks fine (and thread-safe) to me, but I'd agree that you may as well just use the MVar version and leave out the IORef version. The current implementation is synchronous, in that any observer functions are called immediately and synchronously (and in the same thread as the change of subject value). I'm pondering extending the package with an asynchronous version where the update just trips a flag, and the observer function picks this up later - possibly in another thread. The idea there is to help in cases where certain operations have to be in a particular thread. But this will mean a change to the typeclass too, I guess - or the addition of another one for observers themselves. Again, any thoughts? I was a bit surprised at first that the observers were called synchronously. Asynchronous is what I'd expect, and it's also harder to code the asynchronous handlers wrongly. One blocking call (such as putMVar) in a synchronous handler can screw up your whole program by delaying the subsequent observers (and at that stage, the order in which the observers were added begins to matter). But my idea of how asynchronous would be implemented seems different to yours, judging by your description. Why not just augment this function in the synchronous version: notifyObservers :: Subject sub val = sub - IO () notifyObservers subject = do value - getValue subject observers - getObservers subject mapM_ ($ value) observers to become: notifyObserversAsync :: Subject sub val = sub - IO () notifyObserversAsync subject = do value - getValue subject observers - getObservers subject mapM_ (forkIO . ($ value)) observers This is what I was expecting to happen -- all the observer actions are spawned off into their own thread to run whatever code they want (either communicating back to an existing thread, or performing some long in-depth action). Thanks, Neil. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Observer pattern in Haskell?
Andy Gimblett-2 wrote: To help manage dependencies between state and UI elements, I looked for a Haskell version of the Observer design pattern Isn't Reactive Programming approach more suitable than Observer if we talk about Haskell? -- View this message in context: http://old.nabble.com/Observer-pattern-in-Haskell--tp26267269p26268135.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Observer pattern in Haskell?
Hi Neil, On 9 Nov 2009, at 14:50, Neil Brown wrote: 1. Does anyone have any comments, on either version? There is no way to remove an observer, which is something I'd expect to have available. I realise this would require assigning a key to each observer (and thus perhaps storing them in an associative map) or some way to filter them, but I think if you can only ever add observers, it will get awkward. Good point. This occurred to me when I referred to the Gang of Four book, while changing names for consistency. I must confess, in my current project I haven't needed it, but I see your point. 2. In particular, is the MVar version sensible? I'm aiming for mutual exclusion between threads. I _think_ I've got it, but I'm perhaps not familiar enough with the semantics of MVar to be certain. Advice appreciated. If it _is_ sensible, then is there any reason not to just use this, and discard the IORef version? It looks fine (and thread-safe) to me, but I'd agree that you may as well just use the MVar version and leave out the IORef version. Cool, thanks. was a bit surprised at first that the observers were called synchronously. Asynchronous is what I'd expect, and it's also harder to code the asynchronous handlers wrongly. One blocking call (such as putMVar) in a synchronous handler can screw up your whole program by delaying the subsequent observers (and at that stage, the order in which the observers were added begins to matter). True, but the observers shouldn't be able to access the MVars directly, I think? They should only be able to use the exposed interface, which won't let that happen? But my idea of how asynchronous would be implemented seems different to yours, judging by your description. Why not just augment this function in the synchronous version: notifyObservers :: Subject sub val = sub - IO () notifyObservers subject = do value - getValue subject observers - getObservers subject mapM_ ($ value) observers to become: notifyObserversAsync :: Subject sub val = sub - IO () notifyObserversAsync subject = do value - getValue subject observers - getObservers subject mapM_ (forkIO . ($ value)) observers This is what I was expecting to happen -- all the observer actions are spawned off into their own thread to run whatever code they want (either communicating back to an existing thread, or performing some long in-depth action). Interesting. That might be quite sensible. My thoughts have probably been coloured by how I've been doing things in wx. Ta for the suggestion. Cheers, -Andy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Observer pattern in Haskell?
On 9 Nov 2009, at 15:21, Eduard Sergeev wrote: Andy Gimblett-2 wrote: To help manage dependencies between state and UI elements, I looked for a Haskell version of the Observer design pattern Isn't Reactive Programming approach more suitable than Observer if we talk about Haskell? Possibly. Care to expand? If you have a more elegant solution, which fits in well with ordinary wxHaskell, I'd be interested. Cheers, -Andy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: cabal install on Windows
I figured it out. It appears to be Colour package specific. The datadir still point to c:\Program File even with --user. I manually edit the dist/setup-config and get Colour installed. After that, other packages seem working fine. Jian Fan abe...@gmail.com wrote: Does cabal install --user or --prefix work on Windows at all? I tried: cabal install colour --user cabal install --user colour etc and all failed because install try to install at c:Program Files which I don't have permission writing. I have: cabal-install version 0.6.2 using version 1.6.0.3 of the Cabal library The Glorious Glasgow Haskell Compilation System, version 6.10.4 Thanks Jian ~ ~ ~ ~ ~ ~ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Observer pattern in Haskell?
Andy Gimblett-2 wrote: Possibly. Care to expand? If you have a more elegant solution, which fits in well with ordinary wxHaskell, I'd be interested. I believe there are a few experimental frameworks built on top of wxHaskell which use Functional Reactive Programming, like http://www.haskell.org/haskellwiki/Phooey Phooey . They seem to be more ellegant, but probably less practical for now since they are still experimental. I just thought that FRP is more suitable for Haskell but probably in case of wxHaskell it is not a case. Sorry if it was off topic. -- View this message in context: http://old.nabble.com/Observer-pattern-in-Haskell--tp26267269p26269564.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: cabal install on Windows
On Mon, 2009-11-09 at 16:02 +, Michael Fan wrote: I figured it out. It appears to be Colour package specific. The datadir still point to c:\Program File even with --user. I manually edit the dist/setup-config and get Colour installed. After that, other packages seem working fine. From the ticket: http://hackage.haskell.org/trac/hackage/ticket/466 On Windows the --datadir is set independently of the --prefix (at least for libraries). This is actually quite annoying because it's not discoverable and when you do discover it you've got to set the datadir along with the prefix on the command line or in the config file. The problem is to do with relocatable packages and data files. Suppose you have a library that has data files. For a hypothetical example how about some Unicode library that uses data files of character traits. Now we want to use that library in a program and we want to have that program be relocatable. That means that at runtime the library needs to be able to locate its data files. But the place where the library was installed is completely independent of where the .exe is being run from. One way to make this appear to work is for the library data directory to not really be relocatable, then it looks like we can relocate the .exe and have it still work. Of course the .exe is not very re-locatable, in particular it cannot be relocated to another machine. This is often the use case for relocatable packages on Windows. Perhaps another solution would be to place the burden of finding the data files on the executable, or at least on the process of preparing the relocatable executable. If we made the process of generating a relocatable package more explicit we could include in that process checking for dependent library packages that use data files. We could then inform the packager and/or copy/link the necessary data files into a place where the library code will be able to find them relative to the executable. See #469. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Cabal
On Mon, 2009-11-09 at 13:08 +, Stephen Tetley wrote: At this point I'd edit the *.cabal files in each component – this is not 'the done thing', but both libraries need extra flags and as I have to compile them rarely I tend to forget the format (which appears to be Windows style full paths even though you are running Cygwin). Does it not work to say: cabal install readline \ --extra-lib-dirs=C:\cygwin\lib \ --extra-include-dirs=C:\cygwin\usr\include \ --extra-include-dirs=C:\cygwin\usr\include\readline That should work, and probably the recommendation should be for cygwin users to edit their cabal config to at add C:\cygwin\lib and C:\cygwin \usr\include as standard. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Observer pattern in Haskell?
On 9 Nov 2009, at 16:47, Eduard Sergeev wrote: Andy Gimblett-2 wrote: Possibly. Care to expand? If you have a more elegant solution, which fits in well with ordinary wxHaskell, I'd be interested. I believe there are a few experimental frameworks built on top of wxHaskell which use Functional Reactive Programming, like http://www.haskell.org/haskellwiki/Phooey Phooey . They seem to be more ellegant, but probably less practical for now since they are still experimental. I just thought that FRP is more suitable for Haskell but probably in case of wxHaskell it is not a case. Sorry if it was off topic. In that case, I am 100% in agreement with you. :-) I do look forward to using such technology in the future... Thanks! -Andy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Cabal
2009/11/9 Duncan Coutts duncan.cou...@googlemail.com: That should work, and probably the recommendation should be for cygwin users to edit their cabal config to at add C:\cygwin\lib and C:\cygwin \usr\include as standard. Hi Duncan That would definitely be the best idea, but where does the cabal config live? I have the cabal that ships with GHC-6.10.3 and can't find anything: cabal-install version 0.6.0 using version 1.6.0.1 of the Cabal library By the way, this one should be unnecessary, it was a legacy of me hacking all sorts of things to get readline installed: --extra-include-dirs=C:\cygwin\usr\include\readline Best wishes Stephen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: feldspar-language
On Mon, Nov 9, 2009 at 10:09 AM, Emil Axelsson e...@chalmers.se wrote: Nice! One of our project members has been looking at Atom, not for numerical computations, but for real-time scheduling (which Feldspar should deal with eventually). What kind of code (in terms of efficiency) does the above description compile to? Here's and example: module Main (main) where import Language.Atom main :: IO () main = do compile filter defaults design return () design :: Atom () design = atom filter $ do input - float' input output - float' output x - iirFilter filter 1 [(2,3), (4,5)] (value input) output == x -- | IIR filter implemented using direct form 2. iirFilter :: Name - Float - [(Float, Float)] - E Float - Atom (E Float) iirFilter name b0 coeffs x = do -- Create the filter taps. vs - mapM (\ i - float (name ++ show i) 0) [1 .. length coeffs] -- Cascade the filter taps together. mapM_ (\ (vA, vB) - vA == value vB) $ zip (tail vs) vs -- Calculate the input to the chain of taps. let w0 = sum ( x : [ (value v) * Const (-a) | (v, (a, _)) - zip vs coeffs ]) bs = b0 : (snd $ unzip coeffs) ws = w0 : map value vs us = [ w * Const b | (w, b) - zip ws bs ] head vs == w0 -- Return the output. return $ sum us Here's the generated C. Note the filter calculation is done entirely by function __r0: static unsigned long long __global_clock = 0; static const unsigned long __coverage_len = 1; static unsigned long __coverage[1] = {0}; static unsigned long __coverage_index = 0; static float __v1 = 0; /* filter.filter.filter2 */ static float __v0 = 0; /* filter.filter.filter1 */ /* filter.filter */ static void __r0(void) { unsigned char __0 = 1; float __1 = 0.0; float __2 = input; float __3 = __1 + __2; float __4 = __v0 /* filter.filter.filter1 */ ; float __5 = -2.0; float __6 = __4 * __5; float __7 = __3 + __6; float __8 = __v1 /* filter.filter.filter2 */ ; float __9 = -4.0; float __10 = __8 * __9; float __11 = __7 + __10; float __12 = 1.0; float __13 = __11 * __12; float __14 = __1 + __13; float __15 = 3.0; float __16 = __4 * __15; float __17 = __14 + __16; float __18 = 5.0; float __19 = __8 * __18; float __20 = __17 + __19; if (__0) { __coverage[0] = __coverage[0] | (1 0); } output = __20; __v0 /* filter.filter.filter1 */ = __11; __v1 /* filter.filter.filter2 */ = __4; } void filter(void) { { static unsigned char __scheduling_clock = 0; if (__scheduling_clock == 0) { __r0(); /* filter.filter */ __scheduling_clock = 0; } else { __scheduling_clock = __scheduling_clock - 1; } } __global_clock = __global_clock + 1; } ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Observer pattern in Haskell?
Andy Gimblett wrote: was a bit surprised at first that the observers were called synchronously. Asynchronous is what I'd expect, and it's also harder to code the asynchronous handlers wrongly. One blocking call (such as putMVar) in a synchronous handler can screw up your whole program by delaying the subsequent observers (and at that stage, the order in which the observers were added begins to matter). True, but the observers shouldn't be able to access the MVars directly, I think? They should only be able to use the exposed interface, which won't let that happen? Just to clarify -- I meant access to another MVar. Basically, if I do this: do v - newMVar addObserver sub (putMVar v) If when the observers are run, the MVar v (that I've allocated) is non-empty, my code will block until it is empty, which will also block all the subsequent observers from being run (and block the code that called setValue) until the MVar is cleared by another thread. So my one poorly-written observer could deadlock (or cause stutter in) the system, whereas in the forkIO version, this observer would be fine -- it would block in its own new thread. Thanks, Neil. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] O'Haskell
That sounds vaguely ominous... Sir, we've achieved reactive in O'Haskell, we'll have ten minutes till the VB GUI detects his IP address! ... But in all seriousness, it is my understanding that O'Haskell has fallen into disuse. IIRC Timber is the spiritual successor, but I have no idea how accurate that information is. As for implementing reactive in such a language, I imagine it would be pretty easy, as FRP is a _functional_ (hence the name) construct. Objects ought only get in the way (assuming they introduce possibly conflicting syntax) /Joe On Nov 9, 2009, at 7:17 AM, shengwang wrote: Hi, Somebody has idea, how to achieve reactive in O'Haskell? Shawn Wang 使用新一代 Windows Live Messenger 轻松交流和共享! 立刻下载! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Observer pattern in Haskell?
On 9 Nov 2009, at 17:41, Neil Brown wrote: Just to clarify -- I meant access to another MVar. Basically, if I do this: do v - newMVar addObserver sub (putMVar v) If when the observers are run, the MVar v (that I've allocated) is non-empty, my code will block until it is empty, which will also block all the subsequent observers from being run (and block the code that called setValue) until the MVar is cleared by another thread. So my one poorly-written observer could deadlock (or cause stutter in) the system, whereas in the forkIO version, this observer would be fine -- it would block in its own new thread. Ah yes, of course - I understand. Of course, there's nothing really to stop application authors doing such things in the main thread too... ;-) Thanks for the clarification, -Andy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] classes question
Hi. I am using Hugs 98 I have that piece of code: class PlusTimes a where plus :: a - a - a instance PlusTimes Int where plus x y = x + y when I run : plus 2 3 I get this error: ERROR - Unresolved overloading *** Type : (Num a, PlusTimes a) = a *** Expression : plus 2 3 What am I doing wrong? Thanks. -- View this message in context: http://old.nabble.com/classes-question-tp26271257p26271257.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] classes question
You did not specify what type of number it is -- in Haskell numeric constants like 1 are actually typed as forall a. Num a -- that is, can be any type of Num. Try: plus (2::Int) 3 -Ross On Nov 9, 2009, at 1:44 PM, Paul Tokarev wrote: Hi. I am using Hugs 98 I have that piece of code: class PlusTimes a where plus :: a - a - a instance PlusTimes Int where plus x y = x + y when I run : plus 2 3 I get this error: ERROR - Unresolved overloading *** Type : (Num a, PlusTimes a) = a *** Expression : plus 2 3 What am I doing wrong? Thanks. -- View this message in context: http://old.nabble.com/classes-question-tp26271257p26271257.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com . ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] classes question
(+) is a name that is already taken by the Num typeclass, you're trying to overload it with a different class. It's equivalent to doing: foo :: Int foo = 1 foo :: String foo = abc this would cause an (obvious) namespace collision. If you want to redefine (+), you'll have to import a qualified prelude, by using the NoImplicitPrelude pragma and `import qualified Prelude`. A better alternative is to use a different name, `+`, `++` are both taken (for normal addition and list concatenation, resp.). /Joe On Nov 9, 2009, at 1:44 PM, Paul Tokarev wrote: Hi. I am using Hugs 98 I have that piece of code: class PlusTimes a where plus :: a - a - a instance PlusTimes Int where plus x y = x + y when I run : plus 2 3 I get this error: ERROR - Unresolved overloading *** Type : (Num a, PlusTimes a) = a *** Expression : plus 2 3 What am I doing wrong? Thanks. -- View this message in context: http://old.nabble.com/classes-question-tp26271257p26271257.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] classes question
Oh, crap, I'm sorry, I completely misread your post... Disregard my previous message. /Joe On Nov 9, 2009, at 1:44 PM, Paul Tokarev wrote: Hi. I am using Hugs 98 I have that piece of code: class PlusTimes a where plus :: a - a - a instance PlusTimes Int where plus x y = x + y when I run : plus 2 3 I get this error: ERROR - Unresolved overloading *** Type : (Num a, PlusTimes a) = a *** Expression : plus 2 3 What am I doing wrong? Thanks. -- View this message in context: http://old.nabble.com/classes-question-tp26271257p26271257.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Cabal
On Sun, 2009-11-08 at 19:29 -0800, Philippos Apolinarius wrote: D:\ghc\ghcapicabal install mkcabal Note that as of cabal-install-0.8, the mkcabal functionality is integrated as cabal init (thanks to Brent Yorgey). This does not depend on less portable packages like pcre and readline (meaning it will work on Windows). Resolving dependencies... Downloading pcre-light-0.3.1... Configuring pcre-light-0.3.1... There's no reason pcre-light needs a configure script. It should be removed. (It's also not used consistently, the Setup.hs is for a different build-type than the one specified in the .cabal file). Downloading readline-1.0.1.0... Configuring readline-1.0.1.0... cabal: Error: some packages failed to install: mkcabal-0.4.2 depends on readline-1.0.1.0 which failed to install. pcre-light-0.3.1 failed during the configure step. The exception was: exit: ExitFailure 1 readline-1.0.1.0 failed during the configure step. The exception was: exit: ExitFailure 1 As of Cabal-1.8 the error is reported as: cabal: The package has a './configure' script. This requires a Unix compatibility toolchain such as MinGW+MSYS or Cygwin. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] strict mapM implementation correctness
Hi all, while coding recently I came across the need for a strict mapM (that I indicidently use for m = MaybeT IO). I implementented this with the following simple code (it works for my use case): mapM' :: Monad m = (a- m b) - [a] - m [b] mapM' _ [] = return [] mapM' f (x:xs) = do y - f x ys - y `seq` mapM' f xs return (y:ys) Now a couple of questions: 1. is it so rare to need such a beast? Why there isn't anything like that in standard libraries? 2. Is my implementation correct? 3. I've seen that mapM is implemented in base via sequence (which is in turn based on foldr). Is that any specific reason to prefer base implementation to mine? Thanks! Pao ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] classes question
Thanks, that works. But how sould I change my class definition, so that it works without (2::Int), but just with 2? Ross Mellgren wrote: You did not specify what type of number it is -- in Haskell numeric constants like 1 are actually typed as forall a. Num a -- that is, can be any type of Num. Try: plus (2::Int) 3 -Ross On Nov 9, 2009, at 1:44 PM, Paul Tokarev wrote: Hi. I am using Hugs 98 I have that piece of code: class PlusTimes a where plus :: a - a - a instance PlusTimes Int where plus x y = x + y when I run : plus 2 3 I get this error: ERROR - Unresolved overloading *** Type : (Num a, PlusTimes a) = a *** Expression : plus 2 3 What am I doing wrong? Thanks. -- View this message in context: http://old.nabble.com/classes-question-tp26271257p26271257.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com . ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- View this message in context: http://old.nabble.com/classes-question-tp26271257p26274624.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] classes question
It's not your class definition that is the problem -- your class definition is good. The problem is that when you interact with it using the REPL, you don't specify any particular type you want so it's ambiguous. Usually this is not a problem in actual programs that you compile because there's enough context for the type inferencer to figure out what type 'a' should be. You can give it enough context in the REPL either by annotating the value or by using some other typed thing, e.g. let a = 1:: Int If you really want it to only work on Int, then you shouldn't use a typeclass, instead just write the function directly -- plus :: Int - Int - Int plus = (+) -Ross On Nov 9, 2009, at 5:09 PM, Paul Tokarev wrote: Thanks, that works. But how sould I change my class definition, so that it works without (2::Int), but just with 2? Ross Mellgren wrote: You did not specify what type of number it is -- in Haskell numeric constants like 1 are actually typed as forall a. Num a -- that is, can be any type of Num. Try: plus (2::Int) 3 -Ross On Nov 9, 2009, at 1:44 PM, Paul Tokarev wrote: Hi. I am using Hugs 98 I have that piece of code: class PlusTimes a where plus :: a - a - a instance PlusTimes Int where plus x y = x + y when I run : plus 2 3 I get this error: ERROR - Unresolved overloading *** Type : (Num a, PlusTimes a) = a *** Expression : plus 2 3 What am I doing wrong? Thanks. -- View this message in context: http://old.nabble.com/classes-question-tp26271257p26271257.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com . ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- View this message in context: http://old.nabble.com/classes-question-tp26271257p26274624.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com . ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] is proof by testing possible?
I have come across an example: However, the following proof of the lovely identity: sum . map (^3) $ [1..n] = (sum $ [1..n])^2 is perfectly rigorous. Proof: True for n = 0, 1, 2, 3, 4 (check!), hence true for all n. QED. In order to turn this into a full-fledged proof, all you have to do is mumble the following incantation: Both sides are polynomials of degree ≤ 4, hence it is enough to check the identity at five distinct values. from http://www.math.rutgers.edu/~zeilberg/mamarim/mamarimPDF/enquiry.pdf Now this sort of idea surely applies to more than just number theory? -- View this message in context: http://old.nabble.com/is-proof-by-testing-possible--tp25860155p26274773.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Cabal
On Mon, 2009-11-09 at 17:40 +, Stephen Tetley wrote: 2009/11/9 Duncan Coutts duncan.cou...@googlemail.com: That should work, and probably the recommendation should be for cygwin users to edit their cabal config to at add C:\cygwin\lib and C:\cygwin \usr\include as standard. Hi Duncan That would definitely be the best idea, but where does the cabal config live? If you were running the current version then cabal --help would say. To upgrade run: cabal install cabal-install Otherwise, it's somewhere like C:\Documents and Settings\$user\Application Data\cabal\config though on some systems (vista perhaps?) I think it's under the user's roaming profile directory. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Observer pattern in Haskell?
I haven't looked at the code extensively, I just wanted to comment on this point: There is no way to remove an observer, which is something I'd expect to have available. I realise this would require assigning a key to each observer (and thus perhaps storing them in an associative map) or some way to filter them, but I think if you can only ever add observers, it will get awkward. It might be convenient to have the `addObserver` function return a detachment function as its result. At Microsoft, Erik Meijer is working on an Rx framework [1], which is an implementation of the GoF Observer pattern. The implementation is, as Erik describes it, the mathematical dual of the Enumerable pattern. In the Rx framework, the `addObserver` method returns an `IDisposable` object with a single method `dispose()`, this will detach the observer from its subject. This is more convenient than trying to remember the unique object identity of the observer (as that disallows anonymous lambdas). I don't know how this would work in a Haskell context, but it might be interesting to think about. - Tom Lokhorst [1]: http://channel9.msdn.com/shows/Going+Deep/Expert-to-Expert-Brian-Beckman-and-Erik-Meijer-Inside-the-NET-Reactive-Framework-Rx/ On Mon, Nov 9, 2009 at 3:50 PM, Neil Brown nc...@kent.ac.uk wrote: Andy Gimblett wrote: Hi all, I've been doing some GUI programming recently, using wx. To help manage dependencies between state and UI elements, I looked for a Haskell version of the Observer design pattern, and I found an implementation written by Bastiaan Heeren of ou.nl [1]. Now, before I make a hackage release: 1. Does anyone have any comments, on either version? There is no way to remove an observer, which is something I'd expect to have available. I realise this would require assigning a key to each observer (and thus perhaps storing them in an associative map) or some way to filter them, but I think if you can only ever add observers, it will get awkward. 2. In particular, is the MVar version sensible? I'm aiming for mutual exclusion between threads. I _think_ I've got it, but I'm perhaps not familiar enough with the semantics of MVar to be certain. Advice appreciated. If it _is_ sensible, then is there any reason not to just use this, and discard the IORef version? It looks fine (and thread-safe) to me, but I'd agree that you may as well just use the MVar version and leave out the IORef version. The current implementation is synchronous, in that any observer functions are called immediately and synchronously (and in the same thread as the change of subject value). I'm pondering extending the package with an asynchronous version where the update just trips a flag, and the observer function picks this up later - possibly in another thread. The idea there is to help in cases where certain operations have to be in a particular thread. But this will mean a change to the typeclass too, I guess - or the addition of another one for observers themselves. Again, any thoughts? I was a bit surprised at first that the observers were called synchronously. Asynchronous is what I'd expect, and it's also harder to code the asynchronous handlers wrongly. One blocking call (such as putMVar) in a synchronous handler can screw up your whole program by delaying the subsequent observers (and at that stage, the order in which the observers were added begins to matter). But my idea of how asynchronous would be implemented seems different to yours, judging by your description. Why not just augment this function in the synchronous version: notifyObservers :: Subject sub val = sub - IO () notifyObservers subject = do value - getValue subject observers - getObservers subject mapM_ ($ value) observers to become: notifyObserversAsync :: Subject sub val = sub - IO () notifyObserversAsync subject = do value - getValue subject observers - getObservers subject mapM_ (forkIO . ($ value)) observers This is what I was expecting to happen -- all the observer actions are spawned off into their own thread to run whatever code they want (either communicating back to an existing thread, or performing some long in-depth action). Thanks, Neil. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Type-indexed expressions with fixpoint
Hi all, This email is literate Haskell. I'm struggling to come up with the right way to add a fixpoint constructor to an expression language described by a type-indexed GADT (details below). Any suggestions, comments, or pointers welcome. {-# LANGUAGE KindSignatures, GADTs #-} Consider the following type-indexed GADT, which encodes descriptions of polymorphic regular types: data U :: (* - *) - * where Unit :: U None Var :: U Id (:+:) :: U f - U g - U (Sum f g) (:*:) :: U f - U g - U (Prod f g) data None a = None data Id a = Id a data Sum f g a = Inl (f a) | Inr (g a) data Prod f g a = Prod (f a) (g a) Given u :: U f, thanks to the type indexing, we can write the following function to enumerate all the shapes of a given size described by u: enumShapes :: Int - U f - [f ()] enumShapes 0 Unit = [None] enumShapes _ Unit = [] enumShapes 1 Var = [Id ()] enumShapes _ Var = [] enumShapes n (f :+: g) = map Inl (enumShapes n f) ++ map Inr (enumShapes n g) enumShapes n (f :*: g) = [ Prod x y | x - enumShapes n f, y - enumShapes n g ] But of course this isn't very interesting without adding a least fixpoint constructor. That is, I'd like to have something like data U :: (* - *) - * where Unit :: U None Var :: U Id (:+:) :: U f - U g - U (Sum f g) (:*:) :: U f - U g - U (Prod f g) Mu:: ??? enumShapes n (Mu ...) = ... But I am quite at a loss as far as expressing the type of Mu. If the GADT wasn't type-indexed, I'd just use HOAS, i.e. Mu :: (U - U) - U; but since Haskell doesn't have type-level lambdas, I don't see how to make that work. Suggestions greatly appreciated! Pointing out that I am looking at this in the wrong way (if you think such is the case) would be highly appreciated as well. thanks, -Brent ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Exciting job opportunity
Principal investment firm based in Manhattan is looking for an outstanding software developer to maintain and develop proprietary accounting and portfolio management systems. You should have at least a bachelor’s degree in computer science from a top university and impeccable coding style. This is a high-impact, high-visibility job opportunity where successful candidates will be entrusted with a lot of responsibility for products that have a direct effect on the PL of the firm and influences our workflow. This is a very small hedge fund with me being the only developer right now. The next hire will have a very direct say into how this side of our business progresses from here. We are a growth oriented firm that values people who take a craftsman’s pride in their work. We always like to take a contrarian view of things and value experimenting and using often overlooked technologies. That is one of the main reasons why we currently started using Haskell in developing our quantitative models. We are looking for a canditate who shows strong analytical, organizational, and communication skills. Attention to detail is essential, i.e. we fully document everything we do and pay a lot of attention to coding style. The majority of our existing code was written in Java, so candidates must have at least some experience with Java and related technologies. Experience working with SQL would be desired as well. Background in accounting is not necessary but is definitely a plus. Please send your CV and cover letter to recruitment at karamaan.com, or reply to this post if you have any questions. Thanks -- View this message in context: http://old.nabble.com/Exciting-job-opportunity-tp26275652p26275652.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: acme-dont
On Nov 9, 2009, at 11:27 PM, Gracjan Polak wrote: With special apologies to Luke Palmer that it took the Haskell community 7.5 years to catch up with Perl. We may not have had the simple name don't, but we've been able to write const $ return () for a long time. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Help Haskell driving Medical Instruments
Recently, I received as gift medical instruments designed by one of my father former students. There is a description of these instruments on my web page. Here is the address: http://www.discenda.org/med/ By the way, I am not that guy that appears in a picture wearing emg sensors. That said, the instruments and everything else are programmed in Clean. Then I have a new opportunity of translating Clean programs to Haskell and test them in a real application application. Of course, I simplified the programs to see how they work. The medical instruments have on-board computers, that record signals (electromyograms, electroencephalograms, electrocardiograms, end-tydal CO2 partial pressure and temperature), pre-process them and send them to the main computer. The main-computer recognizes patterns in the signals, and use the result to drive a wheelchair, or to call a doctor. On my page you wil find more complete explanations and pictures of the instruments. For ready reference, here is my address: http://www.discenda.org/med/ I decided start my translation work from the most simple programs, the graphical interface and the communication protocol. After substituting a Haskell program for the Clean original, I discovered that the system did not work anymore if I exited the Haskell program. In few words, after leaving the Haskell program without turning off the computer or the sensors, and entering the Haskell program again, Haskell failed to communicate with the sensors. I did what I always do in such a situation: I simplified the program until I reduced it to a few lines. I discovered that Haskell failed to close the serial port. There is a serial to UART-0 driver that allows me to plug the serial cable to a USB port, that both feeds the sensors, and permit communication. I fixed the bug by passing a useless integer argument to the function used to close the port. Since I don't like this kind of patch (useless arguments), I would like to know why the original program does not work, and also I would appreciate if someone could suggest a way to get rid of the argument whose sole job is force Haskell to close the port. The GUI is based on the Small JAPI biding, fixed and incremented with text processing components. Here is the fixed Haskell program: import Gui.Binding import Gui.Types import Gui.Constants import SER.IAL import Control.Monad import Data.Char main = do rv - j_start frame - j_frame Sensors exit_button - j_button frame Exit j_setpos exit_button 50 50 j_setsize exit_button 80 30 fld - j_textfield frame 30 j_setpos fld 50 100 j_show frame opencport(4) waitForFrameAction frame fld exit_button let r = closecport 7 {- without the argument, closecport does not work -} print r return j_quit waitForFrameAction :: Frame - Object - Object - IO Bool waitForFrameAction frame f b = do obj - j_nextaction again - if obj == event b then return False else do {- nm - j_gettext f 200 -} tx - sendMessage 1 t let tp= filter ( ' ') tx rx - sendMessage 1 x let rd= filter ( ' ') rx let x = hex2dec rd let tt= (fromIntegral x)*209.0/1024 - 67.5 j_settext f ((show tt)++ == ++tp) return True if not again then return True else waitForFrameAction frame f b hex2dec :: String - Int hex2dec h= sum (zipWith (*) (map (16^) [3,2,1,0]) [digitToInt c | c - h]) convert d r s0= (fromIntegral (hex2dec d))*r/1024.0- s0 As I told before, let r = closecport 7 did not work until I gave it an argument. Here is the interface between the C-side, and the Haskell-side of the program: {-# LANGUAGE ForeignFunctionInterface #-} module SER.IAL where import Control.Monad import Foreign import Foreign.C.Types import Foreign.C foreign import ccall rs232.h opencport opencport :: CInt - IO () foreign import ccall rs232.h closecport closecport :: CInt - CInt foreign import ccall rs232.h rdrs232 c_sendmsg :: CInt - CString - CString sendMessage :: Int - String - IO String sendMessage n msg = withCString msg $ \str - peekCString (c_sendmsg (fromIntegral n) str) Originally, I had the following line (that did not work properly): foreign import ccall rs232.h closecport closecport :: IO () You will find below the C-program. The original program (that did not work) had the following definition for closecport: int closecport() { CloseComport(); return 3; } This deffinition (that did not work) was replaced by the following one: int closecport(int n) { CloseComport(); return n; } Here is the complete C program: #include serial.h #include string.h #include stdio.h /*
Re: [Haskell-cafe] is proof by testing possible?
On 2009-11-09 14:22 -0800 (Mon), muad wrote: Proof: True for n = 0, 1, 2, 3, 4 (check!), hence true for all n. QED. ... Actually, the test is that it's true for 0 through 4 is not sufficient for a proof; you also need to prove in some way that you need do no further tests. Showing that particular point in this case appears to me to lie outside the realm of testing. cjs -- Curt Sampson c...@starling-software.com+81 90 7737 2974 Functional programming in all senses of the word: http://www.starling-software.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Help Haskell driving Medical Instruments
Does marking the call `unsafe` make any difference? This is running on a *NIX of some flavour? -- Jason Dusek ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe