[Haskell-beginners] trees on Haskell : Do I understand it right ?
Konstantine Rybnikov
k-bx at k-bx.com
Thu Feb 26 14:08:37 UTC 2015
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 <r.wobben at 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 <Type_Name> = <ValueConstructor_Name> <Type_Name> <Type_Name>
> <Type_Name>
>
> You can create values as:
>
> let varName = <ValueConstructor_Name> <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 <r.wobben at 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 at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
>
>
> _______________________________________________
> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150226/801f5b26/attachment-0001.html>
More information about the Beginners
mailing list