Send Beginners mailing list submissions to
        [email protected]

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
        [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:  A few really short beginners questions (Daniel Fischer)
   2. Re:  A few really short beginners questions (Brent Yorgey)
   3. Re:  A few really short beginners questions (Brent Yorgey)
   4. Re:  A few really short beginners questions (Daniel Fischer)
   5. Re:  A few really short beginners questions
      (Andrew Sackville-West)


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

Message: 1
Date: Mon, 4 Oct 2010 14:08:08 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] A few really short beginners
        questions
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="utf-8"

On Sunday 03 October 2010 20:11:47, Andrew Sackville-West wrote:
> But this is not a property of "undefined"
> in this context. You've just given it a name that happens to coincide
> with a reserved word. You could just as easily use "x" or "foo" or
> whatever in the same way. Note that commonly, if you are not going to
> use the argument to a function, you use "_" to prevent it from being
> bound at all.

Minor correction, "undefined" is not a reserved word (like e.g. "data" is), 
it is just a variable (or name) bound in the Prelude.
You can shadow predefined names like undefined, otherwise etc., but not 
reserved words, so

f data = 3

won't compile while

f undefined = 3

will.


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

Message: 2
Date: Mon, 4 Oct 2010 09:43:12 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] A few really short beginners
        questions
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Mon, Oct 04, 2010 at 12:05:55AM +0200, Klaus Gy wrote:
> 2010/10/3, Isaac Dupree <[email protected]>:
> > On 10/03/10 14:39, Klaus Gy wrote:
> >> Thank You very much for the fast replies! I think I expressed myself
> >> badly in the first question. What does not work is the following:
> >>
> >>   class Test a
> >>
> >>   instance Num a =>  Test a
> >
> > For a reason that seems pretty odd until you get used to it.
> > In the instance, "Test a", or the "a" thereof, is called the "instance
> > head".  "Num a" is called the "context".  When the compiler looks for an
> > instance, it works by looking just at the "instance head": and "a"
> > refers to all types.  "instance Num a =>  Test a" says that the one and
> > only instance that the class has is the one described in that instance.
> >   (And it only works when "a" is a Num type; for other attempted uses
> > you'd get a compile error.)  For various reasons, such instances aren't
> > allowed by default.
> >
> > Note that instance Num a =>  Test [a] might also mean something
> > different than you intended, even though it's allowed: it defines the
> > one and only instance of Test on lists.
> >
> > -Isaac
> 
> Thanks! I could have avoided this question because I've just found out
> that the details of instance declarations are all described in the
> Haskell 98 report along with other restrictions I was not aware of.
> So, can I assume that there is no need in praxis to declare all
> instances of an existing class to instances of a new class?

No, this is a reasonable thing to do sometimes.  As the error message
says, if you want to enable this you can turn on the FlexibleInstances
flag (either by passing -XFlexibleInstances to the compiler, or by
putting

{-# LANGUAGE FlexibleInstances #-}

at the top of your program).

-Brent


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

Message: 3
Date: Mon, 4 Oct 2010 09:44:53 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] A few really short beginners
        questions
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Sun, Oct 03, 2010 at 09:44:28PM +0200, Klaus Gy wrote:
> Yea, Hugs tells me:
> 
> ERROR (filepath):3 - Syntax error in instance head (constructor expected)
> 
> But since I'm trying to understand Haskell and have nothing particular
> in mind with this program, I'm not stressed finding a solution for
> this. I'm happy if the code is principally correct.

Ah, I see, you are using Hugs.  As I mention in my other email, GHC
has an extension (FlexibleInstances) to allow this.  Hugs might
support this extension as well (I am not sure) but it unfortunately
doesn't mention the possibility in the error message, like GHC does.

-Brent


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

Message: 4
Date: Mon, 4 Oct 2010 16:08:00 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] A few really short beginners
        questions
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="iso-8859-1"

On Monday 04 October 2010 15:44:53, Brent Yorgey wrote:
> On Sun, Oct 03, 2010 at 09:44:28PM +0200, Klaus Gy wrote:
> > Yea, Hugs tells me:
> >
> > ERROR (filepath):3 - Syntax error in instance head (constructor
> > expected)
> >
> > But since I'm trying to understand Haskell and have nothing particular
> > in mind with this program, I'm not stressed finding a solution for
> > this. I'm happy if the code is principally correct.
>
> Ah, I see, you are using Hugs.  As I mention in my other email, GHC
> has an extension (FlexibleInstances) to allow this.  Hugs might
> support this extension as well (I am not sure)

It does, but AFAIK, hugs offers less fine-grained control over which 
extensions to enable, you need the -98 command line option, which turns on 
almost all extensions hugs has (I think the only extension individually 
controllable is overlapping instances, +o or +O for unsafe overlapping 
instances).

> but it unfortunately
> doesn't mention the possibility in the error message, like GHC does.
>
> -Brent



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

Message: 5
Date: Mon, 4 Oct 2010 09:48:25 -0700
From: Andrew Sackville-West <[email protected]>
Subject: Re: [Haskell-beginners] A few really short beginners
        questions
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

On Mon, Oct 04, 2010 at 02:08:08PM +0200, Daniel Fischer wrote:
> On Sunday 03 October 2010 20:11:47, Andrew Sackville-West wrote:
> > But this is not a property of "undefined"
> > in this context. You've just given it a name that happens to coincide
> > with a reserved word. You could just as easily use "x" or "foo" or
> > whatever in the same way. Note that commonly, if you are not going to
> > use the argument to a function, you use "_" to prevent it from being
> > bound at all.
> 
> Minor correction, "undefined" is not a reserved word (like e.g. "data" is), 
> it is just a variable (or name) bound in the Prelude.
> You can shadow predefined names like undefined, otherwise etc., but not 
> reserved words, so
> 
> f data = 3
> 
> won't compile while
> 
> f undefined = 3
>
> will.
>

Thanks!

A
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
Url : 
http://www.haskell.org/pipermail/beginners/attachments/20101004/cbd2c34e/attachment-0001.bin

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

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 28, Issue 13
*****************************************

Reply via email to