News aggregator

Constrained monad overview for the naive?

Haskell on Reddit - Tue, 04/29/2014 - 12:11pm

I'm a dabbler in Haskell. A few months ago, I made another attempt at it, but ran into the constrained monad problem in my first toy project (dice probabilities, monad over map needs ord).

Now that I know the phrases "constrained monad" and "restricted monad", I can read up on it. I can find Oleg talking about it. I can find the ICFP paper by Sculthorpe, et al. What I can't find, though, is the recommended solution for beginners who run into the problem.

  • Should I just avoid it? I can't re-use the monadic machinery, but I can define my own functions easily.
  • Is there a ghc extension that I could use, that's reasonably well-accepted, that will make the problem go away?
  • Should I just buckle down and try one of the proposed work-arounds? If so, which one?
  • Is there a solution in the works?

Basically, is there a consensus recommendation for what to do?

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

mapAccumL - Hoogle - Tue, 04/29/2014 - 11:58am
Categories: Offsite Blogs

Problem installing dependencies

Haskell on Reddit - Tue, 04/29/2014 - 10:19am

I am trying to install the dependencies for a project but I am running into this error:

Failed to install base-unicode-symbols- cabal: Error: some packages failed to install: base-unicode-symbols- failed during the final install step. The exception was: /tmp/pkgConf-base-unicode-symbols-0.2.25614.4: hGetContents: invalid argument (invalid byte sequence)

How do I fix it?



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

Chris Reade: Red-Black Neighbourhood Stencil Diagrams

Planet Haskell - Tue, 04/29/2014 - 10:05am
Red-Black Neighbourhood Stencil Diagrams (for Laplace)

In a previous blog Repa Laplace and SOR, I used Repa to implement a Laplace solver using the Red-Black scheme. The explanation of alternating stencils probably needed a diagram, so here it is.

This diagram illustrates the shapes of the stencils for adding neighbours of red and black cells. It shows that two different stencils are needed (for odd and even rows) and these are swapped over for red and black.

Red-Black Neighbour Stencils

(The diagram was produced with Haskell Diagrams)

Categories: Offsite Blogs

Douglas M. Auclair (geophf): 'Y' is for Y-Combinator

Planet Haskell - Tue, 04/29/2014 - 9:45am

So, the Y-combinator is from the lambda calculus. It is of the form:
Y = λ f → f (Y f)
Wow. The thing about the Y-combinator, also called the fixpoint function, is that it's a big mess, type-wise, because sometimes you'll get no value out of it (as it does not terminate for many cases of functions) or sometimes you'll get multiple values out of it.
But what is it supposed to do? It's supposed to find the 'fixed' point of a function, the point of the function where it is 'fixed,' or comes to rest.
This is usually the case of a function with multiple cases, a case 'at rest' and an inductive case, like our good old friend, factorial:
factorial x = if (x = 0) then 1 else x * factorial (x -1)
for any natural number x.
The fixed point of this factorial function is one:
factorial x (where x = 1) = x
If you put this into the Y-combinator, you get:
Y factorial = factorial (Y factorial)
and when apply the natural number 1 you get
Y factorial 1 = factorial (Y factorial) 1
which comes to rest at 1 = 1
for any other number, this doesn't come to rest.
So, the Y-combinator is a very simple thing to define (as you saw above) and there's nothing in that definition about recursion (explicitly), but in computer science the Y-combinator is often used to model and to study recursion because of both its restful and (infinitely) inductive properties.
Okay, that's Y-combinator, the combinator from combinatory logic.
So, there's another Y-Combinator, and that's the name of a startup company headed up by Paul Graham (the Paul Graham, who wrote On Lisp).  I had the pleasure of meeting Paul at the Little Languages conferences at MIT back in 2008/2009 time-frame. He had just started Y-Combinator after selling Yahoo!-store to Yahoo! for 40 million dollars.
Nice, personable guy.
At that same conference I met Joe Armstrong, the Joe Armstrong, who invented Erlang (another name from mathematics, c.f. Markov chains and Queuing theory used telephony) after having sold his Erlang company for 40 million dollars.
Nice, soft-spoken guy. Some pretty 'weird' ideas about Concurrent-oriented programming ('weird' is a direct quote from wikipedia when describing the properties of the Y-combinator).
What do these guys have in common ... besides working really hard on something everybody else told them didn't work and would never work. That, and 40 million dollars, each.
I mean, Paul Graham wrote web services (before 'web services' existed as a term) in Lisp, of all things. He was afraid to tell others about using Lisp, for if they found out, they'd start to copy him and program in Lisp, too.
Nobody programs in Lisp, by the way. Just stupid students going to comp.lang.lisp asking "How do I reverse a list in Lisp? Please answer right away; homework due tomorrow morning."
Paul was worried somebody would find out, until his partner, Robert Morris, laughed at him: "Nobody cares! Everybody's programming in Java and has an Oracle back-end. They're following 'best practices;' they'd never use Lisp. That's why they're going to fail, and why we're going to succeed!"
Paul chilled after that pep-talk.
And Joe Armstrong? Ericsson told him: write us a concurrent language.
So he did.
It didn't look like Java, and it was untyped (just like Paul Graham's Lisp), so Ericsson fired him (actually, they didn't fire him, they just mandated that Erlang was not to be used at all in Ericsson anymore, so he left. Yeah. They fired him). He asked if he could keep Erlang. They said. "Erlang? Whatever. Sure. Take it and go."
He took it and went.
Erlang supports 60,000 concurrent nodes, at the same time. Joe showed it by connecting to his Erlang web server.
Netscape webserver crashed after 1,000 connections. It's a Unix thing. So, you know, Java ...? Same problems.
Joe showed his stuff around. Somebody bit. Cell phones? You need to support a lot of concurrency. A lot. He made a lot of money until Ericsson bought him back. Seems they needed his technology, after all.
What's weird about these guys?
Paul Graham's Y-combinator has started up scribd, Dropbox, and reddit.
His startups, in total, are valued at over $13.7 billion dollars. The startups had their original ideas and did all the work, all Paul Graham, and his family and partners did was open the door, give them a tiny little bit of money, and listen to them.
Joe. All he did was go against convention of 'everything has to be typed' and 'shared memory' and what threads are, and he kept at it until he got something working and he made it work with stunning results. And still he was rejected.
These are two men who believed in what they were doing, regardless of what everybody else was telling them was so, and they kept at it through success and disappointment.
And they are both generous with their time and are soft-spoken. Yes, they believe what they believe, and stand up for it, but they don't start confrontations, they don't even finish them. They just walk away and get to work, and make it work.
I see it all the time. That is: very rarely. This one guy, Brian Kernighan, at work, he wasn't given resources and told the acquisition process would take forever, or long after the due delivery date for the project.
So he bought dedicated hardware, set up a web server, and ran the application from his house.
This was for a big, big, really big cable company. Really big.
He was a water-walker. Why? Because he did what he needed to do, regardless of what everybody told him what couldn't be done.
You. Me. Every day we're told 'no' or 'later' or 'that can't be done' or 'you can't do it.'
You. Me. Everybody. We can choose to listen to what we're told, and to believe it, or we can go ahead and do what we see needs to be done, but nobody's doing it, because everybody says it can't be done.
The Y-combinator as a mathematical function that does what math functions aren't suppose to do: it doesn't give an answer, or it can give multiple answers. A function just returns one answer, that's all.  The Y-combinator doesn't. And it's modeled within mathematics using straight-up math.
It can't be done. But it's doing it.
You. You're told every day, 'it can't be done.' You can listen, and be like everybody else.
Or you can do it. And be what nobody else can be: you.
'Y' is for Y-combinator. 'Y' is for you.
Categories: Offsite Blogs

Fifty Years of BASIC, the Programming Language That Made Computers Personal

Lambda the Ultimate - Tue, 04/29/2014 - 8:20am

Fifty Years of BASIC, the Programming Language That Made Computers Personal

A very comprehensive history of BASIC from Time magazine.

Invented by John G. Kemeny and Thomas E. Kurtz of Dartmouth College in Hanover, New Hampshire, BASIC was first successfully used to run programs on the school’s General Electric computer system 50 years ago this week–at 4 a.m. on May 1, 1964, to be precise.

Edit: Dartmouth is celebrating Basic at 50.

Categories: Offsite Discussion

Philip Wadler: Scottish Independence, by the numbers

Planet Haskell - Tue, 04/29/2014 - 8:02am
Slides from my lab lunch are here.
To encourage discussion in preparation for 18 September, this talk will cover some of the relevant figures and list useful sources of information. I won't make a secret of my own view on the issue, but the goal is to cover relevant information, not to argue for one side or the other.
Categories: Offsite Blogs

Douglas M. Auclair (geophf): I've been 'X'-marks-the-spot'ed! Oh, noes!

Planet Haskell - Tue, 04/29/2014 - 5:07am

So, 'X' is for 'X' marks the Spot. It could have been for X-multiplication for division by fractions ...
1/2 ÷ 1/3 = (cross-multiplying gives you 1 * 3  ÷ 2 * 1 as Mr. Milardo, my math teacher in high school would chant: "Criss-cross; Applesause!" as we did fractional division)  3/2 or 1 1/2
But that would be that post and there it is and there you have it.
Where's the adventure and drama in that? Math is exciting and original, so why would I retreat boring, rote stuff like that, which everybody knows math isn't!
(Uh, wait, geophf: most people think math is boring and rote)
But that's not what this post is about. This post is about what happened at 5 pm at work in a meeting yesterday ...
... and why do these things always have to happen at 5 pm at the meeting at work, that you could've  just skipped out on, saying you had to catch your bus, but did you do that, no, and see what it gets you? Trouble, and more Trouble, that's why!
Trouble with a capital-'T'
('T' is for big Trouble)
('Hey, big Trouble.' 'Hey, little trouble.' Ah, the story of Siegfried and Brünnhilde, as retold by Quentin Tarantino)
So, yesterday at work, at 5 pm, we were having an innocuous little meeting about the layout of a chooser-window, allowing our users to select which columns to include, which not to, and which order they want to see them in.
With 600 columns, this isn't a trivial concern. Or it is trivial, but it's also a major time-sink for our users, having to deal with stuff that isn't a business concern.
Anyway, innocuous little meeting. I was bored out of my mind.
Our manager asked: "But what are we doing for learning our users' preferences in the application?"
Me: "Nothing."
Everybody else, all excited: "Well, we could do this and that and this and that!"
The Boss: "But what are we doing now for this?"
Me: "Nothing."
Then the boss goes on this five-minute tirade about how everywhere on the internet, it just knows what you want and how you want it, and how? And we're building applications straight out of 1993 and our users have to deal with this (euphemistic word for excrement), and what are we going to do about this? Who is going to add intelligence to our application?
And he glared right at me.
Somebody read my resume. Nobody reads resumes. Nobody reads emails. Nobody reviews code. I was totally and completely safe here being a 'senior Java developer,' slinging code and recommending 'best practices.'
Somebody read my resume.
I sighed. "I'll take this on."
Boss: "Good."
He got up and left. Meeting adjourned.
I've been played. My strengths have been played to.
My company is 'utilizing my full potential,' as it were.
I checked my shirt and my back. I didn't see a big-ole 'X' targeting me.
But it was there.
Okay, new day, but now I get to think about Markov chains and Google Analytics and neural classifiers ... at work ... and they're paying me to do this research.
Yeah. New day.
Tomorrow we'll look at the letter Y, the combinator and the company.
Categories: Offsite Blogs

Philip Wadler: I Shall Vote Yes

Planet Haskell - Tue, 04/29/2014 - 2:15am
From Bella Caledonia, a follow up to "I Shall Vote No".
My favourite line: "I shall vote Yes because that ‘early day of a better nation’ stuff gets to me, actually." Me too. The original line is "Work as if you live in the early days of a better nation", from a poem by Dennis Lee, popularised by Alasdair Gray.The last in the series of referendum poems by A.R. Frith. Read his sonnet for the Undecided here and his I Shall Vote No here.

I Shall Vote Yes

I shall vote Yes because
I just think that, in a divided world, we shouldn’t be building barriers
against immigrants and asylum seekers.

I shall vote Yes because
Labour say they believe in One Nation,
and that’s how fascism starts.

I shall vote Yes because I am fed up
with silly articles illustrated by stills from Braveheart, in newspapers that should know better.

I shall vote Yes, because the thought of having a written constitution
thrills me inexpressibly.

I shall vote Yes because until Independence we're stuck with Alex Salmond.

I shall vote Yes, because it is seven hundred years since the Battle of Bannockburn,
and yet some condescending gits imagine it is an issue for us now.

I shall vote Yes
to spare the blushes of foreign diplomats who have told their governments I will.

I shall vote Yes,
but No to Nato, if anyone asks me (though nobody ever has, come to think of it).

I shall vote Yes because Nicola Sturgeon is fantastic.


I shall vote Yes because I have no wish whatever
to be loved by Eddie Izzard.

I shall vote Yes, because I am striving to be Green.

I shall vote Yes because I have always liked Sean Connery,
even in Marnie and The Longest Day.

I shall vote Yes because it will kill the Nats stone dead.

I shall vote Yes, so that Scotland may take its rightful place
in the Eurovision Song Contest.

I shall vote Yes because to me as a Quaker it seems the right thing to do.

I shall vote Yes because
that ‘early day of a better nation’ stuff gets to me, actually.

I shall vote Yes because the Proclaimers will vote Yes.

I shall vote Yes because my MSP is a Unitarian
and it will boost his morale if someone agrees with him about something.

I shall vote Yes because, although ‘no-brainer’ is an unpleasing word,
I can’t think what else to call it.

I shall vote Yes, in the fervent hope that certain people will indeed up sticks and leave
(though I shan’t be holding my breath).

I shall vote Yes because James Kelman will vote Yes,
and he won the Booker Prize for using the f-word four thousand times in a novel.

I shall vote Yes, because I am persuaded
that the precedent of how Norwegian independence affected Sweden
shows that England will benefit almost as much as we will.

I shall vote Yes, because the experience of the Czech Republic and Slovakia
was that both countries were more prosperous after their velvet divorce.

I shall vote Yes, just to spite George Osborne.

I shall vote Yes out of curiosity
as to which unionist politician will be the first one to claim Independence
was what they really wanted all along, and is plainly a Good Thing.

I shall vote Yes because, despite what some people say,
I am, and always will be, British, thank God,
and so it is my duty.
Categories: Offsite Blogs

How to run a tree transformer on the GPU?

Haskell on Reddit - Tue, 04/29/2014 - 1:16am

Suppose I have a simple recursive binary-tree like:

data T = Add T T | Mul T T | Sub T T | Div T T | Num Int

Now say I define a recursive function on that datatype:

eval :: T -> T eval (Add a b) = (eval a) + (eval b) eval (Mul a b) = (eval a) * (eval b) eval (Div a b) = (eval a) / (eval b) eval (Sub a b) = (eval a) - (eval b) eval (Num a) = a

If I am not wrong, algorithms like this one, that fold over trees without context, are embarrassingly parallel.

eval (Add (Add 1 2) (Mul 3 4))

Here, (Add 1 2) and (Mul 3 4) could be executed in parallel. My question, is: is there a way to take similar functions, and make them run in parallel, on the GPU?

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