[Haskell-cafe] Re: Unary Minus

2009-04-06 Thread Benjamin L . Russell
On Mon, 6 Apr 2009 12:13:09 +0200, Roel van Dijk
vandijk.r...@gmail.com wrote:

On Mon, Apr 6, 2009 at 12:04 PM, Benjamin L.Russell
dekudekup...@yahoo.com wrote:
 Interesting. ?How is this hack implemented?

This seems to be the relevant grammar:
  lexp6 - - exp7
  lpat6 - - (integer | float)(negative literal)

The '6's and the '7' are superscripts.
Perhaps the hack is in the precedence of the expression in which an
unary minus is allowed.

Yes, I see it now.  It's under 9.5  Context-Free Syntax, instead of
being under 9.2  Lexical Syntax, so it's a syntactic rule, rather
than a lexical rule.

According to the rule, a left-expression of precedence level 6
consists of '-' followed by an expression of precedence level 7, and
a left-pattern of precedence level 6 consists of '-' followed by
(an integer or a float), and by definition, this is a negative
literal.  Integers and floats, in turn, are part of the lexical
syntax.

-- Benjamin L. Russell
-- 
Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile:  +011 81 80-3603-6725
Furuike ya, kawazu tobikomu mizu no oto. 
-- Matsuo Basho^ 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Unary Minus

2009-04-06 Thread Benjamin L . Russell
On Mon, 6 Apr 2009 12:13:09 +0200, Roel van Dijk
vandijk.r...@gmail.com wrote:

On Mon, Apr 6, 2009 at 12:04 PM, Benjamin L.Russell
dekudekup...@yahoo.com wrote:
 Interesting. ?How is this hack implemented?

This seems to be the relevant grammar:
  lexp6 - - exp7
  lpat6 - - (integer | float)(negative literal)

The '6's and the '7' are superscripts.
Perhaps the hack is in the precedence of the expression in which an
unary minus is allowed.

What's interesting are the following definitions of the functions '-'
(binary minus) and negate given in 8  Standard Prelude (see
http://www.haskell.org/onlinereport/standard-prelude.html#$tNum):

class  (Eq a, Show a) = Num a  where
(+), (-), (*):: a - a - a
negate   :: a - a
abs, signum  :: a - a
fromInteger  :: Integer - a

-- Minimal complete definition:
--  All, except negate or (-)
x - y=  x + negate y
negate x =  0 - x

The type of negate, a - a, where a is a Num, is precisely what is
needed for a unary minus.

-- Benjamin L. Russell
-- 
Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile:  +011 81 80-3603-6725
Furuike ya, kawazu tobikomu mizu no oto. 
-- Matsuo Basho^ 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Unary Minus

2009-04-06 Thread Roel van Dijk
On Mon, Apr 6, 2009 at 12:04 PM, Benjamin L.Russell
dekudekup...@yahoo.com wrote:
 Interesting.  How is this hack implemented?

This seems to be the relevant grammar:
  lexp6 - - exp7
  lpat6 - - (integer | float)(negative literal)

The '6's and the '7' are superscripts.
Perhaps the hack is in the precedence of the expression in which an
unary minus is allowed.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Unary Minus

2009-04-06 Thread Benjamin L . Russell
Interesting.  How is this hack implemented?

I just checked the BNF grammar for the lexical syntax of Haskell in
The Haskell 98 Language Report (see the BNF grammer given under 9.2
Lexical Syntax under 9  Syntax Reference at
http://www.haskell.org/onlinereport/syntax-iso.html), but had
difficulty in deriving a unary minus.

Could somebody please enlighten me on how to derive the expression
-1 (a unary minus followed the the ascDigit 1) from the
above-mentioned BNF grammar?  Or is a unary minus not part of this
grammar?

-- Benjamin L. Russell

On Mon, 6 Apr 2009 11:14:52 +0200, Lennart Augustsson
lenn...@augustsson.net wrote:

Unary minus is a hack in the syntax for allowing the function negate
to be written as prefix -.

On Mon, Apr 6, 2009 at 10:36 AM, Martijn van Steenbergen
mart...@van.steenbergen.nl wrote:
 Paul Keir wrote:

 If I use :info (-) I get information on the binary minus. Is unary minus
 also a function?

 No, as far as I know the unary minus is part of the number literals. You can
 use negate if you want it as a function.

 Hope this helps,

 Martijn.

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

-- 
Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile:  +011 81 80-3603-6725
Furuike ya, kawazu tobikomu mizu no oto. 
-- Matsuo Basho^ 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe