| On pattern guards, Simon PJ writes:
| >  f (x:xs) | x<0 = e1
| >           | x>0 = e2
| >           | otherwise = e3
| 
| then
| >   g a | (x:xs) <- h a, x<0 = e1
| >       | (x:xs) <- h a, x>0 = e1
| >       | otherwise = e3
| 
| Am i right in thinking that f [] is bottom, whilst g [] is e3?

Not quite.  Certainly f [] is bottom.  But g matches (x:xs) against (h a),
not against a.  So a might not be of type list.  What is certainly true
is that if (h a) == [], then g a 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
| >         | x<0 = e1
| >         | x>0 = 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
|           | x<0 = e1
|           | x>0 = e2
|        | otherwise = e3

You're dead right.  Nested guards are a bit tricky, eh?

Simon



Reply via email to