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 

Interface and/or Struct Accessor Functions?

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



Joined: 18 Feb 2009
Posts: 5

PostPosted: Sun Apr 26, 2009 3:38 am    Post subject: Interface and/or Struct Accessor Functions? Reply with quote

Given a field in a struct or interface, is there a way to get 'for free' a function that extracts said field? I know I can use dots (and pattern matching for structs) with a single object, but for higher order functions I need a real function to pass.

Example:
Code:
// A simple record type
typedef struct { Key key; Data data; } TaggedPair;
// A structure holding said records
Vector#(N,TaggedPair) taggedPairs;
// Extract the 'key' field for each record
Vector#(N,Key) keys = map ( ...?, taggedPairs);


Of course it's easy enough to write a one-liner 'function extractKey(p) = p.key;', but after the first few times it gets annoying, plus it bloats the code.
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