Composition Operator

Hi (.) :: (b -> c) -> (a -> b) -> (a -> c) While I understand the purpose and the semantics of the (.) operator I'm not sure about the above definition. Is the definition interpreted sequentially - (.) is a fun taht takes a fun of type (b -> c) and returns another fun of type (a -> b) etc? Any ideas? Thanks, Paul

Hello,
It's probably easiest to think of composition as a function which
takes two arguments (both functions), (g :: b -> c) and (f :: a -> b),
and returns a new function of type a -> c. We could write this
explicitly as
composition :: (b -> c, a -> b) -> a -> c
composition (g,f) = \x -> g (f x)
then (.) is the currying of composition:
(.) = curry composition
or
(.) g f = \x -> g (f x)
-Jeff
On 9/21/07, PR Stanley
Hi (.) :: (b -> c) -> (a -> b) -> (a -> c) While I understand the purpose and the semantics of the (.) operator I'm not sure about the above definition. Is the definition interpreted sequentially - (.) is a fun taht takes a fun of type (b -> c) and returns another fun of type (a -> b) etc? Any ideas? Thanks, Paul
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Apply parentheses from the right. So: (.) :: (b -> c) -> (a -> b) -> a -> c is the same as: (.) :: (b -> c) -> (a -> b) -> (a -> c) is the same as: (.) :: (b -> c) -> ((a -> b) -> (a -> c)) How you read that is up to you, but here is one way of reading it: "accepts a function a to c and returns a function. The function returned takes a function a to b and returns a function a to c" The expression f(g(x)) in C-style languages is similar to (f . g) x Tony Morris http://tmorris.net/ PR Stanley wrote:
Hi (.) :: (b -> c) -> (a -> b) -> (a -> c) While I understand the purpose and the semantics of the (.) operator I'm not sure about the above definition. Is the definition interpreted sequentially - (.) is a fun taht takes a fun of type (b -> c) and returns another fun of type (a -> b) etc? Any ideas? Thanks, Paul
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFG9JzXmnpgrYe6r60RAjDrAJ0SvkZHtNsctWNYHjqxjp9lnpNvgACfS/2r 9jwUvD29/ZMMot8x3/nvyI8= =xSzA -----END PGP SIGNATURE-----

Tony Morris wrote:
is the same as: (.) :: (b -> c) -> ((a -> b) -> (a -> c)) .. "accepts a function a to c and returns a function. The function returned takes a function a to b and returns a function a to c"
IMO, that should be "accepts a function b to c and returns a function. The function returned takes a function a to b and returns function a to c" Personally I also find the following a good explanation, since it does not introduce lambdas or other scary things for newbies. f . g = composite where composite x = f (g x) for example printLn = putStrLn . show so printLn x becomes putStrLn (show x) Cheers, Peter
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Apply parentheses from the right.
So: (.) :: (b -> c) -> (a -> b) -> a -> c
is the same as:
(.) :: (b -> c) -> (a -> b) -> (a -> c)
is the same as: (.) :: (b -> c) -> ((a -> b) -> (a -> c))
How you read that is up to you, but here is one way of reading it:
"accepts a function a to c and returns a function. The function returned takes a function a to b and returns a function a to c"
The expression f(g(x)) in C-style languages is similar to (f . g) x
Tony Morris http://tmorris.net/
PR Stanley wrote:
Hi (.) :: (b -> c) -> (a -> b) -> (a -> c) While I understand the purpose and the semantics of the (.) operator I'm not sure about the above definition. Is the definition interpreted sequentially - (.) is a fun taht takes a fun of type (b -> c) and returns another fun of type (a -> b) etc? Any ideas? Thanks, Paul
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFG9JzXmnpgrYe6r60RAjDrAJ0SvkZHtNsctWNYHjqxjp9lnpNvgACfS/2r 9jwUvD29/ZMMot8x3/nvyI8= =xSzA -----END PGP SIGNATURE----- _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Peter Verswyvelen:
Personally I also find the following a good explanation, since it does not introduce lambdas or other scary things for newbies.
f . g = composite where composite x = f (g x)
I suppose that the usual definition, which is (f . g) x = f (g x), is clear enough. No lambdas to be scared of here.

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Peter Verswyvelen wrote:
Tony Morris wrote:
is the same as: (.) :: (b -> c) -> ((a -> b) -> (a -> c)) .. "accepts a function a to c and returns a function. The function returned takes a function a to b and returns a function a to c"
IMO, that should be
"accepts a function b to c and returns a function. The function returned takes a function a to b and returns function a to c"
Oops! IMRevisedO too :) Tony Morris http://tmorris.net/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFG9Ym4mnpgrYe6r60RArGPAKCZHoJz2Sd6eSZs76xd+vqnCqJUBQCfeYzJ q1+WCoXqzRZVeIyeGPVhOC8= =12Iw -----END PGP SIGNATURE-----
participants (5)
-
jeff p
-
Malte Milatz
-
Peter Verswyvelen
-
PR Stanley
-
Tony Morris