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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:40:13+00:00 2026-06-15T23:40:13+00:00

I’m writing a graph library to learn more about building slightly larger things in

  • 0

I’m writing a graph library to learn more about building slightly larger things in Haskell, and I’m coming across an issue.

Basically, I’m trying to define Edges as a set of two points, a from point and a to point. But, I’ve got multiple types of edges (Weighted/not), and I do not want them to be able to mix in graphs.

So, the idea I had was to make a couple of new classes, Weighted and Edgy, in order to be able to achieve the amount of polymorphic behavior I’m striving towards. Both types of Edge will be Edgy, but only the Weighted Edge type will be Weighted.

The Weighted class is simple, because it only has to modify the entire object. This is what it looks like:

class Weighted a where
  modifyWeight :: (Unbounded Int -> Unbounded Int) -> a -> a

where Unbounded is a Num type I threw together to support Infinitely large and small numbers. It’s simple enough, though, because I only have to return an a.

What I’m stuck on is getting the Edgy class to return something of the type of the class type (??? Not really sure how to put this, inner type, maybe?). To make this clearer, here’s what I’m working with, might make more sense:

class Edgy a where
  to :: a -> Vertex a
  from :: a -> Vertex a

where Vertex is a wrapper class — the Edge declarations that I’m trying to make here here:

data Edge a = Edge (Vertex a) (Vertex a) deriving (Show, Eq)

data WEdge a = WEdge (Vertex a) (Vertex a) (Unbounded Int) deriving (Show, Eq)

So, what I’m really trying to do is say “Okay, if you’re a member of the Edgy class, you should be able to return a Vertex of the type of the Edge“.

However, GHC doesn’t like this, because the a type in Edgy ends up being Edge a instead of a, and I’m not sure how to get it to “descend” into the class to pull that type out in order to return it.

If any of this is unclear, please leave a comment.

Any help is greatly appreciated; I’m stumped!

Thanks!

  • 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-15T23:40:14+00:00Added an answer on June 15, 2026 at 11:40 pm

    You may want to use type constructor classes rather than type classes

    class Edgy e where
        to :: e a -> Vertex a
        from :: e a -> Vertex a
    
    instance Edgy Edge where ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am writing an app with both english and french support. The app requests
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I am writing an app for my school newspaper, which is run completely online
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.