Brandon Moore wrote:
> I don't quite understand the problem, but maybe an example involving an 
> explicit recursion operator will help.

-- Maybe he's looking for something like...

{-# OPTIONS -fglasgow-exts #-}
{-# OPTIONS -fallow-undecidable-instances #-}

import List

type Var = String
type Const = String

data MonoType mt = TyVar Var
                 | TyConst Const [mt] deriving (Eq, Show)

newtype Fix f = In { out :: f (Fix f) }

class Types a where
    freeVars :: a -> [Var]

instance Types (a (Fix a)) => Types (Fix a) where
    freeVars (In x) = freeVars x

instance Types a => Types (MonoType a) where    
    freeVars (TyVar x) = [x]
    freeVars (TyConst _ xs) = nub . concatMap freeVars $ xs

main = do
  print $ freeVars 
    (TyConst 
       "foo" 
       [(In (TyVar "abc")),
        (In (TyVar "123")),
        (In (TyConst 
               "bar"
               [(In (TyVar "www"))]))]))
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to