Last active
December 23, 2015 05:48
-
-
Save sile/6589133 to your computer and use it in GitHub Desktop.
http://d.hatena.ne.jp/osiire/20090516#1242456737 のErlang版みたいなもの
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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