-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AST with unbound + recussion schemes for transformations #43
Comments
RepLib/Unbound does not have the facility to do this now. The only way to define new datatypes based on existing ones (i.e. the shape functor) is using TemplateHaskell. RepLib already uses TH to construct representation types; it would be possible to extend this to also construct shape functors too. However, you might be able to replace your uses of cata with datatype-generic functions. For example, Unbound defines a generic version of the free variable function. |
Is it possible to create the shape functor manually for a recursive data type that uses unbound? Or would it break unbound semantics? data Term a = Var (Name a)
| App a a
| Lam (Bind (Name a) a) instead of data Term = Var (Name Term)
| App Term Term
| Lam (Bind (Name Term) Term) |
So, this doesn't work directly. It's fine to define the shape functor
But the problem is that
Instead, we need to work we new recursion schemes that include the monadic traversal of the term. So imagine that we had these definitions
Then your closure conversion function can be defined using
|
fmapM :: (Alpha a, Alpha b, LFresh m) => (a -> m b) -> TermF a -> m (TermF b) is pretty similar to class (Functor t, Foldable t) => Traversable t where
mapM :: Monad m => (a -> m b) -> t a -> m (t b) Is |
TermF is neither a Functor nor Traversable. The version of fmapM that I used
is less general than mapM due to the constrained polymorphism.
… On Aug 16, 2017, at 6:56 PM, Csaba Hruska ***@***.***> wrote:
fmapM :: (Alpha a, Alpha b, LFresh m) => (a -> m b) -> TermF a -> m (TermF b)
is pretty similar to mapM
class (Functor t, Foldable t) => Traversable t where
mapM :: Monad m => (a -> m b) -> t a -> m (t b)
Is TermF a Traversable (but not a Functor)?
If so why should Traversable t must be Functor t also if TermF works just fine?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#43 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ACAZdhbgvb9l92tQ9q_ywmRRjtPKibDFks5sY3OEgaJpZM4OuZwW>.
|
Does unbound semantics allow to create the shape functor for the AST?
It would help a lot to implement the AST transformations using recursion schemes.
I.e. in this short closure conversion tutorial
It would be useful example to have the same thing but with unbound.
The text was updated successfully, but these errors were encountered: