bluespec.com Forum Index bluespec.com
Bluespec Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Overlapping typeclass instances issue

 
Post new topic   Reply to topic    bluespec.com Forum Index -> Designing with BSV's Rules, Interfaces, ...
View previous topic :: View next topic  
Author Message
garethlloyd



Joined: 19 Mar 2014
Posts: 12

PostPosted: Mon Mar 24, 2014 11:18 am    Post subject: Overlapping typeclass instances issue Reply with quote

Code:
typeclass Convertable#(type from, type to);
  function to convert(from x);
endtypeclass

//Convert to the same type
instance Convertable#(a, a);
  function convert(x) = x;
endinstance

//Convert HList to List if its members are convertable
instance Convertable#(HNil, List#(a));
  function convert(x) = tagged Nil;
endinstance
instance Convertable#(HCons#(h, l), List#(a))
  provisos(Convertable#(h, a), Convertable#(l, List#(a)));
  function convert(x) = List::cons(convert(hHead(x)), convert(hTail(x)));
endinstance

//A and B have a Common interface
interface A;
  interface Put#(int) x;
  interface FIFO#(int) other;
endinterface
interface B;
  interface FIFO#(int) y;
  interface FIFO#(int) other;
endinterface

//The Common interface
interface Common;
  interface Put#(int) in;
endinterface

//Random Other interface we want to connect to
interface Other;
  interface Get#(int) out;
endinterface

//Define how to convert A and B to Common
instance Convertable#(A, Common);
  function convert(a) = (
    interface Common;
      interface in = a.x;
    endinterface
    );
endinstance
instance Convertable#(B, Common);
  function convert(b) = (
    interface Common;
      interface in = toPut(b.y);
    endinterface
    );
endinstance

//Define how interfaces that are convertible to Common connect to Other
instance Connectable#(c,Other)
  provisos(Convertable#(c,Common));
  module mkConnection#(c c1, Other other)(Empty);
    mkConnection(convert(c1).in, other.out);
  endmodule
endinstance


Quote:
Error: "TB.bsv", line 60, column 18: (T0128)
Overlapping typeclass instances Connectable::Connectable#(c, TB::Other) and
Connectable::Connectable#(function Action f(a x1), a) (defined at
"Connectable.bs", line 24, column 6 ) cannot be ordered from most-specific
to least-specific, so they cannot support predictable instance-resolution.
Please resolve this by changing one or both of the instances.


I could restrict 'c', replicating the instance for A, B and Common type which I know to be Convertible but if a more elegant solution exists it would preferentially use that.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    bluespec.com Forum Index -> Designing with BSV's Rules, Interfaces, ... All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
bluespec.com topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP