module Recognize.Data.Approach where
import Control.Monad
import Data.List
import Ideas.Text.HTML
import Ideas.Text.XML
import Test.QuickCheck
class HasApproach a where
approach :: a -> Approach
data Approach = Algebraic | Arithmetic | Numerical | Recursive | Generalizing | Graphical | Other String | NoApproach deriving (Eq, Ord)
instance Show Approach where
show Algebraic = "algebraic"
show Arithmetic = "arithmetic"
show Numerical = "numerical"
show Recursive = "recursive"
show Generalizing = "generalizing"
show Graphical = "graphical"
show (Other s) = "Other: " ++ s
show NoApproach = "noapproach"
instance ToHTML Approach where
toHTML = text
instance ToXML Approach where
toXML a = makeXML "approach" $ text a
instance InXML Approach where
fromXML xml = do
unless (name xml == "approach") $ fail "expecting <approach> element"
case getData xml of
"algebraic" -> return Algebraic
"arithmetic" -> return Arithmetic
"numerical" -> return Numerical
"recursive" -> return Recursive
"generalizing" -> return Generalizing
"graphical" -> return Graphical
"noapproach" -> return NoApproach
txt | "Other: " `isPrefixOf` txt -> return (Other (drop 7 txt))
| otherwise -> fail $ "unknown approach " ++ txt
instance Arbitrary Approach where
arbitrary = oneof (pure <$> [Algebraic,Arithmetic, Numerical, Recursive, Generalizing, Graphical, Other "", NoApproach])