KacperFKorban / GUInep

Automatic UI forms for Scala 3 functions
https://kacperfkorban.github.io/GUInep/
Apache License 2.0
14 stars 0 forks source link

Support undecidable generics #30

Open KacperFKorban opened 5 months ago

KacperFKorban commented 5 months ago

It should be possible to use undecidable generics types in function definitions.

e.g.

sealed trait WeirdGADT[+A]
case class IntValue(value: Int) extends WeirdGADT[Int]
case class SomeValue[+A](value: A) extends WeirdGADT[A]
case class SomeOtherValue[+A, +B](value: A, value2: B) extends WeirdGADT[A]

// This fails on unknown type params
def printsWeirdGADT(g: WeirdGADT[String]): String = g match
  case SomeValue(value) => s"SomeValue($value)"
  case SomeOtherValue(value, value2) => s"SomeOtherValue($value, $value2)"

This fails, because SomeOtherValue cannot be fully constructed based on parent's type params.

Either some default will have to be used or a new type of form element introduced - one that lets the user pick any supported type.

It should also be possible to use generic functions with GUInep.

e.g.

def showMaybe[A](maybe: Option[A]): String = maybe match
  case None => "None"
  case Some(v) => s"Some(${v.toString})"

This might require similar mechanisms. Plus the support for this kind of input.

KacperFKorban commented 5 months ago

This is an extension of #28