Thu, 5 Jun 2003 18:44:41 +0100
On Thu, Jun 05, 2003 at 10:03:55AM +0100, Graham Klyne wrote:
> At 19:50 04/06/03 -0400, Derek Elkins wrote:
> > You (Graham) also have some parentheses issues; e.g. in foo ++
> > (combinations 5 l) the parentheses are superfluous.
> I'm tempted to argue that being superfluous doesn't mean they
> shouldn't be there.
Keith already made one argument for less parentheses, here's my take on
(++) :: [a] -> [a] -> [a] -- contatenates lists
foo, l :: [a] -- are lists
bar :: Int -> [a] -> [a] -- produces a list
Which of the following make sense?
> (foo ++) bar 5 l -- No, because bar isn't a list,
> (foo ++ bar) 5 l -- and 5 and l would be applied to a list,
> (foo ++ bar 5) l -- (as opposed to a function,) which make no sense
> foo (++ bar 5 l) -- Can't apply a function to a value,
> -- though (++ bar 5 l) foo has the same effect as what we intended
> foo ++ (bar 5 l) -- which is just foo ++ bar 5 l
Because of the static type checking that takes place, you can't easily
(not unless you were _trying_ ;) produce an ambiguous expression such
that the removal of brackets keeps it well-typed, yet is not equivalent
to the original. So as opposed to the C code where you (and I) would put
in extra brackets `just to be sure', I wouldn't bother with them unless
I know the expression's going to be ambiguous. (or if the compiler tells
me so. ;-)
(I suppose you could argue it's not necessarily obvious that foo is a
list and bar is a 2-ary function of an Int and a list. My response would
be to rename foo and bar so that this is the case. ;-)
> I'd just about figured the ShowS idea, but I've yet to get a handle on this
> idea of [a] 'monoid'.
Might http://www.engr.mun.ca/~theo/Misc/haskell_and_monads.htm be of any
/Liyang -- who managed to sneak into Category Theory lectures, but still
has no idea what a monad is. ^_^;
.--| Liyang HU |--| http://nerv.cx/ |--| Caius@Cam |--| ICQ: 39391385 |--.
| :::::::::::::::::::::: This is not a signature. :::::::::::::::::::::: |