MFlamer
MFlamer

Reputation: 2450

Haskell: Using a function of a type class in a module without an instance

I have a module that defines and exports a type and type class as shown below. The problem is that I can't seem to use a function of the class in this module because there are no instances of the class yet.

this is the GHC error: "The type signature for `aabb' lacks an accompanying binding"

Is there any way around this problem? Thanks.

module AABB (
 AABB
,Boundable(..)
,aabb
,consume
) where

type AABB = (Vec3,Vec3)

class Boundable a where
aabb ∷  a → AABB

consume ∷  (Boundable a) ⇒ AABB → a → AABB
consume (v0,v1) x = (minV v0 v2, maxV v1 v3)
   where (v2,v3) = aabb x

maxV ∷  Vec3 → Vec3 → Vec3
maxV (Vec3 x0 y0 z0) (Vec3 x1 y1 z1) = Vec3 (max x0 x1) (max y0 y1) (max z0 z1)

minV ∷  Vec3 → Vec3 → Vec3
minV (Vec3 x0 y0 z0) (Vec3 x1 y1 z1) = Vec3 (min x0 x1) (min y0 y1) (min z0 z1)

Upvotes: 1

Views: 166

Answers (1)

augustss
augustss

Reputation: 23014

You need to indent aabb.

class Boundable a where
    aabb ∷  a → AABB

Or use braces:

class Boundable a where {
aabb ∷  a → AABB
}

Upvotes: 8

Related Questions