trees on Haskell : Do I understand it right ?

Hello, Suppose we have this definition of a tree : data MessageTree = Leaf | Node MessageTree LogMessage MessageTree deriving (Show, Eq) let Message = LogMessage "E 1 this is a test error" let Message = LogMessage "e 2 this is the second test error " As I understand it right I can make the first entry like this : first_entry = Node Messagetree Message Messagetree And the second one like this second_entry = Node Message Messagetree Message2 Messagetree ?? Roelof

Hi Roelof,
I think you misunderstood it.
There are two things here: types and values (value-constructors). They
exist in different world, not touching each other.
In Haskell, you define a type as:
data
Hello,
Suppose we have this definition of a tree :
data MessageTree = Leaf | Node MessageTree LogMessage MessageTree deriving (Show, Eq)
let Message = LogMessage "E 1 this is a test error" let Message = LogMessage "e 2 this is the second test error "
As I understand it right I can make the first entry like this : first_entry = Node Messagetree Message Messagetree
And the second one like this second_entry = Node Message Messagetree Message2 Messagetree ??
Roelof
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

In my second example you can see a minimal node with a message:
node = Node Leaf "msg" Leaf
Instead of either left or right Leaf you can put another value of type
MessageTree, for example:
node = Node Leaf "msg1" (Node Leaf "msg2" Leaf)
On Thu, Feb 26, 2015 at 4:01 PM, Roelof Wobben
Oke,
So a leaf is a node which has no "branch"
I have made a exercise where I have to made the logMessages. Now I have to turn them into a tree
Where does the second entry goes then ?
Roelof
Konstantine Rybnikov schreef op 26-2-2015 om 14:56:
Hi Roelof,
I think you misunderstood it.
There are two things here: types and values (value-constructors). They exist in different world, not touching each other.
In Haskell, you define a type as:
data
= You can create values as:
let varName =
<Value> <Value> <Value> You need to put <Value> of some type, not type name itself in place of those <Value>s.
So, with datatype you provided, you have two data-constructors:
Leaf
and
Node <val> <val> <val>
You can create a leaf:
let leaf = Leav
or a node:
let node = Node Leaf "msg" Leaf
You can see that Node is a data-constructor that takes 3 values, not type-names as it's parameters.
Hope this helps.
On Thu, Feb 26, 2015 at 3:21 PM, Roelof Wobben
wrote: Hello,
Suppose we have this definition of a tree :
data MessageTree = Leaf | Node MessageTree LogMessage MessageTree deriving (Show, Eq)
let Message = LogMessage "E 1 this is a test error" let Message = LogMessage "e 2 this is the second test error "
As I understand it right I can make the first entry like this : first_entry = Node Messagetree Message Messagetree
And the second one like this second_entry = Node Message Messagetree Message2 Messagetree ??
Roelof
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Roelof,
Do you get any type-errors with your code?
On Thu, Feb 26, 2015 at 8:32 PM, Roelof Wobben
Oke,
I send it a second time but now in plain text.
So for 3 it will be like this :
Node = Node (Node Leaf "msg1" Leaf) (Node Leaf "msg2") (Node "msg3" Leaf) ???
Roelof
Konstantine Rybnikov schreef op 26-2-2015 om 15:08:
In my second example you can see a minimal node with a message:
node = Node Leaf "msg" Leaf
Instead of either left or right Leaf you can put another value of type MessageTree, for example:
node = Node Leaf "msg1" (Node Leaf "msg2" Leaf)
On Thu, Feb 26, 2015 at 4:01 PM, Roelof Wobben
wrote: Oke,
So a leaf is a node which has no "branch"
I have made a exercise where I have to made the logMessages. Now I have to turn them into a tree
Where does the second entry goes then ?
Roelof
Konstantine Rybnikov schreef op 26-2-2015 om 14:56:
Hi Roelof,
I think you misunderstood it.
There are two things here: types and values (value-constructors). They exist in different world, not touching each other.
In Haskell, you define a type as:
data
= You can create values as:
let varName =
<Value> <Value> <Value> You need to put <Value> of some type, not type name itself in place of those <Value>s.
So, with datatype you provided, you have two data-constructors:
Leaf
and
Node <val> <val> <val>
You can create a leaf:
let leaf = Leav
or a node:
let node = Node Leaf "msg" Leaf
You can see that Node is a data-constructor that takes 3 values, not type-names as it's parameters.
Hope this helps.
On Thu, Feb 26, 2015 at 3:21 PM, Roelof Wobben
wrote: Hello,
Suppose we have this definition of a tree :
data MessageTree = Leaf | Node MessageTree LogMessage MessageTree deriving (Show, Eq)
let Message = LogMessage "E 1 this is a test error" let Message = LogMessage "e 2 this is the second test error "
As I understand it right I can make the first entry like this : first_entry = Node Messagetree Message Messagetree
And the second one like this second_entry = Node Message Messagetree Message2 Messagetree ??
Roelof
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Roelof,
Perhaps it would help for you to draw diagrams for the cases you're working.
If a leaf has nothing below it, and a node always has exactly three things
below it (the left child, the message, and the right child),
what would your picture look like for 1, 2, and 3 nodes?
And how would you write out constructor expressions that match those shapes?
Hope that helps,
-jn-
On Thu, Feb 26, 2015 at 12:32 PM, Roelof Wobben
Oke,
I send it a second time but now in plain text.
So for 3 it will be like this :
Node = Node (Node Leaf "msg1" Leaf) (Node Leaf "msg2") (Node "msg3" Leaf) ???
Roelof
Konstantine Rybnikov schreef op 26-2-2015 om 15:08:
In my second example you can see a minimal node with a message:
node = Node Leaf "msg" Leaf
Instead of either left or right Leaf you can put another value of type MessageTree, for example:
node = Node Leaf "msg1" (Node Leaf "msg2" Leaf)
On Thu, Feb 26, 2015 at 4:01 PM, Roelof Wobben
wrote: Oke,
So a leaf is a node which has no "branch"
I have made a exercise where I have to made the logMessages. Now I have to turn them into a tree
Where does the second entry goes then ?
Roelof
Konstantine Rybnikov schreef op 26-2-2015 om 14:56:
Hi Roelof,
I think you misunderstood it.
There are two things here: types and values (value-constructors). They exist in different world, not touching each other.
In Haskell, you define a type as:
data
= You can create values as:
let varName =
<Value> <Value> <Value> You need to put <Value> of some type, not type name itself in place of those <Value>s.
So, with datatype you provided, you have two data-constructors:
Leaf
and
Node <val> <val> <val>
You can create a leaf:
let leaf = Leav
or a node:
let node = Node Leaf "msg" Leaf
You can see that Node is a data-constructor that takes 3 values, not type-names as it's parameters.
Hope this helps.
On Thu, Feb 26, 2015 at 3:21 PM, Roelof Wobben
wrote: Hello,
Suppose we have this definition of a tree :
data MessageTree = Leaf | Node MessageTree LogMessage MessageTree deriving (Show, Eq)
let Message = LogMessage "E 1 this is a test error" let Message = LogMessage "e 2 this is the second test error "
As I understand it right I can make the first entry like this : first_entry = Node Messagetree Message Messagetree
And the second one like this second_entry = Node Message Messagetree Message2 Messagetree ??
Roelof
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Beauty of style and harmony and grace and good rhythm depend on simplicity. - Plato

Hello, Im looking for goofd online software to make the diagrams. As soon as I find it . I will publish them on the ML. Roelof Joel Neely schreef op 1-3-2015 om 14:45:
Roelof,
Perhaps it would help for you to draw diagrams for the cases you're working. If a leaf has nothing below it, and a node always has exactly three things below it (the left child, the message, and the right child), what would your picture look like for 1, 2, and 3 nodes? And how would you write out constructor expressions that match those shapes?
Hope that helps, -jn-
On Thu, Feb 26, 2015 at 12:32 PM, Roelof Wobben
mailto:r.wobben@home.nl> wrote: Oke,
I send it a second time but now in plain text.
So for 3 it will be like this :
Node = Node (Node Leaf "msg1" Leaf) (Node Leaf "msg2") (Node "msg3" Leaf) ???
Roelof
Konstantine Rybnikov schreef op 26-2-2015 om 15:08:
In my second example you can see a minimal node with a message:
node = Node Leaf "msg" Leaf
Instead of either left or right Leaf you can put another value of type MessageTree, for example:
node = Node Leaf "msg1" (Node Leaf "msg2" Leaf)
On Thu, Feb 26, 2015 at 4:01 PM, Roelof Wobben
mailto:r.wobben@home.nl> wrote: Oke,
So a leaf is a node which has no "branch"
I have made a exercise where I have to made the logMessages. Now I have to turn them into a tree
Where does the second entry goes then ?
Roelof
Konstantine Rybnikov schreef op 26-2-2015 om 14:56:
Hi Roelof,
I think you misunderstood it.
There are two things here: types and values (value-constructors). They exist in different world, not touching each other.
In Haskell, you define a type as:
data
= You can create values as:
let varName =
<Value> <Value> <Value> You need to put <Value> of some type, not type name itself in place of those <Value>s.
So, with datatype you provided, you have two data-constructors:
Leaf
and
Node <val> <val> <val>
You can create a leaf:
let leaf = Leav
or a node:
let node = Node Leaf "msg" Leaf
You can see that Node is a data-constructor that takes 3 values, not type-names as it's parameters.
Hope this helps.
On Thu, Feb 26, 2015 at 3:21 PM, Roelof Wobben
mailto:r.wobben@home.nl> wrote: Hello,
Suppose we have this definition of a tree :
data MessageTree = Leaf | Node MessageTree LogMessage MessageTree deriving (Show, Eq)
let Message = LogMessage "E 1 this is a test error" let Message = LogMessage "e 2 this is the second test error "
As I understand it right I can make the first entry like this : first_entry = Node Messagetree Message Messagetree
And the second one like this second_entry = Node Message Messagetree Message2 Messagetree ??
Roelof
_______________________________________________ Beginners mailing list Beginners@haskell.org mailto:Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org mailto:Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org mailto:Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org mailto:Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org mailto:Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Beauty of style and harmony and grace and good rhythm depend on simplicity. - Plato
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Here the diagram for 1 messages : http://imgur.com/yuzXUNB In haskell it would be Node Message1 leaf leaf Roelof Roelof Wobben schreef op 1-3-2015 om 19:08:
Hello,
Im looking for goofd online software to make the diagrams. As soon as I find it . I will publish them on the ML.
Roelof
Joel Neely schreef op 1-3-2015 om 14:45:
Roelof,
Perhaps it would help for you to draw diagrams for the cases you're working. If a leaf has nothing below it, and a node always has exactly three things below it (the left child, the message, and the right child), what would your picture look like for 1, 2, and 3 nodes? And how would you write out constructor expressions that match those shapes?
Hope that helps, -jn-
On Thu, Feb 26, 2015 at 12:32 PM, Roelof Wobben
mailto:r.wobben@home.nl> wrote: Oke,
I send it a second time but now in plain text.
So for 3 it will be like this :
Node = Node (Node Leaf "msg1" Leaf) (Node Leaf "msg2") (Node "msg3" Leaf) ???
Roelof
Konstantine Rybnikov schreef op 26-2-2015 om 15:08:
In my second example you can see a minimal node with a message:
node = Node Leaf "msg" Leaf
Instead of either left or right Leaf you can put another value of type MessageTree, for example:
node = Node Leaf "msg1" (Node Leaf "msg2" Leaf)
On Thu, Feb 26, 2015 at 4:01 PM, Roelof Wobben
mailto:r.wobben@home.nl> wrote: Oke,
So a leaf is a node which has no "branch"
I have made a exercise where I have to made the logMessages. Now I have to turn them into a tree
Where does the second entry goes then ?
Roelof
Konstantine Rybnikov schreef op 26-2-2015 om 14:56:
Hi Roelof,
I think you misunderstood it.
There are two things here: types and values (value-constructors). They exist in different world, not touching each other.
In Haskell, you define a type as:
data
= You can create values as:
let varName =
<Value> <Value> <Value> You need to put <Value> of some type, not type name itself in place of those <Value>s.
So, with datatype you provided, you have two data-constructors:
Leaf
and
Node <val> <val> <val>
You can create a leaf:
let leaf = Leav
or a node:
let node = Node Leaf "msg" Leaf
You can see that Node is a data-constructor that takes 3 values, not type-names as it's parameters.
Hope this helps.
On Thu, Feb 26, 2015 at 3:21 PM, Roelof Wobben
mailto:r.wobben@home.nl> wrote: Hello,
Suppose we have this definition of a tree :
data MessageTree = Leaf | Node MessageTree LogMessage MessageTree deriving (Show, Eq)
let Message = LogMessage "E 1 this is a test error" let Message = LogMessage "e 2 this is the second test error "
As I understand it right I can make the first entry like this : first_entry = Node Messagetree Message Messagetree
And the second one like this second_entry = Node Message Messagetree Message2 Messagetree ??
Roelof
_______________________________________________ Beginners mailing list Beginners@haskell.org mailto:Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org mailto:Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org mailto:Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org mailto:Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org mailto:Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Beauty of style and harmony and grace and good rhythm depend on simplicity. - Plato
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Roelof, please consider changing your mail client to send *both* HTML and plain-text emails! With your current setting you send *only* HTML sometimes and it results in a slightly broken list archive, see [1] for an example of the result. To boot, you also make it more difficult for those of us who use plain-text mail clients to benefit from the diskussions you participate in. /M [1]: https://mail.haskell.org/pipermail/beginners/2015-February/014808.html On Thu, Feb 26, 2015 at 03:01:22PM +0100, Roelof Wobben wrote:
<html> <head> <meta content="text/html; charset=windows-1252" http-equiv="Content-Type"> </head> <body bgcolor="#FFFFFF" text="#000000"> <div class="moz-cite-prefix">Oke, <br> <br> So a leaf is a node which has no "branch"<br> <br> I have made a exercise where I have to made the logMessages. <br> Now I have to turn them into a tree <br> <br> Where does the second entry goes then ?<br> <br> Roelof<br> <br> <br> Konstantine Rybnikov schreef op 26-2-2015 om 14:56:<br> </div> <blockquote cite="mid:CAAbahfQO5o+Db_qy_B+vb3E6WWb1bdeQBmpAPa6E-5TwTjerjg@mail.gmail.com" type="cite"> <div dir="ltr"> <div> <div> <div> <div> <div> <div> <div>Hi Roelof,<br> <br> </div> I think you misunderstood it.<br> <br> </div> <div>There are two things here: types and values (value-constructors). They exist in different world, not touching each other.<br> <br> </div> <div>In Haskell, you define a type as:<br> <br> </div> <div>data <Type_Name> = <ValueConstructor_Name> <Type_Name> <Type_Name> <Type_Name><br> <br> </div> <div>You can create values as:<br> <br> </div> <div>let varName = <ValueConstructor_Name> <Value> <Value> <Value><br> <br> </div> <div>You need to put <Value> of some type, not type name itself in place of those <Value>s.<br> <br> </div> <div>So, with datatype you provided, you have two data-constructors:<br> <br> </div> <div>Leaf<br> <br> </div> <div>and<br> <br> </div> <div>Node <val> <val> <val><br> <br> </div> <div>You can create a leaf:<br> <br> </div> <div>let leaf = Leav<br> <br> </div> <div>or a node:<br> <br> </div> <div>let node = Node Leaf "msg" Leaf<br> <br> </div> <div>You can see that Node is a data-constructor that takes 3 values, not type-names as it's parameters.<br> <br> </div> <div>Hope this helps.<br> </div> </div> </div> </div> </div> </div> </div> <div class="gmail_extra"><br> <div class="gmail_quote">On Thu, Feb 26, 2015 at 3:21 PM, Roelof Wobben <span dir="ltr"><<a moz-do-not-send="true" href="mailto:r.wobben@home.nl" target="_blank">r.wobben@home.nl</a>></span> wrote:<br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br> <br> Suppose we have this definition of a tree :<br> <br> data MessageTree = Leaf<br> | Node MessageTree LogMessage MessageTree<br> deriving (Show, Eq)<br> <br> let Message = LogMessage "E 1 this is a test error"<br> let Message = LogMessage "e 2 this is the second test error "<br> <br> As I understand it right I can make the first entry like this : first_entry = Node Messagetree Message Messagetree<br> <br> And the second one like this second_entry = Node Message Messagetree Message2 Messagetree ??<br> <br> Roelof<br> <br> _______________________________________________<br> Beginners mailing list<br> <a moz-do-not-send="true" href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br> <a moz-do-not-send="true" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br> </blockquote> </div> <br> </div> <br> <fieldset class="mimeAttachmentHeader"></fieldset> <br> <pre wrap="">_______________________________________________ Beginners mailing list <a class="moz-txt-link-abbreviated" href="mailto:Beginners@haskell.org">Beginners@haskell.org</a> <a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a> </pre> </blockquote> <br> </body> </html>
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus@therning.org jabber: magnus@therning.org twitter: magthe http://therning.org/magnus Heuristic is an algorithm in a clown suit. It’s less predictable, it’s more fun, and it comes without a 30-day, money-back guarantee. -- Steve McConnell, Code Complete
participants (4)
-
Joel Neely
-
Konstantine Rybnikov
-
Magnus Therning
-
Roelof Wobben