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

  • Home
  • SEARCH
  • 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 7558373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:21:19+00:00 2026-05-30T12:21:19+00:00

While learning Scalaz 6 , I’m trying to write type-safe readers returning validations. Here

  • 0

While learning Scalaz 6, I’m trying to write type-safe readers returning validations. Here are my new types:

type ValidReader[S,X] = (S) => Validation[NonEmptyList[String],X]
type MapReader[X] = ValidReader[Map[String,String],X]

and I have two functions creating map-readers for ints and strings (*):

def readInt( k: String ): MapReader[Int] = ...
def readString( k: String ): MapReader[String] = ...

Given the following map:

val data = Map( "name" -> "Paul", "age" -> "8" )

I can write two readers to retrieve the name and age:

val name = readString( "name" )
val age = readInt( "age" )

println( name(data) ) //=> Success("Paul")
println( age(data) )  //=> Success(8)

Everything works fine, but now I want to compose both readers to build a Boy instance:

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

My best take is:

  val boy = ( name |@| age ) {
    (n,a) => ( n |@| a ) { Boy(_,_) }
  }
  println( boy(data) ) //=> Success(Boy(Paul,8))

It works as expected, but the expression is awkward with two levels of applicative builders. Is there a way, to get the following syntax to work ?

  val boy = ( name |@| age ) { Boy(_,_) }

(*) Full and runnable implementation in: https://gist.github.com/1891147


Update: Here is the compiler error message that I get when trying the line above or Daniel suggestion:

[error] ***/MapReader.scala:114: type mismatch;
[error]  found   : scalaz.Validation[scalaz.NonEmptyList[String],String]
[error]  required: String
[error]   val boy = ( name |@| age ) { Boy(_,_) }
[error]                                    ^
  • 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-30T12:21:20+00:00Added an answer on May 30, 2026 at 12:21 pm

    How about this?

    val boy = (name |@| age) {
      (Boy.apply _).lift[({type V[X]=ValidationNEL[String,X]})#V]
    }
    

    or using a type alias:

    type VNELStr[X] = ValidationNEL[String,X]
    
    val boy = (name |@| age) apply (Boy(_, _)).lift[VNELStr]
    

    This is based on the following error message at the console:

    scala> name |@| age apply Boy.apply
    <console>:22: error: type mismatch;
     found   : (String, Int) => MapReader.Boy
     required: (scalaz.Validation[scalaz.NonEmptyList[String],String], 
                scalaz.Validation[scalaz.NonEmptyList[String],Int]) => ?
    

    So I just lifted Boy.apply to take the required type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While learning Prolog, I'm trying to solve the following problem, using accumulators: Write a
While I'm learning a new language, I'll typically put lots of silly println's to
While learning c# and wpf, i am trying to get grasp of data binding.
I am trying to program (while learning JQuery) the following: I have a form
I installed Netbeans IDE 6.8 today to use it while learning Ruby. Here the
I'm trying to build some iOS apps while learning and am having some trouble
I'm new to C++ and while learning i came across a lot of places
While learning different languages, I've often seen objects allocated on the fly, most often
i just got some more questions while learning PHP, does php implement any built
MOV is probably the first instruction everyone learns while learning ASM. Just now I

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.