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.  change to wikibook? (Ashley Smith)
   2. Re:  change to wikibook? (Brandon Allbery)
   3. Re:  change to wikibook? (Brent Yorgey)
   4. Re:  change to wikibook? (Gregg Lebovitz)


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

Message: 1
Date: Sat, 12 May 2012 22:15:42 +0200
From: Ashley Smith <[email protected]>
Subject: [Haskell-beginners] change to wikibook?
To: [email protected]
Message-ID:
        <CAFM2CJZwgpWi59AFTu9P=pv+y3sb0gnmp2gpu0uma_h-ql9...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I was wondering if someone could explain this error? I typed in the sample
code from the Haskell Beginning Wikibook to define a function for absolute
value. I have GHC 7.0.4 for OSX. The error went away when I put parentheses
around the negative value, so did the Haskell interpreter think I was
entering - and a second argument, namely 10, when the parentheses weren't
there? Thank you!

*Main> let abs x = if x < 0 then -x else x
*Main> abs 5
5
*Main> abs -10

And got the following error
<interactive>:1:6:
    No instance for (Num (a0 -> a0))
      arising from the literal `10'
    Possible fix: add an instance declaration for (Num (a0 -> a0))
    In the second argument of `(-)', namely `10'
    In the expression: abs - 10
    In an equation for `it': it = abs - 10
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120512/1a9acf88/attachment-0001.htm>

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

Message: 2
Date: Sat, 12 May 2012 16:35:19 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] change to wikibook?
To: Ashley Smith <[email protected]>
Cc: [email protected]
Message-ID:
        <CAKFCL4VjkCFiJp4frTw4FWcKOkN3eNfyAemtfZk=4faer6g...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Sat, May 12, 2012 at 4:15 PM, Ashley Smith <[email protected]>wrote:

> I was wondering if someone could explain this error? I typed in the sample
> code from the Haskell Beginning Wikibook to define a function for absolute
> value. I have GHC 7.0.4 for OSX. The error went away when I put parentheses
> around the negative value, so did the Haskell interpreter think I was
> entering - and a second argument, namely 10, when the parentheses weren't
> there? Thank you!
>

If the WikiBook provided that as an example, then it's buggy and someone
should fix it.  This is a longstanding and difficult to fix annoyance of
Haskel's syntax; the parenthese *are* required there.

Briefly:  unary operators don't work very well.  It can't resolve them by
context because it's not impossible for a function to typecheck there
(nobody recommends Num instances for functions, but they're not forbidden
either), and syntactically they conflict with sections (resolved in favor
of the unary op, with the result that there's a function "subtract" that
exists just to facilitate the (`subtract` 1) section.)  What this adds up
to is that you should be very careful around "-" because it's trying to
satisfy too many mutually incompatible pieces of syntax.

-- 
brandon s allbery                                      [email protected]
wandering unix systems administrator (available)     (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120512/50196fa4/attachment-0001.htm>

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

Message: 3
Date: Sat, 12 May 2012 16:35:30 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] change to wikibook?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Sat, May 12, 2012 at 10:15:42PM +0200, Ashley Smith wrote:
> I was wondering if someone could explain this error? I typed in the sample
> code from the Haskell Beginning Wikibook to define a function for absolute
> value. I have GHC 7.0.4 for OSX. The error went away when I put parentheses
> around the negative value, so did the Haskell interpreter think I was
> entering - and a second argument, namely 10, when the parentheses weren't
> there? Thank you!

Exactly.  This is a rather ugly corner of Haskell's lexical syntax,
but it matches the official specification.  Negative numbers often
require parentheses around them so that the negation symbol does not
parse as subtraction.

If the wikibook itself actually lists "abs -10" as an example for you
to try out, it should be fixed.

-Brent



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

Message: 4
Date: Sat, 12 May 2012 16:37:10 -0400
From: Gregg Lebovitz <[email protected]>
Subject: Re: [Haskell-beginners] change to wikibook?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120512/15bd99d7/attachment-0001.htm>

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

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


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

Reply via email to