git-annex/Types/UUID.hs
Joey Hess 2a43985605 partially completed switch away from having NoUUID in the UUID type
Not sure if this is any better, or even doesn't introduce a lot of bugs.
2013-03-05 13:40:40 -04:00

36 lines
742 B
Haskell

{- git-annex UUID type
-
- Copyright 2011,2013 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Types.UUID (
UUID,
UUIDMap,
fromUUID,
toUUID,
genUUID
) where
import qualified Data.Map as M
import qualified Data.UUID as U
import System.Random
import Control.Applicative
-- A UUID an arbitrary opaque string, which cannot be empty.
data UUID = UUID String
deriving (Eq, Ord, Show, Read)
type UUIDMap = M.Map UUID String
fromUUID :: UUID -> String
fromUUID (UUID u) = u
toUUID :: String -> Maybe UUID
toUUID [] = Nothing
toUUID s = Just (UUID s)
{- Generates a random UUID, that does not include the MAC address. -}
genUUID :: IO UUID
genUUID = UUID . show <$> (randomIO :: IO U.UUID)