News aggregator

Closed Type Families: separate instance groups?

glasgow-user - Thu, 06/04/2015 - 12:09am
Currently (GHC 7.8.3) the only form for Closed Type Families is: type family F a where ... -- list your instances here (This was considered a common use case -- for example in HList to put the type-matching instance with the non-matching, and that would be total coverage; rather than needing a type family decl and an instance decl with the instance head same as family. That was an optimisation over ...) Way back the design was more like this: type family F a type instance F (Foo b c) where F (Foo Int c) = ... F (Foo b Char) = ... type instance F (Bar e f g) where F (Bar Int f g) = ... The idea was that the separate instance groups must have non-overlapping heads. This is handy if Foo, Bar, etc are declared in separate places/modules. You can put the instances with the data decl. And quite possibly the family decl is in an imported/library module you don't want to touch. Is this separate instance group idea still a gleam in someone's eye? If not, is th
Categories: Offsite Discussion

Why can QuasiQuoters only be used to generate top-level declarations?

Haskell on Reddit - Wed, 06/03/2015 - 9:22pm

There's probably a good reason, but it bugs me that this is valid:

[qq| thing :: Custom -> DSL |] thing = ...

...while this is not:

other = thing where [qq| thing :: Custom -> DSL |] thing = ...

...but this is:

other = thing where thing :: [qq| Custom -> DSL |] thing = ...

(Originally posted to /r/haskellquestions, but this didn't get any responses there so I thought I'd try the bigger subreddit.)

submitted by spindakin
[link] [10 comments]
Categories: Incoming News

What is the difference between an Algebraic Data Type and an Abstract Data Type?

Haskell on Reddit - Wed, 06/03/2015 - 8:41pm

I am struggling to understand the difference between those two concepts. To me they look pretty much the same, AlgDT allow type composition but so do AbsDT right?

For example I can compose ints and chars in an abstract data type:

struct coordinates { int x; int y; char data_point_name[5]; };

One powerful feature of AlgDT that really impressed was that I was able to define the set of natural numbers recursively:

data Nat = Z | S Nat

where Z is 0 and S the successor function. That is something that I could not do using 'struct' but does it make the different between AlgDTs and AbsDTs a fundamental one?

I know that I am confusing something and that there is a flaw in my understanding but I don't know what! Thank you for reading.

submitted by fictiveaaron
[link] [42 comments]
Categories: Incoming News

Proposal: Shorter Import Syntax

haskell-cafe - Wed, 06/03/2015 - 6:15pm
Hi Everyone, I didn't think this would see any resistance as it doesn't break anything, but this is the internet, so, if you haven't already, take a look at this GHC feature request <https://ghc.haskell.org/trac/ghc/ticket/10478> The idea is that rather than writing, import Data.Map (Map) import qualified Data.Map as M you could instead write, import Data.Map (Map) as M The Map identifier would imported unqualified, while M would be introduced as an alias for the qualified import of Data.Map. Note that, currently, following a parenthesized group with the "as" keyword is a parse error. So allowing this syntax would not affect any currently working programs. I've mentioned this proposal before and gotten good response, so I finally wrote it up last night after people on IRC responded positively to it. As well as IRC and trac, I put the link up on Twitter to get it in front of a large audience, and here's what we have after a bit over 12 hours (not counting the handful of supporters in IRC): +20 -2 Yo
Categories: Offsite Discussion

haskellers' view of closures? How is this stuff an improvement on OOP?

Haskell on Reddit - Wed, 06/03/2015 - 6:12pm

Touring around other languages like javascript, some of these functional-ish languages seem to make a big deal of closures as part of the functional paradigm.

To me it looks like OOP by another name - passing state and associated method around as a bundle. In fact, I think in the C++ world, STL took pains to characterize lambdas+captures as "stamping out classes" and not "anonymous functions".

The only thing that's slightly better than vanilla OOP is that it seems to default to a many-1 data to function coupling, whereas with OOP you have many-to-many data to function coupling. All in all closures feel a bit like OOP-in-sheep's clothing.

How do haskellers view closures? Maybe there's a win that I'm selling short here?

submitted by klaxion
[link] [36 comments]
Categories: Incoming News

Magnus Therning: Oh no! Success

Planet Haskell - Wed, 06/03/2015 - 6:00pm

This can’t possibly be good for Haskell…

We chose Haskell and the FP Complete stack because we knew the complexity of the problem required a new approach. The result was that we built better software faster than ever, and delivered it defect-free into a production environment where it has proven robust and high-performance

Categories: Offsite Blogs

Brent Yorgey: Crystal Ball Connection Patterns via Species and Generating Functions

Planet Haskell - Wed, 06/03/2015 - 1:07pm

A couple weeks ago, Denise posted Puzzle: Crystal Ball Connection Patterns on her blog, Let’s Play Math. I had fun playing with it and thought I would demonstrate how to apply some high-powered combinatorial techniques to it (probably not what Denise had in mind!).

The setup is that there are (distinct) friends who can talk to each other on the phone. Only two people can talk at a time (no conference calls). The question is to determine how many different “configurations” there are. Not everyone has to talk, so a configuration consists of some subset of the friends arranged in (unordered) conversational pairs.

Warning: spoilers ahead! If you’d like to play around with this yourself (and it is indeed a nice, accessible combinatorics problem to play with), stop reading now. My goal in this post is to have fun applying some advanced tools to this (relatively) simple problem.

Telephone numbers

Let’s start by visualizing some configurations. In her post, Denise illustrated the complete set of configurations for , which I will visualize like this:

Notice how I’ve arranged them: in the first row is the unique configuration where no one is talking (yes, that counts). In the second row are the six possible configurations with just a single conversation. The last row has the three possible configurations with two conversations.

One good approach at this point would be to derive some recurrences. This problem does indeed admit a nice recurrence, but I will let you ponder it. Instead, let’s see if we can just “brute-force” our way to a general formula, using our combinatorial wits. Later I will demonstrate a much more principled, mechanical way to derive a general formula.

Let’s start by coming up with a formula for , the number of configurations with people and conversations. The number of ways of choosing pairs out of a total of is the multinomial coefficient . However, that overcounts things: it actually distinguishes the first pair, second pair, and so on, but we don’t want to have any ordering on the pairs. So we have to divide by , the number of distinct orderings of the pairs. Thus,

Let’s do a few sanity checks. First, when , we have . We can also try some other small numbers we’ve already enumerated by hand: for example, , and . So this seems to work.

For people, there can be at most conversations. So, the total number of configurations is going to be

.

We can use this to compute for the first few values of :

At this point we could look up the sequence 1,1,2,4,10,26,76 on the OEIS and find out all sorts of fun things: e.g. that we are also counting self-inverse permutations, i.e. involutions, that these numbers are also called “restricted Stirling numbers of the second kind”, some recurrence relations, etc., as well as enough references to keep us busy reading for a whole year.

Species

We can describe configurations as elements of the combinatorial species . That is, a configuration is an unordered set () of () things (), where each thing can either be an unordered pair () of people talking on the phone, or () a single person () who is not talking.

We can now use the Haskell species library to automatically generate some counts and see whether they agree with our manual enumerations. First, some boilerplate setup:

ghci> :set -XNoImplicitPrelude ghci> :m +NumericPrelude ghci> :m +Math.Combinatorics.Species

Now we define the species of configurations:

ghci> let configurations = set `o` (set `ofSizeExactly` 2 + singleton)

We can ask the library to count the number of configurations for different :

ghci> take 10 (labelled configurations) [1,1,2,4,10,26,76,232,764,2620]

Oh good, those numbers look familiar! Now, I wonder how many configurations there are for ?

ghci> labelled configurations !! 100 24053347438333478953622433243028232812964119825419485684849162710512551427284402176

Yikes!

We can also use the library to generate exhaustive lists of configurations, and draw them using diagrams. For example, here are all configurations for . (If you want to see the code used to generate this diagram, you can find it here.)

And just for fun, let’s draw all configurations for :

Whee!

A general formula, via generating functions

Finally, I want to show how to use the species definition given above and the theory of generating functions to (somewhat) mechanically derive a general formula for the number of configurations. (Hopefully it will end up being equivalent to the formula we came up with near the beginning of the post!) Of course, this is also what the species library is doing, but only numerically—we will do things symbolically.

First, note that we are counting labelled configurations (the friends are all distinct), so we want to consider exponential generating functions (egfs). Recall that the egf for a species is given by

,

that is, a (possibly infinite) formal power series where the coefficient of is the number of distinct labelled -structures of size . In our case, we need

,

since there is exactly one set structure of any size, and

,

which is just the restriction of to only the term. Of course, we also have . Putting this together, we calculate

Ultimately, we want something of the form , so we’ll need to collect up like powers of . To do that, we can do a bit of reindexing. Right now, the double sum is adding up a bunch of terms that can be thought of as making a triangle:

Each ordered pair in the triangle corresponds to a single term being added. Each column corresponds to a particular value of , with increasing to the right. Within each column, goes from up to .

The powers of in our double sum are given by . If we draw in lines showing terms that have the same power of , it looks like this:

So let’s choose a new variable , defined by . We can see that we will have terms for every . We will also keep the variable for our other index, and substitute to get rid of . In other words, instead of adding up the triangle by columns, we are going to add it up by diagonals.

Previously we had ; substituting for that now turns into . Adding to both sides and dividing by yields (we can round down since is an integer). Looking at the diagram above, this makes sense: the height of each diagonal line is indeed half its index. Rewriting our indices of summation and substituting for , we now have:

And hey, look at that! The coefficient of is exactly what we previously came up with for . Math works!


Categories: Offsite Blogs

The Problem with Curation

Haskell on Reddit - Wed, 06/03/2015 - 11:43am
Categories: Incoming News

Haskell source-browsing nirvana?

Haskell on Reddit - Wed, 06/03/2015 - 11:37am

I'm using an awkward mix of hasktags, dash and hoogle. I wonder if anyone has achieved my dream in any editor: It would work like hasktags except it could use context like imports and qualifications to find the correct definition, jumping across the project source into sources for installed packages including ghc base.

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

The Problem with Curation

Haskell on Reddit - Wed, 06/03/2015 - 11:36am
Categories: Incoming News

mightybyte: The Problem with Curation

Planet Haskell - Wed, 06/03/2015 - 11:25am

Recently I received a question from a user asking about "cabal hell" when installing one of my packages. The scenario in question worked fine for us, but for some reason it wasn't working for the user. When users report problems like this they usually do not provide enough information for us to solve it. So then we begin the sometimes arduous back and forth process of gathering the information we need to diagnose the problem and suggest a workaround or implement a fix.

In this particular case luck was on our side and the user's second message just happened to include the key piece of information. The problem in this case was that they were using stackage instead of the normal hackage build that people usually use. Using stackage locks down your dependency bounds to a single version. The user reporting the problem was trying to add additional dependencies to his project and those dependencies required different versions. Stackage was taking away degrees of freedom from the dependency solver (demoting it from the driver seat to the passenger seat). Fortunately in this case the fix was simple: stop freezing down versions with stackage. As soon as the user did that it worked fine.

This highlights the core problem with package curation: it is based on a closed-world assumption. I think that this makes it not a viable answer to the general question of how to solve the package dependency problem. The world that many users will encounter is not closed. People are constantly creating new packages. Curation resources are finite and trying to keep up with the world is a losing battle. Also, even if we had infinite curation resources and zero delay between the creation of a package and its inclusion in the curated repository, that would still not be good enough. There are many people working with code that is not public and therefore cannot be curated. We need a more general solution to the problem that doesn't require a curator.

Categories: Offsite Blogs

Haskell dev role in Strats at Standard Chartered(Singapore)

General haskell list - Wed, 06/03/2015 - 9:50am
I have an open position for a Haskell developer to join Standard Chartered's Strats team in Singapore. More details at: https://donsbot.wordpress.com/2015/06/03/haskell-dev-role-in-strats-at-standard-chartered-singapore/
Categories: Incoming News

Pixel by pixel image processing

haskell-cafe - Wed, 06/03/2015 - 8:19am
Hi cafe! I want to do some trivial masking manipulation on PNG images: take a picture, crop it to square shape and then make a circular mask, i.e. take all pixels that lies outside circle with radius equal to half of image width and placed at image center and replace that pixels with zero opacity once (hope this description is clear enough). I've found two packages for image processing so far: `friday` [1] and `unm-hip` [2], but can't figure out which of them suits my needs, maybe there are some other packages I miss? [1] https://hackage.haskell.org/package/friday [2] https://hackage.haskell.org/package/unm-hip _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

-prof, -threaded, and -N

glasgow-user - Wed, 06/03/2015 - 6:20am
Hi, The behavior of the -N flag (without argument) with the profiling runtime seems inconsistent compared to the behavior without profiling. The following program ``` module Main where import GHC.Conc main :: IO () main = print numCapabilities ``` when compiled with `ghc -threaded -fforce-recomp Prof.hs` and run as `./Prof +RTS -N` prints `2` on my machine. When the same program is compiled with `ghc -threaded -fforce-recomp -prof Prof.hs` and executed as `./Prof +RTS -N` it prints `1`. When an argument is provided to `-N` (e.g. `./Prof +RTS -N2`) the profiling and non-profiling versions behave the same. I tested this with GHC-7.10.1 but I think that I already observed the same behavior with GHC-7.8. Is this inconsistency intended? Lars
Categories: Offsite Discussion

Don Stewart (dons): Haskell dev role in Strats at Standard Chartered [Singapore]

Planet Haskell - Wed, 06/03/2015 - 2:40am

The Strats team at Standard Chartered has an open position for a typed functional programming developer, based in Singapore.

You will work on the trading floor, directly with traders, building software to automate their work and improve their efficiency. The role is highly development focused and you will use Haskell for almost all tasks: data analysis, market data publishing, database access, web services, desktop GUIs, large parallel tasks, quantitative models, solvers, everything. This is a fast paced role – code you write today will be deployed within hours to hundreds of users and has to work.

This is a permanent position in Singapore as part of the Strats global team. Demonstrated experience in typed FP (Haskell, OCaml, F# etc) is required. We have around 2.5 million lines of Haskell, and our own Haskell compiler. In this context we look for skill and taste in typed functional programming to capture and abstract over complex, messy systems.

Experience writing typed APIs to external systems such as databases, web services, pub/sub platforms is very desirable. We like working code, so if you have Hackage or github libraries, we definitely want to see them. We also like StackOverflow answers, blog posts, academic papers, or other arenas where you can show broad FP ability. A PhD in computer science is a strong advantage.

The role requires physical presence on the trading floor in Singapore. Remote work is not an option. Ideally you have some project and client management skills — you will talk to users, understand their problems and then implement and deliver what they really need. No financial background is required.

More info about our development process is in the 2012 PADL keynote, and a 2013 HaskellCast interview.

If this sounds exciting to you, please send your resume to me – donald.stewart <at> sc.com.

Role posted 2015-06-03


Tagged: jobs
Categories: Offsite Blogs

ghc 7.10.1 hard lock on exit with shake, OS X 10.10

glasgow-user - Wed, 06/03/2015 - 2:36am
After I upgraded to 7.10.1 I started noticing that my shakefile would lock up on exit. It's after the 'main' function exits, and none of the shake tests have a problem, so presumably it's a GHC thing, that shake somehow causes to happen. Only kill -9 gets it to quit. Here's a stack trace from the OS X sampler: Call graph: 2801 Thread_909901 DispatchQueue_2: com.apple.libdispatch-manager (serial) 2801 _dispatch_mgr_thread (in libdispatch.dylib) + 52 [0x7fff8828ca6a] 2801 kevent64 (in libsystem_kernel.dylib) + 10 [0x7fff90ec0232] Total number in stack (recursive counted multiple, when >=5): Sort by top of stack, same collapsed (when >= 5): kevent64 (in libsystem_kernel.dylib) 2801 I know there aren't a lot of details here, but does this sound familiar to anyone? I can't see anything on https://ghc.haskell.org/trac/ghc/wiki/Status/GHC-7.10.2 that looks like this. Is there any way I can get more information I can get to report this? It used to be frequent (once
Categories: Offsite Discussion

GHC Weekly News - 2015/06/03

Haskell on Reddit - Wed, 06/03/2015 - 2:32am
Categories: Incoming News