[Haskell-beginners] Read package name, version from .cabal file

Shakthi Kannan shakthimaan at gmail.com
Tue Dec 13 13:23:50 CET 2011


Hi,

I am trying to read a .cabal find and print the package name and
version. Here is the code snippet:

=== Code ===

getName :: FilePath -> IO ()
getName cabal = do
           gdesc <- readPackageDescription normal cabal
           let desc = flattenPackageDescription gdesc
               final = pkgName $ package desc
           putStrLn final

=== END ===

=== Output ===

    Couldn't match expected type `[Char]'
                with actual type `PackageName'

=== END ===

I see that the method 'package' from:

  http://www.haskell.org/cabal/release/cabal-latest/doc/API/Cabal/Distribution-PackageDescription.html#t%3APackageDescription

allows me to return the PackageIdentifier. Using pkgName returns a PackageName.

  http://www.haskell.org/cabal/release/cabal-latest/doc/API/Cabal/Distribution-Package.html#t%3APackageIdentifier

But, how can I obtain the string value from it?

Appreciate any help in this regard.

Thanks!

SK

-- 
Shakthi Kannan
http://www.shakthimaan.com



More information about the Beginners mailing list