Can you make an instance of a class not for a type but for a whole class in Haskell?

Suppose I want to make all numbers an instance of Monoid. Instead of having to create an instance for each Num like this:

instance Monoid Int where
  mappend = (+)
  mempty = 0

instance Monoid Float where
  mappend = (+)
  mempty = 0.0

-- etc

Is there something like this?

instance Num t => Monoid t where
  mappend = (+)
  mempty = 0

Can you make an instance of a class not for a type but for a whole class in Haskell?

Can you make an instance of a class not for a type but for a whole class in Haskell?

Suppose I want to make all numbers an instance of Monoid. Instead of having to create an instance for each Num like this:

instance Monoid Int where
  mappend = (+)
  mempty = 0

instance Monoid Float where
  mappend = (+)
  mempty = 0.0

-- etc

Is there something like this?

instance Num t => Monoid t where
  mappend = (+)
  mempty = 0

Can you make an instance of a class not for a type but for a whole class in Haskell?

I want to only draw objects that a camera can see

I’m using THREEJS to build a dynamically generated ‘minecraft’ world based on a perlin noise generator.

Here’s how far I am now: Block World

All is well so far except that, I’m noticing extreme performance (framerate) issues once I hit about 7,000 or so ‘objects’.
My board usually generates around 12-14 thousand objects when I set the dimensions to be maximally 64*64*6 (the Perlin map obviously only uses a portion of the max blocks).

I “think” that what I want is to only draw the blocks that the camera can see. I think that I would set mesh.visible = false for the blocks that are behind the other blocks (hidden from the camera). Every frame I would just check to see what blocks are visible to the camera and set their mesh.visible = true.

Regardless, I think what I’m trying to accomplish is called “Occlusion Culling” but I cannot find any working examples of how to do this in ThreeJS.

One idea I had was to Raytrace for every pixel on the screen and look for intersections with the first object:

raycaster.setFromCamera( mouse, camera );
var intersects = raycaster.intersectObjects( scene.children );

I figure that even if I figured this out, it would probably be really slow anyways.

Another idea I had was to merge all of the meshes together into one. That was great. I got incredible frame rates from this. Unfortunately I lost the ability to individually manipulate the specific blocks, and their unique textures were also lost. I’d need a way to be able to still reference, change materials for and remove blocks within that merged geometry.
I don’t think this is the solution.

Honestly I’m hoping someone here could explain how I can hide all of the meshes that are not visible because they are completely behind other objects.

Thanks

EDIT: Concerning the suggesting to implement frustrum culling, I tried this already

            var counter = 0;
            //
            // Only draw objects that you can see... I think
            frustum.setFromMatrix(new THREE.Matrix4().multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse));
            for (var i=0; i<world.length; i++) {
                for (var j=0; j<world[i].length; j++) {
                    for (var d=0; d<world[i][j].length; d++) {
                        if ( world[i][j][d].type !== -1 ) {
                            if ( frustum.intersectsObject( world[i][j][d].block ) ) {
                                world[i][j][d].block.visible = true;
                                counter++;
                            }
                        }
                    }
                 }
             }
            console.log(counter);

read more

What does it mean to POSIX that a thread is "suspended"?

In the course of commentary on a recent question, a subsidiary question arose about at what point a cancellation request for a pthreads thread with cancelability PTHREAD_CANCEL_DEFERRED can be expected to be acted upon. References to the standard and a bit of lawyering ensued. I’m not much concerned specifically about whether I was mistaken in my comments on that question, but I would like to be sure I understand POSIX’s provisions correctly.

The most pertinent section of the standard says

read more

What does it mean to POSIX that a thread is "suspended"?

In the course of commentary on a recent question, a subsidiary question arose about at what point a cancellation request for a pthreads thread with cancelability PTHREAD_CANCEL_DEFERRED can be expected to be acted upon. References to the standard and a bit of lawyering ensued. I’m not much concerned specifically about whether I was mistaken in my comments on that question, but I would like to be sure I understand POSIX’s provisions correctly.

The most pertinent section of the standard says

read more