1

So I saw the algorithm for point free conversion here Point Free problems in Haskell but what if the points i'd like to remove are hiding in a list? For instance a line like the following?

AllNsTill n x = [n,2*n..x]
Community
  • 1
  • 1
Tshimanga
  • 845
  • 6
  • 16
  • I'd like to point out that although lists already have enough functions defined that you can probably make any use of lists point-free, for a general data type there is no way to turn arbitrary pattern matching into point-free form, without first defining new functions for the purpose. – Ørjan Johansen Oct 26 '15 at 19:38

1 Answers1

8

That sequence syntax desugars to a call of the enumFromThenTo function:

allNsTill n x = [n,2*n..x]
-->
allNsTill n x = enumFromThenTo n (2*n) x

Now you can convert that to point-free syntax (if you really want). I'd argue though that it gets really unreadable:

allNsTill = (*2) >>= flip enumFromThenTo
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • Follow up: list-comprehensions can be rewritten in terms of `map` and `filter`. – Bakuriu Oct 26 '15 at 17:16
  • @Bakuriu, don't you mean `concatMap`? – dfeuer Oct 26 '15 at 18:19
  • @dfeuer: depends on what comprehension you use :-) Of course both `map` and `filter` can be implemented using `concatMap`. – Bergi Oct 26 '15 at 18:22
  • @Bergi Ah, I see. Okay. Yeah no I wouldn't want to change it to point free, but was very curious about how it'd be done. Much appreciated. Thanks! – Tshimanga Oct 26 '15 at 19:31
  • @Tshimanga: Maybe `allNsTill n = enumFromThenTo n (2*n)` is a reasonable compromise – Bergi Oct 26 '15 at 19:32
  • @Bergi Yeah that looks pretty good. I was hopeful that there might be a sugared version of the points free form because `lengthOf n = [1..n]` changes to `lengthOf = [1..id]`... oh well – Tshimanga Oct 26 '15 at 19:54