/ src /
src/InfoKind.hs
1 {-# OPTIONS -fallow-undecidable-instances #-}
2 module InfoKind where
3
4 import Text.Parse
5 import Text.XML.HaXml.XmlContent
6
7 -- | The @InfoKind@ class is a predicate that ensures we can always create
8 -- at least a blank (empty) information element, that we can read and
9 -- write them to/from the user, and that there exists some method of
10 -- determining the correctness of the value (completeness/consistency etc)
11 -- against some global type.
12 class (Eq a, Show a, Parse a, XmlContent a) => InfoKind a g | a -> g where
13 blank :: a
14 check :: String -> g -> a -> [String] -- returns warnings
15 -- ^ first arg is container label for error reporting.
16 -- second arg is global value
17
18 -- A basic instance representing "no info"
19 instance InfoKind () () where
20 blank = ()
21 check _ _ () = []
22 -- Assume that info is mandatory, but not supplied a priori.
23 instance InfoKind a b => InfoKind (Maybe a) b where
24 blank = Nothing
25 check n _ Nothing = ["No info value stored with "++n]
26 check n g (Just a) = check n g a
27