Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Haskell Instance Question

Tags:

haskell

I'm trying different data structures for implementing Prim's algorithm. So I made a class to abstract what I want to do:

class VertexContainer a where
  contains :: a -> Vertex -> Bool
  insert :: a -> WeightedEdge -> a
  numVertices :: a -> Int

Now I want to use a heap (from Data.Heap) as my vertex container. But I can't for the life of me figure out the syntax. As you can see from the insert declaration, the container can only hold WeightedEdges, which are a data type. So I tried:

instance VertexContainer (Heap MinPolicy WeightedEdge) where
  contains _ _ = True

It tells me it's an illegal type synonym. I've tried various other permutations, and none of them seem to work. Can anyone help me?

like image 310
Xodarap Avatar asked Aug 15 '26 18:08

Xodarap


1 Answers

If you read the entire error message you'll find that it tells you how to be able to use a type synonym in an instance declaration, namely by using the language extension TypeSynonymInstances. E.g., you can pass -XTypeSynonymInstances on the command line.

like image 164
augustss Avatar answered Aug 17 '26 23:08

augustss



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!