News aggregator

Announce: FRPNow-0.12

Haskell on Reddit - Wed, 07/15/2015 - 7:21am

We have released the (nearly) first version of FRPNow, the functional reactive programming library based on the ICFP 2015 paper "Principled Practical FRP: Forget the Past, Change the Future, FRPNow!".

The main package:


Gloss interoperability:

GTK interoperability:

(hackage doesn't like the newer GTK docs, so you can read the docs here)

submitted by atzeus
[link] [35 comments]
Categories: Incoming News

readMaybe for `ReadS a`

Haskell on Reddit - Wed, 07/15/2015 - 6:48am

So, in Text.Read, there is a function readMaybe. We all love this. Is there a similar function like this:

readMaybe :: Read a => String -> Maybe a -- actually exists readsMaybe :: ReadS a -> String -> Maybe a -- hypothetically could exist

I'm asking this because there are some handy read/show functions for RGB colors, but there is no safe way to read strings with them. If anyone knows of a library that provides this, that would be great.

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

Does Haskell have slow iteration times? Are those a problem?

Haskell on Reddit - Wed, 07/15/2015 - 5:32am

I was re-reading an old article today ( and remembered people complaining about Haskell slow compilation times (especially with frameworks like yesod).

This lead me to several questions:

  1. Do you have slow iteration (complie+test+run) times?
  2. How do you deal with that? Solutions?
  3. Do you find it negatively affects your productivity when the compile+test+execute cycle take longer?
  4. What are your solutions?
submitted by tmnt9001
[link] [85 comments]
Categories: Incoming News

Haskell & Java/Scala interoperbility?

haskell-cafe - Wed, 07/15/2015 - 3:14am
Hello, I have been looking at Hackage for a package/library that supports Haskell interoperability with Java/Scala. Didn't see any such support. If true, is there any project in the works? Thanks, Vasili
Categories: Offsite Discussion

Is this reasoning correct?

Haskell on Reddit - Wed, 07/15/2015 - 2:33am

Hello, I'm studying the fold functions and I have read that the recursive pattern abstracted by foldl is:

f v [] = v f v (x:xs) = f (v ⊕ x) xs

and the recursive pattern abstracted by foldr is:

f [] = v f (x:xs) = x ⊕ f xs

Now, I'm trying to see if the foldl pattern can be expressed as the foldr pattern following these steps:

let g = f v (x ⊛ v) = (x (flip ⊕) v) = (v ⊕ x) then f v [] = v f v (x:xs) = f (v ⊕ x) xs becomes g [] = v g (x:xs) = f (x ⊛ v) xs which then I can rephrase g [] = v g (x:xs) = (x ⊛ v) `f` xs

If I could somehow group v and f I would get:

g [] = v g (x:xs) = x ⊛ g xs

which is where I'm trying to get but I don't know any property that would let me do that which makes me ask: Am I doing some step wrong? Or simply those patterns aren't equivalent and the whole thing is pointless?


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

Are sandboxes relevant to stack?

Haskell on Reddit - Wed, 07/15/2015 - 12:32am

I'm still wrapping my head around how stack works. Coming from cabal, I understand sandboxes are a cabal thing, does stack obviate the need for them (if so, how)? Can stack interact with sandboxes?

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

Just getting started - What are you recommended tools/editors/OS for developing with Haskell?

Haskell on Reddit - Tue, 07/14/2015 - 11:53pm

I'm totally new to Haskell, though I've worked with ML and Racket in the past. I wanted to impart upon the wisdom of /r/haskell, and see what recommended tools, editors, and development environments exist for this language.

I'm currently using gVim or Notepad++ on Windows, but would be interested in switching to Linux if it offers a better developer experience.

I've also tried using SublimeText3 on Windows, but have had some integration issues when installing packages with cabal that ST3 needs.

submitted by komplete
[link] [29 comments]
Categories: Incoming News

Is it possible to create a data type that can take any number of type parameters?

Haskell on Reddit - Tue, 07/14/2015 - 10:49pm

Lets say I want to create a datatype for vectors, is it possible to make it so the type constructor can take any number of values so you can make any size vector?

submitted by Grantselrich
[link] [5 comments]
Categories: Incoming News

Christopher Done: Use the REPL, Luke

Planet Haskell - Tue, 07/14/2015 - 6:00pm

There was an online discussion about iteration times in Haskell and whether and why they are slow. For me, it’s not slow. I do all my Haskell development using a REPL. Here are some tips I wrote up in that discussion.

Prepare for GHCi use

The first thing you want to do before writing anything for your project is make sure you can load your code in the REPL; GHCi. Sometimes you have special configuration options or whatnot (cabal repl and stack ghci make this much easier than in the past). The sooner you start the better. It can be a PITA to load some projects that expect to just be a “start, run and die” process, they often launch threads without any clean-up procedure; in this way the REPL makes you think about cleaner architecture.

Make sure it scales

Learn how to make GHCi fast for your project so that you don’t hit a wall as your project scales. Loading code with byte-code is much faster than object code, but loading with object code has a cache so that in a 100 module project if you only need to reload one, it’ll just load one. Make sure this is happening for you, when you need it. Dabble with the settings.

Write small, parametrized functions

Code that is good for unit tests is code that is good for the REPL. Write small functions that take state as arguments (dependency injection) rather than loading their own state, then they can be ran in the REPL and used in a test suite easily. Regard functions that you can’t just call directly with suspicion.

Test work-in-progress implementations in the REPL

While writing, test your function in the REPL with typical arguments it will expect, rather than implementing a function and then immediately using it in the place you want to ultimately use it. You can skip this for trivial “glue” functions, but it’s helpful for non-trivial functions.

Setup/teardown helpers

Write helpful setup/teardown code for your tests and REPL code. For example, if you have a function that needs a database and application configuration to do anything, write a function that automatically and conveniently gets you a basic development config and database connection for running some action.

Make data inspectable

Make sure to include Show instances for your data types, so that you can inspect them in the REPL. Treat Show as your development instance, it’s for you, don’t use it for “real” serialization or for “user-friendly” messages. Develop a distaste for data structures that are hard to inspect.

Figure out the fastest iteration for you

Use techniques like :reload to help you out. For example, if I’m working on hindent, then I will test a style with HIndent.test chrisDone "x = 1", for example, in the REPL, and I’ll see the output pretty printed as Haskell in my Emacs REPL. But I work on module HIndent.Style.ChrisDone. So I first :load HIndent and then for future work I use :reload to reload my .ChrisDone changes and give me the HIndent environment again.


Make sure you know about the .ghci file which you can put in your ~/ and also in the project directory where GHCi is run from. You can use :set to set regular GHC options including packages (-package foo) and extensions (-XFoo), and any special include directories (-ifoo).

More advanced tricks

Consider tricks like live reloading; if you can support it. I wrote an IRC server and I can run it in the REPL, reload the code, and update the handler function without losing any state. If you use foreign-store you can make things available, like the program’s state, in an IORef or MVar.

This trick is a trick, so don’t use it in production. But it’s about as close as we can get to Lisp-style image development.

In summary

Haskell’s lucky to have a small REPL culture, but you have to work with a Lisp or Smalltalk to really know what’s possible when you fully “buy in”. Many Haskellers come from C++ and “stop program, edit file, re-run compiler, re-run whole program” cycles and don’t have much awareness or interest in it. If you are such a person, the above probably won’t come naturally, but try it out.

Categories: Offsite Blogs

Bryn Keller: Higher Order Type Theory Resources

Planet Haskell - Tue, 07/14/2015 - 6:00pm

Recently there’s been an outpouring of useful resources folks have found for learning Homotopy Type Theory (aka HoTT). These have come mainly from the HoTT Cafe Google Group.

The main resource is of course, the book, but these videos and other resources seem useful enough that I want a consolidated list of them for myself. So I thought maybe you might, too.

Group threads that provided these links:

Note that I’m likely to update this page in the future with other resources as I find them, and those links may or may not come from the Groups threads just mentioned.

Useful resources, in no particular order:


Categories: Offsite Blogs

Saving functions

Haskell on Reddit - Tue, 07/14/2015 - 3:10pm

Stumbled upon the spoon package. I wanted to see if I could make it work for functions instead of just values. After fiddling around with functional dependencies I've managed to get something that works! The code is very short so I'll post the whole thing.

{-# LANGUAGE FlexibleContexts , FlexibleInstances , UndecidableInstances , TypeFamilies , FunctionalDependencies #-} module Control.Safezone where import qualified Control.Exception as Exc import System.IO.Unsafe {-# NOINLINE unsafeCleanup #-} unsafeCleanup :: a -> Maybe a unsafeCleanup x = unsafePerformIO $ Exc.catch (x `seq` return (Just x)) handler where handler :: Exc.ErrorCall -> IO (Maybe a) handler _ = return Nothing class Save f g | f -> g where save :: f -> g instance {-# OVERLAPPABLE #-} (b ~ Maybe a) => Save a b where save = unsafeCleanup instance Save f g => Save (a -> f) (a -> g) where save f x = save (f x) unsafeDiv :: Double -> Double -> Double unsafeDiv x y | y /= 0 = x / y | y == 0 = error "Dividing by zero" --safeDiv :: Double -> Double -> Maybe Double safeDiv = save unsafeDiv

The result is the magical save function that you can apply to any other function (of arbitrary arity) and it will wrap the END result of that function into a Maybe. Just when everything goes well, Nothing when there's an exception.

I'm not sure if there's any practical use case where this is advantageous over just spooning the return value but I guess it's at least more compact. As you can see it's about as offensive to safety as is gets. All it's lacking is TH :D

I've commented out the type signature of safeDiv to show that the type is successfully inferred.


I mean, come on. This is pretty neat stuff

safeRead :: Read a => String -> Maybe a safeRead = save read *Control.Safezone> safeRead "123" :: Maybe Int Just 123 *Control.Safezone> safeRead "123a" :: Maybe Int Nothing submitted by Darwin226
[link] [3 comments]
Categories: Incoming News

FRP and Modifying List Elements

Haskell on Reddit - Tue, 07/14/2015 - 1:46pm

I'm working on a web application right now that uses reflex-dom as a part of the client-side solution. You can see a screenshot here:

The application models a stack of switches, each of which may have many ports. A port can be added to multiple VLANs. You can also set zero or one VLANs to untag for each port. It isn't a super-complicated problem, and I already have a partially working solution. I'm trying to figure out how to improve the flow of data.

All my prior FRP experience is with elm, which recommends the model-update-view pattern. This works very well for a lot of things, but one situation where I feel confused is what to do when you have a list of a hundred or so items, each of which can be changed.

You could do it this way:

  • Model: List of items
  • Update: Index along with single item
  • View: Stuff to display the list

This feels alright, but applying the update to the model feels weird. You have to unsafely index into the list and then replace the item, which in both haskell and elm would mean that most of the list might be reconstructed. (I'm not sure if this would cause all of the ports to be updated in the view. It probably depends on the FRP implementation). Anyway, if any FRP gurus have any insights, or if anyone has worked on a similar problem, I'd really appreciate hearing thought on how to model this situation.

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

Wai support for HTTP/2

Haskell on Reddit - Tue, 07/14/2015 - 12:00pm
Categories: Incoming News

About the name stack

Haskell on Reddit - Tue, 07/14/2015 - 11:32am

There has been lots of discussion about the name stack from the beginning of the project. Firstly, I'm glad everyone cares so much about the project to invest so much thought into what it should be called! And there have been quite a number of very valid concerns raised about the name stack, and by a large number of people.

Based on quite a bit of experience myself and others on the stack team have, I think it's fair to say that no name will be perfect. I can point to specific examples where a name has been criticized for one reason or another, but it's not going to be terribly enlightening. Instead, let me point out some of the points that made us all agree initially with using the name stack:

  • It's short and easily pronounceable
  • It lends itself nicely to having the same package name and executable name, plus module hierarchy for the library
  • It's not a clever pun or recursive acronym (yes, this is a point in favor of stack)
  • It's an unused name in the command line tool space from all searches we did
  • It's easily searchable when using the phrase (which I mentioned from the beginning) "Haskell tool stack". As it turns out, now even "Haskell stack" is sufficient to get good results on most search engines
  • The word has a meaning not completely divorced from its purpose: it's a tool stack, and it's a tool, stack
  • It is a root of Stackage, which is both an inspiration for and an optional dependency for stack

Do these positives discredit the negatives raised by others? Absolutely not. I agree that if we chose something completely unique in computer science there would be a reduction in some confusion in search results (though I haven't seen a proposal that meets or exceeds the other benefits listed above). If we chose a name based on cabal, it might make some people more easily understand the purpose of the project (though I think overall this would cause far more harm than good on the confusion front). If we chose something whimsical (e.g., I thought dude install yesod was cute), people would have more fun using the tool (at the expense of looking immature and be more confusing in spoken conversation). (Note: this list is not intended to be exhausitve, I know there were other concerns with the name stack too.)

If there was a name that was proposed that I honestly thought was a big improvement over stack, I would consider the switch. But I haven't seen it. And frankly, while we can still change the name stack, it's already something that people know, and changing the codebase, documentation, and references to the project is a non-zero cost. Therefore, I'd want the improvement to be a significant one in order to undertake such a change.

submitted by snoyberg
[link] [35 comments]
Categories: Incoming News

Different program behaviour from ghc and from cabal build?

Haskell on Reddit - Tue, 07/14/2015 - 10:34am

[SOLVED] - see final edit.

Hey guys. I'm writing a custom server using the network package. I didn't use a cabal file, just used ghc main and everything worked - when the server starts, it uses forkIO to start a couple of threads. One of these prints out messages to the console that it receives through a TChan (STM) from other threads. Another thread listens to incoming connections (Socket.accept), and sends connecting clients a welcome message. The server can be terminated by Ctrl-C.

But now I want to cabalize my project. I wrote a cabal file (using cabal init), and then built my project with cabal build. However, the resulting binary behaved differently - the logs that should be printed when the logger thread starts are not printed out (but if I want to print something from the main thread before forking, it gets displayed on the console), and incoming connections don't receive the welcome messages. However, if I don't spawn threads, and just accept a single client in the main thread, it gets accepted, and I can send it a message. I also can't terminate the server with Ctrl-C, I have to kill it from Task Manager.

I have tried adding -threaded and -O3 to ghc-options, but it didn't help.

It works correctly from ghci, or when using cabal exec runhaskell main.hs.

I'm on Windows 7 x64, and I use withSocketsDo in my code. GHC: 7.10.1, Cabal: I use network-

Is it a known problem?
Did I make some newbie mistake?
Does it have anything to do with blocking sockets?
Do you have any suggestions about what should I check, or what direction should I look for a solution?

I tried to google it, but found nothing of use.

Thank you in advance.

EDIT 1: Definitely some kind of flag is the cause of the problem. I'm trying to run the ghc invokation with groups of flags left out, and I have had success. Now I need to isolate which group of flags do I need to eliminate.

EDIT 2: It's the -O - the same happens with -O2 and -O3. But without optimization, everything works as it should. Interesting...

EDIT 3: I could reproduce the same error with a much smaller code on my machine. Below is a few lines of code, and if you just use ghc main to compile it, it should write out "Hey" forever, which you can stop by pressing Ctrl-C. However, if you use ghc -O main, it won't write out anything, and you have to kill the process through Task Manager.

module Main where import Control.Concurrent (forkIO) main :: IO () main = do _ <- forkIO $ runForever $ putStrLn "Hey" runForever $ return () runForever :: IO () -> IO () runForever action = action >> runForever action

FWIW Before I received the suggestion to use yield instead of return () from /u/gelisam (thank you again, you were a tremendous help to me!), I have filed a ticket to GHC about it. As it turns out, it is a long-standing, but rare bug, which can also be worked around by the flag -fno-omit-yields.

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

Why is Yesod so slow

Haskell on Reddit - Tue, 07/14/2015 - 9:35am

I was learning Haskell and I wanted to create a web for learning more but when I started using Yesod every time I modified a file even the templates took about 15 seconds to reload the changes this is so unproductive.

submitted by mrkaspa
[link] [56 comments]
Categories: Incoming News