0

Here is a simple example that is not compiled:

import cats.data.Validated

object Ex {

  type FailSlow[A] = Validated[List[String], A]

  case class User(name: String, age: Int)

  //this works fine:
  def validBoth(name:String, age:Int):FailSlow[User] =
    Validated.valid[List[String], User](User(name,age))

  //this not working:
  def validBothNotWorking(name:String, age:Int):FailSlow[User] =
    Validated.valid[FailSlow[User]](User(name,age))
}

It seems I miss something with type aliases. Why in the 1st case it works and in the 2nd case it does not.

Alexandr
  • 9,213
  • 12
  • 62
  • 102
  • 1
    `Validated[List[String], A]` **=!=** `List[String], User`. [_invalid_](https://typelevel.org/cats/api/cats/data/Validated$.html#invalid[E,A](e:E):cats.data.Validated[E,A]) takes two parameters _(`E` & `A`)_ and returns a `Validated[E, A]`. Your type alias does not makes sense there. However, you may remove it and type inference must work since you already said the return type is `FailSlow[User]`. – Luis Miguel Mejía Suárez Mar 11 '19 at 14:35
  • 1
    @LuisMiguelMejíaSuárez, thank you, so stupid mistake. I simplified return type as you recommended to: Validated.valid(User(name,age)) and it works and looks fine now cause of type inference and explicit return type in the signature. – Alexandr Mar 11 '19 at 14:47

0 Answers0