- -- a specific case for strings
- scase s = case reads s of
- [x::(String,String)] -> Just x
- _ -> Nothing
-
- -- the generic default of gread
- gdefault s = undefined
-
--}
-
+ gread' :: GenericB GRead
+ gread' = gdefault `extB` scase
+
+ where
+
+ -- a specific case for strings
+ scase = GRead ( \s -> case reads s of
+ [x::(String,String)] -> Just x
+ _ -> Nothing
+ )
+
+ -- the generic default for gread
+ gdefault =
+ do
+ trafo $ dropWhile ((==) ' ')
+ query $ not . (==) ""
+ query $ (==) '(' . head
+ trafo $ tail
+ trafo $ dropWhile ((==) ' ')
+ str <- parseConstr
+ con <- str2con str
+ x <- gunfoldM con gread'
+ trafo $ dropWhile ((==) ' ')
+ query $ not . (==) ""
+ query $ (==) ')' . head
+ trafo $ tail
+ return x
+
+ where
+ -- Turn string into constructor driven by gdefault's type
+ str2con = maybe mzero return
+ .
+ ( stringCon -- look up constructor at hand
+ $ dataTypeOf -- get handle on all constructurs
+ $ undefinedType -- turn type value into undefined
+ $ paraType -- get a handle on a in m a
+ $ gdefault -- use as type argument
+ )