14.07.2013 Views

Contents - Cultural View

Contents - Cultural View

Contents - Cultural View

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Quark Framework 261<br />

//illustrates positionally based case expression extraction of the<br />

//"name" field of the RegularEmployee data constructor<br />

RegularEmployee empname _ _ -> empname;<br />

;<br />

b) By field name in a case expression:<br />

/**<br />

* @arg employee<br />

* @return the employee's name<br />

*/<br />

employeeName :: Employee -> String;<br />

employeeName employee =<br />

case employee of<br />

//illustrates field-name based case expression extraction of the<br />

//"name" field of the RegularEmployee data constructor<br />

RegularEmployee {name} -> name;<br />

;<br />

This method is obviously more stable with respect to changes in data constructor arguments than the positional<br />

version<br />

c) By a selector expression<br />

/**<br />

* @arg employee<br />

* @return the employee's name<br />

*/<br />

employeeName :: Employee -> String;<br />

employeeName employee =<br />

//illustrates data constructor field selection of the directReports<br />

//field<br />

employee.RegularEmployee.name;<br />

Note that CAL allows multiple constructor arguments to be cited in a case extractor, along with multiple constructors<br />

to match on (so long as they all have the named arguments). So, the following scenario is possible (assuming the<br />

data declaration includes the employeeID field and new constructors for Contractor and Associate):<br />

// ...snip...<br />

case employee of<br />

//illustrates multiple field case expression extraction over multiple<br />

//data constructors. Note the local renaming of the employeeID field<br />

//to 'id'<br />

(RegularEmployee | Contractor | Associate) {name, employeeID = id } -> (name, id);<br />

;<br />

// ...snip...

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!