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
25
votes
2 answers

is point free code more efficient, or just terser?

I wrote the following code, which takes a bunch of points and draws them on the screen using the gloss library. let s = blocks pes pts = map (map mkPt) s {- stitches to points-} lines = map Line pts {-points to lines -} pict =…
nont
  • 9,322
  • 7
  • 62
  • 82
22
votes
3 answers

Understanding `ap` in a point-free function in Haskell

I am able to understand the basics of point-free functions in Haskell: addOne x = 1 + x As we see x on both sides of the equation, we simplify it: addOne = (+ 1) Incredibly it turns out that functions where the same argument is used twice in…
Caridorc
  • 6,222
  • 2
  • 31
  • 46
21
votes
3 answers

Trick for "reusing" arguments in Haskell?

From time to time I stumble over the problem that I want to express "please use the last argument twice", e.g. in order to write pointfree style or to avoid a lambda. E.g. sqr x = x * x could be written as sqr = doubleArgs (*) where doubleArgs f…
Landei
  • 54,104
  • 13
  • 100
  • 195
21
votes
7 answers

Haskell map/zip Vs. list comprehension

Which of the following are you most likely to write? r = zip xs $ map sqrt xs or r = [(x, sqrt x) | x <- xs] Sample code on the Internet seems to indicate that the former is more abundant and the preferred way.
qrest
  • 3,083
  • 3
  • 25
  • 26
21
votes
2 answers

What is the derivation that shows Haskell's \x -> (x, x) equivalent to join (,)?

According to pointfree: \x -> (x, x) is equivalent to: join (,) What is the derivation that shows this?
user1002430
21
votes
3 answers

How to turn a Ruby method into a block?

Is there a way to simplify the following code? filenames is a list of filenames (strings), e.g. ["foo.txt", "bar.c", "baz.yaml"] filenames.map { |f| File.size(f) } Is there any way to turn "File.size" into a proc or block? For methods on existing…
Martin C. Martin
  • 3,565
  • 3
  • 29
  • 36
17
votes
3 answers

Writing in pointfree style f x = g x x

I am learning Haskell. I'm sorry for asking a very basic question but I cant seem to find the answer. I have a function f defined by : f x = g x x where g is an already defined function of 2 arguments. How do I write this pointfree style? Edit :…
user1188374
  • 829
  • 2
  • 7
  • 9
17
votes
1 answer

Help in understanding pointfree code

When playing around with Pointfree I was presented with a piece of code that I can't seem to understand. :pl map (\x -> x * x) [1..10] -- map (join (*)) [1..10] My main problem is that I don't get how join works here. I understand that it 'removes'…
Michael Kohl
  • 66,324
  • 14
  • 138
  • 158
17
votes
5 answers

Point-free in Haskell

I have this code that I want to make point-free; (\k t -> chr $ a + flip mod 26 (ord k + ord t -2*a)) How do I do that? Also are there some general rules for point free style other than "think about this amd come up with something"?
Igor
  • 2,673
  • 5
  • 33
  • 39
17
votes
1 answer

Performance Implications of Point-Free style

I’m taking my first baby-steps in learning functional programing using F# and I’ve just come across the Forward Pipe (|>) and Forward Composition (>>) operators. At first I thought they were just sugar rather than having an effect on the final…
Stoatly
  • 171
  • 4
16
votes
1 answer

Why does the pointfree version of my function use much more memory

I was working on a Project Euler problem and ended up with a Haskell file that included a function that looked like this: matches :: (a -> a -> Bool) -> a -> [(a, Int)] -> Int matches f cs = foldr (\(cs', n) a -> fromBool (f cs cs') * n + a) 0 With…
semicolon
  • 2,530
  • 27
  • 37
16
votes
2 answers

Is there a better way to express the absolute error function in point-free notation?

In pointful notation: absoluteError x y = abs (x-y) An unclear example in pointfree notation: absoluteError' = curry (abs . uncurry (-))
Ben Hamner
  • 4,575
  • 4
  • 30
  • 50
15
votes
2 answers

Point-free pattern matching possible in Haskell?

Given: data TwoInts = TwoInts Int Int add'em :: TwoInts -> Int add'em (TwoInts a b) = a+b is it possible to write add'em without having to name a and b. Something like: add'em TwoInts = (+) -- (Note: Fails to type check)
John F. Miller
  • 26,961
  • 10
  • 71
  • 121
15
votes
2 answers

Number of arguments and point-free in Haskell

With multiple pattern-matching, different numbers of arguments are impossible, even with point-free! foo True b = b + 2 foo _ = id doesn't work for example. But foo True = (+2) foo _ = id does. Sometimes we can use point-free only in one part of…
L01man
  • 1,521
  • 10
  • 27
14
votes
1 answer

Variadic compose function?

I'm trying to write a variadic function composition function. Which is basically the (.) except that the second argument function is variadic. This should allow expressions like: map even . zipWith (+) or just map even . zipWith Currently what…
is7s
  • 3,500
  • 1
  • 20
  • 41
1
2
3
19 20