Carp icon indicating copy to clipboard operation
Carp copied to clipboard

Evaluation using `Traversable`

Open jacereda opened this issue 5 years ago • 8 comments

I thought I might raise this issue to discuss the possibility of evaluating via Traversable.

One of the stumbling blocks I found is the Sets we have in the AST. Normal Data.Set isn't Traversable because it has Ord restrictions.

I found https://github.com/giorgidze/set-monad but it doesn't have Traversable. I have PR'd https://github.com/giorgidze/set-monad/pull/10

Maybe there're other alternatives. I guess we could implement a simplified Set without Ord restriction. Since our sets will be quite small I guess something like that could be implemented on top of List without being too inefficient.

jacereda avatar Dec 20 '20 17:12 jacereda

Of course we could implement manually traverse on our AST, but I thought an automatic instance based on Generic would be more desirable.

jacereda avatar Dec 20 '20 17:12 jacereda

This sounds interesting indeed! What would be a good module to first try out this approach?

eriksvedang avatar Dec 20 '20 17:12 eriksvedang

You mean if it should be Eval or Expand? I guess the second is simpler...

jacereda avatar Dec 20 '20 17:12 jacereda

Oh, instead of Generic we could also use https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#extension-DeriveTraversable

jacereda avatar Dec 20 '20 17:12 jacereda

Oh, maybe those are the only ones... :)

guess the second is simpler

Yes it must be

eriksvedang avatar Dec 20 '20 18:12 eriksvedang

I guess Scoring is a fold. Not sure about Emit, could it also be a fold?

And looking at more modules, looks like most of them could benefit from Foldable and/or Traversable.

jacereda avatar Dec 20 '20 18:12 jacereda

I guess Scoring is a fold. Not sure about Emit, could it also be a fold?

And looking at more modules, looks like most of them could benefit from Foldable and/or Traversable.

Yes, pretty much everything, I think, can be expressed in terms of a fold over the AST

scolsen avatar Dec 20 '20 18:12 scolsen

Some of the recursive functions branch in weird ways though - concretize & manageMemory comes to mind. Perhaps it's still possible to just fold, but I'm not sure.

eriksvedang avatar Dec 20 '20 18:12 eriksvedang