= vs ->

D. Tweed tweed@compsci.bristol.ac.uk
Wed, 10 Oct 2001 07:55:43 +0100 (BST)

On 10 Oct 2001, Ketil Malde wrote:

> Mark Carroll <mark@chaos.x-philes.com> writes:
> > On Tue, 9 Oct 2001, Ashley Yakeley wrote:
> >> At 2001-10-09 11:55, Mark Carroll wrote:
> >>> What is the rationale for when Haskell demands a "=" and when it
> >>> demands a "->"?
> Okay, I can't give you anything formal, but here's my intuitive
> understanding of things
> > e.g. 
> > x :: Integer -> Integer
> A function "from" and Integer to an Integer.  Even more obvious if you
> have one more parameter:
>   g :: Integer -> Integer -> Integer
> g takes an Integer and returns a function that takes an Integer and
> returns an Integer.  Equals-assignment would be very non-intuitive
> here. 

As I understand it, the equals sign is used whenever the item on both
sides are equal, i.e., one side can be replaced with the other without
changing meaning. Of course, in the case of a function definition it's the
degenerate equality you get from defining the lhs in terms of the rhs. The
-> is used whenever you've got something on the right that `leads to' to
something on the left, eg

  case x of
  Maybe y ->True
  Nothing ->False

It is not the case that `Maybe y' is the same as True, so = is clearly
inappropraite. Likewise for lambdas (\x->x+2 doesn't have x = x+2).

It's perhaps less clear because after using functional languages for any
length of time you get very used to thinking of function definitions as a
restricted kind of rewrite rule, and rewrite rules may not necessarily 
have any  connection to a notion of equality.

www.cs.bris.ac.uk/~tweed/pi.htm |tweed's law:  however many computers
email: tweed@cs.bris.ac.uk      |   you have, half your time is spent
work tel: (0117) 954-5250       |   waiting for compilations to finish.