Talk About Network



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 > pointfree notat...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 6 Topic 2804 of 2843
Post > Topic >>

pointfree notation

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

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!




 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 Sat May 17 12:50:42 CDT 2008.