Scala Generics logo

Scala Generics

Organization
cxcscmu
scala-generics

Translating Python generic types, variance, and type bounds to Scala 2.13

Overview

Publishercxcscmu
RepositorySkillLearnBench
Skill namescala-generics
Stars
91
Forks
7
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by cxcscmu on GitHub. Read the source before you install it.

Installation

Install the Scala Generics AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/cxcscmu/SkillLearnBench/tree/main/skills/b1-one-shot-claude-haiku-4-5/python-scala-translation/scala-generics
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/cxcscmu/SkillLearnBench.git /tmp/SkillLearnBench
mkdir -p .claude/skills
cp -r /tmp/SkillLearnBench/skills/b1-one-shot-claude-haiku-4-5/python-scala-translation/scala-generics .claude/skills/scala-generics
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Scala Generics in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Scala Generics on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Scala Generics is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Scala Generics and Type System for Python Developers

Core Concepts

Variance (Key Difference from Python)

Python has no explicit variance system. Scala requires explicit declarations:

Covariance (+T) - "out" position, can return subtypes:

scala
class Container[+T](items: Seq[T]) {
  def get: T = items.head  // OK - returning subtype
  // def set(t: T): Unit   // ERROR - would be contravariant
}

Contravariance (-T) - "in" position, can accept supertypes:

scala
class Consumer[-T] {
  def consume(t: T): Unit  // OK - accepting supertype
  // def produce: T         // ERROR - would be covariant
}

Invariance (T) - exact type, no variance:

scala
class Handler[T] {
  def get: T
  def set(t: T): Unit  // Both OK - invariant
}

Translation Pattern

PythonScalaNotes
TypeVar("T")[T]Invariant by default
TypeVar("T_co", covariant=True)[+T]Covariant, out-position only
TypeVar("T_contra", contravariant=True)[-T]Contravariant, in-position only
TypeVar("T", int, float)[T <: Int | Float]Upper bound (Scala 3) or sealed trait
Generic[T][T]Class definition
Union[A, B]A | B (Scala 3) or sealed traitUse sealed traits for compatibility

Type Bounds

scala
// Upper bound - T must be subtype of Ordered
class Comparable[T <: Ordered[T]]

// Lower bound - T must be supertype of String
class Container[T >: String]

// Context bound (implicit evidence)
class Serializable[T: Format]

Higher-Kinded Types (Scala's advantage)

Python's TypeVar("F") for type constructors cannot express true HKTs. Scala can use type lambdas:

scala
// Scala 2.13 with kind-projector
type Functor[F[_]] = {
  def map[A, B](fa: F[A], f: A => B): F[B]
}

// Or in Scala 3
def map[F[_], A, B](fa: F[A], f: A => B): F[B]

Translation Examples

Generic Container (Python)

python
class TokenContainer(Generic[T_co]):
    def __init__(self, items: Sequence[T_co]) -> None:
        self._items: tuple[T_co, ...] = tuple(items)

    def get_all(self) -> tuple[T_co, ...]:
        return self._items

Generic Container (Scala 2.13)

scala
class TokenContainer[+T](items: Seq[T]) {
  private val _items: Vector[T] = items.toVector

  def getAll: Vector[T] = _items
  def size: Int = _items.size
}

Collections Generics

Python uses Sequence[T], Iterable[T], etc. Scala equivalents:

PythonScala
Sequence[T]Seq[T] (immutable)
Iterable[T]Iterable[T]
Iterator[T]Iterator[T]
list[T]scala.collection.mutable.ListBuffer[T] or List[T] (immutable)
tuple[T, ...]Vector[T] or (T, T, ...) for fixed size
dict[K, V]Map[K, V]

Best Practices for Scala 2.13

  1. Prefer immutable by default - use Vector, List, Map
  2. Generics in method position - use [T] not just at class level
  3. Variance where appropriate - adds flexibility but keep simple
  4. Use sealed traits for union types - more powerful than Python's Union
  5. Type classes for ad-hoc polymorphism - replaces duck typing

Working with Circe JSON Types

Circe provides Json type which is immutable and generic:

scala
import io.circe._

// Json is essentially: Json = JNull | JBoolean | JNumber | JString | JArray | JObject
val json: Json = Json.fromString("hello")
val jsonObj: Json = Json.obj("key" -> Json.fromString("value"))

Frequently asked questions

What does the Scala Generics AI skill do?

Translating Python generic types, variance, and type bounds to Scala 2.13

Why use Scala Generics on TypingMind?

Because you install it once and use it with any model. Scala Generics is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Scala Generics in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/cxcscmu/SkillLearnBench/tree/main/skills/b1-one-shot-claude-haiku-4-5/python-scala-translation/scala-generics. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Scala Generics?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Scala Generics?

As many as you like. As long as a model supports skills, you can use Scala Generics with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Scala Generics AI skill free?

Yes. It is published on GitHub by cxcscmu under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