Search code examples
algorithmhaskelllambdafunctional-programmingpointfree

Point Free with lists in Haskell


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]

Solution

  • 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