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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:12:51+00:00 2026-06-13T02:12:51+00:00

I am using scalacheck and am in the middle of a generic-programming soup right

  • 0

I am using scalacheck and am in the middle of a generic-programming soup right now. The official guide shows this example:

def matrix[T](g: Gen[T]): Gen[Seq[Seq[T]]] = Gen.sized { size =>
  val side = scala.math.sqrt(size).asInstanceOf[Int]
  Gen.listOfN(side, Gen.listOfN(side, g))
}

Meanwhile, for my test I require a matrix of type Array[Array[T]]. I tried with the following function:

def matrix[T](g: Gen[T]): Gen[Array[Array[T]]] = Gen.sized { size =>
  val side = scala.math.sqrt(size).asInstanceOf[Int]
  val g1 = Gen.containerOfN[Array, T](side, g)
  Gen.containerOfN[Array, Array[T]](side, g1)
}

Here, I run into trouble. The compiler says:

Multiple markers at this line
– not enough arguments for method containerOfN: (implicit b: org.scalacheck.util.Buildable[T,Array])org.scalacheck.Gen[Array[T]].
Unspecified value parameter b.
– could not find implicit value for parameter b: org.scalacheck.util.Buildable[T,Array]
– could not find implicit value for parameter b: org.scalacheck.util.Buildable[T,Array]
– not enough arguments for method containerOfN: (implicit b: org.scalacheck.util.Buildable[T,Array])org.scalacheck.Gen[Array[T]].
Unspecified value parameter b.

I understand that stuff like this is usually remedied by adding implicit parameters to the function, however, i havent made this work yet.

I usually encounter this error when building generic arrays, as an example:

  def build[T](n:Int)(implicit m:ClassManifest[T]) = Array.ofDim[T](n)

but, I am afraid I don’t fully understand what is happening or why this is needed.

Can someone explain how to make the correct matrix-function along with an example of usage in scalacheck? A thorough explanation of the details about building sequences with implicit class manifests would be very welcome!

edit

  import org.scalacheck.util.Buildable._
  def matrix[T](g: Gen[T])(implicit b: Buildable[T, Array]): Gen[Array[Array[T]]] = Gen.sized { size =>

    val side = scala.math.sqrt(size).asInstanceOf[Int]
    val g1 = Gen.containerOfN[Array, T](side, g)
    Gen.containerOfN[Array, Array[T]](side, g1)
  }

Still doesn’t work. Need implicit for Buildable[Array[T],Array]… Don’t know how to get this because I can only add 1 implicit argument :/

  • 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-06-13T02:12:53+00:00Added an answer on June 13, 2026 at 2:12 am

    You’re almost there. The important part of the error is could not find implicit value for parameter b: org.scalacheck.util.Buildable[T,Array]

    Looking at the method definition of containerOfN

      def containerOfN[C[_],T](n: Int, g: Gen[T])(implicit b: Buildable[T,C]): Gen[C[T]] = ...
    

    So, there’s your missing argument. You need an implicit argument of type Buildable[T,Array]. Following through to where Buildable is defined in the scalacheck sources, I found that there was an object (org.scalacheck.util.Buildable) that provides implicits that provide Buildables for the common collection types which includes Array. So all you need to bring that into scope. You can do this with:

      import org.scalacheck.util.Buildable._
      def matrix[T](g: Gen[T]): Gen[Array[Array[T]]] = Gen.sized { size =>
        val bT = implicitly[Buildable[T, Array]]
        val bArrayT = implicitly[Buildable[Array[T], Array]]
    
        val side = scala.math.sqrt(size).asInstanceOf[Int]
        val g1 = Gen.containerOfN[Array, T](side, g)
        Gen.containerOfN[Array, Array[T]](side, g1)
      }
    

    Or

      import org.scalacheck.util.Buildable._
      def matrix[T](g: Gen[T])(implicit bT: Buildable[T, Array], bArrayT: Buildable[Array[T], Array]): Gen[Array[Array[T]]] = Gen.sized { size =>
        ...
      }
    

    The particular implicit you need in org.scalacheck.util.Buildable is:

    implicit def buildableArray[T](implicit cm: ClassManifest[T]) = 
      new Buildable[T,Array] {
        def builder = mutable.ArrayBuilder.make[T]
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using rubular.com as a guide, I am trying to get this expression to work
In scalacheck's user guide there is Generating Case Classes paragraph. I modified example from
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using CI for the first time and i'm smashing my head with this seemingly
Using the following as an example (with $db being a previously created database connection
Using the new mvc4 now gives us access to use facebook oauth otb. I
Using Rails 3, but I guess doesn't matter. I put this in the template
Using C#.NET, i wrote a toolbar which is stored now into toolbar.cs file. I
using this code I can send one texture to the shader: devcon->PSSetShaderResources(0, 1, &pTexture);
Using def compare_lsts(list1,list2): first_set = set(list1) second_set=set(list2) results =[x for x in list1 if

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.