Re: Getting the constructor from flat curry

From: Sebastian Fischer <sebf_at_informatik.uni-kiel.de>
Date: Fri, 02 Jul 2010 10:28:32 +0200

Hi Hema,

On Jul 1, 2010, at 11:58 PM, hema kumar wrote:

> I m trying to catch a constructor of a small program given below
> named BinTree.curry
>
> data BinTree a = Leaf | Branch a (BinTree a) (BinTree a)
>
> The constructors will be Branch and Leaf.
>
>
> I tried to execute the program you gave in your last mail:
> [...]
> I m getting an error corresponding to constructorNames. It seems to
> me that its a user defined fuction.

Which error do you get? Did you load the program which contains
`constuctorNames` into PAKCS?

> Please tell me how should I go about it further. Do i have to
> specify the file name as BinTree.fcy or BinTree.curry??

The module FlatCurry contains a function `readFlatCurry :: String ->
IO Prog` that takes a module name (without suffix) and returns the
corresponding FlatCurry program. You can test my program as follows:

     # cat BinTree.curry
     data BinTree a = Leaf | Branch a (BinTree a) (BinTree a)

     # cat flatConstrs.curry
     import FlatCurry
     import FlatCurryGoodies

     constructorNames :: Prog -> [QName]
     constructorNames prog =
       [ name | typ <- progTypes prog, name <- consNames typ ]
      where
       consNames typ =
        [ consName cons | not (isTypeSyn typ), cons <- typeConsDecls
typ ]

     # pakcs
     [...]
     Prelude> :l flatConstrs.curry
     [...]
     flatConstrs> readFlatCurry "BinTree" >>= print . constructorNames
     [("BinTree","Leaf"),("BinTree","Branch")]

hope that helps,
Sebastian

-- 
Underestimating the novelty of the future is a time-honored tradition.
(D.G.)
_______________________________________________
curry mailing list
curry_at_lists.RWTH-Aachen.DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry
Received on Fr Jul 02 2010 - 11:43:22 CEST

This archive was generated by hypermail 2.3.0 : Do Jun 20 2024 - 07:15:10 CEST