Sorry that the first post was mangled, from a wrong cut/paste in
editing. Here is the intended posting. (Can't seem to delete original
one from Google groups...)
-----------------------------------------------------------------------------------------------------------------
I am looking at pointfree notation, which I had previously understood
to be basically just eta-reduction, but now wonder about that
conclusion.
For one example I saw, (in Haskell)
numOccurrences x = length . filter (== x)
seems fine, but
numOccurrences = (length .) . filter . (==)
worries me.
Seems to me that it wouldn't typecheck. I don't use Haskell (rather
SML), but also assume that all of the functions are curried. Basically
it seems (to me) that the intention is that == should consume only one
argument, and leave its result and the other for filter; i.e. the list
argument is not consumed by the first function in the pipeline (==),
but left for the 2nd (filter)
How would a compiler (interpreter) know about that argument
parcelling, v.s. a strict linear pipeline of arguments?
to restate; if one writes:
h = g . f
How would the compiler know if this is intended to define:
h(x,y) = g( f(x), y) # as above
or
h(x,y) = g( f(x,y) ) # as in SML
Is the dot notation the same as conventional functional composition
operator "o" (that is what I was assuming...), your other definitions
seem to imply this.
Trying the example in SML:
- val xx = length o (filter op=);
stdIn:1.1-40.27 Warning: type vars not generalized because of value
restriction are instantiated to dummy types (X1,X2,...)
val xx = fn : (?.X1 * ?.X1) list -> int
But...
- val xx = length o filter o op=;
stdIn:40.1-40.31 Error: operator and operand don't agree [tycon
mismatch]
operator domain: ('Z list -> int) * (('Y -> bool) -> 'Z list)
operand: ('Z list -> int) * (('Y -> bool) -> 'Y list -> 'Y
list)
in expression:
length o filter
stdIn:40.1-40.31 Warning: type vars not generalized because of value
restriction are instantiated to dummy types (X1,X2,...)
Thanks for any comments or references!


|