News aggregator

Reducing boilerplate

haskell-cafe - Sat, 03/05/2016 - 3:56pm
Hi, To write FFI bindings, I use c-storable-deriving [1] to automatically derive CStorable instances for many data types (the only difference between Storable and CStorable is that CStorable provides default methods for types that have Generic instances): {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveAnyClass #-} ... data X = X { fieldStatus :: Vector 24 Word8 , fieldPadding :: Word8 } deriving (Generic, CStorable) However I also need a Storable instance, hence I have to write (the "c*" methods are provided by CStorable): instance Storable X where peek = cPeek poke = cPoke alignment = cAlignment sizeOf = cSizeOf Is there a way to automatically generate this instance for every data that has an instance of CStorable? Ideally, I would like to say once and for all: instance CStorable a => Storable a where peek = cPeek poke = cPoke alignment = cAlignment sizeOf = cSizeOf As I don't think it is currently possible, w
Categories: Offsite Discussion

Digraphs With Text: More flexible than graphs,eager to hear from you

haskell-cafe - Sat, 03/05/2016 - 10:06am
This is a demonstration of DWT, a data structure built from and more flexible than graphs. It is powered by the *wonderful* Functional Graph Library. We beseech your involvement! DWT is open-source and actively seeking co-developers. I would happily trade any and all the privilege of determining tasks, teaching haskell or math, learning anything, and receiving obligations. We surely have much knowledge to trade! Even just a "hey why don't you do [this]!" could be precious to me. This transcript makes tiny digressions about what monads make possible. graph). (0,"0: frog") that expression. None do, because none yet exist. Such contexts offer many possibilities for tracking where you are (the data) and how you got there (also kind of the data, and perhaps enabling a desirable kind of removal of self|redaction). (0,"0: frog") (0,"1: moist") (0,"2: springy") (0,"0: frog") (0,"1: moist") (0,"2: springy") (0,":3 _ #(is a quality of) _") a : to indicate that it is a template, as opposed to the string "_ is a qual
Categories: Offsite Discussion

Accuracy of Data.Number.Fixed

haskell-cafe - Sat, 03/05/2016 - 5:50am
This does not seem right to me: Prelude Data.Number.Fixed> read "4.00" :: Fixed (EpsDiv10 (EpsDiv10 Eps1)) 4.00 Prelude Data.Number.Fixed> read "4.01" :: Fixed (EpsDiv10 (EpsDiv10 Eps1)) 4.00 Prelude Data.Number.Fixed> read "4.02" :: Fixed (EpsDiv10 (EpsDiv10 Eps1)) 4.03 Prelude Data.Number.Fixed> read "4.03" :: Fixed (EpsDiv10 (EpsDiv10 Eps1)) 4.04 Prelude Data.Number.Fixed> read "4.04" :: Fixed (EpsDiv10 (EpsDiv10 Eps1)) 4.05 Maybe I am misunderstanding the purpose of this library. I guess that "two digits" of precision means that it is accurate within +/- 0.01? I think that this library is meant for doing arbitrary-precision transcendental operations. But it would not be good as a model for something like currency. It's using ratios as an internal representation, and I'm not sure what ratios it's choosing, but I think I'd choose, say, 401/100 for the "4.01" representation. I guess it's picking a slightly smaller factor than that. The non-reversibility of read/show is somewhat disconcerting. I think I
Categories: Offsite Discussion

Call for Participation: PLACES 2016

General haskell list - Fri, 03/04/2016 - 6:50pm
--------------------------------------------------------- Call for participation: 9th Workshop on Programming Language Approaches to Concurrency- and Communication-cEntric Software Friday 8th April 2016 Co-located with ETAPS 2016, Eindhoven, The Netherlands --------------------------------------------------------- For more information: --------------------------------------------------------- Modern hardware platforms, from the very small to the very large, increasingly provide parallel computing resources for applications to maximise performance. Many applications therefore need to make effective use of tens, hundreds, and even thousands of compute nodes. Computation in such systems is thus inherently concurrent and communication centric. Effectively programming such applications is challenging; performance, correctness, and scalability are difficult to achieve. Various programming paradigms and methods have emerged to aid this task. The
Categories: Incoming News

HasCallStack - runtime costs?

haskell-cafe - Fri, 03/04/2016 - 4:53pm
Dear Cafe, the new (8.*) call stack feature is certainly nice for debugging during development. But how costly is it at runtime? I notice a 5 percent slowdown. That's not a problem if there's an easy way to switch this off for production (without changing the code). Related: how to make code that uses it, compile with older ghcs that don't have it. I made this hack: do not import GHC.Stack.Types, but instead {-# language CPP, MultiParamTypeClasses #-} #if (__GLASGOW_HASKELL__ < 710) {-# language NullaryTypeClasses #-} #endif module Stack ( HasCallStack ) where #if (__GLASGOW_HASKELL__ >= 800) import GHC.Stack.Types #else class HasCallStack instance HasCallStack #endif When I compile with 8.rc2, and change ">= 800" to ">= 900", I am getting the 5 percent speedup mentioned above. But does it really do what I hope it does (remove all runtime overhead that call stacks may have)? When I compile with 7.10.
Categories: Offsite Discussion

Month in Haskell Mode February 2016

haskell-cafe - Fri, 03/04/2016 - 4:49pm
Welcome Haskell Mode users, Haskell Mode progress report for February 2016. For previous issue see January 2015 <> . Reddit discussion <> . <>What is Haskell Mode? Haskell Mode is an umbrella project for multiple Emacs tools for efficient Haskell development. Haskell Mode is an open source project developed by a group of volunteers constantly looking for contributions. For more information how to help see <>Important developments Fontification received improvements so that it closer follows Haskell lexical rules. It was necessary to change to syntax-propertize-function available only starting with Emac
Categories: Offsite Discussion

Test email

libraries list - Thu, 03/03/2016 - 7:54pm
Please disregard -- sorry for the noise. Gershom
Categories: Offsite Discussion

Order of Map.fromListWith

haskell-cafe - Thu, 03/03/2016 - 7:23pm
Does anybody know why for fromListWith, the arguments to the combining function seem flipped? > import Data.Map > fromListWith (++) [('a',[1]),('a',[2])] fromList [('a',[2,1])] I often use it to group things by some key, e.g. postsByUserId :: Map Int [Int] postsByUserId = fromListWith (++) [ (userId, [postId]) | (userId, postId) <- posts ] and regularly get tricked by the postIds being reversed in the result. This is especially unintuitive to me since: > foldl (++) [] [[1],[2]] [1,2] > foldr (++) [] [[1],[2]] [1,2] Any ideas?
Categories: Offsite Discussion

Function that put elements in Left or Right side ofEither depending on type

haskell-cafe - Thu, 03/03/2016 - 5:04pm
I want a function fun :: q -> Either a b where q is of type a or b. fun shall work in the following way fun x gives Left x if x :: a fun x gives Right x if x :: b Following is a more precise description of what I want. I have function fun1 and fun2 newtype Vec k b = V [(b,k)] deriving (Eq,Ord,Show) fun1 :: (Num k) => a -> Either a (Vec k a) fun1 = Left fun2 :: (Num k) => Vec k a -> Either a (Vec k a) fun2 = Right that work in the following way {- Left 6 Right (V [(6,1)]) -} I want a overloaded function ‘fun' such that {- Left 6 Right (V[(6,1)]) -} I have tried to use a type class to do this (see code below). But when I try I get the following error Could not deduce (Num a0) from the context (Num a, Fun a b v) bound by the inferred type for ‘it’: (Num a, Fun a b v) => Either b (v b) at <interactive>:70:1-5 The type variable ‘a0’ is ambiguous When checking that ‘it’ has the inferred type it :: forall a b (v :: * ->
Categories: Offsite Discussion

apfelmus: FRP — Video of my Talk at Bobkonf 2016

Planet Haskell - Thu, 03/03/2016 - 3:17pm

Two weeks ago, I had the pleasure of attending the BOB Konferenz 2016 in Berlin, Germany, where I gave an introductory talk on functional reactive programming (FRP) in english. The talk was videotaped and the recording is now available online. So, if you like to hear a short introduction from me on what FRP is all about, and why it’s a good idea, I invite you to have a look. Slides are available, too.

The purpose of the conference was to bring together

[…] developers, architects and builders to explore technologies beyond the mainstream and to discover the best tools available today for building software.

My favorite talks were the presentation by Andres Löh on the Servant library, which allows the specification of REST APIs in the type system and eliminates a lot of boilerplate, and the talk by Stefan Wehr on the Swift language (that new language by Apple), where he demonstrated that functional programming actually has already become mainstream.

Categories: Offsite Blogs

LambdaCube: Tuples as heterogeneous lists

Planet Haskell - Thu, 03/03/2016 - 2:42pm

You probably know that lists and tuples are in no way special data types in Haskell. They are basically the following ADTs (algebraic data types) with special syntax:

data List a -- syntax in type context: [a] = Nil -- syntax in expression context: [] | Cons a (List a) -- syntax in expression context: (a : as) data Tuple2 a b -- syntax in type context: (a, b) = Tuple2 a b -- syntax in expression context: (a, b) data Tuple3 a b c -- syntax in type context: (a, b, c) = Tuple3 a b c -- syntax in expression context: (a, b, c) data Tuple4 a b c d -- syntax in type context: (a, b, c, d) = Tuple4 a b c d -- syntax in expression context: (a, b, c, d) ...

All right, but what exactly does that ... mean at the end? Do infinite tuples exist? Or at least, are there infinitely many tuples with different arities? In the case of GHC the answer is no, and this is very easy to demonstrate. Try to enter this tuple in ghci:

GHCi, version 7.10.3: :? for help Prelude> (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) <interactive>:2:1: A 63-tuple is too large for GHC (max size is 62) Workaround: use nested tuples or define a data type

Although this seems reasonable, those who strive for perfection are not satisfied. What is the right solution for this problem? What is the real problem by the way?

I consider the Tuple2, Tuple3, Tuple4, … ADT family an inferior representation of tuples because of the following reasons:

  1. There is this ugly … at the end with several consequences.
  2. This family has no proper beginning. We can define both Tuple0 and Tuple1, but one-element tuples are not yet embraced by the Haskell community.
  3. Tuples with different arities are not related to each other, because they are defined separately, not at once as one data family. One consequence of this is that it is not possible to write generic functions for tuples.

What would be a better representation of tuples? Heterogeneous lists, of course!

data HList :: List Type -> Type where HNil :: HList 'Nil HCons :: forall t ts . t -> HList ts -> HList ('Cons t ts)

Some examples:

HNil :: HList 'Nil HCons True HNil :: HList ('Cons Bool 'Nil) HCons 3 (HCons True HNil) :: HList ('Cons Int ('Cons Bool 'Nil)

The syntactic sugar for heterogeneous lists could be the same as for tuples, for example

() ==> HNil -- in expression context () ==> HList 'Nil -- in type context (3, True) ==> HCons 3 (HCons True HNil) -- in expression context (Int, Bool) ==> HList ('Cons Int ('Cons Bool 'Nil) -- in type context

What are the issues of representing tuples by heterogeneous lists?

  1. There is a thing called one-element tuple, which needs explicit syntax.
  2. We need some type system extensions (at least GADTs and type level lists are needed).
  3. The compiler backend has to be a little bit smarter to produce efficient code for tuples.
  4. Pattern matching on tuples is not obvious anymore.

The LambaCube 3D compiler solves the above issues the following way:

  1. One element tuples are denoted by (( element )).
  2. The compiler has a dependently typed core language, therefore defining and using the HList data type works out-of-the-box.
  3. Currently the compiler has no code generator for CPUs and it has only a limited code generator for GPUs with no support for tuples. Tuples either vanish during reduction, or they are transformed away in the shader code generator.
  4. Pattern matching on heterogeneous lists is restricted: when a tuple is matched, all patterns should have the same tuple arity. We’re okay with this, since this behaviour is not surprising for most programmers, and in LambdaCube 3D code tuple patterns tend to appear without alternative choices anyway.

After solving these issues, and migrating to the new representation of tuples, the built-in LambdaCube 3D library could be simplified significantly.

Some examples: previously we had repetitive, incomplete and potentially wrong functions for tuples like

type family JoinTupleType t1 t2 where JoinTupleType a () = a JoinTupleType a (b, c) = (a, b, c) JoinTupleType a (b, c, d) = (a, b, c, d) JoinTupleType a (b, c, d, e) = (a, b, c, d, e) JoinTupleType a b = (a, b) -- this is wrong if b is a 5-tuple! -- JoinTupleType a ((b)) = (a, b) -- something like this would be OK remSemantics :: ImageSemantics -> Type remSemantics = ... -- definition is not relevant now remSemantics_ :: [ImageSemantics] -> Type remSemantics_ [] = '() remSemantics_ [a] = remSemantics a -- not good enough... -- remSemantics_ [a] = '((remSemantics a)) -- something like this would be OK remSemantics_ [a, b] = '(remSemantics a, remSemantics b) remSemantics_ [a, b, c] = '(remSemantics a, remSemantics b, remSemantics c) remSemantics_ [a, b, c, d] = '(remSemantics a, remSemantics b, remSemantics c, remSemantics d) remSemantics_ [a, b, c, d, e] = '(remSemantics a, remSemantics b, remSemantics c, remSemantics d, remSemantics e)

With heterogeneous lists as tuples these and similar functions shrank considerably:

type family JoinTupleType a b where JoinTupleType x (HList xs) = HList '(x: xs) remSemantics_ :: [ImageSemantics] -> Type remSemantics_ ts = 'HList (map remSemantics ts)

By the way, with heterogeneous lists it was also easier to add row polymorphism (one solution for generic records) to the type system, but that is a different story.

The pattern matching issue deserves a bit more detail. Why is it a good idea to restrict pattern matching for heterogeneous lists? Well, consider the following function with no type annotation:

swap (a, b) = (b, a)

Of course we expect the compiler to infer the type of swap. On the other hand, if tuples are heterogeneous lists, the following function is also typeable:

f (_, _) = 2 f (_, _, _) = 3 f _ = 0

It seems that type inference is not feasible for heterogeneous lists in general. For LambdaCube 3D we settled with above mentioned restriction in order to retain type inference. It seems feasible to create a system that allows the definition of f with a type annotation, but this would not buy much for the users of LambdaCube 3D so we didn’t go for it.

I have found a few implementations of heterogeneous lists in Haskell, Idris and Agda. So far I have not found a language where tuples are represented with heterogeneous lists, neither a language with special syntax for heterogeneous lists.

  1. HVect in reroute package is the same as HList.
  2. HVect in hvect package is a strict variant of HList.
  3. Tuples in Idris are different: (x, y, z) is a synonym for (x, (y, z)). On the other hand, HVect in the standard library is similar to HList. The difference is that the type level list is indexed by its length. I have found this discussion about whether tuples could be represented with HVect. It seems that efficient code generation is the difficult part.
  4. I have found an implementation of HList and HVec in Agda. However, I also found this discussion about size problems, so it is not so convenient to use them. We don’t have such issues because we use type-in-type.
  5. gives a summary about implementing heterogeneous collections in Haskell. Heterogeneous lists are at the bottom (see next item).
  6. Strongly typed heterogeneous collections by Oleg Kiselyov has a more complicated implementation of heterogeneous lists in Haskell using less type system extensions.

To sum it up, in the case of LambdaCube 3D, representing tuples as heterogeneous lists has no drawback and at the same time the base library (which provides the OpenGL binding) became more complete, shorter and more correct. We definitely consider switching to this representation an overall win.

Categories: Offsite Blogs

Neil Mitchell: Compiling GHC on Windows

Planet Haskell - Thu, 03/03/2016 - 2:20pm

Summary: How to compile GHC on Windows using Stack and the new Shake-based GHC build system.

Here are a list of instructions to compile GHC, from source, on Windows. I tested these instructions on a clean machine using the free Windows 10 VirtualBox image (I bumped the VM CPUs to 4, and RAM to 4096Mb).

The first step is to install Stack (I just accepted all the defaults), then open a command prompt and run:

stack setup
stack install happy alex
stack exec -- pacman -S gcc binutils git automake-wrapper tar make patch autoconf --noconfirm
stack exec -- git clone --recursive git://
cd ghc
stack exec -- git clone git:// shake-build
stack build --stack-yaml=shake-build/stack.yaml --only-dependencies
stack exec -- perl boot
stack exec -- bash configure --enable-tarballs-autodownload
stack exec --stack-yaml=shake-build/stack.yaml -- shake-build/build.bat -j

The entire process (after the VM has downloaded) takes a bit less than an hour. These steps use the Stack supplied tools (MinGW, Git), and the new Shake-based build system. The hope is that by using the isolation Stack provides, combined with the portability improvements from writing the build system in Haskell, these instructions will work robustly on many Windows machines.

I have not tried these instructions on other platforms, but suspect that removing the pacman line might be sufficient to get it to work.

Categories: Offsite Blogs

ICFP 2016 Final Call for Papers

General haskell list - Thu, 03/03/2016 - 9:56am
ICFP 2016 The 21st ACM SIGPLAN International Conference on Functional Programming Final Call for Papers Important dates --------------- Submissions due: Wednesday, March 16 2016, 15:00 (UTC) (now open) Author response: Monday, 2 May, 2016, 15:00 (UTC) - Thursday, 5 May, 2016, 15:00 (UTC) Notification: Friday, 20 May, 2016 Final copy due: TBA Early registration: TBA Conference: Monday, 19 September - Wednesday, 21 September, 2016 Please note ----------- For the sake of lightweight double-blind reviewing, the submission procedure may take a little more time than in previous ICFPs; we recommend that you register your submission as early as possible (you can update your paper until the deadline). Scope ----- ICFP 2016 seeks original papers on the art and science of fun
Categories: Incoming News

ICFP 2016 Final Call for Papers

haskell-cafe - Thu, 03/03/2016 - 9:56am
ICFP 2016 The 21st ACM SIGPLAN International Conference on Functional Programming Final Call for Papers Important dates --------------- Submissions due: Wednesday, March 16 2016, 15:00 (UTC) (now open) Author response: Monday, 2 May, 2016, 15:00 (UTC) - Thursday, 5 May, 2016, 15:00 (UTC) Notification: Friday, 20 May, 2016 Final copy due: TBA Early registration: TBA Conference: Monday, 19 September - Wednesday, 21 September, 2016 Please note ----------- For the sake of lightweight double-blind reviewing, the submission procedure may take a little more time than in previous ICFPs; we recommend that you register your submission as early as possible (you can update your paper until the deadline). Scope ----- ICFP 2016 seeks original papers on the art and science of fun
Categories: Offsite Discussion

First Call For Papers -- Erlang Workshop 2016

General haskell list - Thu, 03/03/2016 - 9:19am
Apologies for any duplicates you may receive. CALL FOR PAPERS =============== Fifteenth ACM SIGPLAN Erlang Workshop ----------------------------------------------------------- Nara, Japan, September 23, 2016 Satellite event of the 21st ACM SIGPLAN International Conference on Functional Programming (ICFP 2016) September 18-24, 2016 The Erlang Workshop aims to bring together the open source, academic, and industrial communities of Erlang, to discuss technologies and languages related to Erlang. The Erlang model of concurrent programming has been widely emulated, for example by Akka in Scala, and even new programming languages were designed atop of the Erlang VM, such as Elixir. Therefore we would like to broaden the scope of the workshop to include systems like those mentioned above. The workshop will enable participants to familiarize themselves with recent developments on new techniques and tools, novel applications, draw lessons from users' experiences and identify research problems and common areas
Categories: Incoming News

Brent Yorgey: At SIGCSE 2016 in Memphis

Planet Haskell - Wed, 03/02/2016 - 9:58pm

This weekend I’m in Memphis for SIGCSE 2016. This is my first time at SIGCSE, so I’m looking forward to picking up some new ideas in CS education, and more importantly to meeting lots of new people. If you’re here too, feel free to say hi!

Categories: Offsite Blogs

Take over netlink-hs

haskell-cafe - Wed, 03/02/2016 - 5:31pm
Hi, I want to take over the netlink package on hackage [1]. In accordance to [2] I want to announce that publicly on this list. I have tried to contact the auther in october 2015, and talked about it on the #haskell irc channel. I was able to reach the current maintainer, he told me that he forgot about it and doesn't know his hackage password anymore. Davean (on IRC) offerden to give me maintainer rights after checking back with Max himself. I didn't hear anything after that, neither have I made any effort in this matter since then. ongy [1] [2] _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion

How do I sort items in a wxhaskell listCtrl?

haskell-cafe - Wed, 03/02/2016 - 2:59pm
Hi list, I couldn't find any clues googling and turn to you in the hope that someone might point me in the right direction: I found the function |listCtrlSortItems2| with type |ListCtrl a -> Closure b -> IO Bool| and |closureCreate| (which type is a bit involved..), but I have no idea how to use them.. In the end, I would like to have a listCtrl where clicking on column headers will sort the items and maybe even indicating sorting order with a little arrow. Any help is really appreciated, Tilmann _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion

Haskell 2016: Call for Papers

haskell-cafe - Wed, 03/02/2016 - 12:01am
======================================================================== ACM SIGPLAN CALL FOR SUBMISSIONS Haskell Symposium 2016 Nara, Japan, 22-23 September 2015, directly after ICFP ======================================================================== ** The Haskell Symposium has an early track this year ** ** See the Submission Timetable for details. ** The ACM SIGPLAN Haskell Symposium 2016 will be co-located with the International Conference on Functional Programming (ICFP 2016) in Vancouver, Canada. The Haskell Symposium aims to present original research on Haskell, discuss practical experience and future development of the language, and to promote other forms of denotative programming. Topics of interest include: * Language Design, with a focus on possible extensions and modifications of Haskell as well as critical discussions of the
Categories: Offsite Discussion

[TFP 2016] 2nd call for papers

haskell-cafe - Tue, 03/01/2016 - 10:00am
----------------------------- C A L L F O R P A P E R S ----------------------------- ======== TFP 2016 =========== 17th Symposium on Trends in Functional Programming June 8-10, 2016 University of Maryland, College Park Near Washington, DC The symposium on Trends in Functional Programming (TFP) is an international forum for researchers with interests in all aspects of functional programming, taking a broad view of current and future trends in the area. It aspires to be a lively environment for presenting the latest research results, and other contributions (see below). Authors of draft papers will be invited to submit revised papers based on the feedback receive at the symposium. A post-symposium refereeing process will then select a subset of these articles for formal publication. TFP 201
Categories: Offsite Discussion