Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: CANCEL ME PLEASE (Henk-Jan van Tuyl)
2. Error while using type and data constructor (Nishant)
3. Re: Error while using type and data constructor (Mike Meyer)
4. Re: Error while using type and data constructor (Nishant)
----------------------------------------------------------------------
Message: 1
Date: Fri, 15 May 2015 10:52:48 +0200
From: "Henk-Jan van Tuyl" <[email protected]>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell" <[email protected]>,
"Letizia Galli" <[email protected]>, "The Haskell-Beginners
Mailing List - Discussion of primarily beginner-level topics related
to Haskell" <[email protected]>
Subject: Re: [Haskell-beginners] CANCEL ME PLEASE
Message-ID: <op.xyn5ma06pz0j5l@alquantor>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
delsp=yes
I don't know if an admin will unsubscribe you, but you can do it yourself
at th bottom of the page
https://mail.haskell.org/mailman/listinfo/beginners
Regards,
Henk-Jan van Tuyl
--
Folding@home
What if you could share your unused computer power to help find a cure? In
just 5 minutes you can join the world's biggest networked computer and get
us closer sooner. Watch the video.
http://folding.stanford.edu/
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--
------------------------------
Message: 2
Date: Fri, 15 May 2015 15:18:32 +0530
From: Nishant <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Error while using type and data
constructor
Message-ID:
<CAEQDmz5ThAUcx8aeeyJW1ehtPerfuDeZg-QojoQr=opn6ud...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi,
I was writing some code for Tree.
1 : data Tree a = NULL | Node a (Tree a) (Tree a) works fine. But,
2 : data Tree a = NULL | Tree a (Node a) Tree a does not work. GHCI says
Not in scope " type constructor or class 'Node'.
Why is 2 declaration not valid though second definition looks much more
closer to what a binary tree actually means ?
Regards
Nishant Verma
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150515/54a3fd7a/attachment-0001.html>
------------------------------
Message: 3
Date: Fri, 15 May 2015 05:27:57 -0500
From: Mike Meyer <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Error while using type and data
constructor
Message-ID:
<CAD=7U2DE8JS0e3F2OHZ2YxVLWAqHz_NHdjj8PKk2SKyM1O=s...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Fri, May 15, 2015 at 4:48 AM, Nishant <[email protected]> wrote:
> 1 : data Tree a = NULL | Node a (Tree a) (Tree a) works fine. But,
> 2 : data Tree a = NULL | Tree a (Node a) Tree a does not work. GHCI says
> Not in scope " type constructor or class 'Node'.
>
> Why is 2 declaration not valid though second definition looks much more
> closer to what a binary tree actually means ?
>
Because Haskell isn't english. A constructor is parsed as the name of the
constructor being defined followed by zero or more types. Your first
version defines the constructor name Node followed by the types a, Tree a
and Tree a. The second one defines the constructor name Tree followed by
the types a, Node a and Tree a. You have to define the type Node for this
to work.
So you could do:
data Node a = Node a
data Tree a = NULL | Tree (Tree a) (Node a) (Tree a)
But then you have to say "Tree NULL (Node 1.0) NULL" to a tree holding 1.0
with empty left and right subtrees. If you do it they way you said first,
you can just say "Node 1.0 Null Null".
Maybe you want "date Tree a = NULL | Node (Tree a) a (Tree a)"? Then you
you can say "Node NULL 1.0 NULL". Or even "Date Tree a = NULL | Tree (Tree
a) a (Tree a)", for "Tree NULL 1.0 NULL"?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150515/de76b570/attachment-0001.html>
------------------------------
Message: 4
Date: Fri, 15 May 2015 16:27:23 +0530
From: Nishant <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Error while using type and data
constructor
Message-ID:
<CAEQDmz6V53X_90Erg2qC9rgu7j51ku=f_LQ+XDvUafW=woe...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Thanks Mike. The statement " A constructor is parsed as the name of the
constructor being defined followed by zero or more types" made everything
clear.
On Fri, May 15, 2015 at 3:57 PM, Mike Meyer <[email protected]> wrote:
> On Fri, May 15, 2015 at 4:48 AM, Nishant <[email protected]> wrote:
>
>> 1 : data Tree a = NULL | Node a (Tree a) (Tree a) works fine. But,
>> 2 : data Tree a = NULL | Tree a (Node a) Tree a does not work. GHCI says
>> Not in scope " type constructor or class 'Node'.
>>
>> Why is 2 declaration not valid though second definition looks much more
>> closer to what a binary tree actually means ?
>>
>
> Because Haskell isn't english. A constructor is parsed as the name of the
> constructor being defined followed by zero or more types. Your first
> version defines the constructor name Node followed by the types a, Tree a
> and Tree a. The second one defines the constructor name Tree followed by
> the types a, Node a and Tree a. You have to define the type Node for this
> to work.
>
> So you could do:
>
> data Node a = Node a
> data Tree a = NULL | Tree (Tree a) (Node a) (Tree a)
>
> But then you have to say "Tree NULL (Node 1.0) NULL" to a tree holding 1.0
> with empty left and right subtrees. If you do it they way you said first,
> you can just say "Node 1.0 Null Null".
>
> Maybe you want "date Tree a = NULL | Node (Tree a) a (Tree a)"? Then you
> you can say "Node NULL 1.0 NULL". Or even "Date Tree a = NULL | Tree (Tree
> a) a (Tree a)", for "Tree NULL 1.0 NULL"?
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
--
Nishant
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150515/1f4e843b/attachment-0001.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 83, Issue 42
*****************************************