Archive for the ‘Haskell’ Category

The Pragmatic Haskeller, Episode 4 – Recipe Puppy

Monday, April 29th, 2013

The Pragmatic Haskeller, Episode 4 – Recipe Puppy by Alfredo Di Napoli.

From the post:

Now we have our webapp that can read json from the outside world and store them inside MongoDB. But during my daily job what I usually need to do is to talk to some REST service and get, manipulate and store some arbitrary JSON. Fortunately for us, Haskell and its rich, high-quality libraries ecosystem makes the process a breeze.

Alfredo continues his series on building a basis web app in Haskell.

Promises a small DSL for describing recipes in the next espisode.

Which reminds me to ask, is anyone using a DSL to enable users to compose domain specific topic maps?

That is we say topic, scope, association, occurrence, etc. only because that is our vocabulary for topic maps.

No particular reason why everyone has to use those names in composing a topic map.

For a recipe topic map the user might see: recipe (topic), ingredient (topics), ordered instructions (occurrences), measurements, with associations being implied between the recipe and ingredients and between ingredients and measurements, along with role types, etc.

To a topic map processor, all of those terms are treated as topic map information items but renamed for presentation to end users.

If you select an ingredient, say fresh tomatoes in the salads category, it displays other recipes that also use fresh tomatoes.

How it does that need not trouble the author or the end user.

Yes?

The Pragmatic Haskeller – Episode 2 & 3

Sunday, April 21st, 2013

The Pragmatic Haskeller – Episode 2 – Snap by Alfredo Di Napoli.

Using Snap, this episode gets a minimal web app up and running.

The Pragmatic Haskeller – Episode 3 – Configurator by Alfredo Di Napoli.

Eliminates the hard coding of configuration information.

Here’s a semantic question for you:

If hard coding configuration information is bad practice, why is it acceptable to hard code semantics?

The Pragmatic Haskeller – Episode 1

Sunday, April 7th, 2013

The Pragmatic Haskeller – Episode 1 by Alfredo Di Napoli.

The first episode of “The Pragmatic Haskeller” starts with:

In the beginning was XML, and then JSON.

When I read that sort of thing, it is hard to know whether to weep or pitch a fit.

Neither one is terribly productive but if you are interested in the rich heritage that XML relies upon drop me a line.

The first lesson is a flying start on Haskell data and moving it between JSON and XML fomats.

The Pragmatic Haskeller

Saturday, April 6th, 2013

Announcing The Pragmatic Haskeller by Alfredo Di Napoli.

From the post:

We are working programmers. Even though we are carried away by the beauty and formalism of functional languages, at the end of the day we still need to get the job done. The Haskell community has been accused during the years of navel gazing, and usually the misconception is that “Haskell is an academic language, but you can’t tackle real world problem with it”.

Despite internet is full of fantastic resources for learning Haskell (including the awesome and recently-released School of Haskell) I wanted to use a peculiar approach: I tried to create a web application in a similar fashion of what I would have done during my everyday job in Scala, to see if I was able to replicate a large subset of the features normally present in my Scala apps. Not only was the experiment a success, but I finally had the chance of experimenting with a lot of cool libraries which were in my “to-play-with-list” for a while. So without further ado I’m happy to announce The Pragmatic Haskeller, a collection of small building blocks for creating a full-fledged webapp:

https://github.com/cakesolutions/the-pragmatic-haskeller

As you might notice, we have a lot of small subfolders. Each folder is a self-contained, working, incremental example experimenting with a new library or technique. Even though you could rush and play with each app all at once, I aim to write a dedicated blog post to each sub-project, introducing the used library, in a similar way of what Oliver Charles did with 24 days of Hackage, with the difference we’ll use the same example episode after episode, until transforming our naive bunch of modules into a complete app.

If the future of big data is with functional programming, where’s yours?

Parallel and Concurrent Programming in Haskell

Saturday, March 30th, 2013

Parallel and Concurrent Programming in Haskell by Simon Marlow.

From the introduction:

While most programming languages nowadays provide some form of concurrent or parallel programming facilities, very few provide as wide a range as Haskell. Haskell prides itself on having the right tool for the job, for as many jobs as possible. If a job is discovered for which there isn’t already a good tool, Haskell’s typical response is to invent a new tool. Haskell’s abstraction facilities provide a fertile ground on which to experiment with different programming idioms, and that is exactly what has happened in the space of concurrent and parallel programming.

Is this a good or a bad thing? You certainly can get away with just one way of writing concurrent programs: threads and locks are in principle all you need. But as the programming community has begun to realise over the last few years, threads and locks are not the right tool for most jobs. Programming with them requires a high degree of expertise even for simple tasks, and leads to programs that have hard-to-diagnose faults.

So in Haskell we embrace the idea that different problems require different tools, and we provide the programmer with a rich selection to choose from. The inevitable downside is that there is a lot to learn, and that is what this book is all about.

In this book I will discuss how to write parallel and concurrent programs in Haskell, ranging from the simple uses of parallelism to speed up computation-heavy programs, to the use of lightweight threads for writing high-speed concurrent network servers. Along the way we’ll see how to use Haskell to write programs that run on the powerful processor in a modern graphics card (GPU), and to write programs that can run on multiple machines in a network (distributed programming).

In O’Reilly’s Open Feedback Publishing System.

If you really want to learn something, write a book about it, edit a book about it or teach a class about it.

Here’s your chance for #2.

Read carefully!

I first saw this in Christophe Lalanne’s A bag of tweets / March 2013.

Purely Functional Data Structures in Clojure: Leftist Heaps

Sunday, February 24th, 2013

Purely Functional Data Structures in Clojure: Leftist Heaps by Leonardo Borges.

From the post:

Last year I started reading a book called Purely Functional Data Structures. It’s a fascinating book and if you’ve ever wondered how Clojure’s persistent data structures work, it’s mandatory reading.

However, all code samples in the book are written in ML – with Haskell versions in the end of the book. This means I got stuck in Chapter 3, where the ML snippets start.

I had no clue about Haskell’s – much less ML’s! – syntax and I was finding it very difficult to follow along. What I did notice is that their syntaxes are not so different from each other.

So I put the book down and read Learn You a Haskell For Great Good! with the hopes that learning more about haskell’s syntax – in particular, learning how to read its type signatures – would help me get going with Puretly Functional Data Structures.

Luckily, I was right – and I recommend you do the same if you’re not familiar with either of those languages. Learn You a Haskell For Great Good! is a great book and I got a lot out of it. My series on Monads is a product of reading it.

Enough background though.

The purpose of this post is two-fold: One is to share the github repository I created and that will contain the Clojure versions of the data structures in the book as well as most solutions to the exercises – or at least as many as my time-poor life allows me to implement.

The other is to walk you through some of the code and get a discussion going. Hopefully we will all learn something – as I certainly have when implementing these. Today, we’ll start with Leftist Heaps.

This sounds like a wonderful resource in the making!

I first saw this at Christophe Lalanne’s A bag of tweets / February 2013.

Hoopl (Dataflow and Haskell)

Monday, January 28th, 2013

Hoopl: Dataflow Optimization Made Simple by Norman Ramsey, João Dias, and Simon Peyton Jones.

Abstract:

We present Hoopl, a Haskell library that makes it easy for compiler writers to implement program transformations based on dataflow analyses. The compiler writer must identify (a) logical assertions on which the transformation will be based; (b) a representation of such assertions, which should form a lattice of finite height; (c) transfer functions that approximate weakest preconditions or strongest postconditions over the assertions; and (d) rewrite functions whose soundness is justified by the assertions. Hoopl uses the algorithm of Lerner, Grove, and Chambers (2002), which can compose very simple analyses and transformations in a way that achieves the same precision as complex, handwritten “super-analyses.” Hoopl will be the workhorse of a new back end for the Glasgow Haskell Compiler (version 6.12, forthcoming).

Superceded by later work but recommended by the authors as a fuller introduction to Hoopl.

The superceding work, Hoopl: A Modular, Reusable Library for Dataflow Analysis and Transformation, has the following abstract:

Dataflow analysis and transformation of control-flow graphs is pervasive in optimizing compilers, but it is typically tightly interwoven with the details of a particular compiler. We describe Hoopl, a reusable Haskell library that makes it unusually easy to define new analyses and transformations for any compiler. Hoopl’s interface is modular and polymorphic, and it offers unusually strong static guarantees. The implementation encapsulates state-of-the-art algorithms (interleaved analysis and rewriting, dynamic error isolation), and it cleanly separates their tricky elements so that they can be understood independently.

I started with the later work. Better read in the order presented here.

PragPub #42, December 2012

Wednesday, December 5th, 2012


PragPub #42, December 2012 as HTML PDF epub mobi

Where you will find:

Web Programming in Haskell, Part One by Paul Callaghan.

The next few articles in this series on the Haskell language will look at web programming via Haskell. Web programming is supported in various ways, from low-level libraries for the basic operations like communicating over http and creation of html documents, up to sophisticated frameworks for building apps and performant web servers for running the apps. January’s article will look at the frameworks, primarily Yesod [U1]. This article will look at Fay [U2], which is a Haskell alternative to CoffeeScript.

Replicating the libraries and frameworks of other languages is not too difficult. The interesting question—following a key theme of this series of articles—is how we can use Haskell’s facilities to improve the experience of web programming. For example, less coding and better maintainability via more powerful abstractions, more safety through using the language style and type system to avoid certain problems, or even improved performance by supporting certain kinds of optimization behind the scenes. Even more interesting is to understand the cases and phenomena where Haskell isn’t enough and where more powerful techniques, like dependent types, might provide additional leverage.

The closer web browsers approach being the default app interface, the more important they become for delivery of topic maps.

This issue of PragPub, as always, has several items you will find interesting.

An upcoming issue will have a Raspberry Pi project.

Enjoy!

Bioinformatics Tools in Haskell

Saturday, September 8th, 2012

Bioinformatics Tools in Haskell by Udo Stenzel.

From the post:

This is a collection of miscellaneous stuff that deals mostly with high-throughput sequencing data. I took some of my throw-away scripts that had developed a life of their own, separated out a library, and cleaned up the rest. Everything is licensed under the GPL and naturally comes without any warranty.

Most of the stuff here is written in Haskell. The natural way to run these programs is to install the Haskell Platform, which may be as easy as running ‘apt-get install haskell-platform‘, e.g. on Debian Testing aka “Squeeze”. Instead, you can install\ the Glasgow Haskell Compiler and Cabal individually. After that, download, unpack and ‘cabal install‘ Biohazard first, then install whatever else you need.

If you don’t want to become a Haskell programmer (you really should), you can still download the binary packages (for Linux on ix86_64) and hope that they work. You’ll probably need to install Gnu MP (‘apt-get install libgmp-dev‘ might do it). If the binaries don’t work for you, I don’t care; use the source instead.

Good for bioinformatics and I suspect for learning Haskell in high-throughput situations.

Speculation: How will processing change when there is only “high-throughput data streams?”

That is there isn’t any “going back” to find legacy data, you just wait for it to reappear in the stream?

Or if there were streams of “basic” data that doesn’t change much along with other data streams that are “new” or rapidly changing data.

If that sounds wasteful of bandwidth, imagine if bandwidth were to increase at the same rate as local storage? So that your incoming data connection is 1 TB or higher at your home computer.

Would you really need local storage at all?

Thinking Functionally with Haskell: Types? Tests? We Need a New Word

Friday, September 7th, 2012

Thinking Functionally with Haskell: Types? Tests? We Need a New Word by Paul Callaghan.

From the post:

In which we explore what modern type systems bring to the table.

Imagine an approach to programming where you write down some description of what your code should do, then before running your code you run some automatic tool to see if the code matches the description. That’s Test-driven development, you say!

Actually, this is what you are doing when you use static types in most languages too. Types are a description of the code’s inputs and outputs, and the check ensures that inputs and outputs match up and are used consistently. Modern type systems—such as in Haskell or above—are very flexible, and allow these descriptions to be quite detailed; plus they are not too obtrusive in use and often very helpful.

One point I’ll investigate here is how advances in types are converging with new ideas on testing, to the point where (I claim) the old distinctions are starting to blur and starting to open up exciting new possibilities—hence my suggestion that we need a new word to describe what we’re doing that is free from preconceptions and out-dated thinking.

So put aside your bad experiences from Java, and prepare to be amazed!

I suppose we should all wish Paul luck on finding words that are “…free from preconceptions and out-dated thinking.”;-)

It has been my experience that “new” words replace “[existing] preconceptions and out-dated thinking,” with “[different] preconceptions and out-dated thinking.”

Not a bad thing but let’s be honest that we are contending for different preconceptions and assumptions as opposed to having none at all.

Has the potential to make us less resistant when some (then) younger programming generation wants to overturn “…preconceptions and out-dated thinking.”

If you haven’t kept up with type theory, you should spend some time with Paul’s post. Maybe suggest a new word or two.

Thinking Functionally with Haskell [Privileging Users or System Designers]

Sunday, August 5th, 2012

Thinking Functionally with Haskell by Paul Callaghan.

From the post:

In which we begin an exploration into the Haskell language and dive deeply into functional programming.

Ever wondered how functional programmers think? I aim to give you a glimpse into the programming style and mindset of experienced functional programmers, so you can see why we are so passionate about what we do. We’ll also discuss some wider ideas about programming, such as making our languages fit the problem and not the other way round, and how this affects language design.

Few of these ideas get the exposure they deserve in textbooks or tutorials, and in my view they are essential for coming to grips with a functional language and using it productively in real apps.

Syntax and semantics, the meat and veg of most books and university courses, are ok for basic language use, but to really master a language that embodies a paradigm that is new to you, you need to know about the deeper pragmatic ideas. Let’s see if we can do something about that.

I used Lisp for a few years before university, then switched to Haskell and have been using it for around 20 years. However, inspired by learning about Rails and Ruby when revamping a tired web technology course, I changed career to do full-time Rails work, and have spent the last four years having fun on a variety of apps, including Spree (#2 committer at one point) and recently a big bespoke lab management system.

Ruby feels like naughty fun for a Haskell programmer. Many of the ideas are very similar, like the very natural use of blocks and lambdas and having lots of scope for bending the rules. I really enjoy programming in Ruby, though some times I do get homesick and pine for a bit more oomph.

Most of this article will refer to Haskell, though many of the ideas do apply to other, similar languages as well. Haskell has a few advantages and a good balance of features. Haskell has its weaknesses too, and I hope to explore these in due course.

I rather like the “…making our languages fit the problem and not the other way round…” phrase.

Or to phrase it for topic maps: “….taking subject identity as defined by users, not defining it for them….”

Perhaps I should ask: Do you want to privilege users or system designers?

Graph-rewriting Package

Saturday, August 4th, 2012

Graph-rewriting Package

A Haskell based graph rewriting package I encountered recently.

You can find more information at Jon Rachel’s webpage. And the Wikipedia page on graph rewriting. (The Wikipedia page also has pointers to a number of graph rewriting software packages.)

For the definition of port graph grammars, see Charles Stewart, Reducibility Between Classes of Port Graph Grammar (2001).

Solving the Queens Problem with Haskell

Monday, February 20th, 2012

Solving the Queens Problem with Haskell

From the post:

The eight queens puzzle is a classic problem in algorithm design because it showcases the power of backtracking and recursion. The premise is simple: find a way to place 8 queens on an 8×8 board such that none of them are attacking each other, which means that no two queens can share the same row, column, or diagonal.

Sounds simple enough, but how to implement it? The most basic solution would be to brute force it: try every possible configuration, stopping when a valid one is found. Not very efficient, but hey, at least it’s easy to understand.

A good illustration of recursion and backtracking but also suggests that brute force isn’t the best option for authoring or manipulating topic maps.

A deep understanding of your data, relevant subjects, methods for identifying those subjects, etc., will be more useful than brute force.

Haskell – New Release

Monday, December 26th, 2011

Haskell – New Release

Current stable release: 2011.4.0.0 (December 2011) – Download today!

Translating math into code with examples in Java, Racket, Haskell and Python

Sunday, December 4th, 2011

Translating math into code with examples in Java, Racket, Haskell and Python by Matthew Might.

Any page that claims Okasaki’s Purely Functional Data Structures as an “essential reference” has to be interesting.

And…, it turns out to be very interesting!

If I have a complaint, it is that it ended too soon! See what you think.

“Value polymorphism”, simple explanation with examples

Monday, October 17th, 2011

“Value polymorphism”, simple explanation with examples

At first I thought this would be a post that would interest only one topic map person that I know. But upon reading the entire post, I decided it might interest two.

What pushed me over the edge was:

Thus by merely specifying the return type we have effectively generated a parser. An invalid string will produce an error:

That is a very powerful mechanism to use with processing values returned in processing a topic map (or data about to be included in a topic map).

Hoogle

Tuesday, October 11th, 2011

Hoogle

From the webpage:

Hoogle is a Haskell API search engine, which allows you to search many standard Haskell libraries by either function name, or by approximate type signature.

[example searches omitted]

The Hoogle manual contains more details, including further details on search queries, how to install Hoogle as a command line application and how to integrate Hoogle with Firefox/Emacs/Vim etc.

Just in case you missed the reference in our post on Scalex (a similar interface for Scala).

Oh, Hoogle enables searching by “…function name, or by approximate type signature.”

What other searches you would like to perform?

How would you implement those searches? (by what kind of indexing including software to be used) Care to do that as a project to contribute back to the community?

Do you think topic maps could improve this resource? In what way?

Deterministic Parallel Programming in Haskell

Friday, October 7th, 2011

Deterministic Parallel Programming in Haskell by Andres Löaut;h (pdf)

The bundle for the tutorial with slides, source code and exercises: http://www.well-typed.com/Hal6/Hal6.zip.

Very interesting slide deck on parallel programming in Haskell but you will also learn about parallelism in general.

Whether needed or not, you have to admit it is a current marketing phrase.

Write Yourself a Scheme in 48 Hours

Monday, October 3rd, 2011

Write Yourself a Scheme in 48 Hours

From the webpage:

Most Haskell tutorials on the web seem to take a language-reference-manual approach to teaching. They show you the syntax of the language, a few language constructs, and then have you construct a few simple functions at the interactive prompt. The “hard stuff” of how to write a functioning, useful program is left to the end, or sometimes omitted entirely.

This tutorial takes a different tack. You’ll start off with command-line arguments and parsing, and progress to writing a fully-functional Scheme interpreter that implements a good-sized subset of R5RS Scheme. Along the way, you’ll learn Haskell’s I/O, mutable state, dynamic typing, error handling, and parsing features. By the time you finish, you should be fairly fluent in both Haskell and Scheme.

Functional programming is gaining ground. Are you?

Parallel Haskell Tutorial: The Par Monad [Topic Map Profiling?]

Monday, October 3rd, 2011

Parallel Haskell Tutorial: The Par Monad

Parallel programming will become largely transparent at some point but not today. ;-)

Walk through parallel processing of Sudoku and k-means, as well as measuring performance and debugging. Code is available.

I think the debugging aspects of this tutorial stand out the most for me. Understanding a performance issue as opposed to throwing resources at it seems like the better approach to me.

I know that a lot of time has been spent by the vendors of topic maps software profiling their code, but I wonder if anyone has profiled a topic map?

That is we make choices in terms of topic map construction, some of which may result in more or less processing demands, to reach the same ends.

As topic maps grow in size, the “how” a topic map is written may be as important as the “why” certain subjects were represented and merged.

Have you profiled the construction of your topic maps? Comments appreciated.

What resources & practices (teaching Haskell) [or learning n]

Monday, October 3rd, 2011

What resources & practices (teaching Haskell)

Clifford Beshers answers (in part, the most important part):

I have two recommendations: teach them the simplest definitions of the fundamentals; read programs with them, out loud, like children’s books, skipping nothing.

The second one, reading aloud, is one that I have advocated for standards editors. Mostly because it helps you slow down and not “skim” text that you already “know.”

And the same technique can be applied for self-study of any subject, whether it is Haskell, some other programming language, mathematics, or some other domain.

Let’s make an Elemental Type System in Haskell – Part I

Sunday, October 2nd, 2011

Let’s make an Elemental Type System in Haskell – Part I

From the post:

recently I falled in love (again) with Haskell, and I’ve decided to start a simple toy project just to stretch my Haskell muscles fibers.

Meanwhile, I’ve started Final Fantasy VII again, so I thought to realize a simple Elemental Type System. I dunno how much this project will be complex, but a lot of fun awaits.

By post three (3) the author changes the name to …Elemental Battle System….

Same series.

To put a topic map cast (shadow?) on this adventure think about the creatures, places, events and players as all having identities. Identities that we want to manage in a topic map. Their properties change during the game. So we need to update the topic map, but how often? Does a player “identity” change if they die?

Perhaps not from a system perspective but what about in the game? Or in the view of other players? Assume those differing “views” are also subjects that we want to represent. How do we manage game subjects as they move in and out of those “views?”


Other posts in this series are:

Let’s make an Elemental Type System in Haskell – Part II
Let’s make an Elemental Battle System in Haskell – Part III
Players are coming next.

The HasGP user manual

Monday, September 26th, 2011

The HasGP user manual (pdf)

Abstract:

HasGP is an experimental library implementing methods for supervised learning using Gaussian process (GP) inference, in both the regression and classification settings. It has been developed in the functional language Haskell as an investigation into whether the well known advantages of the functional paradigm can be exploited in the field of machine learning, which traditionally has been dominated by the procedural/object-oriented approach, particularly involving C/C++ and Matlab. HasGP is open-source software released under the GPL3 license. This manual provides a short introduction on how install the library, and how to apply it to supervised learning problems. It also provides some more in-depth information on the implementation of the library, which is aimed at developers. In the latter, we also show how some of the specific functional features of Haskell, in particular the ability to treat functions as first-class objects, and the use of typeclasses and monads, have informed the design of the library. This manual applies to HasGP version 0.1, which is the initial release of the library.

HasGP website

What a nice surprise for a Monday morning, something new and different (not the same thing). Just scanning the pages before a conference call I would say you need to both read and forward this to your Haskell/Gaussian friends.

Comes with demo programs. Release 0.1 so it will be interesting to see what the future holds.

The project does need a mailing list so users can easily discuss their experiences, suggestions, etc. (One may already exist but isn’t apparent from the project webpage. If so, apologies.)

Writing a Simple Keyword Search Engine Using Haskell and Redis

Saturday, June 11th, 2011

Writing a Simple Keyword Search Engine Using Haskell and Redis

Alex Popescu says this is a good guide to “…translat[ing] logical operators in Redis set commands” which is true, but it is also an entertaining post on writing a search engine.

Natural Language Processing for the Working Programmer

Saturday, April 30th, 2011

Natural Language Processing for the Working Programmer

Daniël de Kok and Harm Brouwer have started a book on natural language processing using Haskell.

Functional programming meets NLP!

A work in progress so I am sure the authors would appreciate comments, suggestions, etc.

BTW, there is a blog, ? Try ?t H?ske?? in ?inguistics with posts working through the book.

The Haskell Road to Logic, Math and Programming [pdf]

Monday, January 3rd, 2011

The Haskell Road to Logic, Math and Programming [pdf] Authors: Kees Doets and Jan van Eijck

A detailed review can be found at: Book review “The Haskell Road to Logic, Maths and Programming” by Ralf Laemmel.

There are so many “cell phone dead zones” as Newcomb puts it when dealing with semantics that any assistance in clear thinking is welcome.

This is a work the promotes clear thinking.