Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Empty or Tree? (bahad?r altan) 2. Parsec, parsing 'free text' (Franco) 3. Re: Empty or Tree? (Aditya Manthramurthy) ---------------------------------------------------------------------- Message: 1 Date: Sat, 10 Mar 2012 10:28:43 +0000 (GMT) From: bahad?r altan <doal...@yahoo.co.uk> Subject: [Haskell-beginners] Empty or Tree? To: "beginners@haskell.org" <beginners@haskell.org> Message-ID: <1331375323.74038.yahoomail...@web171601.mail.ir2.yahoo.com> Content-Type: text/plain; charset="iso-8859-1" Hello everyone. I'm trying to write a code which works on binary trees. When I write code like this ?with a tree with empty nodes : data Tree ?= ?Empty | Node ?Integer Tree Tree function Node a (Node b Empty Empty)??(Node c Empty Empty) it works fine.? But when I try to create a more generic code like this ?which could ?work with trees who don't have empty nodes in grandchild level :? function Node a (Node b Tree Tree)??(Node c Tree Tree )? I get this error :?Undefined data constructor "Tree" Can you help me with creating more generic code please? Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20120310/aa5a121d/attachment.html> ------------------------------ Message: 2 Date: Sat, 10 Mar 2012 11:49:24 +0100 From: Franco <franc...@gmx.com> Subject: [Haskell-beginners] Parsec, parsing 'free text' To: beginners@haskell.org Message-ID: <20120310114924.c199afa7fcc8e30ec0e35...@gmx.com> Content-Type: text/plain; charset=US-ASCII I am using Parsec as my parsing library and quite liking it: though, I am unsure on how to properly tackle a 'free element' problem. Let me explain: In my file, there are some elements which look like this: this is some <red - formatted> text. I call this a FormatString. They can be found inside many elements, like: [ someconditions | this is some <red - formatted> text.] + this is some <red - formatted> text. -> somenumberhere To parse a FormatString I call 'generalText', which looks like this: 56 -- TEXT -- 57 58 generalText = many anyText >>= \fss -> 59 return (foldl (+:+%) (toFString "" []) fss) 60 61 anyText = try ( formattedText ) 62 <|> plainText 63 64 formattedText = char '<' >> 65 sepEndBy1 format spacebar >>= \fs -> -- format parser 66 string "- " >> 67 manyTill anyChar (char '>') >>= \cs -> 68 return (toFString cs fs) 69 70 plainText = many1 (noneOf "<") >>= \xs -> 71 return (toFString xs []) It works, but causes quite some headaches in using it: - I would like to call a "read with generalText until you find a ']' character. - or a "read with generalText until you find a " -> " (do not consume it) And the like, but I do not know how. If it were a plain string I would call manyTill1 anyChar myP. I thought of first parsing a raw string searching for a terminator and then feeding it to generalText. But isn't that cluncky codewise? Thanks for your help -F ------------------------------ Message: 3 Date: Sat, 10 Mar 2012 16:27:50 +0530 From: Aditya Manthramurthy <aditya....@gmail.com> Subject: Re: [Haskell-beginners] Empty or Tree? To: beginners@haskell.org Message-ID: <cac_me97dzmbvg3rtnava4qv1vanpdhnt97cg+ercsk2dgtn...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" I think this is because "Tree" is a data type and not a data constructor. According to your definition of Tree, Empty and Node are the constructors. Node a (Node b (Node c Empty Empty) (Node d Empty Empty)) (Node e (Node f Empty Empty) (Node g Empty Empty)) is a valid tree if a, b, c, d, e, f, g are integers. Hope this helps. -- Aditya. On 10 March 2012 15:58, bahad?r altan <doal...@yahoo.co.uk> wrote: > Hello everyone. I'm trying to write a code which works on binary trees. > When I write code like this with a tree with empty nodes : > > data Tree = Empty | Node Integer Tree Tree > > function Node a (Node b Empty Empty) (Node c Empty Empty) > > it works fine. > But when I try to create a more generic code like this which could work > with trees who don't have empty nodes in grandchild level : > > function Node a (Node b Tree Tree) (Node c Tree Tree ) > > I get this error : Undefined data constructor "Tree" > > Can you help me with creating more generic code please? > Thanks > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20120310/9588e1d2/attachment-0001.htm> ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 45, Issue 11 *****************************************