#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>

#include "datatypes.h"
#include "sumlist.h"



// int sum = sumlist( intlist l );
//	sum all the elements (the heads) in l. return the result.
int sumlist( intlist l )
{
	int sum = 0;
	while( intlist_kind(l) == intlist_is_cons )
	{
		int head;
		intlist tail;
		get_intlist_cons( l, &head, &tail );
		sum += head;
		l = tail;
	}
	return sum;
}
