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.  Odd behavior from WinHugs (David Schonberger)
   2. Re:  Odd behavior from WinHugs (Justin Bailey)
   3. Re:  Odd behavior from WinHugs (Conrad Meyer)
   4. Re:  Odd behavior from WinHugs (Daniel Fischer)
   5. Re:  Odd behavior from WinHugs (Conrad Meyer)
   6. Re:  Odd behavior from WinHugs (Daniel Fischer)
   7. Re:  Re: [Haskell-cafe] The problem with Monads...
      (Peter Verswyvelen)


----------------------------------------------------------------------

Message: 1
Date: Wed, 14 Jan 2009 11:44:07 -0800
From: David Schonberger <llp_...@hotmail.com>
Subject: [Haskell-beginners] Odd behavior from WinHugs
To: <beginners@haskell.org>
Message-ID: <bay126-w3e33de97db9d4aa18e0a29a...@phx.gbl>
Content-Type: text/plain; charset="iso-8859-1"



Hi all. I'm attempting exercise 4.6 from Daume's Yet Another Haskell Tutorial:
 
Exercise 4.6 Write a datatype Tuple which can hold one, two, three or four 
elements,
depending on the constructor (that is, there should be four constructors, one 
for each
number of arguments). Also provide functions tuple1 through tuple4 which take a
tuple and return Just the value in that position, or Nothing if the number is 
invalid
(i.e., you ask for the tuple4 on a tuple holding only two elements)
 
For starters, I began with the following, stored in a file called MyTuple.hs:
 
data myTuple a b c d = my4Tuple a b c d
| my3Tuple a b c
| my2Tuple a b
| my1Tuple a
deriving (Show)
 
When I load this into WinHugs I get the following error:
 
file:.\MyTuple.hs:1 - Syntax error in data declaration (unexpected symbol "a")
 
However I get the same error if I reduce it to a single data constructor, in an 
effort to create just a quadruple:
 
data myTuple a b c d = my4Tuple a b c d
 
What is even more odd is that I have the following code in a file called 
Pair.hs:
 
{-data Pair a b = Pair a b deriving (Show)pairFst (Pair x y) = xpairSnd (Pair x 
y) = y
data Quadruple a b c d = Quadruple a a b b deriving (Show)fstPairofQuad 
(Quadruple a b c d) = [a,b]sndPairofQuad (Quadruple a b c d) = [c,d]-}
data Quad a b c d = QuadFour a b c d | QuadThree a b c | QuadTwo a b | QuadOne 
a deriving (Show)
{-fstPairofQuad (QuadFour a b c d) = (a,b)mdlPairofQuad (QuadFour a b c d) = 
(b,c)sndPairofQuad (QuadFour a b c d) = (c,d)fstLstofQuad (QuadFour a b c d) = 
(a,d)-}
 
