module Data.DoList
( DoList (DoList)
, item
, toDList
, fromList
, toList
) where
import qualified Data.DList as D
import GHC.Exts (IsString, fromString)
newtype DoList a r = DoList (D.DList a)
deriving (Eq, Ord, Read, Show)
{-# INLINE toDList #-}
toDList :: DoList a r -> D.DList a
toDList (DoList x) = x
instance Functor (DoList a) where
fmap = notSupported "fmap"
instance Applicative (DoList a) where
pure = notSupported "pure"
(<*>) = notSupported "(<*>)"
instance Monad (DoList a) where
(>>=) = notSupported "(>>=)"
{-# INLINE (>>) #-}
(>>) (DoList x) = DoList . D.append x . toDList
instance (IsString a) => IsString (DoList a r) where
{-# INLINE fromString #-}
fromString = item . fromString
{-# INLINE item #-}
item :: a -> DoList a r
item = DoList . D.singleton
{-# INLINE fromList #-}
fromList :: [a] -> DoList a r
fromList = DoList . D.fromList
{-# INLINE toList #-}
toList :: DoList a r -> [a]
toList = D.toList . toDList
notSupported :: String -> a
notSupported func = error $ "DoList " ++ func ++ " is not supported!"