[<<][rtl][>>][..]
Wed May 15 09:41:17 EDT 2019

About folds

Why do I have trouble writing a fold for this?

data Form = LetPrim Cell [Cell]
          | LetLoop Index [Form]


Maybe because the constructors are not primitive?  While 'Program' is
just a wrapper around [], the [] introduces a substructure.  The
question is then, should the constructors of this substructure be
exposed?

Let's just try the dumb thing first.

EDIT: It's easier to understand when making things a little more
general and looking at Form as being parameterized by the [] type.
This then has a direct correspondence in foldForm being parameterized
by foldList.  The flattened foldr then has all the constructors
involved in the two mutually recursive types letPrim,letLoop,cons,nil
with the remark that there are now 2 types of "accumulators" for the
two mutually recursive types.

EDIT: The mutual recursion is now expressed properly in two separate
legs, and a combined fold that treats all levels the same.



[Reply][About]
[<<][rtl][>>][..]