Skip to content

How to prevent root of a module from being used as a type? #150

Answered by bioball
ric2b asked this question in Q&A
Discussion options

You must be logged in to vote

Hi; a module special because it is both an object, and a class. The module is intended to be usable as a type. I would structure your code this way:

abstract module Vehicle

import "Vehicle.pkl" // self-import

manufacturer: String

class Car extends Vehicle { // extends the module's class
  transmission: "automatic" | "manual"
}

class Boat extends Vehicle {
  has_sails: Boolean
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ric2b
Comment options

@bioball
Comment options

Answer selected by ric2b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants