On Tue, 24 Aug 1999, Ronald J. Legere wrote:

>   It WOULD be nice if you could match on functions and not just
> constructors. But I presume that the constructor/function dichotomy
> in Haskell is what allows it to be strongly typed? For example, in the
> untyped 'language' Mathematica employs, pattern matching is 
> allowed on both constructors and functions, and in fact, there is
> no seperate idea of 'constructor', constructors are just functions that
> dont do anything (they dont match any left hand side pattern by
> themselves). 
> 
>  Can someone confirm/deny that strong typing requires this dichotomy?

Mathematica only allows pattern matching on `functions that are explicitly
present at a given stage of the evaluation process' and not on `values
which have expressions as functions applied to specific arguments' in
general. 

So I can match on f[x_,y_] (in rule f[x_,y_]:=x*y) on the expression
f[x,x] but you can't get a match for the f[x_,y_] in rule
g[f[x_,y_],z_]:=x+y+z on the value g[x*y,z], even though x*y `is' f[x,y].
Xander was trying to match a list as the list<*>last_item, i.e., something
of the later form. You can't match on that in Mathmatica (you have to rely
on the special double & triple underscore forms in for the list problem
particular case, and you can't do solve the problem for general function
applications). In haskell constructors are precisely those functions which
don't reduce further, and hence can be matched upon.

I suspect that there's no strong type system for Mathmatica because in the
presence of `symbols' that you only instantiate later (or not at all) the
type rules you'd need to account for that would make type safety a very
weak concept (`this program is type correct providing any undefined
symbols aren't suddenly bound to expressions with types which break the
program'). 

___cheers,_dave______________________________________________________
email: [EMAIL PROTECTED]       "He'd stay up all night inventing an
www.cs.bris.ac.uk/~tweed/pi.htm   alarm clock to ensure he woke early
work tel: (0117) 954-5253         the next morning"-- Terry Pratchett



Reply via email to