Disclaimer: this is crossposted on StackOverflow.
I've been using the Haskell plugins package to compile strings into functions/values which can be used in Haskell at runtime. However, I've got a problem: when I try to load different values with the same name, it only gives the first value.
Here's my test file:import System.Plugins import System.IO.Temp import System.Directory deleteIfExists :: String -> IO () deleteIfExists filePath = do exists <- doesFileExist filePath if exists then (removeFile filePath) else (return ()) compileInt :: String -> IO Int compileInt codeMinusModule = do withTempDirectory "./.tmp" "__compileTemp" $ \path -> do let filePath = (path ++ "/GetInt.hs" ) let code = "module GetInt where\n" ++ codeMinusModule deleteIfExists filePath writeFile filePath code status <- makeAll filePath  objectPath <- case status of MakeSuccess _ opath -> return opath MakeFailure elist -> error $ "Couldn't make object:\n" ++ (concat elist) strat <- loadInt objectPath path deleteIfExists path return strat where loadInt objectPath folderPath = do loadStatus <- load objectPath [folderPath]  "myInt" case loadStatus of LoadFailure msg -> error $ "Failed to compile " ++ ( concat msg ) LoadSuccess _ strat -> return strat
And my ghci run:*Main> compileInt "myInt = 4" Loading package array-0.4.0.1 ... linking ... done. ... 4 *Main> compileInt "myInt = 3" 4
Even when I give it a different value, it keeps the old one. I delete my temp directories and everything.
Is this an inherent limitation of the plugins package, or am I doing something wrong?submitted by jmite
[link] [2 comments]
EDIT: SEE UPDATED CODE IN NEXT POST
Brand new to programming. I'm learning Haskell. I have this problem that involves writing a program that simulates a game of Go Fish.
Here is the problem I'm stuck on: http://imgur.com/AiHPE6h
I'm trying to define the function using list generation, and it isn't quite working.turn :: Int -> State -> State turn n (,,) = (,,) turn n ( ((Cd suitp1 m):xs), ( (Cd suitp2 p):ys), ) = ( ((Cd suitp1 m):xs), ( (Cd suitp2 p):ys), ) --empty deck, nothing changes turn n ( ((Cd suitp1 m):xs) , ( (Cd suitp2 p):ys) , ( (Cd s r ):rs ) ) | haveAny n ((Cd suitp1 m):xs) == True --player didn't cheat; their hand contains cards of rank n = ( [ Cd suitp1 m | Cd suitp1 m <- ((Cd suitp2 p):ys), n==p ] , [ Cd suitp2 p | Cd suitp2 p <- ((Cd suitp2 p):ys), p/=n ] , [ Cd s r | s <- [Clubs .. Spades], r <-[1..13], s/=suitp1 && s/=suitp2 && r/=m && r/=p ] )
Any help/tips/guidance would be greatly appreciated. If list generation is the wrong way to go about this, what would be a better way? Keep in mind that this is for an Intro Class, so I'm still a beginner.
Thank you in advance.submitted by Johnny_Numbers
[link] [17 comments]
Today, GHC 7.8.1 RC2 has been released.
We've closed approximately 45 issues people filed against RC1. Thanks to everyone who has helped out!
There are actually quite a few nice improvements since then, and some stuff we'd like to announce.iOS cross compiler binaries
This release features iOS cross compiler binaries, courtesy of Luke Iannini. You can download either ghc-188.8.131.5240228-arm-apple-ios or ghc-184.108.40.20640228-i386-apple-ios for the iOS ARM compiler or iOS Simulator, respectively.
To properly use the binary distribution, be sure to carefully read the README! Hopefully this process can be made less tedious in the future.LZMA support for binary distributions
In my experience, lots of people use the binary distributions of GHC for their provided platform (to set up test environments, or because the version for their OS is out of date), and a smaller download for users always helps.
We're now offering LZMA (.tar.xz) compressed binary distributions. On average, these are half the size of their bzip2 counterparts – in some cases even more. The iOS ARM build, for example, is 125M for LZMA vs 267M for bzip2 – a ratio of greater than 50%.
One question now is: with these savings, should we keep supporting .tar.bzip2 distributions? GHC bindists are rather large – xz offers a lot of savings, and is available for every major platform, although it's not typically standard like bzip. But perhaps it's not too much of a burden. Please let us know what you think!
(In the future, this will also save considerable space with nightly build infrastructure as well!)New PPC64 machine
GHC HQ now has a shiny, modern 64-bit POWER7 machine available, courtesy of Gustavo Luiz Duarte. Gustavo is a Fedora PPC64 maintainer, and approached me earlier this year and said he could give us access to a build machine. And now we've got a really nice one! And 7.8.1 works well on it, including dynamic GHCi and shared libraries.
This box is running Fedora 20, has 8 hardware threads split across two cores (one per socket) in a NUMA configuration, and a nice amount of RAM.
Many thanks to Gustavo for letting us use this – and also to OSUOSL, who is hosting it in their data center for us! Hopefully we'll be able to keep supporting this platform (we get a surprising amount of PPC/PPC64 related tickets!)i386/amd64 Ubuntu PPA
This PPA repository now contains 7.8.1 RC2 binaries, available for download for both i386 and amd64 on Ubuntu 12.04 Precise. You should immediately be able to take advantage of these builds in your .travis.yml to test your packages. Furthermore, the binaries are separated from other versions and can coexist with existing packages.
To get started, add the PPA and install the 7.8.1 build:$ sudo add-apt-repository -y ppa:hvr/ghc $ sudo apt-get update $ sudo apt-get install ghc-7.8.1 $ export PATH=/opt/ghc/7.8.1/bin:$PATH $ ghc --version The Glorious Glasgow Haskell Compilation System, version 220.127.116.1140228
This PPA is also integrated into Herbert's multi-ghc-travis project that I mentioned earlier. Just follow the instructions in the README.md, and be sure to enable:GHCVER=7.8.1
inside your .travis.yml. You'll then automatically get build reports with RC2, and any future updates we push to the PPA (including the final version of 7.8.1).
For example, lens now builds with GHC 7.8.1!
Hopefully we can provide builds for all supported Ubuntu configurations in the future – not just Precise.deb.haskell.org for your Debian needs
Currently there aren't 7.8.1 builds yet I'm afraid – but there will be a final version of 7.8.1 available upon release. In the mean time, feel free to use these repositories to test out the latest GHC if you're daring, and report issues to us!
And this leads me to...Rackspace support
Earlier this year, I contacted Rackspace about one of their developer programs. Rackspace is a huge supporter of open source and has some great initiatives to help open source projects. I asked if they could help GHC – we wanted build machines.
Rackspace was extremely kind, and with the help of Jesse Noller, they've provided GHC with a few thousand USD per month in services! This was extremely nice of them, and really blew me away.
Rackspace is what powers http://deb.haskell.org – and not only that. GHC HQ now has machines available solely for testing/build purposes, including many new Windows and Linux instances.
In addition to that, we're using them for haskell.org too – including a FreeBSD backup server (to be revamped soon), and the creation of our new Nagios monitoring infrastructure at monitor.haskell.org.
Right now, we've still got budget available to run more services. This venture is a bit of a joint one between GHC HQ and the current haskell.org administrators, as we're using it for both of our needs at the moment.What's next
We're hoping RC2 will be the final RC, and 7.8.1 proper will follow soon. In the mean time, please download the RC and file bugs if anything goes wrong!