Questions tagged [pointfree]

The pointfree (also called pointless) style of defining a function is to express it directly in terms of existing functions, without mentioning the arguments of the function being defined. Function composition and partial application are often used.

The pointfree (also called pointless) style of defining a function is to express it directly in terms of existing functions (regarded as combinators), without mentioning the arguments of the function being defined. Function composition and partial application are often used.

See also .

292 questions
133
votes
7 answers

What is "point free" style (in Functional Programming)?

A phrase that I've noticed recently is the concept of "point free" style... First, there was this question, and also this one. Then, I discovered here they mention "Another topic that may be worth discussing is the authors' dislike of point free…
Paul Hollingsworth
  • 13,124
  • 12
  • 51
  • 68
123
votes
4 answers

How is this fibonacci-function memoized?

By what mechanism is this fibonacci-function memoized? fib = (map fib' [0..] !!) where fib' 1 = 1 fib' 2 = 1 …
bjornars
  • 1,506
  • 2
  • 10
  • 13
73
votes
4 answers

What are advantages and disadvantages of "point free" style in functional programming?

I know that in some languages (Haskell?) the striving is to achieve point-free style, or to never explicitly refer to function arguments by name. This is a very difficult concept for me to master, but it might help me to understand what the…
Eli Schneider
  • 4,903
  • 3
  • 28
  • 50
60
votes
6 answers

Haskell function composition operator of type (c→d) → (a→b→c) → (a→b→d)

Ordinary function composition is of the type (.) :: (b -> c) -> (a -> b) -> a -> c I figure this should generalize to types like: (.) :: (c -> d) -> (a -> b -> c) -> a -> b -> d A concrete example: calculating difference-squared. We could write…
jameshfisher
  • 34,029
  • 31
  • 121
  • 167
52
votes
2 answers

What does (f .) . g mean in Haskell?

I have seen a lot of functions being defined according to the pattern (f .) . g. For example: countWhere = (length .) . filter duplicate = (concat .) . replicate concatMap = (concat .) . map What does this mean?
45
votes
7 answers

In Haskell performing `and` and `or` for boolean functions

I just wrote the following two functions: fand :: (a -> Bool) -> (a -> Bool) -> a -> Bool fand f1 f2 x = (f1 x) && (f2 x) f_or :: (a -> Bool) -> (a -> Bool) -> a -> Bool f_or f1 f2 x = (f1 x) || (f2 x) They might be used to combined the values of…
John F. Miller
  • 26,961
  • 10
  • 71
  • 121
40
votes
2 answers

How to use (->) instances of Monad and confusion about (->)

At different questions I've found hints in comments concerning using the (->) instance of Monads e.g. for realizing point-free style. As for me, this is a little too abstract. Ok, I've seen Arrow instances on (->) and it seems to me, that (->) can…
makelc
  • 867
  • 8
  • 10
36
votes
5 answers

How can I understand "(.) . (.)"?

I believe I understand fmap . fmap for Functors, but on functions it's hurting my head for months now. I've seen that you can just apply the definition of (.) to (.) . (.), but I've forgot how to do that. When I try it myself it always turns out…
SomeName
  • 505
  • 5
  • 9
34
votes
0 answers

Current State of JavaScript Functional Programming Libraries

The Libraries Low Dash Underscore inspired, fixes lots of stuff apparently, great API Apparently it was so inspired by underscore that its also doing it wrong! fn.js Currently under 1.0 but great documentation, basic functions Bilby.js Created by…
30
votes
4 answers

Applying multiple functions to the same value point-free style in Haskell

I was bored one day and wanted to exercise my brain, so I decided to do the 99 Haskell Problems but restricted myself to doing them in point-free style. A problem that seems to crop up a lot when I'm doing things in point-free style is this: How do…
Dwilson
  • 1,239
  • 9
  • 18
29
votes
7 answers

Composing function composition: How does (.).(.) work?

(.) takes two functions that take one value and return a value: (.) :: (b -> c) -> (a -> b) -> a -> c Since (.) takes two arguments, I feel like (.).(.) should be invalid, but it's perfectly fine: (.).(.) :: (b -> c) -> (a -> a1 -> b) -> a -> a1 ->…
Vlad the Impala
  • 15,572
  • 16
  • 81
  • 124
28
votes
5 answers

Flipped / reversed fmap (<$>)?

I found defining the following (%) = flip fmap I can write code like this: readFile "/etc/passwd" % lines % filter (not . null) To me it makes more sense than the alternative: filter (not . null) <$> lines <$> readFile "/etc/passwd" Obviously,…
James
  • 622
  • 6
  • 6
27
votes
3 answers

What is the equivalent to (+1) for the subtraction, since (-1) is seen as a negative number?

Possible Duplicate: Currying subtraction I started my first haskell project that is not from a tutorial, and of course I stumble on the simplest things. I have the following code: moveUp y = modifyMVar_ y $ return . (+1) moveDn y = modifyMVar_ y…
Niriel
  • 2,605
  • 3
  • 29
  • 36
26
votes
4 answers

How do I re-write a Haskell function of two argument to point-free style

I have the following function in Haskell agreeLen :: (Eq a) => [a] -> [a] -> Int agreeLen x y = length $ takeWhile (\(a,b) -> a == b) (zip x y) I'm trying to learn how to write 'idiomatic' Haskell, which seem to prefer using . and $ instead of…
JonathanZ
  • 1,046
  • 11
  • 20
25
votes
4 answers

The case for point free style in Scala

This may seem really obvious to the FP cognoscenti here, but what is point free style in Scala good for? What would really sell me on the topic is an illustration that shows how point free style is significantly better in some dimension (e.g.…
enhanced_null
  • 407
  • 1
  • 6
  • 9
1
2 3
19 20