@hyphenrf posted a new topic, subject "Using CPS for semi-automatic fusion". It read:

   Usually when I find myself writing a pipeline like this:
    [code] 
        data
        |> fun that produces intermediate data
        |> same
        |> ...
        
    [/code]
    
    where the data isn't lazy, I resort to either converting it to a lazy form (via an external library like iter if it's already pulled), specifically designed to let the compiler fuse it, or rewrite the pipeline, manually “fusing” it, to just one big recursive function.
    
    One day early on my learning journey I'd come across a blog post that suggested a third option: CPS. The changes to the functions were minimal, if they were changed at all (my current understanding of CPS suggests they need to be changed to pass the thunks across computations, but maybe the blogger did something smarter). The transformation was more-or-less purely mechanical. It was used to compose the functions replacing the reverse-apply operator (as opposed to creating a common data structure).  
    At the time this transformation was way over my head, and I made the terrible mistake of not bothering to bookmark the blog post. Now, though, I feel like I understand CPS better – at least the basics, so I set on to hunting for that post and learning what it has to offer. The code examples were written in OCaml too!  
    So far, unfortunately, no dice. Have you good folk come across it?

@LdBeth (Qifan Wang) replied

    I'm not sure if this is the exact blog post you ask for (probably not), but I guess it is close enough because it uses delimited continuation (coroutines) for generators (lazy streams that can fusion), and it has an OCaml implementation (however, it seems this implementation only uses OCaml's exception mechanism).
    
    http://okmij.org/ftp/continuations/generators.html
    
    There might be other posts about similar subjects at Oleg Kiselyov's website.

After which, @hyphenrf added

    It's not the one, but an interesting read nonetheless!

After which, @Armael added

    Gagallium : Generators, iterators, control and continuations ?

To which @hyphenrf replied

    That's not the one either… It's where I first learned about defunctionalization though!


{'source': 'discourse', 'url': 'https://discuss.ocaml.org/t/using-cps-for-semi-automatic-fusion/7381', 'title': 'Using CPS for semi-automatic fusion', 'views': 461, 'has_accepted_answer': False, 'word_count': 332, 'like_count': 2, 'reply_count': 2, 'participant_count': 3, 'posts': 5, 'tags': '', 'author': '@hyphenrf', 'participants': '@hyphenrf, @LdBeth (Qifan Wang), @Armael', 'image_url': [None], 'created_at': '2021-03-01T05:33:45.647Z', 'last_posted_at': '2021-03-01T09:52:05.492Z'}