News aggregator

Yesod Web Framework: Announcing: yesod-gitrepo

Planet Haskell - Wed, 10/29/2014 - 7:16am

I'm happy to announce the first release of a new package, yesod-gitrepo. This package encapsulates a pattern I've used a number of times, namely: loading and refreshing content from a Git repository. Below is the current contents of the README.md file.

This code is currently being used in production, and should be pretty stable. That said, it has not received a huge amount of battle testing yet. So please due test corner cases before shipping it in production for your site.

yesod-gitrepo provides a means of embedding content from a Git repository inside a Yesod application. The typical workflow is:

  • Use gitRepo to specify a repository and branch you want to work with.
  • Provide a function that will perform some processing on the cloned repository.
  • Use grContent in your Handler functions to access this parsed data.
  • Embed the GitRepo as a subsite that can be used to force a refresh of the data.
  • Set up a commit handler that pings that URL. On Github, this would be a webhook.

This is likely easiest to understand with a concrete example, so let's go meta: here's an application that will serve this very README.md file. We'll start off with language extensions and imports:

{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} import ClassyPrelude.Yesod import Text.Markdown import Yesod.GitRepo

Now we're going to create our foundation datatype. We need to give it one field: the GitRepo value containing our parsed content. Our content will simply be the text inside README.md, wrapped up in a Markdown newtype for easy rendering. This gives us:

data App = App { getGitRepo :: GitRepo Markdown } instance Yesod App

And now let's set up our routes. We need just two: a homepage, and the subsite. Our subsite type is GitRepo Markdown (as given above). We replace the space with a hyphen as an escaping mechanism inside Yesod's route syntax:

mkYesod "App" [parseRoutes| / HomeR GET /refresh RefreshR GitRepo-Markdown getGitRepo |]

Next up is our home handler. We start off by getting the current content parsed from the repository:

getHomeR :: Handler Html getHomeR = do master <- getYesod content <- liftIO $ grContent $ getGitRepo master

Then it's just some normal Hamlet code:

defaultLayout $ do setTitle "yesod-gitrepo sample" [whamlet| <p> <a href=@{RefreshR GitRepoRoute}> Force a refresh at @{RefreshR GitRepoRoute} <article>#{content} |]

And finally, our main function. We pass in the repo URL and branch name, plus a function that, given the filepath containing the cloned repo, processes it and generates a Markdown value. Finally, we provide the generated repo value to our App constructor and run it:

main :: IO () main = do repo <- gitRepo "https://github.com/snoyberg/yesod-gitrepo" "master" $ \fp -> fmap Markdown $ readFile $ fp </> "README.md" warp 3000 $ App repo

Give it a shot. You should have a webapp hosting this very README file!

Categories: Offsite Blogs

Discussion: adding displayException to Exception class

libraries list - Wed, 10/29/2014 - 12:43am
I don't want to make a format proposal yet, just open up discussion on an issue, and see how others feel about it. As I recently commented on this list[1], the Show typeclass is overloaded with multiple meanings (serialization, debug info, and user-friendly data display). The general consensus seems to be that the official semantics for Show should be for serialization (as paired up with Read). However, there's at least one use case in base which explicitly uses Show for non-serialization purposes: the Exception class. All instances of Exception are required to have an instance of Show, but there's no way to actually serialize exceptions generally[2]. So by construction and by practice, the Show instance for Exception is used exclusively for the latter two categories I mentioned (debug info and user-friendly data display). As a result of that, it's quite common[3] to define a Show instance for exception types that is *not* serializable, but rather user friendly. This however seems to contradict what is ac
Categories: Offsite Discussion

Job announcement: formal methods engineer and scientificdeveloper at FireEye

General haskell list - Tue, 10/28/2014 - 4:19pm
Dear all, [My excuses if see this email more than once] the FireEye R&D center in Dresden, Germany, seeks outstanding formal-methods experts and scientific programmers to join FireEye's formal methods team in Dresden, Germany. Applicants should have a background in logical reasoning, (formal) software verification and functional programming. Please visit http://FireEye.com/careers for the concrete job descriptions. If you are interested or have questions, please contact me or Roland Carter <roland.carter< at >FireEye.com> or visit http://FireEye.com for more information about FireEye. FireEye is a next generation security company that provides the industry's leading threat protection technology. The formal methods team at FireEye works on the (formal) verification of a non-trivial piece of the software stack of one of FireEye's future products. Dresden is one the most beautiful cities in Germany with unique cultural attractions. The FireEye office is in the heart of the city, next to the famous historical cen
Categories: Incoming News

ANNOUNCE: Hasql: A minimalistic general high level API for relational databases

libraries list - Tue, 10/28/2014 - 4:02pm
This library takes a mission of upgrading the experience of dealing with relational databases in Haskell. It’s robust, it’s API is very concise, yet it’s packed with powerful features like the following: - An abstraction over transactions, which provides an automated resolution of conflicts. The API ensures that you’re only able to perform a specific set of actions in the transaction context, which allows Hasql to safely resolve conflicting transactions by automatically retrying them. This is much inspired by STM and ST. - Support for cursors. Allows to fetch virtually limitless result sets in a constant memory using streaming. - Employment of prepared statements. Every statement you emit gets prepared and cached. This raises the performance of the backend. - Automated management of resources related to connections, transactions and cursors. - A built-in connections pool. - Type-level generation of templates. You just can’t write
Categories: Offsite Discussion

Polymorphic case for this lens transformer?

haskell-cafe - Tue, 10/28/2014 - 3:40pm
Hi all, I have been using this lens transformer http://lpaste.net/113159. However, I can't seem to find a way to implement the polymorphic case (i.e. Lens instead of Lens'). What am I missing? Hans - Hans Höglund Composer, conductor and developer hans [at] hanshoglund.se hanshoglund.com https://twitter.com/hanshogl https://soundcloud.com/hanshoglund http://github.com/hanshoglund _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

Haskell companies hiring interns?

Haskell on Reddit - Tue, 10/28/2014 - 10:38am

Since it's internship application season for lots of college students right now (including me), this is a post for any Haskell-using startups/companies to let students know they may possibly be hiring interns for Summer 2015. I say possibly since that's a fair bit away and lots of companies don't know what they'll be hiring at that point. But yeah, let us know if you possibly have openings! I know I'm not the only one interested in working with Haskell professionally this summer.

submitted by technicolorNoise
[link] [14 comments]
Categories: Incoming News