Re: pattern guards + monads

1997-05-15 Thread Malcolm Wallace

I am having a little trouble following the two discussions on pattern
guards and monads, due to some (probably minor) confusing pieces of
syntax.  Would anyone like to clarify these for me?  It would help me
to understand the underlying issues.  Thanks.


On pattern guards, Simon PJ writes:
  f (x:xs) | x0 = e1
   | x0 = e2
   | otherwise = e3

then
   g a | (x:xs) - h a, x0 = e1
   | (x:xs) - h a, x0 = e1
   | otherwise = e3

Am i right in thinking that f [] is bottom, whilst g [] is e3?

Later, another definition of g (intended to be equivalent?) is given in
which g [] appears to be bottom:
  g a | (x:xs) - h a
 | x0 = e1
 | x0 = e2
 | otherwise = e3

To match the semantics of the earlier definition of g, shouldn't this
read as follows?
   g a | (x:xs) - h a
  | x0 = e1
  | x0 = e2
   | otherwise = e3


Now, for monads, Phil Wadler writes a law:
   m = \x - k x ++ h x  =  m = k ++ n = k

in which 'h' appears on the lhs but not the rhs, and 'n' on the rhs but
not the lhs.  Are h and n the same?  Or perhaps the equation should read
as follows?
m = \x - k x ++ h x  =  m = k ++ m = h


Regards,
Malcolm

[EMAIL PROTECTED]






Re: pattern guards + monads

1997-05-15 Thread Philip Wadler

 Now, for monads, Phil Wadler writes a law:
m = \x - k x ++ h x  =  m = k ++ n = k
 
 in which 'h' appears on the lhs but not the rhs, and 'n' on the rhs but
 not the lhs.  ... perhaps the equation should read as follows?
 m = \x - k x ++ h x  =  m = k ++ m = h

Yes, of course it should.  Thanks for the correction.  -- P