Git Product home page Git Product logo

Comments (7)

marcandre avatar marcandre commented on May 27, 2024

I think you can use an intersection. Since you're returning a class, I think singleton is what you want:

def self.enhance: () -> singleton(A & Ext)

from rbs.

HoneyryderChuck avatar HoneyryderChuck commented on May 27, 2024

That could work. But how can I make it work for "any subclass of A"?

from rbs.

marcandre avatar marcandre commented on May 27, 2024

Oh, right. Replace A with self:

def self.enhance: () -> singleton(self & Ext)

I didn't try it and I'm just starting to get acquainted with RBS. Maybe it's singleton(A) & singleton(Ext), or maybe both are the same, I don't know 🤷‍♂️

from rbs.

HoneyryderChuck avatar HoneyryderChuck commented on May 27, 2024

I'm getting errors on a bit of a different use-case, but similar syntax. So, for that example above:

module Ext
 def self.enhance(klass)
    Class.new(klass) do
      include Ext::InstanceMethods
    end
  end

  module InstanceMethods
    def bar;end
  end
end

Now, if I type it like this:

module Ext
  def self.enhance: (singleton(A)) -> singleton(A)
end

When running the runtime type checker on:

class A
  def foo; ; end
end

B = Ext.enhance(A) #=> this works
C = Ext.enhance(B) #=> this blows: RBS::Test::Tester::TypeError: TypeError: [.enhance] ArgumentTypeError: expected `singleton(::A)` but given `#<Class:0x000055970ae64258>`

I didn't try it and I'm just starting to get acquainted with RBS.

Likewise :)

from rbs.

marcandre avatar marcandre commented on May 27, 2024

It's taking your A literally. You need [A]. Maybe this would work:

module Ext
  def self.enhance: [A] (singleton(A)) -> singleton(A) & singleton(Ext::InstanceMethods)
end

from rbs.

soutaro avatar soutaro commented on May 27, 2024

Yeah, it's not supported at all.

Class.new(klass) do
  include Ext::InstanceMethods
end

The code requires a concept of type of a class object which includes a module... I don't think we can implement it now.

from rbs.

HoneyryderChuck avatar HoneyryderChuck commented on May 27, 2024

:( sad to hear, but it's understandable that one can't ship everthing in one go.

Do you have ideas on how this could look like in the future?

from rbs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.