[Haskell-cafe] SOE code on Mac OS X Lion
I am trying to use code from the book `The Haskell School of Expression' on an iMac with Mac OS X Lion. I have installed the latest version of Haskell Platform (2011.4.0.0 64bit). I then followed step 1 on the Web page http://www.cs.yale.edu/homes/hudak/SOE/software1.htm, and did `cabal install GLFW'. There were no errors in the installation. Regarding step 2 in the instructions, I have downloaded SOE-20120121.zip, but don't know how to proceed further. The Web page says, Note for OS X users: running graphics applications from GHCi is no longer supported. Instead, one has to compile a graphics program using GHC in order to run it (see example/GMIExamples.lhs for an example). Also, SOE/src/Code.html says, For MacOS X, unfortunately SOE cannot be run from under GHCi interactively due to problems with the Graphics library it uses. SOE programs must be compiled in order to run OS X. This means you have to export the main function from a particular module (by adding it to the module export list) and compile with command line: ghc -main-is= I am only trying to learn Haskell from SOE, and don't understand how to compile the SOE software with GHC. What precisely is the command that I should invoke in the Terminal for the compilation? I'd appreciate any help on compiling and using the SOE code. Thanks and regards, Raghavendra. -- N. Raghavendra ra...@mri.ernet.in | http://www.retrotexts.net/ Harish-Chandra Research Institute | http://www.mri.ernet.in/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Suggestions for improvement
At 2010-10-03T13:49:34-07:00, Gregory Crosswhite wrote: It is worth noting that such a function already exists in the standard libraries; it is the operator in Control.Arrow: blowup = uncurry (++) . (blowup . allButLast lastToTheLength) Thanks for that. More reading material! Regards, Raghavendra. -- N. Raghavendra ra...@mri.ernet.in | http://www.retrotexts.net/ Harish-Chandra Research Institute | http://www.mri.ernet.in/ See message headers for contact and OpenPGP information. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Suggestions for improvement
At 2010-10-04T01:52:05+04:00, Victor Nazarov wrote: I suggest to pay more attention to haskell's standard library. allButLast is called init in Data.List module. Thanks for that. I should keep printouts of the Prelude handy. Second, do not use explicit recursion. You can capture recursion using some high-order function like map, filter, foldr and so on: lastToTheLength xs = map f xs where f = const . last $ xs And last, your type signatures are too restrictive. You can apply your functions to arbitrary lists. lastToTheLength :: [a] - [a] Standard library knowledge is very helpful in producing short and clear definitions. blowup = concat . zipWith replicate [1..] That looks neat! Many thanks for the detailed remarks. Regards, Raghavendra. -- N. Raghavendra ra...@mri.ernet.in | http://www.retrotexts.net/ Harish-Chandra Research Institute | http://www.mri.ernet.in/ See message headers for contact and OpenPGP information. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Suggestions for improvement
At 2010-10-03T20:03:22-04:00, wren ng thornton wrote: And just to play a little Haskell golf: lastToTheLength = ap (flip map) (const . last) Thanks for that. Regards, Raghavendra. -- N. Raghavendra ra...@mri.ernet.in | http://www.retrotexts.net/ Harish-Chandra Research Institute | http://www.mri.ernet.in/ See message headers for contact and OpenPGP information. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Suggestions for improvement
At 2010-10-05T09:21:51+13:00, Richard O'Keefe wrote: answer s = concat $ zipWith replicate [1..] s I looked at the examples and said, hmm, elements are being repeated varying numbers of times. Looked up repeat, found that that was the wrong function, and saw replicate, which is the right one: replicate n x = [x . x] with n copies of x So zipWith [1..] abcd is [a, bb, ccc, ] and pasting those together is just what concat does. Had replicate, zipWith, concat not already been provided, I might have done one of two things. Many thanks for the detailed explanation. It is instructive because I thought of a solution in a different way. Another lesson is that I must know the Prelude well. I've also installed `pointfree'. Together with Hlint, it seems a useful tool for learning; for one thing, both of them tell me about functions I didn't know earlier. Regards, Raghavendra. -- N. Raghavendra ra...@mri.ernet.in | http://www.retrotexts.net/ Harish-Chandra Research Institute | http://www.mri.ernet.in/ See message headers for contact and OpenPGP information. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Suggestions for improvement
At 2010-10-03T22:45:30+02:00, Dominique Devriese wrote: You need a function like the following for that: comma :: (a - b) - (a - c) - a - (b,c) comma f g x = (f x, g x) Then you could say: blowup = (uncurry (++)) . comma (blowup . allButLast) lastToTheLength Ignore this if you haven't read about Applicative or type classes yet, but using the Applicative instance for arrow types (-) a, you can also write comma = liftA2 (,) or blowup = (uncurry (++)) . liftA2 (,) (blowup . allButLast) lastToTheLength I tried both of them, but they don't seem to work: -- Pointfree blowup. blowup1 :: String - String blowup1 = (uncurry (++)) . comma1 (blowup1 . allButLast) lastToTheLength comma1 :: (a - b) - (a - c) - a - (b,c) comma1 f g x = (f x, g x) blowup2 :: String - String blowup2 = (uncurry (++)) . comma2 (blowup2 . allButLast) lastToTheLength -- Imported Control.Applicative earlier. comma2 :: (a - b) - (a - c) - a - (b,c) comma2 = liftA2 (,) % ghci GHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading package ffi-1.0 ... linking ... done. Prelude :l Chapter01.hs [1 of 1] Compiling Chapter01( Chapter01.hs, interpreted ) Ok, modules loaded: Chapter01. *Chapter01 comma1 allButLast lastToTheLength abcd (abc,) *Chapter01 comma2 allButLast lastToTheLength abcd (abc,) *Chapter01 blowup1 abcd ^CInterrupted. *Chapter01 blowup2 abcd ^CInterrupted. It looks like both the above versions of blowup go into some infinite recursion, and have to be interrupted. Regards, Raghavendra. -- N. Raghavendra ra...@mri.ernet.in | http://www.retrotexts.net/ Harish-Chandra Research Institute | http://www.mri.ernet.in/ See message headers for contact and OpenPGP information. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Suggestions for improvement
I am reading the book `The Haskell Road to Math, Logic, One of the exercises in the first chapter asks for a function that maps a string abcd to abbccc and bang! to baannn!. Since such a function f fixes the empty word, and maps wa to f(w)a^(length(w)+1) for any word w and any letter a, I came up with the following solution: -- Map abcd to abbccc and bang! to baannn!. blowup :: String - String blowup [] = [] blowup x = blowup (allButLast x) ++ lastToTheLength x -- Map abcd to abc. allButLast :: String - String allButLast [] = [] allButLast [x] = [] allButLast (x : xs) = x : allButLast xs -- Map abcd to d^4 = . lastToTheLength :: String - String lastToTheLength [] = [] lastToTheLength [x] = [x] lastToTheLength (_ : xs) = lastToTheLength xs ++ [last xs] One question I have is whether I can eliminate points in the above definition of blowup, and write something like blowup = (++) . (blowup . allButLast, lastToTheLength) thinking of (++) as a function String x String - String. Also, I can't figure out whether it is possible to get a shorter solution using fold. I have tried Hlint on my file, but it gave no suggestions. I am sure there are better ways, and would like some pointers and any general suggestions for improvement. Thanks and regards, Raghavendra. -- N. Raghavendra ra...@mri.ernet.in | http://www.retrotexts.net/ Harish-Chandra Research Institute | http://www.mri.ernet.in/ See message headers for contact and OpenPGP information. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Suggestions for improvement
At 2010-10-03T22:45:30+02:00, Dominique Devriese wrote: Additionally, you can't combine the functions (blowup . allButLast) and lastToTheLength into a function that returns a pair like you seem to attempt. You need a function like the following for that: comma :: (a - b) - (a - c) - a - (b,c) comma f g x = (f x, g x) Then you could say: blowup = (uncurry (++)) . comma (blowup . allButLast) lastToTheLength Thanks, I'll try that. Ignore this if you haven't read about Applicative or type classes yet, but using the Applicative instance for arrow types (-) a, you can also write comma = liftA2 (,) I hadn't come up to that point, but will read about it now. Regards, Raghavendra. -- N. Raghavendra ra...@mri.ernet.in | http://www.retrotexts.net/ Harish-Chandra Research Institute | http://www.mri.ernet.in/ See message headers for contact and OpenPGP information. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Cabal-install prefix
I am new to Haskell, and am trying to install a package (scan) using cabal-install. I want it to install all files under the directory ${HOME}/nonvc, like in ~/nonvc/share and ~/nonvc/bin. So I specified install-dirs user -- prefix: /home/raghu/nonvc in ~/.cabal/config. But when I do `cabal install scan', it still installs the files in ~/.cabal/bin and ~/.cabal/share. How do I make cabal install these files in ~/nonvc? Thanks and regards, Raghavendra. -- N. Raghavendra ra...@mri.ernet.in | http://www.retrotexts.net/ Harish-Chandra Research Institute | http://www.mri.ernet.in/ See message headers for contact and OpenPGP information. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Cabal-install prefix
At 2010-09-22T16:11:34+10:00, Ivan Lazar Miljenovic wrote: So remove the -- from the front of the line to get it working. Thanks very much. That works. I'd read the header in the config file which said that lines beginning with `--' were comments, but somehow missed uncommenting the line I wanted. Regards, Raghavendra. -- N. Raghavendra ra...@mri.ernet.in | http://www.retrotexts.net/ Harish-Chandra Research Institute | http://www.mri.ernet.in/ See message headers for contact and OpenPGP information. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe