Forum Index
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 Forum Index -> Designing with BSV's Rules, Interfaces, ...
View previous topic :: View next topic  
Author Message

Joined: 19 Mar 2014
Posts: 12

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

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

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

//Convert HList to List if its members are convertable
instance Convertable#(HNil, List#(a));
  function convert(x) = tagged Nil;
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)));

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

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

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

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

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

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
"", 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 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 topic RSS feed 

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