|On a similar note, what does this (legal Haskell 98) definition mean?
|
|       (((+) + 1) + 1) 1 = (+)
|
|That's right!
|
|       (+) :: (Integral a, Num b, Num c) => a -> b -> c -> a

I was about to ask you to explain this, but in writing this email,
I've worked it out.. :-)

decl -> gendecl 
     | (funlhs | pat0) rhs 

funlhs -> var apat {apat } 
       |  pati+1 varop(a,i) pati+1 
       |  lpati varop(l,i) pati+1 
       |  pati+1 varop(r,i) rpati 
       |  ( funlhs ) apat {apat } 

We have: "(((+) + 1) + 1)" then "1", so we can't have <pat0>, so it
must be <funlhs>.  There are only two terms, and the first is not
<var> so it must be <(funlhs) apat>.  For "((+) + 1) + 1" to be
<funlhs>, the third "+" must be a <varop> as it cannot be an <apat>
(it would have to have brackets around it).  So, "((+) + 1)" is a
<pat>, and thus "(+)" is <var>.  Therefore, "(+)" is acting as an
integer here.

But then, to what does the "(+)" on the rhs refer?  This is similar
to:

f f = f

which was on the list a while back IIRC, and defines the identity
according to Hugs (I'm not sure if this is dictated by the language
report or not).  By analogy then, the equation:

(((+) + 1) + 1) 1 = (+)

defines a function (+) that takes an integer N, and two further
elements of Num, and if these elements are both 1 then it returns N-1.

Correct? :-)

There, that only took about an hour... ;-)

Graeme.


Reply via email to