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

How does the expression `ap zip tail` work

I wondered how to write f x = zip x (tail x) in point free. So I used the pointfree program and the result was f = ap zip tail. ap being a function from Control.Monad I do not understand how the point free definition works. I hope I can figure it…
user7610
  • 25,267
  • 15
  • 124
  • 150
11
votes
2 answers

Implement a function to count frequency of each element in a list

I try to write a program which will count the frequency of each element in a list. In: "aabbcabb" Out: [("a",3),("b",4),("c",1)] You can view my code in the following link: http://codepad.org/nyIECIT2 In this code the output of unique…
sabu
  • 297
  • 1
  • 7
  • 23
10
votes
1 answer

Confusion about currying and point free style in Haskell

I was trying to implement the function every :: (a -> IO Bool) -> [a] -> IO Bool which was the topic for this question. I tried to do this without explicit recursion. I came up with the following code every f xs = liftM (all id) $ sequence $ map f…
Jonas
  • 19,422
  • 10
  • 54
  • 67
10
votes
3 answers

Number of elements in Haskell in pointfree style

I want to define a function that computes the number of elements in a list that satisfy a given predicate: number_of_elements :: (a -> Bool) -> [a] -> Int number_of_elements f xs = length (filter f xs) For example: number_of_elements (==2)…
Łukasz Śliwa
  • 600
  • 4
  • 16
10
votes
5 answers

Point-free style and using $

How does one combine using $ and point-free style? A clear example is the following utility function: times :: Int -> [a] -> [a] times n xs = concat $ replicate n xs Just writing concat $ replicate produces an error, similarly you can't write…
Fredrik
  • 4,161
  • 9
  • 28
  • 31
10
votes
3 answers

Where did bind come from?

Using lambdabot's pl plug-in, let iterate f x = x : iterate f (f x) in iterate is converted to fix ((ap (:) .) . ((.) =<<)) What does the (=<<) mean here? I thought that it is only used with monads.
ThePiercingPrince
  • 1,873
  • 13
  • 21
10
votes
3 answers

f1 = flip const map. How does this function work?

Let's say we have this point-free function: f1 = flip const map I'm clueless about how exactly does it work and what it is supposed to do? I.e. I know what map, const and flip functions are. But putting them together like this just doesn't make…
Peter Bosák
  • 317
  • 2
  • 11
10
votes
4 answers

Concise syntax for partial in Clojure

Learning Haskell some time ago, I felt in love with pointfree notation and especially convenient partial function application - just supply args you know. In Clojure, I have partial all the time. I think having a special syntax for partial in reader…
demi
  • 5,384
  • 6
  • 37
  • 57
10
votes
1 answer

Converting expression to pointfree style (Haskell)

I wrote this code and I have to rewrite it to the pointfree style: num_of_occ ele list = length(filter(==ele)list) So I did this: num_of_occ ele = length . filter((==)ele) It works. Than I did this: num_of_occ = length . filter . (==) And it…
ciembor
  • 7,189
  • 13
  • 59
  • 100
10
votes
3 answers

Can any function be reduced to a point-free form?

Many functions can be reduced to point free form - but is this true for all of them? E.g. I don't see how it could be done for: apply2 f x = f x x
Cubic
  • 14,902
  • 5
  • 47
  • 92
9
votes
6 answers

Pointfree function combination in Python

I have some predicates, e.g.: is_divisible_by_13 = lambda i: i % 13 == 0 is_palindrome = lambda x: str(x) == str(x)[::-1] and want to logically combine them as in: filter(lambda x: is_divisible_by_13(x) and is_palindrome(x), range(1000,10000)) The…
Frank S. Thomas
  • 4,725
  • 2
  • 28
  • 47
9
votes
2 answers

Haskell - How does this average function work?

I found this implementation of the average function: avg :: [Int] -> Int avg = div . sum <*> length How does this work? I looked at the function that was produced as a result of div . sum: (div . sum) :: (Integral a, Foldable t) => t a -> a -> a I…
xilpex
  • 3,097
  • 2
  • 14
  • 45
9
votes
2 answers

Why is the point-free style called point free in Haskell when it is full with points? Where does the term "point-free" originates from?

I am currently reading Learn You a Haskell for Great Good and I came across the notion "point-free style" on page 85 as shown below. However, the fn function is full with points! This confuses me. Why is this style of writing functions called…
jhegedus
  • 20,244
  • 16
  • 99
  • 167
9
votes
1 answer

A common pattern involving composition of functions (\a b -> f (g a) (g b))

The composition of f and g that looks like f :. g = \a b -> f (g a) (g b) is a pattern I find very often in my code. It is similar to unary function composition, only f is binary and I want g applied to both arguments before they are passed to…
kqr
  • 14,791
  • 3
  • 41
  • 72
9
votes
3 answers

Currying 3 Arguments in Haskell

I'm having trouble with currying a function to remove three arguments in Haskell. Disclaimer: Not Coursework, I was asked this question by someone struggling with this today and it's been bugging me. The custom types/functions we were given were…
Pete Hamilton
  • 7,730
  • 6
  • 33
  • 58