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

  • Home
  • SEARCH
  • 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 9185111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:12:57+00:00 2026-06-17T19:12:57+00:00

I have written my own implementation of a graph based on adjacency matrices and

  • 0

I have written my own implementation of a graph based on adjacency matrices and made instance of the Read class.

My graph takes a type as input which will be the type of the edges.

If I try expression like

read " - - 8 \n - 9 - \n 1 2 3" :: GraphADJ Int

it works just fine (it’s a graph with 3 nodes, and the edge from first node to the third, from the second to the second and from the third to all the nodes).

What I wanted to do is to be able to not tell the type inference the type of the edges, but to put them into a context (like in read"4"+3).

I have the function insertEdge which takes a graph, a couple of nodes and the new edge.

insertEdge :: Graph g n e => g -> (n, n) -> e -> g

(Graph is the general class for the graph which GraphADJ is made instance of)

So when I try to do

 insertEdge (read " - - 8 \n - 9 - \n 1 2 3" :: GraphADJ Int) (1,2) 3

it works just fine, but if I don’t make the type explicit, I get the error
Ambiguous type variables .

Did I forget something in the Read or a I missing something?

  • 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-17T19:12:58+00:00Added an answer on June 17, 2026 at 7:12 pm

    The problem is compiler does not have enough info to infer type for read.

    Even if you provide type info for n to Int and e to Int compiler still does not have information of g. All it knows that g is a type with an instance for Graph g Int Int. It still can not infer g even if there is single type which inhabit such an instance.

    Compiler can not automatically see that in the current scope there is only on such type which has such a instance as allowing such behavior might result in breaking of code by importing modules.

    So the solution would be either to provide explicit signature or to make a specialized version of insertEdge providing explicit concrete types to provide enough information for read. The latter would be useful if you are using it for the same type at more than one place.

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

Sidebar

Related Questions

I have written my own linked list implementation in C, and it works fine
I have the following class definition, written in C++, residing in it's own header
I have written my own class that extends DateTime . What I haven't been
I have written my own SHA1 implementation in MATLAB, and it gives correct hashes.
I have written my own implementation of java.utils.List. Now I'd like to test it,
I have written my own java.util.List implementation, and now i want to store it
I have written my own function, which in C would be declared like this,
I have written my own hadoop program and I can run using pseudo distribute
have written this little class, which generates a UUID every time an object of
I have written a TCP server implementation using which I created an application which

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.