Playing with 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
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
- Haskell Program Coverage (hpc)
- GHCi includes a debugger
- The code generator uses pointer tagging (which should mean most code improves by 10-15%, and as a result the compiler is also faster)
HBURG on HackageDB
HBURG is now also available via the Haskell HackageDB if you follow this link.
Good Haskell Style
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:
- Ian Lynagh post to the Haskell Libraries list.
- Good Haskell Style
HBURG Version 1.0 Released
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.
- Please visit the HBURG project website for more information.
Ghc 6.6.1 on Mac OS X
ld would throw up and say something along the line:
- ... the table of contents for
*.aarchives are out of date and thatranlib(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"