var mapSyncOptimization = require('./map_sync_optimization')
function mapType(rel, ch){
	var inputType = rel.params[0].schemaType//ch.computeType(rel.params[0], ch.bindingTypes)
	var singleInputType = inputType.members
	//console.log('singleInputType: ' + JSON.stringify(singleInputType))
	//console.log('inputType: ' + JSON.stringify(inputType))
	_.assertDefined(singleInputType)
	
	var implicits1 = rel.params[1].implicits
	var implicits2 = rel.params[2].implicits
	
	var binding1 = {}
	binding1[implicits1[0]] = singleInputType
	var binding2 = {}
	binding2[implicits2[0]] = singleInputType
	
	//s.log('map bound key ' + implicits1[1])
	//s.log('map bound value ' + implicits1[1])
	
	var keyType = ch.computeMacroType(rel.params[1], ch.bindingTypes, binding1)
	var valueType = ch.computeMacroType(rel.params[2], ch.bindingTypes, binding2)
	if(rel.params.length === 4){
		var implicits3 = rel.params[3].implicits
		var moreBinding = {}
		moreBinding[implicits3[0]] = valueType
		moreBinding[implicits3[1]] = valueType
		ch.computeMacroType(rel.params[3], ch.bindingTypes, moreBinding)
	}

	//console.log('map: ' + JSON.stringify([keyType,valueType]))
	
	if(keyType.type === 'set' || keyType.type === 'list'){
		keyType = keyType.members
	}
	
	_.assert(keyType.type !== 'set')
	_.assert(keyType.type !== 'list')
	_.assert(valueType.type !== 'set')
	_.assert(valueType.type !== 'list')
	

	return {type: 'map', key: keyType, value: valueType}
}