[Haskell-beginners] how do you use a package (.cabal)?

7stud bbxx789_05ss at yahoo.com
Sat Mar 28 02:35:12 EDT 2009

In chapter 5 in RWH, they show you how to create, configure,
and install a package.  This is the final step:

...mypretty$ runghc Setup install
Installing: /usr/local/lib/mypretty-0.1/ghc-6.8.2
Setup: /usr/local/lib/mypretty-0.1: createDirectory: permission
 denied (Permission denied)

.../mypretty$ sudo runghc Setup install
Installing: /usr/local/lib/mypretty-0.1/ghc-6.8.2
Registering mypretty-0.1...
Reading package info from "dist/installed-pkg-config" ... done.
Saving old package config file... done.
Writing new package config file... done.

$ ghc-pkg list
    Cabal-, GLUT-, HUnit-, OpenAL-,
    OpenGL-, QuickCheck-, array-, base-,
    bytestring-, cgi-3001.1.5.1, containers-,
    directory-, fgl-, filepath-, (ghc-6.8.2),
    haskell-src-, haskell98-, hpc-, html-,
    mtl-, mypretty-0.1, network-, old-locale-,
    old-time-, packedstring-, parallel-,
    parsec-, pretty-, process-, random-,
    readline-, regex-base-, regex-compat-,
    regex-posix-, rts-1.0, stm-,
    template-haskell-, time-, unix-,

The mypretty package is in that list.  But what does that do for
me? How do I access that package? The .cabal file has this 
text in it:

   Exposed-Modules: SimpleJSON
   Build-Depends: base >= 2.0

But I created a Main.hs file that imported the
"exposed modules":

module Main () where

import Prettify
import PrettyJSON
import SimpleJSON

main = let s = JString "hello world"
           aDoc = renderJValue s
       in printPrettified aDoc

--JString is a JValue value constructor and JValue is defined in 

--renderJVAlue is a function defined in PrettyJSON.hs, and it returns
a data type that is defined in Prettify.js

--printPrettified is a function defined in PrettyJSON.hs

This is what happens:

$ ghc -c Main.hs
~/2testing/dir3$ ghc -o test Main.hs
compilation IS NOT required
/usr/libexec/gcc/i686-apple-darwin8/4.0.1/ld: warning -F: directory name 
(/Users/me/Library/Frameworks) does not exist

/usr/libexec/gcc/i686-apple-darwin8/4.0.1/ld: Undefined symbols:
collect2: ld returned 1 exit status

I googled cabal tutorials, but I can't find anything that
tells me how to access an installed package.

More information about the Beginners mailing list