Skip to content

Instantly share code, notes, and snippets.

@Shadowfiend
Created June 27, 2012 16:41
Show Gist options
  • Save Shadowfiend/3005301 to your computer and use it in GitHub Desktop.
Save Shadowfiend/3005301 to your computer and use it in GitHub Desktop.
/**
* A structural type for an expression that has a getFirst and a getSecond method
* which both return a Symbols.Type.
*/
type TwoPartExpression = {
def getFirst : Symbols.Type
def getSecond : Symbols.Type
}
/**
* Determines the type of the given two part expression's operands.
*
* If the types are divergent, throws an exception.
*/
def expressionType(expression:TwoPartExpression) : Symbols.Type = {
val (firstType, secondType) = (expression.getFirst, expression.getSecond)
if (firstType == secondType)
firstType
else
throw new Exception(...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment