Skip to content

Commit

Permalink
New style typeclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Jun 21, 2024
1 parent c4391c4 commit 709ff98
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/core/polyvinyl.Record.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@

package polyvinyl

trait Record[DataType](data: DataType, access: String => DataType => Any) extends Selectable:
trait Record extends Selectable:
type Format
val data: Format
def access: String => Format => Any
def selectDynamic(name: String): Any = access(name)(data)
3 changes: 2 additions & 1 deletion src/core/polyvinyl.RecordAccessor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package polyvinyl

import anticipation.*
import rudiments.*

trait RecordAccessor[RecordType <: Record[DataType], DataType, LabelType <: Label, TypeConstructorType[_]]:
trait RecordAccessor[RecordType <: Record in DataType, DataType, LabelType <: Label, TypeConstructorType[_]]:
def transform(data: DataType, make: DataType => RecordType): TypeConstructorType[RecordType]
8 changes: 4 additions & 4 deletions src/core/polyvinyl.Schema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import rudiments.*
import anticipation.*
import fulminate.*

trait Schema[DataType, RecordType <: Record[DataType]]:
trait Schema[DataType, RecordType <: Record in DataType]:
def fields: Map[String, RecordField]
def make(data: DataType, transform: String => DataType => Any): RecordType
def access(name: String, value: DataType): DataType
Expand Down Expand Up @@ -52,11 +52,11 @@ trait Schema[DataType, RecordType <: Record[DataType]]:
case (name, RecordField.Value(typeName, params*)) :: tail =>
(ConstantType(StringConstant(typeName)).asType: @unchecked) match
case '[type typeName <: Label; typeName] =>
(Expr.summon[ValueAccessor[RecordType, DataType, typeName, ?]]: @unchecked) match
(Expr.summon[Schematic[RecordType, DataType, typeName, ?]]: @unchecked) match
case None =>
abandon(msg"could not find a ValueAccessor instance for the field $name with type $typeName")
abandon(msg"could not find a Schematic instance for the field $name with type $typeName")

case Some('{$accessor: ValueAccessor[RecordType, DataType, typeName, valueType]}) =>
case Some('{$accessor: Schematic[RecordType, DataType, typeName, valueType]}) =>

val rhs: Expr[DataType => Any] =
'{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package polyvinyl

import anticipation.*
import rudiments.*

trait ValueAccessor[RecordType <: Record[DataType], DataType, LabelType <: Label, ValueType]:
trait Schematic[RecordType <: Record in DataType, DataType, LabelType <: Label, ValueType]:
def transform(data: DataType, params: List[String]): ValueType
2 changes: 1 addition & 1 deletion src/core/soundness+polyvinyl-core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

package soundness

export polyvinyl.{Record, RecordAccessor, RecordField, Schema, ValueAccessor}
export polyvinyl.{Record, RecordAccessor, RecordField, Schema, Schematic}

0 comments on commit 709ff98

Please sign in to comment.