[Haskell-cafe] Re: understanding enumerator/iteratee
Artyom Shalkhakov wrote I would say that it [iteratee] just tells us how to react to various forms of input. :) This is much like the function you pass to foldr. Precisely. To sum up all elements of Data.Map, we do Map.fold (+) 0 mp to sum up all elements of a set we do Set.fold (+) 0 st ditto for any other foldable data structure. Clearly the function that sums the current element with the accumulator, (+), doesn't know or care from which collection the elements are coming from. The initial seed, 0, is again unaware of the collection. Iteratee is indeed the function that you pass to fold (combined with the seed for practical reasons). One may conceptually consider iteratee to be a pair of the function to feed to fold, and the initial seed (the accumulator in the above example). That achieves the separation of concerns: fold (aka, enumerator) has the intimate knowledge of the collection and how to get to the next element; iteratee knows what to do with the current element. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] intercalate and (byte)strings
Hi wman, -- B == Data.ByteString ; L == Data.ByteString.Lazy contents' = B.intercalate B.empty $ L.toChunks contents with a previously unencountered function intercalate. A quick google query later i knew that it's just intersperse concat nicely bundled and started wondering why anybody would do this, as simple contents' = B.concat $ L.toChunks contents would do (probably nearly) the same. The only thing I am able to come up with is that it somehow helps streamline the memory usage (if it has some meaning). Is there some reason to use intercalate empty list instead of concat list (probably when dealing with non-lazy bytestrings) ? If they do the same thing, no - and I'm pretty sure they are identical. If a much more efficient version of concat was intercalate empty, then the bytestring authors would have just defined: concat = interacalate empty It's best to use the clearest code, always. Performance is something for library authors. (It is sometimes acceptable to use the non clearest code for performance, but it is 100% mandatory to add a comment to that effect!) Thanks Neil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] New Haskell logo contest
I think this logo contest is a great idea. I submitted my classy Haskell logo from the merch. page, but I have to admit I like some of the other ones on the submission page a whole lot. Hey, *here's* an idea: maybe whoever wins the logo contest has to take over management of the Haskell merchandise page on CafePress! :) -- Fritz Ruehr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Parsec question
Hi all, I'm rather new to Haskell and I'm diving right into the deep end writing a parser using Parsec. In particular I'm using Text.ParserCombinators.Parsec.Language to do some of the heavy lifting and have this: import qualified Text.ParserCombinators.Parsec.Language as L import qualified Text.ParserCombinators.Parsec.Token as T lexer = T.makeTokenParser L.emptyDef { L.identStart = letter | char '_', L.identLetter = alphaNum | char '_', identifier :: CharParser st String identifier = T.identifier lexer and now I need to parse things this.that.the.other. I'd like to have a function with the following signature: qualifiedIdentifier :: CharParser st [ String ] which should return [ this, that, the, other ] and write it in terms of identifier and thats where I'm stuck. Anyone care to whack me with the cluestick? Cheers, Erik -- - Erik de Castro Lopo - If you don't have freedom as a principle, you can never see a reason not to make an exception. -- Richard Stallman. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Initializing GHC from Python
Hi, We have just published a small article on how one can initialize GHC from Python, with only optional use of C. You can read it at http://gamr7.com/blog/?p=65 . Best regards, Ron de Bruijn ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parsec question
Erik de Castro Lopo wrote: qualifiedIdentifier :: CharParser st [ String ] Ahh, figured it out myself: qualifiedIdentifier :: CharParser st [ String ] qualifiedIdentifier = do i - identifier r - dotIdentifier return (i : r) where dotIdentifier = do char '.' i - identifier r - dotIdentifier return (i : r) | return [] Does that look sane to people who know Haskell and Parsec better than me? Erik -- - Erik de Castro Lopo - The Earth is around 70% water. Fish rule the seas. Humans are over 90% water. It's only a matter of time. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: concurrent haskell: thread priorities
Bulat Ziganshin wrote: Hello Neal, Monday, December 22, 2008, 11:07:32 PM, you wrote: The threaded RT creates an OS thread for each CPU/core on the system and uses them to multiplex userland threads. These are context switched whenever they block/yield/gc and no priorities can be assigned. not exactly. amount of OS threads created controlled by +RTS -N option to the program; unless program has special function that RTS calls to set up this value they are switched on every minor GC which by default occurs after each 256kb allocated which is rather frequent event It seems like we could get some priority based scheduling (and still be slackers) if we allow marked green threads to be strictly associated with a specific OS thread (forkChildIO?). forkOS creates new haskell thread and new OS thread specially for it The docs say that the forkOS thread is still scheduled by the Haskell RT though. What would happen if you bump its priority through FFI? What about this scenario: forkOS = OS thread A1, Haskell Thread A2 forkIO = Haskell thread B Could thread B potentially be run on thread A1? Would the RT yield thread A2 to give time to another Haskell thread? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Problems Installing Takusen with Sqlite Backend
From: haskell-cafe-boun...@haskell.org [mailto:haskell-cafe-boun...@haskell.org] On Behalf Of Günther Schmidt what does it take to install Takusen on Win32 with Sqlite backend? I did manage to install *plain* Takusen via cabal install by downgrading to Cabal-1.4 but when I want to cabal-install takusen -fsqlite it complains about a missing sqlite3. Setup.hs tries to find the location of your sqlite installation by looking for sqlite3.exe, so you need this (and sqlite.dll) in your path. 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
Re: [Haskell-cafe] Problems Installing Takusen with Sqlite Backend
Thanks Alistair, inspiration had stuck me meanwhile and that's exactly what I did. Günther Bayley, Alistair schrieb: From: haskell-cafe-boun...@haskell.org [mailto:haskell-cafe-boun...@haskell.org] On Behalf Of Günther Schmidt what does it take to install Takusen on Win32 with Sqlite backend? I did manage to install *plain* Takusen via cabal install by downgrading to Cabal-1.4 but when I want to cabal-install takusen -fsqlite it complains about a missing sqlite3. Setup.hs tries to find the location of your sqlite installation by looking for sqlite3.exe, so you need this (and sqlite.dll) in your path. 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
[Haskell-cafe] Re: Parsec question
Erik de Castro Lopo schrieb: Erik de Castro Lopo wrote: qualifiedIdentifier :: CharParser st [ String ] Ahh, figured it out myself: qualifiedIdentifier :: CharParser st [ String ] qualifiedIdentifier = do i - identifier r - dotIdentifier return (i : r) where dotIdentifier = do char '.' i - identifier r - dotIdentifier return (i : r) | return [] Does that look sane to people who know Haskell and Parsec better than me? Hi Erik, have a look at the module Text.ParserCombinators.Parsec.Combinator. Those functions should help you to build up parsers from smaller building blocks. Using sepBy1, the above parser can be written as dot = T.dot lexer qualifiedIdentifier = sepBy1 identifier dot benedikt ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Cabal Install Links to Source from Haddock Docs
On Mon, 2008-12-22 at 17:58 -0800, R Hayes wrote: Thank you. As it turns out, I was aware of that recipe. What I wanted was to be able to use cabal install's nice dependency following features and still get source links in my documentation. Due to popular demand we quickly added the --enable-documentation flag but did not manage to agree a design for exposing the other haddock/documentation flags via cabal install. We'd appreciate if you could add your suggestions for the design of the command line interface to this ticket: http://hackage.haskell.org/trac/hackage/ticket/206 Personally, I feel that inclusion of source and docs should be the DEFAULT for cabal, as well as for binary distributions of ghc. You can set it as a default in the ~/.cabal/config file. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Parsec question
Benedikt Huber wrote: have a look at the module Text.ParserCombinators.Parsec.Combinator. Those functions should help you to build up parsers from smaller building blocks. Using sepBy1, the above parser can be written as dot = T.dot lexer qualifiedIdentifier = sepBy1 identifier dot WOW That is really impressive! Thanks, Erik -- - Erik de Castro Lopo - One serious obstacle to the adoption of good programming languages is the notion that everything has to be sacrificed for speed. In computer languages as in life, speed kills. -- Mike Vanier ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Threads with high CPU usage
On Tue, 2008-12-23 at 03:56 +0100, wman wrote: Thanks to you all for inspiration. My web app (which otherwise ran ok) was getting stuck while getting harassed by ab (apache-benchmark) after receiving some 800+ requests in short succession (not less, never gotten to 900, what was weird that running like 500 reqs - pause - 500 reqs ... went ok). After compiling with -threaded and running with +RTS -N2 it handles 10k+ requests (with 10 concurrent request running at once) without missing a beat. How about compiled with -threaded and running with just +RTS -N1 ? I would expect the crucial thing is the -threaded not the number of cpus running Haskell code concurrently (-threaded uses a pool of OS threads to make blocking foreign calls effectively non-blocking). Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] What are side effects in Haskell?
Hello All, I just saw somewhere that one of the purposes of monads is to capture side effects. I understand what a side effect is in C, for example. Say you want to switch the contents of two variables. Then you need a third temporary variable to store an intermediate result. If this is global, then it will be changed by the operation. But what is a side effect in an fp language like Haskell? As a follow up, I understand why an IO action like getLine or getChar is not a function; its results can be different for different calls. But why not have something like getChar c or getLine str? The types of c or str are pretty clear, aren't they? Just something that's been puzzling me for some time now...thanks. Regards, Hans van Thiel ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [Byte8] - ByteString
On Tue, 2008-12-23 at 00:34 -0600, Galchin, Vasili wrote: Hello, I have been reading through Data-ByteString. What is the is most elegant and efficient way to map/unmap [Byte8] - ByteString? Hoogle is your friend! http://haskell.org/hoogle/ [Word8] - ByteString http://haskell.org/hoogle/?hoogle=%5BWord8%5D+-%3E+ByteString ByteString - [Word8] http://haskell.org/hoogle/?hoogle=ByteString+-%3E+%5BWord8%5D Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] intercalate and (byte)strings
On Tue, 2008-12-23 at 05:21 +0100, wman wrote: I encountered the following code : -- B == Data.ByteString ; L == Data.ByteString.Lazy contents' = B.intercalate B.empty $ L.toChunks contents with a previously unencountered function intercalate. A quick google query later i knew that it's just intersperse concat nicely bundled and started wondering why anybody would do this, as simple contents' = B.concat $ L.toChunks contents would do (probably nearly) the same. The only thing I am able to come up with is that it somehow helps streamline the memory usage (if it has some meaning). Is there some reason to use intercalate empty list instead of concat list (probably when dealing with non-lazy bytestrings) ? I cannot see any advantage. I would be extremely surprised if the more obscure version was faster. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] intercalate and (byte)strings
Thank you, guys, i somehow got the impression that there has to be some meaning to this. It seemed unprobable, but why would anybody write it like that if there weren't some reason to it ? ;-))) Have a nice holidays, btw. Cheers, wman. On Tue, Dec 23, 2008 at 3:21 PM, Duncan Coutts duncan.cou...@worc.ox.ac.ukwrote: On Tue, 2008-12-23 at 05:21 +0100, wman wrote: I encountered the following code : -- B == Data.ByteString ; L == Data.ByteString.Lazy contents' = B.intercalate B.empty $ L.toChunks contents with a previously unencountered function intercalate. A quick google query later i knew that it's just intersperse concat nicely bundled and started wondering why anybody would do this, as simple contents' = B.concat $ L.toChunks contents would do (probably nearly) the same. The only thing I am able to come up with is that it somehow helps streamline the memory usage (if it has some meaning). Is there some reason to use intercalate empty list instead of concat list (probably when dealing with non-lazy bytestrings) ? I cannot see any advantage. I would be extremely surprised if the more obscure version was faster. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What are side effects in Haskell?
On Tue, Dec 23, 2008 at 3:16 PM, Hans van Thiel hthiel.c...@zonnet.nl wrote: Hello All, I just saw somewhere that one of the purposes of monads is to capture side effects. I understand what a side effect is in C, for example. Say you want to switch the contents of two variables. Then you need a third temporary variable to store an intermediate result. If this is global, then it will be changed by the operation. But what is a side effect in an fp language like Haskell? Generally speaking, you have no side effects whenever the only result of a function is the return of its outcome, in contrast with those changing something else (like updating a database, a file, the screen output and so on). In Haskell you can't write an effectful function because its scope is limited to the function's local bindings (i.e. its input arguments and any other name locally defined in its definition). If you want something global to affect a function's operations you have to pass it, either explicitly (pure functions) or implicitly (monadic actions). Likewise, if you want to persist an effect after a function's execution you have to gather it from the returned value and feed it to any other subsequent function calls. Though, notice that there are exceptions to the above rule (namely unsafePerformIO) but they are kind of tricks. As a follow up, I understand why an IO action like getLine or getChar is not a function; its results can be different for different calls. Anything in Haskell is a function: getLine and getChar ARE functions returning actions to be executed in the IO Monad, i.e. at run-time. But why not have something like getChar c or getLine str? The types of c or str are pretty clear, aren't they? Because c are not effected by getChar or getLine, as they are outside the scope of the functions. What you are really passing to getChar/getLine is just the content of c and str which goes out of the scope just after the functions have finished executing. Hope this helps. Cristiano ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: What are side effects in Haskell?
Hans van Thiel wrote: I just saw somewhere that one of the purposes of monads is to capture side effects. There are a few things that have side effects. The best way to capture this is to see that there are both (1) commands whose result depends on some external state (2) commands which alter that state The (2) group has side effects, and (1) is affected by them. The order in which (1) and (2) are performed matters. commands that evaluate to different things based on environment/history/input: * reading from memory location or reference * reading from a file or network stream or sensor (e.g. keyboard or mouse) * a random or pseudo-random number generator commands which affect the environment * writing to a memory location or reference * writing to a file or network * changing the display buffer (i.e. windows on the screen) command which are both (1) and (2), often because they might fail: * creating or deleting a file * obtaining a lock or semaphore * interacting with a message queue So allocating a mutable variable and writing to it are side-effect operations which have to be carefully ordered with the corresponding reads. Things without side effects are the immutable bindings produced by let/where, and application of functions. This is independent of being lazy or strict. Note that putStr :: String - IO () is a function, and as such it is a pure value. putString ['a','b','\n'] is a pure value of IO (). Performing this command in the IO monad has side effects. The fact that functions like putStr and things with types of IO () are pure value means that they can be produced and passed around is powerful way of working. It is possible to create objects in C++/Java which encapsulate an operation, but it takes more syntax. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Stupid question #374: why is MaybeT not in the standard library?
On Tue, Dec 23, 2008 at 12:53 AM, Luke Palmer lrpal...@gmail.com wrote: On Mon, Dec 22, 2008 at 6:52 PM, Antoine Latter aslat...@gmail.com wrote: Although I still had to use my own because I wanted a MonadPlus instance. I would offer a patch, but since there's more than one useful MonadPlus instance for MaybeT it probably still wouldn't be right for everyone. There are? The only two I can think of are the left-biased and its dual, in which case the convention is to choose the left-biased one. Is there another? It's a monad-transformer, so the MonadPlus/Alternative instance could either apply Maybe semantics or lift the behavior of whatever it wraps. -Antoine ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] cabal, multi-file applications
Hi, I get the following error message: ce...@unique:~/lab/test/qths/hnm$ make configure runhaskell Setup.hs configure Configuring HNM-0.2... ce...@unique:~/lab/test/qths/hnm$ make build runhaskell Setup.hs build Preprocessing library HNM-0.2... Preprocessing executables for HNM-0.2... Building HNM-0.2... demo3.hs:4:7: Could not find module `HNM.WLAN': Use -v to see a list of the files searched for. make: *** [build] Error 1 when I try to build the following program: http://sert.homedns.org/hs/hnm/ http://sert.homedns.org/hs/hnm/hnm.cabal How can I tell in my cabal file that wlan.hs should be built first than settings.hs than demo3.hs? Best Regards, Cetin Sert ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] cabal, multi-file applications
-BEGIN PGP SIGNED MESSAGE- Hash: SHA512 2008/12/23 Cetin Sert : Hi, I get the following error message: ce...@unique:~/lab/test/qths/hnm$ make configure runhaskell Setup.hs configure Configuring HNM-0.2... ce...@unique:~/lab/test/qths/hnm$ make build runhaskell Setup.hs build Preprocessing library HNM-0.2... Preprocessing executables for HNM-0.2... Building HNM-0.2... demo3.hs:4:7: Could not find module `HNM.WLAN': Use -v to see a list of the files searched for. make: *** [build] Error 1 when I try to build the following program: http://sert.homedns.org/hs/hnm/ http://sert.homedns.org/hs/hnm/hnm.cabal How can I tell in my cabal file that wlan.hs should be built first than settings.hs than demo3.hs? Best Regards, Cetin Sert You need some changes like this (as a Darcs patch): adddir ./HNM move ./settings.hs ./HNM/Settings.hs move ./wlan.hs ./HNM/WLAN.hs hunk ./hnm.cabal 3 - -Description: Happy Network Manager - -License: BSD +Synopsis:Happy Network Manager +Category:Network, System +homepage:http://sert.homedns.org/hs/hnm/ +License: BSD3 hunk ./hnm.cabal 9 - -Maintainer: ce...@sertcom.de +Maintainer: hunk ./hnm.cabal 13 +data-files: settings.conf + hunk ./hnm.cabal 17 - -ghc-options: -O3 -fglasgow-exts +other-modules: HNM.WLAN, HNM.Settings +ghc-options: -O2 -fglasgow-exts Note that -O3 is counterintuitively no better than -O2, and may be worse. You should probably change the -fglasgow-exts to individual per-file {-# LANGUAGE #-} pragmas. And you don't declare all your dependencies, for example I see Gtk2Hs imports, but no declarations in build-depends:. To solve your problem, you need to put the module names in other-modules:, but your modules are at wrong names. If a module's name is HNM.Settings, then it needs to be at Settings.hs. - -- gwern -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) iEYEAREKAAYFAklRGQcACgkQvpDo5Pfl1oLDHgCfcRswCMsUUPZLknvUrENM/MmD U7gAoIBq0CXXU6XHKn0L4kGi45zENNJ3 =txxi -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] cabal, multi-file applications
On Tue, 2008-12-23 at 17:27 +0100, Cetin Sert wrote: when I try to build the following program: http://sert.homedns.org/hs/hnm/ http://sert.homedns.org/hs/hnm/hnm.cabal How can I tell in my cabal file that wlan.hs should be built first than settings.hs than demo3.hs? You need to follow the standard file name convention for modules. The module HNM.WLAN needs to be in the file HNM/WLAN.hs rather than wlan.hs. Similarly you will need to rename settings.hs to HNM/Settings.hs. That way cabal and ghc will be able to find the files. In the .cabal file you do not need these fields: Extra-Source-Files: wlan.hs, settings.hs HS-Source-Dirs: . Instead you should use: other-modules: HNM.WLAN, HNM.Settings Looking at: ghc-options: -fglasgow-exts -O3 --make you do not need '--make'. Using 'cabal check' or 'sdist' will have other suggestions for better portability and recommended practise. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] forkIO on multicore[MESSAGE NOT SCANNED]
Hi Duncan, I'm following the story regarding (parallel) GC in this example with interest, but forgive me if I ask a more minor question regarding your modification of an extra parameter, n, to heavytask. Does this really help (to ensure that each core does work independently)? Surely, with fibs now described in a where clause, the 0:1:etc. form would not be shared among the (8) instantiations of heavytask? heavytask m n = putMVar m $! (fibs !! 10) where fibs = n : (n+1) : zipWith (+) fibs (tail fibs) Regards, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Stupid question #374: why is MaybeT not in the standard library?
On Tue, Dec 23, 2008 at 2:52 AM, Antoine Latter aslat...@gmail.com wrote: Although I still had to use my own because I wanted a MonadPlus instance. I would offer a patch, but since there's more than one useful MonadPlus instance for MaybeT it probably still wouldn't be right for everyone. Umh, there is a MonadPlus instance in the package? http://hackage.haskell.org/packages/archive/MaybeT/0.1.2/doc/html/Control-Monad-Maybe.html (It's the one based on the Maybes.) - Benja ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Stupid question #374: why is MaybeT not in the standard library?
On Tue, Dec 23, 2008 at 8:05 PM, Benja Fallenstein benja.fallenst...@gmail.com wrote: Umh, there is a MonadPlus instance in the package? Ah: ...in the version Cale uploaded two days ago, not in the previous version. Sorrynevermindisee :) - Benja ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How does one use Text.Regex.Base.RegexLike?
I'm trying to migrate code from using the old Text.Regex to the new Text.Regex.Base. But, I'm getting type errors. I can't even create a regex. Looking at the docs, it seems like this should print bcd: import Data.Array import Text.Regex.Base import Text.Regex.Posix rx = makeRegex a(.*)A Just (_, mt, _) = matchOnceText rx abcdA main = putStrLn (fst (mt ! 0)) But I get an error: src\regex.hs:5:5: No instance for (RegexMaker regex compOpt execOpt [Char]) arising from a use of `makeRegex' at src\regex.hs:5:5-22 Possible fix: add an instance declaration for (RegexMaker regex compOpt execOpt [Char]) In the expression: makeRegex a(.*)A In the definition of `rx': rx = makeRegex a(.*)A src\regex.hs:7:18: No instance for (RegexLike regex [Char]) arising from a use of `matchOnceText' at src\regex.hs:7:18-41 Possible fix: add an instance declaration for (RegexLike regex [Char]) In the expression: matchOnceText rx abcdA In a pattern binding: Just (_, mt, _) = matchOnceText rx abcdA Why does it say there is no instance? Isn't the instance imported by Text.Regex.Posix? Why in the world is it so complicated just to get a matched substring out of the text? Is there an easier way? Thanks, Lyle ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] monad constraint + record update
On Mon, Dec 22, 2008 at 06:19:07PM +0100, Peter Padawitz wrote: I'd like to define a monad Set for types in the class Eq. But how can the arguments of Set be constrained when Set is defined as an instance of Monad? instance Eq a = Monad Set where ... obviously cannot work. Is there a standard update function for fields in data types, something that OO programmers do with assignments like obj.attr := value ? Peter Note there is already a package on Hackage to do exactly this, rmonad. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/rmonad -Brent ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] The Haskell re-branding exercise
eelco: On 21 dec 2008, at 22:26, Sebastian Sylvan wrote: I am very shortly travelling abroad for several weeks and will not have (reliable access to) a computer, but isn't this a task for one of the haskell web-apps people (HSP, HAppS, Turbinado, etc.) to show us once and for all why *their* library is better than the competition? :-) Hmm, right. I started on a thing in HAppS. See http://github.com/eelco/voting/ for the source code (contributors more than welcome!) and http://code.tupil.com/voting/ for a live demo. It relies heavily on javascript, needs some work on the UI and there are a lot of features that could be added, but it works. Yay! Yes, let's do something like this. -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How does one use Text.Regex.Base.RegexLike?
Hello, Does this help? http://www.serpentine.com/blog/2007/02/27/a-haskell-regular-expression-tutorial/ j. At Tue, 23 Dec 2008 11:21:41 -0800, Lyle Kopnicky wrote: [1 multipart/alternative (7bit)] [1.1 text/plain; ISO-8859-1 (7bit)] I'm trying to migrate code from using the old Text.Regex to the new Text.Regex.Base. But, I'm getting type errors. I can't even create a regex. Looking at the docs, it seems like this should print bcd: import Data.Array import Text.Regex.Base import Text.Regex.Posix rx = makeRegex a(.*)A Just (_, mt, _) = matchOnceText rx abcdA main = putStrLn (fst (mt ! 0)) But I get an error: src\regex.hs:5:5: No instance for (RegexMaker regex compOpt execOpt [Char]) arising from a use of `makeRegex' at src\regex.hs:5:5-22 Possible fix: add an instance declaration for (RegexMaker regex compOpt execOpt [Char]) In the expression: makeRegex a(.*)A In the definition of `rx': rx = makeRegex a(.*)A src\regex.hs:7:18: No instance for (RegexLike regex [Char]) arising from a use of `matchOnceText' at src\regex.hs:7:18-41 Possible fix: add an instance declaration for (RegexLike regex [Char]) In the expression: matchOnceText rx abcdA In a pattern binding: Just (_, mt, _) = matchOnceText rx abcdA Why does it say there is no instance? Isn't the instance imported by Text.Regex.Posix? Why in the world is it so complicated just to get a matched substring out of the text? Is there an easier way? Thanks, Lyle [1.2 text/html; ISO-8859-1 (7bit)] [2 text/plain; us-ascii (7bit)] ___ 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] monad constraint + record update
Is there a standard update function for fields in data types, something that OO programmers do with assignments like obj.attr := value ? Oh, I missed this question the first time. You probably want Functional References: http://twan.home.fmf.nl/blog/haskell/overloading-functional-references.details -Brent ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New Haskell logo contest
fruehr: I think this logo contest is a great idea. I submitted my classy Haskell logo from the merch. page, but I have to admit I like some of the other ones on the submission page a whole lot. Hey, *here's* an idea: maybe whoever wins the logo contest has to take over management of the Haskell merchandise page on CafePress! :) Thanks for your (nearly decade long?) involvement in the logo story, Fritz!! -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] monad constraint + record update
I think that Conal Elliot's Semantic Editor Combinators do the thing even better: http://conal.net/blog/posts/semantic-editor-combinators/ 2008/12/23 Brent Yorgey byor...@seas.upenn.edu: Is there a standard update function for fields in data types, something that OO programmers do with assignments like obj.attr := value ? Oh, I missed this question the first time. You probably want Functional References: http://twan.home.fmf.nl/blog/haskell/overloading-functional-references.details -Brent ___ 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] Re: concurrent haskell: thread priorities
Thomas DuBuisson wrote: It seems like we could get some priority based scheduling (and still be slackers) if we allow marked green threads to be strictly associated with a specific OS thread (forkChildIO?). I think you want the GHC-only GHC.Conc.forkOnIO Suggestions like this are more motivation for the suggestion [1] to adopt a re-engineered / haskell-based RTS [2]. Tom [1] http://www.reddit.com/r/haskell_proposals/comments/7itaz/simple_robust_maintainable_rts_for_ghc_io_pdf/ [2] http://www.seas.upenn.edu/~lipeng/homepage/papers/lmpjt07hw.pdf ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe GHC.Conc.forkOnIO is helpful but doest work in this case - it doesn't attach them to the same OS thread. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How does one use Text.Regex.Base.RegexLike?
Yes, sort of. It enables me to get some simple examples working with (=~). But I still don't know how to get makeRegex to work. You need it to specify options like case insensitivity, or to use functions like matchAllText. On Tue, Dec 23, 2008 at 11:29 AM, Jeremy Shaw jer...@n-heptane.com wrote: Hello, Does this help? http://www.serpentine.com/blog/2007/02/27/a-haskell-regular-expression-tutorial/ j. At Tue, 23 Dec 2008 11:21:41 -0800, Lyle Kopnicky wrote: [1 multipart/alternative (7bit)] [1.1 text/plain; ISO-8859-1 (7bit)] I'm trying to migrate code from using the old Text.Regex to the new Text.Regex.Base. But, I'm getting type errors. I can't even create a regex. Looking at the docs, it seems like this should print bcd: import Data.Array import Text.Regex.Base import Text.Regex.Posix rx = makeRegex a(.*)A Just (_, mt, _) = matchOnceText rx abcdA main = putStrLn (fst (mt ! 0)) But I get an error: src\regex.hs:5:5: No instance for (RegexMaker regex compOpt execOpt [Char]) arising from a use of `makeRegex' at src\regex.hs:5:5-22 Possible fix: add an instance declaration for (RegexMaker regex compOpt execOpt [Char]) In the expression: makeRegex a(.*)A In the definition of `rx': rx = makeRegex a(.*)A src\regex.hs:7:18: No instance for (RegexLike regex [Char]) arising from a use of `matchOnceText' at src\regex.hs:7:18-41 Possible fix: add an instance declaration for (RegexLike regex [Char]) In the expression: matchOnceText rx abcdA In a pattern binding: Just (_, mt, _) = matchOnceText rx abcdA Why does it say there is no instance? Isn't the instance imported by Text.Regex.Posix? Why in the world is it so complicated just to get a matched substring out of the text? Is there an easier way? Thanks, Lyle [1.2 text/html; ISO-8859-1 (7bit)] [2 text/plain; us-ascii (7bit)] ___ 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] How does one use Text.Regex.Base.RegexLike?
Am Dienstag, 23. Dezember 2008 21:09 schrieb Lyle Kopnicky: Yes, sort of. It enables me to get some simple examples working with (=~). But I still don't know how to get makeRegex to work. You need it to specify options like case insensitivity, or to use functions like matchAllText. Your problem is that GHC can't know which instance to choose. You can help it by giving a type signature, e.g. rx :: Regex rx = makeRegex a(.*)A HTH, Daniel At Tue, 23 Dec 2008 11:21:41 -0800, Lyle Kopnicky wrote: I'm trying to migrate code from using the old Text.Regex to the new Text.Regex.Base. But, I'm getting type errors. I can't even create a regex. Looking at the docs, it seems like this should print bcd: import Data.Array import Text.Regex.Base import Text.Regex.Posix rx = makeRegex a(.*)A Just (_, mt, _) = matchOnceText rx abcdA main = putStrLn (fst (mt ! 0)) But I get an error: src\regex.hs:5:5: No instance for (RegexMaker regex compOpt execOpt [Char]) arising from a use of `makeRegex' at src\regex.hs:5:5-22 Possible fix: add an instance declaration for (RegexMaker regex compOpt execOpt [Char]) In the expression: makeRegex a(.*)A In the definition of `rx': rx = makeRegex a(.*)A src\regex.hs:7:18: No instance for (RegexLike regex [Char]) arising from a use of `matchOnceText' at src\regex.hs:7:18-41 Possible fix: add an instance declaration for (RegexLike regex [Char]) In the expression: matchOnceText rx abcdA In a pattern binding: Just (_, mt, _) = matchOnceText rx abcdA Why does it say there is no instance? Isn't the instance imported by Text.Regex.Posix? Why in the world is it so complicated just to get a matched substring out of the text? Is there an easier way? Thanks, Lyle [1.2 text/html; ISO-8859-1 (7bit)] [2 text/plain; us-ascii (7bit)] ___ 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] How does one use Text.Regex.Base.RegexLike?
Yes, that worked, thanks. I just figured that out too. Here's a whole working program: import Text.Regex.Base import Text.Regex.Posix rx :: Regex rx = makeRegex a(.*)A mr = match rx abcdA text = head $ mrSubList mr main = putStrLn text On Tue, Dec 23, 2008 at 12:30 PM, Daniel Fischer daniel.is.fisc...@web.dewrote: Am Dienstag, 23. Dezember 2008 21:09 schrieb Lyle Kopnicky: Yes, sort of. It enables me to get some simple examples working with (=~). But I still don't know how to get makeRegex to work. You need it to specify options like case insensitivity, or to use functions like matchAllText. Your problem is that GHC can't know which instance to choose. You can help it by giving a type signature, e.g. rx :: Regex rx = makeRegex a(.*)A HTH, Daniel ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] hackage, gtk2hs
Hi, A package I want to upload only builds with the unreleased gtk2hs version from the darcs repository and not the latest released version 0.9.13 or any lesser. But the repository version seems to not have changed, so if I say in my cabal file: gtk = 0.9.14 it does not even build with the gtk2hs version from the repos, on the other hand if I say: gtk = 0.9.13 people using 0.9.13 may be surprised to see the package does not build. What should I do o__O? Wait for the next gtk2hs release before releasing my package? Or is there a way to notify _potential users/those interested_ of the need to use the latest gtk2hs they can get from the darcs repos. Best Regards, Cetin Sert ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] understanding enumerator/iteratee
Jason Dusek schrieb: I'm taking a stab at composable streams, starting with cursors. I managed to make a derived cursor today -- as I work through this stuff, I hope to understand Iteratee/Enumerator better. How about a wiki page on the roles of enumerators and iteratees, best explained using a simple example? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Stupid question #374: why is MaybeT not in the standard library?
On Tue, Dec 23, 2008 at 1:08 PM, Benja Fallenstein benja.fallenst...@gmail.com wrote: On Tue, Dec 23, 2008 at 8:05 PM, Benja Fallenstein benja.fallenst...@gmail.com wrote: Umh, there is a MonadPlus instance in the package? Ah: ...in the version Cale uploaded two days ago, not in the previous version. Sorrynevermindisee :) No, you're right - the haddock generated docs say that their is a MonadPlus instances, but the hand-written notes say that there isn't. That's what I get for reading the documentation. -Antoine ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Initializing GHC from Python
I upmodded this on Reddit. Thank you for your work. -- Jason Dusek ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] understanding enumerator/iteratee
Henning Thielemann schlepp...@henning-thielemann.de wrote: Jason Dusek schrieb: I'm taking a stab at composable streams, starting with cursors. I managed to make a derived cursor today -- as I work through this stuff, I hope to understand Iteratee/Enumerator better. How about a wiki page on the roles of enumerators and iteratees, best explained using a simple example? At present, I am not totally convinced of Iteratee/Enumerator. Why aren't there any functor instances anywhere? Why do filestreams and lists present distinct interfaces? A stream computation is a stream computation; the effect of pulling an item off the stream and handling it is sequenced in these computations so it seems like a monad transformer is in order. So I am just going to keep trying until I can make that transformer. -- Jason Dusek ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] example editrc
This is making ghci with editline nicer for me. It says to use the vi key mapping, tab for completion, C-l to clear the screen, and jj to go into vi command mode. $ cat ~/.editrc bind -v bind \\t rl_complete bind ^L ed-clear-screen bind jj vi-command-mode ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: [Haskell] ANN: HLint 1.0
Well, sort of. Ok, we can parse that. Let's assume a variable x holds the output of :show modules as a String. We call lines on it, then map words on it, do a !! 2 on it, and we get [Util.hs,, Recorder.hs,, Game.hs,, Monadius.hs,, Demo.hs,]. Chuck in a map (filter (\= ',')), and we get a good list. We can turn the list into a string suitable for hlint with a quick unwords. So our long sought after command becomes ':def hoogle (\_ - return $ :! ++ (unwords $ map (filter (\= ',')) $ (map words $ lines x) !! 2))'. But wait, how do we get 'x'? How do we call :show modules inside a Haskell expression? The first url includes a link to a .ghci mini-tutorial (section 4) that, among other things, implements :redir var cmd -- execute cmd, redirecting stdout to var Perhaps my cold has fogged my head too much, but I'm not sure how :redir would help. I could do :redir var hlint ., but that's as unsatisfactory as :! hlint . You were asking about getting the output of ':show modules' into a variable 'x', so that you can process it further. ':redir x :show modules' should do just that. There is another example command for implementing ':edit' this way (by now a native ghci command). Claus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Parsec question
Benedikt Huber wrote: Using sepBy1, the above parser can be written as dot = T.dot lexer qualifiedIdentifier = sepBy1 identifier dot My next problem is matching things like: identifier ('.' identifier)* ('.' '*')? I've had a look at lookAhead from Text.ParserCombinators.Parsec.Combinator but I can't get it to work. Clues? Erik -- - Erik de Castro Lopo - That being done, all you have to do next is call free() slightly less often than malloc(). You may want to examine the Solaris system libraries for a particularly ambitious implementation of this technique. -- Eric O'Dell (comp.lang.dylan) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Parsec question
On Wed, Dec 24, 2008 at 9:22 AM, Erik de Castro Lopo mle...@mega-nerd.com wrote: My next problem is matching things like: identifier ('.' identifier)* ('.' '*')? I've had a look at lookAhead from Text.ParserCombinators.Parsec.Combinator but I can't get it to work. * is analogous to the 'many' combinator, and ? can be implemented with the 'option' combinator. Parsec is all about composing bigger parsers out of smaller ones using combinators like these. One of the tricks I found early on is to understand where to use 'try' (since by default input is consumed even if a parser fails) but apart from that just read Daan's page, even though it's out of date, and look at how all these cool combinators work. http://legacy.cs.uu.nl/daan/download/parsec/parsec.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Parsec question
Toby Hutton wrote: One of the tricks I found early on is to understand where to use 'try' (since by default input is consumed even if a parser fails) but apart from that just read Daan's page, even though it's out of date, and look at how all these cool combinators work. http://legacy.cs.uu.nl/daan/download/parsec/parsec.html Ah yes, reading that document and using 'try' is a good tip. This is what I cam up with: qualifiedIdentStar :: CharParser st [ String ] qualifiedIdentStar = do try identDotStar | qualifiedIdentifier where identDotStar = do s - sepEndBy1 identifier dot char '*' return (s ++ [ * ]) Cheers, Erik -- - Erik de Castro Lopo - It has been discovered that C++ provides a remarkable facility for concealing the trival details of a program -- such as where its bugs are. -- David Keppel ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Detecting system endianness
Maurício wrote: But why would you want that? I understand the only situation when talking about number of bytes makes sense is when you are using Foreign and Ptr. (...) Because I'm using both Ptr and Foreign? ;) See my recent announcement for bytestring-trie. One of the optimizations I'm working on is to read off a full natural word at a time, (...) I see, you mean the size of a machine word, not of Data.Word. AFAIK, Data.Word.Word is defined to be the same size as Prelude.Int (which it isn't on GHC 6.8.2 on Intel OS X: 32bits vs 31bits) and Int is defined to be at least 31bits but can be more. My interpretation of this is that Int and Word will generally be implemented by the architecture's natural word size in order to optimize performance, much like C's int and unsigned int but with better definition of allowed sizes. This seems to be supported by the existence of definite-sized variants Word8, Word16, Word32... So yeah, I'm meaning the machine word, but I think Word is intended to proxy for that. Maybe I'm wrong, but provided that Word contains (or can be persuaded to contain) a round number of Word8 and that operations on Word are cheaper than the analogous sequence of operations on the Word8 representation, that's good enough for my needs. -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What are side effects in Haskell?
Am 23.12.2008 um 15:16 schrieb Hans van Thiel: Hello All, I just saw somewhere that one of the purposes of monads is to capture side effects. I understand what a side effect is in C, for example. Say you want to switch the contents of two variables. Then you need a third temporary variable to store an intermediate result. If this is global, then it will be changed by the operation. But the two variables have also changed. After all they have different values after the switch. You see, even locally changing a variable is a side-effect. It changes the state of the program. Pure Haskell programs on the other hand have no notion of state, there are no variables which can change their value. Every time you want to manipulate something you're actually generating an new copy. You mustn't think of a haskell program as a series of changes to some state. However when you *do* want state you can simulate it with a monad. The IO Monad is a special case here, since its actions don't change your program, they change the world the program is running in (writing files etc.). getLine etc are functions when you think of them as taking a hidden parameter, the state of the world. So getChar would become getChar :: World - (Char,World) but the world stays hidden inside the IO Monad. Regards, Adrian PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is this related to monomorphism restriction?
Maurício wrote: Hi, Why isn't the last line of this code allowed? f :: (TestClass a) = a - Integer f = const 1 a = (f,f) g = fst a Just to make explicit what other folks have brought up in passing. The real type of @f@ (that is without syntactic sugar) is: f :: forall a. TestClass a = a - Integer Which in turn means that the type for @a@ is: a :: ( (forall a. TestClass a = a - Integer) , (forall a. TestClass a = a - Integer) ) This signature isn't valid Haskell98 since it embeds the quantification and the contexts, but it's easily transformable into valid syntax. == {alpha conversion} a :: ( (forall a. TestClass a = a - Integer) , (forall b. TestClass b = b - Integer) ) == {scope extension, twice} a :: forall a b. ( (TestClass a = a - Integer) , (TestClass b = b - Integer) ) == {context raising, twice} a :: forall a b. (TestClass a, TestClass b) = ( (a - Integer) , (b - Integer) ) == {invisible quantification sugar (optional)} a :: (TestClass a, TestClass b) = ( (a - Integer) , (b - Integer) ) The alpha conversion, necessary before doing scope extension, is the step that might not have been apparent. Because @f@ is polymorphic in its argument, the different instances of @f@ can be polymorphic in different ways. This in turn is what leads to the ambiguity in @g@, monomorphism restriction aside. If you wanted to have @a@ give the same types to both elements of the tuple, then you can use this expression instead: a' = let f' = f in (f',f') The important difference is that we're making the sharing explicit. This in turn means that, while @fst a'@ and @snd a'@ are still polymorphic, they can only be polymorphic in the same way. Hence, a' :: forall a. TestClass a = ( (a - Integer) , (a - Integer) ) This transformation is only looking at the type-variable sharing issue. It still runs afoul of the monomorphism restriction unless you resolve it in the ways others have mentioned. -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] The Applicative Functor Monad
Hello, I want to make a Monad which is almost exactly like the Writer monad, except instead of using mappend to glue Monoids together, it uses * to glue applicative functors together. Here is the code: import Control.Applicative import Data.Monoid -- * Sample Implementation of the Writer Monad data Writer w a = Writer { runWriter :: (w, a) } instance (Monoid w) = Monad (Writer w) where return a = Writer (mempty, a) (=) = bindWriter bindWriter :: (Monoid w) = Writer w a - (a - Writer w b) - Writer w b bindWriter (Writer (w,a)) f = let (Writer (w', b)) = f a in Writer (w `mappend` w', b) -- * Sample Implementation of the Applicative Functor Monad data AF af a = AF { runAF :: (af, a) } bindAF :: (Applicative f) = AF (f (a - b)) x - (x - AF (f a) y) - AF (f b) y bindAF (AF (f, x)) g = let (AF (a, y)) = g x in AF (f * a, y) -- instance (Applicative f) = Monad (AF (f ... As you can see, the similarity is striking. Alas, AF and bindAF do not quite have the right type signatures to be used for an instance of the Monad class. Is there some clever work-around I missing? (Aside from, -fno-implicit-prelude). Thanks! - jeremy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type classes vr.s functions
Brian Hurt wrote: So, style question for people, if I can. I have a certain problem- basically, I have a bunch of functions which need a special function, of type a - Foo say. And a bunch of other functions which can define that function on some type of interest, and then what to call the first batch of functions. I can do this either by defining a type class, something like: class Fooable a where toFoo :: a - Foo or I can simply have all the functions which need a toFoo take an extra agrument. Performance really isn't that important here, so it's really a matter of style- which approach would people prefer in this case? For issues of style, I would say to use type-classes. However, this isn't strictly a question of style. As Luke Palmer mentions there are differences of power between the two. In particular, imagine that you have two different and valid ways to convert the same type into Foo; which do you choose? With the continuation/combinator/argument approach this is a non-issue since you can just pass in the one you need. With type-classes it's tricky since they're the same type, which leads to hacks with newtype wrappers or phantom types. If there is guaranteed to be only one valid transformation from any given type into Foo, then type-classes make your intentions clear and they never run into this issue. If more than one valid transformation could exist for some type, then the extra argument is cleaner. Note that when I say any given type I mean the domain of values along with its semantic connotations. For instance, there's a straightforward way of 'converting' Double into an instance of Num. However, if we semantically interpret the values of Double as if they were in the log-domain, then there is a different way to convert it into Num[1]. But really, these are different types because they have different semantics even if they have the same values. Though much abused, newtype declarations are intended to capture exactly this distinction between values and semantics, and they make it straightforward for the Haskell type-checker to see that they are indeed different types. [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/logfloat -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Detecting system endianness
On Tue, Dec 23, 2008 at 07:44:14PM -0500, wren ng thornton wrote: AFAIK, Data.Word.Word is defined to be the same size as Prelude.Int (which it isn't on GHC 6.8.2 on Intel OS X: 32bits vs 31bits) and Int is defined to be at least 31bits but can be more. My interpretation of this is that Int and Word will generally be implemented by the architecture's natural word size in order to optimize performance, much like C's int and unsigned int but with better definition of allowed sizes. This seems to be supported by the existence of definite-sized variants Word8, Word16, Word32... Of course, natural word size can mean 'natural pointer size' or 'natural int size'. Which are different on many architectures. So, you want to be careful about which you want. So yeah, I'm meaning the machine word, but I think Word is intended to proxy for that. Maybe I'm wrong, but provided that Word contains (or can be persuaded to contain) a round number of Word8 and that operations on Word are cheaper than the analogous sequence of operations on the Word8 representation, that's good enough for my needs. If you want to find out the 'natural' sizes, then look at the 'CInt', 'Ptr', and 'FunPtr' types, which follow the C 'int' 'void *' and 'void (*fn)()' types. So they will conform to the architecture ABI for the underlying spec/operating system. If you just want a type guarenteed to be able to hold a pointer or an integer, use 'IntPtr' or 'WordPtr' which are provided for just that case. John -- John Meacham - ⑆repetae.net⑆john⑈ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] intercalate and (byte)strings
On Tue, Dec 23, 2008 at 04:06:38PM +0100, wman wrote: Thank you, guys, i somehow got the impression that there has to be some meaning to this. It seemed unprobable, but why would anybody write it like that if there weren't some reason to it ? ;-))) My guess is that it was probably to gain compatability between different ByteString versions. In older versions, the lazy byte string was just a newtype around a list of bytestrings so you didn't have 'toChunks'. A hack to get around another hack (CPP). John -- John Meacham - ⑆repetae.net⑆john⑈ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] understanding enumerator/iteratee
Jason Dusek schrieb: Henning Thielemann schlepp...@henning-thielemann.de wrote: Jason Dusek schrieb: I'm taking a stab at composable streams, starting with cursors. I managed to make a derived cursor today -- as I work through this stuff, I hope to understand Iteratee/Enumerator better. How about a wiki page on the roles of enumerators and iteratees, best explained using a simple example? At present, I am not totally convinced of Iteratee/Enumerator. Why aren't there any functor instances anywhere? Why do filestreams and lists present distinct interfaces? A stream computation is a stream computation; the effect of pulling an item off the stream and handling it is sequenced in these computations so it seems like a monad transformer is in order. So I am just going to keep trying until I can make that transformer. I have put essentially Oleg's explanation to the Wiki: http://haskell.org/haskellwiki/Enumerator_and_iteratee ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Comparing on multiple criteria
David Menendez schrieb: On Sun, Dec 21, 2008 at 11:20 AM, Jan-Willem Maessen jmaes...@alum.mit.edu wrote: On Dec 21, 2008, at 8:52 AM, Martijn van Steenbergen wrote: Hello all, Data.Ord has a handy function called comparing, and its documentation shows an example of its use. But what if you want to sort a list of values based on multiple criteria? It turns out there is a neat way to do this: compareTuple = mconcat [comparing fst, comparing snd] The default Monoid instances for Ordering and functions work exactly as required here. (Thanks to vixey in #haskell for the hint to look at monoids!) This is a great example of why it's a bad idea to introduce new functionality with a Monoid instance. Even if you know the instance exists, mappend is so general that it's difficult or impossible to predict what it will do at a given type. There should be an explicit function for combining Ordering values lexicographically, with a note in the documentation saying that it's the basis of the Monoid instance. +1 http://haskell.org/haskellwiki/Slim_instance_declaration ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Defining a containing function on polymorphic list
Andrew Wagner schrieb: The problem here is even slightly deeper than you might realize. For example, what if you have a list of functions. How do you compare two functions to each other to see if they're equal? There is no good way really to do it! So, not only is == not completely polymorphic, but it CAN'T be. There is a nice solution for this, however, and it's very simple: contain :: Eq a - [a] - Bool contain x [] = False contain x (y:ys) = if x == y then True else contain x ys Would HLint jump in here and suggest: contain x (y:ys) = x == y || contain x ys ? Or even replace 'contain' by 'elem' ? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] monad constraint + record update
Brent Yorgey schrieb: On Mon, Dec 22, 2008 at 06:19:07PM +0100, Peter Padawitz wrote: I'd like to define a monad Set for types in the class Eq. But how can the arguments of Set be constrained when Set is defined as an instance of Monad? instance Eq a = Monad Set where ... obviously cannot work. Is there a standard update function for fields in data types, something that OO programmers do with assignments like obj.attr := value ? Peter Note there is already a package on Hackage to do exactly this, rmonad. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/rmonad And also http://hackage.haskell.org/cgi-bin/hackage-scripts/package/data-accessor ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Defining a containing function on polymorphic list
-BEGIN PGP SIGNED MESSAGE- Hash: SHA512 On Tue, Dec 23, 2008 at 10:48 PM, Henning Thielemann wrote: Andrew Wagner schrieb: The problem here is even slightly deeper than you might realize. For example, what if you have a list of functions. How do you compare two functions to each other to see if they're equal? There is no good way really to do it! So, not only is == not completely polymorphic, but it CAN'T be. There is a nice solution for this, however, and it's very simple: contain :: Eq a - [a] - Bool contain x [] = False contain x (y:ys) = if x == y then True else contain x ys Would HLint jump in here and suggest: contain x (y:ys) = x == y || contain x ys ? Or even replace 'contain' by 'elem' ? I just tried it out. hlint makes no suggestions. Incidentally, your syntax is wrong. Should be: contain :: (Eq a) = a - [a] - Bool contain _ [] = False contain x (y:ys) = if x == y then True else contain x ys - -- gwern -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) iEYEAREKAAYFAklRtvAACgkQvpDo5Pfl1oKTLQCgixTp95VA8ccRxuWTpIgXVo2k +XkAniyWDU6f1sSCzdUuJIq4pAcgDS0K =Uhkz -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Time for a new logo?
My design, entitled Origami-lambda-supernova-warp, consists of an H composed of two identical vertically tiled lambdas warping from a supernova. It symbolizes the warp of the Haskell-lambda away from the O of object-orientation (symbolized by the supernova). Created in Inkscape, then adjusted in GIMP. First attempt at graphic design. Already posted two days ago at http://haskell.org/haskellwiki/Haskell_logos/New_logo_ideas. -- Benjamin L. Russell -- 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^ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Can I build and install GHC 6.10.1withoutprevious installed ghc
Hi Duncan, Thanks. IT WORKS ! I install 6.6.1, then compile the 6.10.1. There are some warning message. It seems that it doesn't matter. Best Regards Chunye Wang chunye.w...@nsn.com Ahh, x86-64. Those have always been built on Fedora Core 5. My only suggestion is to try older ones, eg 6.6.1. That version should still be able to built 6.10.1 from source and should still be usable for the RWH book. Duncan -Original Message- From: ext Duncan Coutts [mailto:duncan.cou...@worc.ox.ac.uk] Sent: Monday, December 22, 2008 7:37 PM To: Wang, Chunye (NSN - CN/Beijing) Cc: Haskell-Cafe@haskell.org Subject: RE: [Haskell-cafe] Can I build and install GHC 6.10.1withoutprevious installed ghc On Mon, 2008-12-22 at 17:53 +0800, Wang, Chunye (NSN - CN/Beijing) wrote: Hi Duncan, wget http://haskell.org/ghc/dist/6.8.2/ghc-6.8.2-x86_64-unknown-linux.tar.b z2 tar -jxvf ghc-6.8.2-x86_64-unknown-linux.tar.bz2 Ahh, x86-64. Those have always been built on Fedora Core 5. My only suggestion is to try older ones, eg 6.6.1. That version should still be able to built 6.10.1 from source and should still be usable for the RWH book. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Time for a new logo?
There are a lot of nice designs on the new_logo_ideas page. My favourite by far is Conal's. One thing I noticed - everyone seems to include lower-case lambda in the design, but no-one seems to have replaced the terminal double ell in Haskell with a double lambda. -- Colin Adams Preston Lancashire ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe