Skip to content

Trait/Type Class Bridge #2

Description

@markovejnovic

It would be kind of neat to be able to bridge traits and type classes. My needs are currently met without that, but I could imagine that trait objects can be safely passed between Rust and haskell. Unfortunately, generics, as-is, cannot be, since it's impossible to prove which possible instantiations they have.

But an example might be:

trait Foo {
  fn foo(&self);
}

struct Bar {
  pub fn bar(&self, foo: &dyn Foo);
}

and have that emit something like

class Foo a where
  foo :: a -> IO ()

data SomeFoo = forall a. Foo a => SomeFoo a
data Bar

bar :: Bar -> SomeFoo -> IO ()

I'm still a little befuddled as to whether this is the right approach or not.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions