Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6945215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:24:27+00:00 2026-05-27T13:24:27+00:00

How do I compose two functions returning Validations? Following are my attempts that didn’t

  • 0

How do I compose two functions returning Validations? Following are my attempts that didn’t work:

scala> def f: Int => Validation[String, Int] = i => if(i % 2 == 0) Success(i * 2) else Failure("Odd!")
f: Int => scalaz.Validation[String,Int]

scala> def g: Int => Validation[String, Int] = i => if(i > 0) Success(i + 1) else Failure("Not positive!")
g: Int => scalaz.Validation[String,Int]

scala> kleisli(f) >=> kleisli(g)
<console>:16: error: no type parameters for method kleisli: (f: A => M[B])scalaz.Kleisli[M,A,B] exist so that it can be applied to arguments (Int => scalaz.Validation[String,Int])
 --- because ---
argument expression's type is not compatible with formal parameter type;
 found   : Int => scalaz.Validation[String,Int]
 required: ?A => ?M[?B]

              kleisli(f) >=> kleisli(g)
              ^

scala> type Va[+A] = Validation[String, A]
defined type alias Va

scala> kleisli[Va, Int, Int](f) >=> kleisli[Va, Int, Int](g)
<console>:17: error: could not find implicit value for parameter b: scalaz.Bind[Va]
              kleisli[Va, Int, Int](f) >=> kleisli[Va, Int, Int](g)
                                       ^

This works in Haskell, so I am expecting there should be a way of doing this with Scalaz as well.

λ> let f i = if i `mod` 2 == 0 then Right $ i * 2 else Left "Odd!"
λ> let g i = if i > 0 then Right $ i + 1 else Left "Not positive!"
λ> let h = f >=> g
λ> h 11
Left "Odd!"
λ> h (-4)
Left "Not positive!"
λ> h 4
Right 9
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:24:28+00:00Added an answer on May 27, 2026 at 1:24 pm

    you need to import Validation.Monad._ since >=> requires a Bind[M]

    scala> import scalaz._, Scalaz._
    import scalaz._
    import Scalaz._
    
    scala> def f: Int => Validation[String, Int] = i => if(i % 2 == 0) Success(i * 2) else    Failure("Odd!")
    f: Int => scalaz.Validation[String,Int]
    
    scala> def g: Int => Validation[String, Int] = i => if(i > 0) Success(i + 1) else Failure("Not positive!")
    g: Int => scalaz.Validation[String,Int]
    
    scala> type Va[+A] = Validation[String, A]
    defined type alias Va
    
    scala> import Validation.Monad._
    import Validation.Monad._
    
    scala> kleisli[Va, Int, Int](f) >=> kleisli[Va, Int, Int](g)
    res0: scalaz.Kleisli[Va,Int,Int] = scalaz.Kleislis$$anon$1@4fae3fa6
    
    scala> res0(11)
    res1: Va[Int] = Failure(Odd!)
    
    scala> res0(-4)
    res2: Va[Int] = Failure(Not positive!)
    
    scala> res0(4)
    res3: Va[Int] = Success(9)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to compose the results of two Linq Expressions. They exist in the
In Facebook's Compose Message, each name that appears in the TO field uses a
I am attempting to compose a style sheet that, given an XML input (obviously)
Imagine a GPS tracking system that is following the position of several objects. The
Assume that we have two classes public class EntityA { public EntityB EntityB {
I have two strings in python that I have converted to lists: Seq1 =
Hello Friends I am trying to compose two images in imagemagick shell script commane
I am coding a small Python module composed of two parts: some functions defining
While learning Scalaz 6 , I'm trying to write type-safe readers returning validations. Here
So I have a list of a functions of two arguments of the type

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.