Error Type Mistmatch

Good morning ,

I have a type of the form :
type Formula = Function[Environment, Either[Unit, Formula]]

and I have a function of the form :

def mon_id():Formula = (_Env: Environment) => {
debug(“mon_id no match”)
}
}

However Scala keeps on saying type mismatch. Required Either[Unit,Formula], Found : Unit

Could you kindly help on what is best to do please ?

Thanks a lot and good day,
Gianluca Zahra

What is the signature of debug?

As a side note, using Either[Unit, T] is unusual and makes one wonder whether Option[T] would be more appropriate.

1 Like

Formula seems odd beyond the Either[Unit, *]. In the “success” case, it will produce another formula that may be fed (the same? another?) environment to produce yet another formula, etc. The only way to break out of this recursion is for a formula to “fail” with Unit. IOW, at best, Formula represents a chain of black-box, side-effecting computations that never yields an explicit result. This may make some sense with a mutable environment, but still - is this the intended semantics? :face_with_raised_eyebrow:

1 Like

Forgetting that Formula feels weird. The reason why your code doesn’t work is because you have to return an Either, but you are returning some value and expecting the compiler to magically create the either for you.

// This should compile.
def mon_id(): Formula = (_Env: Environment) => {
  Left(debug(“mon_id no match”))
}
1 Like

Thanks a lot all for your answers.

Really appreciate :slight_smile:

Thanks a lot and good day