summaryrefslogtreecommitdiff
path: root/src/Util.hs
blob: 1e10eeca50c3846018b42a38681d575f52794f63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{-# LANGUAGE DeriveFoldable #-}
module Util (module Util, toList) where

import Data.Foldable (toList)
import Data.Word (Word8)


data Snoc a = SnocNil | Snoc (Snoc a) a
  deriving (Show, Foldable)

-- | Time-of-day, in unspecified time zone
data YMDHMS = YMDHMS {-# UNPACK #-} !YMD
                     {-# UNPACK #-} !HMS
  deriving (Show)

-- | Calendar day
data YMD = YMD {-# UNPACK #-} !Int
               {-# UNPACK #-} !Word8  -- ^ 1-based
               {-# UNPACK #-} !Word8
  deriving (Show, Eq, Ord)

-- | Time-of-day in seconds, in unspecified time zone
data HMS = HMS {-# UNPACK #-} !Word8
               {-# UNPACK #-} !Word8
               {-# UNPACK #-} !Word8
  deriving (Show)

pad :: Show a => Char -> Int -> a -> String
pad c w val =
  let s = show val
  in replicate (w - length s) c ++ s

uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d
uncurry3 f (x, y, z) = f x y z