Whether I just keep Quad visible in the file or I take away both pairs of 
comment braces, when I load that file into WinHugs it works fine,
and I have no trouble constructing a Quad or using any of the QuadFour utility 
fcns (which, admittedly are not what is called for in the exercise...
but that's probably besides the point). 
 
What in the world might be causing the error in the MyTuple file?
 
Thanks,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20090114/dd594b02/attachment-0001.htm

------------------------------

Message: 2
Date: Wed, 14 Jan 2009 11:46:23 -0800
From: "Justin Bailey" <jgbai...@gmail.com>
Subject: Re: [Haskell-beginners] Odd behavior from WinHugs
To: "David Schonberger" <llp_...@hotmail.com>
Cc: beginners@haskell.org
Message-ID:
        <a45dff840901141146o6f1c120bne5932da151485...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

You have to capitalize your type names and data constructors:

data MyTuple a b c d = My4Tuple a b c d
| My3Tuple a b c
| My2Tuple a b
| My1Tuple a
deriving (Show)

On Wed, Jan 14, 2009 at 11:44 AM, David Schonberger <llp_...@hotmail.com> wrote:
>
> Hi all. I'm attempting exercise 4.6 from Daume's Yet Another Haskell
> Tutorial:
>
>
> Exercise 4.6
>
> Write a datatype Tuple which can hold one, two, three or four elements,
>
> depending on the constructor (that is, there should be four constructors,
> one for each
>
> number of arguments). Also provide functions
>
> tuple1 through tuple4 which take a
>
> tuple and return
>
> Just the value in that position, or Nothing if the number is invalid (i.e.,
> you ask for the tuple4 on a tuple holding only two elements)
>
> For starters, I began with the following, stored in a file called
> MyTuple.hs:
>
> data myTuple a b c d = my4Tuple a b c d
> | my3Tuple a b c
> | my2Tuple a b
> | my1Tuple a
> deriving (Show)
>
> When I load this into WinHugs I get the following error:
>
> file:.\MyTuple.hs:1 - Syntax error in data declaration (unexpected symbol
> "a")
>
> However I get the same error if I reduce it to a single data constructor, in
> an effort to create just a quadruple:
>
> data myTuple a b c d = my4Tuple a b c d
>
> What is even more odd is that I have the following code in a file called
> Pair.hs:
>
> {-data Pair a b = Pair a b
>  deriving (Show)
> pairFst (Pair x y) = x
> pairSnd (Pair x y) = y
> data Quadruple a b c d = Quadruple a a b b
>  deriving (Show)
> fstPairofQuad (Quadruple a b c d) = [a,b]
> sndPairofQuad (Quadruple a b c d) = [c,d]
> -}
>
> data Quad a b c d = QuadFour a b c d | QuadThree a b c | QuadTwo a b |
> QuadOne a
>  deriving (Show)
>
> {-
> fstPairofQuad (QuadFour a b c d) = (a,b)
> mdlPairofQuad (QuadFour a b c d) = (b,c)
> sndPairofQuad (QuadFour a b c d) = (c,d)
> fstLstofQuad (QuadFour a b c d) = (a,d)-}
>
> Whether I just keep Quad visible in the file or I take away both pairs of
> comment braces, when I load that file into WinHugs it works fine,
> and I have no trouble constructing a Quad or using any of the QuadFour
> utility fcns (which, admittedly are not what is called for in the
> exercise...
> but that's probably besides the point).
>
> What in the world might be causing the error in the MyTuple file?
>
> Thanks,
> David
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>


------------------------------

Message: 3
Date: Wed, 14 Jan 2009 12:23:55 -0800
From: Conrad Meyer <kon...@tylerc.org>
Subject: Re: [Haskell-beginners] Odd behavior from WinHugs
To: beginners@haskell.org
Message-ID: <200901141223.55751.kon...@tylerc.org>
Content-Type: text/plain;  charset="iso-8859-1"

On Wednesday 14 January 2009 11:46:23 am Justin Bailey wrote:
> You have to capitalize your type names and data constructors:
>
> data MyTuple a b c d = My4Tuple a b c d
>
> | My3Tuple a b c
> | My2Tuple a b
> | My1Tuple a
>
> deriving (Show)

Also, I think (but by no means am I sure) that you should cut out 'a b c d' 
from the left side, i.e.:

data MyTuple = My4Tuple a b c d
  | My3Tuple a b c
  | My2Tuple a b
  | My1Tuple a
  deriving (Show)

Someone please tell me if I am wrong :).

Regards,
-- 
Conrad Meyer <kon...@tylerc.org>




------------------------------

Message: 4
Date: Wed, 14 Jan 2009 22:07:06 +0100
From: Daniel Fischer <daniel.is.fisc...@web.de>
Subject: Re: [Haskell-beginners] Odd behavior from WinHugs
To: Conrad Meyer <kon...@tylerc.org>, beginners@haskell.org
Message-ID: <200901142207.06678.daniel.is.fisc...@web.de>
Content-Type: text/plain;  charset="iso-8859-1"

Am Mittwoch, 14. Januar 2009 21:23 schrieb Conrad Meyer:
> On Wednesday 14 January 2009 11:46:23 am Justin Bailey wrote:
> > You have to capitalize your type names and data constructors:
> >
> > data MyTuple a b c d = My4Tuple a b c d
> >
> > | My3Tuple a b c
> > | My2Tuple a b
> > | My1Tuple a
> >
> > deriving (Show)
>
> Also, I think (but by no means am I sure) that you should cut out 'a b c d'
> from the left side, i.e.:
>
> data MyTuple = My4Tuple a b c d
>
>   | My3Tuple a b c
>   | My2Tuple a b
>   | My1Tuple a
>
>   deriving (Show)
>
> Someone please tell me if I am wrong :).

