{-# LANGUAGE DeriveFoldable, DeriveFunctor, DeriveTraversable, Safe #-}
module Data.Char.Block(
Row(Row, left, right)
, Block(Block, upper, lower)
, filled
) where
import Test.QuickCheck.Arbitrary(Arbitrary(arbitrary), Arbitrary1(liftArbitrary), arbitrary1)
data Row a = Row {
left :: a
, right :: a
} deriving (Eq, Foldable, Functor, Ord, Read, Show, Traversable)
data Block a = Block {
upper :: Row a
, lower :: Row a
} deriving (Eq, Foldable, Functor, Ord, Read, Show, Traversable)
instance Applicative Row where
pure x = Row x x
Row fl fr <*> Row l r = Row (fl l) (fr r)
instance Applicative Block where
pure x = Block (pure x) (pure x)
Block fu fl <*> Block u l = Block (fu <*> u) (fl <*> l)
instance Arbitrary a => Arbitrary (Row a) where
arbitrary = arbitrary1
instance Arbitrary1 Row where
liftArbitrary arb = Row <$> arb <*> arb
instance Arbitrary a => Arbitrary (Block a) where
arbitrary = arbitrary1
instance Arbitrary1 Block where
liftArbitrary arb = Block <$> arb' <*> arb'
where arb' = liftArbitrary arb
filled
:: Block Bool
-> Char
filled (Block (Row False False) (Row False False)) = ' '
filled (Block (Row True True ) (Row False False)) = '\x2580'
filled (Block (Row False False) (Row True True )) = '\x2584'
filled (Block (Row True True ) (Row True True )) = '\x2588'
filled (Block (Row True False) (Row True False)) = '\x258c'
filled (Block (Row False True ) (Row False True )) = '\x2590'
filled (Block (Row False False) (Row True False)) = '\x2596'
filled (Block (Row False False) (Row False True )) = '\x2597'
filled (Block (Row True False) (Row False False)) = '\x2598'
filled (Block (Row True False) (Row True True )) = '\x2599'
filled (Block (Row True False) (Row False True )) = '\x259a'
filled (Block (Row True True ) (Row True False)) = '\x259b'
filled (Block (Row True True ) (Row False True )) = '\x259c'
filled (Block (Row False True ) (Row False False)) = '\x259d'
filled (Block (Row False True ) (Row True False)) = '\x259e'
filled (Block (Row False True ) (Row True True )) = '\x259f'