purescript-contrib/purescript-argonaut-core

folds are actually case analysis

maxsnew opened this issue · 2 comments

Maybe this is a bit pedantic but the functions like foldJson are not really folds since they only inspect one layer of the structure, whereas folds deeply traverse a structure.
I was a bit confused in trying out this library by this naming.
I would expect foldJson to have the type

foldJson :: forall a.
            (JNull -> a) -> (JBoolean -> a) -> (JNumber -> a) ->
            (JString -> a) -> (Array a -> a) -> (StrMap a -> a) ->
            Json -> a

which of course you can implement using the current foldJson and recursion.

It's probably too much of a pain, but it seems to me like all the things currently called foldFoo should be caseFoo.

I was confused at first too. But here is the reason as far as I understand.

Fold is recursive call of algebra I.e. cata alg. Algebra is case analysis. List is recursive datatype -- fold is different with case analysis. (Especially when list isn't defined via Mu) Json isn't recursive datatype -- fold is exactly case analysis.

garyb commented

Will be resolved in the release for 0.12, thanks!