[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
Password:
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
/usr/local/lib/ghc-6.8.2/package.conf:
    Cabal-1.2.3.0, GLUT-2.1.1.1, HUnit-1.2.0.0, OpenAL-1.3.1.1,
    OpenGL-2.2.1.1, QuickCheck-1.1.0.0, array-0.1.0.0, base-3.0.1.0,
    bytestring-0.9.0.1, cgi-3001.1.5.1, containers-0.1.0.1,
    directory-1.0.0.0, fgl-5.4.1.1, filepath-1.1.0.0, (ghc-6.8.2),
    haskell-src-1.0.1.1, haskell98-1.0.1.0, hpc-0.5.0.0, html-1.0.1.1,
    mtl-1.1.0.0, mypretty-0.1, network-2.1.0.0, old-locale-1.0.0.0,
    old-time-1.0.0.0, packedstring-0.1.0.0, parallel-1.0.0.0,
    parsec-2.1.0.0, pretty-1.0.0.0, process-1.0.0.0, random-1.0.0.0,
    readline-1.0.1.0, regex-base-0.72.0.1, regex-compat-0.71.0.1,
    regex-posix-0.72.0.2, rts-1.0, stm-2.1.1.0,
    template-haskell-2.2.0.0, time-1.1.2.0, unix-2.3.0.0,
    xhtml-3000.0.2.1

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:

library
   Exposed-Modules: SimpleJSON
                    PrettyJSON
                    Prettify
   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 
SimpleJSON.hs

--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:
___stginit_myprettyzm0zi1_Prettify_
___stginit_myprettyzm0zi1_PrettyJSON_
___stginit_myprettyzm0zi1_SimpleJSON_
_myprettyzm0zi1_PrettyJSON_printPrettified_closure
_myprettyzm0zi1_PrettyJSON_renderJValue_closure
_myprettyzm0zi1_SimpleJSON_JString_static_info
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