[Haskell-cafe] what is the fastest way to extract variables
from a proposition?
ajb at spamcop.net
ajb at spamcop.net
Wed Feb 20 21:59:40 EST 2008
G'day all.
Quoting Cetin Sert <cetin.sert at gmail.com>:
> -- proposition
> data Prp a = Var a
> | Not (Prp a)
> | Or (Prp a) (Prp a)
> | And (Prp a) (Prp a)
> | Imp (Prp a) (Prp a)
> | Xor (Prp a) (Prp a)
> | Eqv (Prp a) (Prp a)
> | Cns Bool
> deriving (Show, Eq)
This is probably the fastest:
vars :: Prp a -> [a]
vars p = vars' p []
where
vars' (Var a) = (a:)
vars' (Not p) = vars' p
vars' (Or l r) = vars' l . vars' r
{- etc -}
vars' (Cns _) = id
Cheers,
Andrew Bromage
More information about the Haskell-Cafe
mailing list