Skip to content

Instantly share code, notes, and snippets.

@BekaValentine
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save BekaValentine/d6f23ff589859e255179 to your computer and use it in GitHub Desktop.

Select an option

Save BekaValentine/d6f23ff589859e255179 to your computer and use it in GitHub Desktop.
data IntList = nil | cons(int,IntList)
is sugar for
enum IntListCon { nilCon , consCon };
struct IntList { IntListCon con ; int head ; IntList* tail; };
struct IntList nil;
nil.con = nilCon;
struct IntList cons(int x, IntList* xs) {
struct IntList xs';
xs'.con = consCon;
xs'.head = x;
xs'.tail = xs;
return xs';
}
and
case xs of {
nil -> f
cons(x,xs') -> g
}
is sugar for
if (nilCon == xs.con) {
f
} else if (consCon == xs.con) {
int x = xs.head;
IntList* xs' = xs.tail;
g
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment