2016-03-31 8 views
0
datatype cards = king of int * int 
       | queen of string 
       | jack of cards 
       | ace of cards * cards 
       | joker of int * cards 
+2

真剣に奇妙なカードゲームのデータ型のように思えます。何か動機づけはありますか? –

答えて

2

です。

fun hasKing cards = 
    case cards of 
     king (i, j)   => true 
     | queen s    => false 
     | jack cards1   => hasKing cards1 
     | ace (cards1, cards2) => hasKing cards1 orelse hasKing cards2 
     | joker (i, cards2) => hasKing cards2 

しかし、私は、関数と区別するために大文字で私の値コンストラクタに名前を付けます:

datatype cards = King of int * int 
       | Queen of string 
       | Jack of cards 
       | Ace of cards * cards 
       | Joker of int * cards 
関連する問題