Scala Adt Enums logo

Scala Adt Enums

Organization
cxcscmu
scala-adt-enums

Translating Python Enums and Protocols to Scala sealed traits and algebraic data types

Overview

Publishercxcscmu
RepositorySkillLearnBench
Skill namescala-adt-enums
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 Adt Enums 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-adt-enums
  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-adt-enums .claude/skills/scala-adt-enums
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Scala Adt Enums 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 Adt Enums 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 Adt Enums 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 ADTs, Sealed Traits, and Enums for Python Developers

Enums

Python Enum

python
from enum import Enum

class TokenType(Enum):
    STRING = "string"
    NUMERIC = "numeric"
    TEMPORAL = "temporal"
    STRUCTURED = "structured"
    BINARY = "binary"
    NULL = "null"

# Usage
t = TokenType.STRING
t.value  # "string"
t.name   # "STRING"

Scala Enum (Scala 2.13 - using sealed trait + case objects)

scala
sealed trait TokenType {
  def value: String
}
object TokenType {
  case object STRING extends TokenType { val value = "string" }
  case object NUMERIC extends TokenType { val value = "numeric" }
  case object TEMPORAL extends TokenType { val value = "temporal" }
  case object STRUCTURED extends TokenType { val value = "structured" }
  case object BINARY extends TokenType { val value = "binary" }
  case object NULL extends TokenType { val value = "null" }

  // Helper for pattern matching
  def all: List[TokenType] = List(STRING, NUMERIC, TEMPORAL, STRUCTURED, BINARY, NULL)
}

// Usage
val t: TokenType = TokenType.STRING
t.value  // "string"

Algebraic Data Types (ADTs)

Python Union Types

python
from typing import Union

JsonValue = Union[str, int, float, bool, None, list["JsonValue"], dict[str, "JsonValue"]]

# Function handling multiple types
def process(value: Union[str, int]) -> str:
    if isinstance(value, str):
        return value
    else:
        return str(value)

Scala Sealed Traits (Idiomatic ADT)

scala
sealed trait JsonValue
case class JString(value: String) extends JsonValue
case class JNumber(value: Double) extends JsonValue
case class JBoolean(value: Boolean) extends JsonValue
case object JNull extends JsonValue
case class JArray(value: Vector[JsonValue]) extends JsonValue
case class JObject(value: Map[String, JsonValue]) extends JsonValue

// Pattern matching (exhaustive)
def process(json: JsonValue): String = json match {
  case JString(s) => s
  case JNumber(n) => n.toString
  case JBoolean(b) => b.toString
  case JNull => "null"
  case JArray(arr) => s"Array(${arr.size})"
  case JObject(obj) => s"Object(${obj.size})"
}

Protocols → Scala Traits

Python Protocol

python
from typing import Protocol, runtime_checkable

@runtime_checkable
class Tokenizable(Protocol):
    def to_token(self) -> str: ...

def process(obj: Tokenizable) -> str:
    return obj.to_token()

Scala Trait (Type Class Pattern)

scala
trait Tokenizable {
  def toToken: String
}

def process(obj: Tokenizable): String = obj.toToken

// Or as type class (more flexible, less invasive)
trait Tokenizable[T] {
  def toToken(value: T): String
}

object Tokenizable {
  implicit val stringTokenizable: Tokenizable[String] = new Tokenizable[String] {
    def toToken(value: String) = value
  }
}

def process[T](obj: T)(implicit ev: Tokenizable[T]): String = ev.toToken(obj)

Abstract Classes and Inheritance

Python ABC

python
from abc import ABC, abstractmethod
from typing import Generic, TypeVar

T = TypeVar("T")

class BaseTokenizer(ABC, Generic[T]):
    @abstractmethod
    def tokenize(self, value: T) -> Token:
        pass

    def tokenize_batch(self, values: Iterable[T]) -> Iterator[Token]:
        for v in values:
            yield self.tokenize(v)

class StringTokenizer(BaseTokenizer[str]):
    def tokenize(self, value: str) -> Token:
        return Token(value, TokenType.STRING)

Scala Abstract Class

scala
abstract class BaseTokenizer[T] {
  def tokenize(value: T): Token

  def tokenizeBatch(values: Iterable[T]): Iterator[Token] =
    values.toIterator.map(tokenize)
}

class StringTokenizer extends BaseTokenizer[String] {
  def tokenize(value: String): Token =
    Token(value, TokenType.STRING)
}

Dataclasses → Case Classes

Python Dataclass

python
from dataclasses import dataclass, field
from typing import Any

@dataclass(frozen=True)
class Token:
    value: str
    token_type: TokenType
    metadata: dict[str, Any] = field(default_factory=dict)

    def with_metadata(self, **kwargs: Any) -> "Token":
        new_meta = {**self.metadata, **kwargs}
        return Token(self.value, self.token_type, new_meta)

Scala Case Class

scala
case class Token(
  value: String,
  tokenType: TokenType,
  metadata: Map[String, Any] = Map()
) {
  def withMetadata(pairs: (String, Any)*): Token = {
    val newMeta = metadata ++ pairs.toMap
    copy(metadata = newMeta)
  }
}

Mutable Dataclasses → Regular Classes

Python Mutable Dataclass

python
@dataclass
class MutableTokenBatch:
    tokens: list[Token] = field(default_factory=list)
    _processed: bool = False

    def add(self, token: Token) -> None:
        if self._processed:
            raise RuntimeError("Batch already processed")
        self.tokens.append(token)

    def mark_processed(self) -> None:
        self._processed = True

Scala Class

scala
class MutableTokenBatch {
  private val tokens = scala.collection.mutable.ListBuffer[Token]()
  private var processed = false

  def add(token: Token): Unit = {
    if (processed) throw new RuntimeException("Batch already processed")
    tokens += token
  }

  def markProcessed(): Unit = {
    processed = true
  }

  def getTokens: List[Token] = tokens.toList
}

Pattern Matching for Type Narrowing

Scala pattern matching is more powerful than Python's isinstance checks:

scala
// Python equivalent:
if isinstance(value, str):
    return value
elif isinstance(value, int):
    return value.toString()

// Scala pattern matching:
value match {
  case s: String => s
  case i: Int => i.toString
  case _ => "unknown"
}

// Even better with case classes:
value match {
  case Token(v, TokenType.STRING, _) => v
  case Token(v, TokenType.NUMERIC, _) => s"[NUM]$v"
  case _ => "other"
}

Best Practices

  1. Use sealed traits for sum types - ensures exhaustive pattern matching
  2. Prefer case classes over regular classes - automatic equals, hashCode, toString, copy
  3. Use case objects for singleton ADT members
  4. Leverage pattern matching - more concise than isinstance chains
  5. Consider type classes for ad-hoc polymorphism - instead of duck typing
  6. Use Option[T] instead of None/null - more type-safe

Frequently asked questions

What does the Scala Adt Enums AI skill do?

Translating Python Enums and Protocols to Scala sealed traits and algebraic data types

Why use Scala Adt Enums on TypingMind?

Because you install it once and use it with any model. Scala Adt Enums 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 Adt Enums 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-adt-enums. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Scala Adt Enums?

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 Adt Enums?

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

Is the Scala Adt Enums 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 👇