Re: Getting the constructor from flat curry

From: Gustavo Arroyo Delgado <garroyo_at_dsic.upv.es>
Date: Thu, 08 Jul 2010 03:47:03 +0200

hi hema,

i just want to show that the Sebastian program works. i remove the
data type Bintree from the flatConstrs program, as you require, i
declare this data type into another file, finally i execute two
examples to get the constructor names, it works!

Prelude> :l BinTree.curry
Parsing 'BinTree.curry'...
skipping BinTree.curry ...
BinTree> :show
data BinTree a = Leaf | Branch a (BinTree a) (BinTree a)
BinTree> :l flatConstrs
Parsing 'flatConstrs.curry'...
skipping flatConstrs.curry ...
flatConstrs> :show
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 ]


getNames p = do progFlat <- readFlatCurry p
                 let cN = constructorNames progFlat
                 putStrLn (show cN)

flatConstrs> :t constructorNames
constructorNames :: FlatCurry.Prog -> [(String,String)]
flatConstrs> getNames "BinTree"
[("BinTree","Leaf"),("BinTree","Branch")]
flatConstrs> readFlatCurry "BinTree" >>= print . constructorNames
[("BinTree","Leaf"),("BinTree","Branch")]
flatConstrs>


hema, please verify the following: all the function definitions must
be written in the first column, i put the constructorNames definition
in the second column of the program and got the same error message:

flatConstrs> :l flatConstrs
Parsing 'flatConstrs.curry'...
generating flatConstrs.fcy ...
cymake:
"flatConstrs.curry", line 5.2: Unexpected token identifier `constructorNames'
ERROR occurred during parsing!
flatConstrs>


i hope this solve the problem...

good luck!

Quoting hema kumar <hemasid_at_gmail.com>:

> Hi Gustavo,
>
> Thanks for replying.
>
> The program you edited does not do the task i require. For me Bintree.curry
> is a separate program and in the future i need to write a program which
> could give me the constructor from a file which I plan to dynamically
> provide.
>
> If you can please tell me what is the error in the program Sebastian mailed.
> Do not get why it is giving the error i mailed in my last mail.
>
> error corresponding to constructorNames.
>
> Prelude> :l flatConstrs.curry
> Parsing 'flatConstrs.curry'...
> generating flatConstrs.fcy ...
> cymake:
> "flatConstrs.curry", line 4.2: Unexpected token identifier
> `constructorNames'
> ERROR occurred during parsing!
> Prelude>
>
> Thanks and Regards
> Hema
>
>
>
> On Tue, Jul 6, 2010 at 8:27 AM, Gustavo Arroyo Delgado
> <garroyo_at_dsic.upv.es>wrote:
>
>> hola a todos!
>>
>> I made a little change in Sebastian program:
>>
>> Prelude> :l BinTree
>> Parsing 'BinTree.curry'...
>> skipping BinTree.curry ...
>> BinTree> :show
>>
>> import FlatCurry
>> import FlatCurryGoodies
>>
>>
>> data BinTree a = Leaf | Branch a (BinTree a) (BinTree a)
>>
>> getNames p = do progFlat <- readFlatCurry p
>> let cN = constructorNames progFlat
>> putStrLn (show cN)
>>
>>
>> constructorNames :: Prog -> [QName]
>> constructorNames prog = [ name | typ <- progTypes prog, name <- consNames
>> typ ]
>> where
>> consNames typ = [ consName cons | not (isTypeSyn typ), cons <-
>> typeConsDecls typ ]
>> BinTree> getNames "BinTree"
>> [("BinTree","Leaf"),("BinTree","Branch")]
>> BinTree>
>>
>>
>> I'm using "BinTree" file as program as well as getName's argument...
>>
>>
>>
>> hasta luego...
>>
>>
>>
>> Quoting hema kumar <hemasid_at_gmail.com>:
>>
>> Hi Sebastian,
>>> Thanks for the effort for explaining me regarding the program. Really
>>> appreciate your help
>>>
>>> But, I m still getting the same error corresponding to constructorNames.
>>>
>>> Prelude> :l flatConstrs.curry
>>> Parsing 'flatConstrs.curry'...
>>> generating flatConstrs.fcy ...
>>> cymake:
>>> "flatConstrs.curry", line 4.2: Unexpected token identifier
>>> `constructorNames'
>>> ERROR occurred during parsing!
>>> Prelude>
>>>
>>> Please help.
>>> Thanks
>>> Hema
>>>
>>>
>>> On Fri, Jul 2, 2010 at 1:28 AM, Sebastian Fischer <
>>> sebf_at_informatik.uni-kiel.de> wrote:
>>>
>>> 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.)
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>
>> ----------------------------------------------------------------
>> This message was sent using IMP, the Internet Messaging Program.
>>
>>
>



-- 
Gustavo Arroyo Delgado
-------------------------------------------------
Estudiante del Tercer Ciclo en el DSIC de la UPV
Telefon: 963877355 Ext: 73537
Profesor Titular del CIIDET
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
_______________________________________________
curry mailing list
curry_at_lists.RWTH-Aachen.DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry
Received on Do Jul 08 2010 - 09:20:31 CEST

This archive was generated by hypermail 2.3.0 : Do Feb 01 2024 - 07:15:09 CET