News aggregator

Requesting an informal code review for simple first package to go on Hackage eventually

Haskell on Reddit - Sun, 08/30/2015 - 12:31pm

Hi, first of all let me say that I love the community here on /r/haskell. You all have been super helpful in my journey of learning this great language.

In running a personal file-serving site using Scotty, I ran into the problem of authentication and sessions. Seeing as the package called scotty-sessions was deprecated (and later turned into Spock, a different framework), I decided to roll my own authentication/sessions. I did so, and it seems to work, so I abstracted it into a library. My friend has suggested that I put it on Hackage, but I do not think that it is ready. I would greatly appreciate it if a few of you could take the time to skim my code (~120 lines) and give me some pointers!

Background: * The code generates sessionId's from random Ints, stores them in a cookie called "SessionId" which expires in a number of minutes (currently 10 for testing purposes), and makes an entry into a SQLite database with the sessionId and expiration. * I used persistent as a database backend, but I am unsure of the best way to give configuration options to the user (e.g. database location/name). Wrap everything IO in a ReaderT? Configuration file? * The solution I came up with for removing expired sessions from the database feels inadequate/improper (uses forkIO and threadDelay).

Example program using it

Package on Github

Any and all suggestions regarding style or functionality would be greatly appreciated!

submitted by shishkabeb
[link] [16 comments]
Categories: Incoming News

When NOT to use State?

Haskell on Reddit - Sun, 08/30/2015 - 12:06pm

After discovering the absolute magic that is the State monad, every single program I've made since has used it almost exclusively, in some cases even using State a (). In what situation does it work better or is it cleaner to NOT use the State monad?

submitted by part-ick-you-are-lee
[link] [69 comments]
Categories: Incoming News

Applicatives in Math vs Code

Haskell on Reddit - Sun, 08/30/2015 - 11:58am
Categories: Incoming News

Final CFP: FLOPS 2016, International Symposium on Functional and Logic Programming

General haskell list - Sun, 08/30/2015 - 9:08am
NEW: revised submission deadlines (Sep 21 for abstracts, Sep 25 for papers) FLOPS 2016: March 3-6, 2016, Kochi, Japan Final Call For Papers Writing down detailed computational steps is not the only way of programming. The alternative, being used increasingly in practice, is to start by writing down the desired properties of the result. The computational steps are then (semi-)automatically derived from these higher-level specifications. Examples of this declarative style include functional and logic programming, program transformation and re-writing, and extracting programs from proofs of their correctness. FLOPS aims to bring together practitioners, researchers and implementors of the declarative programming, to discuss mutually interesting results and common problems: theoretical advances, their implementations in language systems and tools, and applications of these systems in practice. The scope includes all aspects of the design, semantics, the
Categories: Incoming News

Documentation for GHC.IO.Exception

libraries list - Sun, 08/30/2015 - 3:00am
On Hackage, there seems to be no documentation for GHC.IO.Exception in base, but the package can in fact be imported so it's not exactly an internal package. directory and likely many other packages do use the GHC-specific error types like InappropriateType in exceptions, so it would be useful if there were a documentation page for these things even if there isn't any text. As it is right now, the discoverability of these error types is very low as you need to know the magical URL to show the source code: That's also partly a problem with Haddock; AFAIK there's no way to navigate to the Source Code packages of modules whose documentation is disabled, even though they are in fact present if you can figure out the URL. So would it be OK to open up this module or is there a reason for keeping them discreet?
Categories: Offsite Discussion

Problem running zlib test suite: ghc: unrecognised flag: -fno-stack-protector

libraries list - Sun, 08/30/2015 - 2:08am
Hi, I'm trying of running the zlib test suite using GHC 7.10.2 and hsc2hs 0.67: $ darcs get $ cd zlib $ cabal install $ cd test $ make test hsc2hs --cc=ghc --ld=ghc --lflag=-lz -o ../Codec/Compression/Zlib/Stream.hs ../Codec/Compression/Zlib/Stream.hsc ghc: unrecognised flag: -fno-stack-protector ... compiling ../Codec/Compression/Zlib/Stream_hsc_make.c failed (exit code 1) command was: ghc -c ../Codec/Compression/Zlib/Stream_hsc_make.c -o ../Codec/Compression/Zlib/Stream_hsc_make.o -fno-stack-protector -I/usr/local/stow/ghc-7.10.2/lib/ghc-7.10.2/include/ Am I doing something wrong? Best,
Categories: Offsite Discussion

Question, re: type class syntax.

haskell-cafe - Sun, 08/30/2015 - 12:45am
Hi all, I can’t figure out why this is invalid: class (Show a, Num a) => LogTree2 a where evaluator :: (LogTree2 a) t => t -> SizedVector a -> SizedVector a error| ‘LogTree2’ is applied to too many type arguments In the type ‘(LogTree2 a) t => t -> SizedVector a -> SizedVector a’ In the class declaration for ‘LogTree2’ Can anyone help me understand? Thanks, -db _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion

wren gayle romano: (Re)meeting folks at ICFP

Planet Haskell - Sun, 08/30/2015 - 12:36am

In the spirit of Brent's post, I figure I'll make a public announcement that I'm in Vancouver all week attending HOPE, ICFP, and the Haskell Symposium. I love reconnecting with old friends, as well as meeting new folks. Even if I've met you at past ICFPs, feel free to re-introduce yourself as ...things have changed over the past few years. I know I've been pretty quiet of late on Haskell cafe as well as here, but word on the street is folks still recognize my name around places. So if you want to meet up, leave a comment with when/where to find you, or just look for the tall gal with the blue streak in her hair.

Unlike Brent, and unlike in years past, I might should note that I am looking to "advance my career". As of this fall, I am officially on the market for research and professorship positions. So if you're interested in having a linguistically-minded constructive mathematician help work on your problems, come say hi. For those not attending ICFP, you can check out my professional site; I need to fix my script for generating the publications page, but you can find a brief background/research statement there along with the other usuals like CV, recent projects, and classes taught.

Categories: Offsite Blogs

Is there a DateTime library in haskell that as user friendly as moment.js?

Haskell on Reddit - Sun, 08/30/2015 - 12:33am

I've tried 'time' but the interface confuse me. Is it just me or you guys have the same experience?

submitted by eckyputr
[link] [39 comments]
Categories: Incoming News

Idiomatic way to parse bytecodes

haskell-cafe - Sun, 08/30/2015 - 12:12am
Hello all, I have some bytecodes to parse and I look for the most idiomatic way to do it. It's mostly JVM Bytecode, long story short, I have some embedded JVM Bytecodes: * one part is specification-defined, from 0x00 to 0xB8, differ from the regular JVM Bytecode * and the other part is proprietary and changes often I have two main goals: * print the signification of each bytecodes (a more explicit one than the hexadecimal value of the bytecode) * Do some analysis on it, spot patterns, apply markov model on it and so on. The issue with JVM Bytecode in general is that each bytecode hasn't been made equal. Some of them requires parameters, some of them modify the length of the next bytecode, etc. I'm not looking for a way to parse bytecode quickly, or for a library doing it for me. I look for a simple/composable/idiomatic way to do it. So if you have any thoughts, papers, articles or even code snippets (part of a library of not) that is done in the Haskell-way, please, share it :) Thanks in advance for
Categories: Offsite Discussion

apfelmus: FRP — API redesign for reactive-banana 1.0

Planet Haskell - Sat, 08/29/2015 - 12:23pm

After having released version 0.9 of my reactive-banana library, I now want to discuss the significant API changes that I have planned for the next release of the library, version number 1.0. These changes will not be backward compatible.

Since its early iterations (version 0.2), the goal of reactive-banana has been to provide an efficient push-based implementation of functional reactive programming (FRP) that uses (a variation of) the continuous-time semantics as pioneered by Conal Elliott and Paul Hudak. Don’t worry, this will stay that way. The planned API changes may be radical, but they are not meant to change the direction of the library.

I intend to make two major changes:

  1. The API for dynamic event switching will be changed to use a monadic approach, and will become more similar to that of the sodium FRP library. Feedback that I have received indicates that the current approach using phantom types is just too unwieldy.

  2. The type Event a will be changed to only allow a single event occurrence per moment, rather than multiple simultaneous occurrences. In other words, the types in the module Reactive.Banana.Experimental.Calm will become the new default.

These changes are not entirely cast in stone yet, they are still open for discussion. If you have an opinion on these matters, please do not hesitate to write a comment here, send me an email or to join the discussion on github on the monadic API!

The new API is not without precedent: I have already implemented a similar design in my threepenny-gui library. It works pretty well there and nobody complained, so I have good reason to believe that everything will be fine.

Still, for completeness, I want to summarize the rationale for these changes in the following sections.

Dynamic Event Switching

One major impediment for early implementations of FRP was the problem of so-called time leaks. The key insight to solving this problem was to realize that the problem was inherent to the FRP API itself and can only be solved by restricting certain types. The first solution with first-class events (i.e. not arrowized FRP) that I know is from an article by Gergeley Patai [pdf].

In particular, the essential insight is that any FRP API which includes the functions

accumB :: a -> Event (a -> a) -> Behavior a switchB :: Behavior a -> Event (Behavior a) -> Behavior a

with exactly these types is always leaky. The first combinator accumulates a value similar to scanl, whereas the second combinator switches between different behaviors – that’s why it’s called “dynamic event switching”. A more detailed explanation of the switchB combinator can be found in a previous blog post.

One solution the problem is to put the result of accumB into a monad which indicates that the result of the accumulation depends on the “starting time” of the event. The combinators now have the types

accumB :: a -> Event (a -> a) -> Moment (Behavior a) switchB :: Behavior a -> Event (Behavior a) -> Behavior a

This was the aforementioned proposal by Gergely and has been implemented for some time in the sodium FRP library.

A second solution, which was inspired by an article by Wolfgang Jeltsch [pdf], is to introduce a phantom type to keep track of the starting time. This idea can be expanded to be equally expressive as the monadic approach. The combinators become

accumB :: a -> Event t (a -> a) -> Behavior t a switchB :: Behavior t a -> Event t (forall s. Moment s (Behavior s a) -> Behavior t a

Note that the accumB combinator keeps its simple, non-monadic form, but the type of switchB now uses an impredicative type. Moreover, there is a new type Moment t a, which tags a value of type a with a time t. This is the approach that I had chosen to implement in reactive-banana.

There is also a more recent proposal by Atze van der Ploeg and Koen Claessen [pdf], which dissects the accumB function into other, more primitive combinators and attributes the time leak to one of the parts. But it essentially ends up with a monadic API as well, i.e. the first of the two mentioned alternatives for restricting the API.

When implementing reactive-banana, I intentionally decided to try out the second alternative, simply in order to explore a region of the design space that sodium did not. With the feedback that people have sent me over the years, I feel that now is a good time to assess whether this region is worth staying in or whether it’s better to leave.

The main disadvantage of the phantom type approach is that it relies not just on rank-n types, but also on impredicative polymorphism, for which GHC has only poor support. To make it work, we need to wrap the quantified type in a new data type, like this

newtype AnyMoment f a = AnyMoment (forall t. Moment t (f t a))

Note that we also have to parametrize over a type constructor f, so that we are able to write the type of switchB as

switchB :: forall t a. Behavior t a -> Event t (AnyMoment Behavior a) -> Behavior t a

Unfortunately, wrapping and unwrapping the AnyMoment constructor and getting the “forall”s right can be fairly tricky, rather tedious, outright confusing, or all three of it. As Oliver Charles puts it in an email to me:

Right now you’re required to provide an AnyMoment, which in turn means you have to trim, and then you need a FrameworksMoment, and then an execute, and then you’ve forgotten what you were donig! :-)

