haskell – 创建记录表单列表的最短方法是什么?

haskell – 创建记录表单列表的最短方法是什么?,第1张

概述假设我有记录定义 data Zone = Zone { zId :: Int -- this zone's ID , zOwnerId :: Int -- the player who owns this zone (-1 otherwise) , zPodsP0 :: Int -- player 0's PODs on this zone , zPodsP1 :: 假设我有记录定义

data Zone = Zone  { zID      :: Int -- this zone's ID,zOwnerID :: Int -- the player who owns this zone (-1 otherwise),zPodsP0  :: Int -- player 0's PODs on this zone,zPodsP1  :: Int -- player 1's PODs on this zone,zPodsP2  :: Int -- player 2's PODs on this zone (always 0 for a two player game),zPodsP3  :: Int -- player 3's PODs on this zone (always 0 for a two or three player game)  } deriving Show

从getline读取的[String]创建记录的短路是什么?

zones <- replicateM zoneCount $fmap (mkZone . words) getline

这是迄今为止我能做的最好的事情.

{-# LANGUAGE namedFIEldPuns #-}mkZone :: [String] -> ZonemkZone xs = Zone {zID,zOwnerID,zPodsP0,zPodsP1,zPodsP2,zPodsP3}  where [zID,zPodsP3] = map read xs

在编写bot programmings编码时我会使用这种模式,如果有更好的方法可以做到这一点会很好.

解决方法 RecordWildCards删除了一半的样板.

{-# LANGUAGE RecorDWildCards #-}mkZone :: [String] -> ZonemkZone xs = Zone {..}  where [zID,zPodsP3] = map read xs
总结

以上是内存溢出为你收集整理的haskell – 创建记录表单列表的最短方法是什么?全部内容,希望文章能够帮你解决haskell – 创建记录表单列表的最短方法是什么?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1085123.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存