I would like to add that if you use a solution based on 5 tuples (as suggested in other answers), you can still use all the folding / moving functions. In particular, first define
import Control.Applicative import Data.Foldable import Data.Traversable data Tuple5 a = Tuple5 aaaaa
and define folding and moving operations on it:
instance Traversable Tuple5 where traverse f (Tuple5 abcde) = Tuple5 <$> fa <*> fb <*> fc <*> fd <*> fe instance Foldable Tuple5 where foldMap = foldMapDefault instance Functor Tuple5 where fmap = fmapDefault
Then you can have
data Hand = Hand (Tuple5 Card)
and reset / move the structure using any methods from Foldable / Traversable / Functor .
Update: I recently created a small tuples-homogenous-h98 library that defines newtype aliases for uniform tuples such as
newtype Tuple5 a = Tuple5 { untuple5 :: (a,a,a,a,a) }
and adds examples of Traversable , Foldable , Functor , Applicative and Monad .
Petr pudlák
source share