+-- | This is a replacement for @xpOption xpFoo@ within an 'xpAttr'.
+-- There's a bug <https://github.com/UweSchmidt/hxt/issues/39> in
+-- newer versions of HXT that prevents us from using the usual
+-- 'xpOption' solution, so this is our stopgap. It should work on
+-- any type that can be unpickled with a plain read/show.
+--
+xp_attr_option :: forall a. (Read a, Show a) => PU (Maybe a)
+xp_attr_option =
+ (to_a, from_a) `xpWrap` xpText
+ where
+ to_a :: String -> Maybe a
+ to_a = readMaybe
+
+ from_a :: Maybe a -> String
+ from_a Nothing = ""
+ from_a (Just x) = show x
+