News aggregator

Trying to learn Haskell, but where is the standard API documentation?

Haskell on Reddit - Thu, 09/03/2015 - 9:47am

Obviously coming from Java background here, API might even be wrong term. Anyways, what I'm looking for is something exactly like this:

Meanwhile in Haskell docs page there is nothing like that. Stackoverflow answers suggest Hoogle, but I'd rather just look at a list of functions thanks.

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

Roadmap to better database bindings?

Haskell on Reddit - Thu, 09/03/2015 - 9:35am

In the ICFP 2015 talk 04 An Optimizing Compiler for a Purely Functional Web Application Language a comment was made at end that one reason Haskell performs poorly in web benchmarks is because of its database binding libraries.

What needs to be done to improve this situation?

The comment occurs approx 15m into the talk:

submitted by mn-haskell-guy
[link] [15 comments]
Categories: Incoming News

Felipe Almeida Lessa: Using Caps Lock as Menu/Apps keys on Emacs

Planet Haskell - Thu, 09/03/2015 - 9:28am

I’m an ergoemacs-mode user, a mode that changes most key bindings so that they put less strain on your hands.  For example, it uses Alt instead of Ctrl most of the time, which is easier to press: use your curled thumb instead of a karate chop.  Also, many commands are activated by first pressing the Menu/Apps key (that key near the Right Ctrl which usually opens the context menu).  For example, pressing Menu then T allows you to switch buffers.

However, the keyboard on my new notebook doesn’t have a dedicated Menu key.  Instead, one needs to press Fn+Right Ctrl, which is of course extremely painful.

Menu key hidden on the Right Ctrl.


I’ve found a workaround, though.  A very hackish workaround.

The ergoemacs-mode FAQ suggests using Caps Lock as a Menu/Apps key for Mac users.  Using xmodmap it’s trivial to make Caps Lock a Menu key:

$ xmodmap -e "keycode 66 = Menu"

However, using xmodmap properly with Gnome is nigh impossible.  It’s recommend to use xkb instead, but xkb doesn’t support mapping Caps Lock to the Menu key out-of-the-box (at least not yet).  At this point, having wandered through many documentation pages, I’ve decided to try using some of the xkb options that already exist.

At first I tried setting Caps Lock as the Hyper key.  However, by default the Hyper key gets the same modifier code as the Super key (which is usually the key with the Windows logo).  There’s a straightforward way of separating them, but I couldn’t find a way to make it play nice with Gnome.  And even if I could, it’s not clear to me if I could use the Hyper key as a substitute for the Menu key on emacs.

When ready to admit defeat, I’ve set the Caps Lock behavior to “Caps Lock is disabled” in preparation of trying a hack using xmodmap.  Much to my surprise, I accidentally discovered that emacs then began treating the disabled Caps Lock key as <VoidSymbol>! The gears started turning in my head, then I added the following line to my ~/.emacs file:

(define-key key-translation-map (kbd "<VoidSymbol>") (kbd "<menu>"))

Surprisingly, it worked!  Now pressing Caps Lock then T will switch buffers, for example.  As a bonus, pressing Caps Lock accidentally while on another application won’t do anything.

It’s not clear to me how fragile this hack really is.  I’ll update this blog post if I ever find some drawback to it.  But right now it seems to work quite nicely.

Categories: Offsite Blogs

ETAPS 2016 2nd call for papers

General haskell list - Thu, 09/03/2015 - 7:34am
****************************************************************** CALL FOR PAPERS: ETAPS 2016 19th European Joint Conferences on Theory And Practice of Software Eindhoven, The Netherlands, 2-8 April 2016 ******************************************************************
Categories: Incoming News

Private packages on hackage

haskell-cafe - Thu, 09/03/2015 - 2:42am
Hi all I had a chat with Duncan Coutts of Well-Typed about the possibility of an extension to hackage which would allow private packages to be uploaded and managed by hackage, for a fee. The idea is that it operates in a similar fashion to GitHub, where public packages are free, but there is a monthly fee for hosting private packages. This would give commercial organisations wanting to get started with Haskell a simple way to host their packages, so that members of the organisation could see the private and public packages when logged in, and cabal install would work as expected with the superset. Duncan is worried about the up-front effort required vs an uncertain return. Personally I think that this could be a good way to fund the hackage infrastructure. So the question is, apart from me, would anyone be interested in such a feature? Regards Alan _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion

How to direct cabal to use an alternative ghcversion, ala stack?

haskell-cafe - Thu, 09/03/2015 - 1:37am
Hi all, How do I direct cabal to use an alternative (i.e. - not my system’s default) version of ghc, which I’ve installed, via stack? I tried this: stack exec cabal install ... but got this: cabal: Use of GHC's environment variable GHC_PACKAGE_PATH is incompatible with Cabal. Use the flag --package-db to specify a package database (it can be used multiple times). Thanks, -db _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion

ICFP recordings

Haskell on Reddit - Thu, 09/03/2015 - 1:22am
Categories: Incoming News

Examples for Control.Lens.Plated?

haskell-cafe - Thu, 09/03/2015 - 12:44am
Hello Cafe, I'm considering porting some of my code that uses uniplate to lens. But Control.Lens.Plated is giving me headaches. So I'm looking for remedy. Has anyone used it and willing to share examples? I hope that seeing some of the combinators in action would help me understand the type signatures and documentation. What I'm particularly interested in is the following: 1) implementation of something like transformBi and rewriteBi using lens 2) usage of *On, *Off and *OnOff combinators (e.g., transformMOn, transformMOff, transformMOnOff). What I want to understand is the difference between the 3 variants. Also, what does it mean to "Transform every element in the tree in a region indicated by a supplied Traversal" and how exactly does the traversal define the region. 3) any recursive tree traversals/transformations using Plated that stop the recursion at a certain point (e.g., upon seeing a certain constructor) I hope this isn't too vague, but, please, let me know if it is. /Andrey
Categories: Offsite Discussion

Flag to recompile modules which had warnings

haskell-cafe - Wed, 09/02/2015 - 7:44pm
This is a call for comments before I'd create a ticket in corresponding project (I'm not sure if it should be ghc or stack/cabal). There's a common situation I get into: I compile with "stack build" (or cabal build), get a big list of warnings, fix few of them, then I re-compile project, but a lot of warnings are gone now. The only option I'm left with is to use "-fforce-recomp". Problems with -fforce-recomp are: - full-recompile is quite long for big projects - most people don't know about it, especially newbies I think some flag, which would be turned on by default, which would indicate to "recompile modules if they previously had warnings" would be awesome to have. 1. would you like to have that flag? 2. would you like it "on" by default? 3. should ticket go into ghc or stack/cabal-install project? Thank you. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion

Question about Snap + Heist + Static Pages

Haskell on Reddit - Wed, 09/02/2015 - 7:39pm

A common use case for Apache + PHP is for simple static sites where you just need to do simple sharing of html fragments (like the header and footer). Is there an example anywhere of using snap and heist to do this? In fact, it could just be wai instead of snap (but I believe that it's more likely that someone has done this with snap). Specifically, what I am looking for is a way to set things up such that I have a directory with heist templates, and routing just takes the path from the URL, and uses it for a template lookup. That's it. No database, no persistence, no auth. I thought that snap init might give me enough to figure this out, but it didn't. I would appreciate any help. Thanks.

submitted by andrewthad
[link] [11 comments]
Categories: Incoming News

Roman Cheplyaka: MonadFix example: compiling regular expressions

Planet Haskell - Wed, 09/02/2015 - 2:00pm
{-# LANGUAGE RecursiveDo, BangPatterns #-} import Control.Applicative import Data.Function (fix) import Data.IntMap as IntMap import Control.Monad.Fix (mfix) import Control.Monad.Trans.State import Control.Monad.Trans.Class (lift) import Text.Read (readMaybe)

MonadFix is an odd beast; many Haskell programmers will never use it in their careers. It is indeed very rarely that one needs MonadFix; and for that reason, non-contrived cases where MonadFix is needed are quite interesting to consider.

In this article, I’ll introduce MonadFix and show how it can be handy for compiling the Kleene closure (also known as star or repetition) of regular expressions.

What is MonadFix?

If you hear about MonadFix for the first time, you might think that it is needed to define recursive monadic actions, just like ordinary fix is used to define recursive functions. That would be a mistake. In fact, fix is just as applicable to monadic actions as it is to functions:

guessNumber m = fix $ \repeat -> do putStrLn "Enter a guess" n <- readMaybe <$> getLine if n == Just m then putStrLn "You guessed it!" else do putStrLn "You guessed wrong; try again" repeat

So, what is mfix for? First, recall that in Haskell, one can create recursive definitions not just for functions (which makes sense in other, non-lazy languages) or monadic actions, but for ordinary data structures as well. This is known as cyclic (or circular, or corecursive) definitions; and the technique itself is sometimes referred to as tying the knot.

The classic example of a cyclic definition is the (lazy, infinite) list of Fibonacci numbers:

fib = 0 : 1 : zipWith (+) fib (tail fib)

Cyclic definitions are themselves rare in day-to-day Haskell programming; but occasionally, the right hand side will be not a pure value, but a monadic computation that needs to be run in order to obtain the value.

Consider this (contrived) example, where we start the sequence with an arbitrary number entered by the user:

fibIO1 = do putStrLn "Enter the start number" start <- read <$> getLine return $ start : 1 : zipWith (+) fibIO1 (tail fibIO1)

This doesn’t typecheck because fibIO is not a list; it’s an IO action that produces a list.

But if we try to run the computation, it doesn’t make much sense either:

fibIO2 = do putStrLn "Enter the start number" start <- read <$> getLine fib <- fibIO2 return $ start : 1 : zipWith (+) fib (tail fib)

This version of fibIO will ask you to enter the start number ad infinitum and never get to evaluating anything.

Of course, the simplest thing to do would be to move IO out of the recursive equation; that’s why I said the example was contrived. But MonadFix gives another solution:

fibIO3 = mfix $ \fib -> do putStrLn "Enter the start number" start <- read <$> getLine return $ start : 1 : zipWith (+) fib (tail fib)

Or, using the do-rec syntax:

fibIO4 = do rec fib <- do putStrLn "Enter the start number" start <- read <$> getLine return $ start : 1 : zipWith (+) fib (tail fib) return fib Compiling regular expressions

As promised, I am going to show you an example usage of MonadFix that solved a problem other than “how could I use MonadFix?”. This came up in my work on regex-applicative.

For a simplified presentation, let’s consider this type of regular expressions:

data RE = Sym Char -- symbol | Seq RE RE -- sequence | Alt RE RE -- alternative | Rep RE -- repetition

Our goal is to compile a regular expression into a corresponding NFA. The states will be represented by integer numbers. State 0 corresponds to successful completion; and each Sym inside a regex will have a unique positive state in which we are expecting the corresponding character.

type NFAState = Int

The NFA will be represented by a map

type NFA = IntMap (Char, [NFAState])

where each state is mapped to the characters expected at that state and the list of states where we go in case we get the expected character.

To compile a regular expression, we’ll take as an argument the list of states to proceed to when the regular expression as a whole succeeds (otherwise we’d have to compile each subexpression separately and then glue NFAs together). This is essentially the continuation-passing style; only instead of functions, our continuations are NFA states.

During the compilation, we’ll use a stack of two State monads: one to assign sequential state numbers to Syms; the other to keep track of the currently constructred NFA.

-- Returns the list of start states and the transition table compile :: RE -> ([NFAState], NFA) compile re = runState (evalStateT (go re [0]) 0) IntMap.empty -- go accepts exit states, returns entry states go :: RE -> [NFAState] -> StateT NFAState (State NFA) [NFAState] go re exitStates = case re of Sym c -> do !freshState <- gets (+1); put freshState lift $ modify' (IntMap.insert freshState (c, exitStates)) return [freshState] Alt r1 r2 -> (++) <$> go r1 exitStates <*> go r2 exitStates Seq r1 r2 -> go r1 =<< go r2 exitStates

This was easy so far: alternatives share their exit states and their entry states are combined; and consequtive subexpressions are chained. But how do we compile Rep? The exit states of the repeated subexpression should become its own entry states; but we don’t know the entry states until we compile it!

And this is precisely where MonadFix (or recursive do) comes in:

Rep r -> do rec let allEntryStates = ownEntryStates ++ exitStates ownEntryStates <- go r allEntryStates return allEntryStates

Why does this circular definition work? If we unwrap the State types, we’ll see that the go function actually computes a triple of three non-strict fields:

  1. The last used state number
  2. The list of entry states
  3. The NFA map

The elements of the triple may depend on each other as long as there are no actual loops during evaluation. One can check that the fields can be indeed evaluated linearly in the order in which they are listed above:

  1. The used state numbers at each step depend only on the regular expression itself, so it can be computed wihtout knowing the other two fields.
  2. The list of entry states relies only on the state number information; it doesn’t need to know anything about the NFA transitions.
  3. The NFA table needs to know the entry and exit states; but that is fine, we can go ahead and compute that information without creating any reverse data dependencies.
Further reading

An ASM Monad – a similar example from a different domain.

Oliver Charles’s 24 Days of GHC Extensions: Recursive Do.

Levent Erkok’s thesis which contains all you need to know about MonadFix, including several other examples.

Todd Wilson points out that Douglas McIlroy describes a similar regular expression compilation technique in his 2004 JFP Functional Pearl Enumerating the strings of regular languages. Like this article, Douglas’s paper uses a circular definition when compiling the Kleene closure. But the circular definition is not monadic there: instead of using the State monad, Douglas passes the state around by hand.

Categories: Offsite Blogs