[Haskell-cafe] Why does ghci recompile the module compiled in different OS ?
Both linux and freebsd has the same .ghci file. cat ~/.ghci :def hoogle \str - return $ :! hoogle --count=15 \ ++ str ++ \ :cd /media/G/www/qachina/db/doc/money the money.hs has many functions i need to use. On freebsd, i use the following command to compile it: ghc -c -O2 money.hs ls Money.hi Money.hs Money.o When entering ghci, it indeed doesnot recompile the module. ghci ... Ok, modules loaded: Money However, when i use the same module in archlinux, the ghci does recompile the module: ghci ... [1 of 1] Compiling Money( Money.hs, interpreted ) Ok, modules loaded: Money. Any suggestion is appreciated! - e^(π⋅i) + 1 = 0 -- View this message in context: http://old.nabble.com/Why-does-ghci-recompile-the-module-compiled-in-different-OS---tp29619740p29619740.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] After `readFile`, why cannot i `writeFile` ?
hitSSQ :: String - [Int] - IO () hitSSQ no hitNum = do let newNum = unwords $ [no] ++ map (\n - show n) hitNum hitNums - fmap lines $ readFile test.txt writeFile test.txt $ unlines $ hitNums ++ [newNum] *** Exception: test.txt: openFile: resource busy (file is locked) Sincerely! - e^(π⋅i) + 1 = 0 -- View this message in context: http://old.nabble.com/After-%60readFile%60%2C-why-cannot-i-%60writeFile%60tp28793133p28793133.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] After `readFile`, why cannot i `writeFile` ?
Bill Atkins-6 wrote: readFile reads the file lazily so it isn't closed until the entire contents have been consumed. Try System.IO.Strict.readFile, which will read the entire file at once. Yes, and i can use appendFile too. appendFile ssqHitNum.txt $ unwords $ [no] ++ map (\n - show n) hitNum ++ [\n] zaxis z_a...@163.com writes: hitSSQ :: String - [Int] - IO () hitSSQ no hitNum = do let newNum = unwords $ [no] ++ map (\n - show n) hitNum hitNums - fmap lines $ readFile test.txt writeFile test.txt $ unlines $ hitNums ++ [newNum] *** Exception: test.txt: openFile: resource busy (file is locked) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - e^(π⋅i) + 1 = 0 -- View this message in context: http://old.nabble.com/After-%60readFile%60%2C-why-cannot-i-%60writeFile%60tp28793133p28812627.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] How to fix this problem in FreeBSD ?
I have to use openbox instead of xmonad now. As a reward , i can `make config` in any ports using openbox. (xmonad canot) zaxis wrote: /usr/ports/devel/hs-ghc-pathssudo make install clean === hs-ghc-paths-0.1.0.5_1 depends on executable: ghc - found === Configuring for hs-ghc-paths-0.1.0.5_1 [1 of 1] Compiling Main ( Setup.hs, Setup.o ) Setup.hs:18:22: Not in scope: `preMakefile' *** Error code 1 Stop in /usr/ports/devel/hs-ghc-paths. Sincerely! - e^(π⋅i) + 1 = 0 -- View this message in context: http://old.nabble.com/How-to-fix-this-problem-in-FreeBSD---tp28714271p28725835.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] How to fix this problem in FreeBSD ?
/usr/ports/devel/hs-ghc-pathssudo make install clean === hs-ghc-paths-0.1.0.5_1 depends on executable: ghc - found === Configuring for hs-ghc-paths-0.1.0.5_1 [1 of 1] Compiling Main ( Setup.hs, Setup.o ) Setup.hs:18:22: Not in scope: `preMakefile' *** Error code 1 Stop in /usr/ports/devel/hs-ghc-paths. Sincerely! - e^(π⋅i) + 1 = 0 -- View this message in context: http://old.nabble.com/How-to-fix-this-problem-in-FreeBSD---tp28714271p28714271.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] How to fix this problem in FreeBSD ?
ghc --version The Glorious Glasgow Haskell Compilation System, version 6.10.4 cabal --version cabal-install version 0.8.2 using version 1.8.0.2 of the Cabal library cat Makefile # New ports collection makefile for: hs-ghc-paths # Date created:July 09 2009 # Whom:Giuseppe Pilichi aka Jacula Modyun jac...@gmail.com # # $FreeBSD: ports/devel/hs-ghc-paths/Makefile,v 1.3 2010/05/26 11:18:37 jacula Exp $ PORTNAME= ghc-paths PORTVERSION=0.1.0.5 PORTREVISION= 1 CATEGORIES= devel haskell MAINTAINER= hask...@freebsd.org COMMENT=Utility looking for GHC installation directories CABAL_SETUP=Setup.hs .if defined(SLAVE) GHC_CMD=ghc .endif .include ${.CURDIR}/../../lang/ghc/bsd.cabal.mk .include bsd.port.mk Ivan Miljenovic wrote: Which version of GHC, which version of Cabal, and what is the Makefile? zaxis z_a...@163.com writes: /usr/ports/devel/hs-ghc-pathssudo make install clean === hs-ghc-paths-0.1.0.5_1 depends on executable: ghc - found === Configuring for hs-ghc-paths-0.1.0.5_1 [1 of 1] Compiling Main ( Setup.hs, Setup.o ) Setup.hs:18:22: Not in scope: `preMakefile' *** Error code 1 Stop in /usr/ports/devel/hs-ghc-paths. Sincerely! - e^(π⋅i) + 1 = 0 -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - e^(π⋅i) + 1 = 0 -- View this message in context: http://old.nabble.com/How-to-fix-this-problem-in-FreeBSD---tp28714271p28714430.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] Why cannot ghc find a existng module ?
`ghc-pkg list` finds two random packages. After `ghc-pkg unregsiter` the one installed by cabal in ~/.ghc/, all works normally now! %ghc-pkg list|grep -i random random-1.0.0.2 zaxis wrote: I have reinstall ghc, xmonad and xmonad-contrib but it still doesnot work! %ghc-pkg list|grep xmonad xmonad-0.9.1 xmonad-contrib-0.9.1 %cat /usr/lib/ghc-6.12.1/package.conf.d/xmonad-contrib-0.9.1-e073c906e3b29eb062e632e9bb989664.conf|grep LayoutHints XMonad.Layout.LayoutCombinators XMonad.Layout.LayoutHints %ls /usr/lib/ghc-6.12.1/site-local/xmonad-contrib-0.9.1/XMonad/Layout/LayoutHints.hi ../site-local/xmonad-contrib-0.9.1/XMonad/Layout/LayoutHints.hi LayoutHints is indeed there. But ghc still cannot find it ! Thanks for your suggestion. i will try #xmonad and xmond mailinglist later! Ivan Lazar Miljenovic wrote: zaxis z_a...@163.com writes: It seems that it is not a xmonad problem as xmond just call ghc directly. Well, yes, except that it might be something else to do with your config, etc. and as such the xmonad mailing list is probably more relevant. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - e^(π⋅i) + 1 = 0 -- View this message in context: http://old.nabble.com/Why-cannot-ghc-find-a-existng-module---tp28507704p28521179.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] Why cannot ghc find a existng module ?
It seems that it is not a xmonad problem as xmond just call ghc directly. %cd ~/.xmonad %ghc --make xmonad.hs xmonad.hs:20:7: Could not find module `XMonad.Layout.LayoutHints': Use -v to see a list of the files searched for. Ivan Lazar Miljenovic wrote: I suggest you either go on #xmonad and ask the people there, or send an email to the xmonad mailing list with your config attached. On 10 May 2010 15:37, zaxis z_a...@163.com wrote: %rm ~/.xmonad/xmonad.{hi,o} %ls ~/.xmonad history xmonad-i386-linux* xmonad.errors xmonad.hs %xmonad --recompile Error detected while loading xmonad configuration file: /home/sw2wolf/.xmonad/xmonad.hs xmonad.hs:20:7: Could not find module `XMonad.Layout.LayoutHints': Use -v to see a list of the files searched for. Please check the file for errors. Ivan Lazar Miljenovic wrote: (Note that this really should be on the xmonad mailing list, but anyway...). On 10 May 2010 15:09, zaxis z_a...@163.com wrote: There is no any complain by ghc-pkg. %ghc-pkg field xmonad-contrib exposed-modules | grep LayoutHints XMonad.Layout.LayoutCombinators XMonad.Layout.LayoutHints Try rm ~/.xmonad/xmonad.{hi,o} and then xmonad --recompile again. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - e^(π⋅i) + 1 = 0 -- View this message in context: http://old.nabble.com/Why-cannot-ghc-find-a-existng-module---tp28507704p28507878.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 -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - e^(π⋅i) + 1 = 0 -- View this message in context: http://old.nabble.com/Why-cannot-ghc-find-a-existng-module---tp28507704p28508239.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] Why cannot ghc find a existng module ?
I have reinstall ghc, xmonad and xmonad-contrib but it still doesnot work! %ghc-pkg list|grep xmonad xmonad-0.9.1 xmonad-contrib-0.9.1 %cat /usr/lib/ghc-6.12.1/package.conf.d/xmonad-contrib-0.9.1-e073c906e3b29eb062e632e9bb989664.conf|grep LayoutHints XMonad.Layout.LayoutCombinators XMonad.Layout.LayoutHints %ls /usr/lib/ghc-6.12.1/site-local/xmonad-contrib-0.9.1/XMonad/Layout/LayoutHints.hi ../site-local/xmonad-contrib-0.9.1/XMonad/Layout/LayoutHints.hi LayoutHints is indeed there. But ghc still cannot find it ! Thanks for your suggestion. i will try #xmonad and xmond mailinglist later! Ivan Lazar Miljenovic wrote: zaxis z_a...@163.com writes: It seems that it is not a xmonad problem as xmond just call ghc directly. Well, yes, except that it might be something else to do with your config, etc. and as such the xmonad mailing list is probably more relevant. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - e^(π⋅i) + 1 = 0 -- View this message in context: http://old.nabble.com/Why-cannot-ghc-find-a-existng-module---tp28507704p28508920.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] Why cannot ghc find a existng module ?
%pacman -Q|grep xmonad xmonad 0.9.1-4 xmonad-contrib 0.9.1-2 %%xmonad --recompile Error detected while loading xmonad configuration file: /home/sw2wolf/.xmonad/xmonad.hs xmonad.hs:20:7: Could not find module `XMonad.Layout.LayoutHints': Use -v to see a list of the files searched for. %ghc-pkg list|grep xmonad xmonad-0.9.1 xmonad-contrib-0.9.1 %pacman -Ql xmonad-contrib|grep LayoutHints xmonad-contrib /usr/lib/ghc-6.12.1/site-local/xmonad-contrib-0.9.1/XMonad/Layout/LayoutHints.hi Sincerely! - e^(π⋅i) + 1 = 0 -- View this message in context: http://old.nabble.com/Why-cannot-ghc-find-a-existng-module---tp28507704p28507704.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] Why cannot ghc find a existng module ?
There is no any complain by ghc-pkg. %ghc-pkg field xmonad-contrib exposed-modules | grep LayoutHints XMonad.Layout.LayoutCombinators XMonad.Layout.LayoutHints Ivan Lazar Miljenovic wrote: Does ghc-pkg check complain? Is the version of GHC being used the same one that was used to build xmonad-contrib? What does ghc-pkg field xmonad-contrib exposed-modules | grep LayoutHints say? On 10 May 2010 14:59, zaxis z_a...@163.com wrote: %pacman -Q|grep xmonad xmonad 0.9.1-4 xmonad-contrib 0.9.1-2 %%xmonad --recompile Error detected while loading xmonad configuration file: /home/sw2wolf/.xmonad/xmonad.hs xmonad.hs:20:7: Could not find module `XMonad.Layout.LayoutHints': Use -v to see a list of the files searched for. %ghc-pkg list|grep xmonad xmonad-0.9.1 xmonad-contrib-0.9.1 %pacman -Ql xmonad-contrib|grep LayoutHints xmonad-contrib /usr/lib/ghc-6.12.1/site-local/xmonad-contrib-0.9.1/XMonad/Layout/LayoutHints.hi Sincerely! - e^(π⋅i) + 1 = 0 -- View this message in context: http://old.nabble.com/Why-cannot-ghc-find-a-existng-module---tp28507704p28507704.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 -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - e^(π⋅i) + 1 = 0 -- View this message in context: http://old.nabble.com/Why-cannot-ghc-find-a-existng-module---tp28507704p28507747.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] Why cannot ghc find a existng module ?
%rm ~/.xmonad/xmonad.{hi,o} %ls ~/.xmonad history xmonad-i386-linux* xmonad.errors xmonad.hs %xmonad --recompile Error detected while loading xmonad configuration file: /home/sw2wolf/.xmonad/xmonad.hs xmonad.hs:20:7: Could not find module `XMonad.Layout.LayoutHints': Use -v to see a list of the files searched for. Please check the file for errors. Ivan Lazar Miljenovic wrote: (Note that this really should be on the xmonad mailing list, but anyway...). On 10 May 2010 15:09, zaxis z_a...@163.com wrote: There is no any complain by ghc-pkg. %ghc-pkg field xmonad-contrib exposed-modules | grep LayoutHints XMonad.Layout.LayoutCombinators XMonad.Layout.LayoutHints Try rm ~/.xmonad/xmonad.{hi,o} and then xmonad --recompile again. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - e^(π⋅i) + 1 = 0 -- View this message in context: http://old.nabble.com/Why-cannot-ghc-find-a-existng-module---tp28507704p28507878.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] Haskell and scripting
xmonad is my favorite WM. BTW, why canot i receive any email from its mailinglist (i have subscribed from http://www.haskell.org/mailman/listinfo/xmonad)? minh thu wrote: Hi, You can take the xmonad approach: the configuration file is written in Haskell and compiled, so no need for another language. Cheers, Thu 2010/5/3 Martin Erwig er...@eecs.oregonstate.edu: One of my students has worked on scripting approach in Haskell: http://web.engr.oregonstate.edu/~erwig/papers/abstracts.html#SLE09 -- Martin On May 3, 2010, at 9:51 AM, Limestraël wrote: Hello Café, I don't know if you know conky. It's a well-known open-source system monitor (a software that displays information on the desktop, like CPU frequency, disk usage, network rate, etc.). It is quite good, but it's very descriptive, and even if you can call shell commands it's clearly not made for being scripted. What I would do is to make a similar system monitor, which base would be compiled Haskell code, but that would be scriptable with some DSL, or already existing interpreted language. I've thought about a Lisp/Scheme language, since those languages are functional, dynamically typed and simple (so enable a quick scripting) and I'm not very keen on making my own DSL What I would like to know is: 1) If you have other solutions 2) How do haskellers usually script their applications ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - e(π⋅i) + 1 = 0 -- View this message in context: http://old.nabble.com/Haskell-and-scripting-tp28437468p28441722.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] A newbie question ?
newtype TypeMap = TypeMap (Map.Map TypeRep Dynamic) lookup :: Typeable a = TypeMap - Maybe a lookup (TypeMap mp) = res where res = liftM (fromJust . fromDynamic) $ Map.lookup (typeOf $ fromJust res) mp It seems that the `res` in `fromJust res` has not been defined ? Sincerely! - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/A-newbie-question---tp28383563p28383563.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] A newbie question ?
proxy type is indeed much clear! thanks Ryan Ingram wrote: Remember, fromJust res won't be evaluated unless typeOf needs it. But it does get typechecked at compile time, and the type is used to select which instance of typeOf to call. Fortunately, legal instances of Typeable require typeOf to not inspect its argument. This is a somewhat old design; modern variations on this tend to use a proxy type to make it clear that the argument's value cannot be evaluated. In modern Haskell, I would write it like so: data Proxy a = Proxy proxy :: a - Proxy a class Typeable a where typeOf :: Proxy a - TypeRep -- uses ScopedTypeVariables extension lookup :: forall a. Typeable a = TypeMap - Maybe a lookup (TypeMap mp) = liftM (fromJust . fromDynamic) $ Map.lookup (typeOf (Proxy :: Proxy a)) mp -- ryan On Tue, Apr 27, 2010 at 5:17 PM, zaxis z_a...@163.com wrote: newtype TypeMap = TypeMap (Map.Map TypeRep Dynamic) lookup :: Typeable a = TypeMap - Maybe a lookup (TypeMap mp) = res where res = liftM (fromJust . fromDynamic) $ Map.lookup (typeOf $ fromJust res) mp It seems that the `res` in `fromJust res` has not been defined ? Sincerely! - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/A-newbie-question---tp28383563p28383563.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 - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/A-newbie-question---tp28383563p28384431.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] what does the '~' mean ?
instance (BinaryDefer a, BinaryDefer b) = BinaryDefer (a,b) where put (a,b) = put2 a b get = get2 (,) size x = let ~(a,b) = x in size a + size b putFixed (a,b) = putFixed2 a b getFixed = getFixed2 (,) in `size` function, what does the `~` mean ? Sincerely! - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/what-does-the-%27%7E%27-mean---tp28263383p28263383.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] Why is it so different between 6.12.1 and 6.10.4_1 ?
I just start ghci from shell and do nothing else. In fact, i really donot know `Monad ((-) a) ` . Would you mind expplain it ? Yusaku Hashimoto wrote: Did you import the module includes the instance of Monad ((-) e) somewhere in your code loaded in ghci? I tried this on a fresh ghci 6.12, but I got No instance error. -nwn On Sat, Mar 27, 2010 at 9:20 AM, zaxis z_a...@163.com wrote: In 6.12.1 under archlinux let f x y z = x + y + z :t f f :: (Num a) = a - a - a - a :t (=) . f (=) . f :: (Num a) = a - ((a - a) - a - b) - a - b ((=) . f) 1 (\f x - f x) 2 5 In 6.10.4_1 under freebsd let f x y z = x + y + z *Money :t f f :: (Num a) = a - a - a - a :t (=) . f (=) . f :: (Monad ((-) a), Num a) = a - ((a - a) - a - b) - a - b ((=) . f) 1 (\f x - f x) 2 interactive:1:1: No instance for (Monad ((-) a)) arising from a use of `=' at interactive:1:1-5 Possible fix: add an instance declaration for (Monad ((-) a)) In the first argument of `(.)', namely `(=)' In the expression: ((=) . f) 1 (\ f x - f x) 2 In the definition of `it': it = ((=) . f) 1 (\ f x - f x) 2 Sincerely! - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/Why-is-it-so-different-between-6.12.1-and-6.10.4_1---tp28049329p28049329.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 - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/Why-is-it-so-different-between-6.12.1-and-6.10.4_1---tp28049329p28050535.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] Why is it so different between 6.12.1 and 6.10.4_1 ?
Why do you bother with the interior definition of f in there? Because i want to try a C code style not layout style without `do` syntax sugar . Yusaku Hashimoto wrote: fac n = let { f = foldr (*) 1 [1..n] } in f Why do you bother with the interior definition of f in there? fac = product . enumFromTo 1 let fac = do is_zero - (==0); if is_zero then return 1 else liftM2 (*) id (fac . pred) -nwn On Sat, Mar 27, 2010 at 9:59 AM, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: zaxis z_a...@163.com writes: In 6.10.4_1 under freebsd let f x y z = x + y + z *Money :t f f :: (Num a) = a - a - a - a :t (=) . f (=) . f :: (Monad ((-) a), Num a) = a - ((a - a) - a - b) - a - b ((=) . f) 1 (\f x - f x) 2 interactive:1:1: No instance for (Monad ((-) a)) arising from a use of `=' at interactive:1:1-5 Possible fix: add an instance declaration for (Monad ((-) a)) In the first argument of `(.)', namely `(=)' In the expression: ((=) . f) 1 (\ f x - f x) 2 In the definition of `it': it = ((=) . f) 1 (\ f x - f x) 2 Some definitions and exports got changed, so in 6.12 the (- a) Monad instance is exported whereas in 6.10 it isn't. fac n = let { f = foldr (*) 1 [1..n] } in f Why do you bother with the interior definition of f in there? fac = product . enumFromTo 1 -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/Why-is-it-so-different-between-6.12.1-and-6.10.4_1---tp28049329p28050543.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] Why is it so different between 6.12.1 and 6.10.4_1 ?
Of course, you are wrong ! C is VERY important for almost every programmer in the world! Why cannot C programmer use haskell ? And Why does haskell support C code style ? Ivan Miljenovic wrote: zaxis z_a...@163.com writes: Why do you bother with the interior definition of f in there? Because i want to try a C code style not layout style without `do` syntax sugar . Haskell /= C, so stop trying to code as if it is. If you like C so much, then use C. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/Why-is-it-so-different-between-6.12.1-and-6.10.4_1---tp28049329p28051693.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] Why is it so different between 6.12.1 and 6.10.4_1 ?
I just mean syntax. For example. the following code snippet is C-style. In vim, i can use `shift+%` to jump between `{' and `}', and so on. hitSSQ hitNum = do { nums - fmap str_ints_pick $ readFile ssqNum.txt; forM_ nums (\n - do { let { hitB = if (n!!6 == hitNum!!6) then 1 else 0 ; hitR = foldl (\acc x - if(elem x (init hitNum)) then acc+1 else acc) 0 (init n);}; printf %s\t%d:%d\t%s\n (show n) (hitR::Int) (hitB::Int) (hit_desc hitR hitB); }); } Dietrich Epp-2 wrote: I think Miljenovic was asking about this (I removed explicit braces): fac n = let f = foldr (*) 1 [1..n] in f Which is strictly equivalent to: fac n = foldr (*) 1 [1..n] Translated into C, this is kind of like doing this: int add(int x, int y) { int sum = x + y; return sum; } instead of this: int add(int x, int y) { return x + y; } I find it very cumbersome (though not *difficult*) and painful to use a C style of programming with Haskell, so I am not sure what you mean when you ask why Haskell supports C style. Are you talking about mutable state, syntax, or something else? --Dietrich On 2010 March 27, at 4:28, zaxis wrote: Of course, you are wrong ! C is VERY important for almost every programmer in the world! Why cannot C programmer use haskell ? And Why does haskell support C code style ? Ivan Miljenovic wrote: zaxis z_a...@163.com writes: Why do you bother with the interior definition of f in there? Because i want to try a C code style not layout style without `do` syntax sugar . Haskell /= C, so stop trying to code as if it is. If you like C so much, then use C. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/Why-is-it-so-different-between-6.12.1-and-6.10.4_1---tp28049329p28051693.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 - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/Why-is-it-so-different-between-6.12.1-and-6.10.4_1---tp28049329p28056674.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] Why is it so different between 6.12.1 and 6.10.4_1 ?
thanks for your answer! However, i still feel the following code snippets have different code style. 1. C-style winSSQ count noRed noBlue = do { let {yesRed=[1..33] \\ noRed; yesBlue=[1..16] \\ noBlue}; ps - picoSec; setStdGen (mkStdGen $ fromInteger ps); result - pick_ssq_nums count yesRed yesBlue []; forM_ result (\x - print x); writeFile ssqNum.txt $ ints_str result; } 2. layout style picoSec :: IO Integer picoSec = do t - ctPicosec `liftM` (getClockTime = toCalendarTime) return t The layout style makes me think of python. Maciej Piechotka wrote: On Sat, 2010-03-27 at 04:28 -0700, zaxis wrote: Of course, you are wrong ! C is VERY important for almost every programmer in the world! Hmm. We don't deny that C is important. However importance of hammer does not make screwdriver unimportant. While you can say that you can use screwdriver like a hammer (like you can use Haskell to do imperative programming or vice versa) it is usually terribly inefficient and/or inelegant. Why cannot C programmer use haskell ? (S)He can. However (s)he have to redefine him/herself from being C programmer. As real programmer can program in Fortran in any language you can program in any language in Haskell. You just shouldn't (as you shouldn't program in X in Y for nearly any X != Y). And Why does haskell support C code style ? And BTW. Haskell have no 'C' style. You probably refer to do syntax sugar which is: - Not really C-style. It have syntax nowhere like C - Only partially in traditional imperative style as it do distinguish still between pure and unpure computation - It can be use for much more then crude C ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/Why-is-it-so-different-between-6.12.1-and-6.10.4_1---tp28049329p28056698.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] Why is it so different between 6.12.1 and 6.10.4_1 ?
Both 6.10 and 6.12 use same .ghci ! %cat ~/.ghci :cd /media/G/www/qachina/db/doc/money :l Money %cat Money.hs|grep import import System( getArgs ) import System.Random import System.IO import System.Time import Text.Printf (printf) import Text.Regex import Data.List import Data.Time.Calendar import Data.Time.Calendar.WeekDate import Control.Monad Sincerely! Yusaku Hashimoto wrote: Hmm, When a ghci was started, there should be the only loaded module (Prelude.) And in both 6.10 and 6.12, such instance is not defined or exported in its Prelude. So please try `ghci -ignore-dot-ghci`. It invokes ghci without reading ~/.ghci and ./.ghci. And `((-) a)` is known as the Reader Monad, `a` can be regarded as the environment. My typical usage of that is like following: import Control.Monad data Vec = Vec { x :: Int, y :: Int } absolute :: Vec - Double absolute = sqrt . fromIntegral . liftM2 (+) (square . x) (square . y) where square a = a * a The definition of `absolute` above can be rewritten as absolute p = sqrt . fromIntegral $ square (x p) + square (y p) where square a = a * a How `square . x` and `square . y` share the argument? Because `Monad ((-) a)` is defined as instance Monad ((-) a) where return x = \a - x m = f = \a - f (m a) a Note `(=)` propagates `a` into both of its arguments. That's why the functions read same argument. HTH -nwn On Sat, Mar 27, 2010 at 3:31 PM, zaxis z_a...@163.com wrote: I just start ghci from shell and do nothing else. In fact, i really donot know `Monad ((-) a) ` . Would you mind expplain it ? Yusaku Hashimoto wrote: Did you import the module includes the instance of Monad ((-) e) somewhere in your code loaded in ghci? I tried this on a fresh ghci 6.12, but I got No instance error. -nwn On Sat, Mar 27, 2010 at 9:20 AM, zaxis z_a...@163.com wrote: In 6.12.1 under archlinux let f x y z = x + y + z :t f f :: (Num a) = a - a - a - a :t (=) . f (=) . f :: (Num a) = a - ((a - a) - a - b) - a - b ((=) . f) 1 (\f x - f x) 2 5 In 6.10.4_1 under freebsd let f x y z = x + y + z *Money :t f f :: (Num a) = a - a - a - a :t (=) . f (=) . f :: (Monad ((-) a), Num a) = a - ((a - a) - a - b) - a - b ((=) . f) 1 (\f x - f x) 2 interactive:1:1: No instance for (Monad ((-) a)) arising from a use of `=' at interactive:1:1-5 Possible fix: add an instance declaration for (Monad ((-) a)) In the first argument of `(.)', namely `(=)' In the expression: ((=) . f) 1 (\ f x - f x) 2 In the definition of `it': it = ((=) . f) 1 (\ f x - f x) 2 Sincerely! - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/Why-is-it-so-different-between-6.12.1-and-6.10.4_1---tp28049329p28049329.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 - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/Why-is-it-so-different-between-6.12.1-and-6.10.4_1---tp28049329p28050535.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 - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/Why-is-it-so-different-between-6.12.1-and-6.10.4_1---tp28049329p28056706.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] Why is it so different between 6.12.1 and 6.10.4_1 ?
In 6.12.1 under archlinux let f x y z = x + y + z :t f f :: (Num a) = a - a - a - a :t (=) . f (=) . f :: (Num a) = a - ((a - a) - a - b) - a - b ((=) . f) 1 (\f x - f x) 2 5 In 6.10.4_1 under freebsd let f x y z = x + y + z *Money :t f f :: (Num a) = a - a - a - a :t (=) . f (=) . f :: (Monad ((-) a), Num a) = a - ((a - a) - a - b) - a - b ((=) . f) 1 (\f x - f x) 2 interactive:1:1: No instance for (Monad ((-) a)) arising from a use of `=' at interactive:1:1-5 Possible fix: add an instance declaration for (Monad ((-) a)) In the first argument of `(.)', namely `(=)' In the expression: ((=) . f) 1 (\ f x - f x) 2 In the definition of `it': it = ((=) . f) 1 (\ f x - f x) 2 Sincerely! - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/Why-is-it-so-different-between-6.12.1-and-6.10.4_1---tp28049329p28049329.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: Re[Haskell-cafe] mote invocations in Haskell?
Maybe erlang is more suitable for you as rpc is built in function in erlang. Yves Parès wrote: Okay, well, apparently I have to rely on an external HTTP server. This is not very simple, is there another more suitable way to get RPC working in haskell? Yves Parès wrote: Okay, I tried to make the sample here: http://www.haskell.org/haskellwiki/HaXR But I can't get it working... Is there an external XML-RPC server that must be running? Maybe even an external HTTP server? The server launches without complaining about anything, whereas the client tells: simple_client: user error (Error calling examples.add: connect: does not exist (Connection refused)) I know I have to adapt the url the client tries to connect at (in the sample, http://localhost/~bjorn/cgi-bin/simple_server;), but I don't know how. - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/Remote-invocations-in-Haskell--tp28006793p28009901.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: Re: [Haskell-cafe] Why does `flip` cause function type so different ?
yes, i am a haskell-beginners. However, i still feel haskell-cafe is a good place for me to learn haskell ! If the question is too simple for you to answer, then you can just ignore it . I believe somebody else can still supply help even if without you. Ivan Lazar Miljenovic wrote: Heinrich Apfelmus apfel...@quantentunnel.de writes: Ivan Miljenovic wrote: Also, there's a haskell-beginners mailing list. You may wish to post there rather than asking us every question you get whilst learning Haskell. Every question is welcome on haskell-cafe . The goal of haskell-beginners is to encourage answers that are tailored to beginners, i.e. no scary existential multi-parameter category theory type class monads there. :) Well, yes; except that recently zaxis has been asking quite a few of these beginner-level questions to the list, and I figured that haskell-beginners was catering more for the type of questions he had. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/Why-does-%60flip%60-cause-function-type-so-different---tp27950886p27973331.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] Why does `flip` cause function type so different ?
As a beginner, i cannot understand completely what both Maciej Piechotka and Daniel Fischer-4 said. However, i think it will be a big step for me to study haskell once i understand it. thanks ! zaxis wrote: let f x xs = [x:xs,xs] :t f f :: a - [a] - [[a]] :t (=) .f (=) .f :: a - ([[a]] - [a] - b) - [a] - b :t (flip (=) .f) (flip (=) .f) :: a - [[a]] - [[a]] Why is the type of `(=) .f` and `flip (=) .f` so different ? BTW, Would you mind explaining the following result ? let fff x y z = x + y +z ((=) . fff) 2 (\f x - f x) 3 8 Sincerely! - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/Why-does-%60flip%60-cause-function-type-so-different---tp27950886p27973366.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] How to improve its performance ?
%cat Test.hs module Test(mcombs) where import Data.List mcombs = foldr (flip (=) . f) [[]] where f x xs = [x:xs,xs] %ghc -c -O2 Test.hs %ghci :l Test Ok, modules loaded: Test. :set +s length $ mcombs [1..20] 1048576 (0.06 secs, 56099528 bytes) length $ mcombs [1..50] ^CInterrupted. Daniel Fischer-4 wrote: Am Donnerstag 18 März 2010 04:29:53 schrieb zaxis: The time is wasted to run combination even if use `combination (x:xs) = concat [(x:ys), ys] | ys - combination xs] ' instead. in ghci combination [1..20] will wait for a long time ... Hm, really? Prelude :set +s Prelude let combination [] = [[]]; combination (x:xs) = [x:ys | ys - combination xs] ++ combination xs (0.00 secs, 1818304 bytes) Prelude let combs [] = [[]]; combs (x:xs) = concat [[x:ys,ys] | ys - combs xs] (0.00 secs, 2102280 bytes) Prelude length [1 .. 2^20] 1048576 (0.07 secs, 49006024 bytes) Prelude length $ combination [1 .. 20] 1048576 (8.28 secs, 915712452 bytes) Prelude length $ combs [1 .. 20] 1048576 (0.78 secs, 146841964 bytes) That's interpreted, so not optimised. Optimisation narrows the gap, speeds both up significantly, so put combination :: [a] - [[a]] combination [] = [[]] combination (x:xs) = [x:ys | ys - combination xs] ++ combination xs combs :: [a] - [[a]] combs [] = [[]] combs (x:xs) = concat [[x:ys,ys] | ys - combs xs] mcombs :: [a] - [[a]] mcombs = foldr (flip (=) . f) [[]] where f x xs = [x:xs,xs] in a file, compile with -O2 and load into ghci: Prelude Parts length $ combination [1 .. 20] 1048576 (0.16 secs, 43215220 bytes) Prelude Parts length $ combs [1 .. 20] 1048576 (0.05 secs, 55573436 bytes) Prelude Parts length $ mcombs [1 .. 20] 1048576 (0.06 secs, 55572692 bytes) Prelude Parts length $ combination [1 .. 24] 16777216 (3.06 secs, 674742880 bytes) Prelude Parts length $ combs [1 .. 24] 16777216 (0.62 secs, 88170 bytes) Prelude Parts length $ mcombs [1 .. 24] 16777216 (0.62 secs, 881788956 bytes) Prelude Parts length [1 .. 2^24] 16777216 (0.64 secs, 675355184 bytes) So combs and the pointfree combinator version mcombs are equally fast and significantly faster than combination. In fact they're as fast as a simple enumeration. Now, if you actually let ghci print out the result, the printing takes a long time. So much that the difference in efficiency is hardly discernible or not at all. Daniel Fischer-4 wrote: Am Donnerstag 18 März 2010 00:53:28 schrieb zaxis: import Data.List combination :: [a] - [[a]] combination [] = [[]] combination (x:xs) = (map (x:) (combination xs) )++ (combination xs) That would normally be called sublists (or subsets, if one regards lists as representing a set), I think. And, apart from the order in which they are generated, it's the same as Data.List.subsequences (only less efficient). samp = [1..100] allTwoGroup = [(x, samp\\x) | x - combination samp] The above code is used to calculate all the two groups from sample data All partitions into two sublists/sets/samples. ? It is very slow ! I found it surprisingly not-slow (code compiled with -O2, as usual). There are two points where you waste time. First, in combination (x:xs) you calculate (combination xs) twice. If the order in which the sublists come doesn't matter, it's better to do it only once: combination (x:xs) = concat [(x:ys), ys] | ys - combination xs] Second, (\\) is slow, xs \\ ys is O(length xs * length ys). Also, (\\) requires an Eq constraint. If you're willing to constrain the type further, to (Ord a = [a] - [([a],[a])]), and call it only on ordered lists, you can replace (\\) by the much faster difference of oredered lists (implementation left as an exercise for the reader). But you can work with unconstrained types, and faster, if you build the two complementary sublists at the same time. The idea is, -- An empty list has one partition into two complementary sublists: partitions2 [] = [([],[])] -- For a nonempty list (x:xs), the partitions into two complementary -- sublists each have x either in the first sublist or in the second. -- Each partition induces a corresponding partition of the tail, xs, -- by removing x from the group in which it appears. -- Conversely, every partition ox xs gives rise to two partitions -- of (x:xs), by adding x to either the first
[Haskell-cafe] Why does `flip` cause function type so different ?
let f x xs = [x:xs,xs] :t f f :: a - [a] - [[a]] :t (=) .f (=) .f :: a - ([[a]] - [a] - b) - [a] - b :t (flip (=) .f) (flip (=) .f) :: a - [[a]] - [[a]] Why is the type of `(=) .f` and `flip (=) .f` so different ? Sincerely! - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/Why-does-%60flip%60-cause-function-type-so-different---tp27950886p27950886.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] How to improve its performance ?
import Data.List combination :: [a] - [[a]] combination [] = [[]] combination (x:xs) = (map (x:) (combination xs) )++ (combination xs) samp = [1..100] allTwoGroup = [(x, samp\\x) | x - combination samp] The above code is used to calculate all the two groups from sample data ? It is very slow ! Sincerely! - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/How-to-improve-its-performance---tp27940036p27940036.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] How to improve its performance ?
The time is wasted to run combination even if use `combination (x:xs) = concat [(x:ys), ys] | ys - combination xs] ' instead. in ghci combination [1..20] will wait for a long time ... Daniel Fischer-4 wrote: Am Donnerstag 18 März 2010 00:53:28 schrieb zaxis: import Data.List combination :: [a] - [[a]] combination [] = [[]] combination (x:xs) = (map (x:) (combination xs) )++ (combination xs) That would normally be called sublists (or subsets, if one regards lists as representing a set), I think. And, apart from the order in which they are generated, it's the same as Data.List.subsequences (only less efficient). samp = [1..100] allTwoGroup = [(x, samp\\x) | x - combination samp] The above code is used to calculate all the two groups from sample data All partitions into two sublists/sets/samples. ? It is very slow ! I found it surprisingly not-slow (code compiled with -O2, as usual). There are two points where you waste time. First, in combination (x:xs) you calculate (combination xs) twice. If the order in which the sublists come doesn't matter, it's better to do it only once: combination (x:xs) = concat [(x:ys), ys] | ys - combination xs] Second, (\\) is slow, xs \\ ys is O(length xs * length ys). Also, (\\) requires an Eq constraint. If you're willing to constrain the type further, to (Ord a = [a] - [([a],[a])]), and call it only on ordered lists, you can replace (\\) by the much faster difference of oredered lists (implementation left as an exercise for the reader). But you can work with unconstrained types, and faster, if you build the two complementary sublists at the same time. The idea is, -- An empty list has one partition into two complementary sublists: partitions2 [] = [([],[])] -- For a nonempty list (x:xs), the partitions into two complementary -- sublists each have x either in the first sublist or in the second. -- Each partition induces a corresponding partition of the tail, xs, -- by removing x from the group in which it appears. -- Conversely, every partition ox xs gives rise to two partitions -- of (x:xs), by adding x to either the first or the second sublist. So partitions2 (x:xs) = concat [ [(x:ys,zs),(ys,x:zs)] | (ys,zs) - partitions2 xs ] We can also write the second case as partitions2 (x:xs) = concatMap (choice x) (partitions2 xs) where choice x (ys,zs) = [(x:ys,zs),(ys,x:zs)] Now it's very easy to recognise that partitions2 is a fold, partitions2 xs = foldr (concatMap . choice) [([],[])] xs Sincerely! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/How-to-improve-its-performance---tp27940036p27941317.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] How to improve its performance ?
`allPairs list = [(x,y) | x - list, y - list] ` is not what `combination` does ! let allPairs list = [(x,y) | x - list, y - list] allPairs [1,2,3] [(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)] combination [1,2,3] [[1,2,3],[2,3],[1,3],[3],[1,2],[2],[1],[]] Alexander Solla-2 wrote: On Mar 17, 2010, at 6:14 PM, Daniel Fischer wrote: I found it surprisingly not-slow (code compiled with -O2, as usual). There are two points where you waste time. I found one big point where time is wasted: in computing the powerset of a list. He's making 2^n elements, and then iterating through them all and filtering, but only needs n^2 or n `choose` 2 of the (depending on the semantics for his groups). The answer is to do something like: allPairs list = [(x,y) | x - list, y - list] to get it done in n^2 time. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/How-to-improve-its-performance---tp27940036p27941343.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] Are there any web server framework ?
Erlang has yaws (http://yaws.hyber.org/) Scala has lift (http://liftweb.net/) Python has django (http://www.djangoproject.com/) Ruby has rails (http://rubyonrails.org/) How about haskell ? Is there any similar framework, which should be steady, powerful and easy to use, in haskell ? Sincerely! - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/Are-there-any-web-server-framework---tp27926433p27926433.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] If the local variable can be changed ...
In FP the variable can not be changed once created. Yes, it has much advantage . However, i feel it is too strict. As we know, the local variable is allocated on stack which is thread safe. So if the local variable can be changed, then we can use loop, etc. same as imperative languages. For example, for (i=0; i100; i++) where `i` is a local variable in function. Any suggestion is appreciated! - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/If-the-local-variable-can-be-changed-...-tp27844016p27844016.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] If the local variable can be changed ...
Yes, we can imitate all of it (such as `when`, `until` and `for`) because haskell is a good DSL language. However, i feel it will be more convenient if the language itself supports all these fundations. jmillikin wrote: If your code performs a common task (such as conversion, accumulation, testing), then you should use higher-level constructs than a for loop. Using map, filter, foldr, and foldl will make it easier to write correct code. If you'd like to imitate a for loop exactly -- that is, to perform some action multiple times -- it's very easy to create a pure function. We do not have to stoop to mutable variables. - for :: Monad m = a - (a - Bool) - (a - a) - (a - m ()) - m () for start test step body = loop start where loop x = if test x then body x loop (step x) else return () main = for 0 ( 100) (+ 1) $ \i - do -- do something with i print i - On Tue, Mar 9, 2010 at 16:25, zaxis z_a...@163.com wrote: In FP the variable can not be changed once created. Yes, it has much advantage . However, i feel it is too strict. As we know, the local variable is allocated on stack which is thread safe. So if the local variable can be changed, then we can use loop, etc. same as imperative languages. For example, for (i=0; i100; i++) where `i` is a local variable in function. Any suggestion is appreciated! - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/If-the-local-variable-can-be-changed-...-tp27844016p27844016.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 - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/If-the-local-variable-can-be-changed-...-tp27844016p27845844.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] How to understand `|` in this code snippet ?
xxxMain = do timeout - getEnv xxx_TIMEOUT case timeout of Just str | [(t, _)] - reads str - do addTimeout t (hPutStrLn stderr *** TIMEOUT _exit 1) return () _ - return () ... What does the `|` mean in Just str | [(t, _)] - reads str ? Is it a logical `or` ? Sincerely! - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/How-to-understand-%60%7C%60-in-this-code-snippet---tp27726581p27726581.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] How to understand `|` in this code snippet ?
Then can i change it to : case timeout of Just str - do [(t, _)] - reads str addTimeout t (hPutStrLn stderr *** TIMEOUT _exit 1) return () _ - return () Sincerely! Brandon S. Allbery KF8NH wrote: On Feb 27, 2010, at 04:07 , zaxis wrote: xxxMain = do timeout - getEnv xxx_TIMEOUT case timeout of Just str | [(t, _)] - reads str - do addTimeout t (hPutStrLn stderr *** TIMEOUT _exit 1) return () _ - return () ... What does the `|` mean in Just str | [(t, _)] - reads str ? Is it a logical `or` ? It's a guard. Same as with function definitions (in fact, function definitions of that form are converted to case expressions). -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/How-to-understand-%60%7C%60-in-this-code-snippet---tp27726581p27732364.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] How to understand `|` in this code snippet ?
thanks! case timeout of Just str - case reads str of [(t,_)] - addtimeout (hPutStrLn stderr *** TIMEOUT _exit 1) _ - return () _ - return () is VERY clear! Daniel Fischer-4 wrote: Am Sonntag 28 Februar 2010 02:08:18 schrieb zaxis: Then can i change it to : case timeout of Just str - do [(t, _)] - reads str addTimeout t (hPutStrLn stderr *** TIMEOUT _exit 1) return () _ - return () Sincerely! No. The | [(t,_)] - reads str in case timeout of Just str | [(t,_)] - reads str - ... is a pattern guard, not a monadic bind (and where p - reads str is a monadic bind, it's in the list monad). You can change it to case timeout of Just str - case reads str of [(t,_)] - addtimeout (hPutStrLn stderr *** TIMEOUT _exit 1) _ - return () _ - return () but why would you? Brandon S. Allbery KF8NH wrote: On Feb 27, 2010, at 04:07 , zaxis wrote: xxxMain = do timeout - getEnv xxx_TIMEOUT case timeout of Just str | [(t, _)] - reads str - do addTimeout t (hPutStrLn stderr *** TIMEOUT _exit 1) return () _ - return () ... What does the `|` mean in Just str | [(t, _)] - reads str ? Is it a logical `or` ? It's a guard. Same as with function definitions (in fact, function definitions of that form are converted to case expressions). -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - fac n = let { f = foldr (*) 1 [1..n] } in f -- View this message in context: http://old.nabble.com/How-to-understand-%60%7C%60-in-this-code-snippet---tp27726581p27732673.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] About code style ?
thanks for all suggestions. zaxis wrote: For me i like C style instead of layout. For example, func1 a = do -- ... a * 2 -- ... I always write it as: func1 a = do { -- ...; a * 2; -- ...; } However, i donot know how to write pure function using C style. func1 a = { -- ...; a * 2; -- ...; } will not compile without `do`. Sincerely! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/About-code-style---tp27414627p27416932.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] About code style ?
fac n = let { f = foldr (*) 1 [1..n] } in f VERY interesting :) Jinjing Wang wrote: fac n = let { f = foldr (*) 1 [1..n] } in f :D sorry for double reply, need to cc cafe, this is fun. On Tue, Feb 2, 2010 at 4:33 PM, zaxis z_a...@163.com wrote: thanks for all suggestions. zaxis wrote: For me i like C style instead of layout. For example, func1 a = do -- ... a * 2 -- ... I always write it as: func1 a = do { -- ...; a * 2; -- ...; } However, i donot know how to write pure function using C style. func1 a = { -- ...; a * 2; -- ...; } will not compile without `do`. Sincerely! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/About-code-style---tp27414627p27416932.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 -- jinjing ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/About-code-style---tp27414627p27429649.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] About code style ?
For me i like C style instead of layout. For example, func1 a = do -- ... a * 2 -- ... I always write it as: func1 a = do { -- ...; a * 2; -- ...; } However, i donot know how to write pure function using C style. func1 a = { -- ...; a * 2; -- ...; } will not compile without `do`. Sincerely! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/About-code-style---tp27414627p27414627.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] Why cannot i add the `let` declaration ?
thanks! Ivan Lazar Miljenovic wrote: zaxis z_a...@163.com writes: find_the_day sDay 0 = sDay find_the_day sDay nDay = let nextDay = addDays 1 sDay if (is_trade_day $ nextDay) then find_the_day nextDay (nDay - 1) else find_the_day nextDay nDay The correct syntax is let ... in ...; you've forgotten the in, so something like this: , | find_the_day sDay 0 = sDay | find_the_day sDay nDay = | let nextDay = addDays 1 sDay | in if (is_trade_day $ nextDay) |then find_the_day nextDay (nDay - 1) |else find_the_day nextDay nDay ` Note that in do-blocks you don't need the `in'; in normal code you do. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/Why-cannot-i-add-the-%60let%60-declaration---tp27381811p27382334.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] Could not find module `Text.Regex'
`cabal install regex-compat` fixes my problem. thanks! Lee Houghton-3 wrote: On 29/01/2010 03:51, zaxis wrote: import Text.Regex date_by_ntday dateStr ntday = do let [y,m,d] = map (\x - read x::Int) $ splitRegex (mkRegex -) dateStr %ghc --version The Glorious Glasgow Haskell Compilation System, version 6.12.1 Which package(s) do i need to use Text.Regex ? Sincerely! It looks like you want regex-compat: http://hackage.haskell.org/packages/archive/regex-compat/0.92/doc/html/Text-Regex.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/Could-not-find-module-%60Text.Regex%27-tp27366745p27367473.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] Why cannot i add the `let` declaration ?
find_the_day sDay 0 = sDay find_the_day sDay nDay = if (is_trade_day $ nextDay sDay) then find_the_day (nextDay sDay) (nDay - 1) else find_the_day (nextDay sDay) nDay nextDay sDay = addDays 1 sDay The above code works fine. But the following always reports `compiling error`: find_the_day sDay 0 = sDay find_the_day sDay nDay = let nextDay = addDays 1 sDay if (is_trade_day $ nextDay) then find_the_day nextDay (nDay - 1) else find_the_day nextDay nDay Any suggestion is appreciated! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/Why-cannot-i-add-the-%60let%60-declaration---tp27381811p27381811.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] Could not find module `Text.Regex'
import Text.Regex date_by_ntday dateStr ntday = do let [y,m,d] = map (\x - read x::Int) $ splitRegex (mkRegex -) dateStr %ghc --version The Glorious Glasgow Haskell Compilation System, version 6.12.1 Which package(s) do i need to use Text.Regex ? Sincerely! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/Could-not-find-module-%60Text.Regex%27-tp27366745p27366745.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] xmonad cannot find its library after upgrading GHC
After `pacman -Syu`, the ghc is upgraded to 6.12.1 %ghc --version The Glorious Glasgow Haskell Compilation System, version 6.12.1 However, the xmonad still stay as it is: %pacman -Q|grep -i xmonad xmonad 0.9-2.1 xmonad-contrib 0.9-1.2 %pacman -Ql xmonad|more .. xmonad /usr/lib/ghc-6.10.4/ xmonad /usr/lib/ghc-6.10.4/site-local/ xmonad /usr/lib/ghc-6.10.4/site-local/xmonad-0.9/ xmonad /usr/lib/ghc-6.10.4/site-local/xmonad-0.9/HSxmonad-0.9.o xmonad /usr/lib/ghc-6.10.4/site-local/xmonad-0.9/XMonad.hi xmonad /usr/lib/ghc-6.10.4/site-local/xmonad-0.9/XMonad/ . So it will fail when running `xmonad --recompile` as xmonad cannot find its library in /usr/lib/ghc-6.12.1. Do i need to re-install xmonad ? Sincerely! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/xmonad-cannot-find-its-library-after-upgrading-GHC-tp27206013p27206013.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] darcs 2.4 beta 1 release
Both darcs and xmonad are only great product i know! thanks! Reinier Lamers-2 wrote: Hi all, The darcs team would like to announce the immediate availability of darcs 2.4 beta 1. darcs 2.4 will contain many improvements and bugfixes compared to darcs 2.3.1. Highlights are the fast index-based diffing which is now used by all darcs commands, and the interactive hunk-splitting in darcs record. This beta is your chance to test-drive these improvements and make darcs even better. If you have installed the Haskell Platform or cabal-install, you can install this beta release by doing: $ cabal update $ cabal install --reinstall darcs-beta Alternatively, you can download the tarball from http://darcs.net/releases/darcs-2.3.98.1.tar.gz , and build it by hand as explained in the README file. A list of important changes since 2.3.1 is as follows (please let me know if there's something you miss!): * Use fast index-based diffing everywhere (Petr) * Interactive patch splitting (Ganesh) * An 'optimize --upgrade' option to convert to hashed format in-place (Eric) * Hunk matching (Kamil Dworakowski, tat.wright) * Progress reporting is no longer deceptive (Roman Plášil) * A 'remove --recursive' option to remove a directory tree from revision control (Roman Plášil) * A '--remote-darcs' flag for pushing to a host where darcs isn't called darcs * Many miscellaneous Windows improvements (Salvatore, Petr and others) * 'darcs send' now mentions the repository name in the email body (Joachim) * Handle files with boring names in the repository correctly (Petr) * Fix parsing of .authorspellings file (Tomáš Caitt) * Various sane new command-line option names (Florent) * Remove the '--checkpoint' option (Petr) * Use external libraries for all UTF-8 handling (Eric, Reinier) * Use the Haskell zlib package exclusively for compression (Petr) Kind Regards, the darcs release manager, Reinier Lamers ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/darcs-2.4-beta-1-release-tp27033177p27070775.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] How can i set the seed random number generator ?
In erlang, first i use the following function to set the seed: new_seed() - {_,_,X} = erlang:now(), {H,M,S} = time(), H1 = H * X rem 32767, M1 = M * X rem 32767, S1 = S * X rem 32767, put(random_seed, {H1,M1,S1}). then use random:uniform/1 to get the random number. In haskell, i just use the following function to get the random number. It seems i donot need to set the seed of random number generator manually? rollDice :: Int - IO Int rollDice n = randomRIO(1,n) Sincerely! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/How-can-i-set-the-seed-random-number-generator---tp26882798p26882798.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] How to understand such a `case` ?
findHelper (x:xs) = do -- not lazy, but that's not really important here filex - fileExists (file x) filex' - fileExists (file' x) case () of _ | filex - return $ Just $ file x | filex'- return $ Just $ file' x | otherwise - findHelper xs file x = foldl1 joinFileName (x ++ [helper]) file' x = (file x) ++ (getConfig exe_ext) Sincerely! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/How-to-understand-such-a-%60case%60---tp26703526p26703526.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] How to understand such a `case` ?
thanks for your quick answer ! Then what's the advantage using such a `case` not using `if` statement given by you ? For me, the `if` statement is more clear . jmillikin wrote: Sorry; forgot to CC the list That case is equivalent to: if filex then return $ Just $ file x else if filex' then return $ Just $ file' x else findHelper xs The specific syntax being used is called a pattern guard: http://www.haskell.org/haskellwiki/Pattern_guard On Tue, Dec 8, 2009 at 16:59, zaxis z_a...@163.com wrote: findHelper (x:xs) = do -- not lazy, but that's not really important here filex - fileExists (file x) filex' - fileExists (file' x) case () of _ | filex - return $ Just $ file x | filex' - return $ Just $ file' x | otherwise - findHelper xs file x = foldl1 joinFileName (x ++ [helper]) file' x = (file x) ++ (getConfig exe_ext) Sincerely! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/How-to-understand-such-a-%60case%60---tp26703526p26703526.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 - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/How-to-understand-such-a-%60case%60---tp26703526p26703743.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] I really donot know how to use `newtype` ?
import Control.Monad.State import Control.Monad.Reader data XConf = XConf {} data XState = XState {} newtype X a = X (ReaderT XConf (StateT XState IO) a) :t StateT StateT :: (s - m (a, s)) - StateT s m a :t ReaderT ReaderT :: (r - m a) - ReaderT r m a then how to use `X` ? Would you mind explaining the newtype X in detail ? Sinerely! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/I-really-donot-know-how-to-use-%60newtype%60---tp26541671p26541671.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] Where is `newTVarIO` defined ?
I cannot hoogle it. It appears in Pugs: run' (-d:rest) = do info - fmap Just (io $ newTVarIO Map.empty) let ?debugInfo = info run' rest Sincerely! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/Where-is-%60newTVarIO%60-defined---tp26504967p26504967.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] Where is `newTVarIO` defined ?
thanks! Maybe the hoogle shoud add it Ross Mellgren wrote: Control.Concurrent.STM On Nov 24, 2009, at 6:11 PM, zaxis wrote: I cannot hoogle it. It appears in Pugs: run' (-d:rest) = do info - fmap Just (io $ newTVarIO Map.empty) let ?debugInfo = info run' rest Sincerely! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/Where-is-%60newTVarIO%60-defined---tp26504967p26504967.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 - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/Where-is-%60newTVarIO%60-defined---tp26504967p26505553.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] How to understand such a newtype ?
newtype X a = X (ReaderT XConf (StateT XState IO) a) #ifndef __HADDOCK__ deriving (Functor, Monad, MonadIO, MonadState XState, MonadReader XConf, Typeable) #endif In `X (ReaderT XConf (StateT XState IO) a)`, X is a type constructor, how to understand `(ReaderT XConf (StateT XState IO) a)` ? And why use `#ifndef __HADDOCK__` ? Sincerely! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/How-to-understand-such-a-newtype---tp26462332p26462332.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] How to understand such a newtype ?
thanks ! Felipe Lessa wrote: On Sat, Nov 21, 2009 at 06:20:40PM -0800, zaxis wrote: newtype X a = X (ReaderT XConf (StateT XState IO) a) #ifndef __HADDOCK__ deriving (Functor, Monad, MonadIO, MonadState XState, MonadReader XConf, Typeable) #endif In `X (ReaderT XConf (StateT XState IO) a)`, X is a type constructor, how to understand `(ReaderT XConf (StateT XState IO) a)` ? Well, “ReaderT XConf (StateT XState IO) a” is *the* type :). It's a monad that is a Reader of XConf and has a State of XState. This means you can use, for example, ask :: X XConf and get :: X XState And why use `#ifndef __HADDOCK__` ? Because Haddock used to have difficulties in processing some directives, like that “deriving (..., MonadState XState, ...)” which is part of the GeneralizedNewtypeDeriving extension. HTH, -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/How-to-understand-such-a-newtype---tp26462332p26462674.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] About xmonad
I have subscribed to xmonad maillist but i never received any email ! Deniz Dogan-3 wrote: 2009/11/16 zaxis z_a...@163.com: %uname -a Linux myarch 2.6.31-ARCH #1 SMP PREEMPT Tue Nov 10 19:48:17 CET 2009 i686 AMD Athlon(tm) 64 X2 Dual Core Processor 3600+ AuthenticAMD GNU/Linux %xmonad --version xmonad 0.9 In firefox, the `save as` dialog doesnot appear when i want to choose picture to save by right clicking the mouse. %cat ~/.xmonad/xmonad.hs import XMonad import XMonad.Hooks.ManageDocks import XMonad.Hooks.EwmhDesktops import XMonad.Hooks.DynamicLog import XMonad.Hooks.ManageHelpers import XMonad.Util.Run(spawnPipe) import XMonad.Layout.TwoPane import XMonad.Layout.WindowNavigation import qualified XMonad.StackSet as W import qualified Data.Map as M main = do xmonad $ defaultConfig { borderWidth = 1 , focusedBorderColor = #ff , normalBorderColor = #aa , manageHook = manageHook defaultConfig + myManageHook , workspaces = map show [1 .. 10 :: Int] , terminal = roxterm , modMask = mod4Mask , focusFollowsMouse = True , startupHook = myStartupHook , logHook = myLogHook , layoutHook = windowNavigation $ avoidStruts $ (Mirror tall ||| tall ||| Full) --, layoutHook = ewmhDesktopsLayout $ windowNavigation $ avoidStruts $ (Mirror tall ||| tall ||| Full) , keys = \c - myKeys c `M.union` keys defaultConfig c --, mouseBindings = \c - myMouse c `M.union` mouseBindings defaultConfig c } where tall = Tall 1 (3/100) (1/2) myStartupHook :: X () myStartupHook = do { spawn fcitx; spawn roxterm; spawn lxpanel; spawn /home/sw2wolf/bin/kvm.sh; } myLogHook :: X () myLogHook = ewmhDesktopsLogHook myManageHook :: ManageHook myManageHook = composeAll . concat $ [ [ className =? c -- doFloat | c - myCFloats] ,[ resource =? r -- doFloat | r - myRFloats] ,[ title =? t -- doFloat | t - myTFloats] ,[ className =? c -- doIgnore | c - ignores] ,[ className =? Audacious -- doShift 3 ] ,[ className =? Firefox -- doF W.swapDown] ,[(role =? gimp-toolbox || role =? gimp-image-window) -- (ask = doF . W.sink)]] where myCFloats = [Thunderbird-bin, GQview, MPlayer, Gimp,Vncviewer,Xmessage] myRFloats = [Dialog, Download, Places] myTFloats = [Firefox Preferences, Element Properties] ignores = [trayer] role = stringProperty WM_WINDOW_ROLE myKeys (XConfig {modMask = modm}) = M.fromList $ -- Apps and tools [ ((modm, xK_F2), spawn gmrun) , ((modm, xK_f), spawn /home/firefox/firefox) , ((modm, xK_t), spawn thunderbird) --, ((modm, xK_p), spawn exe=`dmenu_path | dmenu -b` eval \exec $exe\) , ((modm, xK_F11), spawn sudo shutdown -r now) , ((modm, xK_F12), spawn sudo shutdown -h now) , ((modm .|. controlMask, xK_Print), spawn sleep 0.2; scrot -s) , ((modm, xK_Print), spawn scrot '/tmp/%Y-%m-%d_%H:%M:%S_$wx$h_scrot.png' -e 'mv $f ~') , ((modm, xK_c), kill) -- Window Navigation , ((modm, xK_Right), sendMessage $ Go R) , ((modm, xK_Left ), sendMessage $ Go L) , ((modm, xK_Up ), sendMessage $ Go U) , ((modm, xK_Down ), sendMessage $ Go D) -- swap... , ((modm .|. controlMask, xK_Right), sendMessage $ Swap R) , ((modm .|. controlMask, xK_Left ), sendMessage $ Swap L) , ((modm .|. controlMask, xK_Up ), sendMessage $ Swap U) , ((modm .|. controlMask, xK_Down ), sendMessage $ Swap D) ] - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/About-xmonad-tp26367498p26367498.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 You should try asking on the xmonad mailing list: http://www.haskell.org/mailman/listinfo/xmonad -- Deniz Dogan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/About-xmonad-tp26367498p26370168.html Sent from the Haskell - Haskell-Cafe
Re: [Haskell-cafe] Why can `env` be assigned value two times ?
thanks for all your answers ! zaxis wrote: defineVar :: Env - (Id, Val) - IOThrowsError Val defineVar envRef (id, val) = do { env - liftIO $ readIORef envRef; env - return $ filter (\(_id, _) - _id/=id) env; -- clear the current scope valRef - liftIO $ newIORef val; liftIO $ writeIORef envRef $ ((id, valRef):env); return val; } In haskell, the variable canot change its value , right? If so, why can the `env` be assigned value twice? Sincerely! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/Why-can-%60env%60-be-assigned-value-two-times---tp26356073p26367496.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] About xmonad
%uname -a Linux myarch 2.6.31-ARCH #1 SMP PREEMPT Tue Nov 10 19:48:17 CET 2009 i686 AMD Athlon(tm) 64 X2 Dual Core Processor 3600+ AuthenticAMD GNU/Linux %xmonad --version xmonad 0.9 In firefox, the `save as` dialog doesnot appear when i want to choose picture to save by right clicking the mouse. %cat ~/.xmonad/xmonad.hs import XMonad import XMonad.Hooks.ManageDocks import XMonad.Hooks.EwmhDesktops import XMonad.Hooks.DynamicLog import XMonad.Hooks.ManageHelpers import XMonad.Util.Run(spawnPipe) import XMonad.Layout.TwoPane import XMonad.Layout.WindowNavigation import qualified XMonad.StackSet as W import qualified Data.Map as M main = do xmonad $ defaultConfig { borderWidth= 1 , focusedBorderColor = #ff , normalBorderColor = #aa , manageHook = manageHook defaultConfig + myManageHook , workspaces = map show [1 .. 10 :: Int] , terminal= roxterm , modMask = mod4Mask , focusFollowsMouse = True , startupHook = myStartupHook , logHook = myLogHook , layoutHook = windowNavigation $ avoidStruts $ (Mirror tall ||| tall ||| Full) --, layoutHook= ewmhDesktopsLayout $ windowNavigation $ avoidStruts $ (Mirror tall ||| tall ||| Full) , keys = \c - myKeys c `M.union` keys defaultConfig c --, mouseBindings = \c - myMouse c `M.union` mouseBindings defaultConfig c } where tall = Tall 1 (3/100) (1/2) myStartupHook :: X () myStartupHook = do { spawn fcitx; spawn roxterm; spawn lxpanel; spawn /home/sw2wolf/bin/kvm.sh; } myLogHook :: X () myLogHook = ewmhDesktopsLogHook myManageHook :: ManageHook myManageHook = composeAll . concat $ [ [ className =? c -- doFloat | c - myCFloats] ,[ resource =? r -- doFloat | r - myRFloats] ,[ title =? t -- doFloat | t - myTFloats] ,[ className =? c -- doIgnore | c - ignores] ,[ className =? Audacious -- doShift 3 ] ,[ className =? Firefox -- doF W.swapDown] ,[(role =? gimp-toolbox || role =? gimp-image-window) -- (ask = doF . W.sink)]] where myCFloats = [Thunderbird-bin, GQview, MPlayer, Gimp,Vncviewer,Xmessage] myRFloats = [Dialog, Download, Places] myTFloats = [Firefox Preferences, Element Properties] ignores = [trayer] role = stringProperty WM_WINDOW_ROLE myKeys (XConfig {modMask = modm}) = M.fromList $ -- Apps and tools [ ((modm, xK_F2), spawn gmrun) , ((modm, xK_f), spawn /home/firefox/firefox) , ((modm, xK_t), spawn thunderbird) --, ((modm, xK_p), spawn exe=`dmenu_path | dmenu -b` eval \exec $exe\) , ((modm, xK_F11), spawn sudo shutdown -r now) , ((modm, xK_F12), spawn sudo shutdown -h now) , ((modm .|. controlMask, xK_Print), spawn sleep 0.2; scrot -s) , ((modm, xK_Print), spawn scrot '/tmp/%Y-%m-%d_%H:%M:%S_$wx$h_scrot.png' -e 'mv $f ~') , ((modm, xK_c), kill) -- Window Navigation , ((modm, xK_Right), sendMessage $ Go R) , ((modm, xK_Left ), sendMessage $ Go L) , ((modm, xK_Up ), sendMessage $ Go U) , ((modm, xK_Down ), sendMessage $ Go D) -- swap... , ((modm .|. controlMask, xK_Right), sendMessage $ Swap R) , ((modm .|. controlMask, xK_Left ), sendMessage $ Swap L) , ((modm .|. controlMask, xK_Up ), sendMessage $ Swap U) , ((modm .|. controlMask, xK_Down ), sendMessage $ Swap D) ] - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/About-xmonad-tp26367498p26367498.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] Why can `env` be assigned value two times ?
defineVar :: Env - (Id, Val) - IOThrowsError Val defineVar envRef (id, val) = do { env - liftIO $ readIORef envRef; env - return $ filter (\(_id, _) - _id/=id) env; -- clear the current scope valRef - liftIO $ newIORef val; liftIO $ writeIORef envRef $ ((id, valRef):env); return val; } In haskell, the variable canot change its value , right? If so, why can the `env` be assigned value twice? Sincerely! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/Why-can-%60env%60-be-assigned-value-two-times---tp26356073p26356073.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] What does the `forall` mean ?
import Text.ParserCombinators.Parsec data PermParser tok st a = Perm (Maybe a) [Branch tok st a] data Branch tok st a = forall b. Branch (PermParser tok st (b - a)) (GenParser tok st b) I have hoogled the `forall` but i cannot find any appropriate answer! thanks! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/What-does-the-%60forall%60-mean---tp26311291p26311291.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] What does the `forall` mean ?
Without `forall`, the ghci will complain: Not in scope: type variable `b' It is clear now. thank you! Dan Piponi-2 wrote: On Wed, Nov 11, 2009 at 4:24 PM, zaxis z_a...@163.com wrote: data Branch tok st a = forall b. Branch (PermParser tok st (b - a)) (GenParser tok st b) I have hoogled the `forall` but i cannot find any appropriate answer! That's an example of an existential type. What that line is saying is that for any type b (ie. for all b) that you could pick, the constructor called 'Branch' can take something of type 'PermParser tok st (b - a)' and something of type 'GenParser tok st b' and make something of type 'Branch tok st a' out of it. The reason it's called an existential type is something like this: once you've constructed your thing of type 'Branch tok st a' you've lost the information about what the type b was. So all you know is that inside your thing is a pair of objects of type 'PermParser tok st (b - a)' and 'GenParser tok st b' but you don't know what b is. All you know is that there exists some type 'b' that it was made of. To use these types with ghc you need to use the compilation flag -XExistentialQuantification. There's more to be found here: http://www.haskell.org/haskellwiki/Existential_type -- Dan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/What-does-the-%60forall%60-mean---tp26311291p26314602.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] ANNOUNCE: xmonad 0.9 is now available!
xmonad is great WM i have ever seen. I have used it for a long time. However, i donot know whether or not it is a *good* combination to use xmonad and lxpanel together insead of dzen . Don Stewart-2 wrote: http://xmonad.org The xmonad dev team is pleased to announce xmonad 0.9! We think this is a great release. The headlines: * Actions.SpawnOn: Windows go to the workspace they were launched on, even if you're no longer viewing that workspace. Especially handy for slow-launching applications like Firefox * Actions.GridSelect: graphically go to, select, do things with windows, workspaces, prompts ... * Many new window layouts: http://is.gd/4BzAI * Many new scriptable actions: http://is.gd/4BzCN * Focus changes across screens with mouse movement, no longer requiring a click, even for empty workspaces. * Improved xmobar/dzen statusbar functions, easier to use, more compositional * New --restart command line flag to restart a running xmonad process. * Supports for multi-module local configuration files * Support for user-defined X event handling * xmonad comes with 180 extensions for enhancing functionality * Over 3000 commits have been made to the project. Extensive change logs: http://haskell.org/haskellwiki/Xmonad/Notable_changes_since_0.8 About: xmonad is a leading tiling window manager, known for its lightness, reliability, extensibility and efficiency. It supports true multiheaded tiling, and rich, rapid customisation. It is also highly portable, running on regular desktops, laptops, netbooks, phones, game consoles, the OLPC, and more. Features: * Very stable, fast, small and simple. * Automatic window tiling and management * First class keyboard support: a mouse is unnecessary * Full support for tiling windows on multi-head displays * Full support for floating, tabbing and decorated windows * Full support for Gnome and KDE utilities * XRandR support to rotate, add or remove monitors * Per-workspace layout algorithms * Per-screens custom status bars * Compositing support * Powerful, stable customisation and reconfiguration * Large extension library * Excellent, extensive documentation * Large, active development team, support and community Get it! Information, screenshots, documentation, tutorials and community resources are available from the xmonad home page: http://xmonad.org The 0.9 release, and its dependencies, are available from hackage.haskell.org: http://hackage.haskell.org/package/xmonad xmonad packages are available in pretty much every package system, including. Debian, Gentoo, Arch, Ubuntu, OpenBSD, NetBSD, FreeBSD, Gobo, NixOS, Source Mage, Slackware and 0.9 packages will appear in coming days (some are already available). On the fly updating to xmonad 0.9 is supported, without losing your session! You can even use cabal-install: $ cabal update $ cabal install xmonad-0.9 $ cabal install xmonad-contrib-0.9 $ xmonad --recompile mod-q Extensions: xmonad comes with a huge library of extensions (now around 15 times the size of xmonad itself), contributed by viewers like you. Extensions allow for all sorts of functionality and enhancements to the window manager, via Haskell in your config file. For more information on using and writing extensions see the webpage. The library of extensions is available from hackage: http://hackage.haskell.org/cgi-bin/xmonad-contrib Full documentation for using and writing your own extensions: http://xmonad.org/documentation.html This release brought to you by the xmonad dev team: Spencer Janssen Don Stewart Adam VogtBrent Yorgey Daniel WagnerDevin Mullins Daniel Schoepe Braden Shepherdson Nicolas PouillardRoman Cheplyaka Gwern BranwenLukas Mai Featuring code contributions from over 80 developers: Aaron DenneyJason Creighton Alec Berryman Alex Tarkovsky Alexandre BuisseAndrea Rossato Austin SeippBas van Dijk Ben VouiBrandon Allbery Chris Mears Christian Thiemann Clemens Fruhwirth Daniel Neri Anders Engstrom Dave Harrison David Glasser David Lazar Dmitry KurochkinDominik Bruhn Dougal Stanton Eric Mertens Ferenc Wagner Jan Vornberger Hans Philipp Annen Ivan Tarasov Ivan VeselovJamie Webb Jeremy Apthorp Malebria Joachim BreitnerJoachim Fasting Joe Thornber
[Haskell-cafe] Hoogle is great but ...
http://www.haskell.org/hoogle/ is VERY great for haskeller. However, i feel hoogle should be improved by providing more examples as : isInfixOf :: Eq a = [a] - [a] - Bool The isInfixOf function takes two lists and returns True iff the first list is contained, wholly and intact, anywhere within the second. Example: isInfixOf Haskell I really like Haskell. - True isInfixOf Ial I really like Haskell. - False The Example code will be helpful for programmer to understand its definition. Sincerely! -- View this message in context: http://www.nabble.com/Hoogle-is-great-but-...-tp26046410p26046410.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] Lazy problem ?
ssqHitNum.txt contains data as below: 6 7 18 24 30 32 9 4 12 20 25 28 29 16 3 5 11 12 31 32 11 2 9 13 15 19 24 3 5 17 21 25 27 32 14 5 9 15 21 26 31 13 12 16 25 26 27 31 05 ... good_ssq_red:: IO [Int] good_ssq_red = withFile ssqHitNum.txt ReadMode (\h - do { samp - fmap str2Ints $ hGetContents h; print samp;--without this line, the result will always [1..16] return $ statis samp; }) statis :: [Int] - [Int] statis samp = take 16 $ map (\(a,b) - a) $ sortBy (\a b- if (snd a = snd b) then LT else GT) $ times4n where times = map (\n - (foldl (\acc x - if x==n then acc+1 else acc) 0 samp)) [1..33] times4n = map (\n - (n,times!!(n-1))) [1..33] Does it mean that the sampe will not be evalued with `print samp` line ? thanks! -- View this message in context: http://www.nabble.com/Lazy-problem---tp26021845p26021845.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] Lazy problem ?
good_ssq_red:: IO [Int] good_ssq_red =do { samp - fmap str2Ints $ readFile ssqHitNum.txt; return $ statis samp; } It works now ! thank you Bulat Ziganshin-2 wrote: Hello zaxis, Friday, October 23, 2009, 11:15:01 AM, you wrote: good_ssq_red = withFile ssqHitNum.txt ReadMode (\h - do { samp - fmap str2Ints $ hGetContents h; print samp;--without this line, the result will always [1..16] return $ statis samp; }) withFile and hGetContents shouldn't be used together. both closes file handle and, here, withFile closes it before hGetContents lazily reads data. it's why you need to force reading with print use readFile instead -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- View this message in context: http://www.nabble.com/Lazy-problem---tp26021845p26022301.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] How can i safely change the value of specified key ?
aaa - newIORef ([]::[(Int,Int)]) writeIORef aaa [(1,1),(2,2),(3,3)] then if i want to change aaa to [(1,1),(2,222),(3,3)] , what's the best way ? re-write aaa is not permitted. Sincerely! -- View this message in context: http://www.nabble.com/How-can-i-safely-change-the-value-of-specified-key---tp26005244p26005244.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] How can i safely change the value of specified key ?
value - readIORef aaa writeIORef aaa (f value) then aaa will *point to* a new value. The original value will be Garbage Collected, right ? BTW, Is [(1,1),(2,2),(3,3)] been regarded as a hash ? If not, what is the best way to change it to [(1,1),(2,),(3,3)] in function `f` ? Bulat Ziganshin-2 wrote: Hello zaxis, Thursday, October 22, 2009, 11:28:14 AM, you wrote: aaa - newIORef ([]::[(Int,Int)]) writeIORef aaa [(1,1),(2,2),(3,3)] then if i want to change aaa to [(1,1),(2,222),(3,3)] , what's the best way ? re-write aaa is not permitted. it's the only way. in Haskell, you have *immutable* values. aaa is a reference to immutable value. you can mutate reference so it will point to another immutable value but you cannot change this value. there are two ways to make aaa==[(1,1),(2,222),(3,3)]. first, you can apply function to whole value: value - readIORef aaa writeIORef aaa (f value) second, you may create list of IORefs, tuple of IORefs and so: a - newIORef (1,1) ... let aaa = [a,b,c] now aaa is a immutable list of mutable IORefs. of course, you can create IORef pointing to list of IORefs too -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- View this message in context: http://www.nabble.com/How-can-i-safely-change-the-value-of-specified-key---tp26005244p26006471.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] How can i safely change the value of specified key ?
f xs = (2,) : filter ((/=2) . fst) xs It works but not general as `f` still needs to change other value according to the KEY. Maybe Data.List will supply what i need. Ketil Malde-5 wrote: zaxis z_a...@163.com writes: value - readIORef aaa writeIORef aaa (f value) then aaa will *point to* a new value. Exactly. That's what IORefs are, references pointing to contents that can be changed in the IO monad. The original value will be Garbage Collected, right ? Yes, unless something else is holding on to it. Is [(1,1),(2,2),(3,3)] been regarded as a hash? It's a list of pairs. You can treat it as an association list using e.g. 'lookup' from Data.List, if that's what you mean. If not, what is the best way to change it to [(1,1),(2,),(3,3)] in function `f` ? Not sure if there's anything in Data.List, but you could do something like: f xs = (2,) : filter ((/=2) . fst) xs -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 -- View this message in context: http://www.nabble.com/How-can-i-safely-change-the-value-of-specified-key---tp26005244p26006947.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] How can i safely change the value of specified key ?
replace k v xs = (k,v) : filter ((/=v) . fst) xs Great ! thanks you very much minh thu wrote: 2009/10/22 zaxis z_a...@163.com: f xs = (2,) : filter ((/=2) . fst) xs It works but not general as `f` still needs to change other value according to the KEY. Maybe Data.List will supply what i need. I don't think Data.List has what you want as-is. The above code is generalized simply: replace k v xs = (k,v) : filter ((/=v) . fst) xs Cheers, Thu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- View this message in context: http://www.nabble.com/How-can-i-safely-change-the-value-of-specified-key---tp26005244p26007076.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] why cannot i get the value of a IORef variable ?
let aaa = unsafePerformIO $ newIORef [] writeIORef aaa [1,2,3] readIORef aaa [(),(),()] sincerely! -- View this message in context: http://www.nabble.com/why-cannot-i-get-the-value-of-a-IORef-variable---tp26004111p26004111.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] why cannot i get the value of a IORef variable ?
Yes, it works now! thank you very much! Kyle Murphy-2 wrote: I assume you're trying this at the GHCi prompt, which is where you're problem is coming from, specifically on the first line. When you do: let aaa = unsafePerformIO $ newIORef [] GHCi takes a wild stab at the type of [] and comes up with the type [()], so now you have a IORef [()] type, which is why when you try to store [1,2,3] in the IORef you get back [(),(),()]. Try this instead and it should work: let aaa = unsafePerformIO $ newIORef ([] :: [Int]) -R. Kyle Murphy -- Curiosity was framed, Ignorance killed the cat. On Thu, Oct 22, 2009 at 01:02, zaxis z_a...@163.com wrote: let aaa = unsafePerformIO $ newIORef [] writeIORef aaa [1,2,3] readIORef aaa [(),(),()] sincerely! -- View this message in context: http://www.nabble.com/why-cannot-i-get-the-value-of-a-IORef-variable---tp26004111p26004111.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://www.nabble.com/why-cannot-i-get-the-value-of-a-IORef-variable---tp26004111p26004260.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] why cannot i get the value of a IORef variable ?
thank you! In fact i really donot understand unsafePerformIO very much ! Thomas DuBuisson wrote: zaxis z_a...@163.com wrote: let aaa = unsafePerformIO $ newIORef [] writeIORef aaa [1,2,3] readIORef aaa [(),(),()] What in Haskells name do you think you're doing? Don't use unsafePerformIO like that! Its unnecessary and a bit concerning, really. Prelude :m Data.IORef Prelude Data.IORef x - newIORef [] :: IO (IORef [Int]) Prelude Data.IORef writeIORef x [1,2,3] Prelude Data.IORef readIORef x [1,2,3] sincerely! -- View this message in context: http://www.nabble.com/why-cannot-i-get-the-value-of-a-IORef-variable---tp26004111p26004111.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://www.nabble.com/why-cannot-i-get-the-value-of-a-IORef-variable---tp26004111p26004340.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] How to use bracket properly ?
thanks for your quick answer. But winSSQ count noRed noBlue = do { let yesRed = [1..33] \\ noRed; let yesBlue = [1..16] \\ noBlue; bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 - pickSSQ count yesRed yesBlue hd1); } will report: parse error on input `let' Daniel Peebles wrote: They're in different Monads. The first one does x - [...], which means that you're operating in the list Monad instance, and bracket operates in the IO Monad. The second one uses let x = [...] which doesn't have any effect on what Monad you're in, so the whole thing can be in IO. Note that when you do x - [1..3]; y - [4..6] you're going to get all 9 pairs of values from x and y, by the way. Hope this helps, Dan On Mon, Oct 19, 2009 at 1:33 AM, zaxis z_a...@163.com wrote: winSSQ count noRed noBlue = do { yesRed - [1..33] \\ noRed; yesBlue - [1..16] \\ noBlue; bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 - pickSSQ count yesRed yesBlue hd1); return () } will report: Couldn't match expected type `IO ()' against inferred type `[()]' In a stmt of a 'do' expression: bracket (openFile ssqNum.txt WriteMode) (hClose) (\ hd1 - pickSSQ count yesRed yesBlue hd1) However, the following works fine: winSSQ count noRed noBlue = do let yesRed = [1..33] \\ noRed let yesBlue = [1..16] \\ noBlue bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 - pickSSQ count yesRed yesBlue hd1) Why ? -- View this message in context: http://www.nabble.com/How-to-use-%22bracket%22-properly---tp25953522p25953522.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://www.nabble.com/How-to-use-%22bracket%22-properly---tp25953522p25953716.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] How to use bracket properly ?
The original code is: winSSQ count noRed noBlue = do let yesRed = [1..33] \\ noRed let yesBlue = [1..16] \\ noBlue bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 - pickSSQ count yesRed yesBlue hd1) It works very well. However, as i am used to C style so i want convert it into winSSQ count noRed noBlue = do { let yesRed = [1..33] \\ noRed; let yesBlue = [1..16] \\ noBlue; bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 - pickSSQ count yesRed yesBlue hd1); } or winSSQ count noRed noBlue = do { yesRed - [1..33] \\ noRed; yesBlue - [1..16] \\ noBlue; bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 - pickSSQ count yesRed yesBlue hd1); } but all fail ! Thomas DuBuisson wrote: thanks for your quick answer. But I think he actually answered your question. I.e. try it with this extra 'do' statement: winSSQ count noRed noBlue = do { do let yesRed = [1..33] \\ noRed; let yesBlue = [1..16] \\ noBlue; bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 - pickSSQ count yesRed yesBlue hd1); } In the future please use complete examples that have all variables and import statements. It helps us help you. Cheers, Thomas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- View this message in context: http://www.nabble.com/How-to-use-%22bracket%22-properly---tp25953522p25953946.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] How to use bracket properly ?
oh! thanks! But why ? Heinrich Apfelmus wrote: zaxis wrote: It works very well. However, as i am used to C style so i want convert it into winSSQ count noRed noBlue = do { let yesRed = [1..33] \\ noRed; let yesBlue = [1..16] \\ noBlue; bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 - pickSSQ count yesRed yesBlue hd1); } You need to put brackets around the declarations in a let as well: winSSQ count noRed noBlue = do { let { yesRed = [1..33] \\ noRed }; let { yesBlue = [1..16] \\ noBlue }; bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 - pickSSQ count yesRed yesBlue hd1); } Regards, apfelmus -- http://apfelmus.nfshost.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- View this message in context: http://www.nabble.com/How-to-use-%22bracket%22-properly---tp25953522p25956932.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] How to use bracket properly ?
winSSQ count noRed noBlue = do { yesRed - [1..33] \\ noRed; yesBlue - [1..16] \\ noBlue; bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 - pickSSQ count yesRed yesBlue hd1); return () } will report: Couldn't match expected type `IO ()' against inferred type `[()]' In a stmt of a 'do' expression: bracket (openFile ssqNum.txt WriteMode) (hClose) (\ hd1 - pickSSQ count yesRed yesBlue hd1) However, the following works fine: winSSQ count noRed noBlue = do let yesRed = [1..33] \\ noRed let yesBlue = [1..16] \\ noBlue bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 - pickSSQ count yesRed yesBlue hd1) Why ? -- View this message in context: http://www.nabble.com/How-to-use-%22bracket%22-properly---tp25953522p25953522.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] There is no Text.Regex module
In Archlinux i can use Text.Regex as below: import Text.Regex let [y,m,d] = map (\x - read x::Int) $ splitRegex (mkRegex -) dateStr However, in Ubuntu 9.10 it doesnot work reporting no Text.Regex module. So i download and install regex-base and regex-posix from Hackage. But it still doesnot work ! $dpkg -l ghc6 名称版本简介 == ghc6 6.10.4-1ubuntu2 GHC - the Glasgow Haskell Compilation system SIncerely! -- View this message in context: http://www.nabble.com/There-is-no-Text.Regex-module-tp25935308p25935308.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] There is no Text.Regex module
Hoogle is great ! thanks! Thomas DuBuisson wrote: Modules come from Haskell packages, most of which can be found on hackage.haskell.org. If you are looking for a module but you don't know which package it comes from then feel free to search using hoogle or hayoo!. Obviously manually checking all the seemingly related packages on hackage is also an option (and still practical for sufficiently narrow categories). Hoogle: http://haskell.org/hoogle/?hoogle=Text.Regex Hayoo!: http://holumbus.fh-wedel.de/hayoo/hayoo.html Thomas On Fri, Oct 16, 2009 at 9:17 PM, zaxis z_a...@163.com wrote: In Archlinux i can use Text.Regex as below: import Text.Regex let [y,m,d] = map (\x - read x::Int) $ splitRegex (mkRegex -) dateStr However, in Ubuntu 9.10 it doesnot work reporting no Text.Regex module. So i download and install regex-base and regex-posix from Hackage. But it still doesnot work ! $dpkg -l ghc6 名称 版本 简介 == ghc6 6.10.4-1ubuntu2 GHC - the Glasgow Haskell Compilation system SIncerely! -- View this message in context: http://www.nabble.com/There-is-no-Text.Regex-module-tp25935308p25935308.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://www.nabble.com/There-is-no-Text.Regex-module-tp25935308p25935393.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] Would you mind explain such a code ?
myFoldl :: (a - b - a) - a - [b] - a myFoldl f z xs = foldr step id xs z where step x g a = g (f a x) I know myFoldl implements foldl using foldr. However i really donot know how it can do it ? Please shed a light one me, thanks! -- View this message in context: http://www.nabble.com/Would-you-mind-explain-such-a-code---tp25377949p25377949.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] Would you mind explain such a code ?
thanks for your quick answer! As I understand foldr (\x g - g . (`f`x)) id xs will return a function such as (`f` 3).(`f` 2).(`f` 1) . You have already made it clear ! However, why does the step function below has three parameters ? I think foldr will call step using two parameters, the 1st is list element and the 2nd is a funtion whose initial value is id). myFoldl f z xs = foldr step id xs z where step x g a = g (f a x) staafmeister wrote: zaxis wrote: myFoldl :: (a - b - a) - a - [b] - a myFoldl f z xs = foldr step id xs z where step x g a = g (f a x) I know myFoldl implements foldl using foldr. However i really donot know how it can do it ? Please shed a light one me, thanks! Hi, Nice example! Well this is indeed an abstract piece of code. But basically foldl f z xs starts with z and keeps applying (`f`x) to it so for example foldl f z [1,2,3] = ((`f`3).(`f`2).(`f`1)) z Because functions are first-class in haskell, we can also perform a foldl where instead of calculating the intermediate values we calculate the total function, i.e. ((`f`3).(`f`2).(`f`1)) and apply it to z. When the list is empty z goes to z, so the start function must be id. So we can write (`f`3).(`f`2).(`f`1) = foldr (\x g - g . (`f`x)) id xs This is almost in your form. Hope this helps, Gerben -- View this message in context: http://www.nabble.com/Would-you-mind-explain-such-a-code---tp25377949p25378882.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] How to preload the module of my own
I want to preload the module automatically when starting ghci. The module located in ~/work directory contains some functions i use everyday. Now i use an alias: alias ghci='ghci -i ~/money/Money.hs' which works fine. However i feel there maybe are more elegant way. thanks! -- View this message in context: http://www.nabble.com/How-to-preload-the-module-of-my-own-tp25304154p25304154.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] How to preload the module of my own
My module is not in any package. Your solution is VERY elegant. thanks! mf-hcafe-15c311f0c wrote: echo ':load ~/money/Money.hs' ~/.ghci works for me. this adds a line to the startup script that loads a file that is not in any package. if this module loads other modules, you may need to play with ':cd' in addition to ':load'. hope this helps, matthias On Fri, Sep 04, 2009 at 06:14:50PM -0700, Alexander Dunlap wrote: To: zaxis z_a...@163.com, Haskell Cafe haskell-cafe@haskell.org Cc: From: Alexander Dunlap alexander.dun...@gmail.com Date: Fri, 4 Sep 2009 18:14:50 -0700 Subject: Re: [Haskell-cafe] How to preload the module of my own On Fri, Sep 4, 2009 at 6:08 PM, zaxisz_a...@163.com wrote: I want to preload the module automatically when starting ghci. The module located in ~/work directory contains some functions i use everyday. Now i use an alias: alias ghci='ghci -i ~/money/Money.hs' which works fine. However i feel there maybe are more elegant way. thanks! If the module is part of a package you can put 'import NameOfModule' in your ~/.ghc/.ghci file. That file contains commands that are run when ghci starts. I'm not sure if you can load a module that isn't installed. Alex ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ** ACCEPT: CRM114 PASS osb unique microgroom Matcher ** CLASSIFY succeeds; success probability: 1. pR: 11.8869 Best match to file #0 (nonspam.css) prob: 1. pR: 11.8869 Total features in input file: 2936 #0 (nonspam.css): features: 758386, hits: 2835097, prob: 1.00e+00, pR: 11.89 #1 (spam.css): features: 1686574, hits: 2959087, prob: 1.30e-12, pR: -11.89 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- View this message in context: http://www.nabble.com/How-to-preload-the-module-of-my-own-tp25304154p25304648.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] How to understand the 'forall' ?
seems a bit understanding, i still need to think it for a while thanks! jkff wrote: 2009/9/2 zaxis z_a...@163.com: Isnot it clear without the 'forall' ? data Branch tok st a = Branch (PermParser tok st (b - a)) (GenParser tok st b) thanks! The situation is not so simple. Consider, for example, a procedure that takes as input a *generic* sorting algorithm: sortThem :: (forall a. Ord a = [a] - [a]) - [Int] - [String] - ([Int], [String]) sortThem sortAlgo ints strings = (sortAlgo ints, sortAlgo strings) Here you can't omit the 'forall' because if you do, then inside the body of the sortThem function the 'a' type variable has a fixed value and can't be both Int and String! This is a somewhat esoteric example, but one could consider, for instance, a procedure that takes as input some trees of different types and a generic tree traversal algorithm. Well, have a look at the haskellwiki page, there's a pile of examples :) P.S. I tried to write up the difference between datatype and function declarations in this respect, but my explanations turned into a mess, so I erased them in the hope that someone will explain it better than me. jkff wrote: This means that for any type 'b' you can construct a value of type 'Branch tok st a' by passing to Branch an argument of type '(PermParser tok st (b - a))' and 'GenParser tok st b'. This also means that when you're given a value of type Branch tok st a, you don't know what that 'b' type was; the only thing you know is that the 'b' in 'b - a' in the first argument of Branch is the same as the 'b' in 'GenParser tok st b'. See also: the haskellwiki page on existential types. 2009/9/2 zaxis z_a...@163.com: data Branch tok st a = forall b. Branch (PermParser tok st (b - a)) (GenParser tok st b) please shed a light on me, thanks! -- View this message in context: http://www.nabble.com/How-to-understand-the-%27forall%27---tp25250783p25250783.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 -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- View this message in context: http://www.nabble.com/How-to-understand-the-%27forall%27---tp25250783p25251783.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 -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- View this message in context: http://www.nabble.com/How-to-understand-the-%27forall%27---tp25250783p25254016.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] How to understand the 'forall' ?
data Branch tok st a = forall b. Branch (PermParser tok st (b - a)) (GenParser tok st b) please shed a light on me, thanks! -- View this message in context: http://www.nabble.com/How-to-understand-the-%27forall%27---tp25250783p25250783.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] How to understand the 'forall' ?
Isnot it clear without the 'forall' ? data Branch tok st a = Branch (PermParser tok st (b - a)) (GenParser tok st b) thanks! jkff wrote: This means that for any type 'b' you can construct a value of type 'Branch tok st a' by passing to Branch an argument of type '(PermParser tok st (b - a))' and 'GenParser tok st b'. This also means that when you're given a value of type Branch tok st a, you don't know what that 'b' type was; the only thing you know is that the 'b' in 'b - a' in the first argument of Branch is the same as the 'b' in 'GenParser tok st b'. See also: the haskellwiki page on existential types. 2009/9/2 zaxis z_a...@163.com: data Branch tok st a = forall b. Branch (PermParser tok st (b - a)) (GenParser tok st b) please shed a light on me, thanks! -- View this message in context: http://www.nabble.com/How-to-understand-the-%27forall%27---tp25250783p25250783.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 -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- View this message in context: http://www.nabble.com/How-to-understand-the-%27forall%27---tp25250783p25251783.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] Data.Time is so weak ?!
toWeekDate meets my need, thank you! Colin Adams-3 wrote: How about: import Data.Time.Calendar import Data.Time.Calendar.WeekDate main = do let (y, w, d) = toWeekDate $ addDays 150 (fromGregorian 2009 8 31) putStrLn $ show d 2009/8/31 zaxis z_a...@163.com: addDays 150 (fromGregorian 2009 8 31) will work. However, how can i get its weekday from the result ? thanks! zaxis wrote: today = fromGregorian 2009 8 31 then how to calculate the day passing 150 days ? today + 150 doesnot work ! -- View this message in context: http://www.nabble.com/Data.Time-is-so-weak--%21-tp25218462p25218554.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 -- Colin Adams Preston, Lancashire, ENGLAND ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- View this message in context: http://www.nabble.com/Data.Time-is-so-weak--%21-tp25218462p25219065.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] How to fix such a TYPE problem ?
let [y,m,d] = map (\x - read x::Int) $ splitRegex (mkRegex -) 2009-08-31 fromGregorian y m d Couldn't match expected type `Integer' against inferred type `Int' In the first argument of `fromGregorian', namely `y' In the expression: fromGregorian y m d In the definition of `it': it = fromGregorian y m d thanks! -- View this message in context: http://www.nabble.com/How-to-fix-such-a-TYPE-problem---tp25233906p25233906.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] How to fix such a TYPE problem ?
thanks! Luke Palmer-2 wrote: On Mon, Aug 31, 2009 at 9:47 PM, zaxisz_a...@163.com wrote: let [y,m,d] = map (\x - read x::Int) $ splitRegex (mkRegex -) 2009-08-31 fromGregorian y m d Couldn't match expected type `Integer' against inferred type `Int' In the first argument of `fromGregorian', namely `y' In the expression: fromGregorian y m d In the definition of `it': it = fromGregorian y m d fromGregorian is expecting an Integer for y, and you gave it an Int. You just need to convert; fromIntegral works fine for this. fromGregorian (fromIntegral y) m d ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- View this message in context: http://www.nabble.com/How-to-fix-such-a-TYPE-problem---tp25233906p25234336.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] Data.Time is so weak ?!
today = fromGregorian 2009 8 31 then how to calculate the day passing 150 days ? today + 150 doesnot work ! -- View this message in context: http://www.nabble.com/Data.Time-is-so-weak--%21-tp25218462p25218462.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] Data.Time is so weak ?!
addDays 150 (fromGregorian 2009 8 31) will work. However, how can i get its weekday from the result ? thanks! zaxis wrote: today = fromGregorian 2009 8 31 then how to calculate the day passing 150 days ? today + 150 doesnot work ! -- View this message in context: http://www.nabble.com/Data.Time-is-so-weak--%21-tp25218462p25218554.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