News aggregator

monads, memoization etc

haskell-cafe - Sat, 08/08/2015 - 2:11am
Hi everyone, I'm new to Haskell and decided to learn a bit about monads and their utility. Actually, what worked nicely for me was: to read first several pages from "Computational lambda-calculus and monads", then do exercises from, and then map these exercises to actual functions in the standard library. Then, I decided to implement memoization to practice a bit with ST, HashTable's and such. Here is what I managed to get: . This code computes Fibonacci numbers while caching the intermediate values in a hash table. I tried to make the code as fast as possible (it runs in under 15 seconds, when computing 1M'th Fibonacci number modulo 999983). It uses the package hashtables. I have several question about all this. First, is there a cheap way to speed this code up? Note that I'm interested in a universal memoization strategy, that is I don't want to use arrays instead of hash tables etc. Second, is this
Categories: Offsite Discussion

Nix ±Cabal [video]

Haskell on Reddit - Sat, 08/08/2015 - 1:00am
Categories: Incoming News

More concise code using phantom types

haskell-cafe - Sat, 08/08/2015 - 12:28am
Hello! Consider the following code: module Units where data Units a = U Double deriving Eq units :: Double -> a -> Units a units value _ = U value data Meters data Yards meters = undefined :: Meters yards = undefined :: Yards instance Show Meters where show _ = "meters" instance Show Yards where show _ = "yards" extractA :: Units a -> a extractA = undefined instance Show a => Show (Units a) where show u< at >(U value) = show value ++ " " ++ show $ extractA u main = (print $ units 5 yards) >> (print $ units 5 meters) Is it possible to use something instead extractA function here? For example, substitute "extractA u” with “undefined :: a”? GHC disallows it, so is there a way to explain that I only need a token with type a? Also, with highlighting on lpaste: With regards, Nikita Kartashov _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion

ANN: happstack-server-tls-cryptonite

haskell-cafe - Sat, 08/08/2015 - 12:12am
Hi, I'd like to announce happstack-server-tls-cryptonite, package adding native TLS support to happstack, utilizing hs-tls and cryptonite packages by Vincent Hanquez. You can now run secure web server without using OpenSSL or other foreign libraries. This package is almost drop-in replacement for happstack-server-tls, just change Happstack.Server.SimpleHTTPS to Happstack.Server.SimpleTLS in imports. Regards, Andrey
Categories: Offsite Discussion

Writing fast Vector code.

Haskell on Reddit - Fri, 08/07/2015 - 7:20pm

dI seem to have a curse that whenever I rewrite code using lists to programs using vectors, the program runs in significantly less memory but is much slower (sample size of 3). Also my intuitions about refactoring code don't actually make code faster. For example, I also rewrote a function using a 2-d (V.Vector (U.Vector Float)) to use a 1-d (U.Vector Float) and suddenly things got really slow despite smaller cleaner code and I'm baffled.

So my question is are there any good references for writing good Vector code? I seem to suck at it.

EDIT: The code by popular demand. The original code using lists can be found here. The rewritten vector function in question is in this gist:

colorPixel1 is the first version of the function. colorPixel2 is the second version. Hopefully I have included enough explanation. I apologize in advance for the code.

EDIT2: Some of you have also asked about profiling information. Here is the profiling info on the original list implementation and vector implementation

and I didn't profile the second version because it was taking too long to run > 20 minutes. Interesting that many basicUnsafeIndex are happening because I use safeIndex (!) in the code. grep "unsafe" src/ -r returns nothing.

GC time for all versions have been ~1%.

EDIT3: After looking through the vector source code, I believe a big reason for the slowdown is I expected vector (a,b) to be represented as a and b unpacked next to each other in one vector. However it looks like from

data instance MVector s (a, b) = MV_2 {-# UNPACK #-} !Int !(MVector s a) !(MVector s b)

that it is instead represented as vector a and vector b. In retrospect this is probably why there is a O(1) bound on zip. This would absolutely destroy cache performance because I used vectors of tuples a fair bit, and whenever I access the first element I always access the second.

I guess the solution to this would be to wrap my tuples in a newtype and make it an instance of Unbox with

newtype Point = Point (Float,Float) derivingUnbox "Point" [t| Point -> (Float,Float) |] [| \(Point (x,y)) -> (x,y) |] [| \(x,y) -> Point (x,y) |]

but I'm not sure how to use derivingUnbox with anything other than (,).

btw if there is an easier way to make things an instance of Unbox I'd love to hear it because derivingUnbox really slows down compile times.

FINAL EDIT (probably): I found a stack overflow question which addresses my need by showing how to write vector instances for my datatypes to store the items sequentially :)

submitted by jura__
[link] [17 comments]
Categories: Incoming News

Serialize to Haskell

haskell-cafe - Fri, 08/07/2015 - 6:55pm
Hello! I'm wondering if it's possible to serialize some data to a format that is valid Haskell. In practice I would read a file like this: module Foo where myData :: MyData myData = MyData {name = "foo", descr = "test" ... } Reading this into a program is easily feasible with Hint, for example. Then the program would modify some data and serialize it back to: module Foo where myData :: MyData myData = MyData {name = "bar", descr = "test2" ... } In practice I think that the format should be a subset of Haskell that is not Turing-complete. A bit like JSON, which is a subset of Javascript but not Turing complete. Is it possible? Thanks, Corentin _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion

"cabal sdist" oddity

haskell-cafe - Fri, 08/07/2015 - 5:31pm
Cabal from HEAD started to issue the warning "Warning: Cannot run preprocessors. Run 'configure' command first." when running "cabal sdist" after a "cabal install", see e.g. Previous versions didn't do this, see e.g. Somehow the warning doesn't make sense, because the package has obviously been built before, so configuration must have happened, too. Is this a new bug in Cabal? Cheers, S. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion

Can't get function that should compile without issues to compile

Haskell on Reddit - Fri, 08/07/2015 - 4:29pm

I'm trying to compile the baby.hs function from LYAH but for some reason it's just not working.

When I use ghci and do :l baby.hs it gives me the output of

[1 of 1] Compiling Main ( baby.hs, interpreted ) baby.hs:1:16: Not in scope: ‘+’ Failed, modules loaded: none.

Anyone know what's up? Also earlier when I tried adding in type defs like Int, it didn't work.

Weirdly enough I can do addition just fine in the ghci (w/o trying to load in a function)

submitted by ThrowawayTartan
[link] [29 comments]
Categories: Incoming News

FGL: The cost and propoer way of changing the labelat a node.

haskell-cafe - Thu, 08/06/2015 - 11:29pm
Is changing the label at a node O(N)? The only way I can think of to do it is with a map, like the following -- which works, but seems like its speed must be linear in the number of nodes of the graph: 'b', adjOut); _ -> c} mkGraph [(1,'a')] [(1,1,())] mkGraph [(1,'b')] [(1,1,())] Is that in fact the right way? Am I somehow missing the point of FGL if I have to do a lot of that? _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion

Library for package preprocessing

haskell-cafe - Thu, 08/06/2015 - 9:33pm
Hi all, I'm writing a tool to analyze source code of a package, which uses haskell-src-extra. As copied from hackage, libraries may contain some extra stuff (for example, cpp directives). What is the modern way to preprocess the package (configuring for the environment, running the cpp ecc) to obtain code which is guaranteed to be parsed by haskell-src-extra? Ideally I'd like to leave most of the logic for this part outside of the package. Could you point me towards some libraries doing a similar thing? Best regards
Categories: Offsite Discussion

simultaneous ghc versions

glasgow-user - Fri, 07/31/2015 - 7:10pm
The recent release of ghc 7.10.2 reminded me of something I meant to ask about a long time ago. Most of the binaries ghc installs are versioned (x linked to x-7.10.2), with some exceptions (hpc and hsc2hs). Shouldn't they all be versioned? Also, 'haddock' is inconsistent with all the rest, in that it's haddock linked to haddock-ghc-7.10.2. I've long used a few shell scripts (recently upgraded to python) to manage ghc installs. A 'set' which creates symlinks to make a particular version current, and an 'rm' to remove all traces of a version. But due to the inconsistency, I have to remember to run "fix" first, which moves the unversioned binaries to versioned names. As an aside, I have three scripts I use all the time: set version, remove version, and remove library. Come to think of it, shouldn't ghc include this, instead of everyone creating their own shell scripts by hand?
Categories: Offsite Discussion

broken source link

glasgow-user - Fri, 07/24/2015 - 8:59am
Hi, when trying to look up the original definition for Data.List.transpose in I found that the source link does not work. Could this be fixed? Or should I look elsewhere for the sources? Cheers Christian P.S. my looking up transpose was inspired by
Categories: Offsite Discussion

New gtk2hs 0.12.4 release

gtk2hs - Wed, 11/21/2012 - 12:56pm

Thanks to John Lato and Duncan Coutts for the latest bugfix release! The latest packages should be buildable on GHC 7.6, and the cairo package should behave a bit nicer in ghci on Windows. Thanks to all!


Categories: Incoming News