News aggregator

Jan Stolarek: Autocomplete command-line flags with GHC 7.8.2

Planet Haskell - Wed, 04/16/2014 - 8:48am

GHC 7.8.2 has been released just a few days ago1. This is the first official release of GHC that contains my contributions. Most of them are improvements in the code generator and are thus practically invisible to most users. But I also implemented one very nice feature that will be useful to an average Haskeller. GHC now has --show-options flag that lists all command-line flags. This feature can be used to auto-complete command-line flags in shells that support this feature. To enable auto-completion in Bash add this code snippet to your ~/.bashrc file:

# Autocomplete GHC commands _ghc() { local envs=`ghc --show-options` # get the word currently being completed local cur=${COMP_WORDS[$COMP_CWORD]}   # the resulting completions should be put into this array COMPREPLY=( $( compgen -W "$envs" -- $cur ) ) } complete -F _ghc -o default ghc

From my experience the first completion is a bit slow but once the flags are cached things work fast.

  1. Please ignore 7.8.1 release. It shipped with a bug that caused rejection of some valid programs.
Categories: Offsite Blogs

Philip Wadler: Team Scotland

Planet Haskell - Wed, 04/16/2014 - 6:19am
What happens after Yes? It's not the SNP, it's the people. A great post on Bella Caledonia.
The UK chattering classes have been wondering what a real, mass grass-roots campaign might look like in modern, professionalised politics. Impotent is their usual conclusion. Well come on up and we’ll show you. The old feudal dance where councilor doths cap to MP, MP to Minister, Minister to Prime Minister and Prime Minister to corporate CEO may well continue apace even here in Scotland. But it’s not winning Scotland.
Categories: Offsite Blogs

Philip Wadler: Help ORG restart the debate about internet filters

Planet Haskell - Wed, 04/16/2014 - 5:59am
The Open Rights Group is starting a campaign opposed to the default filtering now imposed by all providers in the UK---de facto censorship. You can fund it via IndieGogo.
Categories: Offsite Blogs

CLaSH.Tutorial - Wed, 04/16/2014 - 2:58am
Categories: Offsite Blogs

faylang/fay - Tue, 04/15/2014 - 10:58pm
Categories: Offsite Blogs

LtU now supports Mathjax

Lambda the Ultimate - Tue, 04/15/2014 - 12:56pm

LtU now supports MathJax, which allows the use of TeX markup in posts and comments. Note that only TeX/LaTeX markup is currently supported - the alternate MathML format conflict's with the blog's HTML sanitization.

This enhancement is dedicated to neelk, who most recently suggested this feature just over a year ago.

When I went searching for a bit of Mathjax-compatible LaTeX that was relevant to programming languages, the first good example Google found for me was on Neel's blog:

\newcommand{\judge}[3]{{#1} \vdash {#2} : {#3}}
\newcommand{\letv}[3]{\mathsf{let}\;{#1} = {#2}\;\mathsf{in}\;{#3}}
\rule{\judge{\Gamma}{e}{T(A)} \qquad
\judge{\Gamma, x:A}{e'}{T(C)}}

Copy-pasting the above and making it work immediately made it clear that we're going to need a package of useful macros. But it's a start. Feedback welcome.

Note that MathJax rendering is entirely client-side - if you don't see a well-formatted formula above, check the MathJax browser compatibility page and their FAQ.

Categories: Offsite Discussion

Douglas M. Auclair (geophf): 'K' is for Kappa-calculus

Planet Haskell - Tue, 04/15/2014 - 12:48pm

'K' is for κ-calculus
This is an epic story of epic epicness!
No, really.
So, way back when, this guy named Church (Alonzo was his Christian name, and he liked going to churches)
(Actually, that's just conjecture on my part.)
Okay, everybody, stop everything and go to this wikipedia link on the Frege-Church ontology, right now.
Have you read it?
Well, what are you waiting for, read the post, for goodness sake!
So, I read the post, and I was all like skyr, you know? No whey!
Like, totally! Like. I mean, like, wikipedia, wrote that?
So, I quizzed my girls:
"Girls!" I shouted excitedly, "What's the farthest planet from the Sun?"
They were like, "Whaaaaa?"
Then they asked, like, "Papa!" with arched eyebrows, "why do you want to know what's the farthest plant from the Sun?"
Hm. I, like, have to work on my, like, diction.
(We'll get to the reason behind the paroxysms of 'like's momentarily.)
So, I clarified, "Planet, planet!" I shouted, "What's the farthest planet from the Sun!"
EM, the older, and therefore smarter one (she has to be, you see), said, "Pluto. No, wait. Pluto's not a planet. Neptune, then!"
"HAAAAAA!" I screamed.
Elena Marie looked at me like her Papa had finally gone off the deep end.
Well, finally off the deep end, but this time, never to return, gone-off-the-deep kind-of-way.
But before I could explain my victorious berserker scream ...
(Berserker, n.: etymology: íslandic, "Bear Skinned")
(Question: what is the etymology of the word 'etymology'?)
(Did you know Icelandic is an insular Nordic language? They can read the poetic and prose eddas straight off, just like that. Could you read a 1,000 year old document? No, you can't, unless your an Icelander. So there.)
(But I digress.)
(As always.)
(The neat thing here, is this is a digression, from a digression! And it's not even leading us back to the topic, but further away) (just as this digressionary turn discussing my digressionary habits).
(Digressions within digressions within digressions.) (Move over, Frank Herbert, you dead old guy, you're not the only one who can write 'Wheels within wheels within wheels' and have a really bad movie with a Sting cameo made out of your book!)
BUT BEFORE I COULD EXPLAIN my berserker-scream, Li'l Iz piped right up.
"How can you know what's the farthest planet of the Sun, huh, Papa? There're other planets in this galaxy, and what about other galaxies, huh?"
She had me there. But never confuse the point you're trying to make with facts.
WHEN I REREAD what I wrote to my girls, they sighed, appreciatively, EM said, "How ironic can that be?" and walked off to her room to read another book before her ballet recital in forty-five minutes.
I asked Li'l Iz, "Was that, like, ironic?"
She rolled her eyes and deigned not to answer, returning to her own book.
SO, the POINT of all this is:
Pluto is not a planet!
I'm so glad that the ravings of a madman in Borderlands 2 would actually have significance to mathematical logic theory. The things one learns by reading blogposts by the geophfmeister.
(That is moi-self) (That is French) (No, it's not.)
Ooh! Digression!
When I was working with some Ph.D.'s and cognitive scientists, I worked with this flaming-red-haired dude (cognitive scientist) named Bill. He would always say 'Gratzi' to people answering his questions, I would always respond: "That is French."
He always gave me weird looks, but he never got the nerve to correct me.
Until one day, he said 'Gratzi' to one of our analysts, and I said, 'That is French.'
She looked me dead in the eye and snarled a disdainful, "Who cares?" before stalking off.
Bill was on the floor, suffering a paroxysm of laugher.
I think that was the best day of his life.
Pluto, not planet ... It's not even a plant.
Besides which, Eris is more massive than Pluto, anyway. So there.
Hail, Eris!
The Lambda calculus ('L' is for Lambda calculus) addressed a certain set of concerns, which I'll get to in Monday's post, but it, like mathematics in general, has its own set of problems, that is, you can write a function that never terminates and so it is undecidable.
So, along came this little kid by the name of Masahito Hasegawa (dunno, maybe he's Italian?) and he noticed something, and that was this: the problem of the lambda calculus is that it's actually two calculi intertwined. And when you disentangle them, you have two distinct calculi, neither of which are undecidable.
The first of the calculi, the one we focus on here, is the κ-calculus, or contextual calculus.
The κ-calculus is this.
The types are pairs of unit types:
τ : 1|τ x τ|...
So, you see from the types that it's either nothing (the 1, or unit type) or it's a (crossed, or cartesian product) of types.
The functions only take these types, NOT functional types, so we're safe in that we're only working with unit types.
The primary operation is the lifting function, which takes an instance and lifts it into the type of concern.
liftτ x -> (a, x) where a is of type τ
Then the κ-abstraction that when acting with an instance carries it along:
κ x . (some function (τ1, τ2) -> τ3) : τ3
Tying lift and the κ-abstraction together gives us our function 'application' where actually no application happens, it's all just composing (in this case) tuples.
Categories: Offsite Blogs

Anyone have a "guide" to reading TaPL?

Haskell on Reddit - Tue, 04/15/2014 - 6:20am

Sorry if this isn't the place to ask this, but I know a lot of you have read Types and Programming Languages. I want to read it also, over the summer.

I tried last year and failed, I think partially because I was too busy when I picked it up. I heard later on that there are certain sections that can be skimmed or skipped over, and some sections that I should really put focus into. Just wanted to hear any suggestions anyone might have.


submitted by 5outh
[link] [8 comments]
Categories: Incoming News

Silk: Writing admin interfaces with Fay using fay-builder

Planet Haskell - Tue, 04/15/2014 - 3:38am

We are in the process of open sourcing a lot of the general purpose libraries we’ve built at Silk under the BSD3 license. We’re planning to write a series of blog posts introducing them so please stay tuned!

First off is one of the smaller packages, fay-builder (github).

Fay is a proper subset of Haskell that compiles to JavaScript, as well as a compiler. I’ve been helping out with the project since its first release in July 2012.

We have several Haskell backend services with admin interfaces written in HTML and JavaScript that communicate with the running server using REST APIs. It seemed like a good idea to write their admin interfaces in Haskell and we have been experimenting with using Fay for this. Since Fay supports Cabal packages we can use our usual tools and upload these packages to the public hackage or our private instance.

fay-builder lets you store options needed to compile Fay code along with an executable. This is done by using custom cabal flags that can be read either by Setup.hs (but see caveats below) or from within the application at startup, on request, or at some other point.

If you want to try it out you can install it by running cabal install fay-builder.

This post demonstrates how we build Haskell code for our admin interfaces.
Join our team if you enjoy this stuff too, we’re hiring! The Cabal file

Here’s how you can define a Cabal file that uses fay-builder for a project:

name: my-program version: 0.1

Use a custom build type

build-type: Custom

extra-source-files specifies files what should be included with a source distribution. The fay files are added here so they don’t get lost when running cabal sdist.

extra-source-files: fay/*.hs

data-files are also included, with the addition that Cabal will generate a paths module that you can use to fetch the resources during runtime. We probably want to precompile the fay files so the program can just serve them.

data-files: my-program.cabal, js/*.js

x-foo specifies custom flags that Cabal itself ignores, but we can use it for extra configuration options.

x-fay-packages: fay-jquery, fay-text x-fay-root-modules: Index, Misc x-fay-include-paths: src x-fay-output-dir: data/js x-fay-source-dir: fay executable my-program main-is: Main.hs hs-source-dirs: src default-language: Haskell2010 ghc-options: -Wall

This is the haskell module Cabal generates to let us access data-files.

other-modules: Paths_my_program

To make sure we can build the Fay code we add all the dependencies it has here along with the GHC libraries dependencies.

One thing to note is that we can’t depend on base and fay-base at the same time since they have clashing module names. But if we depend on some other fay package we get a transitive dependency to fay-base and we know it will be available.

build-depends: base, Cabal, fay, fay-builder, fay-jquery, fay-text

We have a few options for when to build the Fay code.

Building as a Cabal hook

With a custom Setup.hs we can add a postBuildHook that will compile the Fay code after the executable has been compiled, but before an sdist is created. This is nice because it will generate the needed .js files before the tarball is created. The disadvantage is that Setup.hs cannot have explicit dependencies so you won’t be able to sdist your program unless you already have all dependencies installed.

It is possible to do this, and fay-builder includes a defaultFayHook that you can use in Setup.hs like this:

import Fay.Builder (defaultFayHook) main = defaultFayHook

It’s pretty cool, but maybe not very useful because of the dependency issue. Just make sure to have fay-builder installed before running cabal configure.

Building inside the program

For one application I started out with the above Setup.hs approach, but soon realized that this would not work out since sdisting wasn’t possible in a clean package DB. I instead chose to add a --compile-fay flag that would compile all Fay sources when the process starts when developing. The live setup won’t do this and instead read the data-files.

The trick here is that we added the .cabal file as a data-file to let us access it from other modules.

import qualified Paths_my_program as Paths import qualified Fay.Builder as Builder compileFay :: IO () compileFay = do pkgDb <- getPackageDb packageDesc <- Paths.getDataFileName "my-program.cabal" >>= Builder.readPackageDescription packageDesc pkgDb where -- Some clever way to fetch the current package DB -- if you are using a sandbox. getPackageDb :: IO (Maybe FilePath)

If we had added the settings elsewhere, such as in a custom configurator file like snaplet-fay does, we wouldn’t be able to read it from within Setup.hs so the cabal file might be the only place to put this configuration if we want both features at once.

One of the biggest advantages in using fay-builder is that all dependencies can be listed in one cabal file instead of having to split the client and server code into multiple packages (which would turn into three different packages if there’s shared code).

Categories: Offsite Blogs