News aggregator

ML Family Workshop -- Last call for presentations

General haskell list - Fri, 05/09/2014 - 3:37am
Important dates Monday May 19 (any time zone): Abstract submission Monday June 30: Author notification Thursday September 4, 2014: ML Family Workshop Higher-order, Typed, Inferred, Strict: ACM SIGPLAN ML Family Workshop Thursday September 4, 2014, Gothenburg, Sweden (immediately following ICFP and preceding OCaml Users and Developers Workshop) Call For Papers ML is a very large family of programming languages that includes Standard ML, OCaml, F#, SML#, Manticore, MetaOCaml, JoCaml, Alice ML, Dependent ML, Flow Caml, and many others. All ML languages, beside the great deal of syntax, share several fundamental traits. They are all higher-order, strict, mostly pure, and typed, with algebraic and other data types. Their type systems inherit from Hindley-Milner. The development of these languages has inspired a significant amount of computer science research and influenced a number of programming languages, including Haskell, Scala and Clojure,
Categories: Incoming News

Create line-histogram while iterating over STDIN (and possibly beat Python)

Haskell on Reddit - Fri, 05/09/2014 - 3:02am

I was recently challenged by a Python colleague to come up with a comparable implementation of the seemingly trivial Python 4-liner below:

import sys from collections import Counter for (line,count) in Counter(sys.stdin).items(): print("{}\t{}".format(count, line.rstrip('\r\n')))

For those unfamiliar with Python, the code above basically iterates over each line of /dev/stdin and inserts each line into an anonymous multiset. When /dev/stdin is exhausted, the multiset is iterated over, and each entry printed (prefixed by its cardinality). IOW, the output is similiar to sort | uniq -c, except that no explicit sorting occurs.

When processing a large testfile,

/usr/bin/time -v ./ < testdata.log > out.log

It had the following runtime properties:

Command being timed: "./" User time (seconds): 0.36 System time (seconds): 0.02 Percent of CPU this job got: 99% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.39 Average shared text size (kbytes): 0 Average unshared data size (kbytes): 0 Average stack size (kbytes): 0 Average total size (kbytes): 0 Maximum resident set size (kbytes): 14600 Average resident set size (kbytes): 0 Major (requiring I/O) page faults: 0 Minor (reclaiming a frame) page faults: 5082 Voluntary context switches: 1 Involuntary context switches: 43 Swaps: 0 File system inputs: 0 File system outputs: 3704 Socket messages sent: 0 Socket messages received: 0 Signals delivered: 0 Page size (bytes): 4096 Exit status: 0

And the testdata used and the result output had the following properties

$ wc testdata.log ; wc out.log 1681572 6727447 67789693 testdata.log 43967 220018 1893213 out.log

The testdata was not in any particular order (in fact, randomizing via sort --random-sort didn't change the result significantly)

I thought this would be an easy challenge. After all, Haskell is compiled and Python is purely interpreted. I tried coming up with a solution involving Data.HashMap but couldn't figure out a way to have a comparable memory footprint (i.e. max-RSS < 15MB) and runtime (while also avoiding Lazy I/O). I didn't even try to come up with concise code at this point as I wanted to get the runtime properties right first.

Can anybody help me defend Haskell's honor?

PS: here's simple code to create testdata to /dev/stdout with similiar runtime properties I measured above:

import os, binascii, random lines = [ binascii.b2a_hex(os.urandom(random.randint(15,25))) for _ in range(44000) ] for _ in range(1700000): print random.choice(lines) submitted by RedLambda
[link] [20 comments]
Categories: Incoming News

Joachim Breitner: Going to TFP 2014

Planet Haskell - Fri, 05/09/2014 - 1:59am

Near the end of my internship with Simon Peyton Jones at MSR Cambridge I tackled the problem that foldl is not a good consumer in the sense of list fusion, as the resulting code compiles quite badly. I found an analysis that would allow GHC to safely do the required transformation to fix this in the common case; I dubbed this analysis Call Arity. The code is in GHC master (but not in 7.8), and I get to present at the Trends in Functional Programming conference in Soesterburg in 2½ weeks. If you are curious you can either look at the code in CallArity.hs or the submitted paper, which yet has to go through the formal post-conference peer review in order to be officially accepted.

If you are going to TFP as well and want to get your GPG key signed, just talk to me there!

Categories: Offsite Blogs

Could a plugin be made to run Haskell games on the web/android/iOS, akin to Unity3D?

Haskell on Reddit - Fri, 05/09/2014 - 1:39am

I've been thinking in starting to invest in gamedev using Haskell. The language is awesome and has everything I could ever dream. It lacks a proper gaming engine, but I could work on that. There is just one problem, portability. It doesn't matter if I get a 3D game to work using LambdaCube and whatnot, if I am not able to get this running on the browser and mobile apps, which is where the market is.

I find this a huge downside of the language. I comprehend the difficulty involved in compiling to JavaScript, for example. My question is: wouldn't it be possible to create a "Haskell Plugin", similar to Flash/Unity3D, for that purpose? When the subject is a game, most users won't mind a small plugin download.

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

Brazilian type checking - Fri, 05/09/2014 - 1:11am
Categories: Offsite Blogs

Edward Z. Yang: GHC and mutable arrays: a DIRTY little secret

Planet Haskell - Fri, 05/09/2014 - 12:34am

Brandon Simmon recently made a post to the glasgow-haskell-users mailing list asking the following question:

I've been looking into an issue in a library in which as more mutable arrays are allocated, GC dominates (I think I verified this?) and all code gets slower in proportion to the number of mutable arrays that are hanging around. which I replied:

In the current GC design, mutable arrays of pointers are always placed on the mutable list. The mutable list of generations which are not being collected are always traversed; thus, the number of pointer arrays corresponds to a linear overhead for minor GCs.

If you’re coming from a traditional, imperative language, you might find this very surprising: if you paid linear overhead per GC in Java for all the mutable arrays in your system... well, you probably wouldn't use Java ever, for anything. But most Haskell users seem to get by fine; mostly because Haskell encourages immutability, making it rare for one to need lots of mutable pointer arrays.

Of course, when you do need it, it can be a bit painful. We have a GHC bug tracking the issue, and there is some low hanging fruit (a variant of mutable pointer arrays which has more expensive write operation, but which only gets put on the mutable list when you write to it) as well as some promising directions for how to implement card-marking for the heap, which is the strategy that GCs like the JVM's use.

On a more meta-level, implementing a perfomant generational garbage collector for an immutable language is far, far easier than implementing one for a mutable language. This is my personal hypothesis why Go doesn’t have a generational collector yet, and why GHC has such terrible behavior on certain classes of mutation.

Postscript. The title is a pun on the fact that “DIRTY” is used to describe mutable objects which have been written to since the last GC. These objects are part of the remembered set and must be traversed during garbage collection even if they are in an older generation.

Categories: Offsite Blogs

Status of Data Parallel Haskell (DPH)?

Haskell on Reddit - Fri, 05/09/2014 - 12:31am

It seems the development has basically stopped since late 2012. The current version on hackage depends on base ==4.6.* which won't compile on GHC 7.8 either. Is it still being worked on or has all the efforts been transferred to repa now?

submitted by pkmxtw
[link] [7 comments]
Categories: Incoming News

Using mutable array after an unsafeFreezeArray, and GC details

glasgow-user - Fri, 05/09/2014 - 12:18am
I have an unusual application with some unusual performance problems and I'm trying to understand how I might use unsafeFreezeArray to help me, as well as understand in detail what's going on with boxed mutable arrays and GC. I'm using the interface from 'primitive' below. First some basic questions, then a bit more background 1) What happens when I do `newArray s x >>= \a-> unsafeFreezeArray a 2) And what if a do a `cloneMutableArray` on `a` and likewise use the resulting array? Background: I've been looking into an issue [1] in a library in which as more mutable arrays are allocated, GC dominates (I think I verified this?) and all code gets slower in proportion to the number of mutable arrays that are hanging around. I've been trying to understand how this is working internally. I don't quite understand how the "remembered set" works with respect to MutableArray. As best I understand: the remembered set in generation G points to certain objects in older generations, which objects hold references to ob
Categories: Offsite Discussion

Templates as typeclasses?

haskell-cafe - Fri, 05/09/2014 - 12:18am
In going over yet again the many failings of template frameworks for building web apps, I recalled some of the features of the best of the lot, and wondered if those features might be useful in a Haskell template framework. Python's Cheetah tool makes templates almost fully functional members of Python's OO system. A template can inherit from a Python class or another template, and a Python class can inherit from a template. Which makes me wonder if something similar might not be useful in a Haskell template framework. Possibly have each template create an appropriate datatype and make it as an instance of the Template typeclass (and possibly others). Is there already a Haskell web framework that does something like this? Would it actually add value to a framework? Thanks, Mike _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion

A Modern History of Lenses (PDF) - Thu, 05/08/2014 - 8:08pm
Categories: Offsite Blogs

Categories with different objects

Haskell on Reddit - Thu, 05/08/2014 - 7:41pm

For context, this question was formulated while trying to understand the heart of van laarhoven lenses, particularly the special case of isomorphisms.

In a very simple case, we could have a datatype

Isomorph a b = Iso {view :: a -> b, reView :: b -> a}

but if we try to do (not so) fancy things like

swap = let f (a,b) = (b,a) in Iso f f under (Iso f f') g = f' . g . f simple = under (let f (a,b) = (b,a) in Iso f f) (first show)

we get a type error on 'simple' because the tuple type chances in the middle of the conjugation This is why the full lens type from Control.Lens

Iso s t a b

is useful, it is separately polymorphic in the to/from direction So we could model this like

data Isomorph s t a b = Iso {view :: s -> a, reView :: b -> t}

but this is a datatype, so we can't just compose it with (.) like lenses unless we provide a category instance... but we CAN'T provide a category instance, because Isomorph doesn't have kind (* -> * -> *), though we could provide a perfectly good composition function, it wouldn't be general and would take up namespace.

More generally, the class Category is really only for categories with all haskell types as objects.

I tried something like

class Cat (c :: k) where type Ob c a b iden :: forall x. Ob c x x comp :: forall x y z. Ob c y z -> Ob c x y -> Ob c x z instance Cat Isomorph where type Ob Isomorph (a,a') (b,b') = Isomorph a a' b b' iden = Iso id id

But no matter how I mangle it, it doesn't want to compile. It seems the problem is trying to shove two foralls into one, but foralls aren't first class, so I don't know of any programatic way to do this. Or maybe there is a better way alltogether to represent a category with different objects?

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

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 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 >
Categories: Offsite Discussion