Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Functional > Re: pointfree n...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 6 Topic 2804 of 2887
Post > Topic >>

Re: pointfree notation

by guthrie <guthrie@[EMAIL PROTECTED] > Mar 31, 2008 at 10:27 AM

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!
 




 6 Posts in Topic:
pointfree notation
guthrie <guthrie@[EMAI  2008-03-31 09:59:19 
Re: pointfree notation
guthrie <guthrie@[EMAI  2008-03-31 10:27:18 
Re: pointfree notation
Paul Rubin <http://phr  2008-03-31 10:45:01 
Re: pointfree notation
Chris Smith <cdsmith@[  2008-03-31 17:57:22 
Re: pointfree notation
KE <koray.erkan@[EMAIL  2008-04-02 04:19:28 
Re: pointfree notation
Chris Smith <cdsmith@[  2008-04-02 13:53:08 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 9 6:01:43 CDT 2008.