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 6628667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:09:05+00:00 2026-05-25T22:09:05+00:00

Given a signature like this one or that one : def foo[A, F[_]](implicit mon:

  • 0

Given a signature like this one or that one:

def foo[A, F[_]](implicit mon: Monoid[F[A]], pr: Pure[F]): F[A]

Assuming A is Char, is there a way to get a String instead of a List[Char]?

String does not take a type parameter, so I assume it’s not possible. What’s the next best option? Right now, I use mkString on the result, but that doesn’t feel optimal.

I think String is a monoid with zero "" and append +…

  • 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-25T22:09:06+00:00Added an answer on May 25, 2026 at 10:09 pm

    It is possible to persuade String to masquerade as a higher-kinded type, and hence allow functions of the form of foo to be applicable. However, Scala’s type inference isn’t currently up to the job of inferring foo‘s type arguments, so you’ll have to supply them explicitly,

    // Assuming the the definitions of Pure and Monoid from Scalaz
    
    type ConstString = {
      type λ[X] = String
    }
    
    implicit def StringPure = new Pure[ConstString#λ] {
      def pure[A](a: => A) = a.toString
    }
    
    val sm = implicitly[Monoid[String]]
    val sp = implicitly[Pure[ConstString#λ]]
    val f : String = foo[Char, ConstString#λ](sm, sp) // OK
    

    Note that the Char type argument to foo is unused and can be anything, but must be something: in this case either Char is the natural choice, but Nothing or Any would do as well.

    Note that this solution trades on String‘s special characteristics: values of all types are convertible to Strings so pure[A](a : => A) : String is implementable for all types A. Replicating this idiom for types other than String would most likely have to exploit some mechanism for implementing type-specific cases in the body of pure (eg. a pattern match of some sort).

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

Sidebar

Related Questions

Given a function object, how can I get its signature? For example, for: def
I'd like to decorate a function, using a pattern like this: def deco(func): def
Given a method signature: public bool AreTheSame<T>(Expression<Func<T, object>> exp1, Expression<Func<T, object>> exp2) What would
Given a specific DateTime value, how do I display relative time, like: 2 hours
Given a Python object of any kind, is there an easy way to get
Given an absolute or relative path (in a Unix-like system), I would like to
Given 2 rgb colors and a rectangular area, I'd like to generate a basic
Given a (source) patch file, what's the easiest way to apply this patch on
Need some help with crypto routines in Java. Given a PKCS#7 signature, I want
This isn't homework for me , it's a task given to students from some

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.