News aggregator

wren gayle romano: Women in FP

Planet Haskell - Sun, 05/04/2014 - 4:56pm

Katie Miller is giving a talk about FP outreach and diversity at next month's Erlang User Conference. She sent a questionnaire to the Lambda Ladies mailing list about our experiences, and I thought I'd share my responses here.

What led you to pursue functional programming?

Curiosity. I was in grad school, working towards a masters in computer science. And I was particularly interested in programming languages, though I was only familiar with imperative and OO languages at that point. I saw a course on functional programming, so I signed up. Best CS decision I ever made.

What sort of perception did you have of functional programming before you learnt more about it? Was this a barrier? If so, how did you overcome this?

All I knew at the time was that it was some sort of paradigm completely different from imperative and OO. That's it really. This was before FP started becoming popular; so, long before Clojure or Scala were invented, and long before C++ considered adding lambdas/closures to the language. Even within the FP community, Haskell was still considered the new kid on the block (despite having been around for quite some time).

What were the challenges for becoming part of the FP community?

The main challenge was just in figuring out where the community was and how to take part. As I said, this was long before FP became popular. My first FP language was Haskell, but I'd learned it in that course on functional programming so I didn't really know what the community was like. It was a year or two after taking the class that I decided to start really using Haskell for projects. At the time I was taking part in the Perl community, so I thought I'd go searching for some Haskell mailing lists to join. That's when I found the firehose that is Haskell Cafe.

Why do you think women are underrepresented in FP, more so than in programming generally?

I think there are a number of reasons. One of the big ones is how academic the community is. I don't mean that in the way people usually do. I'm an academic, and I love it here! No, the problem is that this creates a huge selection bias. I only really found FP by stumbling into it, and I only stumbled into it because I had a number of supportive advisors who helped foster my interest in programming languages. By the point I found FP, many women would have already been filtered out. Just getting into and affording college is a huge thing, especially for women of color. Let alone making it through undergrad and then getting into a masters program in CS without a bachelor's in CS. Let alone ending up at a school that can offer good FP classes, and finding those supportive advisors to help you along and guide you in the right direction.

If my story is anything to go by, it takes a lot of privilege (and luck) just to get to the point where you discover FP. After that, then you add on all the issues about maintaining community involvement. Because the community is so academic, this heightens issues of impostor syndrome. (Even men are driven out of FP due to impostor syndrome!) And since FP tends to be sold in a hyper-intellectualized manner, this evokes the "math is hard" brand of anti-intellectualism. While this drives a lot of people away, I think it has a differentially powerful impact on women due to the way we gender the sciences. That is, FP propaganda has a habit of taking the things which cause women to be underrepresented in STEM generally, and then cranking them up to eleven.

Another issue, and one I haven't seen discussed very often, is the fact that many FP communities are also FOSS communities. Women are more underrepresented in FOSS than in other CS communities, so the fact that FP tends to be FOSS means that women will tend to be more underrepresented in FP than other CS communities.

What strategies do you think the community could employ to address this problem and improve the (gender, and other types of) diversity in FP?

Setting up communities which aren't so hyper-intellectualized is a big step. Getting rid of all that propaganda and just treating FP like any other paradigm will do a lot to mitigate the impact of impostor syndrome and "math is hard" anti-intellectualism. It's no panacea, but it's probably the easiest thing we can tackle. Addressing the systemic issues is a lot harder.

Do you think it helps to have a women's group like Lambda Ladies? How has it been helpful for you?

I do think it helps. Over the years I've seen a lot of women come and go (mostly go) on Haskell Cafe. Overall I feel like the Cafe is one of the safer and more welcoming communities, but we've still had our misogynistic flareups. And after each one, I've watched the subsequent evacuation as women no longer feel quite so safe or welcome. By offering a safe space, women's groups are an important form of resistance against this sort of problem. It's a space where you don't always have to be on your guard against harassment. It's a space where you don't have to worry about how you present yourself, don't have to worry that femininity will undermine your credibility, don't have to worry about how asking "stupid" questions will affect the way people think of women as a whole.

Also —we don't really do this on LL, but— women's groups can provide a safe environment for venting about the sorts of problems we encounter online, in the work force, etc. Venting is always a tricky topic, but I think the importance of venting is grossly underrated. Whatever community you're a part of, bad things are going to come up sooner or later. When that happens, having a side community where you can let off steam or discuss why the particular thing is problematic is an important way to deal with the emotional fallout of these bad things. Once you've dealt with it, you can return to the main community; but if you have nowhere to deal with it, then things build up and up until you're just done and you quit the community.

In addition to providing a safe space, women's groups also serve an important role regarding announcements for jobs, conferences, etc. The announcements we get are tailored for women and so include important details like how welcoming they are of women, whether they can offer travel expenses, whether they offer child care, and so on.

For me, LL has been helpful mainly as a place to witness women in FP. Just seeing other women is energizing, and keeps me interested in being out there as part of the general FP community. The bit about announcements has also been helpful.

Categories: Offsite Blogs

Ideomatic way to compose "sum"-like functions and apply over a functor

Haskell on Reddit - Sun, 05/04/2014 - 2:46pm

Imagine you have a function "a -> a -> a" similar to (+) or (++). Let's call it 'sum'. If you have two arguments "x :: a" and "y :: a" you can apply it like this

result = sum x y


result = x `sum` y

Imagine you need to apply it over arguments in a functor (sorry if it's a wrong way to put it), "xf :: f a" and "yf :: f a". You can use the notation from Applicative:

result = sum <$> xf <*> yf

So far so good. Now imagine you need to "sum" three arguments. As long as they are "plain", you can simply write:

result = x `sum` y `sum` z

and it looks clean and nice. But what would be a "nice" notation for that if the arguments are in a functor? I came up with this:

result = ((.).(.)) sum sum <$> xf <*> yf <*> zf

but the owlish face at the beginning is somewhat scary (i.e. not intuitively obvious). Using some sort of foldM seems an overkill when the number of arguments is small.

Any advice? Thanks in advance!

submitted by lukewarm
[link] [6 comments]
Categories: Incoming News

What happened to #haskell?

Haskell on Reddit - Sun, 05/04/2014 - 11:47am

I briefly played around with haskell back in 2007 or so, and back then #haskell seemed to have a lot of helpful and patient people willing to answer even dumb noob questions. Since I've been actually using haskell for real the past year or so, I've been hanging around the irc channel and it seems like that is no longer the case. Lots of questions either get ignored totally or are given one line non-answers now. Is it just my imagination or do you basically have to use stackoverflow to get help now? Is stackoverflow the reason #haskell isn't helpful anymore, or is it just a co-incidence?

submitted by haskellnoob
[link] [57 comments]
Categories: Incoming News

Deadline extension: The 20th IEEE Pacific Rim International Symposium on Dependable Computing (PRDC 2014)

General haskell list - Sun, 05/04/2014 - 11:22am
*** Apologies for cross-posting *** *Due to numerous requests, the deadline of PRDC 2014 has been extended to May 16th 2014.* *Call for Papers: The 20th IEEE Pacific Rim International Symposium on Dependable Computing (PRDC 2014)* *Singapore Nov 18-21, 2014 * PRDC 2014 ( is the twentieth in this series of symposia started in 1989 that are devoted to dependable and fault-tolerant computing. PRDC is recognized as the main event in the Pacific area that covers the many dimensions of dependability and fault tolerance, encompassing fundamental theoretical approaches, practical experimental projects, and commercial components and systems. As applications of computing systems have permeated into all aspects of daily life, the dependability of computing systems has become increasingly critical. This symposium provides a forum for countries around the Pacific Rim and other areas of the world to exchange ideas for improving the dependability of computing systems.
Categories: Incoming News

What's the most idiomatic way to partially apply a function to an arbitrary subset of its arguments?

Haskell on Reddit - Sun, 05/04/2014 - 8:57am

It often happens in Haskell that there is a function with lots of parameters

a -> b -> c -> d -> e -> f

and it would be convenient to partially apply it not to "a" and "b" but, say, to "b" and "e".

For a 2-parameter function flip works fine but writing a bunch of n-ary flips feels crufty.

I'm also aware of passing a record as an argument which allows the simulation of keyword args, but many (most?) library functions aren't written that way.

Is there another way, besides generating the closure definitions through Template Haskell?

submitted by DreamyDreugh
[link] [18 comments]
Categories: Incoming News

State of secure coding in Haskell?

Haskell on Reddit - Sun, 05/04/2014 - 5:05am

Recently, I've been forced to study a bit of software security. Everyone who has ever done so probably knows how frustrating that can be - pretty much every tool for building programs seems either broken or beyond repair.

Static checking and fuzzing seem to be the state of art in C and Java side of the fence. What is the status of such tools in Haskell? Are there taint tracking tools or other static analysers beyond the type system? Or any recommended libraries specially aimed for secure programming? (I'd guess that quickcheck covers pretty much everything you'd use fuzzing for. And without the nasty difficulty of devising oracles.)

(As an example why I feel such tools are necessary, both the snap tutorial and the example in scotty docs present code with an obvious xss vulnerability without any warning sticker attached.)

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

What's the best way to get involved with open source Haskell projects?

Haskell on Reddit - Sun, 05/04/2014 - 4:44am

Hi. I've been learning Haskell for a while now and I feel like a good way to practice would be to get involved with some open source projects. I was wondering if anyone knew the best way to start getting involved. Are there any projects which are welcoming to people who may not be the best Haskell programmers or is there a particular project you know that could do with a hand?

Thanks and sorry if this is in the wrong place. I originally posted this to /r/haskellquestions but there were no replies. Thanks

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

Edward Z. Yang: The cost of weak pointers and finalizers in GHC

Planet Haskell - Sun, 05/04/2014 - 2:55am

Weak pointers and finalizers are a very convenient feature for many types of programs. Weak pointers are useful for implementing memotables and solving certain classes of memory leaks, while finalizers are useful for fitting "allocate/deallocate" memory models into a garbage-collected language. Of course, these features don’t come for free, and so one might wonder what the cost of utilizing these two (closely related) features are in GHC. In this blog post, I want to explain how weak pointers and finalizers are implemented in the GHC runtime system and characterize what extra overheads you incur by using them. These post assumes some basic knowledge about how the runtime system and copying garbage collection work.

The userland API

The API for weak pointers is in System.Mem.Weak; in its full generality, a weak pointer consists of a key and a value, with the property that if the key is alive, then the value is considered alive. (A "simple" weak reference is simply one where the key and value are the same.) A weak pointer can also optionally be associated with a finalizer, which is run when the object is garbage collected. Haskell finalizers are not guaranteed to run.

Foreign pointers in Foreign.ForeignPtr also have a the capability to attach a C finalizer; i.e. a function pointer that might get run during garbage collection. As it turns out, these finalizers are also implemented using weak pointers, but C finalizers are treated differently from Haskell finalizers.

Representation of weak pointers

A weak pointer is a special type of object with the following layout:

typedef struct _StgWeak { /* Weak v */ StgHeader header; StgClosure *cfinalizers; StgClosure *key; StgClosure *value; /* v */ StgClosure *finalizer; struct _StgWeak *link; } StgWeak;

As we can see, we have pointers to the key and value, as well as separate pointers for a single Haskell finalizer (just a normal closure) and C finalizers (which have the type StgCFinalizerList). There is also a link field for linking weak pointers together. In fact, when the weak pointer is created, it is added to the nursery's list of weak pointers (aptly named weak_ptr_list). This list is global, so we do have to take out a global lock when a new weak pointer is allocated.

Garbage collecting weak pointers

Pop quiz! When we do a (minor) garbage collection on weak pointers, which of the fields in StgWeak are considered pointers, and which fields are considered non-pointers? The correct answer is: only the first field is considered a “pointer”; the rest are treated as non-pointers by normal GC. This is actually what you would expect: if we handled the key and value fields as normal pointer fields during GC, then they wouldn’t be weak at all.

Once garbage collection has been completed (modulo all of the weak references), we then go through the weak pointer list and check if the keys are alive. If they are, then the values and finalizers should be considered alive, so we mark them as live, and head back and do more garbage collection. This process will continue as long as we keep discovering new weak pointers to process; however, this will only occur when the key and the value are different (if they are the same, then the key must have already been processed by the GC). Live weak pointers are removed from the "old" list and placed into the new list of live weak pointers, for the next time.

Once there are no more newly discovered live pointers, the list of dead pointers is collected together, and the finalizers are scheduled (scheduleFinalizers). C finalizers are run on the spot during GC, while Haskell finalizers are batched together into a list and then shunted off to a freshly created thread to be run.

That's it! There are some details for how to handle liveness of finalizers (which are heap objects too, so even if an object is dead we have to keep the finalizer alive for one more GC) and threads (a finalizer for a weak pointer can keep a thread alive).

Tallying up the costs

To summarize, here are the extra costs of a weak pointer:

  1. Allocating a weak pointer requires taking a global lock (this could be fixed) and costs six words (fairly hefty as far as Haskell heap objects tend to go.)
  2. During each minor GC, processing weak pointers takes time linear to the size of the weak pointer lists for all of the generations being collected. Furthermore, this process involves traversing a linked list, so data locality will not be very good. This process may happen more than once, although once it is determined that a weak pointer is live, it is not processed again. The cost of redoing GC when a weak pointer is found to be live is simply the cost of synchronizing all parallel GC threads together.
  3. The number of times you have to switch between GC'ing and processing weak pointers depends on the structure of the heap. Take a heap and add a special "weak link" from a key to its dependent weak value. Then we can classify objects by the minimum number of weak links we must traverse from a root to reach the object: call this the "weak distance". Supposing that a given weak pointer's weak distance is n, then we spend O(n) time processing that weak pointer during minor GC. The maximum weak distance constitutes how many times we need to redo the GC.

In short, weak pointers are reasonably cheap when they are not deeply nested: you only pay the cost of traversing a linked list of all of the pointers you have allocated once per garbage collection. In the pessimal case (a chain of weak links, where the value of each weak pointer was not considered reachable until we discovered its key is live in the previous iteration), we can spend quadratic time processing weak pointers.

Categories: Offsite Blogs

Suppose there is a function, `foo :: T -> T` that is probably too complex for a human to program. What can a Haskeller do?

Haskell on Reddit - Sun, 05/04/2014 - 1:41am

Suppose that you want to write a function for a type T, foo :: T -> T, that is considerably complex for a human to program. Suppose it is purposely made so. You can generate infinitely many valid input-output pairs, but you can not code that function itself. Is there anything you can do?

(I've been thinking in genetic programming libraries and similars...)

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

[Question] Composable events: Applicative and Alternative

Haskell on Reddit - Sat, 05/03/2014 - 11:20pm

For a game I am making, I am using events that the player can program. For example, the player can register a callback that will be triggered when a new player arrives. He can also program some forms (with buttons, checkboxes, textboxes...) to appear on the Web GUI. The problem is those events are not composable: he has to create and handle them one by one.

So I'm thinking of making those events composable by making them an instance of Applicative and Alternative. For Applicative, this makes events composable very much like in Applicative-Functors and Reform. I can build neat composed events such as (full program below):

onInputMyRecord :: Event MyRecord onInputMyRecord = MyRecord <$> onInputText <*> onInputCheckbox

For Alternative, I haven't seen any example of it on the net. The idea is that the first event that fires is used to build the alternative:

onInputMyAlternative :: Event Bool onInputMyAlternative = (const True <$> onInputButton) <|> (const False <$> onInputButton)

Have you heard about a similar implementation? It seems pretty useful. Maybe in FRP frameworks?

Here is an example program:

{-# LANGUAGE GADTs #-} module ComposableEvents where import Control.Applicative import Data.Time import Data.Traversable type PlayerNumber = Int data Event a where OnInputText :: PlayerNumber -> Event String -- A textbox will be created for the player. When filled, this event will fire and return the result OnInputCheckbox :: PlayerNumber -> Event Bool -- Idem with a checkbox OnInputButton :: PlayerNumber -> Event () -- Idem with a button OnTime :: UTCTime -> Event () -- time event EventSum :: Event a -> Event a -> Event a -- The first event to fire will be returned EventProduct :: Event (a -> b) -> Event a -> Event b -- both events should fire, and then the result is returned Fmap :: (a -> b) -> Event a -> Event b -- transforms the value returned by an event. Pure :: a -> Event a -- Create a fake event. The result is useable with no delay. Empty :: Event a -- An event that is never fired. instance Functor Event where fmap = Fmap instance Applicative Event where pure = Pure (<*>) = EventProduct instance Alternative Event where (<|>) = EventSum empty = Empty onInputText = OnInputText onInputCheckbox = OnInputCheckbox onInputButton = OnInputButton onTime = OnTime -- A product type data MyRecord = MyRecord String Bool -- A sum type data MyAlternative = A | B -- Using the Applicative instance, we can build a product type from two separate event results. -- The event callback should be called only when all two events have fired. onInputMyRecord :: Event MyRecord onInputMyRecord = MyRecord <$> onInputText 1 <*> onInputCheckbox 1 -- other possible implementation (given a monad instance) -- onInputMyRecord' = do -- s <- onInputText -- b <- onInputCheckbox -- return $ MyRecord s b -- Using the Alternative instance, we build a sum type. -- The event callback should be called when the first event have fired. onInputMyAlternative :: Event MyAlternative onInputMyAlternative = (const A <$> onInputButton 1) <|> (const B <$> onInputButton 1) allPlayers = [1 .. 10] -- Now complex events can be created, such as voting systems: voteEvent :: UTCTime -> Event ([Maybe Bool]) voteEvent time = sequenceA $ map (singleVote time) allPlayers singleVote :: UTCTime -> PlayerNumber -> Event (Maybe Bool) singleVote timeLimit pn = (Just <$> onInputCheckbox pn) <|> (const Nothing <$> onTime timeLimit) vote :: UTCTime -> Event Bool vote timeLimit = unanimity <$> (voteEvent timeLimit) unanimity :: [Maybe Bool] -> Bool unanimity = all (== Just True) --Evaluation --evalEvent :: Event a -> State Game a --evalEvent = undefined

With this DSL, I can create complex events such as time limited votes very neatly...
There is much left to do for a full implem: the way to register callbacks on complex events, the evaluator and the event manager.
Any pointers to similar works?

PS: I copied this example also in

submitted by kaukau
[link] [2 comments]
Categories: Incoming News

How can I desugar a code snippet?

Haskell on Reddit - Sat, 05/03/2014 - 11:14pm

Is there a compiler option or other tools can help me to see the desugared version source code?

submitted by cakebunny
[link] [1 comment]
Categories: Incoming News