小编Uzi*_*iel的帖子

F#类型和循环

我正在研究一个创建一副牌的F#教程.列出了类型,但我无法理解如何遍历类型以创建完整套牌的地图.我期待做类似的事情

Foreach rank in ranks
   Foreach suit in suits
       somehow combine the two
   next suit
next rank
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点?以下是创建的类型.

我想如果我把它们从类型更改为列表它们可以合并,对吧?那么,类型有什么意义呢?

type suits=
    |Spade=1
    |Heart=2
    |Club=3
    |Diamond=4

type ranks=
    |ValCard of int
    |Jack 
    |Queen
    |King

type deck= Deck of ranks * suits
Run Code Online (Sandbox Code Playgroud)

f# types loops

5
推荐指数
2
解决办法
290
查看次数

标签 统计

f# ×1

loops ×1

types ×1