Skip to content

Instantly share code, notes, and snippets.

@macintux
Last active December 22, 2015 03:18
Show Gist options
  • Save macintux/6408859 to your computer and use it in GitHub Desktop.
Save macintux/6408859 to your computer and use it in GitHub Desktop.
Erlang type examples, because I can never remember how they work and I utterly fail at reading docs

Doc: http://www.erlang.org/doc/reference_manual/typespec.html

-type square() :: tuple(pos_integer(), pos_integer()).
-type side() :: 'white'|'black'.
-type movefun() :: fun((square(), square(), side()) -> tuple(square(), list(square()))).
-type movedef() :: tuple(atom(), movefun()).

-record(move, { piece,
                start,
                target,
                movetype }).
-type moverec() :: #move{}.

-record(piece, { type=pawn,
                 team=white,
                 history=[],
                 movefun=pawnmove,
                 capturefun=pawncap }).
-type piece() :: #piece{}.

-record(historyitem, { endsquare,
                       traversed=[] }).
-type historyitem() :: #historyitem{}.

-record(boardstate, { pieces,
                      whiteking={5, 1},
                      blackking={5, 8} }).
-type boardstate() :: #boardstate{}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment