News aggregator

Is `network` library poorly implemented or am I misunderstanding the problem?

Haskell on Reddit - Wed, 12/03/2014 - 4:04am

Hi all,

Sorry for ranty post -- I'm very frustrated by some of the things in Haskell. I think there are some very widely-used(like, ten thousand downloads per month) libraries that are broken/poorly implemented and I'd like to understand how come nobody complains about some problems in those very, very widely used libraries. It may also be that the library is fine and I'm misusing it, in that case I'd like to learn how to use it.

The library in question is network: http://hackage.haskell.org/package/network

I've recently been playing with a network application and I'm using this library. What my application does is that it opens some TCP and UDP sockets and talk with lots of other clients in the wild.

What happens when I run my client is that all network functions fail in subtle, undocumented, untraceable and impossible to handle ways. Furthermore, existing documentation is also wrong/bad. I think it's not possible to write any "safe" applications using this library. (while native bindings allow that)

So I think the library is deeply broken and doesn't allow to write stable software.

I wrote a long post with details and examples here: https://github.com/haskell/network/issues/151 and the maintainer looked like in agreement with me at least for some subset of my points. However it looks like the library is not actively maintained. So we can't even fix it. (and then there are problems with backwards-compatibility)

I thought about forking and doing things my way, but didn't do that so far because 1) I'm not a systems/network programming guy so I have to spend a lot of time learning things(especially the BSD socket API) 2) I don't want to start doing that before asking to people in case I'm misunderstanding/misusing the library and the problem is actually me.

So my questions are:

  1. Am I doing something wrong or is the library poorly implemented/broken? (please see the Github discussion)
  2. If it's the library's problem, how come nobody complains about this? It's not possible to write stable software with this library and it's downloaded 18113 times in last 30 days!
  3. If it's the library's problem, how can we fix/improve it?
submitted by semanticistZombie
[link] [70 comments]
Categories: Incoming News

School of Haskell | FP Complete

del.icio.us/haskell - Wed, 12/03/2014 - 3:03am
Categories: Offsite Blogs

Vim - HaskellWiki

del.icio.us/haskell - Wed, 12/03/2014 - 3:03am
Categories: Offsite Blogs

IDEs - HaskellWiki

del.icio.us/haskell - Wed, 12/03/2014 - 3:03am
Categories: Offsite Blogs

Yesod Web Framework: Yesod's new scaffolding

Planet Haskell - Wed, 12/03/2014 - 12:00am

After lots of discussion and testing, I'm happy to announce a significant update to the Yesod scaffolded site. You can see some mailing list discussions on this at:

The newest version of yesod-bin (and all versions going forward) will ship with this newly minted scaffolding. There is no migration guide for existing sites; scaffoldings aren't the kind of things to be easily migrated, and all existing sites will continue to function due to lack of breaking API changes. Nonetheless, if people are excited enough about these changes that they'd like to integrate them into their existing sites, please start up a discussion on the mailing list.

The primary motivation in this change is an overhaul to the settings system. The new system is much more modular regarding environment variables, config files, and hard-coded settings. It's also much simpler to determine where a setting value comes from, and to configure things differently in different environments. Since I've already described these changes in quite some detail, I will instead point you to the second mailing list thread linked above.

To give an example of how this works, take a look at the following lines from the new settings.yml file:

host: "_env:HOST:*4" # any IPv4 host port: "_env:PORT:3000" approot: "_env:APPROOT:http://localhost:3000"

In the old scaffolding, both PORT and APPROOT were recognized environment variable names, that would override whatever was defined in settings.yml. However, that overriding occurred in a library (Yesod.Default.Config) and was not obvious to users, which led to many bug reports/support questions. Additionally, there was no way to override the host/interface binding via environment variables. In the new system:

  • It's obvious from reading the config file which settings can be overridden via environment variables, and what the names of those variables are.
  • It's trivial to change the names, or disable environment variable overriding (e.g., replace the approot line with approot: http://localhost:3000).
  • New arbitrary settings can be added at will, and easily use environment variables to override their values.

The other change is that we've replaced the ad-hoc Import prelude replacement previously found in the scaffolding with ClassyPrelude.Yesod. For users not interested in classy-prelude, it should be trivial to replace import ClassyPrelude.Yesod with import Prelude, import Yesod, and whatever else you want. Greg has also spent quite some time in the past week improving the documentation for both classy-prelude and mono-traversable, which will help things out considerably.

Besides that, I've done a bunch of minor maintenance on the scaffolding, cleaning up import lists, adding some missing documentation, and so on.

Like any new release, it's certainly possible that there are some issues, so if you notice any, please feel free to bring them up. Also, documentation fixes are great as well. As always, please send any pull requests against the postgres branch of the yesod-scaffold repo, from which we automatically merge changes to all other versions of the scaffolding.

Categories: Offsite Blogs

Douglas M. Auclair (geophf): November 2014 1HaskellADay Problems and Solutions

Planet Haskell - Tue, 12/02/2014 - 11:50pm

November 2014
  • November 3st, 2014: Let it snow, let it snow, let it ... lambda for today's #haskell problem http://lpaste.net/113682 ... and the answer is Snow Mittens for Snow Kittens! YAY! http://lpaste.net/113716
  • November 4nd, 2014: At the First National Bank the MEN like to play chess with each other http://lpaste.net/113734 Today's #haskell problem. Men in banks like playing chess with each other http://lpaste.net/113775 come to find in the solution to today's #haskell logic puzzle
  • November 5th, 2014: Doin' the spiral from projecteuler.net, problem 28, for today's #haskell puzzler lpaste.net/113798 Heh, I actually spiraled out to the solution for today's #haskell problem. http://lpaste.net/113111
  • November 6th, 2014: From @BenVitale funwithnumb3rs site, we have a, b, and c ... and how simple can today's #haskell problem be? ;) http://lpaste.net/113846It's as easy as 1, 2, 3! is our solution http://lpaste.net/113849 to today's problem
  • November 7th, 2014: Making sensical tweets for #ingress for today's #haskell problem http://lpaste.net/113886 A semantical romp through syntax (that is: the solution) is posted at http://lpaste.net/113908
  • November 10th, 2014: As I embark on my morning commute, I share today's #haskell problem about ... the morning commute! http://lpaste.net/114038 To get to the solution ya gotta keep on truckin' http://lpaste.net/114068
  • November 11th, 2014: Some Coin sums. In for a penny, in for a £ for today's #haskell problem http://lpaste.net/114089 Solution coded, but is it the correct one for counting coins? lpaste.net/113284 How did you do it? HA! I found the problem with my counting-coins solution! Redundancies! Updated solution at http://lpaste.net/113284
  • November 12th, 2014: Squares, Cubes and Triangles masquerade as numbers in today's #haskell problem http://lpaste.net/114158 The square by a cube of a triangle is our digit-picking solution to today's math puzzle http://lpaste.net/114194
  • November 13th, 2014: It's all about making the grade. I MEANT: 'THE SEARCH FOR TRUTH'! Yeah, THAT's what I meant. Not: 'making the grade.' http://lpaste.net/114233 Translation: Today's #haskell problem is about making the grade. I MEANT 'SEEKING KNOWLEDGE'! Yeah. That's what I meant. *blush* Isabella makes the grade in today's equational solution lpaste.net/114248 (rant by @geophf provided free of charge).
  • November 14th, 2014: 0h, h1 there! for today's #haskell puzzle http://lpaste.net/114276 
  • Our bonus solution is coded here (http://lpaste.net/114304), and looks like this:



  • November 17th, 2014: The in-laws bump into Amy and her baby in the perambulator on her daily stroll for today's #haskell problem http://lpaste.net/114430 For today's solution we find a really roundabout way to say 'brother-in-law' http://lpaste.net/114460 And the bonus solution(http://lpaste.net/114461) we graph it with Neo4J:

  • November 18th, 2014: Would you like some chips with that Fish? The #haskell puzzler for today is a 'SOLE' word-square http://lpaste.net/114433 Sole Open Ends Lead! A newspaper-escque headline-y-like solution to today's Haskell puzzler http://lpaste.net/114522
  • November 19th, 2014: Next Mensa puzzler for today's #haskell problem. Who gotfirst place in the science fair? http://lpaste.net/114559 Woman Power! A solution to today's Haskell puzzler http://lpaste.net/114583
  • November 20th, 2014: "Trick or treat!" But how many bags of candy did the new cashier, to be named later, sell? Solve this lpaste.net/114620 to let her know. The solution is posted here (http://lpaste.net/114635) and graphed out ... for 'funzies.'
  • November 21st, 2014: Her Majesty, Queen Victoria (Vicky or Maj to her buds) (not really), has a #haskell poem-puzzler for you: http://lpaste.net/114436 (Standard disclaimer: we make no representation of reigning monarchs, living or dead, implied or otherwise. Besides... the Queen has no buds.) So, that brings to mind two thoughts, or pensées: 
  1. you see how I used the royal-'we' there? ;)
  2. 2) How sad to be Queen, and have no buds :(
    (@1HaskellADay In which it is learned it is a sadness to be Queen, to have no buds withal. :( *sniffle*) The 'clever' solution (http://lpaste.net/114733) comes even with its own 'TA-DAH!' ... gratis. You're welcome.

    • November 24th, 2014: Circular primes, from projecteuler.net, is today's #haskell puzzler: http://lpaste.net/114816. A solution to the circular primes problem is posted at http://lpaste.net/114817 
    • November 25th, 2014: Have a well-ordered (re)presentation of today's #haskell problem http://lpaste.net/114999  Suffice to say: today's 'date' is 'fig.' geddit? ;) A solution is a (sorta) logical calendar http://lpaste.net/115036 
    • November 26th, 2014: Got a question for ya! for today's Haskell problemlpaste.net/115096 1-9 in so many ways http://lpaste.net/115129
    • November 27th, 2014: Happy Thanksgiving to all you Haskell aficionados out there! Today's #haskell puzzle set involves da turkeyzzzz! http://lpaste.net/115184 That there is a lot of turkey! http://lpaste.net/115272
    • November 28th, 2014: Black Friday. OKAY, FOLKS! TODAY, AND _ONLY_ TODAY, EVERYTHING IS ON SAAAAAAAALLLLEEEE! http://lpaste.net/115229 Today's Black Friday #haskell problem. THESE PRICES ARE ...INSAAAAANNNNEEE! http://lpaste.net/115294 A solution to today's Black Friday logic puzzle.
    Categories: Offsite Blogs

    Let's Build a Browser Engine in Haskell: not a blog post

    Haskell on Reddit - Tue, 12/02/2014 - 11:24pm

    Hey guys, when I made my last post I mentioned that I was thinking about rewriting the layout code with lenses to reduce clutter. I've now done so and I'm still not very happy with the result (lenses are super ugly), so I thought I'd see how people felt about it before deciding to move forward with it or stick with the old code.

    The new code is in the lens branch on github, but most important changes are in Layout.hs

    submitted by Hrothen
    [link] [27 comments]
    Categories: Incoming News

    Learn You an Agda

    Haskell on Reddit - Tue, 12/02/2014 - 9:22pm
    Categories: Incoming News

    What is a fast, recursive getter for a balanced binary tree?

    Haskell on Reddit - Tue, 12/02/2014 - 7:45pm
    data Tree = Node Tree Tree | Leaf a get :: Int → Tree a -- Tree is always balanced (can you encode that with types?) get n tree = ??? main = print $ get 2 (Node (Node (Leaf 10) (Leaf 20)) (Node (Leaf 30) (Leaf 40))) // desired output: 30

    Does anyone know how to make this function fast? I was thinking in dividing n by 2 until it is zero and taking the left/right path based on mod n 2, but I guess that is not how I'm supposed to do it?

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

    data ConstFunction a b = ConstantCF b | FunctionCF (a -> b)

    Haskell on Reddit - Tue, 12/02/2014 - 7:29pm

    Does anything like this exist in any of the more mainstream libraries? It has a ton of useful class instances which I can't be bothered to write.

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

    Oliver Charles: 24 Days of GHC Extensions: Pattern Synonyms

    Planet Haskell - Tue, 12/02/2014 - 6:00pm

    Continuing yesterday’s theme of binding extensions, as I like to call them, today we’re going to look at pattern synonyms. Previously, we saw how view patterns allow us to view data through the result of function application. This allowed us to keep some of the definition of the data type abstract, while presenting an easy-to-use interface to API users. However, we noted that there was a syntactic cost - view patterns require the user to learn new syntax.

    Today, we’ll look at a brand new extension to GHC - pattern synonyms. Pattern synonyms were introduced in GHC 7.8, and they allow us to give names to pattern matches. This allows us to keep code maintainable, introduce new abstractions, and even pattern match values as if they were ordinary data definitions. This sounds somewhat magical, so lets dive right in and look at examples.

    Pattern Synonyms As Constants

    Perhaps the most basic use of pattern synonyms is as a tool to replace magic constants in code. When working with foreign code, for example from C libraries, enumerations are often loosely typed as an integer. As an example, let’s look at the SDL library. In this library, there are C routines such as

    int SDL_SetRenderDrawBlendMode(SDL_Renderer* renderer, SDL_BlendMode blendMode)

    Looking at the documentation, we see that SDL_BlendMode is just an enum - so what we’re actually passing around at runtime is a number - a CInt. This is a little clunky, and it’s idiomatic Haskell to move constants into a ADT:

    data BlendMode = NoBlending | AlphaBlending | AdditiveBlending | ColourModulatedBlending toBlendMode :: BlendMode -> CInt toBlendMode NoBlending = #{const SDL_BLENDMODE_NONE} toBlendMode AlphaBlending = #{const SDL_BLENDMODE_BLEND} toBlendMode ... fromBlendMode :: CInt -> Maybe BlendMode fromBlendMode 0 = Just NoBlending fromBlendMode ...

    (Note that the #{const ...} syntax comes from hsc2hs).

    However, this abstraction comes with a cost - we have to do an actual runtime conversion between the two representations. It’s unfortunate that we have to pay this cost just to write idiomatic code.

    Fortunately, this cost goes away entirely when we use pattern synonyms:

    pattern NoBlending = #{const SDL_BLENDMODE_NONE} :: CInt pattern AlphaBlending = #{const SDL_BLENDMODE_BLEND} :: CInt pattern ...

    Here we see the definition of some new pattern synonyms. This indicates to GHC that any time you see a pattern match for NoBlending, we’re actually expecting a number, and that number should be equal to the SDL_BLENDMODE_NONE constant. This would allow us to write a function such as:

    setUpBlendMode :: CInt -> IO () setUpBlendMode AlphaBlending = do putStrLn "Enabling Alpha Blending" activateAlphaBlendingForAllTextures activateRenderAlphaBlending

    Here, we pattern match on a CInt, but we use a pattern synonym to give the constant a much more readable name. Astute readers might be a little concerned at this point - we still have to pattern match against values that don’t semantically make sense, because we are still pattern matching against a CInt. However, pattern synoyms play well with the rest of Haskell, so we can use a newtype to introduce more safety:

    newtype BlendMode = MkBlendMode { unBlendMode :: CInt } pattern NoBlending = MkBlendMode #{const SDL_BLENDMODE_NONE} pattern AlphaBlending = MkBlendMode #{const SDL_BLENDMODE_BLEND}

    Now we can hide the MkBlendMode constructor in our module, and export only the pattern synonyms. Thus we get all the benefits of an ADT, but without the runtime overhead! Very cool.

    Bidirectional Patterns

    So far, we’ve looked at how pattern synoyms can be used to help pattern matching. However, we can do more than this - bidirectional pattern synonyms also allow us to create data. For example, using the previous example, we already have the ability to send the correct integers to the SDL c library:

    setRenderAlphaBlending :: Renderer -> IO () setRenderAlphaBlending r = sdlSetRenderDrawBlendMode r (unBlendMode AlphaBlending)

    Here we use the AlphaBlending pattern synonym - a bidirectional pattern - to construct a value of type BlendMode - the newtype we defined earlier. We use unBlendMode to coerce the newtype back to the underlying CInt and hand this off to SDL. Very cool!

    This type of idea can be taken a lot further - in the linked blog post, Matthew Pickering shows us how we can use some seriously cutting edge features of pattern synonyms (not even released yet!) to work with so called “unfixed” versions of data types.

    icelandj embraces pattern synonyms to almost an absurd level in this FPComplete article to build an IRC bot - using patterns in a way that is very different to what you may be used to!

    Personally, I’m only just getting started with pattern synonyms myself - so I’m in the middle of a learning process to determine when they are useful. It seems when we are working with very generic data (as in Matt’s blog post) pattern synonyms really shine, but I find the patterns-as-constants usage a really nice trick too (first demonstrated to me by Edward Kmett in gl and later in sdl2).

    I see pattern synonyms as a tool to compliment view patterns. If you’re only using view patterns as a way to tidy up bindings, then there’s a good chance that pattern synonyms will be a better fit. However, view patterns have the advantage of being able to perform actual computations - something that (to the best of my knowlege) pattern synonyms cannot do.

    Have a play with them - see what you find! Code accompanying this blog post can be found on Github.

    This post is part of 24 Days of GHC Extensions - for more posts like this, check out the calendar.

    Categories: Offsite Blogs

    Haskell — is it growing?

    Haskell on Reddit - Tue, 12/02/2014 - 4:57pm

    Just a very simple question. Is Haskell a dying language? I note some events in my area (Australia) — AusHac — the last one was 2011.

    submitted by princearthur
    [link] [26 comments]
    Categories: Incoming News

    GHC Weekly News - 2014/12/01

    Haskell on Reddit - Tue, 12/02/2014 - 2:43am
    Categories: Incoming News