News aggregator

begriffs/postgrest - Sat, 01/03/2015 - 7:21pm
Categories: Offsite Blogs

How are Haskell functions represented in-memory?

Haskell on Reddit - Sat, 01/03/2015 - 4:27pm

See title. For example, let's say I have something like

f :: Integer -> Integer -> Integer f a b = a + b + 100000

I assume that when this gets compiled down into an executable, a native function f is created that takes two arguments. However, this function also might be partially applied, meaning the runtime has to wrap everything into some sort of closure object, and include a reference to f in there too. How does this work under the hood? (You can also point me to documentation on the implementation of functions/closures in languages with a similar functional approach, e.g. OCaml.)

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

Curious linking error

Haskell on Reddit - Sat, 01/03/2015 - 4:16pm

This is not strictly a Haskell question, but since I'd love to get some feedback from people who know how to deal with these issues if and when they arise during development, I hope it's allowed. A guided adventure in debugging, I hope! :-)

I have a file test.hs which is simply main = putStrLn "Hello World!"

~/scratch ❯ ghc test.hs Linking test ... /usr/bin/ld: final link failed: Illegal seek collect2: error: ld returned 1 exit status

That's odd. Never seen that error before, but it sounds like a disk read error of some kind. So I tried copying it:

~/scratch ❯ ghc test2.hs [1 of 1] Compiling Main ( test2.hs, test2.o ) Linking test2 ... ~/scratch ❯

That works. Now comes the part where I don't know how to proceed. I've straced both compilations, and I don't see any obvious read errors. Anything specific to look for?

Here are the straces:

strace -o out1 ghc test.hs (failure)

strace -o out2 ghc test2.hs (success)

I realize this is a very specific problem that probably can't be replicated outside of my own computer, but I'd still very much love to know how to diagnose the issue, if someone would care to take a stab. :)

submitted by srhb
[link] [2 comments]
Categories: Incoming News

bitemyapp - Functional Education - Sat, 01/03/2015 - 10:43am
Categories: Offsite Blogs

Kronos Haskell - Sat, 01/03/2015 - 8:16am
Categories: Offsite Blogs

GHC Illustrated - Fri, 01/02/2015 - 9:39pm
Categories: Offsite Blogs

Worked-for-me instructions for trying out GHC 7.10 RC1

Haskell on Reddit - Fri, 01/02/2015 - 6:59pm

This was much more painful than GHC 7.8 so I thought I'd make an attempt at a little guide. I have GHC 7.8.3 installed:

  • comment any executable-profiling: False lines you may have in ~/.cabal/config (not sure why I had that or why it's causing problems)

  • get and unpack the appropriate binary distribution for your arch/OS from here

  • cd then ./configure && sudo make install

  • Replace the symlinks that were just overwritten at /usr/local/bin/{ghc,ghci,ghc-pkg,haddock,runghc} to point back to your old version 7.8.3 (if you want).

  • EDIT: 1.22 has been released so you can now just cabal install cabal-install. You'll also need some flavor of cabal/cabal-install 1.22 it seems: download tarballs for both the latest Cabal library and cabal-install packages here

  • cd to the Cabal directory and follow the instructions

  • cd to the cabal-install directory and do cabal install (./ didn't work and/or wasn't necessary)

Now you can try out 7.10 in your cabal projects with:

$ cabal sandbox init $ cabal install -w /usr/local/bin/ghc- --only-dependencies

I forget which incantations of cabal require -w and don't know what changes vis a vis sandboxes are in this new cabal 1.22. Hopefully that helps; I think a proper guide from GHC devs would go a long way to getting their code in front of users before the release in Feb.

submitted by jberryman
[link] [1 comment]
Categories: Incoming News

Magnus Therning: Simple state machines in Haskell

Planet Haskell - Fri, 01/02/2015 - 6:00pm

During this past autumn I’ve had to work with products implementing two small and simple protocols, one was USB based, the other completely proprietary. In both cases I found it very helpful to write clients where the central behaviour was modelled as a state machine. In the case of the proprietary protocol I’ve ended up writing a couple of servers implementing a subset of the behaviour of the real product, also here I found using a state machine as the central piece to be very useful.

I started out having a look at [Hackage][] to see if there was already some tool or DSL that would help me create machines. Surprisingly I found nothing, which probably just means I didn’t look carefully enough. Anyway, after reading the Wikipedia articles on Finite-state machine, finite state transducer, Moore machine and Mealy machine I decided to write my own naïve implementation of something resembling Mealy machines.

A Mealy machine is a 6-tuple comprising

  • a finite set of states
  • a start state
  • a finite set called the input alphabet
  • a finite set called the output alphabet
  • a transition function mapping a state and an input symbol to the next state
  • an output function mapping a state and an input symbol to an output symbol

If the transition and output functions are combined into a single function, and we don’t care about being able to reset a machine, it’s possible to use a representation as simple as this:

data Machine state event signal = Machine { mCurState :: state , mTransFunction :: state -> event -> (state, signal) }

I’ve opted to call the input alphabet event and the output alphabet signal.

Stepping a machine is then performed by passing the current state and an event to the combined function and updating the machine with the result. Of course the generated signal has to be dealt with too. Or in other words:

stepMachine :: Machine state event signal -> event -> (Machine state event signal, signal) stepMachine machine event = (machine {mCurState = newState}, output) where curState = mCurState machine (newState, output) = mTransFunction machine curState event

I also decided to add a function for creating a machine given a start state and a function. With the definition above it becomes trivial:

createMachine :: state -> (state -> event -> (state, signal)) -> Machine state event signal createMachine = Machine

That’s it, really. Except of course that the actual transition function still has to be written. However, with the pattern matching of Haskell I’ve found that to be rather simple, but I’ll keep that for the next post.

Categories: Offsite Blogs

begriffs/postgrest - Fri, 01/02/2015 - 4:20pm
Categories: Offsite Blogs

begriffs/postgrest - Fri, 01/02/2015 - 4:20pm
Categories: Offsite Blogs

Haskell Platform for Mac OS X - Fri, 01/02/2015 - 11:43am
Categories: Offsite Blogs

Ur/Web presentation

Haskell on Reddit - Fri, 01/02/2015 - 5:50am
Categories: Incoming News

Philip Wadler: Antidotes to The Imitation Game

Planet Haskell - Fri, 01/02/2015 - 5:33am

I was so disappointed by the treatment of Alan Turing in The Imitation Game that I devoted a standup routine to it. "The film begins: 'Based on a true story'. Now I know what that means: 'Contains characters with the same names as real people'. Preferably dead, so they can't sue for defamation."

The following articles, better than I could, debunk the treatment meted out to Alan Turing by the film. If you see the film, give them a look as well.

  A Poor Imitation of Alan Turing
  Christian Caryl, New York Review of Books

  The Imitation Game: inventing a new slander to insult Alan Turing
  Alex von Tunzelmann, The Guardian

  The Imitation Game is strangely shy about Alan Turing’s sexuality
  Catherine Shoard, The Guardian
Categories: Offsite Blogs