Scala Types query

Good afternoon,

I am trying to write manual types

type environment = List[(String.type, formula)]
type formula = (environment => (Either[String.type,formula]))

But when I try to compile the program, an error crops up that states :

illegal cyclic reference involving type environment
  type formula = (environment => (Either[String.type,formula]))

Could you kindly tell me what is best to do please ?

Thanks a lot and good day :slight_smile:

First String.type is not doing what you think it does. Second, the type keyword just creates a type-alias, as such, it is just assigning a new name to the type on the right-hand side of the equals, it is not really defining a new type.
Thus, it can not be recursive or have cycles since then it doesn’t know to what to expand.

In this case, I believe the best is to just define new classes.

final case class Environment(data: List[(String, Formula)]) // Maybe a map would be better?
final case class Formula(run: Environment => Either[String, Formula])

Thanks a lot for your help and good day :slight_smile: