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

When to use pointless style?

Many haskell programmers, including me, like pointless style, especially when writing complicated parsers. They make code more readable and less verbose. But sometimes, it's just the other way round (for instance while abusing the instances of Monad…
fuz
  • 88,405
  • 25
  • 200
  • 352
14
votes
6 answers

make function with 'if' point-free

I have a task in Haskell (no, it's not my homework, I'm learning for exam). The task is: Write point-free function numocc which counts occurrences of element in given lists. For example: numocc 1 [[1, 2], [2, 3, 2, 1, 1], [3]] = [1, 2, 0] This is…
user4638556
14
votes
2 answers

Why does the pointfree version of this function look like this?

I've been playing around with Haskell a fair bit, including practising writing functions in point-free form. Here is an example function: dotProduct :: (Num a) => [a] -> [a] -> a dotProduct xs ys = sum (zipWith (*) xs ys) I would like to write this…
guhou
  • 1,732
  • 12
  • 32
14
votes
1 answer

Style vs Performance Using Vectors

Here's the code: {-# LANGUAGE FlexibleContexts #-} import Data.Int import qualified Data.Vector.Unboxed as U import qualified Data.Vector.Generic as V {-# NOINLINE f #-} -- Note the 'NO' --f :: (Num r, V.Vector v r) => v r -> v r -> v r --f ::…
crockeea
  • 21,651
  • 10
  • 48
  • 101
13
votes
4 answers

simple Haskell functions in point-free style

I am trying to understand how to convert functions to point-free notation in Haskell. I saw this example, but it is more complicated than what I am looking for. I feel like I understand the logic behind it, but when I am trying to execute some…
KJ50
  • 765
  • 1
  • 10
  • 27
13
votes
3 answers

Can this function be written in point-free style? If not, why?

One related question is this, but some of the answer say that almost anything can be made point free, so what is wrong with this function? \[x] -> x http://pointfree.io/ doesn't seem to be able to write it in point-free style. Does this mean that…
Enlico
  • 23,259
  • 6
  • 48
  • 102
13
votes
3 answers

Point Free problems in Haskell

I am trying to convert the following Haskell code to point free style, to no avail. bar f g xs = filter f (map g xs ) I'm new to Haskell and any help would be great.
Lee
  • 139
  • 8
13
votes
3 answers

Functional composition with multi-valued functions in haskell?

I was wondering if it was possible to do functional composition with functions that take more than one argument. I want to be able to do something like this x = (+3).(*) setting x equal to a function that adds three to the product of two numbers.
MYV
  • 4,294
  • 6
  • 28
  • 24
13
votes
2 answers

Tacit function composition in Haskell

Say I have a mean function defined like so: mean xs = sum xs / (fromIntegral $ length xs) but I want it in some tacit form, like this: mean = sum / (fromIntegral . length) Is there a built-in Haskell way to do something along these lines without…
Benjamin Kovach
  • 3,190
  • 1
  • 24
  • 38
12
votes
2 answers

How do I implement using point-free recursion to remove null values in objects using Ramda?

I am learning about pointfree functions and am trying to implement this recursive null remover in that style. Works, but is not pointfree: function removeNulls(obj) { return R.ifElse( R.either(R.is(Array), R.is(Object)), R.pipe( …
11
votes
2 answers

Combining fragments of Haskell Code to get the bigger picture

This is the code that I came upon somewhere but want to know how this works: findIndices :: (a -> Bool) -> [a] -> [Int] findIndices _ [] = [] findIndices pred xs = map fst (filter (pred . snd) (zip [0..] xs)) Output: findIndices (== 0)…
11
votes
3 answers

Explain (.)(.) to me

Diving into Haskell, and while I am enjoying the language I'm finding the pointfree style completely illegible. I've come a across this function which only consists of these ASCII boobies as seen below. f = (.)(.) And while I understand its type…
Erik
  • 293
  • 1
  • 8
11
votes
5 answers

Point-free style capitalize function with Ramda

While writing a capitalize function is trivial, such that: "hello" => "Hello" "hi there" => "Hi there" How would one write it using point-free style using Ramda JS? https://en.wikipedia.org/wiki/Tacit_programming
Tutan Ramen
  • 1,234
  • 1
  • 8
  • 27
11
votes
2 answers

Making numeric functions an instance of Num?

I want to be able to compose numeric functions in haskell using binary operators. So, for example, with unary numeric functions: f*g should translate to: \x -> (f x)*(g x) and similarly for addition. Making your own operator to do this is pretty…
Nathan BeDell
  • 2,263
  • 1
  • 14
  • 25
11
votes
1 answer

Is it possible to make pointfree functions more readable using different combinators than (.)?

What are potential alternative representations (e.g. using arrows, lenses, Haskell idioms, do syntax) of pointfree expressions that could read more like plain English? Here is trivial example: qNameIs :: String -> QName -> Bool qNameIs = (. qName)…
Rumca
  • 1,809
  • 12
  • 17
1 2
3
19 20