Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. How to structure your Haskell installation? (frode k) 2. Re: small expression evaluator (Henk-Jan van Tuyl) 3. Re: How to structure your Haskell installation? (Daniel Fischer) 4. Re: Recursion in monad (Chadda? Fouch?) ---------------------------------------------------------------------- Message: 1 Date: Tue, 22 Mar 2011 13:31:44 +0100 From: frode k <mailingl...@klevstul.com> Subject: [Haskell-beginners] How to structure your Haskell installation? To: beginners@haskell.org Message-ID: <aanlktinfrp0t7zmmueegah4recf704+3civb3axk_...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Hi. I'm installing the Haskell Platform om my Linux box and need some tips on how to structure the files on the OS. I need to install and use both GHC 6.12.3 and GHC 7.0.2. Hence I want to separate these installations. I've setup two directories, one for each platform (related to the GHC): # ls -d -1 $PWD/*.* /usr/haskell/2010.2.0.0 /usr/haskell/2011.2.0.0 I've installed GHC-6.12.3 in "2010.2.0.0" and will install GHC-7.0.2 in "2011.2.0.0". My question is more related to where I should install the packages. When I install a package using "runhaskell Setup ..." I assumed this to ONLY be installed for the version of GHC I'm using when installing it. Am I right about this? Having $PATH pointing to GHC-6.12.3 I've done this when installing packages, to add them to "2010.2.0.0": - - - - - - - cd /usr/src wget http://hackage.haskell.org/packages/archive/transformers/0.2.2.0/transformers-0.2.2.0.tar.gz tar xzf transformers-0.2.2.0.tar.gz cd transformers-0.2.2.0 runhaskell Setup configure --prefix=/usr/haskell/2010.2.0.0/ runhaskell Setup build runhaskell Setup install - - - - - - - Later when I switch to GHC-7.0.2 I plan to install the packages into the "2011.2.0.0" directory in stead. Is this a good way to structure several Haskell installations on the same system? Is there a "best practice" on how to structure the files? I want to get this right from the start, to avoid having to go back and re-arrange everything. Regards, Frode K [k] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110322/54edc960/attachment-0001.htm> ------------------------------ Message: 2 Date: Tue, 22 Mar 2011 13:43:51 +0100 From: "Henk-Jan van Tuyl" <hjgt...@chello.nl> Subject: Re: [Haskell-beginners] small expression evaluator To: "Haskell Beginners List" <beginners@haskell.org>, "Petr Novotnik" <pnovot...@googlemail.com> Message-ID: <op.vsqwbd1lpz0...@zen5.arnhem.chello.nl> Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes On Tue, 22 Mar 2011 10:14:57 +0100, Henk-Jan van Tuyl <hjgt...@chello.nl> wrote: > On Tue, 22 Mar 2011 08:56:45 +0100, Petr Novotnik > <pnovot...@googlemail.com> wrote: > >> data Person = Person { >> personName :: String >> , personAge :: Int >> } >> deriving (Show) >> >> exampleExpr :: Bool >> exampleExpr = (VConst 99) .==. (VFunc personAge) $ Person "pete" 99 >> >> >> I was wondering, whether it'd be possible to enable defining expression >> without the Value data constructors, i.e. >> >> >> 99 .==. personAge $ Person "pete" 99 > > You can write: > 99 == personAge (Person "pete" 99) > Or you could write: c .==. f = \x -> c == f x test = 99 .==. personAge $ Person "pete" 99 The .==. operator is not symmetrical in this case, of course Regards, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html -- ------------------------------ Message: 3 Date: Tue, 22 Mar 2011 14:05:57 +0100 From: Daniel Fischer <daniel.is.fisc...@googlemail.com> Subject: Re: [Haskell-beginners] How to structure your Haskell installation? To: beginners@haskell.org Message-ID: <201103221405.58024.daniel.is.fisc...@googlemail.com> Content-Type: Text/Plain; charset="utf-8" On Tuesday 22 March 2011 13:31:44, frode k wrote: > Hi. > > I'm installing the Haskell Platform om my Linux box and need some tips > on how to structure the files on the OS. I need to install and use both > GHC 6.12.3 and GHC 7.0.2. Hence I want to separate these installations. > I've setup two directories, one for each platform (related to the GHC): > > # ls -d -1 $PWD/*.* > /usr/haskell/2010.2.0.0 > /usr/haskell/2011.2.0.0 > > I've installed GHC-6.12.3 in "2010.2.0.0" and will install GHC-7.0.2 in > "2011.2.0.0". > > My question is more related to where I should install the packages. When > I install a package using "runhaskell Setup ..." I assumed this to ONLY > be installed for the version of GHC I'm using when installing it. Am I > right about this? Yes. A package can only be installed for the compiler it was compiled with, so to install it for multiple compilers you have to compile it repeatedly. > > Having $PATH pointing to GHC-6.12.3 I've done this when installing > packages, to add them to "2010.2.0.0": > - - - - - - - > cd /usr/src > wget > http://hackage.haskell.org/packages/archive/transformers/0.2.2.0/transfo > rmers-0.2.2.0.tar.gz tar xzf transformers-0.2.2.0.tar.gz > cd transformers-0.2.2.0 > runhaskell Setup configure --prefix=/usr/haskell/2010.2.0.0/ > runhaskell Setup build > runhaskell Setup install > - - - - - - - Install cabal-install, then $ cabal install --with-compiler=/path/to/desired/ghc wanted-package takes care of it automatically (after tweaking the settings in cabal's config file). And it gets necessary Haskell dependencies automatically and installs them, too. > > Later when I switch to GHC-7.0.2 I plan to install the packages into the > "2011.2.0.0" directory in stead. > > Is this a good way to structure several Haskell installations on the > same system? Is there a "best practice" on how to structure the files? Don't know. I have everything under $HOME and let GHC and cabal figure out how to organise packages. Works for me?. > I want to get this right from the start, to avoid having to go back and > re-arrange everything. > > Regards, > Frode K > > [k] ------------------------------ Message: 4 Date: Tue, 22 Mar 2011 21:44:20 +0100 From: Chadda? Fouch? <chaddai.fou...@gmail.com> Subject: Re: [Haskell-beginners] Recursion in monad To: Adrian May <adrian.alexander....@gmail.com> Cc: beginners@haskell.org Message-ID: <AANLkTi=uk9Z2Ky=gd+h_lzj6c8t2idgm+ep_kmbrj...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Tue, Mar 22, 2011 at 5:46 AM, Adrian May <adrian.alexander....@gmail.com> wrote: > OK I did this: > > import System.Random > > walk :: Int -> IO Int > walk i = randomRIO (0,1) >>= \r -> return (i+r*2-1) > > say :: Int -> IO () > say i = putStrLn $ show i > > rep :: Int -> a -> (a -> IO a) -> (a -> IO ()) -> IO () > rep n i w s > ????? | n<=0 = return () > ????? | otherwise = s i >> w i >>= \ii -> rep (n-1) ii w s > > main :: IO () > main = rep 10 50 walk say > > Is that the easiest way? I don't know about "easiest", it's not bad though there are thing that can be improved > say i = putStrLn $ show i This already exist and is called "print" (though its type is more general than your signature). > walk i = randomRIO (0,1) >>= \r -> return (i+r*2-1) The >>= ... return is pretty ugly, it would rather be written as : > walk i = fmap (\r -> i + r * 2 - 1) $ randomRIO (0,1) > rep n i w s Passing say and walk as parameter seems a bit overkill, I seriously doubt that you'll ever need this exact structure again, and even then passing a single action should be enough : > rep n act i > | n <= 0 = return () > | otherwise = act i >>= \x -> rep (n-1) act x rep may also be written with standard monad operations : > rep n act i = foldM (\x _ -> act x) i $ replicate (n-1) () Lastly it may be that the structure of the program itself, particularly the use of randomRIO is suboptimal and a bit ugly, for a throwaway program I would probably just use randomRs : > main = do > g <- newStdGen > mapM_ print . tail . scanl (\i r -> i+r*2-1) 50 . take 10 $ randomRs (0,1) g but for a more complex endeavour I would rather use a serious library like mwc-random. (System.Random performances are awful) -- Jeda? ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 33, Issue 31 *****************************************