Skip to content
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

Offer a flipped version #116

Open
treeowl opened this issue Mar 23, 2018 · 3 comments
Open

Offer a flipped version #116

treeowl opened this issue Mar 23, 2018 · 3 comments

Comments

@treeowl
Copy link
Contributor

treeowl commented Mar 23, 2018

I've been playing around with Rec-like things for a while, and I've noticed that there are quite a few typeclass-worthy generalizations ... of flipped Rec. For example, rmap is really just imap for a McBride-style indexed functor. And rtraverse suggests the following class:

class IFunctor t => ITraversable (t :: (k -> Type) -> Type) where
  itraverse :: Applicative h
            => (forall x. f x -> h (g x))
            -> t f -> h (t g)

which happens to provide reasonably nice language for building arrays. I'm wondering if it might make sense to offer a module for a version of Rec with its type arguments flipped.

@acowley
Copy link
Contributor

acowley commented Mar 23, 2018

I spent a fair amount of time with a flipped version, and it does offer some niceties. What happened to my efforts then is that I found I was really recapitulating compdata, so I ran out of steam. I'd definitely be interested if you have some concrete uses in mind, but I had thought it wasn't worth adding them unless I also offered something useful. The arrays case is handled to some extent in Frames.InCore, but I'm willing to believe it would be done better with a flipped Rec.

@treeowl
Copy link
Contributor Author

treeowl commented Mar 23, 2018

vector offers

createT :: Traversable t => (forall s. ST s (t (MVector s a))) -> t (Vector a)

which only lets you make vectors of one type in a Traversable context. But a natural generalization comes from rank2classes:

createIT :: Rank2.Traversable t => (forall s. ST s (t (MVector s))) -> t Vector

This could be used with a flipped Rec, but not (directly) with a Rec.

I haven't looked at compdata yet; I'll check it out.

@treeowl
Copy link
Contributor Author

treeowl commented Mar 23, 2018

To clarify, rank2classes doesn't have that function. I made it up. But I think it's the right thing. I don't know if someone else made it up before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants