[<<][erlang][>>][..]
Thu Sep 8 01:56:41 EDT 2016

composing folds, dual approach?

Is it possible to transform fold bodies in the same way as folds?
That way they could be opened up in a gen_server

Example: chunker: take a fold body that operates on complete chunks,
and transform it into one that operates on partial ones.

This would be a dual or something?


EDIT: you'll need:
- a transformation of the function
- an injection of wrapped state into new state
- a projection of new state (if a final version is desired)


State injection, projection could be standardized to just pair and
picking the first element.

Actually, this is what is done in DSPM.

EDIT: might be interesting to see how this can be factored out in
fold.erl


chunks(Fold, {foldl, Split, SplitInit}=_Splitter) ->
    fun(Fun, FunInit) ->
            {FunResult, _} =
                Fold(
                  fun(Chunk, {FunState, SplitState}) ->
                          SplitFold = Split(Chunk, SplitState),
                          SplitFold(Fun, FunState)
                  end,
                  {FunInit, SplitInit}),
            FunResult
    end.



The custom core here is:

fun(Fun) -> 
    fun(Chunk, {FunState, SplitState}) ->
        SplitFold = Split(Chunk, SplitState),
        SplitFold(Fun, FunState)
    end

All the rest is generic.


So this is not a siso, but a sis transformer.
Might be generic enough (remember DSPM has only applicative functors).


Anyways.  Might work as a guiding abstraction, but until there is a
clear need for splitting this in fold.erl that would save a lot of
code, it's probably best to keep it more concrete and easier to read.






[Reply][About]
[<<][erlang][>>][..]