Thanks for the article(s), I am looking at pointfree notation, which I
had previously understood to be basically just eta-reduction, but now
wonder about that conclusion.
For example your example,
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 your functions are curried.
basically it seem 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?
length :: a-list -> int
filter :: a-list -> ( a -> bool) -> a-list
== :: int -> int -> bool (ignoring
polymorphism...)
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 your 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!


|