Skip to content

Instantly share code, notes, and snippets.

@sile
Last active December 23, 2015 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sile/6589133 to your computer and use it in GitHub Desktop.
Save sile/6589133 to your computer and use it in GitHub Desktop.
http://d.hatena.ne.jp/osiire/20090516#1242456737 のErlang版みたいなもの
-module(card).
-export([num/1]).
-export_type([card/0]).
-type card() :: {num, 1..10} | jack | queen | king.
-spec num(card()) -> 1..13.
num({num, N}) -> N;
num(jack) -> 11;
num(queen) -> 12;
num(king) -> 13.
-module(card_ex).
-export([num/1, next/1]).
-export_type([card/0]).
-type card() :: card:card() | joker.
-spec num(card()) -> 0..13.
num(joker) -> 0;
num(Other) -> card:num(Other).
-spec next(card()) -> card().
next({num, N}) when N < 10 -> {num, N+1};
next({num, _}) -> jack;
next(jack) -> queen;
next(queen) -> king;
next(king) -> joker;
next(joker) -> {num, 1}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment