News aggregator

Comonads are objects

Haskell on Reddit - Thu, 02/14/2013 - 10:41am
Categories: Incoming News

Theory Lunch (Institute of Cybernetics, Tallinn): The Constraint kind

Planet Haskell - Thu, 02/14/2013 - 10:24am

I talked about the Constraint kind, a recent addition to Haskell. There is a write-up of my talk on my personal blog.


Categories: Offsite Blogs

Wolfgang Jeltsch: The Constraint kind

Planet Haskell - Thu, 02/14/2013 - 10:19am

A recent language extension of the Glasgow Haskell Compiler (GHC) is the Constraint kind. In this blog post, I will show some examples of how this new feature can be used. This is a write-up of my Theory Lunch talk from 7 February 2013. The source of this article is a literate Haskell file, which you can download and load into GHCi.

Prerequisites

The example code in this article needs support for the Constraint kind, of course. So we have to enable the appropriate language extension (which is surprisingly called ConstraintKinds instead of ConstraintKind). Furthermore, we want to make use of type families. All in all, this leads to the following LANGUAGE pragma:

{-# LANGUAGE ConstraintKinds, TypeFamilies #-}

We will define our own version of the Monad class. Therefore, we have to hide the Monad class from the Prelude:

import Prelude hiding (Monad (..))

We will need the module Data.Set from the containers package for some example code:

import Data.Set

Last, but not least, we have to import the kind Constraint:

import GHC.Exts (Constraint) The general picture

Originally, classes and contexts were not first-class citizens in Haskell. The introduction of the Constraint kind has changed this. Classes and contexts can now be used as parameters of types, for example. This is because they are now types themselves.

However, classes and contexts are still not types in the strict sense. There are still no values of type Eq or Eq Integer, for example. As I have explained in my previous post, Haskell’s notion of type is more general than the usual one. In particular, functions on types are types themselves. However, they are not types of kind *. The same holds for classes and contexts. They are not types of kind *, but they are types of some other kinds, so that they can generally be used in places where types can be used.

The new kind Constraint, which is exported by GHC.Exts, is the kind of all contexts. Classes and contexts are now handled as follows:

  • Each class with parameters of kinds k_1 through k_n is a type of kind k_1 -> k_n -> Constraint.

  • Each tuple type (t_1, ..., t_n) where t_1 through t_n are of kind Constraint is also of kind Constraint and denotes the conjunction of t_1 through t_n. As a corner case, the nullary tuple type () is also of type Constraint and denotes the constraint that is always true.

  • A context can be any type of kind Constraint.

These rules guarantee that classes and contexts can be used as before. For example, (Read val, Show val) is still a context, because Read and Show are types of kind * -> Constraint, so Read val and Show val are types of kind Constraint, and therefore (Read val, Show val) is a type of kind Constraint.

However, classes and constraints can be used in new ways now. Here are some examples:

  • Classes can be partially applied, and the results can be used like classes again.

  • Classes, partially applied classes, and contexts can be parameters of types and instances of classes.

  • Aliases of classes, partially applied classes, and contexts can be defined using type declarations.

  • Families of classes, partially applied classes, and contexts can be defined using type synonym families.

In the remainder of this article, I will illustrate the last two of these points.

Context aliases

Sometimes, the same conjunction of several contexts appears in multiple types. In such cases, it can become cumbersome to always write these conjunctions explicitly. For example, there might be several functions in a library that deal with values that can be turned into strings and generated from strings. In this case, the types of these functions will typically have a context that contains constraints Show val and Read val. With the Constraint kind, we can define context aliases Text val as follows:

type Text val = (Show val, Read val)

Instead of Show val, Read val, we can now simply write Text val in contexts.

A few years ago, there was an attempt to implement support for context aliases (often called class aliases) in GHC. With the Constraint kind, this is now obsolete, as context aliases are now just a special kind of type aliases.

Context families

We will illustrate the use of context families by defining a generalized version of the Monad class.

The actual definition of a monad from category theory says that a monad on a category 

Categories: Offsite Blogs

Is there any documentation for HaskellDB 2.2.2

Haskell on Reddit - Thu, 02/14/2013 - 9:20am

I've hunted for a while but I have literally no idea how to do anything with the latest HaskellDB. There's basically no docs or examples on Hackage showing how I can start using it with an existing database. Help please?

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

ANNOUNCE: graphviz-2999.16.0.0

General haskell list - Thu, 02/14/2013 - 6:54am
I'm pleased to announce that I've finally tracked down all the pesky little bugs that prevented me from releasing version 2999.16.0.0 of my graphviz library, that helps you use the Graphviz suite of tools to visualise graphs. The important changes are: * Add support for Graphviz-2.30.0: - New attributes: + `Area` + `Head_LP` + `LayerListSep` + `LayerSelect` + `Tail_LP` + `XLP` - `BgColor`, `Color` and `FillColor` now take a list of colors with optional weightings. - Layer handling now supports layer sub-ranges. - Added the voronoi-based option to `Overlap`. - Added the `Striped` and `Wedged` styles. * Updates to attributes and their values: - The following attributes have had their values changed to better reflect what they represent: + `FontPath` takes a `Path` value. + `Layout` takes a `GraphvizCommand` (and thus `GraphvizCommand` has been moved to `Data.GraphViz.Attributes.Co
Categories: Incoming News

I/O is Pure - Chris Taylor

del.icio.us/haskell - Thu, 02/14/2013 - 4:50am
Categories: Offsite Blogs

Photoshop 1.0 Source Code

Lambda the Ultimate - Thu, 02/14/2013 - 3:57am

Some people are amazed that it's in Pascal... HN discussion is here.

Categories: Offsite Discussion

Haskell Weekly News: Issue 258

General haskell list - Thu, 02/14/2013 - 3:17am
Welcome to issue 258 of the HWN, an issue covering crowd-sourced bits of information about Haskell from around the web. This issue covers the week of February 03 to 09, 2013. Quotes of the Week * shachaf: The trouble with the lens rabbit hole is that there are a few of us here at the bottom, digging. * monochrom: "a monad is like drinking water from a bottle without human mouth touching bottle mouth" Top Reddit Stories * GHCi 7.4.2 is finally working on ARM Domain: luzhuomi.blogspot.com, Score: 49, Comments: 15 On Reddit: [1] http://goo.gl/yBh9o Original: [2] http://goo.gl/Kgx9R * Implementation of a Java Just In Time Compiler in Haskell Domain: blog.wien.tomnetworks.com, Score: 41, Comments: 15 On Reddit: [3] http://goo.gl/BjpX3 Original: [4] http://goo.gl/f1Qrh * I/O is pure Domain: chris-taylor.github.com, Score: 32, Comments: 41 On Reddit: [5] http://goo.gl/pYMXz Original: [6] http://goo.gl/9xeKd * Introduction to Has
Categories: Incoming News

Haskellの単体テスト最前線

Haskell on Reddit - Thu, 02/14/2013 - 12:12am
Categories: Incoming News

How to quantify the overhead?

haskell-cafe - Thu, 02/14/2013 - 12:06am
Before I write the code I like to be able to quantify my expected result. But I am having hard time quantifying my expected result for alternative approaches in Haskell. I would appreciate any comments from experienced Haskell-ers on this problem: Suppose I have a big list of integers and I like to find the first two that add up to a number, say 10. One approach is to put the numbers in the map as I read them and each step look for the 10-x of the number before going on to the next value in the list. Alternatively, I am trying to see if I it make sense to covert the list to a series of computations that each is looking for the 10-x in the rest of the list (running them in breath first search). I like to find out sanity of using the Applicative/Alternative class's (<|>) operator to set up the computation. So each element of the list (say x) is recursively converted to a computation to SearchFor (10 - x) that is (<|>)-ed with all previous computation until one of the computations returns the pair
Categories: Offsite Discussion

deprecation rage :: hpaste

Haskell on Reddit - Wed, 02/13/2013 - 9:09pm
Categories: Incoming News

Haskell Weekly News: Issue 258

Haskell on Reddit - Wed, 02/13/2013 - 7:17pm
Categories: Incoming News

Free lunch with GADTs

haskell-cafe - Wed, 02/13/2013 - 7:01pm
Hi cafe, I'm playing around with GADTs and was hoping they would let me have my cake and eat it too. I am trying to use GADTs to tag a type with some extra information. This information is very useful in a few cases, but the more common case is that I just have a list of items without the tags. Ideally I'll be able to recover the tags from the common case via pattern matching. What I have right now is: {-# LANGUAGE GADTs, ExistentialQuantification, EmptyDataDecls, RankNTypes, LiberalTypeSynonyms #-} data Tag1 data Tag2 data T tag where T1 :: Int -> T Tag1 T2 :: Double -> T Tag2 f1 :: [T t] -> Int f1 = foldr worker 0 where worker (T1 i) a = i+a worker _ a = a f2 :: [T Tag1] -> Int f2 = foldr worker 0 where worker :: T Tag1 -> Int -> Int worker (T1 i) a = a + i In f2 I can work with just values with one tag, but f1 is also important to me (working with the untagged values). f1 type checks but I do not know how to make a list [T t]. If I try the naive thing in ghci, it un
Categories: Offsite Discussion

searching the attic for lambada

haskell-cafe - Wed, 02/13/2013 - 4:16pm
I'm interested in resurrecting the idl generator from lambada: http://www.dcs.gla.ac.uk/mail-www/haskell/msg02391.html is the code out there in anyone's attic?
Categories: Offsite Discussion

Call for Papers (ICFEM 2013)

General haskell list - Wed, 02/13/2013 - 12:02pm
ICFEM 2013 CALL FOR PAPERS 15th International Conference on Formal Engineering Methods (ICFEM 2013) Queenstown, New Zealand, 29 October - 1 November 2013 http://www.cs.auckland.ac.nz/icfem2013/ The 15th International Conference on Formal Engineering Methods (ICFEM 2013) will be held at the Crowne Plaza Hotel in Queenstown, New Zealand from 29 October to 1 November 2013. Since 1997, ICFEM has been serving as an international forum for researchers and practitioners who have been seriously applying formal methods to practical applications. Researchers and practitioners, from industry, academia, and government, are encouraged to attend, and to help advance the state of the art. We are interested in work that has been incorporated into real production systems, and in theoretical work that promises to bring practical and tangible benefit. ICFEM 2013 is organized and sponsored by The University of Auckland and will be held in the world renowned travel destination - Queenstown. Around 1.9 m
Categories: Incoming News

optimization of recursive functions

haskell-cafe - Wed, 02/13/2013 - 10:55am
Hello, Is there any difference in efficiency between these two functions, when compiled with all optimizations? map f [] = [] map f (a:as) = f a : map f as and map f x = map' x where map' [] = [] map' (a:as) = f a : map' as Thanks, Andrew _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

jgm/pandoc - GitHub

del.icio.us/haskell - Wed, 02/13/2013 - 7:47am
Categories: Offsite Blogs

Structured Graphs

haskell-cafe - Wed, 02/13/2013 - 6:16am
What are the prospects for Haskell supporting Structured Graphs as defined here? http://www.cs.utexas.edu/~wcook/Drafts/2012/graphs.pdf Is there an interest by developers of GHC in doing this? -John_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion