News aggregator

GHC.Generics and instances of Functor, Applicative, etc?

libraries list - Wed, 01/13/2016 - 3:28am
I'm using GHC.Generics and have noticed that the data types defined there don't have instances of the standard classes (at least not defined in that module), such as Functor, Applicative, Foldable and Traversable. It'd be very useful to be able to rely on such instances, so that one can define instances of custom types via instances of the generic types. (Hopefully, the compiler can remove most or all conversion overhead) Is there any reason not to add these generic instances?
Categories: Offsite Discussion

Core Spec

Haskell on Reddit - Tue, 01/12/2016 - 8:12pm
Categories: Incoming News

Yesod + ? for reactive web programming.

Haskell on Reddit - Tue, 01/12/2016 - 7:03pm

I'm looking to build a Reactive Web application and in Haskell. I've read through the Yesod book and some blog posts (http://www.yesodweb.com/blog/2012/10/yesod-fay-js - this one to be specific) and it seems as though (correct me if I'm wrong) the Yesod Framework in 2012 wasn't really suitable for that. Have there been changes to that end? In fact a more basic question (excuse my naievity) is would Yesod work with with reactive libraries like Reactive banana to provide the same functionality as the Reactive Stocks example from Play + Scala (https://www.typesafe.com/activator/template/reactive-stocks)?

What options to I have for client side interactivity in Yesod besides Angular and Fay as mentioned in the article?

submitted by ChavXO
[link] [8 comments]
Categories: Incoming News

Magnus Therning: Free play, part one

Planet Haskell - Tue, 01/12/2016 - 6:00pm

When I read John A De Goes post A Modern Architecture for FP I found it to be a bit too vague for me, but the topic was just interesting enough to finally push me to play a little with free monads. It’s not the first post I’ve read on the topic, there have been many before. None have quite managed to push me into actually doing something though!

A file API

To make it concrete but still short enough to not bore readers I came up with a small API for working with files:

data SimpleFileF a = LoadFile FilePath (String -> a) | SaveFile FilePath String a

The free monad wraps a functor, so here’s an implementation of that

instance Functor SimpleFileF where fmap f (LoadFile fp f')= LoadFile fp (f . f') fmap f (SaveFile fp d a) = SaveFile fp d (f a)

Now for some convenient functions to work with the API type

loadFile :: FilePath -> Free SimpleFileF String loadFile fp = liftF $ LoadFile fp id saveFile :: FilePath -> String -> Free SimpleFileF () saveFile fp d = liftF $ SaveFile fp d ()

With this in place I can write a somewhat more complex one

withSimpleFile :: (String -> String) -> FilePath -> Free SimpleFileF () withSimpleFile f fp = do d <- loadFile fp let result = f d saveFile (fp ++ "_new") result

Now I need a way to run programs using the API

runSimpleFile :: Free SimpleFileF a -> IO a runSimpleFile = foldFree f where f (LoadFile fp f') = liftM f' $ readFile fp f (SaveFile fp d r) = writeFile fp d >> return r

If this code was save in the file FreePlay.hs I can now convert it all to upper case by using

runSimpleFile $ withSimpleFile toUpper "FreePlay.hs"

which of course will create the file FreePlay.hs_new.

What have I bought so far?

Well, not much really.

So far it’s not much more than a rather roundabout way to limit what IO actions are available. In other words it’s not much more than what can be done by creating a limited IO, as in my earlier posts here and here.

Of course it would be possible to write another run function, e.g. one that doesn’t actually perform the file actions but just says what it would do. The nice thing though is, to use that same metaphor as John does, that I can add a layer to the onion. In other words, I can decorate each use of my SimpleFileF API with some other API. I think it was John’s description of this layering that pushed me to play with Free.

Categories: Offsite Blogs

Buy the Haskell book (by Chris Allen) in installments?

Haskell on Reddit - Tue, 01/12/2016 - 3:51pm

I've finished with one Haskell course (cis194 by Brent Yorgey) but would like a good source to 'understand' the concepts better.

I think this book ("Haskell Programming - from first principles" - haskellbook.com) could be a good choice but it's expensive (and based on what little I've read about it, rightly so!).

Does anyone know if it's possible to pay for the book "Haskell Programming - from first principles" (haskellbook.com) in installments over a few months?

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

Well-Typed.Com: Haskell courses in New York City

Planet Haskell - Tue, 01/12/2016 - 3:45pm

Well-Typed is happy to announce that once again we will be running Haskell training courses in New York alongside

C◦mp◦se conference

Thursday, February 4 – Sunday, February 7, 2016, New York City

This conference is focused on typed functional programming and features a keynote by Eugenia Cheng and an excellent line-up of talks including one by our own Austin Seipp on Cryptography and verification with Cryptol. There’s also an “unconference” with small workshops and tutorials as well as the opportunity to get your hands dirty and try things out yourself.

For several years now, we have been running successful Haskell courses in collaboration in Skills Matter. The New York courses will be taught by Duncan Coutts, co-founder and partner at Well-Typed. He’s an experienced teacher and is involved in lots of commercial Haskell development projects at Well-Typed.

You can participate in our Haskell courses directly before or directly after C◦mp◦se in February, or if that doesn’t suit we are running two of the courses in London this April:

Fast Track to Haskell

Tuesday, February 2 – Wednesday, February 3, 2016, New York City
(and Monday, April 4 – Tuesday, April 5, 2016, London)

Find out more or register here.

This course is for developers who want to learn about functional programming in general or Haskell in particular. It introduces important concepts such as algebraic datatypes, pattern matching, type inference, polymorphism, higher-order functions, explicit effects and, of course, monads and provides a compact tour with lots of hands-on exercises that provide a solid foundation for further adventures into Haskell or functional programming.

Guide to Haskell Performance and Optimization

Monday, February 8 – Tuesday, February 9, 2016, New York City
(and Wednesday, April 6 – Thursday, April 7, 2016, London)

Find out more or register here.

This brand-new course looks under the surface of Haskell at how things are implemented, including how to reason about performance and optimize your programs, so that you can write beautiful programs that scale. It covers the internal representation of data on the heap, what exactly lazy evaluation means and how it works, how the compiler translates Haskell code to a target language via several internal representations, what you can and cannot reasonably expect the compiler to do, and how you can tweak the optimizer behaviour by using compiler pragmas such as inlining annotations and rewrite rules.

Guide to the Haskell Type System

Wednesday, February 10, 2016, New York City

Find out more or register here.

This course is a one-day introduction to various type-system extensions that GHC offers, such as GADTs, rank-n polymorphism, type families and more. It assumes some familiarity with Haskell. It does not make use of any other advanced Haskell concepts except for the ones it introduces, so it is in principle possible to follow this course directly after Fast Track. However, as this course focuses on the extreme aspects of Haskell’s type system, it is particularly recommended for participants who are enthusiastic about static types and perhaps familiar with a strong static type system from another language.

Well-Typed training courses

In general, our courses are very practical, but don’t shy away from theory where necessary. Our teachers are all active Haskell developers with not just training experience, but active development experience as well. In addition to the courses in New York, we regularly offer courses in London.

We also provide on-site training on requests nearly anywhere in the world. If you want to know more about our training or have any feedback or questions, have a look at our dedicated training page or just drop us a mail.

Categories: Offsite Blogs

Can I refractor this out and how do I do that.

Haskell on Reddit - Tue, 01/12/2016 - 3:02pm

Hello,

To learn Haskell I made a very simple accounting system which is still in development. You can find the code here ; https://github.com/rwobben/paytime/blob/master/paytime/src/Lib.hs

Now noticed that on line 50-51 , on 87-88 and 109-110 I asked for a amount, which is stored as a string.

So to use it I use read x ::Integer which will crash on something else then a integer.

Now I can solve it by using readmaybe.

but I noticed that I have to do this 3 times to solve all read function.

Now my question is : Can I somehow refractor the part which ask for a amount out of the functions and make a seperate function where I use maybeRead for checking. Then I have to do the fix one time.

If I can , how can I do that and what are the types of the new function.

submitted by wobbenr
[link] [9 comments]
Categories: Incoming News

Does this product-like type have a name?

Haskell on Reddit - Tue, 01/12/2016 - 2:33pm

Let's say I have two applicative functors. Both of them have run-like functions that execute them into IO, something like runF :: forall x . F x -> IO x

I want to treat a pair of these Applicatives itself as an Applicative. I thought of using Data.Functor.Product, but I hit a roadblock: Data.Functor.Product forces the parameter of each functor to be of the same type. I want to be able to pair, say, a f Int with a g Bool and have a separate "combining function" Int -> Bool -> SomeType that is pure.

So I came up with this type:

{-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE RankNTypes #-} import Control.Applicative data Wat f g a = forall x y. Wat (x -> y -> a) (f x) (g y) instance Functor (Wat f g) where fmap func (Wat combine f g) = Wat (\x y -> func (combine x y)) f g instance (Applicative f, Applicative g) => Applicative (Wat f g) where pure x = Wat (\_ _ -> x) (pure ()) (pure ()) (Wat combine1 f1 g1) <*> (Wat combine2 f2 g2) = Wat (\(x1,y1) (x2,y2) -> combine1 x1 x2 (combine2 y1 y2)) (liftA2 (,) f1 f2) (liftA2 (,) g1 g2) runWat :: Wat f g a -> (forall x. f x -> IO x) -> (forall x. g x -> IO x) -> IO a runWat (Wat combine f g) run1 run2 = liftA2 combine (run1 f) (run2 g)

My doubt is: does this type or something equivalent to it already exist somewhere? It looks a bit like Coyoneda, but with two functors instead of one...

submitted by Faucelme
[link] [15 comments]
Categories: Incoming News

MSFP 2016: Final Call for Papers

General haskell list - Tue, 01/12/2016 - 1:30pm
Sixth Workshop on MATHEMATICALLY STRUCTURED FUNCTIONAL PROGRAMMING 8 April 2016, in Eindhoven, The Netherlands A satellite workshop of ETAPS 2016 http://msfp2016.bentnib.org/ NOTE: the deadline for paper submissions has been extended by one day to: *Monday 18th January* Prior submission of an abstract is not required The sixth workshop on Mathematically Structured Functional Programming is devoted to the derivation of functionality from structure. It is a celebration of the direct impact of Theoretical Computer Science on programs as we write them today. Modern programming languages, and in particular functional languages, support the direct expression of mathematical structures, equipping programmers with tools of remarkable power and abstraction. Where would Haskell be without monads? Functional reactive programming without temporal logic? Call-by-push-value without adjunctions? The list goes on. This workshop is a forum for researchers who seek to reflect mathematical phenomena in data and con
Categories: Incoming News

Performance Problems You Can Fix: A Dynamic Analysis of Memoization Opportunities

Lambda the Ultimate - Tue, 01/12/2016 - 10:42am

Performance Problems You Can Fix: A Dynamic Analysis of Memoization Opportunities
Luca Della Toffola, Michael Pradel, Thomas Gross
2015

Performance bugs are a prevalent problem and recent research proposes various techniques to identify such bugs. This paper addresses a kind of performance problem that often is easy to address but difficult to identify: redundant computations that may be avoided by reusing already computed results for particular inputs, a technique called memoization. To help developers find and use memoization opportunities, we present MemoizeIt, a dynamic analysis that identifies methods that repeatedly perform the same computation. The key idea is to compare inputs and outputs of method calls in a scalable yet precise way. To avoid the overhead of comparing objects at all method invocations in detail, MemoizeIt first compares objects without following any references and iteratively increases the depth of exploration while shrinking the set of considered methods. After each iteration, the approach ignores methods that cannot benefit from memoization, allowing it to analyze calls to the remaining methods in more detail. For every memoization opportunity that MemoizeIt detects, it provides hints on how to implement memoization, making it easy for the developer to fix the performance issue. Applying MemoizeIt to eleven real-world Java programs reveals nine profitable memoization opportunities, most of which are missed by traditional CPU time profilers, conservative compiler optimizations, and other existing approaches for finding performance bugs. Adding memoization as proposed by MemoizeIt leads to statistically significant speedups by factors between 1.04x and 12.93x.

This paper was recommended by Asumu Takikawa. It is a nice idea, which seems surprisingly effective. The examples they analysed (sadly they don't really explain how they picked the program to study) have a mix of memoization opportunities in fairly different parts of the codebase. There are several examples of what we could call "peripheral communication logic", eg. date formatting stuff, which we could assume is not studied really closely by the programmers focusing more on the problem-domain logic. But there is also an interesting of subtle domain-specific memoization opportunity: an existing cache was over-pessimistic and would reset itself at times where it was in fact not necessary, and this observation corresponds to a non-trivial program invariant.

The authors apparently had some difficulties finding program inputs to exercise profiling. Programs should more often be distributed with "performance-representative inputs", not just functionality-testing inputs. In one example of a linting tool, the provided "standard test" was to feed the code of the linting tool to itself. But this was under a default configuration for which the tools' developers had already fixed all alarms, so the alarm-creating code (which actually had an optimization opportunity) was never exercised by this proposed input.

Note that the caching performed is very lightweight, usually not a full tabulation of the function. Most examples just add a static variable to cache the last (input, output) pair, which is only useful when the same input is typically called several times in a row, but costs very little space.

Categories: Offsite Discussion

Proposal: Add Peano numbers to base

libraries list - Mon, 01/11/2016 - 7:29pm
I have seen these redefined many times now. Examples: https://hackage.haskell.org/package/numericpeano-0.2.0.0/docs/Numeric-Peano.html#t:Nat https://hackage.haskell.org/package/numeric-prelude-0.4.2/docs/Number-Peano.html#t:T https://hackage.haskell.org/package/type-fun-0.0.1/docs/TypeFun-Data-Peano.html#t:N https://hackage.haskell.org/package/number-0.1.1.0/docs/Data-Number-Peano.html#t:Nat https://hackage.haskell.org/package/Peano-0.0.4/docs/Data-Peano.html#t:Peano I often see them used as DataKinds. Too, operations on them can be lazy, which is sometimes useful. I filed a ticket: https://ghc.haskell.org/trac/ghc/ticket/11402 Discussion period: 2 weeks
Categories: Offsite Discussion

ANN: true-name 0.1.0.0 released

General haskell list - Mon, 01/11/2016 - 6:40am
It is with some shame that I announce ‘true-name’, a package to assist one in violating those pesky module abstraction boundaries via the magick of Template Haskell. http://hackage.haskell.org/package/true-name Take ‘Control.Concurrent.Chan’ for example; you can get your grubby mitts on the ‘Chan’ data constructor, despite it not being exported. Here we pattern match on it, and bind ‘chanR’ and ‘chanW’ to the ‘MVar’s containing the read and write ends of the channel respectively: Now, the type of ’chanR’ references the unexported ‘Stream’ and ‘ChItem’ types. We need the ‘ChItem’ data constructor―which is hidden under a few indirections—but that's not a problem: This gives us a rather dodgy ‘peekChan’. This sort of thing is usually a Bad Idea™, but may sometimes be more palatable than the alternatives. Full example: https://github.com/liyang/true-name/blob/master/sanity.hs Taking another example, suppose we want the ‘Array’ type constructor hidde
Categories: Incoming News

Eq1, Ord1, Show1: move from eq1, compare1, showsPrec1 to liftEq, liftCompare, liftShowsPrec

libraries list - Sun, 01/10/2016 - 3:08pm
In transformers-0.5:Data.Functor.Classes class methods like eq1 are replaced by liftEq. With transformers-0.4 I could define: data T a = complicated definition ... deriving (Eq, Ord, Show) instance Eq1 T where eq1 = (==) instance Ord1 T where compare1 = compare instance Show1 T where showsPrec1 = showsPrec In transformers-0.5 it seems that I have to implement Eq1, Ord1, Show1 instances manually. Is there some assistance to define eq1 and compare1 for an ADT? What are the use cases where eq1 was not powerful enough and liftEq is needed?
Categories: Offsite Discussion

suppress warning "Defined but not used: type variable ‘x’" in GHC-8.0

glasgow-user - Sun, 01/10/2016 - 12:57am
GHC-8.0 emits several new warnings of this kind: Defined but not used: type variable ‘x’ for declarations like type instance Snd x y = y Enthusiastically, I started to replace unused type function arguments by underscores, only to find out that older GHC versions do not accept that. With what option can I disable this warning? Or can it be removed from -Wall for now?_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users< at >haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users
Categories: Offsite Discussion

New gtk2hs 0.12.4 release

gtk2hs - Wed, 11/21/2012 - 12:56pm

Thanks to John Lato and Duncan Coutts for the latest bugfix release! The latest packages should be buildable on GHC 7.6, and the cairo package should behave a bit nicer in ghci on Windows. Thanks to all!

~d

Categories: Incoming News