Another disadvantage is that the phantom type t “taints” every abstraction that a library user may want to build on top of Event and Behavior. For instance, image a GUI widget were some aspects are modeled by a Behavior. Then, the type of the widget will have to include a phantom parameter t that indicates the time at which the widget was created. Ugh.

On the other hand, the main advantage of the phantom type approach is that the accumB combinator can keep its simple non-monadic type. Library users who don’t care much about higher-order combinators like switchB are not required to learn about the Moment monad. This may be especially useful for beginners.

However, in my experience, when using FRP, even though the first-order API can carry you quite far, at some point you will invariably end up in a situation where the expressivitiy of dynamic event switching is absolutely necessary. For instance, this happens when you want to manage a dynamic collection of widgets, as demonstrated by the BarTab.hs example for the reactive-banana-wx library. The initial advantage for beginners evaporates quickly when faced with managing impredicative polymorphism.

In the end, to fully explore the potential of FRP, I think it is important to make dynamic event switching as painless as possible. That’s why I think that switching to the monadic approach is a good idea.

Simultaneous event occurences

The second charge is probably less controversial, but also breaks backward compatibility.

The API includes a combinator for merging two event streams,

union :: Event a -> Event a -> Event a

If we think of Event as a list of values with timestamps, Event a = [(Time,a)], this combinator works like this:

union ((timex,x):xs) ((timey,y):ys) | timex < timey = (timex,x) : union xs ((timey,y):ys) | timex > timey = (timey,y) : union ((timex,x):xs) yss | timex == timey = ??

But what happens if the two streams have event occurrences that happen at the same time?

Before answering this question, one might try to argue that simultaneous event occurrences are very unlikely. This is true for external events like mouse movement or key presses, but not true at all for “internal” events, i.e. events derived from other events. For instance, the event e and the event fmap (+1) e certainly have simultaneous occurrences.

In fact, reasoning about the order in which simultaneous occurrences of “internal” events should be processed is one of the key difficulties of programming graphical user interfaces. In response to a timer event, should one first draw the interface and then update the internal state, or should one do it the other way round? The order in which state is updated can be very important, and the goal of FRP should be to highlight this difficulty whenever necessary.

In the old semantics (reactive-banana versions 0.2 to 0.9), using union to merge two event streams with simultaneous occurrences would result in an event stream where some occurrences may happen at the same time. They are still ordered, but carry the same timestamp. In other words, for a stream of events

e :: Event a e = [(t1,a1), (t2,a2), …]

it was possible that some timestamps coincide, for example t1 == t2. The occurrences are still ordered from left to right, though.

In the new semantics, all event occurrences are required to have different timestamps. In other to ensure this, the union combinator will be removed entirely and substituted by a combinator

unionWith f :: (a -> a -> a) -> Event a -> Event a -> Event a unionWith f ((timex,x):xs) ((timey,y):ys) | timex < timey = (timex,x) : union xs ((timey,y):ys) | timex > timey = (timey,y) : union ((timex,x):xs) yss | timex == timey = (timex,f x y) : union xs ys

where the first argument gives an explicit prescription for how simultaneous events are to be merged.

The main advantage of the new semantics is that it simplies the API. For instance, with the old semantics, we also needed two combinators

collect :: Event a -> Event [a] spill :: Event [a] -> Event a

to collect simultaneous occurrences within an event stream. This is no longer necessary with the new semantics.

Another example is the following: Imagine that we have an input event e :: Event Int whose values are numbers, and we want to create an event that sums all the numbers. In the old semantics with multiple simultaneous events, the event and behavior defined as

bsum :: Behavior Int esum :: Event Int esum = accumE 0 ((+) <@> e) bsum = stepper 0 esum

are different from those defined by

bsum = accumB 0 ((+) <@> e) esum = (+) <$> bsum <@ e

The reason is that accumE will take into account simultaneous occurrences, but the behavior bsum will not change until after the current moment in time. With the new semantics, both snippets are equal, and accumE can be expressed in terms of accumB.

The main disadvantage of the new semantics is that the programmer has to think more explicitly about the issue of simultaneity when merging event streams. But I have argued above that this is actually a good thing.

In the end, I think that removing simultaneous occurrences in a single event stream and emphasizing the unionWith combinator is a good idea. If required, s/he can always use an explicit list type Event [a] to handle these situations.

(It just occurred to me that maybe a type class instance

instance Monoid a => Monoid (Event a)

could give us the best of both worlds.)

This summarizes my rationale for these major and backward incompatible API changes. As always, I appreciate your comments!

Categories: Offsite Blogs

Stack vs Cabal

Haskell on Reddit - Sat, 08/29/2015 - 9:52am

With the no-reinstall cabal project coming soon, it seems that cabal is back on track to face the stack attack.

Which one do use, why ?

submitted by maxigit
[link] [76 comments]
Categories: Incoming News

Brent Yorgey: Meeting new people at ICFP

Planet Haskell - Sat, 08/29/2015 - 8:49am

This afternoon I’ll be getting on a plane to Vancouver for ICFP. I’m looking forward to seeing many friends, of course, but I also enjoy meeting new people—whether or not they are “famous”, whether or not I think they can “advance my career”. So I’ll just throw this out there: if you will be in Vancouver this week and would like to meet me, just leave a comment and I will make a point of trying to find you to chat! I’ll be attending the Haskell Implementor’s Workshop, the Ally Skills Tutorial, ICFP itself, the Haskell Symposium, and FARM, but there’s also plenty of time to chat in the hallway or over a meal.

Categories: Offsite Blogs

Edward Z. Yang: Help us beta test “no-reinstall Cabal”

Planet Haskell - Fri, 08/28/2015 - 10:31pm

Over this summer, Vishal Agrawal has been working on a GSoC project to move Cabal to more Nix-like package management system. More simply, he is working to make it so that you'll never get one of these errors from cabal-install again:

Resolving dependencies... In order, the following would be installed: directory- (reinstall) changes: time-1.4.2 -> 1.5 process- (reinstall) extra-1.0 (new package) cabal: The following packages are likely to be broken by the reinstalls: process- hoogle-4.2.35 haskell98- ghc-7.8.3 Cabal- ...

However, these patches change a nontrivial number of moving parts in Cabal and cabal-install, so it would be very helpful to have willing guinea pigs to help us iron out some bugs before we merge it into Cabal HEAD. As your prize, you'll get to run "no-reinstall Cabal": Cabal should never tell you it can't install a package because some reinstalls would be necessary.

Here's how you can help:

  1. Make sure you're running GHC 7.10. Earlier versions of GHC have a hard limitation that doesn't allow you to reinstall a package multiple times against different dependencies. (Actually, it would be useful if you test with older versions of GHC 7.8, but only mostly to make sure we haven't introduced any regressions here.)
  2. git clone (I've added some extra corrective patches on top of Vishal's version in the course of my testing) and git checkout cabal-no-pks.
  3. In the Cabal and cabal-install directories, run cabal install.
  4. Try building things without a sandbox and see what happens! (When I test, I've tried installing multiple version of Yesod at the same time.)

It is NOT necessary to clear your package database before testing. If you completely break your Haskell installation (unlikely, but could happen), you can do the old trick of clearing out your .ghc and .cabal directories (don't forget to save your .cabal/config file) and rebootstrapping with an old cabal-install.

Please report problems here, or to this PR in the Cabal tracker. Or chat with me in person next week at ICFP. :)

Categories: Offsite Blogs

Andrei Alexandrescu - "Generic Programming Must Go"

Haskell on Reddit - Fri, 08/28/2015 - 5:02pm

Anyone have thoughts on this talk by C++/D guru Andrei Alexandrescu? Talk is focused on pretty low level C++ memory allocator use case, but since generic programming is an important paradigm, I'm curious what people here think.

EDIT: link

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