The type variables are necessary on the left hand side, otherwise a 
(My3Tuple x y z) could hold values of completely unknown type and so you 
couldn't do anything useful with it.

If the types of things held weren't specified on the left, what type could 
firstOfTuple have?

>
> Regards,



------------------------------

Message: 5
Date: Wed, 14 Jan 2009 13:11:14 -0800
From: Conrad Meyer <kon...@tylerc.org>
Subject: Re: [Haskell-beginners] Odd behavior from WinHugs
To: beginners@haskell.org
Message-ID: <200901141311.14861.kon...@tylerc.org>
Content-Type: text/plain;  charset="iso-8859-1"

On Wednesday 14 January 2009 01:07:06 pm Daniel Fischer wrote:
> If the types of things held weren't specified on the left, what type could
> firstOfTuple have?

Polymorphic (i.e. any) type.

-- 
Conrad Meyer <kon...@tylerc.org>




------------------------------

Message: 6
Date: Wed, 14 Jan 2009 22:29:11 +0100
From: Daniel Fischer <daniel.is.fisc...@web.de>
Subject: Re: [Haskell-beginners] Odd behavior from WinHugs
To: Conrad Meyer <kon...@tylerc.org>, beginners@haskell.org
Message-ID: <200901142228.27682.daniel.is.fisc...@web.de>
Content-Type: text/plain;  charset="iso-8859-1"

Am Mittwoch, 14. Januar 2009 22:11 schrieb Conrad Meyer:
> On Wednesday 14 January 2009 01:07:06 pm Daniel Fischer wrote:
> > If the types of things held weren't specified on the left, what type
> > could firstOfTuple have?
>
> Polymorphic (i.e. any) type.

You mean

firstOfTuple :: exists a. MyTuple -> a

?
As of now, that's an illegal type.


------------------------------

Message: 7
Date: Wed, 14 Jan 2009 12:30:11 +0100
From: "Peter Verswyvelen" <bugf...@gmail.com>
Subject: Re: [Haskell-beginners] Re: [Haskell-cafe] The problem with
        Monads...
To: "Henk-Jan van Tuyl" <hjgt...@chello.nl>
Cc: beginners@haskell.org,      Rafael Gustavo da Cunha Pereira Pinto
        <rafaelgcpp.li...@gmail.com>,   haskell-c...@haskell.org
Message-ID:
        <a88790d10901140330k524aaf0ag6f54af2dd1cb9...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

>
> I have written a reference manual for the basic Haskell monad functions, "A
> Tour of the Haskell Monad functions". It contains a lot of examples. You can
> find it at:
>  http://members.chello.nl/hjgtuyl/tourdemonad.html


Wow! I like these examples. I'm a pragmatist, and although Haskell gave me
the most intense joy I ever experienced with programming (and also
frustrations ;-), I find it extremely difficult to learn it from research
papers.

But these small examples are exactly what I need, because my brain will
easier recognize a pattern match with the specific examples, than with the
abstract explanation (and I was pretty good at abstract algebra, but that's
20 years ago, and I filled these 2 decades with lots and lots of imperative
and OO hacking ;-).

I wish every function in every module in the documentation had an "examples"
link next to the "source" link, or a link to examples on the wiki or
something.

I guess the smart computer scientists here will tell me that I need to lift
my brain to learn to recognize abstract patterns, but I'm afraid this is not
something that is given to all of us, certainly not in the short term. But I
still want to enjoy Haskell, so keep the short examples coming :)


>
> As far as I know, there is no reference guide for advanced monads, like the
> Reader, Writer and State monads.
>
> --
> Regards,
> Henk-Jan van Tuyl
>
>
> --
> http://functor.bamikanarie.com
> http://Van.Tuyl.eu/
> --
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> haskell-c...@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20090114/f8e570df/attachment.htm

------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 7, Issue 12
****************************************

Reply via email to