且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

接口抽象设计

更新时间:2023-01-12 12:33:26

首先,请记住类型类的主要目的是允许函数重载,即您可以使用不同类型的单一功能.您实际上并不需要这样做,因此***使用类似于

First of all, keep in mind that the main purpose of type classes is to permit overloading of functions, i.e. that you can use a single function at different types. You don't really require that, so you are better off with a record type along the lines of

data Player = Player { playCard :: [Card] -> IO (Card, Player), ... }


其次,一些玩家需要IO而一些不需要的问题可以通过自定义monad来解决.我已经为一个井字游戏编写了相应的示例代码,这是我的操作 包.