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

Michael Snoyman michael at snoyman.com
Tue Dec 13 13:27:43 CET 2011


On Tue, Dec 13, 2011 at 2:23 PM, Shakthi Kannan <shakthimaan at gmail.com> wrote:
> 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
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners

You need to use pattern patching, e.g.:

let PackageName str = pkgName $ ...

HTH,
Michael



More information about the Beginners mailing list