views:

264

answers:

6

I really wish that Google was better at searching for syntax:

decades         :: (RealFrac a) => a -> a -> [a] -> Array Int Int
decades a b     =  hist (0,9) . map decade
                   where decade x = floor ((x - a) * s)
                         s        = 10 / (b - a)
+3  A: 

It is a function composition: link

demas
+5  A: 

It means function composition. See this question.

Note also the f.g.h x is not equivalent to (f.g.h) x, because it is interpreted as f.g.(h x) which won't typecheck unless (h x) returns a function.

This is where the $ operator can come in handy: f.g.h $ x turns x from being a parameter to h to being a parameter to the whole expression. And so it becomes equivalent to f(g(h x)) and the pipe works again.

Alex Jenter
But, that is crazy!
Casebash
You just need to remember that the function application operator (space) has the highest priority. After some time it will all make sense.
Alex Jenter
+2  A: 

"The period is a function composition operator. In general terms, where f and g are functions, (f . g) x means the same as f (g x). In other words, the period is used to take the result from the function on the right, feed it as a parameter to the function on the left, and return a new function that represents this computation."

Source: Google search 'haskell period operator'

Alan
+2  A: 

Function composition (the page is pretty long, use search)

Drakosha
Look at this add-on: https://addons.mozilla.org/en-US/firefox/addon/416
Casebash
+7  A: 

. is a higher order function for function composition.

Prelude> :type (.)
(.) :: (b -> c) -> (a -> b) -> a -> c
Prelude> (*2) . (+1) $ 1
4
Prelude> ((*2) . (+1)) 1
4
retronym
+8  A: 

f(g(x))

is

in mathematics : f ∘ g (x)

in haskell : ( f . g ) (x)

TheMachineCharmer
FYI: I've change the `o` to the actual ring symbol used in Mathematics.
KennyTM
Thanks Kenny :) How did you do it?
TheMachineCharmer
@TheMachine, perhaps, he used a cheatsheet (check this: http://tlt.its.psu.edu/suggestions/international/bylanguage/mathchart.html)
Pavel Shved
@TheMachineCharmer: In Windows, open `charmap.exe` and search for "Ring". Similar for Mac but use Character Viewer. Should be similar for other OS too.
KennyTM
Ya g∘t it. Thanks! ;)
TheMachineCharmer
Sometimes I really wish Haskell had been invented just a couple of years later, *after* the invention of Unicode.
Jörg W Mittag
@TheMachineCharmer: On Macintosh, at the bottom of almost any Edit menu is "Special Characters..." which will bring up a wonderful Unicode character explorer.
MtnViewMark
@Jörg: It was neck and neck: Haskell 1.0 in 1990, Unicode 1.0 in 1991, Unicode 2.0 in 1996, Haskell 98 in 1998. Haskell 98 came late enough to pick up the beyond-16-bit definition of Unicode in 2.0, but apparently too late for them to change the libraries established back in 1990.Then there is the issue of that the full characters are harder to type, though I imagine Haskell IDEs, like Leksah, take care of that.Nonetheless, I think there are modules on Hackage that add nice Unicode synonyms for functions.
MtnViewMark
Several Haskell compilers already understands some Unicode synonyms (e.g. `∀` as `forall`, see http://hackage.haskell.org/trac/haskell-prime/wiki/UnicodeInHaskellSource), but I bet no one will use them practically because it's so much faster to type than dig out from charmap.
KennyTM