Using the Glasgow Haskell Compiler (GHC) on OS X Lion with Xcode 4.3

Here is what you need to do if you want to use the Glasgow Haskell Compiler (GHC) on OS X Lion with a clean installation of Xcode 4.3.

Command line tools

You need to install the command line tools from Apple. You may do that in two ways (the second is faster as it is a much smaller download):

  1. Install all of Xcode:
    • Install Xcode from the Mac App Store.
    • Launch Xcode.
    • In the Preferences dialog of Xcode, select the "Downloads" pane and install "Command line tools".
  2. Install the command line tools only:

In both cases, you need to register as an Apple developer. (This is a free registration.)

Install GHC 7.4.1 (or later)

Older versions of GHC —including GHC 7.0.4, which is part of the Haskell Platform 2011.4.0.0 (December 2011)— won't work. They complain about not being able to execute '/Developer/usr/bin/gcc'. (You can fix this by modifying GHC's wrapper script as mentioned in the comments.)

Download and install GHC 7.4.1 (or a later version) — or install the Haskell Platform once a 2012 release has been made.

Install Cabal tools (optional)

To facilitate the easy installation of Haskell packages, you should get the cabal-install tool.

  • Download cabal-install-0.14.0.tar.gz
  • Unpack the tarball and, inside the created 'cabal-install-0.14.0' directory, run the following: 'sh bootstrap.sh'

Update: As @zmoazeni points out in the comments, Homebrew has now been updated, so that you can install both GHC and cabal-install version 0.14 by executing

brew install ghc --devel
brew install cabal-install

Using GHC's LLVM backend (optional)

If you like to use GHC's LLVM backend —which is more efficient for array-based and other loop-oriented code— you need to seperately install LLVM. (This is despite the Apple tools being based on LLVM as well.)

  • Install Homebrew (as per the instructions on that webpage).
  • Then, execute the following: 'brew install llvm'

Compiling GHC from the sources in the Git repositories (GHC developers only)

If you plan to work on GHC itself and you need to compile the develeopment version of GHC straight from the Git repositories, you need to install the GNU auto tools as well (which are no longer distributed by Apple).

  • Install Homebrew (as per the instructions on that webpage) — if you didn't do that already to install LLVM above.
  • Then, execute the following: 'brew install autoconf automake'

The GHC Trac has more information on Building and Porting GHC.

Filed under  //  ghc   haskell   lion   mac  
Posted

Moving mail archives to MobileMe (or other Sun Java System Messaging Servers)

I recently consolidated all my email on MobileMe (for easy access from both my Mac and iPad). However, I ran into a problem with the MobileMe IMAP server when I tried to move my old mail archives to the MobileMe IMAP server. MobileMe uses the Sun Java System Messaging Server (which has since become the Oracle Communications Messaging Exchange Server). It turns out that this IMAP server (like some others as well) is rather strict about the format of mail headers; hence, uploading old mail archives usually aborts with the following error message: "The IMAP command “APPEND” (to …) failed with server error: Message contains invalid header".

Querying the Internets and some experimentation revealed that the problem are lines in email message headers that start with "From ", ">From ", and ">>From ". These are not proper message headers fields (whose names need to be delimited by a colon), but remnants from storage of these mail messages in the mbox format. The remedy is to delete or edit these invalid lines in all affected message headers.

Apple Mail stores mail messages in "$USER/Library/Mail/Mailboxes/". Each mailbox directory (suffix ".mbox") contains a directory "Messages" with one file per message. These files can easily be modified using your favourite command line tools that support matching of regular expressions or by loading them, en masse, into TextMate for project-wide search and replace. This is somewhat naughty as the files containing individual messages contain the message header and text as well as a property list (plist), used by Mail.app to store a few attributes. The start of that property list in the text file is marked by a character count in the first line of each message. By eliminating or modifying the offending lines, you invalidate that character count.  However, Mail.app seems to cope just fine with those slightly malformed messages. After fixing the headers, all my messages uploaded without problems (and no attributes seemed to get lost).

Filed under  //  iPad   imap   mac   mail   mobileme  
Posted

Quickly searching Hackage and Hoogle on Mac OS X

Haskellers on Macs should check out Alfred App.  It's a launcher application that also does web searches and a few other things.  In particular, it enables you to define custom searches that you can quickly access with a hot key from wherever you are.  I am using the two following custom searches to quickly search through Hackage and Hoogle:

The strings "hackage" and "hoogle" are the keywords, followed by the query strings.

Filed under  //  alfredapp   haskell   mac  
Posted

Heads Up: GHC devs on Macs - GHC's testsuite crashes spotlight indexer on SL

GHC's testsuite[1] contains a test encoding001 (in the I/O library section) that generates files in various unicode encodings including one using UTF-8 with byte order markers, namely encoding001.utf16.utf8_bom. On Mac OS X 10.6 (Snow Leopard), this file causes the indexing process of Spotlight to hang. More precisely, the mds (meta dataserver) process appears to go into a loop (eating all cycles of one processor core) — it appears to hang in the library libmecap trying to parse what it probably believes to be Japanese or Chinese text.

Interestingly, the file command regards the file to be "Unicode text, UTF-32, big-endian".

Filed under  //  ghc   haskell   mac  
Posted

Language Specification for Blocks

Here is the language specification for blocks (that is lambda abstractions) for C, Objective-C & C++ as implemented in the Clang compiler and used in Mac OS X 10.6 (Snow Leopard):

   http://clang.llvm.org/docs/BlockLanguageSpec.txt

Filed under  //  cocoa   mac   objc  
Posted

Grand Central Dispatch aka libdispatch is now Open Source

Apple released the source code of one of the core technologies in Snow Leopard: http://libdispatch.macosforge.org/
 
This is an interesting move, as discussed at http://www.macresearch.org/grand-central-now-open-all — it will be very interesting to see whether this will lead to a wider adoption of Grand Central Dispatch beyond Mac OS.

Filed under  //  concurrency   mac   parallelism  
Posted