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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:53:57+00:00 2026-05-26T01:53:57+00:00

I have this: data Vector3 t = Vector3 { ax, ay, az :: t

  • 0

I have this:

data Vector3 t = Vector3 { ax, ay, az :: t }
data Point3 t = Point3 { x, y, z :: t }
data Ray3 t = Ray3 { ori :: Point3 t, dir :: Vector3 t }
data Sphere t = Sphere { center :: Point3 t, radius :: t }

I want a Shape type class, so I did this:

class Shape s where
      distance :: s -> Ray3 t -> t

distance takes a shape and a ray and computes the distance to the shape along the given ray. When I try to create an instance, it doesn’t work. This is what I have so far:

instance Shape (Sphere t) where
         distance (Sphere center radius) ray = -- some value of type t --

How do I create an instance of Shape? I’ve tried everything I can think of, and I’m getting all kind of errors.

  • 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-26T01:53:57+00:00Added an answer on May 26, 2026 at 1:53 am

    The problem is that the type variable t in Sphere t is not the same as the one in the type signature of distance. Your current types are saying that if I have a Sphere t1, I can check it against a Ray3 t2. However, you probably want these to be the same type. To solve this, I would change the Shape class to

    class Shape s where
        distance :: s t -> Ray3 t -> t
    

    Now the dependency on t is explicit, so if you write your instance as

    instance Shape Sphere where
        distance (Sphere center radius) ray = ...
    

    the types should line up nicely, although you’ll probably need to add in some numeric constraints on t to do any useful calculations.

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

Sidebar

Related Questions

Say I have a vector: (def data [Hello World Test This]) And I want
I have this class: public MyClass { public void initialize(Collection<String> data) { this.data =
I have this Javascript data: [{id:123,type:test},{id:154,type:another}] How would you transform that into something so
I have this script that collects data from users and I want to check
I have several data that looks like this: Vector1_elements = T,C,A Vector2_elements = C,G,A
I have this data from a xml file: <?xml version=1.0 encoding=utf-8 ?> <words> <id>...</id>
Say I have this table schema. ID AccNo Amount Say I have this data
I have this big data-entry sort of page, a table kind of layout using
We have this set of data that we need to get the average of
I have this scenario where I need data integrity in the physical database. For

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.