Playing with Rank-N Types

Posted by igor Sun, 10 Aug 2008 12:51:00 GMT

The following shows some dummy Haskell example code that demonstrates the usage of rank-n types:
{-# LANGUAGE RankNTypes #-}
module Main (main) where
-- g1: identity function
-- GHC implicitely quantifies it to: forall a. a -> a
g1 :: a -> a
g1 x = x
-- g2: Rank2Type
g2 :: (forall a. a -> a) -> (Bool, Char)
g2 f = (f True, f 'a')
-- g3: Rank3Type
g3 :: ((forall a. a -> a) -> (Bool, Char)) -> (Char, Bool)
g3 f = (\x -> (snd x, fst x)) (f g1)
-- g4: Rank4Type
g4 :: (((forall a. a -> a) -> (Bool, Char)) -> (Char, Bool)) ->
         (Bool, Char)
g4 f = (\x -> (snd x, fst x)) (f g2)

main :: IO ()
main = do
  putStrLn "Rank-2 Example:" 
  putStrLn . show . fst . g2 $ g1
  putStrLn . show . snd . g2 $ g1
  putStrLn "Rank-3 Example:" 
  putStrLn . show . fst . g3 $ g2
  putStrLn . show . snd . g3 $ g2
  putStrLn "Rank-4 Example:" 
  putStrLn . show . fst . g4 $ g3
  putStrLn . show . snd . g4 $ g3
If you want to see more ‘useful’ examples have a look at the paper Practical Type Inference for Arbitrary-Rank Types.

Build Darcs with GHC 6.8.1

Posted by igor Thu, 22 Nov 2007 14:25:00 GMT

Download stable or pre-release darcs source distribution. You need to edit two files, namely aclocal.m4 and autoconf.mk:

  • aclocal.m4: add the following before the AC_MSG_RESULT([failed]) line in the WORKAROUND_openFd section:
AC_MSG_RESULT([okay])
IMPORT_WORKAROUND([
   import qualified GHC.Handle ( fdToHandle' )
   import System.IO ( Handle, IOMode )
   import System.Posix.Internals ( FDType )
   import qualified GHC.IOBase ( FD )
])
CODE_WORKAROUND([[
  {- 
   Work around change in the GHC.Handle.fdToHandle' API.
  -}
openFd :: GHC.IOBase.FD -> Maybe FDType -> FilePath -> IOMode -> Bool -> Bool -> IO Handle
openFd fd x y z a b = GHC.Handle.fdToHandle' fd x b y z a
]]),
  • autoconf.mk: add -package containers to GHCFLAGS
  • run autoconf

Now you are ready and set to build darcs with GHC 6.8.1. The unstable darcs branch works out of the box with GHC 6.8.1.

GHC 6.8.1 is out

Posted by igor Sun, 04 Nov 2007 19:26:00 GMT

A new version of GHC is out. Significant changes since the last release: The full release notes are at:

HBURG on HackageDB

Posted by igor Sat, 11 Aug 2007 15:42:00 GMT

HBURG is now also available via the Haskell HackageDB if you follow this link.

Good Haskell Style

Posted by igor Sat, 11 Aug 2007 15:28:00 GMT

If you have written lots of Haskell code and used tabs for indentation because you have not yet read Good Haskell Style by Ian Lynagh, then the following little Perl snippet may help you to easily convert your Haskell code:

  • perl -e '($_ = join "",<>) =~ s/(\t)/ /g; print;'

If you are using TextMate you can easily use this snippet as a Filter Through Command…

Sources:

HBURG Version 1.0 Released

Posted by igor Wed, 25 Jul 2007 14:00:00 GMT

HBURG (Haskell Bottom Up Rewrite Generator) version 1.0 is available as of today! As always there is still work to do, but it is finally the time to release a first version. A very simple example compiler showing how to use HBURG in the compiler design and development process is provided as well.

Ghc 6.6.1 on Mac OS X

Posted by igor Tue, 29 May 2007 15:35:00 GMT

Today I finally went ahead and upgraded Ghc to version 6.6.1. On Max OS X Tiger I additionally needed to install the GNU-Readline Framework as described in this post. The installation went really fine but when trying to link executable programs ld would throw up and say something along the line:
  • ... the table of contents for *.a archives are out of date and that ranlib(1) should be re-run.

Oh well, life is imperfect but the following solves the problem:

$ cd /usr/local/lib/ghc-6.6.1/
$ sudo sh -c "ls *.a | xargs ranlib"