Hi

I'm trying to write a function:

reaches :: Type -> Q [Type]

The intention is that reaches (Either Bool [Int]) would return [Either
Bool [Int], Bool, [Int], Int] - i.e. all types which are contained by
the initial type at any level.

I took a shot at this:

getTypes :: Type -> Q [Type]
getTypes t = do
       let (ConT c, cs) = typeApp t
       TyConI dat <- reify c
       return $ concatMap ctorTypes $ dataCtors dat


reaches :: Type -> Q [Type]
reaches t = f [] [t]
   where
       f done [] = return done
       f done (t:odo)
           | t `elem` done = f done odo
           | otherwise = do
               ts <- getTypes t
               f (t:done) (odo ++ ts)

Where typeApp splits a type to find its constructor, ctorTypes gets
the types of the fields, and dataCtors gets the constructors in a data
type. Unfortunately reify doesn't seem to work on types. Is it
possible to do what I am after?

Thanks

Neil
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to