News aggregator

CFP: UNIF 2015

General haskell list - Wed, 01/21/2015 - 4:35pm
========================================================== Call for Papers UNIF 2015 The 29th International Workshop on Unification June 28, 2015. Warsaw, Poland ********* part of the Federated Conference on Rewriting, Deduction, and Programming (RDP'15) ========================================================== UNIF 2015 is the 29th event in a series of international meetings devoted to unification theory and its applications. Unification is concerned with the problem of identifying terms, finding solutions for equations, or making formulas equivalent. It is a fundamental process used in a number of fields of computer science, including automated reasoning, term rewriting, logic programming, natural language processing, program analysis, types, etc. The International Workshop on Unification (UNIF) is a yearly forum for researchers in unificatio
Categories: Incoming News

AVoCS 2015: First Call for Papers

General haskell list - Wed, 01/21/2015 - 2:48pm
--------------------------------------------------------------------- FIRST CALL FOR PAPERS The 15th International Workshop on Automated Verification of Critical Systems AVoCS 2015 1-4 September 2015, Edinburgh, UK avocs2015< at > --------------------------------------------------------------------- IMPORTANT DATES Submission of abstract (full papers): 5th June 2015 Submission of full papers: 12th June 2015 Notification (full papers): 14th July 2015 Submission of research idea papers: 7th August 2015 Notification (research idea): 14th August 2015 Early registration: 18th August 2015 Submissions of final versions: 21st August 2015 INVITED SPEAKERS Colin O'Halloran (D-RisQ & the University of Oxford) Don Sannella (Contemplate & the University of Edinburgh) SPONSORS Formal Methods Europe (FME) The Scottish Informatics & Compute
Categories: Incoming News

Any fast octree in Haskell with a ray transversal feature?

Haskell on Reddit - Wed, 01/21/2015 - 1:20pm

Obviously for a ray-tracer.

submitted by SrPeixinho
[link] [10 comments]
Categories: Incoming News

mightybyte: LTMT Part 3: The Monad Cookbook

Planet Haskell - Wed, 01/21/2015 - 11:09am

The previous two posts in my Less Traveled Monad Tutorial series have not had much in the way of directly practical content. In other words, if you only read those posts and nothing else about monads, you probably wouldn't be able to use monads in real code. This was intentional because I felt that the practical stuff (like do notation) had adequate treatment in other resources. In this post I'm still not going to talk about the details of do notation--you should definitely read about that elsewhere--but I am going to talk about some of the most common things I have seen beginners struggle with and give you cookbook-style patterns that you can use to solve these issues.

Problem: Getting at the pure value inside the monad

This is perhaps the most common problem for Haskell newcomers. It usually manifests itself as something like this:

main = do lineList <- lines $ readFile "myfile.txt" -- ... do something with lineList here

That code generates the following error from GHC:

Couldn't match type `IO String' with `[Char]' Expected type: String Actual type: IO String In the return type of a call of `readFile'

Many newcomers seem puzzled by this error message, but it tells you EXACTLY what the problem is. The return type of readFile has type IO String, but the thing that is expected in that spot is a String. (Note: String is a synonym for [Char].) The problem is, this isn't very helpful. You could understand that error completely and still not know how to solve the problem. First, let's look at the types involved.

readFile :: FilePath -> IO String lines :: String -> [String]

Both of these functions are defined in Prelude. These two type signatures show the problem very clearly. readFile returns an IO String, but the lines function is expecting a String as its first argument. IO String != String. Somehow we need to extract the String out of the IO in order to pass it to the lines function. This is exactly what do notation was designed to help you with.

Solution #1 main :: IO () main = do contents <- readFile "myfile.txt" let lineList = lines contents -- ... do something with lineList here

This solution demonstrates two things about do notation. First, the left arrow lets you pull things out of the monad. Second, if you're not pulling something out of a monad, use "let foo =". One metaphor that might help you remember this is to think of "IO String" as a computation in the IO monad that returns a String. A do block lets you run these computations and assign names to the resulting pure values.

Solution #2

We could also attack the problem a different way. Instead of pulling the result of readFile out of the monad, we can lift the lines function into the monad. The function we use to do that is called liftM.

liftM :: Monad m => (a -> b) -> m a -> m b liftM :: Monad m => (a -> b) -> (m a -> m b)

The associativity of the -> operator is such that these two type signatures are equivalent. If you've ever heard Haskell people saying that all functions are single argument functions, this is what they are talking about. You can think of liftM as a function that takes one argument, a function (a -> b), and returns another function, a function (m a -> m b). When you think about it this way, you see that the liftM function converts a function of pure values into a function of monadic values. This is exactly what we were looking for.

main :: IO () main = do lineList <- liftM lines (readFile "myfile.txt") -- ... do something with lineList here

This is more concise than our previous solution, so in this simple example it is probably what we would use. But if we needed to use contents in more than one place, then the first solution would be better.

Problem: Making pure values monadic

Consider the following program:

import Control.Monad import System.Environment main :: IO () main = do args <- getArgs output <- case args of [] -> "cat: must specify some files" fs -> liftM concat (mapM readFile fs) putStrLn output

This program also has an error. GHC actually gives you three errors here because there's no way for it to know exactly what you meant. But the first error is the one we're interested in.

Couldn't match type `[]' with `IO' Expected type: IO Char Actual type: [Char] In the expression: "cat: must specify some files"

Just like before, this error tells us exactly what's wrong. We're supposed to have an IO something, but we only have a String (remember, String is the same as [Char]). It's not convenient for us to get the pure result out of the readFile functions like we did before because of the structure of what we're trying to do. The two patterns in the case statement must have the same type, so that means that we need to somehow convert our String into an IO String. This is exactly what the return function is for.

Solution: return return :: a -> m a

This type signature tells us that return takes any type a as input and returns "m a". So all we have to do is use the return function.

import Control.Monad import System.Environment main :: IO () main = do args <- getArgs output <- case args of [] -> return "cat: must specify some files" fs -> liftM concat (mapM readFile fs) putStrLn output

The 'm' that the return function wraps its argument in, is determined by the context. In this case, main is in the IO monad, so that's what return uses.

Problem: Chaining multiple monadic operations import System.Environment main :: IO () main = do [from,to] <- getArgs writeFile to $ readFile from

As you probably guessed, this function also has an error. Hopefully you have an idea of what it might be. It's the same problem of needing a pure value when we actually have a monadic one. You could solve it like we did in solution #1 on the first problem (you might want to go ahead and give that a try before reading further). But this particular case has a pattern that makes a different solution work nicely. Unlike the first problem, you can't use liftM here.

Solution: bind

When we used liftM, we had a pure function lines :: String -> [String]. But here we have writeFile :: FilePath -> String -> IO (). We've already supplied the first argument, so what we actually have is writeFile to :: String -> IO (). And again, readFile returns IO String instead of the pure String that we need. To solve this we can use another function that you've probably heard about when people talk about monads...the bind function.

(=<<) :: Monad m => (a -> m b) -> m a -> m b (=<<) :: Monad m => (a -> m b) -> (m a -> m b)

Notice how the pattern here is different from the first example. In that example we had (a -> b) and we needed to convert it to (m a -> m b). Here we have (a -> m b) and we need to convert it to (m a -> m b). In other words, we're only adding an 'm' onto the 'a', which is exactly the pattern we need here. Here are the two patterns next to each other to show the correspondence.

writeFile to :: String -> IO () a -> m b

From this we see that "writeFile to" is the first argument to the =<< function. readFile from :: IO String fits perfectly as the second argument to =<<, and then the return value is the result of the writeFile. It all fits together like this:

import System.Environment main :: IO () main = do [from,to] <- getArgs writeFile to =<< readFile from

Some might point out that this third problem is really the same as the first problem. That is true, but I think it's useful to see the varying patterns laid out in this cookbook style so you can figure out what you need to use when you encounter these patterns as you're writing code. Everything I've said here can be discovered by carefully studying the Control.Monad module. There are lots of other convenience functions there that make working with monads easier. In fact, I already used one of them: mapM.

When you're first learning Haskell, I would recommend that you keep the documentation for Control.Monad close by at all times. Whenever you need to do something new involving monadic values, odds are good that there's a function in there to help you. I would not recommend spending 10 hours studying Control.Monad all at once. You'll probably be better off writing lots of code and referring to it whenever you think there should be an easier way to do what you want to do. Over time the patterns will sink in as form new connections between different concepts in your brain.

It takes effort. Some people do pick these things up more quickly than others, but I don't know anyone who just read through Control.Monad and then immediately had a working knowledge of everything in there. The patterns you're grappling with here will almost definitely be foreign to you because no other mainstream language enforces this distinction between pure values and side effecting values. But I think the payoff of being able to separate pure and impure code is well worth the effort.

Categories: Offsite Blogs

Why are record field lenses the opposite of every other lens?

Haskell on Reddit - Wed, 01/21/2015 - 4:34am

After getting into lenses a bit one thing stuck out for me [1]: all the "built-in" lenses seem to start with _ (e.g. _1, _2, _left, etc.) but with records this is exactly reversed: the actual field starts with _ but its lens does not.

Is there any reason for this? Is it under consideration to flip this for consistency?

[1] I don't like the _ convention and would have preferred something like putting an L at the end, but it's probably far too prolific to think about now. Regardless, whatever the convention is, it would be nice if it were completely consistent.

submitted by nicheComicsProject
[link] [7 comments]
Categories: Incoming News - Wed, 01/21/2015 - 1:21am
Categories: Offsite Blogs - Wed, 01/21/2015 - 1:21am
Categories: Offsite Blogs

Question about understanding type inference rules.

Haskell on Reddit - Wed, 01/21/2015 - 12:28am

I've been rereading about type inference rules lately and on thing that has always puzzled me is the difference between an implication symbol and a comma when describing a type context Gamma. For example in some cases a rule will say:

Gamma ⊢ x : T

This makes sense as the context gamma implies x has type T. But in some cases you will see, for example:

Gamma, y : S ⊢ x : T Which I understand to mean that the context Gamma with the added assumption y has type S implies x has type T. My question is why not say: Gamma ⊢ x : T, y : S

Is it because the assumption for y is being provided by the rule, meaning S is a new type variable?


submitted by biglambda
[link] [13 comments]
Categories: Incoming News

Kevin Reid (kpreid): A Visual Introduction to DSP for SDR — now live in your browser!

Planet Haskell - Tue, 01/20/2015 - 10:51pm

My interactive presentation on digital signal processing (previous post with video) is now available on the web, at! More details, source code, etc. at the site.

(P.S. I'll also be at the next meetup, which is tomorrow, January 21, but I don’t have another talk planned. (Why yes, I did procrastinate getting this site set up until a convenient semi-deadline.))

Categories: Offsite Blogs

Unit test that a particular expression *does not* compile?

Haskell on Reddit - Tue, 01/20/2015 - 9:27pm

I just came across this D library that does compile-time unit checking similar to units or dimensional. However, if you look at the test cases on that page, there are tests that actually check whether certain sub-expressions compile:

// Dimensional correctness is check at compile-time unittest { Mass mass; static assert(!__traits(compiles, mass = 15 * meter)); static assert(!__traits(compiles, mass = 1.2)); }

Instead of just testing desired behaviour, this explicitly makes sure that bad behaviour is disallowed at compile-time.

Is this something we could implement in Haskell, possibly using TH? It seems like a good idea for libraries which intend to expose a typesafe API, and verify that bad behaviour is illegal at compile-time.

submitted by theonlycosmonaut
[link] [7 comments]
Categories: Incoming News

Why does that work but not this?

Haskell on Reddit - Tue, 01/20/2015 - 8:36pm

[x/4 | x <-- [0..100], x mod 4 == 0]

doesn't work

but this

[x*4 | x <-- [0..100], x mod 4 == 0]

works. Why?

submitted by SnakeNoir
[link] [3 comments]
Categories: Incoming News

"Found hole"

glasgow-user - Tue, 01/20/2015 - 8:36pm
Hello! What is a "hole"? This program fails to compile: main = _exit 0 I get this error message: ex.hs:1:8: Found hole ‘_exit’ with type: t Where: ‘t’ is a rigid type variable bound by the inferred type of main :: t at ex.hs:1:1 Relevant bindings include main :: t (bound at ex.hs:1:1) In the expression: _exit In an equation for ‘main’: main = _exit When I replace "_exit" with "foo", it produces a "not in scope" error, as expected. What is special about "_exit"? It doesn't occur in the Haskell Hierarchical Libraries. Bye Volker _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users< at >
Categories: Offsite Discussion

Robin KAY: HsQML released: Control those Contexts

Planet Haskell - Tue, 01/20/2015 - 5:17pm
Happy New Year! Another year and another new release of HsQML is out, the Haskell binding to the Qt Quick framework that's kind to your skin. As usual, it's available for download from Hackage and immediate use adding a graphical user-interface to your favourite Haskell program.

The major new feature in this release is the addition of the OpenGLContextControl QML item to the HsQML.Canvas module. Previously, the OpenGL canvas support introduced in left programs at the mercy of Qt to configure the context on their behalf and there was no way to influence this process. That was a problem if you want to use the latest OpenGL features because they require you to obtain a newfangled Core profile context whereas Qt appears to default to the Compatibility profile (or just plain OpenGL 2.x if that's all you have).

To use it, simply place an OpenGLContextControl item in your QML document inside the window you want to control and set the properties to the desired values. For example, the following snippet of code would request the system provide it with a context supporting at least the OpenGL 4.1 Core profile:

import HsQML.Canvas 1.0

OpenGLContextControl {
    majorVersion: 4;
    minorVersion: 1;
    contextType: OpenGLContextControl.OpenGL;
    contextProfile: OpenGLContextControl.CoreProfile;
The supported properties are all detailed in the Haddock documentation for the Canvas module. There's also a more sophisticated example in the corresponding new release of the hsqml-demo-samples package. This example, hsqml-opengl2, displays the current context settings and allows you to experiment with requesting different values.

This graphics chip-set has seen better days.
Also new in this release, i) the defSignalNamedParams function allows you to give names to your signal parameters and ii) the EngineConfig record has been extended to allow setting additional search paths for QML modules and native plugins..

The first point is an interesting one because, harking back, my old blog post on the Connections item, doesn't actually demonstrate passing parameters to the signal handler and that's because you couldn't ordinarily. You could connect a function to the signal manually using the connect() method in QML code and access arguments positionally that way, or written the handler to index into the arguments array for it's parameters if you were willing to stoop that low. Now, you can give the parameters names and they will automatically be available in the handler's scope.

Finally, the Template Haskell shims inside Setup.hs have been extended to support the latest version of the Cabal API shipping with version 1.22. The Template-free SetupNoTH.hs remains supporting 1.18 ≤ n < 1.22 will continue to do so at least until Debian upgrades their Cabal package. Setup.hs will now try to set QT_SELECT if you're running a recent enough version of GHC to support setting environment variables and this can prevent some problems with qtchooser(1).

release- - 2015.01.20

  * Added support for Cabal 1.22 API.
  * Added facility for controlling the OpenGL context.
  * Added defSignal variant with ability to set parameter names.
  * Added option for setting the module and plugin search paths.
  * Changed Setup script to set QT_SELECT (base >= 4.7).
  * Fixed crash resizing canvas in Inline mode.
  * Fixed leaking stable pointers when objects are collected.
  * Fixed Canvas delegate marshaller to fail on invalid values.
  * Fixed discrepancy between kinds of type conversion.
Categories: Offsite Blogs

New Student to Haskell

Haskell on Reddit - Tue, 01/20/2015 - 3:25pm

Hey guys,

First off, I've never posted on here before, so I hope I'm doing this correctly.

Anyways I was wondering how I, as a new student, can expand my knowledge/familiarity with what haskell can be used for in the real world. My haskell class that I'm taking is kinda slow for me and my experience with coding, so I want to get a head start with some personal projects. Unfortunately, I'm not sure where to find exercises/projects that I can solve with haskell on my own, and I was hoping someone could point me in the right direction.

Basically, I'm asking what small project can I create using Haskell? A video game? A database? Something on a website?

I don't know much about Haskell, or functional programming, since I am mostly familiar with object oriented Java and Python, so again, not sure what to pursue to fully understand this aspect of the programming language.

I know I can read books and articles and such but for me and many other programmers I know, the best way to learn is to program in the language itself.

So again, I'm looking for what I can pursue as a small project to help me get ahead with familiarity with the language.

Any references or examples to get started would be much appreciated.

Thanks! -President

submitted by Clown_For_President
[link] [20 comments]
Categories: Incoming News

Philip Wadler: Democracy vs the 1%

Planet Haskell - Tue, 01/20/2015 - 2:37pm

To celebrate the 750th anniversary of the first meeting of the British parliament, the BBC Today programme sponsored a special edition of The Public Philosopher, asking the question Why Democracy? The programme spent much time wondering why folk felt disenfranchised but spent barely two minutes on the question of how wealth distorts politics. (Three cheers to Shirley Williams for raising the issue.) An odd contrast, if you compare it to yesterday's story that the wealthiest 1% now own as much as the other 99% combined; or to Lawrence Lessig's Mayday campaign to stop politicians slanting their votes to what will help fund their reelection; or to Thomas Picketty's analysis of why the wealthy inevitably get wealthier. (tl;dr: "Piketty's thesis has been shorthanded as r > g: that the rate of return on capital today -- and through most of history -- has been higher than general economic growth. This means that simply having money is the best way to get more money.")
Categories: Offsite Blogs


haskell-cafe - Tue, 01/20/2015 - 2:33pm
Hi! I'm working with a lot of HashMap's and it's very frustrating how many times I've "lost" my data because of usage of either a Monoid instance of a HashMap (which is defined as H.union, which, upon collision, takes value from first hm and discards from second), or just using fromList in the wrong place. Whereas the data I'm working is is mostly defined as (Monoid v => HashMap k v), so what I need "by default" is actually something like `H.unionWith (<>)`. What I was wondering is this: is something like MonoidHashMap is desired to be in unordered-containers, or is this use-case only popular in my programs? I'm asking because I have a feeling that this thing might be useful quite a lot for others also. If not -- sorry for bothering :) Cheers! _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion