+{-# LANGUAGE DeriveDataTypeable #-}
+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
+{-# LANGUAGE OverloadedStrings #-}
module Hcompta.Model.Amount.Unit where
-type Unit
- = String
+import Data.Data
+import Data.String (IsString)
+import qualified Data.Text as Text
+import Data.Text (Text)
+import Data.Typeable ()
+
+import qualified Hcompta.Model.Filter as Model.Filter
+
+newtype Unit
+ = Unit Text
+ deriving (Data, Eq, IsString, Ord, Show, Typeable)
+
+instance Model.Filter.Unit Unit where
+ unit_text = text
+
+-- NOTE: maybe consider using text-show package
+text :: Unit -> Text
+text (Unit t) = t
+
+nil :: Unit
+nil = Unit ""
+
+length :: Unit -> Int
+length = Text.length . text