News aggregator

A leak free and tail recursive foldl'

Haskell on Reddit - Thu, 05/08/2014 - 4:28pm
foldl' f z0 xs0 = lgo z0 xs0 where lgo z [] = z lgo z (x:xs) = lgo z' $ seq z' xs where z' = f z x

Are there any reasons why it shouldn't be this?
Note: the original implementation

submitted by mmirman
[link] [25 comments]
Categories: Incoming News

Ghc Compiling Trouble

Haskell on Reddit - Thu, 05/08/2014 - 4:23pm

I'm using ubuntu and emacs to go through LYAHFGG, and no problems, until I got up to the part where you have to compile your programs. $ ghc --make/<filename> $ ./<filename>

Doesn't work, terminal is telling me that it doesn't recognize <$>, or <ghc>, or <.>, or </> and I can't run any of my programs. I've tried to continue, but I can never test out any of my code. Help! I really like the Glascow Haskell Compiler and I need to know how to at least compile my darn programs. Thanks.

submitted by lazilyEVALUATED
[link] [8 comments]
Categories: Incoming News

Compile Time TDD Coverage

Haskell on Reddit - Thu, 05/08/2014 - 4:12pm
Categories: Incoming News

Roman Cheplyaka: Avoid equational function definitions

Planet Haskell - Thu, 05/08/2014 - 3:00pm

One of the first things that Haskell beginners usually notice is that Haskell has this somewhat unusual but attractive way of defining functions case-by-case:

foldr f z [] = z foldr f z (x:xs) = f x (foldr f z xs)

It looks fun and math-y. The other way to do pattern matching, case expressions, is much less advertized, probably because case invokes associations with dirty old imperative programming. Here’s how the same function could be defined using case:

foldr f z l = case l of [] -> z x:xs -> f x (foldr f z xs)

However, there are plenty of reasons to prefer case to multiple function definition clauses.

(If some of these look insignificant at first sight, think of a datatype with tens of constructors, which is quite common when working with abstract syntax trees.)

  1. DRY. Notice how in the equational style the function name and argument names get repeated.

  2. It makes it clear what the function decides upon. The equational style allows you to pattern match on different arguments in different clauses, or even on multiple arguments in the same clause:

    f [] 0 = 0 f _ 1 = 1 f _ _ = 2

    It gives more power, but also makes it harder to see what’s going on. More importantly, even when this additional power is not used, it’s not obvious from the code itself until you eye-scan all the clauses.

  3. It makes code easier to modify or refactor. Tasks like

    • adding or removing a function argument
    • introducing a local definition common for multiple cases
    • preprocessing function arguments or post-processing the function result

    are trivial with the case expression, and hard to impossible (without rewriting or introducing other top-level functions) with clauses.

  4. When profiling, you often want to add an {-# SCC #-} pragma for a function. If the function is written using multiple cases, you need to attach this pragma to every clause separately. Moreover, even if you do so, they won’t account for the evaluation of arguments due to pattern matching in left-hand sides of the equations.

  5. Once you start reading the Core or STG code, writing functions using case makes it much easier to follow the connection between the original source and its intermediate representation.

Perhaps the only reason to have multiple clauses is if you need that additional power of matching on several arguments at the same time, e.g.

Right a <*> Right b = Right (a b) Left a <*> Right _ = Left a Right _ <*> Left b = Left b Left a <*> Left b = Left (a <> b)

You could do this with case by matching on tuples, but it isn’t as nice.

Other than this, I rarely ever define functions in the equational style in my code.

Categories: Offsite Blogs

reactive-banana GLFW-b event register example

haskell-cafe - Thu, 05/08/2014 - 1:08pm
Hello List, I am trying to make the following quasi-code example work: registerMouseButton :: IO (Event MouseButton) registerMouseButton = do(addHandler, fire) <- newAddHandler setMouseButtonCallback $ \button _ -> fire button fromAddHandler addHandler According to http://stackoverflow.com/questions/8631816/reactive-banana-how-to-create-an-addhandlerit looks like it should be something straightforward. Can somebody show an example of a functional code that registers a key or a mouse event? Thanks, Vladimir _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

Benefits of coroutine?

Haskell on Reddit - Thu, 05/08/2014 - 8:51am

I found a link(http://www.haskellforall.com/2014/03/introductions-to-advanced-haskell-topics.html) from haskelllforall.com earlier and am trying to go through the materials in it. I am now reading the corontine article(http://themonadreader.files.wordpress.com/2011/10/issue19.pdf).

I think the article did a good job explaining what corontine is and how it works. However, i don't think i see the full benefits of coroutine from the article.

I know one usage is that you can stream a list of coroutines together as a data process flow. Because you don't need to hold a lot data in memory this way, data is consumed and send to next 'data processor' immediately, low memory footprint is definitely a benefit. Also, because you don't have to put 'data processor's in different threads, so less context switch will happen. The coroutines just cooperate with each other without any locks/mutexes/etc. That can be another benefit.

But don't we lose some parallelism as a result? If we allow more memory usage, and put processors in different threads. Processor 1 can accumulate some data then pass to processor 2, and while processor 2 is at it, processor 1 can continue to process. In fact, this is how java blocking queue is usually used.

Or maybe coroutines can be used to do this, it's just the pipe functions in the article are just simple implementation to help people understand the concept? If this is true, how are those implemented in a real world?

Also, coroutine seems to be useful in many other cases, can someone list those as well?

I know this is a lot questions..but i really want to understand coroutines, they on their own are very interesting already.

submitted by icetortoise
[link] [5 comments]
Categories: Incoming News

Haskell Game Lib Preferences? (SDL/SFML)

Haskell on Reddit - Thu, 05/08/2014 - 7:57am

I'm just starting out learning Haskell, and as I'm primarily a game developer, I figure the best way is to make some games. The most promising bindings appear to be for SDL and SFML.

Is there any consensus as to which of these (or another alternative) is the nicest to use? I don't have any experience with SDL or SFML.

submitted by detorid
[link] [13 comments]
Categories: Incoming News

Haskell Weekly News: Issue 294

haskell-cafe - Thu, 05/08/2014 - 4:26am
Welcome to issue 294 of the HWN, an issue covering crowd-sourced bits of information about Haskell from around the web. This issue covers from April 27 to May 3, 2014 Quotes of the Week * roconnor: oh no. edwardk and I can never meet otherwise it will be revealed that I am actually him in a very short costume. * edwardk: I'm a product mostly of old Wadler monad papers and TaPL with some Cale thrown in. * benzrf: zippers are fun / they are zippy! / anyway bye Top Reddit Stories * Nikki and the Robots (FOSS Haskell game) has been greenlit on Steam Domain: steamcommunity.com, Score: 130, Comments: 7 Original: [1] http://goo.gl/VgbYzB On Reddit: [2] http://goo.gl/rsKKLn * So I re-implemented Freenet in Haskell, what now? Domain: self.haskell, Score: 85, Comments: 34 Original: [3] http://goo.gl/yLHLD4 On Reddit: [4] http://goo.gl/yLHLD4 * Meditations on learning Haskell from an ex-Clojure user Domain: bitemyapp.com, Score: 79, Comments: 113
Categories: Offsite Discussion

Is there a tool to check if "cabal frozen" dependencies are outdated

Haskell on Reddit - Thu, 05/08/2014 - 2:07am

cabal-install includes a freeze command these days, which is very helpful to get reproducible builds, especially for executables. See the announcement of cabal 1.20 for more details.

Now, my question: Is there a tool which can tell if/when there are newer versions of cabal frozen dependencies?

I guess one way to achieve this is rebuilding the application in a clean sandbox with no cabal.config and calling cabal freeze again.

However that requires recompiling the universe unnecessarily. I assume packdeps can be extended to support this functionality or cabal-install can itself provide this information.

submitted by ozgurakgun
[link] [4 comments]
Categories: Incoming News

Programming programs that program programs to simplify programming.

Haskell on Reddit - Wed, 05/07/2014 - 9:49pm

Hello, I've been recently interested in programs that can program programs for you. That is, you give it a map of input/output pairs and it gives you the source code of a program that is valid for that map. If we had something like that that worked for arbitrary programs, programming would become so much ridiculously easier that the whole field would change. In order to investigate, I made a small program that finds the definition of the (λx -> x+tan(x*x)) function from 20 input/output pairs. I was actually surprised by how fast it could find the result, but, obviously, anything much more complex than that results in a combinatory explosion.

But thinking about it, most of the functions we write in Haskell are really small. Even complex stuff that take hours to get right, such as an interpreter for the lambda calculus, could be written in as few as 3 lines. So this makes me suspect that kind of thing, with some added heuristics (genetic programming?) could actually be useful to practical jobs. So this makes me wonder, why I never heard of it? Has anyone ever tried to use and incorporate this kind of thing in their daily Haskell work? How successful (or not) was it?

submitted by SrPeixinho
[link] [8 comments]
Categories: Incoming News

OCL 2014: First Call for Papers

General haskell list - Wed, 05/07/2014 - 9:37pm
(Apologies for duplicates) CALL FOR PAPERS 14th International Workshop on OCL and Textual Modeling Applications and Case Studies (OCL 2014) Co-located with ACM/IEEE 17th International Conference on Model Driven Engineering Languages and Systems (MODELS 2014) September 28-30 (tbc), 2014, VALENCIA, SPAIN http://www.software.imdea.org/OCL2014/ Modeling started out with UML and its precursors as a graphical notation. Such visual representations enable direct intuitive capturing of reality, but some of their features are difficult to formalize and lack the level of precision required to create complete and unambiguous specifications. Limitations of the graphical notations encouraged the development of text-based modeling languages that either integrate with or replace graphical notations for modeling. Typical examples of such languages are OCL, textual MOF, Epsilon, and Alloy. Textual modeling languages have the
Categories: Incoming News

OCL 2014: First Call for Papers

haskell-cafe - Wed, 05/07/2014 - 9:37pm
(Apologies for duplicates) CALL FOR PAPERS 14th International Workshop on OCL and Textual Modeling Applications and Case Studies (OCL 2014) Co-located with ACM/IEEE 17th International Conference on Model Driven Engineering Languages and Systems (MODELS 2014) September 28-30 (tbc), 2014, VALENCIA, SPAIN http://www.software.imdea.org/OCL2014/ Modeling started out with UML and its precursors as a graphical notation. Such visual representations enable direct intuitive capturing of reality, but some of their features are difficult to formalize and lack the level of precision required to create complete and unambiguous specifications. Limitations of the graphical notations encouraged the development of text-based modeling languages that either integrate with or replace graphical notations for modeling. Typical examples of such languages are OCL, textual MOF, Epsilon, and Alloy. Textual modeling languages have the
Categories: Offsite Discussion

Edward Z. Yang: Elimination with a Motive (in Coq)

Planet Haskell - Wed, 05/07/2014 - 9:13pm

Elimination rules play an important role in computations over datatypes in proof assistants like Coq. In his paper "Elimination with a Motive", Conor McBride argued that "we should exploit a hypothesis not in terms of its immediate consequences, but in terms of the leverage it exerts on an arbitrary goal: we should give elimination a motive." In other words, proofs in a refinement setting (backwards reasoning) should use their goals to guide elimination.

I recently had the opportunity to reread this historical paper, and in the process, I thought it would be nice to port the examples to Coq. Here is the result:

http://web.mit.edu/~ezyang/Public/motive/motive.html

It's basically a short tutorial motivating John Major equality (also known as heterogenous equality.) The linked text is essentially an annotated version of the first part of the paper—I reused most of the text, adding comments here and there as necessary. The source is also available at:

http://web.mit.edu/~ezyang/Public/motive/motive.v

Categories: Offsite Blogs

Need pointer to explain CPU usage

haskell-cafe - Wed, 05/07/2014 - 8:43pm
Hello List, I have a tiny scotty-based application, which when compiled and started in profiling mode, consumes 10x CPU it does in normal mode. Interestingly, if I fire a request on the app, CPU usage drops to minimal after finishing the request for a while. But after a few minutes it starts consuming 10x CPU again. First I would have suspected scotty, however collecting time profiling info with -p, -P or -Pa doesn't reveal much. That still not rules scotty out however. To make matters worse, I inspect strange time profiling tick count I can't explain - the .prof file says "2 ticks < at > 1000 us", while the application was clearly running idle for a good few seconds. Any ideas what am I missing? Thanks, Robin
Categories: Offsite Discussion